private void btnLog_Click(object sender, EventArgs e) { //文本框验证为纯数字 if (tetLogId.CheckData(@"^[1-9]\d*$", "账号格式为纯数字!") * tetLogPwd.CheckNullOrEmpty() != 0) { //将登录账号和密码封装成收银员对象 SalesPerson person = new SalesPerson() { SalesPersonid = int.Parse(tetLogId.Text), LoginPwd = tetLogPwd.Text.Trim() }; //在数据库中将对账户和密码,如果登陆成功则将登陆对象保存到全局,并且保存到系统日志 SalesPerson res = manager.SaleLogin(person); if (manager.SaleLogin(person) != null) { Program.Sale = res; int Logid = manager.WriteSaleLog(new LoginLogs() { Loginid = res.SalesPersonid, SPName = res.SPName, ServerName = Dns.GetHostName() }); Program.Sale.Logid = Logid; this.DialogResult = DialogResult.OK; Log4net.WriteInfo((string.Format("" + res + ""))); this.Close(); } else { Log4net.WriteInfo((string.Format("" + res + ""))); MessageBox.Show("账号或密码错误", "登陆提示"); } } }
/// <summary> /// 登录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLog_Click(object sender, EventArgs e) { //【1】文本框数据的验证 //如果为0则有必填项未填写! if (txtLogId.CheckData(@"^[1-9]\d*$", "账号格式为纯数字!") * txtLogPwd.CheckNullOrEmpty() != 0) { //【2】登录账号和密码封装成收银员对象 SalesPerson person = new SalesPerson() { SalesPersonId = int.Parse(txtLogId.Text), LoginPwd = txtLogPwd.Text.Trim() }; //【3】数据库中查询 SalesPerson res = manerger.SalesLogin(person); if (res != null)//证明登录成功 { //(1)将登录对象保存到全局 Program.Sale = res; //(2)将登录信息记录进系统日志 //记录一下不等于null的数据(获取到收银员的数据) int logId = manerger.WriteSalesLog(new LoginLogs() { LoginId = res.SalesPersonId, SPName = res.SPName, ServerName = Dns.GetHostName() }); Program.Sale.LogId = logId; this.DialogResult = DialogResult.OK; Log4net.WriteInfo(string.Format("" + res + "")); this.Close(); } else { Log4net.WriteInfo(string.Format("" + res + "")); MessageBox.Show("账号或密码错误!", "登录提示"); } } }