/// <summary> /// 添加和新增修改 /// </summary> /// <param name="param">新增或修改的实体</param> /// <returns></returns> public WCFAddUpdateResult AddOrUpdate(HR_EmployeeResult param) { this.CheckSession(); WCFAddUpdateResult ret = new WCFAddUpdateResult(); try { int affect = 0; #region 判断 if (param.EmpCode.Trim() == "") { throw new WarnException("请输入人员编号!"); } if (param.EmpName.Trim() == "") { throw new WarnException("请输入人员名称!"); } if (param.OrgID == 0) { throw new WarnException("请选择所属机构!"); } if (param.DeptID == 0) { throw new WarnException("请选择所属部门!"); } #endregion #region 判断重复 WhereClip whereChk = HR_Employee._.EmpCode == param.EmpCode; if (param.EmpID > 0) { whereChk = whereChk && HR_Employee._.EmpID != param.EmpID; } int chkNum = this.Count <HR_EmployeeResult>(whereChk); if (chkNum > 0) { throw new WarnException("存在重复的人员编号!"); } #endregion #region 系统默认值 if (param.EmpID != 0) { WhereClip where = HR_Employee._.EmpGuid == param.EmpGuid; affect = this.Update <HR_EmployeeResult>(param, where); } else { param.EmpGuid = Guid.NewGuid(); param.GCompanyID = this.SessionInfo.CompanyID; param.IsDeleted = false; affect = this.Insert <HR_EmployeeResult>(param); param = this.Select <HR_EmployeeResult>(new List <Field>() { HR_Employee._.EmpID }, HR_Employee._.EmpGuid == param.EmpGuid); } #region 保存帐户登录信息 SYS_UserAccount userAcct = new SYS_UserAccount(); userAcct = this.Select <SYS_UserAccount>(SYS_UserAccount._.EmpID == param.EmpID && SYS_UserAccount._.IsDeleted == false); if (userAcct == null) { userAcct = new SYS_UserAccount(); } userAcct.Account = param.EmpCode; userAcct.EmpID = param.EmpID; userAcct.NeedValidate = param.NeedValidate; userAcct.IsActive = param.IsActive; if (param.Password.ToStringHasNull().Trim() != "") { userAcct.PWD = StringExt.MD5(param.Password); } if (userAcct.UserID.ToInt32() <= 0) { userAcct.GCompanyID = this.SessionInfo.CompanyID; userAcct.UserGUID = Guid.NewGuid(); userAcct.CreatedTime = DateTime.Now; userAcct.CreatedByID = this.SessionInfo.UserID; userAcct.CreatedByName = this.SessionInfo.UserName; userAcct.IsDeleted = false; this.Insert <SYS_UserAccount>(userAcct); } else { this.Update <SYS_UserAccount>(userAcct, SYS_UserAccount._.EmpID == param.EmpID && SYS_UserAccount._.IsDeleted == false); } #endregion #region 设置返回值 ret.Key = param.EmpID; ret.KeyGuid = param.EmpGuid; #endregion #endregion } catch (WarnException exp) { throw exp; } catch (System.Exception exp) { LogInfoBLL.WriteLog(this.SessionInfo, exp); throw exp; } return(ret); }
public SYS_UserAccountResult UserLogin(SYS_UserAccountParam param) { var result = new SYS_UserAccountResult(); try { #region 用户帐号判定 param.Account.ThrowIfNullOfEmpty("请指定用户名!"); param.CompanyName.ThrowIfNullOfEmpty("请指定公司名称!"); param.PWD.ThrowIfNullOfEmpty("请指定登录密码!"); #endregion #region 验证公司 //正式版验证时需要排除平台用户相关的公司 WhereClip coInfoWhereClip = SYS_CompanyInfo._.CompanyName == param.CompanyName && SYS_CompanyInfo._.IsActive != (int)ZNLCRM.Utility.CommonEnum.IsActive.Deleted; if (!string.IsNullOrEmpty(param.PartnerCode)) { coInfoWhereClip = coInfoWhereClip && SYS_CompanyInfo._.PartnerCode == param.PartnerCode; } else { coInfoWhereClip = coInfoWhereClip && SYS_CompanyInfo._.PartnerCode.IsNull(); } SYS_CompanyInfo coInfo = Select <SYS_CompanyInfo>(coInfoWhereClip); coInfo.ThrowIfNull("未找到公司帐户信息!"); SYS_UserAccount userAccount = Select <SYS_UserAccount>( SYS_UserAccount._.GCompanyID == coInfo.CompanyID && SYS_UserAccount._.Account == param.Account && SYS_UserAccount._.IsActive != (int)ZNLCRM.Utility.CommonEnum.IsActive.Deleted && SYS_UserAccount._.IsDeleted == false ); userAccount.ThrowIfNull("未找到公司用户信息!"); userAccount.IsActive.ThrowIfEqual( (int?)ZNLCRM.Utility.CommonEnum.IsActive.Disabled, "当前用户已被禁用!" ); HR_Employee userEmpInfo = Select <HR_Employee>( HR_Employee._.GCompanyID == coInfo.CompanyID && HR_Employee._.EmpCode == param.Account && HR_Employee._.IsActive != (int)ZNLCRM.Utility.CommonEnum.IsActive.Deleted && HR_Employee._.IsDeleted == false ); userEmpInfo.ThrowIfNull("未找到公司用户信息!"); userEmpInfo.IsActive.ThrowIfEqual( (int?)ZNLCRM.Utility.CommonEnum.IsActive.Disabled, "当前用户已被禁用!" ); bool isMater = false; userEmpInfo.EmpStatus.ThrowIfEqual(3, "当前用户状态已离职!"); //子帐号需要做验证逻辑判断 if (!isMater) { if (userAccount.NeedValidate.ToBooleanHasNull() && !string.IsNullOrEmpty(userAccount.MacAddress.ToStringHasNull()) && !string.IsNullOrEmpty(userAccount.HardDiskSN.ToStringHasNull())) { if (userAccount.MacAddress.ToStringHasNull().Trim().ToLower() != param.MacAddress.ToStringHasNull().Trim().ToLower() || userAccount.HardDiskSN.ToStringHasNull().Trim().ToLower() != param.HardSN.ToStringHasNull().Trim().ToLower()) { throw new WarnException("您不能在本机登录!"); } } if (!string.IsNullOrEmpty(userAccount.UseTimeBegin.ToStringHasNull()) && !string.IsNullOrEmpty(userAccount.UseTimeOver.ToStringHasNull())) { DateTime start = (DateTime.Now.ToString("yyyy-MM-dd") + " " + userAccount.UseTimeBegin).ToDateTime(); DateTime end = (DateTime.Now.ToString("yyyy-MM-dd") + " " + userAccount.UseTimeOver).ToDateTime(); if (!(DateTime.Now >= start && DateTime.Now <= end)) { throw new WarnException("您不能在非工作时间(" + userAccount.UseTimeBegin + " - " + userAccount.UseTimeOver + ")登录!"); } } } #endregion #region 判断登录用户数 SYS_SignLogInfoBLL signBll = new SYS_SignLogInfoBLL(); signBll.SessionInfo = this.SessionInfo; signBll.CheckLogUserRuler( userAccount.GCompanyID, userEmpInfo.EmpID, userEmpInfo.EmpGuid, userEmpInfo.EmpName, SessionInfo.ClientIP, SessionInfo.AdapterAddress); #endregion #region 修改登录统计信息 this.Update <SYS_UserAccount>(new Field[] { SYS_UserAccount._.SignInTimes, SYS_UserAccount._.LastSignIP, SYS_UserAccount._.LastSignTime, SYS_UserAccount._.MacAddress, SYS_UserAccount._.HardDiskSN }, new object[] { userAccount.SignInTimes.GetValueOrDefault(0) + 1, param.ClientIP, DateTime.Now, param.MacAddress, param.HardSN }, SYS_UserAccount._.UserID == userAccount.UserID); #endregion #region 修改登录session SYS_SignLogInfoResult signParam = new SYS_SignLogInfoResult(); signBll.SessionInfo = this.SessionInfo; signParam.GCompanyID = userAccount.GCompanyID; signParam.UserID = userAccount.UserID; signParam.UserName = userEmpInfo.EmpName; signParam.UserAdapter = this.SessionInfo.AdapterAddress; signParam.UserIP = this.SessionInfo.ClientIP; signBll.UpdateUserOnline(signParam); #endregion #region 返回值 result.GCompanyID = userAccount.GCompanyID; result.UserID = userAccount.UserID; result.EmpName = userEmpInfo.EmpName; result.UserGUID = userAccount.UserGUID; result.Account = userAccount.Account; result.SaleCurrency = userEmpInfo.DefaultSaleCurreny; result.BuyCurrency = userEmpInfo.DefaultBuyCurreny; result.OrgID = userEmpInfo.OrgID; result.DeptID = userEmpInfo.DeptID; result.LoginSucceed = 1; #endregion #region 获取部门名称和机构名称 HR_OrgBLL orgBll = new HR_OrgBLL(); HR_DepartmentBLL deptBll = new HR_DepartmentBLL(); orgBll.SessionInfo = this.SessionInfo; deptBll.SessionInfo = this.SessionInfo; result.OrgName = orgBll.GetOrgName(result.OrgID.ToInt32()); result.DeptName = deptBll.GetDeptName(result.DeptID.ToInt32()); #endregion } catch (Exception ex) { throw ex; } return(result); }