From 9723016b4f4ae90b798673aa2903b28d8057ce0e Mon Sep 17 00:00:00 2001 From: aufe20202437 Date: Tue, 22 Nov 2022 09:19:05 +0800 Subject: [PATCH] Update README.md --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2479ea7..f06cc1c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,51 @@ -# LibraryManagementSystem - +// 用户登录代码实现:主要通过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(); + } + } +} \ No newline at end of file