public ResultModel CreateSIApply(UserModel user, NFMT.Operate.Model.Apply apply, List<Model.InvoiceApplySIDetail> details, bool isSubmitAudit) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); result = applyDAL.Insert(user, apply); if (result.ResultStatus != 0) return result; int applyId = (int)result.ReturnValue; decimal totalBala = 0; NFMT.Operate.DAL.InvoiceDAL invoiceDAL = new Operate.DAL.InvoiceDAL(); foreach (Model.InvoiceApplySIDetail detail in details) { result = invoiceDAL.Get(user, detail.InvoiceId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Invoice invoice = result.ReturnValue as NFMT.Operate.Model.Invoice; totalBala += invoice.InvoiceBala; } result = invoiceapplyDAL.Insert(user, new Model.InvoiceApply() { ApplyId = applyId, TotalBala = totalBala }); if (result.ResultStatus != 0) return result; int invoiceApplyId = (int)result.ReturnValue; DAL.InvoiceApplySIDetailDAL invoiceApplySIDetailDAL = new InvoiceApplySIDetailDAL(); foreach (Model.InvoiceApplySIDetail detail in details) { detail.InvoiceApplyId = invoiceApplyId; detail.ApplyId = applyId; result = invoiceApplySIDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } if (isSubmitAudit) { apply.ApplyId = applyId; NFMT.WorkFlow.AutoSubmit submit = new WorkFlow.AutoSubmit(); NFMT.WorkFlow.ITaskProvider taskProvider = new NFMT.Invoice.TaskProvider.InvoiceApplyTaskProvider(); result = submit.Submit(user, apply, taskProvider, WorkFlow.MasterEnum.发票申请审核); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }
public ResultModel UpdateSIApply(UserModel user, NFMT.Operate.Model.Apply apply, Model.InvoiceApply invoiceApply, List<Model.InvoiceApplySIDetail> details) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); result = applyDAL.Get(user, apply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply applyRes = result.ReturnValue as NFMT.Operate.Model.Apply; if (applyRes == null) { result.ResultStatus = -1; result.Message = "获取申请信息失败"; return result; } applyRes.ApplyCorp = apply.ApplyCorp; applyRes.ApplyDept = apply.ApplyDept; applyRes.EmpId = user.EmpId; applyRes.ApplyTime = DateTime.Now; applyRes.ApplyDesc = apply.ApplyDesc; result = applyDAL.Update(user, applyRes); if (result.ResultStatus != 0) return result; decimal totalBala = 0; NFMT.Operate.DAL.InvoiceDAL invoiceDAL = new Operate.DAL.InvoiceDAL(); foreach (Model.InvoiceApplySIDetail detail in details) { result = invoiceDAL.Get(user, detail.InvoiceId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Invoice invoice = result.ReturnValue as NFMT.Operate.Model.Invoice; totalBala += invoice.InvoiceBala; } invoiceApply.TotalBala = totalBala; result = invoiceapplyDAL.Update(user, invoiceApply); if (result.ResultStatus != 0) return result; DAL.InvoiceApplySIDetailDAL invoiceApplySIDetailDAL = new InvoiceApplySIDetailDAL(); result = invoiceApplySIDetailDAL.InvalidAll(user, invoiceApply.InvoiceApplyId); if (result.ResultStatus != 0) return result; foreach (Model.InvoiceApplySIDetail detail in details) { detail.InvoiceApplyId = invoiceApply.InvoiceApplyId; detail.ApplyId = apply.ApplyId; result = invoiceApplySIDetailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } finally { if (result.ResultStatus != 0) this.Log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (this.Log.IsInfoEnabled) this.Log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }