Beispiel #1
0
 public ActionResult _New_Detail(BomDetail bomDetail)
 {
     ModelState.Remove("Item.Description");
     if (ModelState.IsValid)
     {
         //判断描述不能重复
         if (base.genericMgr.FindAll<long>(DuiplicateBomDetailVerifyStatement, new object[] { bomDetail.Bom,bomDetail.Item })[0] > 0)
         {
             base.SaveErrorMessage(Resources.ErrorMessage.Errors_Existing_Code, bomDetail.Id.ToString());
         }
         else
         {
             base.genericMgr.Create(bomDetail);
             SaveSuccessMessage(Resources.PRD.Bom.BomDetail_Added);
             return RedirectToAction("_Edit_Detail/" + bomDetail.Id);
         }
     }
     return PartialView(bomDetail);
 }
Beispiel #2
0
        public ActionResult _Edit_Detail(BomDetail bomDetail)
        {
            ModelState.Remove("Item.Description");
            if (ModelState.IsValid)
            {
                base.genericMgr.Update(bomDetail);
                SaveSuccessMessage(Resources.PRD.Bom.BomDetail_Updated);
            }

            return PartialView(bomDetail);
        }
Beispiel #3
0
        public void ProcessSectionBom()
        {
            log.Info("------------------------------------------------------------------");
            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 bom in bomMasterDic)
            {
                var bomMaster = bom.Value;
                var bomDetails = bomDetailDic.ValueOrDefault(bom.Key) ?? new List<BomDetail>();
                var bomDetail29s = bomDetails.Where(p => p.Item.StartsWith("29"));

                //如果下级物料是断面,分母就是1000
                if(bomDetail29s.Count() > 0)
                {
                    #region bomMaster
                    decimal masterQty = bomMaster.Qty; //30的原来的分母
                    bomMaster.Qty = 1000;
                    this.genericMgr.Update(bomMaster);
                    #endregion

                    #region BomDetail
                    var bomDetail29First = bomDetail29s.First();
                    bomDetail29First.EndDate = DateTime.Parse("9999-1-1");
                    this.genericMgr.Update(bomDetail29First);
                    var bomMaster29 = bomMasterDic.ValueOrDefault(bomDetail29First.Bom);
                    var bomDetail2_s = bomDetails.Where(p => !p.Item.StartsWith("29"));
                    var bomDetails29 = bomDetailDic.ValueOrDefault(bomDetail29First.Item) ?? new List<BomDetail>();
                    foreach(var bomDetail2_ in bomDetail2_s)
                    {
                        var bomDetail = bomDetails29.FirstOrDefault(p => p.Item == bomDetail2_.Item && p.Operation == bomDetail2_.Operation);

                        decimal rateQty = (bomDetail2_.RateQty / masterQty)
                                        * (bomMaster.Qty / bomDetail29First.RateQty)
                                        * bomMaster29.Qty;
                        if(bomDetail == null)
                        {
                            //Id	Bom	Item	Op	Uom	StartDate	EndDate	RateQty	ScrapPct
                            var newBomDetail = new BomDetail();
                            newBomDetail.Bom = bomDetail2_.Bom;
                            newBomDetail.Item = bomDetail2_.Item;
                            newBomDetail.Operation = bomDetail2_.Operation;
                            newBomDetail.Uom = bomDetail2_.Uom;
                            newBomDetail.StartDate = DateTime.Parse("2004-1-1");
                            newBomDetail.EndDate = DateTime.Parse("9999-1-1");
                            newBomDetail.RateQty = rateQty;
                            newBomDetail.ScrapPercentage = bomDetail2_.ScrapPercentage;
                            this.genericMgr.Create(newBomDetail);
                        }
                        else
                        {
                            if(bomDetail.Uom != bomDetail2_.Uom ||
                                bomDetail.RateQty != rateQty ||
                                bomDetail.ScrapPercentage != bomDetail2_.ScrapPercentage)
                            {
                                bomDetail.Uom = bomDetail2_.Uom;
                                bomDetail.RateQty = rateQty;
                                bomDetail.ScrapPercentage = bomDetail2_.ScrapPercentage;
                                bomDetail.StartDate = DateTime.Parse("2004-1-1");
                                bomDetail.EndDate = DateTime.Parse("9999-1-1");
                                this.genericMgr.Update(bomDetail);
                            }
                        }
                        bomDetail2_.EndDate = DateTime.Parse("2000-1-1");
                        this.genericMgr.Update(bomDetail2_);
                    }

                    foreach(var bomDetail in bomDetails29)
                    {
                        var dataRow = bomDetail2_s.FirstOrDefault(p => p.Item == bomDetail.Item && p.Operation == bomDetail.Operation);
                        if(dataRow == null)
                        {
                            bomDetail.EndDate = DateTime.Today;
                            this.genericMgr.Update(bomDetail);
                        }
                    }
                    #endregion
                }
                else if(bomDetail29s.Count() == 0 && bom.Key.StartsWith("30"))
                {
                    log.Error(string.Format(Resources.EXT.ServiceLan.BomNotHaveMatchedSection, bom.Key));
                }
            }
        }
