/// <summary> /// 创建部门集合 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entitys">部门集合</param> /// <returns></returns> public bool CreateCollection(ref ValidationErrors validationErrors, IQueryable <SysDepartment> entitys) { try { if (entitys != null) { int flag = 0, count = entitys.Count(); if (count > 0) { using (TransactionScope transactionScope = new TransactionScope()) { foreach (var entity in entitys) { if (Create(ref validationErrors, db, entity)) { flag++; } else { Transaction.Current.Rollback(); return(false); } } if (count == flag) { transactionScope.Complete(); return(true); } } } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 修改密码 /// </summary> /// <param name="personName">用户名</param> /// <param name="oldPassword">旧密码</param> /// <param name="newPassword">新密码</param> /// <returns>修改密码是否成功</returns> public bool ChangePassword(string personName, string oldPassword, string newPassword) { if (!string.IsNullOrWhiteSpace(personName) && !string.IsNullOrWhiteSpace(oldPassword) && !string.IsNullOrWhiteSpace(newPassword)) { try { using (SysEntities db = new SysEntities()) { var person = db.SysPerson.FirstOrDefault(p => (p.Name == personName) && (p.Password == oldPassword)); person.Password = newPassword; person.SurePassword = newPassword; db.SaveChanges(); return(true); } } catch (Exception ex) { ExceptionsHander.WriteExceptions(ex); } } return(false); }
/// <summary> /// 创建标准装置/计量标准器信息集合 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entitys">标准装置/计量标准器信息集合</param> /// <returns></returns> public bool EditCollection(ref ValidationErrors validationErrors, IQueryable <METERING_STANDARD_DEVICE> entitys) { if (entitys != null) { try { int flag = 0, count = entitys.Count(); if (count > 0) { //using (TransactionScope transactionScope = new TransactionScope()) { foreach (var entity in entitys) { if (Edit(ref validationErrors, db, entity)) { flag++; } else { //Transaction.Current.Rollback(); return(false); } } if (count == flag) { //transactionScope.Complete(); return(true); } } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } } return(false); }
/// <summary> /// 删除菜单集合 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="deleteCollection">主键的菜单</param> /// <returns></returns> public bool DeleteCollection(ref ValidationErrors validationErrors, string[] deleteCollection) { try { if (deleteCollection != null) { //using (TransactionScope transactionScope = new TransactionScope()) { repository.Delete(db, deleteCollection); if (deleteCollection.Length == repository.Save(db)) { db.SaveChanges(); //要先提交事务,然后修改编码,否则IsLeaf字段得不到更新 //在1.2版本中修改 //此方法由eastday(qq:76381028)提供 //删除后重置菜单编码 List <int> flags = new List <int>();//层级 GetMenus2(null, flags); db.SaveChanges(); //transactionScope.Complete(); return(true); } else { //Transaction.Current.Rollback(); } } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 创建一个人员 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个人员</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, SysPerson entity) { try { //using (TransactionScope transactionScope = new TransactionScope()) { if (Create(ref validationErrors, db, entity)) { //transactionScope.Complete(); return(true); } else { //Transaction.Current.Rollback(); } } } catch (Exception ex) { ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 创建客户_企业阶梯报价_待审核集合 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entitys">客户_企业阶梯报价_待审核集合</param> /// <returns></returns> public bool EditCollection(ref ValidationErrors validationErrors, IQueryable <CRM_CompanyLadderPrice_Audit> entitys) { try { if (entitys != null) { int count = entitys.Count(); if (count == 1) { return(this.Edit(ref validationErrors, entitys.FirstOrDefault())); } else if (count > 1) { using (TransactionScope transactionScope = new TransactionScope()) { repository.Edit(db, entitys); if (count == repository.Save(db)) { transactionScope.Complete(); return(true); } else { Transaction.Current.Rollback(); } } } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 创建数表单相含频率不确定度附表参考集合 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entitys">数表单相含频率不确定度附表参考集合</param> /// <returns></returns> public bool CreateCollection(ref ValidationErrors validationErrors, IQueryable <UNCERTAINTY2_HZ> entitys) { try { if (entitys != null) { int count = entitys.Count(); if (count == 1) { return(this.Create(ref validationErrors, entitys.FirstOrDefault())); } else if (count > 1) { //using (TransactionScope transactionScope = new TransactionScope()) { repository.Create(db, entitys); if (count == repository.Save(db)) { //transactionScope.Complete(); return(true); } else { //Transaction.Current.Rollback(); } } } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 编辑一个文档管理 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个文档管理</param> /// <returns>是否编辑成功</returns> public bool Edit(ref ValidationErrors validationErrors, SysDocument entity) { try { using (TransactionScope transactionScope = new TransactionScope()) { if (Edit(ref validationErrors, db, entity)) { transactionScope.Complete(); return(true); } else { Transaction.Current.Rollback(); } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 创建一个标准装置/计量标准器信息 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个标准装置/计量标准器信息</param> /// <returns></returns> public bool CreateX(ref ValidationErrors validationErrors, METERING_STANDARD_DEVICE entity) { try { ////using (TransactionScope transactionScope = new TransactionScope()) //{ if (CreateX(ref validationErrors, db, entity)) { ////transactionScope.Complete(); return(true); } else { //Transaction.Current.Rollback(); } //} } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 编辑一个预备方案 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个预备方案</param> /// <returns>是否编辑成功</returns> public bool Edit(ref ValidationErrors validationErrors, PREPARE_SCHEME entity) { try { ////using (TransactionScope transactionScope = new TransactionScope()) //{ if (Edit(ref validationErrors, db, entity)) { ////transactionScope.Complete(); return(true); } else { //Transaction.Current.Rollback(); } //} } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 设置一个部门 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个部门</param> /// <returns>是否设置成功</returns> public bool SetSysDepartment(ref ValidationErrors validationErrors, SysDocument entity) { bool bResult = false; int count = 0; using (TransactionScope transactionScope = new TransactionScope()) { try { SysDocument editEntity = repository.GetById(db, entity.Id); List <string> addSysDepartmentId = new List <string>(); List <string> deleteSysDepartmentId = new List <string>(); if (entity.SysDepartmentId != null) { addSysDepartmentId = entity.SysDepartmentId.Split(',').ToList(); } if (entity.SysDepartmentIdOld != null) { deleteSysDepartmentId = entity.SysDepartmentIdOld.Split(',').ToList(); } DataOfDiffrent.GetDiffrent(addSysDepartmentId, deleteSysDepartmentId, ref addSysDepartmentId, ref deleteSysDepartmentId); if (addSysDepartmentId != null && addSysDepartmentId.Count() > 0) { foreach (var item in addSysDepartmentId) { SysDepartment sys = new SysDepartment { Id = item }; db.SysDepartment.Attach(sys); editEntity.SysDepartment.Add(sys); count++; } } if (deleteSysDepartmentId != null && deleteSysDepartmentId.Count() > 0) { List <SysDepartment> listEntity = new List <SysDepartment>(); foreach (var item in deleteSysDepartmentId) { SysDepartment sys = new SysDepartment { Id = item }; listEntity.Add(sys); db.SysDepartment.Attach(sys); } foreach (SysDepartment item in listEntity) { editEntity.SysDepartment.Remove(item);//查询数据库 count++; } } if (count > 0 && count == repository.Save(db)) { transactionScope.Complete(); bResult = true; } else if (count == 0) { validationErrors.Add("数据没有改变"); } } catch (Exception ex) { Transaction.Current.Rollback(); ExceptionsHander.WriteExceptions(ex); validationErrors.Add("编辑出错了。原因" + ex.Message); } } return(bResult); }
/// <summary> /// 建立方案保存下一步 /// </summary> /// <param name="validationErrors"></param> /// <param name="entity"></param> /// <returns></returns> public bool EditInst(ref ValidationErrors validationErrors, PREPARE_SCHEME entity) { try { if (entity == null) { return(false); } List <string> addMETERING_STANDARD_DEVICEID = new List <string>(); List <string> deleteMETERING_STANDARD_DEVICEID = new List <string>(); PREPARE_SCHEME prepare = null; if (entity != null) { prepare = repository.GetById(entity.ID); } DataOfDiffrent.GetDiffrent(entity.METERING_STANDARD_DEVICEID.GetIdSort(), entity.METERING_STANDARD_DEVICEIDOld.GetIdSort(), ref addMETERING_STANDARD_DEVICEID, ref deleteMETERING_STANDARD_DEVICEID); PREPARE_SCHEME editEntity = repository.EditInst(db, entity); if (addMETERING_STANDARD_DEVICEID != null && addMETERING_STANDARD_DEVICEID.Count() > 0) { foreach (var item in addMETERING_STANDARD_DEVICEID) { STANDARDCHOICE sys = new STANDARDCHOICE { ID = Result.GetNewId(), PREPARE_SCHEMEID = entity.ID, METERING_STANDARD_DEVICEID = item.Split('*')[0], GROUPS = item.Split('*')[1], TYPE = item.Split('*')[2], NAMES = item.Split('*')[3], CREATEPERSON = entity.CREATEPERSON, CREATETIME = entity.CREATETIME }; //db.STANDARDCHOICE.Attach(sys); editEntity.STANDARDCHOICE.Add(sys); } } if (deleteMETERING_STANDARD_DEVICEID != null && deleteMETERING_STANDARD_DEVICEID.Count() > 0) { foreach (var item in deleteMETERING_STANDARD_DEVICEID) { string ID = item.Split('*')[0]; STANDARDCHOICE sys = new STANDARDCHOICE() { ID = ID }; db.STANDARDCHOICE.Attach(sys); editEntity.STANDARDCHOICE.Remove(sys); db.STANDARDCHOICE.Remove(sys); } } #region 更新了引用方案,需要删除原方案数据所录入的数据 if (prepare != null && !string.IsNullOrWhiteSpace(prepare.SCHEMEID) && prepare.SCHEMEID != entity.SCHEMEID) { List <QUALIFIED_UNQUALIFIED_TEST_ITE> deleteQUALIFIED_UNQUALIFIED_TEST_ITEList = (from f in db.QUALIFIED_UNQUALIFIED_TEST_ITE where f.PREPARE_SCHEMEID == entity.ID select f).ToList(); db.QUALIFIED_UNQUALIFIED_TEST_ITE.RemoveRange(deleteQUALIFIED_UNQUALIFIED_TEST_ITEList); } #endregion repository.Save(db); return(true); } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 创建一个预备方案 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个预备方案</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, PREPARE_SCHEME entity) { try { ////using (TransactionScope transactionScope = new TransactionScope()) //{ if (Create(ref validationErrors, db, entity)) { ////transactionScope.Complete(); return(true); } else { //Transaction.Current.Rollback(); } //} } catch (Exception ex) { validationErrors.Add(ex.Message + "@"); validationErrors.Add(ex.Source + "@"); validationErrors.Add(ex.StackTrace + "@"); validationErrors.Add(ex.HelpLink + "@"); validationErrors.Add(ex.HResult.ToString() + "@"); if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message)) { validationErrors.Add(ex.InnerException.Message); } if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Source)) { validationErrors.Add(ex.InnerException.Source); } if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.StackTrace)) { validationErrors.Add(ex.InnerException.StackTrace); } if (ex.InnerException != null && null != (ex.InnerException.TargetSite)) { validationErrors.Add(ex.InnerException.TargetSite.Name); } if (ex.Data != null) { validationErrors.Add(ex.Data.Count.ToString()); } if (ex.Data != null) { foreach (KeyValuePair <string, string> kvp in ex.Data.Keys) { validationErrors.Add(string.Format("姓名:{0},电影:{1}", kvp.Key, kvp.Value)); } } if (ex.TargetSite != null) { validationErrors.Add(ex.TargetSite.Name); } if (ex.TargetSite != null) { validationErrors.Add(ex.TargetSite.ReflectedType.ToString()); } if (ex.TargetSite != null) { validationErrors.Add(ex.TargetSite.Module.ToString()); } if (ex.TargetSite != null) { validationErrors.Add(ex.TargetSite.MethodImplementationFlags.ToString()); } if (ex.TargetSite != null) { validationErrors.Add(ex.TargetSite.MethodHandle.ToString()); } if (ex.TargetSite != null) { validationErrors.Add(ex.TargetSite.MetadataToken.ToString()); } ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 获取中间表里的社保费用(含正常和对比) /// </summary> /// <param name="costTable">主表Id</param> /// <param name="CRM_Company_ID">企业Id</param> /// <param name="yearMonth">年月</param> /// <param name="CreateUserID">创建人Id</param> /// <param name="CreateUserName">创建人姓名</param> /// <param name="BranchID">所属分支机构</param> /// <returns></returns> //public List<COST_CostTableInsurance> Get_List_COST_CostTableInsurance(int COST_CostTable_ID, int CRM_Company_ID, int yearMonth, int CreateUserID, string CreateUserName, int BranchID) //{ // IQueryable<EmployeeMiddle> employeeMiddle_List = null; // List<COST_CostTableInsurance> queryData = repository.Get_List_COST_CostTableInsurance(COST_CostTable_ID, CRM_Company_ID, yearMonth, CreateUserID, CreateUserName, BranchID, out employeeMiddle_List); // return queryData.ToList(); //} /// <summary> /// 获取正常服务费用 /// </summary> /// <param name="costTable">主表Id</param> /// <param name="CRM_Company_ID">企业Id</param> /// <param name="yearMonth">年月</param> /// <param name="CreateUserID">创建人Id</param> /// <param name="CreateUserName">创建人姓名</param> /// <param name="BranchID">所属分支机构</param> /// <returns></returns> //public List<COST_CostTableService> Get_List_COST_CostTableService(int COST_CostTable_ID, int CRM_Company_ID, int yearMonth, int CreateUserID, string CreateUserName, int BranchID) //{ // List<COST_CostTableService> queryData = repository.Get_List_COST_CostTableService(COST_CostTable_ID, CRM_Company_ID, yearMonth, CreateUserID, CreateUserName, BranchID); // return queryData.ToList(); //} /// <summary> /// 获取中间表里的其他费用和其他社保费用 /// </summary> /// <param name="costTable">主表Id</param> /// <param name="CRM_Company_ID">企业Id</param> /// <param name="yearMonth">年月</param> /// <param name="CreateUserID">创建人Id</param> /// <param name="CreateUserName">创建人姓名</param> /// <param name="BranchID">所属分支机构</param> /// <returns></returns> //public List<COST_CostTableOther> Get_List_COST_CostTableOther(int COST_CostTable_ID, int CRM_Company_ID, int yearMonth, int CreateUserID, string CreateUserName, int BranchID) //{ // IQueryable<EmployeeMiddle> employeeMiddle_List = null; // List<COST_CostTableOther> queryData = repository.Get_List_COST_CostTableOther(COST_CostTable_ID, CRM_Company_ID, yearMonth, CreateUserID, CreateUserName, BranchID, out employeeMiddle_List); // return queryData.ToList(); // } //生成费用 public bool Save(ref ValidationErrors validationErrors, COST_CostTable cOST_CostTable, int CRM_Company_ID, int yearMonth, int CreateUserID, string CreateUserName, int BranchID) { try { using (TransactionScope transactionScope = new TransactionScope()) { //1.主表数据 repository.Create(db, cOST_CostTable); db.SaveChanges(); //2.获取将要插入社保明细费用表中的数据 IQueryable <EmployeeMiddle> employeeMiddle_List_Z = null; var list_COST_CostTableInsurance = repository.Get_List_COST_CostTableInsurance(db, cOST_CostTable.ID, CRM_Company_ID, yearMonth, CreateUserID, CreateUserName, BranchID, out employeeMiddle_List_Z); //2.2改变中间表的使用记录 if (employeeMiddle_List_Z.Count() > 0) { var emlz = new EmployeeMiddleBLL(); foreach (var list_emlz in employeeMiddle_List_Z) { list_emlz.UseBetween = yearMonth; list_emlz.BillId = cOST_CostTable.ID.ToString(); emlz.Edit(db, list_emlz); } } //3.获取正常服务费用 var list_COST_CostTableService = repository.Get_List_COST_CostTableService(db, cOST_CostTable.ID, CRM_Company_ID, yearMonth, CreateUserID, CreateUserName, BranchID); //4.1获取其他费用和其他社保费用 IQueryable <EmployeeMiddle> employeeMiddle_List_B = null; var list_COST_CostTableOther = repository.Get_List_COST_CostTableOther(db, cOST_CostTable.ID, CRM_Company_ID, yearMonth, CreateUserID, CreateUserName, BranchID, out employeeMiddle_List_B); //4.2改变中间表的使用记录 if (employeeMiddle_List_B.Count() > 0) { var emlb = new EmployeeMiddleBLL(); foreach (var list_emlb in employeeMiddle_List_B) { list_emlb.UseBetween = yearMonth; list_emlb.BillId = cOST_CostTable.ID.ToString(); emlb.Edit(db, list_emlb); } } //5.创建社保费用明细数据(正常、补缴、上月对比) var ccti = new COST_CostTableInsuranceBLL(); foreach (var list_ccti in list_COST_CostTableInsurance) { ccti.Create(db, list_ccti); } //6.创建服务费用明细数据(正常、补缴、上月对比) var ccts = new COST_CostTableServiceBLL(); foreach (var list_ccts in list_COST_CostTableService) { ccts.Create(db, list_ccts); } //7.创建其他费用和其他社保费用 var ccto = new COST_CostTableOtherBLL(); foreach (var list_ccto in list_COST_CostTableOther) { ccto.Create(db, list_ccto); } //8.计算总费用 cOST_CostTable.ChargeCost = (decimal)(list_COST_CostTableInsurance.Sum(o => o.CompanyCost) + list_COST_CostTableInsurance.Sum(o => o.PersonCost) + list_COST_CostTableService.Sum(o => o.ChargeCost) + list_COST_CostTableOther.Sum(o => o.ChargeCost)); //9.最后保存 int count = 1 + list_COST_CostTableInsurance.Count() + list_COST_CostTableService.Count + list_COST_CostTableOther.Count + employeeMiddle_List_Z.Count() + employeeMiddle_List_B.Count();//先计算总数共多少个 int dbCount = db.SaveChanges(); if (count == dbCount) { transactionScope.Complete(); return(true); } else { Transaction.Current.Rollback(); } } } catch (Exception ex) { Delete(ref validationErrors, cOST_CostTable.ID); validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }