/// <summary> /// 创建消费记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(RBCC)) //判断成本中心是否已经选择 { throw new Exception("请选择成本中心!"); } else { RBInputDto RB = new RBInputDto(); //定义一个新的报销单 RB.CC_ID = RBCC; //成本中心编号 RB.RB_Note = this.TxtNote.Text; //报销单备注 //将选中的消费记录行项添加到报销单中 foreach (ListViewRow Row in listRBRowData.Rows) { frmRBCreateLayout layout = Row.Control as frmRBCreateLayout; //如果当前行项消费记录被选中 if (layout.checkNum() == 1) { //把选中行的消费记录行项的数据添加到报销单中 int RID = layout.getID(); RB_RowsDto RBRow = AutofacConfig.rBService.GetRowByRowID(RID); RB_RowsInputDto NewRBRow = new RB_RowsInputDto(); NewRBRow.R_ID = RBRow.R_ID; //消费记录编号 NewRBRow.R_TypeID = RBRow.R_TypeID; //消费类型编号 NewRBRow.R_Amount = RBRow.R_Amount; //消费记录金额 NewRBRow.R_Note = RBRow.R_Note; //消费记录日期 NewRBRow.R_ConsumeDate = RBRow.R_ConsumeDate; //消费日期 RB.RB_Rows.Add(NewRBRow); } } RB.RB_CreateUser = Client.Session["U_ID"].ToString(); //创建用户 ReturnInfo r = AutofacConfig.rBService.CreateRB(RB); if (r.IsSuccess == true) { //如果数据库添加报销记录成功 this.ShowResult = ShowResult.Yes; this.Close(); Toast("报销提交成功!"); } else { throw new Exception(r.ErrorInfo); } } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 保存报销编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Press(object sender, EventArgs e) { try { RBInputDto ReimBur = new RBInputDto(); ReimBur.RB_Rows = new List <RB_RowsInputDto>(); ReimBur.RB_ID = this.lblRBNO.Text; //报销单编号 ReimBur.CC_ID = RBCC; //成本中心编号 ReimBur.RB_Note = this.TxtNote.Text; //备注 //消费记录行项更改 foreach (ListViewRow Row in listRBRowData.Rows) { //判断消费记录是否选中 frmConsumption1Layout layout = Row.Control as frmConsumption1Layout; if (layout.checkNum() == 1) { //把选中行的Row的数据添加到报销单中 int RID = layout.getID(); RB_RowsDto RBRow = AutofacConfig.rBService.GetRowByRowID(RID); RB_RowsInputDto NewRBRow = new RB_RowsInputDto(); NewRBRow.R_ID = RBRow.R_ID; NewRBRow.R_TypeID = RBRow.R_TypeID; NewRBRow.R_Amount = RBRow.R_Amount; NewRBRow.R_Note = RBRow.R_Note; NewRBRow.R_ConsumeDate = RBRow.R_ConsumeDate; ReimBur.RB_Rows.Add(NewRBRow); } } ReturnInfo r = AutofacConfig.rBService.UpdateRB(ReimBur); //将报销记录更新到数据库中 if (r.IsSuccess == true) { this.ShowResult = ShowResult.Yes; this.Close(); Toast("报销提交成功!"); } else { throw new Exception(r.ErrorInfo); } } catch (Exception ex) { Toast(ex.Message); } }
/// <summary> /// 报销单验证 /// </summary> /// <param name="entity">报销单对象</param> public static string ValidateRBInputDto(RBInputDto entity) { //基础验证 StringBuilder sb = BasicValidate <RBInputDto>(entity); //额外验证(Rows中的每个的类型,金额,事由均不能为空,list必须有值,审批人在用户列表里) if (entity.RB_Rows.Count == 0) { sb.Append("报销明细至少需要1条;"); } else { foreach (RB_RowsInputDto row in entity.RB_Rows) { sb.Append(BasicValidate <RB_RowsInputDto>(row)); } } return(sb.ToString()); }
/// <summary> /// 更新报销单 /// </summary> /// <param name="entity">报销单对象</param> public ReturnInfo UpdateRB(RBInputDto entity) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); Reimbursement rb = _reimbursementRepository.GetByID(entity.RB_ID).FirstOrDefault(); if (rb != null) { Reimbursement rb2 = _reimbursementRepository.GetByID(entity.RB_ID).AsNoTracking().FirstOrDefault(); if (rb2.RB_Status >= 1) { RInfo.IsSuccess = false; RInfo.ErrorInfo = "只有新建和已拒绝的才能修改."; return(RInfo); } else { string ValidateInfo = Helper.ValidateRBInputDto(entity); sb.Append(ValidateInfo); if (string.IsNullOrEmpty(ValidateInfo)) { try { rb.RB_UpdateDate = DateTime.Now; List <int> OldIDs = _rbrowsRepository.GetByRBID(entity.RB_ID).Select(o => o.R_ID).ToList(); List <int> NewIDs = new List <int>(); decimal Total = 0; foreach (RB_RowsInputDto row in entity.RB_Rows) { NewIDs.Add(row.R_ID); Total += row.R_Amount; } rb.RB_TotalAmount = Total; CostCenter cc = _costCenterRepository.GetByID(entity.CC_ID).AsNoTracking().FirstOrDefault(); if (cc != null) { rb.RB_LiableMan = cc.CC_LiableMan; } CC_Type_Template ctp = _cc_Type_TemplateRepository.GetByID(cc.CC_TemplateID).AsNoTracking().FirstOrDefault(); if (ctp != null) { rb.RB_AEACheckers = ctp.CC_TT_AEACheckers; rb.RB_FinancialCheckers = ctp.CC_TT_FinancialCheckers; } if (entity.CC_ID != null) { rb.CC_ID = entity.CC_ID; } rb.RB_Img1 = entity.RB_Img1; rb.RB_Img2 = entity.RB_Img2; rb.RB_Img3 = entity.RB_Img3; rb.RB_Img4 = entity.RB_Img4; rb.RB_Img5 = entity.RB_Img5; rb.RB_Img6 = entity.RB_Img6; rb.RB_Img7 = entity.RB_Img7; rb.RB_Img8 = entity.RB_Img8; rb.RB_Img9 = entity.RB_Img9; if (entity.RB_Note != null) { rb.RB_Note = entity.RB_Note; } //rb.RB_RejectionReason = entity.RB_RejectionReason; rb.RB_Status = (int)RB_Status.新建; rb.RB_UpdateDate = DateTime.Now; if (entity.RB_UpdateUser != null) { rb.RB_UpdateUser = entity.RB_UpdateUser; } rb.RB_CurrantCheck = ""; _unitOfWork.RegisterDirty(rb); List <int> Add = NewIDs.Except(OldIDs).ToList(); List <int> Delete = OldIDs.Except(NewIDs).ToList(); foreach (int addID in Add) { RB_Rows row = _rbrowsRepository.GetByID(addID).FirstOrDefault(); row.RB_ID = entity.RB_ID; _unitOfWork.RegisterDirty(row); } foreach (int deleteID in Delete) { RB_Rows row = _rbrowsRepository.GetByID(deleteID).FirstOrDefault(); row.RB_ID = null; _unitOfWork.RegisterDirty(row); } bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } catch (Exception ex) { _unitOfWork.RegisterClean(rb); _unitOfWork.Rollback(); sb.Append(ex.Message); RInfo.IsSuccess = false; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } } else { RInfo.IsSuccess = false; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } } } else { RInfo.IsSuccess = false; RInfo.ErrorInfo = "查找不到该ID的报销单!"; return(RInfo); } }
/// <summary> /// 添加报销单 /// </summary> /// <param name="entity">报销单对象</param> public ReturnInfo CreateRB(RBInputDto entity) { ReturnInfo RInfo = new ReturnInfo(); StringBuilder sb = new StringBuilder(); string MaxID = _reimbursementRepository.GetMaxID(); string NowID = Helper.GenerateID("RB", MaxID); entity.RB_ID = NowID; string ValidateInfo = Helper.ValidateRBInputDto(entity); sb.Append(ValidateInfo); if (string.IsNullOrEmpty(ValidateInfo)) { try { Reimbursement rb = Mapper.Map <RBInputDto, Reimbursement>(entity); rb.RB_CreateDate = DateTime.Now; rb.RB_UpdateDate = DateTime.Now; rb.RB_AEADate = DateTime.Now; rb.RB_FinDate = DateTime.Now; rb.RB_LiableDate = DateTime.Now; rb.RB_Status = (int)RB_Status.新建; rb.RB_CurrantCheck = ""; if (!string.IsNullOrEmpty(entity.CC_ID)) { CCDetailDto cc = Mapper.Map <CostCenter, CCDetailDto> (_costCenterRepository.GetByID(entity.CC_ID).AsNoTracking().FirstOrDefault()); rb.RB_LiableMan = cc.CC_LiableMan; if (!string.IsNullOrEmpty(cc.CC_TemplateID)) { CC_Type_TemplateDto ctp = Mapper.Map <CC_Type_Template, CC_Type_TemplateDto>(_cc_Type_TemplateRepository.GetByID(cc.CC_TemplateID).AsNoTracking().FirstOrDefault()); rb.RB_AEACheckers = ctp.CC_TT_AEACheckers; rb.RB_FinancialCheckers = ctp.CC_TT_FinancialCheckers; } } decimal Total = 0; string MaxID2 = _reimbursementRepository.GetMaxID(); string NowID2 = Helper.GenerateID("RB", MaxID2); rb.RB_ID = NowID2; foreach (RB_RowsInputDto row in entity.RB_Rows) { RB_Rows r = _rbrowsRepository.GetByID(row.R_ID).FirstOrDefault(); r.RB_ID = NowID2; _unitOfWork.RegisterDirty(r); Total += row.R_Amount; } rb.RB_TotalAmount = Total; _unitOfWork.RegisterNew(rb); bool result = _unitOfWork.Commit(); RInfo.IsSuccess = result; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } catch (Exception ex) { _unitOfWork.Rollback(); sb.Append(ex.Message); RInfo.IsSuccess = false; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } } else { RInfo.IsSuccess = false; RInfo.ErrorInfo = sb.ToString(); return(RInfo); } }