BLL.LoginTblBLL loginBLL = new BLL.LoginTblBLL(); private void btnLogin_Click(object sender, EventArgs e) { string loginName = txtLoginName.Text.Trim(); string loginPwd = txtLoginPwd.Text; if (string.IsNullOrEmpty(loginName)||string.IsNullOrEmpty(loginPwd)) { return; } if (loginBLL.IsLogin(loginName, loginPwd)) { //登录成功 this.DialogResult = DialogResult.OK; } else { MessageBox.Show("用户名或密码错误!"); } }
<connectionStrings> <add name="SQLite" connectionString="Data Source=db\CaterSystem.db;version=3;"/> connectionStrings>
public class LoginTblBLL { DAL.LoginTblDAL loginDAL = new DAL.LoginTblDAL(); public bool IsLogin(string loginName, string loginPwd) { return loginDAL.IsLogin(loginName, loginPwd)>0; } }
public class LoginTblDAL { public int IsLogin(string loginName, string loginPwd) { string sql = "select count(*) from LoginTbl where loginUid=@uid and loginPwd=@pwd"; SQLiteParameter[] ps = { new SQLiteParameter("@uid",loginName), new SQLiteParameter("@pwd",loginPwd) }; object count = SQLiteHelper.ExecuteScalar(sql, ps); return (int)(long)count; } }}