C#radiobutto身份验证登录问题
用户密码正确,radiobotton也选择对,可是也会出现messgebox提示错误。不明原因。求大侠帮助
程序代码: private void btnGo_Click(object sender, EventArgs e)
{
string 用户名 = tbx用户名.Text.Trim();
string 密码 = tbx密码.Text.Trim();
string Roler;
if (rbt普通职工.Checked) Roler = rbt普通职工.Text;
if (rbt管理员.Checked) Roler = rbt管理员.Text;
if (rbt超级管理员.Checked) Roler = rbt超级管理员.Text;
if (tbx用户名.Text == "请输入用户名" || tbx用户名.Text == "")
{
MessageBox.Show("用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbx用户名.Focus();
}
else if (tbx密码.Text == "")
{
MessageBox.Show("密码不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbx密码.Focus();
}
else if (rbt超级管理员.Checked == true)
{
DataSet ds = (SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, "SELECT 用户类型 FROM 员工表 WHERE 超级管理员"));
if (IsValidateBySqlHelper(tbx用户名.Text.Trim(), tbx密码.Text.Trim()))
{
MessageBox.Show("登录成功,您的权限是超级管理员.", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form MainForm = new MainForm();
MainForm.Show();
this.Hide();//隐藏本窗体
}
else
{
MessageBox.Show("用户名密码不匹配,请检查是否选择了相应权限", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbx用户名.Text = String.Empty;
tbx密码.Text = String.Empty;
}
}
else if (rbt管理员.Checked == true)
{
if (IsValidateBySqlHelper(tbx用户名.Text.Trim(), tbx密码.Text.Trim()))
{
MessageBox.Show("登录成功,您的权限是管理员.", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form MainFormMancs = new MainFormMancs();
MainFormMancs.Show();
this.Hide();//隐藏本窗体
}
else
{
MessageBox.Show("用户名密码不匹配,请检查是否选择了相应权限", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbx用户名.Text = String.Empty;
tbx密码.Text = String.Empty;
}
}
else if (rbt普通职工.Checked == true)
{
if (IsValidateBySqlHelper(tbx用户名.Text.Trim(), tbx密码.Text.Trim()))
{
MessageBox.Show("登录成功,您的权限是普通职工.", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form MainFormUser = new MainFormUser();
MainFormUser.Show();
this.Hide();//隐藏本窗体
}
else
{
MessageBox.Show("用户名密码不匹配,请检查是否选择了相应权限", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbx用户名.Text = String.Empty;
tbx密码.Text = String.Empty;
}
}
public bool IsValidateBySqlHelper(string strUserName, string strPwd)
{
SqlConnection conn = SqlHelper.GetConnection();
string strSQL = "select * from 员工表 Where 职工姓名=@用户名 and 密码=@密码 and 用户类型=@Roler";
SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@用户名", SqlDbType.NVarChar);
para[1] = new SqlParameter("@密码", strPwd);
para[2] = new SqlParameter("@Roler", SqlDbType.NVarChar);
SqlDataReader reader = SqlHelper.ExecuteReader(conn, CommandType.Text, strSQL, para);
if (reader.HasRows)
{
conn.Close();
return true;
}
else
{
conn.Close();
return false;
}
}









