public ActionResult _Update(LocationDetailPref locationDetailPref, string id) { if (CheckLocDetPref(locationDetailPref)) { LocationDetailPref upLocationDetailPref = base.genericMgr.FindById<LocationDetailPref>(Convert.ToInt32(id)); upLocationDetailPref.Item = locationDetailPref.Item; upLocationDetailPref.ItemDesc = this.genericMgr.FindById<Item>(locationDetailPref.Item).Description; upLocationDetailPref.Location = locationDetailPref.Location; upLocationDetailPref.MaxStock = locationDetailPref.MaxStock; upLocationDetailPref.SafeStock = locationDetailPref.SafeStock; this.genericMgr.Update(upLocationDetailPref); SaveSuccessMessage("修改成功。"); } GridCommand command = (GridCommand)TempData["GridCommand"]; LocationDetailPrefSearchModel searchModel = (LocationDetailPrefSearchModel)TempData["searchModel"]; TempData["GridCommand"] = command; TempData["searchModel"] = searchModel; SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel); GridModel<LocationDetailPref> gridModel = GetAjaxPageData<LocationDetailPref>(searchStatementModel, command); foreach (var locDetPref in gridModel.Data) { locDetPref.ReferenceItemCode = this.genericMgr.FindById<Item>(locDetPref.Item).ReferenceCode; } return PartialView(gridModel); }
public ActionResult _Insert(LocationDetailPref LocationDetailPref) { if (CheckLocDetPref(LocationDetailPref)) { this.genericMgr.Create(LocationDetailPref); SaveSuccessMessage("添加成功。"); } GridCommand command = (GridCommand)TempData["GridCommand"]; LocationDetailPrefSearchModel searchModel = (LocationDetailPrefSearchModel)TempData["searchModel"]; TempData["GridCommand"] = command; TempData["searchModel"] = searchModel; SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel); GridModel<LocationDetailPref> gridModel = GetAjaxPageData<LocationDetailPref>(searchStatementModel, command); foreach (var locDetPref in gridModel.Data) { locDetPref.ReferenceItemCode = this.genericMgr.FindById<Item>(locDetPref.Item).ReferenceCode; } return PartialView(gridModel); }
private bool CheckLocDetPref(LocationDetailPref locationDetailPref) { bool hasError = false; if (string.IsNullOrWhiteSpace(locationDetailPref.Item)) { hasError = true; SaveErrorMessage("物料编号不能为空。"); } if (string.IsNullOrWhiteSpace(locationDetailPref.Location)) { hasError = true; SaveErrorMessage("库位不能为空。"); } if (locationDetailPref.SafeStock<=0) { hasError = true; SaveErrorMessage("安全库存必须大于0。"); } if (locationDetailPref.MaxStock <= 0) { hasError = true; SaveErrorMessage("最大库存必须大于0。"); } if (this.genericMgr.FindAllWithNativeSql<int>(" select isnull(count(*),0) as counts from INV_LocationDetPref where Item=? and Location=? and Id <>? ", new object[] { locationDetailPref.Item, locationDetailPref.Location, locationDetailPref.Id }, new IType[] { NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.String, NHibernate.NHibernateUtil.Int32 })[0] > 0) { hasError = true; SaveErrorMessage("物料编号+库位已经维护,请确认!"); } return !hasError; }
public void ImportLocDetPrefXls(Stream inputStream) { if (inputStream.Length == 0) { throw new BusinessException("Import.Stream.Empty"); } HSSFWorkbook workbook = new HSSFWorkbook(inputStream); ISheet sheet = workbook.GetSheetAt(0); IEnumerator rows = sheet.GetRowEnumerator(); ImportHelper.JumpRows(rows, 10); BusinessException businessException = new BusinessException(); #region 列定义 int colItem = 2;//车系 int colLocation = 1;//库位 int colSafeStock = 3;//安全库存 int colMaxStock = 4;//最大库存 #endregion IList<LocationDetailPref> exactLotDetPrefList = new List<LocationDetailPref>(); IList<Item> allItemList = this.genericMgr.FindAll<Item>(); IList<Location> allLocationList = this.genericMgr.FindAll<Location>(); IList<LocationDetailPref> allLotDetPref = this.genericMgr.FindAll<LocationDetailPref>(); int i = 10; while (rows.MoveNext()) { i++; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 5)) { break;//边界 } string itemCode = string.Empty; string locatioCode = string.Empty; decimal safeStock = 0; decimal maxStock = 0; LocationDetailPref lotDetPref = new LocationDetailPref(); #region 读取数据 #region Item itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if (string.IsNullOrWhiteSpace(itemCode)) { businessException.AddMessage(string.Format("第{0}行物料编号不能为空", i)); } else { var items = allItemList.FirstOrDefault(a => a.Code == itemCode); //var duplicateItemTrace= if (items == null) { businessException.AddMessage(string.Format("第{0}行{1}物料编号不存在。", i, itemCode)); } else { lotDetPref.Item = items.Code; lotDetPref.ItemDesc = items.Description; } } #endregion #region Location locatioCode = ImportHelper.GetCellStringValue(row.GetCell(colLocation)); if (string.IsNullOrWhiteSpace(locatioCode)) { businessException.AddMessage(string.Format("第{0}行库位代码不能为空", i)); } else { var locations = allLocationList.FirstOrDefault(a => a.Code == locatioCode); //var duplicateItemTrace= if (locations == null) { businessException.AddMessage(string.Format("第{0}行{1}库位代码不存在。", i, locatioCode)); } else { lotDetPref.Location = locatioCode; } } #endregion #region safeStock string safeStockRead = ImportHelper.GetCellStringValue(row.GetCell(colSafeStock)); if (string.IsNullOrWhiteSpace(safeStockRead)) { businessException.AddMessage(string.Format("第{0}行安全库存不能为空", i)); } else { decimal.TryParse(safeStockRead, out safeStock); if (safeStock > 0) { lotDetPref.SafeStock = safeStock; } else { businessException.AddMessage(string.Format("第{0}行安全库存填写错误。", i)); } } #endregion #region maxStock string maxStockRead = ImportHelper.GetCellStringValue(row.GetCell(colMaxStock)); if (string.IsNullOrWhiteSpace(maxStockRead)) { businessException.AddMessage(string.Format("第{0}行最大库存不能为空", i)); } else { decimal.TryParse(maxStockRead, out maxStock); if (maxStock > 0) { lotDetPref.MaxStock = maxStock; } else { businessException.AddMessage(string.Format("第{0}行最大库存填写错误。", i)); } } #endregion if (allLotDetPref.Where(a => a.Item == lotDetPref.Item && a.Location == lotDetPref.Location).Count() > 0) { //businessException.AddMessage(string.Format("第{0}行【物料编号+库位代码】已经存在", i)); var updateLotdetPref = allLotDetPref.FirstOrDefault(a => a.Item == lotDetPref.Item && a.Location == lotDetPref.Location); updateLotdetPref.SafeStock = lotDetPref.SafeStock; updateLotdetPref.MaxStock = lotDetPref.MaxStock; updateLotdetPref.IsUpdate = true; exactLotDetPrefList.Add(updateLotdetPref); } else if (exactLotDetPrefList.Count > 0 && exactLotDetPrefList.Where(e => e.Item == lotDetPref.Item && e.Location == lotDetPref.Location).Count() > 0) { businessException.AddMessage(string.Format("第{0}行【物料编号+库位代码】在模板中重复", i)); } else { exactLotDetPrefList.Add(lotDetPref); } #endregion } if (businessException.HasMessage) { throw businessException; } if (exactLotDetPrefList == null || exactLotDetPrefList.Count == 0) { throw new BusinessException("模版为空,请确认。"); } foreach (LocationDetailPref lotDetPref in exactLotDetPrefList) { if (lotDetPref.IsUpdate) { genericMgr.Update(lotDetPref); } else { genericMgr.Create(lotDetPref); } } }