public override bool Equals(object obj) { BomMaster another = obj as BomMaster; if (another == null) { return(false); } else { return(this.Code == another.Code); } }
public ActionResult _New_Master(BomMaster bomMaster) { if (ModelState.IsValid) { //判断描述不能重复 if (base.genericMgr.FindAll<long>(DuiplicateBomMasterVerifyStatement, new object[] { bomMaster.Code })[0] > 0) { base.SaveErrorMessage(Resources.ErrorMessage.Errors_Existing_Code, bomMaster.Code); } else { base.genericMgr.Create(bomMaster); SaveSuccessMessage(Resources.PRD.Bom.BomMaster_Added); return RedirectToAction("_Edit_Master/" + bomMaster.Code); } } return PartialView(bomMaster); }
public ActionResult _Edit_Master(BomMaster bomMaster) { if (ModelState.IsValid) { base.genericMgr.Update(bomMaster); SaveSuccessMessage(Resources.PRD.Bom.BomMaster_Updated); } return PartialView(bomMaster); }
public void ImportBom(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, 1); #region 列定义 int colBom = 0;//物料 int colBomDesc = 1;//物料描述 int colBomQty = 2;//基本数量 int colBomUom = 3;//Bom单位 int colOp = 4;//项目 int colItem = 5;//组件 int colItemDesc = 6;//描述 int colRateQty = 7;//数量 int colItemUom = 8;//组件单位 int colScrap = 9;//工序废品 #endregion var errorMessage = new BusinessException(); int colCount = 0; List<RowData> rowDataList = new List<RowData>(); #region 读取数据 while(rows.MoveNext()) { HSSFRow row = (HSSFRow)rows.Current; if(!ImportHelper.CheckValidDataRow(row, 0, 9)) { break;//边界 } colCount++; var rowData = new RowData(); #region rowData.Bom = ImportHelper.GetCellStringValue(row.GetCell(colBom)); if(rowData.Bom == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineBomShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } rowData.BomDesc = ImportHelper.GetCellStringValue(row.GetCell(colBomDesc)); if(rowData.BomDesc == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineBomDescShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } string BomQty = ImportHelper.GetCellStringValue(row.GetCell(colBomQty)); if(BomQty == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineBomQtyShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } else { decimal _BomQty = 0m; if(!decimal.TryParse(BomQty, out _BomQty)) { rowData.HasError = true; errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineBomQtyIsNotNum, colCount.ToString()); } rowData.BomQty = _BomQty; } rowData.BomUom = ImportHelper.GetCellStringValue(row.GetCell(colBomUom)); if(rowData.BomUom == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineBomUomShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } string Op = ImportHelper.GetCellStringValue(row.GetCell(colOp)); if(Op == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineOPShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } else { int _Op = 0; if(!int.TryParse(Op, out _Op)) { rowData.HasError = true; errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineOPIsNotNum, colCount.ToString()); } rowData.Op = _Op; } rowData.Item = ImportHelper.GetCellStringValue(row.GetCell(colItem)); if(rowData.Item == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineItemShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } if(itemMgr.GetCacheItem(rowData.Item) == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineItemIsNotExists, colCount.ToString(), rowData.Item); rowData.HasError = true; } string rateQty = ImportHelper.GetCellStringValue(row.GetCell(colRateQty)); if(rateQty == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineRateQtyShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } else { decimal _rateQty = 0m; if(!decimal.TryParse(rateQty, out _rateQty)) { rowData.HasError = true; errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineRateQtyIsNotNum, colCount.ToString()); } rowData.RateQty = _rateQty; } rowData.ItemUom = ImportHelper.GetCellStringValue(row.GetCell(colItemUom)); if(rowData.ItemUom == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineItemUomShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } else { rowData.ItemUom = rowData.ItemUom.ToUpper(); } string scrap = ImportHelper.GetCellStringValue(row.GetCell(colScrap)); if(scrap == null) { errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineScrapShouldNotEmpty, colCount.ToString()); rowData.HasError = true; } else { decimal _Scrap = 0m; if(!decimal.TryParse(scrap, out _Scrap)) { rowData.HasError = true; errorMessage.AddMessage(Resources.EXT.ServiceLan.TheSpecialLineScrapIsNotNum, colCount.ToString()); } rowData.Scrap = _Scrap; } #endregion rowDataList.Add(rowData); } #endregion if(rowDataList.Count == 0) { errorMessage.AddMessage(Resources.EXT.ServiceLan.NotFoundEffectData); throw errorMessage; } #region 验证 var dataRowGroup = rowDataList.Where(p => !p.HasError) .GroupBy(p => new { p.Bom, p.Item, p.Op }, (k, g) => new { k, Count = g.Count() }) .Where(p => p.Count > 1).Select(p => new { p.k.Bom, p.k.Item, p.k.Op }); foreach(var dataRow in dataRowGroup) { errorMessage.AddMessage(Resources.EXT.ServiceLan.BomImportDuplicate, dataRow.Bom, dataRow.Item, dataRow.Op.ToString()); } #endregion if(!errorMessage.HasMessage) { var distinctDataRows = rowDataList.Where(p => !p.HasError) .GroupBy(p => new { p.Bom, p.Item, p.Op }, (k, g) => new { k, j = g.First() }) .Select(p => p.j); var excelBomMasterList = distinctDataRows.GroupBy(p => p.Bom, (k, g) => new { Bom = k, List = g }); var bomMasterDic = this.genericMgr.FindAll<BomMaster>().ToDictionary(d => d.Code, d => d); var bomDetailDic = this.genericMgr.FindAll<BomDetail>().GroupBy(p => p.Bom, (k, g) => new { k, g }) .ToDictionary(d => d.k, d => d.g.ToList()); foreach(var excelBomMaster in excelBomMasterList) { var firstDataRow = excelBomMaster.List.First(); var bomMaster = bomMasterDic.ValueOrDefault(excelBomMaster.Bom); var bomDetails = bomDetailDic.ValueOrDefault(excelBomMaster.Bom) ?? new List<BomDetail>(); #region bomMaster if(bomMaster == null) { try { var newBomMaster = new BomMaster(); newBomMaster.Code = excelBomMaster.Bom; newBomMaster.Description = firstDataRow.BomDesc; newBomMaster.IsActive = true; newBomMaster.Qty = firstDataRow.BomQty; newBomMaster.Uom = firstDataRow.BomUom; this.genericMgr.Create(newBomMaster); } catch(Exception ex) { errorMessage.AddMessage(string.Format(Resources.EXT.ServiceLan.FaildCreateBomMaster, excelBomMaster.Bom, ex.Message)); break; } } else { if(true || bomMaster.Description != firstDataRow.BomDesc || bomMaster.Qty != firstDataRow.BomQty || bomMaster.Uom != firstDataRow.BomUom) { bomMaster.Description = firstDataRow.BomDesc; bomMaster.Qty = firstDataRow.BomQty; bomMaster.Uom = firstDataRow.BomUom; this.genericMgr.Update(bomMaster); } } #endregion #region BomDetail foreach(var dataRow in excelBomMaster.List) { try { var bomDetail = bomDetails.FirstOrDefault(p => p.Item == dataRow.Item && p.Operation == dataRow.Op); if(bomDetail == null) { //Id Bom Item Op Uom StartDate EndDate RateQty ScrapPct var newBomDetail = new BomDetail(); newBomDetail.Bom = dataRow.Bom; newBomDetail.Item = dataRow.Item; newBomDetail.Operation = dataRow.Op; newBomDetail.OpReference = "10"; newBomDetail.Uom = dataRow.ItemUom; newBomDetail.StartDate = DateTime.Parse("2004-1-1"); newBomDetail.EndDate = DateTime.Parse("9999-1-1"); newBomDetail.RateQty = dataRow.RateQty; newBomDetail.ScrapPercentage = dataRow.Scrap; this.genericMgr.Create(newBomDetail); } else { if(true || bomDetail.Uom != dataRow.ItemUom || bomDetail.RateQty != dataRow.RateQty || bomDetail.ScrapPercentage != dataRow.Scrap) { bomDetail.Uom = dataRow.ItemUom; bomDetail.RateQty = dataRow.RateQty; bomDetail.Operation = dataRow.Op; bomDetail.ScrapPercentage = dataRow.Scrap; bomDetail.StartDate = DateTime.Parse("2004-1-1"); bomDetail.EndDate = DateTime.Parse("9999-1-1"); this.genericMgr.Update(bomDetail); } } } catch(Exception ex) { errorMessage.AddMessage(string.Format(Resources.EXT.ServiceLan.FaildCreateBomDetail, dataRow.Item, ex.Message)); goto theEnd; } } foreach(var bomDetail in bomDetails) { var dataRow = excelBomMaster.List.FirstOrDefault(p => p.Item == bomDetail.Item && p.Op == bomDetail.Operation); if(dataRow == null) { bomDetail.EndDate = DateTime.Today; this.genericMgr.Update(bomDetail); } } #endregion } ResetBomCache(); } theEnd: if(errorMessage.HasMessage) { throw errorMessage; } }
public IList<BomDetail> GetFlatBomDetail(BomMaster bom, DateTime? effectiveDate, bool isMrp = false) { if(effectiveDate == null) { effectiveDate = DateTime.Now; } IList<BomDetail> flatBomDetailList = new List<BomDetail>(); IList<BomDetail> nextBomDetailList = this.GetNextLevelBomDetail(bom.Code, effectiveDate, isMrp); foreach(BomDetail nextBomDetail in nextBomDetailList) { nextBomDetail.UnitBomQty = nextBomDetail.RateQty / bom.Qty; nextBomDetail.CalculatedQty = nextBomDetail.UnitBomQty * (1 + nextBomDetail.ScrapPercentage); ProcessCurrentBomDetailStructrue(flatBomDetailList, nextBomDetail, effectiveDate.Value, isMrp); } return flatBomDetailList; }
public ActionResult _Edit_Master(BomMaster bomMaster) { if (ModelState.IsValid) { genericMgr.UpdateWithTrim(bomMaster); bomMgr.ResetBomCache(); SaveSuccessMessage(Resources.PRD.Bom.BomMaster_Updated); } return PartialView(bomMaster); }