public IActionResult OnPost() { var remoteOrder = _pinhuaContext.生产单.FirstOrDefault(p => p.单号 == Order.M.单号); if (remoteOrder == null) { ModelState.AddModelError("", $"单号为 {Order.M.单号} 的生产订单不存在,操作失败。"); PartnerSelectList = _pinhuaContext.GetCustomerSelectList(); return(Page()); } // 对主表的缺失信息赋值,ExcelServerRcid,ExcelServerRtid,其他 Order.M.ExcelServerRcid = remoteOrder.ExcelServerRcid; Order.M.ExcelServerRtid = remoteOrder.ExcelServerRtid; Order.M.客户名 = _pinhuaContext.往来单位.FirstOrDefault(p => p.单位编号 == Order.M.客户号).单位名称; // 将修改标记到数据库中跟踪的数据,remoteOrder _mapper.Map <dto生产单M, 生产单>(Order.M, remoteOrder); // 删除明细表的老数据 var remoteDetails = _pinhuaContext.生产单d.Where(p => p.ExcelServerRcid == remoteOrder.ExcelServerRcid); _pinhuaContext.生产单d.RemoveRange(remoteDetails); // 删除旧的图片数据 var oldCasePic = _pinhuaContext.EsCasePic.Where(p => p.RcId == remoteOrder.ExcelServerRcid); _pinhuaContext.EsCasePic.RemoveRange(oldCasePic); // 对明细表的缺失信息赋值 Order.D.ForEach(i => { var newRecord = new 生产单d { ExcelServerRcid = remoteOrder.ExcelServerRcid, ExcelServerRtid = remoteOrder.ExcelServerRtid, 长 = i.长, 宽 = i.宽, 高 = i.高, 片数 = i.片数, 刻线要求 = i.刻线要求, 拉丝要求 = i.拉丝要求, 开槽要求 = i.开槽要求, 油漆要求 = i.油漆要求, 描述 = i.描述, 其他要求 = i.其他要求, 是否刻线 = i.是否刻线, 是否拉丝 = i.是否拉丝, 是否开槽 = i.是否开槽, 是否油漆 = i.是否油漆, 图片name = i.图片name, 图片type = i.图片type, }; if (!string.IsNullOrEmpty(i.图片base64)) // base64非空,插入图片 { var picNo = _pinhuaContext.GetNewPicNo(); var newBase64 = i.图片base64.Substring(i.图片base64.IndexOf(',') + 1); _pinhuaContext.EsCasePic.Add(new EsCasePic { RcId = remoteOrder.ExcelServerRcid, PicNo = picNo, Img = Convert.FromBase64String(newBase64), FileType = string.IsNullOrEmpty(i.图片name) ? ".jpg" : i.图片name.Substring(i.图片name.LastIndexOf(".")), RtfId = 2573, Sh = 2, R = 21, C = 51, IsNew = 0, Rng = null, SaveInto = 0, NfsfolderId = 0, Nfsfolder = "", PhyFileName = "", RelaFolder = "" }); newRecord.图片 = picNo; } _pinhuaContext.生产单d.Add(newRecord); }); // 保存修改 _pinhuaContext.SaveChanges(); return(RedirectToPage("Index")); }
public IActionResult OnPost() { if (ModelState.IsValid) { var Rcid = _pinhuaContext.GetNewRcId(); var rtId = "179.1"; var repCase = new EsRepCase { RcId = Rcid, RtId = rtId, LstFiller = 2, LstFillerName = "*****@*****.**", LstFillDate = DateTime.Now, //fillDate = DateTime.Now, //wiId = "", //state = 1, }; var main = _mapper.Map <dto生产单M, 生产单>(Order.M); main.单号 = _pinhuaContext.GetZkyAutoId(181); main.ExcelServerRcid = Rcid; main.ExcelServerRtid = rtId; main.客户名 = _pinhuaContext.往来单位.AsNoTracking().FirstOrDefault(p => p.单位编号 == Order.M.客户号).单位名称; if (Order?.D?.Count == 0) { ModelState.AddModelError("", "产品清单不可为空"); PartnerSelectList = _pinhuaContext.GetCustomerSelectList(); return(Page()); } foreach (var d in Order.D) { var newRecord = new 生产单d { ExcelServerRcid = Rcid, ExcelServerRtid = rtId, 长 = d.长, 宽 = d.宽, 高 = d.高, 片数 = d.片数, 刻线要求 = d.刻线要求, 拉丝要求 = d.拉丝要求, 开槽要求 = d.开槽要求, 油漆要求 = d.油漆要求, 描述 = d.描述, 其他要求 = d.其他要求, 是否刻线 = d.是否刻线, 是否拉丝 = d.是否拉丝, 是否开槽 = d.是否开槽, 是否油漆 = d.是否油漆, 图片name = d.图片name, 图片type = d.图片type, }; if (!string.IsNullOrEmpty(d.图片base64)) // base64非空,插入图片 { var picNo = _pinhuaContext.GetNewPicNo(); var newBase64 = d.图片base64.Substring(d.图片base64.IndexOf(',') + 1); _pinhuaContext.EsCasePic.Add(new EsCasePic { RcId = Rcid, PicNo = picNo, Img = Convert.FromBase64String(newBase64), FileType = string.IsNullOrEmpty(d.图片name) ? ".jpg" : d.图片name.Substring(d.图片name.LastIndexOf(".")), RtfId = 2573, Sh = 2, R = 21, C = 51, IsNew = 0, Rng = null, SaveInto = 0, NfsfolderId = 0, Nfsfolder = "", PhyFileName = "", RelaFolder = "" }); newRecord.图片 = picNo; } _pinhuaContext.生产单d.Add(newRecord); } _pinhuaContext.EsRepCase.Add(repCase); _pinhuaContext.生产单.Add(main); _pinhuaContext.SaveChanges(); return(RedirectToPage("Index")); } else { PartnerSelectList = _pinhuaContext.GetCustomerSelectList(); return(Page()); } }