public override bool Equals(object obj) { ItemTrace another = obj as ItemTrace; if (another == null) { return(false); } else { return(this.Item == another.Item); } }
public ActionResult New(ItemTrace itemTrace) { if (ModelState.IsValid) { IList<ItemTrace> itemTraceList = base.genericMgr.FindAll<ItemTrace>("from ItemTrace as i where i.Item=?", itemTrace.Item); if (itemTraceList.Count > 0) { SaveErrorMessage("关键件已经存在"); } else{ base.genericMgr.Create(itemTrace); SaveSuccessMessage("添加成功"); return RedirectToAction("List"); } } return View(itemTrace); }
public ActionResult New(ItemTrace itemTrace) { if (ModelState.IsValid) { IList<ItemTrace> itemTraceList = genericMgr.FindAll<ItemTrace>("from ItemTrace as i where i.Item=?", itemTrace.Item); if (itemTraceList.Count > 0) { SaveErrorMessage(Resources.EXT.ControllerLan.Con_KeyArticleAlreadyExists); } else{ this.genericMgr.CreateWithTrim(itemTrace); SaveSuccessMessage(Resources.EXT.ControllerLan.Con_AddedSuccessfully); return RedirectToAction("List"); } } return View(itemTrace); }
public void CreateItemTraceXls(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 = 1;//车系 #endregion IList<ItemTrace> exactItemTraceList = new List<ItemTrace>(); IList<Item> allItemList = this.genericMgr.FindAll<Item>(); IList<ItemTrace> allItemTraceList = this.genericMgr.FindAll<ItemTrace>(); int i = 10; while (rows.MoveNext()) { i++; HSSFRow row = (HSSFRow)rows.Current; if (!ImportHelper.CheckValidDataRow(row, 1, 2)) { break;//边界 } string itemCode = string.Empty; ItemTrace itemTrace = new ItemTrace(); #region 读取数据 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 existsItemTrace = allItemTraceList.FirstOrDefault(a => a.Item == itemCode); //var duplicateItemTrace= if (items == null) { businessException.AddMessage(string.Format("第{0}行{1}物料编号不存在。", i, itemCode)); } else if (existsItemTrace!=null) { businessException.AddMessage(string.Format("第{0}行{1}关键件已经存在。", i, itemCode)); } else { itemTrace.Item = items.Code; itemTrace.ItemDescription = items.Description; if (exactItemTraceList == null || exactItemTraceList.Count == 0) { exactItemTraceList.Add(itemTrace); } else { bool isDuplicate = exactItemTraceList.Where(e => e.Item == itemCode).Count()>0; if (isDuplicate) { businessException.AddMessage(string.Format("第{0}行{1}关键件在模板中重复。", i, itemCode)); } else { exactItemTraceList.Add(itemTrace); } } } } #endregion } if (businessException.HasMessage) { throw businessException; } if (exactItemTraceList == null || exactItemTraceList.Count == 0) { throw new BusinessException("模版为空,请确认。"); } foreach (ItemTrace itemTrace in exactItemTraceList) { genericMgr.Create(itemTrace); } }