public ResultModel UpdateMain(UserModel user, Model.ReceivableAllot rec, ref List<Model.RecAllotDetail> details) { ResultModel result = new ResultModel(); //获取分配 result = this.receivableallotDAL.Get(user, rec.ReceivableAllotId); if (result.ResultStatus != 0) return result; Model.ReceivableAllot resultObj = result.ReturnValue as Model.ReceivableAllot; if (resultObj == null || resultObj.ReceivableAllotId <= 0) { result.ResultStatus = -1; result.Message = "分配不存在"; return result; } //更新分配 decimal sumBala = details.Sum(temp => temp.AllotBala); resultObj.AllotBala = sumBala; resultObj.AllotDesc = rec.AllotDesc; result = this.receivableallotDAL.Update(user, resultObj); if (result.ResultStatus != 0) return result; DAL.RecAllotDetailDAL detailDAL = new RecAllotDetailDAL(); //获取当前分配下所有有效明细 result = detailDAL.Load(user, resultObj.ReceivableAllotId); if (result.ResultStatus != 0) return result; List<Model.RecAllotDetail> resultDetails = result.ReturnValue as List<Model.RecAllotDetail>; if (resultDetails == null) { result.ResultStatus = -1; result.Message = "获取明细失败"; return result; } //作废所有有效明细 foreach (Model.RecAllotDetail d in resultDetails) { if (d.DetailStatus == StatusEnum.已生效) d.DetailStatus = StatusEnum.已录入; result = detailDAL.Invalid(user, d); if (result.ResultStatus != 0) return result; } foreach (Model.RecAllotDetail detail in details) { int detailId = 0; detail.DetailStatus = StatusEnum.已生效; detail.AllotId = resultObj.ReceivableAllotId; result = detailDAL.Insert(user, detail); if (result.ResultStatus != 0) return result; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId)) { result.ResultStatus = -1; result.Message = "收款分配明细更新失败"; return result; } detail.DetailId = detailId; } return result; }
public ResultModel Invalid(UserModel user, int allotId) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = receivableallotDAL.Get(user, allotId); if (result.ResultStatus != 0) return result; Model.ReceivableAllot receivableAllot = result.ReturnValue as Model.ReceivableAllot; if (receivableAllot == null || receivableAllot.ReceivableAllotId <= 0) { result.Message = "分配不存在"; result.ResultStatus = -1; return result; } result = receivableallotDAL.Invalid(user, receivableAllot); if (result.ResultStatus != 0) return result; DAL.RecAllotDetailDAL detailDAL = new RecAllotDetailDAL(); result = detailDAL.Load(user, receivableAllot.ReceivableAllotId); if (result.ResultStatus != 0) return result; List<Model.RecAllotDetail> details = result.ReturnValue as List<Model.RecAllotDetail>; if (details == null) { result.Message = "明细获取失败"; result.ResultStatus = -1; return result; } foreach (Model.RecAllotDetail d in details) { if (d.DetailStatus == StatusEnum.已生效) d.DetailStatus = StatusEnum.已录入; result = detailDAL.Invalid(user, d); 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; }