private void btnLogin_Click(object sender, EventArgs e) { ///1 验证不为空 if (this.txtLoginId.Text.Trim().Length == 0) { MessageBox.Show("xxxxxxxxxx"); this.txtLoginId.Focus(); return; } if (this.txtLoginPwd.Text.Trim().Length == 0) { MessageBox.Show("Please entry the Password"); this.txtLoginPwd.Focus(); return; } //2 封装 sysAdmin objAdmin = new sysAdmin() { LoginId = Convert.ToInt32(this.txtLoginId.Text.Trim()), LoginPwd = this.txtLoginPwd.Text.Trim() }; try { objAdmin = objSysAdminService.AdminLogin(objAdmin); if (objAdmin != null) { //save Admin info Program.objCurrentAdmin = objAdmin; // this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("UserId or Password wrong!"); } } catch (Exception ex) { MessageBox.Show("sql connection error!!!"); } }
public sysAdmin AdminLogin(sysAdmin objAdmin) { string sql = "select AdminName from Admins where LoginId={0} and LoginPwd ='{1}'"; sql = string.Format(sql, objAdmin.LoginId, objAdmin.LoginPwd); //quary SqlDataReader objReader = SQLHelper.GetReader(sql); if (objReader.Read()) { objAdmin.AdminName = objReader["AdminName"].ToString(); } else { objAdmin = null; } objReader.Close(); //retrun return(objAdmin); }