Beispiel #4
0
 public ActionResult _New_Detail()
 {
     BomDetail bomDetail = new BomDetail();
     bomDetail.ScrapPercentage = 0;
     return PartialView(bomDetail);
 }
Beispiel #5
0
        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;
            }
        }
Beispiel #6
0
 private void TryLoadBomItem(BomDetail bomDetail)
 {
     if(bomDetail.CurrentItem == null)
     {
         bomDetail.CurrentItem = this.itemMgr.GetCacheItem(bomDetail.Item);//this.genericMgr.FindById<Item>(bomDetail.Item);
     }
 }
Beispiel #7
0
 private void NestingGetNextLevelBomDetail(IList<BomDetail> flatBomDetailList, BomDetail currentBomDetail, DateTime efftiveDate, bool isMrp)
 {
     NestingGetNextLevelBomDetail(flatBomDetailList, currentBomDetail.Item, currentBomDetail.Uom, currentBomDetail.UnitBomQty, currentBomDetail.CalculatedQty, efftiveDate, isMrp);
 }
Beispiel #8
0
        private void ProcessCurrentBomDetailItem(IList<BomDetail> flatBomDetailList, BomDetail currentBomDetail, DateTime efftiveDate, bool isMrp)
        {
            TryLoadBomItem(currentBomDetail);
            if(currentBomDetail.CurrentItem.IsVirtual)
            {
                //如果是虚零件(X),继续向下分解
                NestingGetNextLevelBomDetail(flatBomDetailList, currentBomDetail, efftiveDate, isMrp);
            }
            else if(currentBomDetail.CurrentItem.IsKit)
            {
                //组件,先拆分组件再继续向下分解
                //考虑组件的比例
                IList<ItemKit> itemKitList = itemMgr.GetKitItemChildren(currentBomDetail.Item);

                if(itemKitList != null && itemKitList.Count() > 0)
                {
                    foreach(ItemKit itemKit in itemKitList)
                    {
                        NestingGetNextLevelBomDetail(flatBomDetailList, itemKit.ChildItem.Code, currentBomDetail.Uom, (currentBomDetail.UnitBomQty * itemKit.Qty), (currentBomDetail.CalculatedQty * itemKit.Qty), efftiveDate, isMrp);
                    }
                }
                else
                {
                    throw new BusinessException("Errors.ItemKit.ChildrenItemNotFound", currentBomDetail.Item);
                }
            }
            else
            {
                //thinking:是否需要考虑某种零件不能作为BomDetail.Item

                //直接加入到flatBomDetailList
                flatBomDetailList.Add(currentBomDetail);
            }
        }
Beispiel #9
0
 private void ProcessCurrentBomDetailStructrue(IList<BomDetail> flatBomDetailList, BomDetail currentBomDetail, DateTime efftiveDate, bool isMrp)
 {
     if(currentBomDetail.StructureType == com.Sconit.CodeMaster.BomStructureType.Normal) //普通结构
     {
         ProcessCurrentBomDetailItem(flatBomDetailList, currentBomDetail, efftiveDate, isMrp);
     }
     else if(currentBomDetail.StructureType == com.Sconit.CodeMaster.BomStructureType.Virtual) //虚结构
     {
         //如果是虚结构(X),不把自己加到返回表里,继续向下分解
         NestingGetNextLevelBomDetail(flatBomDetailList, currentBomDetail, efftiveDate, isMrp);
     }
 }