public Result <stockapply> Add(stockapply sto, List <stockapplydetails> stockapplydetails) { //模拟数据 sto.Appcircs = 3; sto.Appdept = ""; sto.Appperson = ""; sto.Enables = 0; sto.Appdeptid = ""; sto.Apppersonid = "1"; sto.Appauditing = "未复核"; sto.Appauditingperson = "1"; sto.Appmaker = "1"; sto.Stockapplyname = ""; sto.Safetyone = ""; sto.Safetytwo = ""; Result <stockapply> result = null; try { Affair.Whether <int, stockapply>(sto, (s) => { int i = 1; //修改采后编号 stockapplydetails.ForEach(d => { d.Safetyone = ""; d.Safetytwo = ""; d.Appid = sto.Appid; d.TockapplyDetails = sto.Appid + i.ToString("00"); i++; }); _StockapplyDAL.Add(sto, stockapplydetails); int count = _StockapplyDAL.SaveChanges(); int DbCount = 1 + stockapplydetails.Count; if (count != DbCount) { throw new Exception("请购单 和 请购详细新增条数不正确"); } return(count); }); result = new Result <stockapply>() { errorInfo = "新增采购成功", errorNo = 0, results = new ModelData <stockapply>() { data = sto } }; } catch (Exception ex) { result = new Result <stockapply>() { errorInfo = ex.Message, errorNo = -5, results = null }; } return(result); }
public Result <stockapply> Update(stockapply sto, List <stockapplydetails> stockapplydetails) { Result <stockapply> result = null; try { var entity = this._StockapplyDAL.GetModel(s => s.Appid == sto.Appid); if (entity == null) { throw new Exception($"{sto.Appid} 单号不存在"); } if (!string.IsNullOrEmpty(entity.Extend0)) { throw new Exception("请购单状态不可以更改"); } entity.Apptype = sto.Apptype; entity.Appcircs = sto.Appcircs; Affair.Whether <int, stockapply>(sto, (s) => { int i = 1; //修改采后编号 stockapplydetails.ForEach(d => { d.Safetyone = "测试修改"; d.Safetytwo = "测试修改"; d.Appid = sto.Appid; d.TockapplyDetails = sto.Appid + i.ToString("00"); i++; }); _StockapplyDAL.Update(entity.Appid, stockapplydetails); int count = _StockapplyDAL.SaveChanges(); return(count); }); result = new Result <stockapply>() { errorInfo = "修改采购请购单成功", errorNo = 0, results = new ModelData <stockapply>() { data = sto } }; } catch (Exception ex) { result = new Result <stockapply>() { errorInfo = ex.Message, errorNo = -5, results = null }; } return(result); }
/// <summary> /// 新增采购请购单 /// </summary> /// <param name="sto">采购订单</param> /// <param name="stockorderdetails">采购订单详细</param> /// <returns></returns> public Result <stockorder> Add(stockorder sto, List <stockorderdetails> stockorderdetails, int changeOrderType) { var result = new Result <stockorder>() { errorNo = 0, errorInfo = "新增采购订单成功", results = new ModelData <stockorder>() { data = sto } }; int id = 1; try { //修改新增固定值 sto.Checkstate = 2; switch (changeOrderType) { case 0: //普通新增采购订单 Affair.Whether <int, Result <stockorder> >(result, (obj) => { var stoder = this._StockorderDAL.GetModel(s => s.Stoid == sto.Stoid); if (stoder != null) { throw new Exception("单据号码 {sto.Stoid} 已经存在"); } //新增 采购订单 this._StockorderDAL.Add(sto); foreach (var item in stockorderdetails) { item.Sodlineid = sto.Stoid + id++.ToString("00"); item.Sodid = sto.Stoid; //新增采购订单详细 this._StockorderdetailsDAL.Add(item); } return(this.DAL.SaveChanges()); }); break; case 1: //转单采购请购单的 Affair.Whether <int, Result <stockorder> >(result, (obj) => { var stoder = this._StockorderDAL.GetModel(s => s.Stoid == sto.Stoid); if (stoder != null) { throw new Exception("单据号码 {sto.Stoid} 已经存在"); } //新增 采购订单 this._StockorderDAL.Add(sto); var appid = stockorderdetails[0].Sodorigin; var stockapply = this._StockapplyDAL.GetModel(s => s.Appid.Equals(appid)); if (stockapply == null) { throw new Exception($"转入的请购单:{appid} 不存在 "); } //获取请购详细 var stockapplyderdetails = this._StockapplydetailsDAL.ListModels(s => s.Appid == stockapply.Appid).ToList(); foreach (var item in stockapplyderdetails) { var orderderdetails = stockorderdetails.FirstOrDefault(s => s.Extend0 == item.TockapplyDetails); if (orderderdetails == null) { throw new Exception($"请购单中:{appid} 请购列表物料 {item.TockapplyDetails} 物料名称{item.Apdmateridlid} 缺少 "); } //大于请购单 直接未采购数量变成0 if (orderderdetails.Sodamount > item.Apdnotnum) { item.Apdnotnum = 0; } else { //修改未采购数量 item.Apdnotnum = item.Apdnotnum - orderderdetails.Sodamount; } orderderdetails.Sodlineid = sto.Stoid + id++.ToString("00"); orderderdetails.Sodid = sto.Stoid; //新增采购订单详细 this._StockorderdetailsDAL.Add(orderderdetails); } //判断是否全部采购完成 var count = stockapplyderdetails.Count(s => s.Apdnotnum <= 0); if (count == stockapplyderdetails.Count) { //修改采购请购单 stockapply.Appcircs = 1; stockapply.Extend0 = "不可修改"; } return(this._StockapplyDAL.SaveChanges()); }); break; } return(result); } catch (Exception ex) { return(new Result <stockorder>() { errorNo = -788, errorInfo = ex.Message, results = null }); } }