public ResultModel Confirm(UserModel user, int stockOutApplyId) { ResultModel result = new ResultModel(); try { DAL.StockDAL stockDAL = new StockDAL(); DAL.StockExclusiveDAL exclusiveDAL = new StockExclusiveDAL(); DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL(); Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); DAL.StockOutApplyDetailDAL detailDAL = new StockOutApplyDetailDAL(); DAL.StockLogDAL stockLogDAL = new StockLogDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证出库申请 result = outApplyDAL.Get(user, stockOutApplyId); if (result.ResultStatus != 0) return result; Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply; if (outApply == null || outApply.StockOutApplyId <= 0) { result.ResultStatus = -1; result.Message = "出库申请不存在"; return result; } //验证主申请 result = applyDAL.Get(user, outApply.ApplyId); if (result.ResultStatus != 0) return result; Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "主申请不存在"; return result; } //验证是否执行完成 result = stockoutapplyDAL.CheckStockOutCanConfirm(user, outApply.StockOutApplyId); if (result.ResultStatus != 0) return result; Common.StatusEnum status = (Common.StatusEnum)result.ReturnValue; //获取已生效出库申请明细 result = detailDAL.Load(user, outApply.StockOutApplyId); if (result.ResultStatus != 0) return result; List<Model.StockOutApplyDetail> details = result.ReturnValue as List<Model.StockOutApplyDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取出库申请明细失败"; return result; } //获取已生效排他明细 result = exclusiveDAL.Load(user, outApply.ApplyId); if (result.ResultStatus != 0) return result; List<Model.StockExclusive> exclusives = result.ReturnValue as List<Model.StockExclusive>; if (exclusives == null) { result.ResultStatus = -1; result.Message = "获取排他明细失败"; return result; } //主申请更新状态至已完成 if (status == StatusEnum.已完成) result = applyDAL.Confirm(user, apply); else if (status == StatusEnum.部分完成) result = applyDAL.PartiallyConfirm(user, apply); else { result.ResultStatus = -1; result.Message = "更新主申请状态失败"; return result; } if (result.ResultStatus != 0) return result; //出库申请明细更新状态至已完成 foreach (Model.StockOutApplyDetail detail in details) { //出库申请明细更新状态至已完成 result = detailDAL.Confirm(user, detail); if (result.ResultStatus != 0) return result; } //排他明细更新状态至已完成 foreach (Model.StockExclusive exc in exclusives) { result = exclusiveDAL.Confirm(user, exc); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel ContractOutCompleteStockOperate(UserModel user, int subId) { ResultModel result = new ResultModel(); try { NFMT.WareHouse.DAL.StockOutApplyDAL stockOutApplyDAL = new NFMT.WareHouse.DAL.StockOutApplyDAL(); NFMT.WareHouse.DAL.StockOutApplyDetailDAL stockOutApplyDetailDAL = new NFMT.WareHouse.DAL.StockOutApplyDetailDAL(); NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); NFMT.WareHouse.DAL.StockExclusiveDAL stockExclusiveDAL = new NFMT.WareHouse.DAL.StockExclusiveDAL(); //获取子合约出库申请 result = stockOutApplyDAL.LoadBySubId(user, subId); if (result.ResultStatus != 0) return result; List<NFMT.WareHouse.Model.StockOutApply> outApplies = result.ReturnValue as List<NFMT.WareHouse.Model.StockOutApply>; if (outApplies == null || outApplies.Count == 0) { result.ResultStatus = -1; result.Message = "获取出库申请失败"; return result; } foreach (NFMT.WareHouse.Model.StockOutApply outApply in outApplies) { //验证是否执行完成 result = stockOutApplyDAL.CheckStockOutCanConfirm(user, outApply.StockOutApplyId); if (result.ResultStatus != 0) return result; result = applyDAL.Get(user, outApply.ApplyId); if (result.ResultStatus != 0) return result; NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "获取主申请失败"; return result; } //主申请完成 result = applyDAL.Confirm(user, apply); if (result.ResultStatus != 0) return result; //获取出库申请明细 result = stockOutApplyDetailDAL.Load(user, outApply.StockOutApplyId); if (result.ResultStatus != 0) return result; List<NFMT.WareHouse.Model.StockOutApplyDetail> details = result.ReturnValue as List<NFMT.WareHouse.Model.StockOutApplyDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取出库申请明细失败"; return result; } foreach (NFMT.WareHouse.Model.StockOutApplyDetail detail in details) { //出库申请明细完成 result = stockOutApplyDetailDAL.Confirm(user, detail); if (result.ResultStatus != 0) return result; //获取排他明细 result = stockExclusiveDAL.Get(user, apply.ApplyId, outApply.StockOutApplyId, detail.DetailId); if (result.ResultStatus != 0) return result; NFMT.WareHouse.Model.StockExclusive stockExclusive = result.ReturnValue as NFMT.WareHouse.Model.StockExclusive; if (stockExclusive == null || stockExclusive.ExclusiveId <= 0) { result.ResultStatus = -1; result.Message = "获取排他明细失败"; return result; } //排他明细完成 result = stockExclusiveDAL.Confirm(user, stockExclusive); if (result.ResultStatus != 0) return result; } } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }