/// <summary> /// 校验Excel数据,这个方法一般用于重写校验逻辑 /// </summary> public virtual bool CheckImportData(string fileName, List <Spl_EarlyWareingGoodModel> list, ref ValidationErrors errors) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return(false); } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.WareDetailsId, "货品名称"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.LowNumber, "最低库存"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.TotalNumber, "库存"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.ProductType, "货品类别"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.ProductPrice, "货品单价"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.PriceTotal, "货品总价"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.WarehouseId, "WarehouseId"); excelFile.AddMapping <Spl_EarlyWareingGoodModel>(x => x.CreateTime, "更新时间"); //SheetName var excelContent = excelFile.Worksheet <Spl_EarlyWareingGoodModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var entity = new Spl_EarlyWareingGoodModel(); entity.Id = row.Id; entity.WareDetailsId = row.WareDetailsId; entity.LowNumber = row.LowNumber; entity.TotalNumber = row.TotalNumber; entity.ProductType = row.ProductType; entity.ProductPrice = row.ProductPrice; entity.PriceTotal = row.PriceTotal; entity.WarehouseId = row.WarehouseId; entity.CreateTime = row.CreateTime; //============================================================================= 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 JsonResult Edit(Spl_EarlyWareingGoodModel model) { if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",WareDetailsId" + model.WareDetailsId, "成功", "修改", "Spl_EarlyWareingGood"); return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed))); } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",WareDetailsId" + model.WareDetailsId + "," + ErrorCol, "失败", "修改", "Spl_EarlyWareingGood"); return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol))); } } else { return(Json(JsonHandler.CreateMessage(0, Resource.EditFail))); } }
public virtual bool Create(ref ValidationErrors errors, Spl_EarlyWareingGoodModel model) { try { Spl_EarlyWareingGood entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new Spl_EarlyWareingGood(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.LowNumber = model.LowNumber; entity.TotalNumber = model.TotalNumber; entity.ProductType = model.ProductType; entity.ProductPrice = model.ProductPrice; entity.PriceTotal = model.PriceTotal; entity.WarehouseId = model.WarehouseId; entity.CreateTime = model.CreateTime; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual Spl_EarlyWareingGoodModel GetById(object id) { if (IsExists(id)) { Spl_EarlyWareingGood entity = m_Rep.GetById(id); Spl_EarlyWareingGoodModel model = new Spl_EarlyWareingGoodModel(); model.Id = entity.Id; model.WareDetailsId = entity.WareDetailsId; model.LowNumber = entity.LowNumber; model.TotalNumber = entity.TotalNumber; model.ProductType = entity.ProductType; model.ProductPrice = entity.ProductPrice; model.PriceTotal = entity.PriceTotal; model.WarehouseId = entity.WarehouseId; model.CreateTime = entity.CreateTime; return(model); } else { return(null); } }
public ActionResult Edit(string id) { Spl_EarlyWareingGoodModel entity = m_BLL.GetById(id); return(View(entity)); }