public JsonResult Edit(WMS_AIModel model) { //List<WMS_AIModel> list = m_BLL.GetListByWhere(ref setNoPagerAscById, "Id = " + id + " &&InspectStatus = \"已送检\""); if (model.InspectStatus == "已送检") { return(Json(JsonHandler.CreateMessage(0, "已送检单据不能修改"))); } else { model.ModifyTime = ResultHelper.NowTime; model.ModifyPerson = GetUserTrueName(); if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",ArrivalBillNum" + model.ArrivalBillNum, "成功", "修改", "WMS_AI"); return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",ArrivalBillNum" + model.ArrivalBillNum + "," + ErrorCol, "失败", "修改", "WMS_AI"); return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.EditFail))); } } }
public ActionResult Edit(long id) { WMS_AIModel entity = m_BLL.GetById(id); //给关联字段订单号赋值 WMS_POModel entity_po = m_POBLL.GetById(entity.POId); entity.PO = entity_po.PO; //给关联字段物料编码赋值 WMS_PartModel entity_p = m_PartBLL.GetById(entity.PartId); entity.PartCode = entity_p.PartCode; return(View(entity)); }
public ActionResult Create(int AIId) { ViewBag.EditStatus = true; WMS_ReInspectModel entity = new WMS_ReInspectModel(); WMS_AIModel entity_AI = m_AIBLL.GetById(AIId); entity.OCheckOutDate = entity_AI.CheckOutDate; entity.OCheckOutRemark = entity_AI.CheckOutRemark; entity.OCheckOutResult = entity_AI.CheckOutResult; entity.ONoQualifyQty = entity_AI.NoQualifyQty; entity.OQualifyQty = entity_AI.QualifyQty; entity.InspectBillNum = entity_AI.InspectBillNum; return(View(entity)); }
public virtual WMS_AIModel GetById(object id) { if (IsExists(id)) { WMS_AI entity = m_Rep.GetById(id); WMS_AIModel model = new WMS_AIModel(); model.Id = entity.Id; model.ArrivalBillNum = entity.ArrivalBillNum; model.POId = entity.POId; model.PartId = entity.PartId; model.BoxQty = entity.BoxQty; model.ArrivalQty = entity.ArrivalQty; model.ArrivalDate = entity.ArrivalDate; model.ReceiveMan = entity.ReceiveMan; model.ReceiveStatus = entity.ReceiveStatus; model.InspectBillNum = entity.InspectBillNum; model.InspectMan = entity.InspectMan; model.InspectDate = entity.InspectDate; model.InspectStatus = entity.InspectStatus; model.CheckOutDate = entity.CheckOutDate; model.CheckOutResult = entity.CheckOutResult; model.QualifyQty = entity.QualifyQty; model.NoQualifyQty = entity.NoQualifyQty; model.CheckOutRemark = entity.CheckOutRemark; model.ReInspectBillNum = entity.ReInspectBillNum; model.InStoreBillNum = entity.InStoreBillNum; model.InStoreMan = entity.InStoreMan; model.InvId = entity.InvId; model.SubInvId = entity.SubInvId; model.InStoreStatus = entity.InStoreStatus; model.Attr1 = entity.Attr1; model.Attr2 = entity.Attr2; model.Attr3 = entity.Attr3; model.Attr4 = entity.Attr4; model.Attr5 = entity.Attr5; model.CreatePerson = entity.CreatePerson; model.CreateTime = entity.CreateTime; model.ModifyPerson = entity.ModifyPerson; model.ModifyTime = entity.ModifyTime; model.Lot = entity.Lot; return(model); } else { return(null); } }
public JsonResult Edit(WMS_AIModel model) { if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",ArrivalBillNum" + model.ArrivalBillNum, "成功", "修改", "WMS_AI"); return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserTrueName(), "Id" + model.Id + ",ArrivalBillNum" + model.ArrivalBillNum + "," + ErrorCol, "失败", "修改", "WMS_AI"); return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.EditFail))); } }
public JsonResult Create(string arrivalBillNum, string inserted) { var detailsList = JsonHandler.DeserializeJsonToList <WMS_POForAIModel>(inserted); foreach (var model in detailsList) { WMS_AIModel aiModel = new WMS_AIModel(); aiModel.Id = 0; aiModel.ArrivalBillNum = arrivalBillNum; aiModel.ArrivalDate = model.ArrivalDate; //到货批次:年+月(根据到货日期) aiModel.Lot = model.ArrivalDate.ToString("yyyyMM"); aiModel.ReceiveMan = GetUserTrueName(); aiModel.ReceiveStatus = "已到货"; aiModel.CreateTime = ResultHelper.NowTime; aiModel.CreatePerson = GetUserTrueName(); aiModel.POId = model.Id; aiModel.PartId = model.PartId; aiModel.BoxQty = model.BoxNum; aiModel.ArrivalQty = model.CurrentQty; aiModel.ReceiveMan = GetUserTrueName(); aiModel.InspectStatus = "未送检"; aiModel.InStoreStatus = "未入库"; try { m_BLL.Create(ref errors, aiModel); LogHandler.WriteServiceLog(GetUserTrueName(), "保存成功", "成功", "保存", "WMS_AI"); } catch (Exception ex) { LogHandler.WriteServiceLog(GetUserTrueName(), ex.Message, "失败", "保存", "WMS_AI"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ex.Message))); } } return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed))); }
/// <summary> /// 校验Excel数据,这个方法一般用于重写校验逻辑 /// </summary> public virtual bool CheckImportData(string fileName, List <WMS_AIModel> list, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping <WMS_AIModel>(x => x.ArrivalBillNum, "到货单据号"); excelFile.AddMapping <WMS_AIModel>(x => x.POId, "采购订单ID"); excelFile.AddMapping <WMS_AIModel>(x => x.PartId, "PartId"); excelFile.AddMapping <WMS_AIModel>(x => x.BoxQty, "到货箱数"); excelFile.AddMapping <WMS_AIModel>(x => x.ArrivalQty, "到货数量"); excelFile.AddMapping <WMS_AIModel>(x => x.ArrivalDate, "到货日期"); excelFile.AddMapping <WMS_AIModel>(x => x.ReceiveMan, "接收人"); excelFile.AddMapping <WMS_AIModel>(x => x.ReceiveStatus, "到货状态"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectBillNum, "送检单号"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectMan, "送检人"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectDate, "送检日期"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectStatus, "送检状体"); excelFile.AddMapping <WMS_AIModel>(x => x.CheckOutDate, "检验日期"); excelFile.AddMapping <WMS_AIModel>(x => x.CheckOutResult, "检验结果"); excelFile.AddMapping <WMS_AIModel>(x => x.QualifyQty, "合格数量"); excelFile.AddMapping <WMS_AIModel>(x => x.NoQualifyQty, "不合格数量"); excelFile.AddMapping <WMS_AIModel>(x => x.CheckOutRemark, "检验说明"); excelFile.AddMapping <WMS_AIModel>(x => x.ReInspectBillNum, "重新送检单"); excelFile.AddMapping <WMS_AIModel>(x => x.InStoreBillNum, "入库单号"); excelFile.AddMapping <WMS_AIModel>(x => x.InStoreMan, "入库员"); excelFile.AddMapping <WMS_AIModel>(x => x.InvId, "入库仓库"); excelFile.AddMapping <WMS_AIModel>(x => x.SubInvId, "SubInvId"); excelFile.AddMapping <WMS_AIModel>(x => x.InStoreStatus, "入库状态"); excelFile.AddMapping <WMS_AIModel>(x => x.Attr1, "Attr1"); excelFile.AddMapping <WMS_AIModel>(x => x.Attr2, "Attr2"); excelFile.AddMapping <WMS_AIModel>(x => x.Attr3, "Attr3"); excelFile.AddMapping <WMS_AIModel>(x => x.Attr4, "Attr4"); excelFile.AddMapping <WMS_AIModel>(x => x.Attr5, "Attr5"); excelFile.AddMapping <WMS_AIModel>(x => x.CreatePerson, "创建人"); excelFile.AddMapping <WMS_AIModel>(x => x.CreateTime, "创建时间"); excelFile.AddMapping <WMS_AIModel>(x => x.ModifyPerson, "修改人"); excelFile.AddMapping <WMS_AIModel>(x => x.ModifyTime, "修改时间"); excelFile.AddMapping <WMS_AIModel>(x => x.Lot, "批次号:YYYYMM"); //SheetName var excelContent = excelFile.Worksheet <WMS_AIModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var entity = new WMS_AIModel(); entity.Id = row.Id; entity.ArrivalBillNum = row.ArrivalBillNum; entity.POId = row.POId; entity.PartId = row.PartId; entity.BoxQty = row.BoxQty; entity.ArrivalQty = row.ArrivalQty; entity.ArrivalDate = row.ArrivalDate; entity.ReceiveMan = row.ReceiveMan; entity.ReceiveStatus = row.ReceiveStatus; entity.InspectBillNum = row.InspectBillNum; entity.InspectMan = row.InspectMan; entity.InspectDate = row.InspectDate; entity.InspectStatus = row.InspectStatus; entity.CheckOutDate = row.CheckOutDate; entity.CheckOutResult = row.CheckOutResult; entity.QualifyQty = row.QualifyQty; entity.NoQualifyQty = row.NoQualifyQty; entity.CheckOutRemark = row.CheckOutRemark; entity.ReInspectBillNum = row.ReInspectBillNum; entity.InStoreBillNum = row.InStoreBillNum; entity.InStoreMan = row.InStoreMan; entity.InvId = row.InvId; entity.SubInvId = row.SubInvId; entity.InStoreStatus = row.InStoreStatus; entity.Attr1 = row.Attr1; entity.Attr2 = row.Attr2; entity.Attr3 = row.Attr3; entity.Attr4 = row.Attr4; entity.Attr5 = row.Attr5; entity.CreatePerson = row.CreatePerson; entity.CreateTime = row.CreateTime; entity.ModifyPerson = row.ModifyPerson; entity.ModifyTime = row.ModifyTime; entity.Lot = row.Lot; //============================================================================= if (errorMessage.Length > 0) { errors.Add(string.Format( "第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); } list.Add(entity); rowIndex += 1; } if (errors.Count > 0) { return(false); } return(true); }
public virtual bool Edit(ref ValidationErrors errors, WMS_AIModel model) { try { WMS_AI entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.ArrivalBillNum = model.ArrivalBillNum; entity.POId = model.POId; entity.PartId = model.PartId; entity.BoxQty = model.BoxQty; entity.ArrivalQty = model.ArrivalQty; entity.ArrivalDate = model.ArrivalDate; entity.ReceiveMan = model.ReceiveMan; entity.ReceiveStatus = model.ReceiveStatus; entity.InspectBillNum = model.InspectBillNum; entity.InspectMan = model.InspectMan; entity.InspectDate = model.InspectDate; entity.InspectStatus = model.InspectStatus; entity.CheckOutDate = model.CheckOutDate; entity.CheckOutResult = model.CheckOutResult; entity.QualifyQty = model.QualifyQty; entity.NoQualifyQty = model.NoQualifyQty; entity.CheckOutRemark = model.CheckOutRemark; entity.ReInspectBillNum = model.ReInspectBillNum; entity.InStoreBillNum = model.InStoreBillNum; entity.InStoreMan = model.InStoreMan; entity.InvId = model.InvId; entity.SubInvId = model.SubInvId; entity.InStoreStatus = model.InStoreStatus; entity.Attr1 = model.Attr1; entity.Attr2 = model.Attr2; entity.Attr3 = model.Attr3; entity.Attr4 = model.Attr4; entity.Attr5 = model.Attr5; entity.CreatePerson = model.CreatePerson; entity.CreateTime = model.CreateTime; entity.ModifyPerson = model.ModifyPerson; entity.ModifyTime = model.ModifyTime; entity.Lot = model.Lot; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public bool ImportExcelData(string oper, string filePath, ref ValidationErrors errors) { bool rtn = true; var targetFile = new FileInfo(filePath); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(filePath); using (XLWorkbook wb = new XLWorkbook(filePath)) { //第一个Sheet using (IXLWorksheet wws = wb.Worksheets.First()) { //对应列头 excelFile.AddMapping <WMS_AIModel>(x => x.ArrivalBillNum, "到货单据号"); excelFile.AddMapping <WMS_AIModel>(x => x.POId, "采购订单ID"); excelFile.AddMapping <WMS_AIModel>(x => x.PartId, "物料ID"); excelFile.AddMapping <WMS_AIModel>(x => x.BoxQty, "到货箱数"); excelFile.AddMapping <WMS_AIModel>(x => x.ArrivalQty, "到货数量"); excelFile.AddMapping <WMS_AIModel>(x => x.ArrivalDate, "到货日期"); excelFile.AddMapping <WMS_AIModel>(x => x.ReceiveMan, "接收人"); excelFile.AddMapping <WMS_AIModel>(x => x.ReceiveStatus, "到货状态"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectBillNum, "送检单号"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectMan, "送检人"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectDate, "送检日期"); excelFile.AddMapping <WMS_AIModel>(x => x.InspectStatus, "送检状体"); excelFile.AddMapping <WMS_AIModel>(x => x.CheckOutDate, "检验日期"); excelFile.AddMapping <WMS_AIModel>(x => x.CheckOutResult, "检验结果"); excelFile.AddMapping <WMS_AIModel>(x => x.QualifyQty, "合格数量"); excelFile.AddMapping <WMS_AIModel>(x => x.NoQualifyQty, "不合格数量"); excelFile.AddMapping <WMS_AIModel>(x => x.CheckOutRemark, "检验说明"); excelFile.AddMapping <WMS_AIModel>(x => x.ReInspectBillNum, "重新送检单"); excelFile.AddMapping <WMS_AIModel>(x => x.InStoreBillNum, "入库单号"); excelFile.AddMapping <WMS_AIModel>(x => x.InStoreMan, ""); excelFile.AddMapping <WMS_AIModel>(x => x.InvId, "入库仓库"); excelFile.AddMapping <WMS_AIModel>(x => x.SubInvId, "子库"); excelFile.AddMapping <WMS_AIModel>(x => x.InStoreStatus, "入库状态"); excelFile.AddMapping <WMS_AIModel>(x => x.Attr1, ""); excelFile.AddMapping <WMS_AIModel>(x => x.Attr2, ""); excelFile.AddMapping <WMS_AIModel>(x => x.Attr3, ""); excelFile.AddMapping <WMS_AIModel>(x => x.Attr4, ""); excelFile.AddMapping <WMS_AIModel>(x => x.Attr5, ""); excelFile.AddMapping <WMS_AIModel>(x => x.CreatePerson, "创建人"); excelFile.AddMapping <WMS_AIModel>(x => x.CreateTime, "创建时间"); excelFile.AddMapping <WMS_AIModel>(x => x.ModifyPerson, "修改人"); excelFile.AddMapping <WMS_AIModel>(x => x.ModifyTime, "修改时间"); //SheetName,第一个Sheet var excelContent = excelFile.Worksheet <WMS_AIModel>(0); //开启事务 using (DBContainer db = new DBContainer()) { var tran = db.Database.BeginTransaction(); //开启事务 int rowIndex = 0; //检查数据正确性 foreach (var row in excelContent) { rowIndex += 1; string errorMessage = String.Empty; var model = new WMS_AIModel(); model.Id = row.Id; model.ArrivalBillNum = row.ArrivalBillNum; model.POId = row.POId; model.PartId = row.PartId; model.BoxQty = row.BoxQty; model.ArrivalQty = row.ArrivalQty; model.ArrivalDate = row.ArrivalDate; model.ReceiveMan = row.ReceiveMan; model.ReceiveStatus = row.ReceiveStatus; model.InspectBillNum = row.InspectBillNum; model.InspectMan = row.InspectMan; model.InspectDate = row.InspectDate; model.InspectStatus = row.InspectStatus; model.CheckOutDate = row.CheckOutDate; model.CheckOutResult = row.CheckOutResult; model.QualifyQty = row.QualifyQty; model.NoQualifyQty = row.NoQualifyQty; model.CheckOutRemark = row.CheckOutRemark; model.ReInspectBillNum = row.ReInspectBillNum; model.InStoreBillNum = row.InStoreBillNum; model.InStoreMan = row.InStoreMan; model.InvId = row.InvId; model.SubInvId = row.SubInvId; model.InStoreStatus = row.InStoreStatus; model.Attr1 = row.Attr1; model.Attr2 = row.Attr2; model.Attr3 = row.Attr3; model.Attr4 = row.Attr4; model.Attr5 = row.Attr5; model.CreatePerson = row.CreatePerson; model.CreateTime = row.CreateTime; model.ModifyPerson = row.ModifyPerson; model.ModifyTime = row.ModifyTime; if (!String.IsNullOrEmpty(errorMessage)) { rtn = false; errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage; continue; } //执行额外的数据校验 try { AdditionalCheckExcelData(ref model); } catch (Exception ex) { rtn = false; errorMessage = ex.Message; errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage; continue; } //写入数据库 WMS_AI entity = new WMS_AI(); entity.Id = model.Id; entity.ArrivalBillNum = model.ArrivalBillNum; entity.POId = model.POId; entity.PartId = model.PartId; entity.BoxQty = model.BoxQty; entity.ArrivalQty = model.ArrivalQty; entity.ArrivalDate = model.ArrivalDate; entity.ReceiveMan = model.ReceiveMan; entity.ReceiveStatus = model.ReceiveStatus; entity.InspectBillNum = model.InspectBillNum; entity.InspectMan = model.InspectMan; entity.InspectDate = model.InspectDate; entity.InspectStatus = model.InspectStatus; entity.CheckOutDate = model.CheckOutDate; entity.CheckOutResult = model.CheckOutResult; entity.QualifyQty = model.QualifyQty; entity.NoQualifyQty = model.NoQualifyQty; entity.CheckOutRemark = model.CheckOutRemark; entity.ReInspectBillNum = model.ReInspectBillNum; entity.InStoreBillNum = model.InStoreBillNum; entity.InStoreMan = model.InStoreMan; entity.InvId = model.InvId; entity.SubInvId = model.SubInvId; entity.InStoreStatus = model.InStoreStatus; entity.Attr1 = model.Attr1; entity.Attr2 = model.Attr2; entity.Attr3 = model.Attr3; entity.Attr4 = model.Attr4; entity.Attr5 = model.Attr5; entity.CreatePerson = model.CreatePerson; entity.CreateTime = model.CreateTime; entity.ModifyPerson = model.ModifyPerson; entity.ModifyTime = model.ModifyTime; entity.CreatePerson = oper; entity.CreateTime = DateTime.Now; entity.ModifyPerson = oper; entity.ModifyTime = DateTime.Now; db.WMS_AI.Add(entity); try { db.SaveChanges(); } catch (Exception ex) { rtn = false; //将当前报错的entity状态改为分离,类似EF的回滚(忽略之前的Add操作) db.Entry(entity).State = System.Data.Entity.EntityState.Detached; errorMessage = ex.InnerException.InnerException.Message; errors.Add(string.Format("第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); wws.Cell(rowIndex + 1, excelFile.GetColumnNames("Sheet1").Count()).Value = errorMessage; } } if (rtn) { tran.Commit(); //必须调用Commit(),不然数据不会保存 } else { tran.Rollback(); //出错就回滚 } } } wb.Save(); } return(rtn); }
public void AdditionalCheckExcelData(ref WMS_AIModel model) { }
public ActionResult Details(long id) { WMS_AIModel entity = m_BLL.GetById(id); return(View(entity)); }
public void AdditionalCheckExcelData(DBContainer db, ref WMS_AIModel model) { //获取物料ID if (!String.IsNullOrEmpty(model.PartCode)) { var partCode = model.PartCode; Expression <Func <WMS_Part, bool> > exp = x => x.PartCode == partCode; //var part = m_PartRep.GetSingleWhere(exp); var part = db.WMS_Part.FirstOrDefault(exp); if (part == null) { throw new Exception("物料编码不存在!"); } else { model.PartId = part.Id; } } else { throw new Exception("物料编码不能为空!"); } //采购订单号 if (!String.IsNullOrEmpty(model.PO)) { var po = model.PO; var partid = model.PartId; Expression <Func <WMS_PO, bool> > exp = x => x.PO == po && x.PartId == partid && x.Status == "有效"; var result = db.WMS_PO.FirstOrDefault(exp); if (result != null) { model.POId = result.Id; } else { throw new Exception("无此订单或者订单无此物料!"); } } else { throw new Exception("采购订单号不能为空!"); } //校验入库日期 //if (!String.IsNullOrEmpty(model.ArrivalDate.ToString())) if (!String.IsNullOrEmpty(model.PO)) { model.Lot = DateTimeHelper.GetLot(DateTime.Now); //if (!DateTimeHelper.CheckYearMonth(model.ArrivalDate.Value.ToString("yyyyMM"))) //{ // throw new Exception("批次号不合符规范!"); //} //else { model.Lot = model.ArrivalDate.Value.ToString("yyyyMM"); } } else { throw new Exception("到货日期不能为空!"); } //校验到货单号 if (!String.IsNullOrEmpty(model.ArrivalBillNum)) { var partId = model.PartId; var arrivalBillNum = model.ArrivalBillNum; Expression <Func <WMS_AI, bool> > exp = x => x.PartId == partId && x.ArrivalBillNum == arrivalBillNum; //var part = m_PORep.GetSingleWhere(exp); var part = db.WMS_AI.FirstOrDefault(exp); if (part != null) { throw new Exception("到货单号与物料编码重复!"); } } else { throw new Exception("到货单号不能为空!"); } //不允许超量接受 //投料数量不能为空 if (model.ArrivalQty < 0) { throw new Exception("到货数量必须大于0!"); } }