public void LoginLog(OperLogin login) { try { conn = ConnectionPool.BorrowConnection(); trans = conn.BeginTransaction(); string strHostName = Environment.MachineName; IPHostEntry oIPHost = Dns.GetHostEntry(Environment.MachineName);//Dns.Resolve(Environment.MachineName); string strHostIP = ""; if (oIPHost.AddressList.Length > 0) { strHostIP = oIPHost.AddressList[0].ToString(); } login.cnvcHostName = strHostName; login.cnvcHostAddress = strHostIP; SeqSerialNo serialNo = new SeqSerialNo(); serialNo.cnvcFill = "0"; login.cnnSerialNp = EntityMapping.Create(serialNo, trans); EntityMapping.Create(login, trans); //折扣上限 trans.Commit(); } catch (BusinessException bex) //业务异常 { trans.Rollback(); //LogAdapter.WriteBusinessException(bex); throw new BusinessException(bex.Type, bex.Message); } catch (SqlException sex) //数据库异常 { //事务回滚 trans.Rollback(); //LogAdapter.WriteDatabaseException(sex); throw new BusinessException("数据库异常", sex.Message); } catch (Exception ex) //其他异常 { //事务回滚 trans.Rollback(); //LogAdapter.WriteFeaturesException(ex); throw new BusinessException("其它异常", ex.Message); } finally { ConnectionPool.ReturnConnection(conn); } }
private void btnBrushCard_Click(object sender, System.EventArgs e) { //刷卡登录 try { //读取会员卡号 iLoginTime += 1; if (iLoginTime > 3) { Application.Exit(); } else { CardM1 m1 = new CardM1(); string strCardNo = ""; string strRet = m1.ReadCard(out strCardNo); //,out dtemp,out itemp); if (strRet != ConstMsg.RFOK) { throw new BusinessException("卡操作失败", "读取操作员卡失败!"); } DataTable dtOper = Helper.Query("select * from tbOper where cnvcCardNo is not null and cnvcCardNo = '" + strCardNo + "'"); if (dtOper.Rows.Count == 0) { throw new BusinessException("登录", "未找到操作员"); } if (dtOper.Rows.Count > 1) { throw new BusinessException("登录", "未找到操作员"); } Oper oper = new Oper(dtOper); byte[] bIn = Convert.FromBase64String(oper.cnvcPwd); byte[] bRet = Cryptographer.DecryptSymmetric("Custom Symmetric Cryptography Provider", bIn); if (bRet == null) { throw new BusinessException("登录", "密码错误"); } string strpwd = Encoding.UTF8.GetString(bRet); SysInit.LoadPara(Login.constApp); LogIn(oper.cnvcOperName, strpwd, Login.constApp.strCardTypeL6Name, Login.constApp.strCardTypeL8Name); SecurityManage security = new SecurityManage(); //security.OperLogin(oper.cnvcOperName);//,oper.cnvcPwd); //constApp.alOperFunc = security.alOperFunc; //constApp.oper = security.oper; //constApp.iDiscount = security.iDiscount; //SysInit.LoadPara(Login.constApp); OperLogin login = new OperLogin(oper.ToTable()); login.cndLoginDate = DateTime.Now; login.cnvcLoginMethod = "刷卡"; login.cnnAgainTime = iLoginTime; security.LoginLog(login); MainForm mForm = new MainForm(); //mForm.ll = this; mForm.Owner = this; mForm.Show(); this.Hide(); // = false; } } catch (BusinessException bex) { MessageBox.Show(this, bex.Message, bex.Type, MessageBoxButtons.OK, MessageBoxIcon.Error); } //catch (System.Exception ex) //{ // MessageBox.Show(this,ex.Message,"系统错误",MessageBoxButtons.OK,MessageBoxIcon.Error); //} }
private void btnLogin_Click(object sender, System.EventArgs e) { //登录 try { if (iLoginTime > 3) { Application.Exit(); } else { string strOperName = txtOperName.Text.Trim(); string strPWD = txtPWD.Text.Trim(); if (strOperName.Length == 0) { throw new BusinessException("登录错误", "请输入用户名!"); } if (strPWD.Length == 0) { throw new BusinessException("登录错误", "请输入密码!"); } SysInit.LoadPara(Login.constApp); LogIn(strOperName, strPWD, Login.constApp.strCardTypeL6Name, Login.constApp.strCardTypeL8Name); SecurityManage security = new SecurityManage(); //security.OperLogin(strOperName);//,DataSecurity.Encrypt(strPWD); //constApp.alOperFunc = security.alOperFunc; //constApp.oper = security.oper; //constApp.iDiscount = security.iDiscount; //isLogin = true; //constApp = new ConstApp(); //LogAdapter.WriteFeaturesException(new Exception("导入基本数据前")); //LogAdapter.WriteFeaturesException(new Exception("导入基本数据后")); OperLogin login = new OperLogin(); if (cmbDept.SelectedItem != null) { login.cnnDeptID = int.Parse(cmbDept.SelectedItem.DataValue.ToString()); } login.cnvcOperName = txtOperName.Text; login.cndLoginDate = DateTime.Now; login.cnvcLoginMethod = "录入"; login.cnnAgainTime = iLoginTime; security.LoginLog(login); //LogAdapter.WriteFeaturesException(new Exception("写登录日志")); MainForm mForm = new MainForm(); mForm.Owner = this; //mForm.ll = this; //LogAdapter.WriteFeaturesException(new Exception("主窗体new完成")); mForm.Show(); //LogAdapter.WriteFeaturesException(new Exception("主窗体show完成")); this.Hide(); //LogAdapter.WriteFeaturesException(new Exception("主窗体打开完成")); } } catch (BusinessException bex) { iLoginTime += 1; //MessageBox.Show(this, bex.Message, bex.Type,MessageBoxButtons.OK,MessageBoxIcon.Error); this.txtOperName.Focus(); throw bex; //isLogin = false; } //catch (System.Exception ex) //{ // MessageBox.Show(this, ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); // Application.Exit(); // //this.btnLogin.DialogResult = DialogResult.Cancel; //} }