/// <summary> /// 窗体加载事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainFormLoad(object sender, EventArgs e) { try { ribbonControl1.Minimized = true; // 加载一些默认皮肤 SkinHelper.InitSkinGallery(rbSkin, true); // ChildFormManagementHelper.Navigate(this, "http://yd.zt-express.com/Help/Index2", "帮助"); ChildFormManagementHelper.LoadMdiForm(this, "FrmPrintData"); // ChildFormManagementHelper.Navigate(this, "http://zto.com", "申通官网"); // radialMenu1.ShowPopup(Control.MousePosition, true); //ChildFormManagement.LoadMdiForm(this, "FrmSendManData"); //ChildFormManagement.LoadMdiForm(this, "FrmReceiveManData"); if (xtraTabbedMdiManager1.Pages.Count > 1) { xtraTabbedMdiManager1.SelectedPage = xtraTabbedMdiManager1.Pages[1]; } #region 底部一些基本信息绑定 barItemsUser.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; barItemWeather.Visibility = DevExpress.XtraBars.BarItemVisibility.Never; var version = Assembly.GetExecutingAssembly().GetName().Version; barItemWelcome.Caption = string.Format("欢迎使用{1}-当前版本:{0}", version, BaseSystemInfo.SoftFullName); // 得到数据库的版本 BaseParameterManager parameterManager = new BaseParameterManager(BillPrintHelper.DbHelper, BaseSystemInfo.UserInfo, BaseParameterEntity.TableName); var synchronous = parameterManager.GetParameter("Bill", "DBVersion", "Synchronous"); if (!string.IsNullOrEmpty(synchronous)) { barItemWelcome.Caption += " 主库版本:" + synchronous; } this.Text = string.Format("{0}-当前版本:{1}", this.Text, version); barItemTime.Caption = string.Format("登录时间:{0} {1}", DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat), DateUtil.GetDayOfWeek(DateTime.Now.DayOfWeek.ToString(), true) + " " + DateHelper.GetChineseDateTime(DateTime.Now)); #endregion var userManager = new ZtoUserManager(BillPrintHelper.DbHelper); var userList = userManager.GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1)); if (!userList.Any()) { if (XtraMessageBox.Show(@"未添加默认发件人信息,请添加默认发件人信息,有利于提取申通大头笔", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK) { var addSendMan = new FrmAddSendMan(); addSendMan.ShowDialog(); addSendMan.Dispose(); } } timerUpdate.Start(); //FrmChatMessage chatMessage = new FrmChatMessage(); //chatMessage.Show(); } catch (Exception ex) { ProcessException(ex); } }
/// <summary> /// 批量删除参数 /// </summary> /// <param name="userInfo">用户</param> /// <param name="ids">主键数组</param> /// <returns>影响行数</returns> public int BatchDelete(BaseUserInfo userInfo, string[] ids) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseParameterManager parameterManager = new BaseParameterManager(dbHelper, userInfo); for (int i = 0; i < ids.Length; i++) { returnValue += parameterManager.Delete(ids[i]); } BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ParameterService_BatchDelete, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 按编号获取参数列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="categoryId">分类主键</param> /// <param name="parameterId">参数主键</param> /// <param name="parameterCode">参数编号</param> /// <returns>数据表</returns> public DataTable GetDataTableParameterCode(BaseUserInfo userInfo, string categoryId, string parameterId, string parameterCode) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseParameterEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseParameterManager parameterManager = new BaseParameterManager(dbHelper, userInfo); dataTable = parameterManager.GetDataTableParameterCode(categoryId, parameterId, parameterCode); dataTable.TableName = BaseParameterEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.ParameterService_GetDataTableParameterCode, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }
/// <summary> /// 同步省市区数据 /// </summary> /// <param name="delete"></param> /// <returns></returns> public static int SynchronousArea(bool delete = false) { int result = 0; if (!System.IO.File.Exists(SqLiteDb)) { return(result); } DateTime?modifiedOn = new DateTime(2014, 01, 01); string dbConnection = "Data Source={StartupPath}/DataBase/STO.Bill.db;Pooling=true;FailIfMissing=false;Password=ZTO20149988"; dbConnection = dbConnection.Replace("{StartupPath}", System.Windows.Forms.Application.StartupPath); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(CurrentDbType.SQLite, dbConnection)) { BaseParameterManager parameterManager = new BaseParameterManager(dbHelper, BaseSystemInfo.UserInfo, BaseParameterEntity.TableName); var tableName = BaseAreaEntity.TableName; if (!delete) { var synchronous = parameterManager.GetParameter(BaseParameterEntity.TableName, "System", tableName, "Synchronous"); if (!string.IsNullOrEmpty(synchronous)) { modifiedOn = DateTime.Parse(synchronous); } } if (delete) { dbHelper.ExecuteNonQuery("DELETE FROM " + tableName); } result = SynchronousTable("UserCenter", tableName, new string[] { BaseAreaEntity.FieldId }, modifiedOn, "Bill", tableName, 20000, false); if (result > 0) { parameterManager.SetParameter(BaseParameterEntity.TableName, "System", tableName, "Synchronous", DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat)); } } return(result); }
/// <summary> /// 登录前运行的方法 /// </summary> public static void BeforeLogOn() { // 0:若文件不存在,就退出数据同步,不进行数据同步 string sqLiteDb = System.Windows.Forms.Application.StartupPath + @"\DataBase\STO.Bill.db"; if (!System.IO.File.Exists(sqLiteDb)) { return; } try { // 01:打开业务数据库 string dbConnection = "Data Source={StartupPath}/DataBase/STO.Bill.db;Pooling=true;FailIfMissing=false;Password=ZTO20149988"; dbConnection = dbConnection.Replace("{StartupPath}", System.Windows.Forms.Application.StartupPath); IDbHelper dbHelper = DbHelperFactory.GetHelper(CurrentDbType.SQLite, dbConnection); // 02: 先保存个同步时间标志,什么时间成功同步过本地数据库?这样不用每次都同步所有的数据,只同步那个时间之后的数据就可以了。 BaseParameterManager parameterManager = new BaseParameterManager(dbHelper, BaseSystemInfo.UserInfo, BaseParameterEntity.TableName); // 03:用参数的方式读取同步时间 // 04:检查数据库里的版本号 var synchronous = parameterManager.GetParameter("Bill", "DBVersion", "Synchronous"); if (string.IsNullOrEmpty(synchronous)) { synchronous = "5.2015.7.15"; parameterManager.SetParameter("Bill", "DBVersion", "Synchronous", synchronous); } var versionEntity = new Version(synchronous); if (versionEntity < new Version("5.2015.08.14")) { Upgrade20150814(); } if (versionEntity < new Version("5.2015.08.21")) { Upgrade20150821(); } if (versionEntity < new Version("5.2015.08.23")) { if (Upgrade20150823()) { // InitExpressData(); } } if (versionEntity < new Version("5.2015.08.26")) { if (Upgrade20150826()) { if (Upgrade20150823()) { // InitExpressData(); parameterManager.SetParameter(BaseParameterEntity.TableName, "Bill", "DBVersion", "Synchronous", "5.2015.08.26"); } } } if (versionEntity < new Version("5.2015.09.14")) { Upgrade20150914(); } if (versionEntity < new Version("5.2015.10.15")) { Upgrade20151015(); } if (versionEntity < new Version("5.2015.10.25")) { Upgrade20151025(); } if (versionEntity < new Version("5.2015.11.05")) { Upgrade20151105(); } if (versionEntity < new Version("5.2015.11.11")) { Upgrade20151111(); } if (versionEntity < new Version("5.2015.12.12")) { Upgrade20151212(); } if (versionEntity < new Version("5.2016.01.20")) { Upgrade20160120(); } if (versionEntity < new Version("6.2016.06.20")) { Upgrade20160620(); } if (versionEntity < new Version("6.2016.07.20")) { Upgrade20160720(); } //if (versionEntity < new Version("6.2016.03.21")) //{ // parameterManager.SetParameter(BaseParameterEntity.TableName, "Bill", "DBVersion", "Synchronous", "6.2016.03.21"); //} InitExpressData(); } catch (Exception ex) { // 在本地记录异常 LogUtil.WriteException(ex); } }
/// <summary> /// 添加IP地址或者Mac地址 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAdd_Click(object sender, EventArgs e) { //检查输入是否有效 if (!this.CheckInput()) { return; } string statusCode = string.Empty; string returnValue = string.Empty; string[] nameArr = new string[2]; string[] valueArr = new string[2]; BaseParameterManager parameterManager = new BaseParameterManager(this.UserCenterDbHelper, this.UserInfo); BaseSequenceManager sequenceManager = new BaseSequenceManager(this.UserCenterDbHelper, this.UserInfo); // 增加ip List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); if (!string.IsNullOrEmpty(this.txtIPAddress.Text.Trim())) { parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, this.ucUser.SelectedId)); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, this.txtIPAddress.Text.Trim())); // 检查是否存在IpAddress if (parameterManager.Exists(parameters)) { statusCode = AppMessage.MSG0055; MessageBox.Show(statusCode, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } BaseParameterEntity entityIp = new BaseParameterEntity(); entityIp.Id = sequenceManager.GetSequence(BaseParameterEntity.TableName); entityIp.CategoryId = "IPAddress"; entityIp.ParameterId = this.ucUser.SelectedId; string ipStr = this.txtIPAddress.Text.Trim(); //Range Mask 和Single 在CheckInput 方法中使用正则表达式对输入进行验证 //如果是地址段 if (ipStr.IndexOf('-') > 0) { entityIp.ParameterCode = "Range";// mask range } else if (ipStr.IndexOf('*') > 0) { //如果有mask entityIp.ParameterCode = "Mask"; } else { entityIp.ParameterCode = "Single"; } //如果是单个ip entityIp.ParameterContent = this.txtIPAddress.Text.Trim(); returnValue = parameterManager.AddEntity(entityIp); if (!string.IsNullOrEmpty(returnValue)) { statusCode = AppMessage.MSG0056; } else { statusCode = AppMessage.MSG0057; } } // 增加Mac if (!string.IsNullOrEmpty(this.txtMacAddress.Text.Trim())) { parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, this.ucUser.SelectedId)); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterContent, this.txtMacAddress.Text.Trim())); // 检查是否存在MacAddress if (parameterManager.Exists(parameters)) { statusCode = AppMessage.MSG0058; MessageBox.Show(statusCode, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } BaseParameterEntity entityMac = new BaseParameterEntity(); entityMac.Id = sequenceManager.GetSequence(BaseParameterEntity.TableName); entityMac.CategoryId = "MacAddress"; entityMac.ParameterId = this.ucUser.SelectedId; entityMac.ParameterCode = "Single"; entityMac.ParameterContent = this.txtMacAddress.Text.Trim(); returnValue = parameterManager.AddEntity(entityMac); if (!string.IsNullOrEmpty(returnValue)) { statusCode += AppMessage.MSG0059; } else { statusCode += AppMessage.MSG0061; } } MessageBox.Show(statusCode, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); // 重新绑定listbox this.GetIpList(this.ucUser.SelectedId); this.GetMacList(this.ucUser.SelectedId); this.CleanScreen(); }
/// <summary> /// 进行登录操作 /// </summary> /// <param name="userName">用户名</param> /// <param name="password">密码</param> /// <param name="createNewOpenId"></param> /// <param name="ipAddress">IP地址</param> /// <param name="macAddress">MAC地址</param> /// <param name="checkUserPassword">是否要检查用户密码</param> /// <returns>用户信息</returns> public BaseUserInfo LogOn(string userName, string password, bool createNewOpenId = false, string ipAddress = null, string macAddress = null, bool checkUserPassword = true) { BaseUserInfo userInfo = null; string realName = string.Empty; if (UserInfo != null) { realName = UserInfo.RealName; } if (ipAddress == null) { if (UserInfo != null) { ipAddress = UserInfo.IPAddress; } } // 01: 系统是否采用了在线用户的限制 if (BaseSystemInfo.OnLineLimit > 0) { if (this.CheckOnLineLimit()) { this.ReturnStatusCode = StatusCode.ErrorOnLineLimit.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0089 + BaseSystemInfo.OnLineLimit.ToString()); return(userInfo); } } // 04. 默认为用户没有找到状态,查找用户 // 这是为了达到安全要求,不能提示用户未找到,那容易让别人猜测到帐户 if (BaseSystemInfo.CheckPasswordStrength) { this.ReturnStatusCode = StatusCode.ErrorLogOn.ToString(); } else { this.ReturnStatusCode = StatusCode.UserNotFound.ToString(); } // 02. 查询数据库中的用户数据?只查询未被删除的 // 先按用户名登录 DataTable dataTable = this.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldUserName, userName) , new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); // 若不是严格检查,可以采用多种方式登录 if (!BaseSystemInfo.CheckPasswordStrength) { if (dataTable.Rows.Count == 0) { // 若没数据再按工号登录 dataTable = this.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, userName) , new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); } if (dataTable.Rows.Count == 0) { // 若没数据再按邮件登录 dataTable = this.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldEmail, userName) , new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); } if (dataTable.Rows.Count == 0) { // 若没数据再按手机号码登录 dataTable = this.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldMobile, userName) , new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); } if (dataTable.Rows.Count == 0) { // 若没数据再按手机号码登录 dataTable = this.GetDataTable(new KeyValuePair <string, object>(BaseUserEntity.FieldTelephone, userName) , new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); } } BaseUserEntity userEntity = null; if (dataTable.Rows.Count > 1) { this.ReturnStatusCode = StatusCode.UserDuplicate.ToString(); } else if (dataTable.Rows.Count == 1) { // 03. 系统是否采用了密码加密策略? string encryptPassword = string.Empty; if (checkUserPassword) { if (BaseSystemInfo.ServerEncryptPassword) { password = this.EncryptUserPassword(password); } } // 05. 判断密码,是否允许登录,是否离职是否正确 foreach (DataRow dataRow in dataTable.Rows) { userEntity = new BaseUserEntity(dataRow); if (!string.IsNullOrEmpty(userEntity.AuditStatus) && userEntity.AuditStatus.EndsWith(AuditStatus.WaitForAudit.ToString())) { this.ReturnStatusCode = AuditStatus.WaitForAudit.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0078); return(userInfo); } // 用户是否有效的 if (userEntity.Enabled == 0) { this.ReturnStatusCode = StatusCode.LogOnDeny.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0079); return(userInfo); } // 用户是否有效的 if (userEntity.Enabled == -1) { this.ReturnStatusCode = StatusCode.UserNotActive.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0080); return(userInfo); } // 06. 允许登录时间是否有限制 if (userEntity.AllowEndTime != null) { userEntity.AllowEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userEntity.AllowEndTime.Value.Hour, userEntity.AllowEndTime.Value.Minute, userEntity.AllowEndTime.Value.Second); } if (userEntity.AllowStartTime != null) { userEntity.AllowStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userEntity.AllowStartTime.Value.Hour, userEntity.AllowStartTime.Value.Minute, userEntity.AllowStartTime.Value.Second); if (DateTime.Now < userEntity.AllowStartTime) { this.ReturnStatusCode = StatusCode.UserLocked.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0081 + userEntity.AllowStartTime.Value.ToString("HH:mm")); return(userInfo); } } if (userEntity.AllowEndTime != null) { if (DateTime.Now > userEntity.AllowEndTime) { this.ReturnStatusCode = StatusCode.UserLocked.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0082 + userEntity.AllowEndTime.Value.ToString("HH:mm")); return(userInfo); } } // 07. 锁定日期是否有限制 if (userEntity.LockStartDate != null) { if (DateTime.Now > userEntity.LockStartDate) { if (userEntity.LockEndDate == null || DateTime.Now < userEntity.LockEndDate) { this.ReturnStatusCode = StatusCode.UserLocked.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0083 + userEntity.LockStartDate.Value.ToString("yyyy-MM-dd")); return(userInfo); } } } if (userEntity.LockEndDate != null) { if (DateTime.Now < userEntity.LockEndDate) { this.ReturnStatusCode = StatusCode.UserLocked.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0084 + userEntity.LockEndDate.Value.ToString("yyyy-MM-dd")); return(userInfo); } } // 08. 是否检查用户IP地址,是否进行访问限制?管理员不检查IP. if (BaseSystemInfo.CheckIPAddress && !this.IsAdministrator(userEntity.Id.ToString())) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, userEntity.Id.ToString())); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryId, "IPAddress")); // 没有设置IP地址时不检查 BaseParameterManager baseParameterManager = new BaseParameterManager(this.DbHelper); if (baseParameterManager.Exists(parameters)) { if (!string.IsNullOrEmpty(ipAddress) && !this.CheckIPAddress(ipAddress, userEntity.Id.ToString())) { this.ReturnStatusCode = StatusCode.ErrorIPAddress.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, ipAddress, ipAddress, AppMessage.MSG0085); return(userInfo); } } // 没有设置MAC地址时不检查 parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldParameterId, userEntity.Id.ToString())); parameters.Add(new KeyValuePair <string, object>(BaseParameterEntity.FieldCategoryId, "MacAddress")); if (baseParameterManager.Exists(parameters)) { if (!string.IsNullOrEmpty(macAddress) && !this.CheckMacAddress(macAddress, userEntity.Id.ToString())) { this.ReturnStatusCode = StatusCode.ErrorMacAddress.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, macAddress, ipAddress, AppMessage.MSG0086); return(userInfo); } } } // 10. 只允许登录一次,需要检查是否自己重新登录了,或者自己扮演自己了 if ((UserInfo != null) && (!UserInfo.Id.Equals(userEntity.Id.ToString()))) { if (BaseSystemInfo.CheckOnLine) { if (userEntity.UserOnLine > 0) { this.ReturnStatusCode = StatusCode.ErrorOnLine.ToString(); BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0087); return(userInfo); } } } // 11. 密码是否正确(null 与空看成是相等的) if (!(string.IsNullOrEmpty(userEntity.UserPassword) && string.IsNullOrEmpty(password))) { bool userPasswordOK = true; // 用户密码是空的 if (string.IsNullOrEmpty(userEntity.UserPassword)) { // 但是输入了不为空的密码 if (!string.IsNullOrEmpty(password)) { userPasswordOK = false; } } else { // 用户的密码不为空,但是用户是输入了密码 if (string.IsNullOrEmpty(password)) { userPasswordOK = false; } else { // 再判断用户的密码与输入的是否相同 userPasswordOK = userEntity.UserPassword.Equals(password); } } // 用户的密码不相等 if (!userPasswordOK) { // 密码错误后 1:应该记录日志 BaseLogManager.Instance.Add(DbHelper, userEntity.Id.ToString(), userEntity.RealName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userEntity.RealName, ipAddress, AppMessage.MSG0088); // TODO: 密码错误后 2:看最近1个小时输入了几次错误了?24小时里。 // TODO: 密码错误后 3:若错误密码数量已经超过了指定的限制,那用户就需要被锁定1个小时。 // TODO: 密码错误后 4:同时需要处理返回值,是由于密码次数过多导致的被锁定,登录时也应该能读取这个状态比较,时间过期了,也应该进行处理一下状态。 // 密码强度检查,若是要有安全要求比较高的,返回的提醒消息要进行特殊处理,不能返回非常明确的提示信息。 if (BaseSystemInfo.CheckPasswordStrength) { this.ReturnStatusCode = StatusCode.ErrorLogOn.ToString(); } else { this.ReturnStatusCode = StatusCode.PasswordError.ToString(); } return(userInfo); } } // 09. 更新IP地址,更新MAC地址 if (!string.IsNullOrEmpty(ipAddress)) { this.SetProperty(userEntity.Id, new KeyValuePair <string, object>(BaseUserEntity.FieldIPAddress, ipAddress)); } if (!string.IsNullOrEmpty(macAddress)) { this.SetProperty(userEntity.Id, new KeyValuePair <string, object>(BaseUserEntity.FieldMACAddress, macAddress)); } // 可以正常登录了 this.ReturnStatusCode = StatusCode.OK.ToString(); // 13. 登录、重新登录、扮演时的在线状态进行更新 this.ChangeOnLine(userEntity.Id.ToString()); userInfo = this.ConvertToUserInfo(userEntity); // 获得员工的信息,这里员工的一些信息还是有错误,部门的主键啥的 if (userEntity.IsStaff == 1) { // BaseStaffManager staffManager = new BaseStaffManager(DbHelper, UserInfo); // 这里需要按 员工的用户ID来进行查找对应的员工-用户关系 // BaseStaffEntity staffEntity = new BaseStaffEntity(staffManager.GetDataTable(BaseStaffEntity.FieldUserId, userEntity.Id)); // if (staffEntity.Id > 0) // { // userInfo = staffManager.ConvertToUserInfo(staffEntity, userInfo); // } } userInfo.IPAddress = ipAddress; userInfo.MACAddress = macAddress; userInfo.Password = password; // 这里是判断用户是否为系统管理员的 userInfo.IsAdministrator = IsAdministrator(userInfo.Id); userInfo.StaffId = new BaseStaffManager(DbHelper).GetIdByUserId(userInfo.Id); // 数据找到了,就可以退出循环了) break; } } // 14. 记录系统访问日志 if (this.ReturnStatusCode == StatusCode.OK.ToString()) { BaseLogManager.Instance.Add(DbHelper, userEntity.Id.ToString(), userEntity.RealName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userEntity.RealName, ipAddress, AppMessage.BaseUserManager_LogOnSuccess); if (string.IsNullOrEmpty(userInfo.OpenId)) { createNewOpenId = true; } if (createNewOpenId) { userInfo.OpenId = this.UpdateVisitDate(userEntity.Id.ToString(), createNewOpenId); } else { this.UpdateVisitDate(userEntity.Id.ToString()); } } else { BaseLogManager.Instance.Add(DbHelper, userName, realName, "LogOn", AppMessage.BaseUserManager, "LogOn", AppMessage.BaseUserManager_LogOn, userName, ipAddress, AppMessage.MSG0090); } return(userInfo); }
/// <summary> /// 更新密码 /// </summary> /// <param name="oldPassword">原密码</param> /// <param name="newPassword">新密码</param> /// <param name="statusCode">返回状态码</param> /// <returns>影响行数</returns> public virtual int ChangePassword(string oldPassword, string newPassword, out string statusCode) { #if (DEBUG) int milliStart = Environment.TickCount; #endif int returnValue = 0; // 密码强度检查 if (BaseSystemInfo.CheckPasswordStrength) { if (String.IsNullOrEmpty(newPassword)) { statusCode = StatusCode.PasswordCanNotBeNull.ToString(); return(returnValue); } } // 加密密码 if (BaseSystemInfo.ServerEncryptPassword) { oldPassword = this.EncryptUserPassword(oldPassword); newPassword = this.EncryptUserPassword(newPassword); } // 判断输入原始密码是否正确 BaseUserEntity userEntity = new BaseUserEntity(); userEntity.GetSingle(this.GetDataTableById(UserInfo.Id)); if (userEntity.UserPassword == null) { userEntity.UserPassword = string.Empty; } // 密码错误 if (!userEntity.UserPassword.Equals(oldPassword)) { statusCode = StatusCode.OldPasswordError.ToString(); return(returnValue); } // 对比是否最近2次用过这个密码 if (BaseSystemInfo.CheckPasswordStrength) { int i = 0; BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo); DataTable dataTable = parameterManager.GetDataTableParameterCode("User", this.UserInfo.Id, "Password"); foreach (DataRow dataRow in dataTable.Rows) { string parameter = dataRow[BaseParameterEntity.FieldParameterContent].ToString(); if (parameter.Equals(newPassword)) { statusCode = StatusCode.PasswordCanNotBeRepeat.ToString(); return(returnValue); } i++; { // 判断连续2个密码就是可以了 if (i > 2) { break; } } } } // 更改密码,同时修改密码的修改日期 List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldUserPassword, newPassword)); // 注意日期格式,ACCESS中要用字符 parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldChangePasswordDate, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); returnValue = this.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, UserInfo.Id), parameters); if (returnValue == 1) { statusCode = StatusCode.ChangePasswordOK.ToString(); // 若是强类型密码检查,那就保存密码修改历史,防止最近2-3次的密码相同的功能实现。 if (BaseSystemInfo.CheckPasswordStrength) { BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo); BaseParameterEntity parameterEntity = new BaseParameterEntity(); parameterEntity.CategoryId = "User"; parameterEntity.ParameterId = this.UserInfo.Id; parameterEntity.ParameterCode = "Password"; parameterEntity.ParameterContent = newPassword; parameterEntity.DeletionStateCode = 0; parameterEntity.Enabled = true; parameterEntity.Worked = true; parameterManager.AddEntity(parameterEntity); } } else { // 数据可能被删除 statusCode = StatusCode.ErrorDeleted.ToString(); } // 写入调试信息 #if (DEBUG) int milliEnd = Environment.TickCount; Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " " + " BaseUserManager.ChangePassword(" + userEntity.Id + ")"); #endif return(returnValue); }