You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LibraryManagementSystem/README.md

1.9 KiB

// 用户登录代码实现主要通过sql语句调用DataAccess类中的GetDataSetBySql()方法来实现的 namespace L019_BookMange { public partial class frmLogin : Form { public frmLogin() { InitializeComponent(); } private void btnLogin_Click(object sender, EventArgs e) { //输入账号密码正确
if (Validate()) { string state = this.cboUserType.Text; int num; if (state.Equals("管理员"))//判断用户角色,若为管理员 num = 2; else //若为读者 num = 1; //定义查询语句 string sql = string.Format("select * from userinfo where uname='{0}'and upwd='{1}'and ustate={2}", this.txtName.Text.Trim(), this.txtPwd.Text.Trim(), num); DataSet ds = DataAccess.GetDataSetBySql(sql); //操作数据库 if (ds.Tables[0].Rows.Count > 0) { MessageBox.Show("登录成功"); FrmMain.result = DialogResult.OK;//为变量result赋值 this.Close(); } else MessageBox.Show("用户名或密码错误,请重新输入"); }
} private void frmLogin_Load(object sender, EventArgs e) { this.cboUserType.SelectedIndex = 0; } private bool Validate() //检测用户名和密码是否为空 { if (this.txtName.Text != string.Empty && this.txtPwd.Text != string.Empty) return true; else MessageBox.Show("用户名或密码不能为空"); //返回错误提示信息 return false; } private void btnCancle_Click(object sender, EventArgs e) { this.Close(); } } }