| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 689 人关注过本帖
标题:为什么在登陆的时候总说我没有选择用户角色了了?
只看楼主 加入收藏
万光海
Rank: 3Rank: 3
来 自:桂林
等 级:论坛游侠
帖 子:92
专家分:133
注 册:2012-10-21
结帖率:68.75%
收藏
已结贴  问题点数:20 回复次数:5 
为什么在登陆的时候总说我没有选择用户角色了了?
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DormManageSystem
{
    public partial class Login : Form
    {

        private SqlConnection sqlConnection1 = null;
        public Login()
        {
            InitializeComponent();
            this.sqlConnection1 = new SqlConnection(DormManageSystem.database.sqlConnection.connection);
        }
        string user;
        private void radioButton1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                user = radioButton1.Text.Trim();
            }
        }

        private void radioButton2_Click(object sender, EventArgs e)
        {
            if (radioButton2.Checked == true)
            {
                user = radioButton2.Text.Trim();
            }
        }
        private void btOk_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (name.Text.Trim() == "" || password.Text == "")
                    MessageBox.Show("请输入用户名或密码!", "提示");
                else
                {
                    sqlConnection1.Open();
                    SqlCommand cmd = new SqlCommand("", sqlConnection1);
                    string sql = "select rolename from userinfo where  uid='" + name.Text.Trim() + "'and pwd='" + password.Text + "' ";
                     = sql;
                    string rolename = cmd.ExecuteScalar().ToString();
                    //判断权限
                    if (rolename.ToString() == user.ToString())
                    {
                        this.Hide();
                        Main main = new Main();
                        main.Tag = this.FindForm();
                        sql = "select * from role where rolename='" + rolename + "' ";
                        SqlDataReader dr;
                         = sql;
                        dr = cmd.ExecuteReader();
                        dr.Read();
                        main.SuSheXinXi.Visible = (bool)(dr.GetValue(1));
                        main.StudentRuZhu.Visible = (bool)(dr.GetValue(1));
                        main.WeiShengManage.Visible = (bool)(dr.GetValue(1));
                        main.WEManage.Visible = (bool)(dr.GetValue(1));
                        main.RoomRepair.Visible = (bool)(dr.GetValue(1));
                        main.Register.Visible = (bool)(dr.GetValue(1));
                        main.AddYongHu.Visible = (bool)(dr.GetValue(1));
                        main.Accident.Visible = (bool)(dr.GetValue(1));
                        main.HolidayDrom.Visible = (bool)(dr.GetValue(1));
                        main.tooluser.Text =  name.Text.Trim();
                        main.toolquanxian.Text = " |  用户角色:" + rolename.ToString();
                        main.ShowDialog();
                    }
                    else
                        MessageBox.Show("用户名或密码或角色不正确!", "警告");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请选择用户角色!","提示");
            }
            sqlConnection1.Close();
        }

        private void btChongZhi_Click_1(object sender, EventArgs e)
        {
            name.Text = "";
            password.Text = "";
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
搜索更多相关主题的帖子: namespace 角色 private public null 
2013-04-23 10:08
lantian8134
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:8
帖 子:115
专家分:789
注 册:2013-1-11
收藏
得分:15 
user还没有赋值,radioButton1和radioButton2的Click事件没有触发过,可以给user赋一个默认值
2013-04-23 13:05
lxb932979339
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:84
专家分:313
注 册:2013-4-24
收藏
得分:5 
能把程序 给我么 我看看 lxb932979339@
2013-04-24 03:19
万光海
Rank: 3Rank: 3
来 自:桂林
等 级:论坛游侠
帖 子:92
专家分:133
注 册:2012-10-21
收藏
得分:0 
回复 2楼 lantian8134
求解怎么赋值???
2013-04-27 17:04
lantian8134
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:8
帖 子:115
专家分:789
注 册:2013-1-11
收藏
得分:0 
string user = 某一个单选按钮的值
用户名、密码你确定输入正确的吧
2013-04-27 17:13
万光海
Rank: 3Rank: 3
来 自:桂林
等 级:论坛游侠
帖 子:92
专家分:133
注 册:2012-10-21
收藏
得分:0 
回复 5楼 lantian8134
谢了撒!
2013-04-30 10:56
快速回复:为什么在登陆的时候总说我没有选择用户角色了了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033772 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved