/// <summary> /// 创建一个费用_费用表 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个费用_费用表</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, COST_CostTable entity) { try { repository.Create(entity); return(true); } catch (Exception ex) { validationErrors.Add(ex.Message); 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); }