为什么在登陆的时候总说我没有选择用户角色了了?
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)
{
}
}
}