public TableData Query(MbomHeader entity) { var result = new TableData(); var data = _app.Find(EntityToExpression <MbomHeader> .GetExpressions(entity)); GetData(data, result); result.count = data.Count(); return(result); }
public string Upd(MbomHeader Table_entity) { try { _app.Upd(Table_entity); } catch (Exception ex) { Result.Status = false; Result.Message = ex.Message; } return(JsonHelper.Instance.Serialize(Result)); }
public string GetTemplate() { var result = new TableData(); List <MbomHeader> listMbomHeader = new List <MbomHeader>(); MbomHeader entity = _app.FindSingle(u => u.Id > 0); if (entity != null) { listMbomHeader.Add(entity); } else { listMbomHeader.Add(new MbomHeader()); } result.data = listMbomHeader; result.count = listMbomHeader.Count; return(JsonHelper.Instance.Serialize(result)); }
public Response ImportIn(IFormFile excelfile) { Response result = new Infrastructure.Response(); List <MbomHeader> exp = imp.ConvertToModel <MbomHeader>(excelfile); string sErrorMsg = ""; for (int i = 0; i < exp.Count; i++) { try { MbomHeader e = exp[i]; e.Id = null; _app.Add(e); } catch (Exception ex) { sErrorMsg += "第" + (i + 2) + "行:" + ex.Message + "<br>"; result.Message = sErrorMsg; break; } } if (sErrorMsg.Equals(string.Empty)) { if (exp.Count == 0) { sErrorMsg += "没有发现有效数据, 请确定模板是否正确, 或是否有填充数据!"; result.Message = sErrorMsg; } else { result.Message = "导入完成"; } } else { result.Status = false; result.Message = result.Message; } return(result); }
public string Load(PageReq pageRequest, MbomHeader entity) { return(JsonHelper.Instance.Serialize(_app.Load(pageRequest, entity))); }
public string Export(MbomHeader entity) { return(JsonHelper.Instance.Serialize(_app.ExportData(entity))); }
public void Upd(MbomHeader entity) { entity.ProductId = _unitWork.FindSingle <ProductHeader>(u => u.Code.Equals(entity.ProductCode)).Id; _app.Update(entity); }
public TableData Load(PageReq pageRequest, MbomHeader entity) { return(_app.Load(pageRequest, entity)); }
public TableData ExportData(MbomHeader entity) { return(_app.ExportData(entity)); }
public Response InsertMBom(InterfaceMBomModel interfacembom) { Response Response = new Response(); if (!CheckLogin()) { Response.Code = 500; Response.Status = false; Response.Message = "请先登录!"; return(Response); } try { #region 保存生产MBOM接口主表 InterfaceMbomHeader headdata = _context.Set <InterfaceMbomHeader>().AsQueryable().Where(u => u.ProductCode.Equals(interfacembom.interfaceMbomHeader.ProductCode)).SingleOrDefault(); interfacembom.interfaceMbomHeader.Id = headdata?.Id; if (_unitWork.IsExist <ProductHeader>(u => u.Code.Equals(interfacembom.interfaceMbomHeader.ProductCode))) { interfacembom.interfaceMbomHeader.ProductId = _unitWork.FindSingle <ProductHeader>(u => u.Code.Equals(interfacembom.interfaceMbomHeader.ProductCode)).Id; } else { interfacembom.interfaceMbomHeader.ProductId = 0; } if (interfacembom.interfaceMbomHeader.Id == null) { if (interfacembom.interfaceMbomHeader.CreateBy == null) { interfacembom.interfaceMbomHeader.CreateBy = "system"; interfacembom.interfaceMbomHeader.CreateTime = DateTime.Now; } _unitWork.Add(interfacembom.interfaceMbomHeader); } else { if (interfacembom.interfaceMbomHeader.UpdateBy == null) { interfacembom.interfaceMbomHeader.UpdateBy = "system"; interfacembom.interfaceMbomHeader.UpdateTime = DateTime.Now; } _unitWork.UpdateByTracking(interfacembom.interfaceMbomHeader); } #endregion #region 保存生产MBOM主表 MbomHeader mbomHeader = _unitWork.FindSingle <MbomHeader>(u => u.ProductCode.Equals(interfacembom.interfaceMbomHeader.ProductCode)); if (mbomHeader == null) { mbomHeader = new MbomHeader(); } mbomHeader.ProductCode = interfacembom.interfaceMbomHeader.ProductCode; if (_unitWork.IsExist <ProductHeader>(u => u.Code.Equals(interfacembom.interfaceMbomHeader.ProductCode))) { mbomHeader.ProductId = _unitWork.FindSingle <ProductHeader>(u => u.Code.Equals(interfacembom.interfaceMbomHeader.ProductCode)).Id; } else { mbomHeader.ProductId = 0; } mbomHeader.DrawingNumber = interfacembom.interfaceMbomHeader.DrawingNumber; mbomHeader.Version = interfacembom.interfaceMbomHeader.Version; if (interfacembom.interfaceMbomHeader.LineId == null) { var workship = _unitWork.FindSingle <ProductHeader>(u => u.Code == interfacembom.interfaceMbomHeader.ProductCode).WorkShop; mbomHeader.LineId = _unitWork.FindSingle <Line>(u => u.WorkshopCode.Equals(workship)).Id; } else { mbomHeader.LineId = interfacembom.interfaceMbomHeader.LineId; } mbomHeader.Verifyer = interfacembom.interfaceMbomHeader.Verifyer; mbomHeader.CreateTime = interfacembom.interfaceMbomHeader.CreateTime; mbomHeader.CreateBy = interfacembom.interfaceMbomHeader.CreateBy; mbomHeader.UpdateTime = interfacembom.interfaceMbomHeader.UpdateTime; mbomHeader.UpdateBy = interfacembom.interfaceMbomHeader.UpdateBy; if (mbomHeader.Id == null) { if (mbomHeader.CreateBy == null) { mbomHeader.CreateBy = "system"; mbomHeader.CreateTime = DateTime.Now; } _unitWork.Add(mbomHeader); } else { if (mbomHeader.UpdateBy == null) { mbomHeader.UpdateBy = "system"; mbomHeader.UpdateTime = DateTime.Now; } _unitWork.UpdateByTracking(mbomHeader); } #endregion foreach (var item in interfacembom.interfaceMbomDetails) { try { #region 保存生产MBOM接口子表 InterfaceMbomDetail data = _context.Set <InterfaceMbomDetail>().AsQueryable().Where(u => u.MbomHeaderId.Equals(interfacembom.interfaceMbomHeader.Id) && u.MaterialCode.Equals(item.MaterialCode)).SingleOrDefault(); item.Id = data?.Id; if (item.Id == null) { item.ProductCode = interfacembom.interfaceMbomHeader.ProductCode; item.MbomHeaderId = interfacembom.interfaceMbomHeader.Id; if (item.CreateBy == null) { item.CreateBy = "system"; item.CreateTime = DateTime.Now; } _unitWork.Add(item); } else { if (item.UpdateBy == null) { item.UpdateBy = "system"; item.UpdateTime = DateTime.Now; } _unitWork.UpdateByTracking(item); } #endregion #region 保存生产MBOM子表 MbomDetail mbomDetail = _context.Set <MbomDetail>().AsQueryable().Where(u => u.MbomHeaderId.Equals(mbomHeader.Id) && u.MaterialCode.Equals(item.MaterialCode)).SingleOrDefault(); if (mbomDetail == null) { mbomDetail = new MbomDetail(); } mbomDetail.MbomHeaderId = mbomHeader.Id; mbomDetail.ProductCode = interfacembom.interfaceMbomHeader.ProductCode; mbomDetail.StepId = item.StepId; mbomDetail.MaterialCode = item.MaterialCode; mbomDetail.BaseQty = item.BaseQty; if (item.IsCheck == null) { mbomDetail.IsCheck = false; } else { mbomDetail.IsCheck = item.IsCheck; } mbomDetail.DrawingNumber = item.DrawingNumber; mbomDetail.CreateTime = item.CreateTime; mbomDetail.CreateBy = item.CreateBy; mbomDetail.UpdateTime = item.UpdateTime; mbomDetail.UpdateBy = item.UpdateBy; if (mbomDetail.Id == null) { if (mbomDetail.CreateBy == null) { mbomDetail.CreateBy = "system"; mbomDetail.CreateTime = DateTime.Now; } _unitWork.Add(mbomDetail); } else { if (mbomDetail.UpdateBy == null) { mbomDetail.UpdateBy = "system"; mbomDetail.UpdateTime = DateTime.Now; } _unitWork.UpdateByTracking(mbomDetail); } #endregion } catch (Exception ex) { #region 记录生产MBOM接口子表错误信息 InterfaceMbomDetail data = _context.Set <InterfaceMbomDetail>().AsQueryable().Where(u => u.MbomHeaderId.Equals(mbomHeader.Id) && u.MaterialCode.Equals(item.MaterialCode)).SingleOrDefault(); if (data != null) { data.ErrorMessage = ex.Message; if (data.UpdateBy == null) { data.UpdateBy = "system"; data.UpdateTime = DateTime.Now; } _unitWork.Update(data); } #endregion Response.Code = 500; Response.Status = false; Response.Message = (Response.Message == "操作成功" ? "" : Response.Message) + "\r\n" + "主表ID:" + item.MbomHeaderId + ",MaterialCode:" + item.MaterialCode + "同步失败:" + ex.Message; } } } catch (Exception ex) { #region 记录生产MBOM接口主表错误信息 try { InterfaceMbomHeader data = _unitWork.FindSingle <InterfaceMbomHeader>(u => u.ProductCode.Equals(interfacembom.interfaceMbomHeader.ProductCode)); if (data != null) { data.ErrorMessage = ex.Message; if (data.UpdateBy == null) { data.UpdateBy = "system"; data.UpdateTime = DateTime.Now; } _unitWork.Update(data); } } catch (Exception) { } #endregion Response.Code = 500; Response.Status = false; Response.Message = (Response.Message == "操作成功" ? "" : Response.Message) + "\r\n" + "同步失败:" + ex.Message; } return(Response); }