Пример #1
0
        public ActionResult _Strategy(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return HttpNotFound();
            }

            FlowStrategy flowStrategy = this.flowMgr.GetFlowStrategy(id);
            if (flowStrategy == null)
            {
                flowStrategy = new FlowStrategy();
                flowStrategy.Flow = id;
            }
            ViewBag.NextWindowTime = flowStrategy.NextWindowTime;
            ViewBag.NextOrderTime = flowStrategy.NextOrderTime;
            ViewBag.WindowTimeType = flowStrategy.WindowTimeType;
            return PartialView(flowStrategy);
        }
Пример #2
0
 public ActionResult _Strategy(FlowStrategy flowStrategy)
 {
     ViewBag.WindowTimeType = flowStrategy.WindowTimeType;
     if (ModelState.IsValid)
     {
         flowMgr.UpdateFlowStrategy(flowStrategy);
         SaveSuccessMessage(Resources.SCM.FlowStrategy.FlowStrategy_Updated);
     }
     return PartialView(flowStrategy);
 }
Пример #3
0
        public void ImportFlow(Stream inputStream, CodeMaster.OrderType flowType)
        {
            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);

            #region 列定义
            // FlowMaster
            int colType = 1;//路线类型
            int colCode = 2; // 路线代码
            int colDesc = 3; // 路线描述


            // FlowDet
            int colItem = 4; // 物料
            int colUom = 5; // 单位
            int colUnitCount = 6; // 单包装
            int colUcDesc = 7; // 单包装
            int colMinStock = 8;//
            int colMaxStock = 9;//

            // FlowStrategy
            int colLeadTime = 10; // 提前期
            #endregion

            var errorMessage = new BusinessException();
            int colCount = 10;
            List<List<string>> rowDataList = new List<List<string>>();
            var items = this.genericMgr.FindAll<Item>().ToDictionary(d => d.Code, d => d);
            #region 读取数据
            while (rows.MoveNext())
            {
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 1, 8))
                {
                    break;//边界
                }
                colCount++;

                var rowData = new List<string>();

                #region FlowMaster
                rowData.Add("0");
                rowData.Add(((int)flowType).ToString());
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colCode)));
                if (string.IsNullOrWhiteSpace(rowData[2]))
                {
                    rowData[0] = "1";
                    errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowCodeShouldNotEmpty, colCount.ToString()));
                }
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colDesc)));
                if (string.IsNullOrWhiteSpace(rowData[3]))
                {
                    rowData[0] = "1";
                    errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.FlowDescShouldNotEmpty, colCount.ToString()));
                }
                #endregion

                #region FlowDetail
                Item item = null;
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colItem)));
                if (!string.IsNullOrWhiteSpace(rowData[4]))
                {
                    item = items.ValueOrDefault(rowData[4]);
                }
                if (item == null)
                {
                    rowData[0] = "1";
                    errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineItemNotFound,
                        colCount.ToString(), rowData[4]));
                    continue;
                }

                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUom)));
                if (string.IsNullOrWhiteSpace(rowData[5]))
                {
                    rowData[5] = item.Uom;
                }
                else
                {
                    try
                    {
                        Uom uom = this.genericMgr.FindById<Uom>(rowData[5].ToUpper());
                        rowData[5] = uom.Code;
                    }
                    catch (Exception)
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUomNotFound,
                            colCount.ToString(), rowData[5]));
                    }
                }
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUnitCount)));
                if (string.IsNullOrWhiteSpace(rowData[6]))
                {
                    rowData[6] = item.UnitCount.ToString();
                }
                else
                {
                    decimal unitCount = item.UnitCount;
                    if (!decimal.TryParse(rowData[6], out unitCount))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineUCIsNotNum, colCount.ToString()));
                    }
                    rowData[6] = unitCount == 0 ? item.UnitCount.ToString() : unitCount.ToString();
                }
                //7
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colUcDesc)));

                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMinStock)));
                if (string.IsNullOrWhiteSpace(rowData[8]))
                {
                    rowData[8] = "0";
                }
                else
                {
                    decimal decVal = 0m;
                    if (!decimal.TryParse(rowData[8], out decVal))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineSafeInvIsNotNum, colCount.ToString()));
                    }
                    rowData[8] = decVal.ToString();
                }

                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colMaxStock)));
                if (string.IsNullOrWhiteSpace(rowData[9]))
                {
                    rowData[9] = "0";
                }
                else
                {
                    decimal decVal = 0m;
                    if (!decimal.TryParse(rowData[9], out decVal))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineMaxInvIsNotNum, colCount.ToString()));
                    }
                    rowData[9] = decVal.ToString();
                }
                #endregion

                #region FlowStrategy
                rowData.Add(ImportHelper.GetCellStringValue(row.GetCell(colLeadTime)));
                if (string.IsNullOrWhiteSpace(rowData[10]))
                {
                    rowData[10] = "0";
                }
                else
                {
                    decimal leadTimeVal = 0m;
                    if (!decimal.TryParse(rowData[10], out leadTimeVal))
                    {
                        rowData[0] = "1";
                        errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error, Resources.EXT.ServiceLan.TheSpecialLineLeantimeIsNotNum, colCount.ToString()));
                    }
                    rowData[10] = leadTimeVal.ToString();
                }
                #endregion

                rowData.Add(item.Description);//11
                rowData.Add(item.Uom);//12
                rowData.Add(item.ReferenceCode);//13

                rowDataList.Add(rowData);
            }
            #endregion

            #region 验证

            //Excle中重复性验证
            var flowItems = rowDataList.Where(p => p[0] == "0")
                            .Select(p => new
                           {
                               Type = (CodeMaster.OrderType)(int.Parse(p[1])),
                               Flow = p[2],
                               FlowDescription = p[3],
                               Item = p[4],
                               Uom = p[5],
                               UnitCount = decimal.Parse(p[6]),
                               UcDesc = p[7],
                               MinStock = decimal.Parse(p[8]),
                               MaxStock = decimal.Parse(p[9]),
                               LeadTime = decimal.Parse(p[10]),
                               ItemDescription = p[11],
                               BaseUom = p[12],
                               ReferenceCode = p[13]
                           });

            if (flowItems == null || flowItems.Count() == 0)
            {
                errorMessage.AddMessage(Resources.EXT.ServiceLan.TheImportIsNotEffect);
                throw errorMessage;
            }
            var flowItemGroup = flowItems.GroupBy(p => new { p.Flow, p.Item, p.Uom, p.UnitCount }, (k, g) => new { k, Count = g.Count() })
                .Where(p => p.Count > 1).Select(p => new { p.k.Flow, p.k.Item });
            foreach (var flowItem in flowItemGroup)
            {
                errorMessage.AddMessage(new Message(com.Sconit.CodeMaster.MessageType.Error,
                    Resources.EXT.ServiceLan.DuplicateFlowDetail, flowItem.Flow, flowItem.Item));
            }

            var distinctFlowItems = flowItems.GroupBy(p => new { p.Flow, p.Item }, (k, g) => new { k, j = g.First() })
                .Select(p => p.j);

            var excelFlowMasterList = distinctFlowItems.GroupBy(p => p.Flow, (k, g) => new
                                    {
                                        Code = k,
                                        List = g
                                    });
            var flowMasterDic = this.genericMgr.FindAllIn<FlowMaster>("from FlowMaster where Code in(?",
                excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Code, d => d);

            var flowStrategyDic = this.genericMgr.FindAllIn<FlowStrategy>("from FlowStrategy where Flow in(?",
                excelFlowMasterList.Select(p => p.Code)).ToDictionary(d => d.Flow, d => d);

            var allParty = this.genericMgr.FindAll<Party>().ToDictionary(d => d.Code, d => d.Code);
            var allPriceList = this.genericMgr.FindAll<PriceListMaster>().ToDictionary(d => d.Code, d => d.Code);
            var allAddress = this.genericMgr.FindAll<Address>().ToDictionary(d => d.Code, d => d.Code);
            var allLocation = this.genericMgr.FindAll<Location>().ToDictionary(d => d.Code, d => d.Code);

            foreach (var excelFlowMaster in excelFlowMasterList)
            {
                var firstFlowItem = excelFlowMaster.List.First();
                var flowMaster = flowMasterDic.ValueOrDefault(excelFlowMaster.Code);
                var flowStrategy = flowStrategyDic.ValueOrDefault(excelFlowMaster.Code);

                if (flowType != firstFlowItem.Type)
                {
                    errorMessage.AddMessage(Resources.EXT.ServiceLan.FlowTypeIsNotCorrect, firstFlowItem.Type.ToString());
                    continue;
                }
                #region flowMaster
                if (flowMaster == null)
                {
                    #region FlowMaster赋值
                    var flowCodeSplits = excelFlowMaster.Code.Split('-');
                    var flowDescriptionSplits = firstFlowItem.FlowDescription.Split('-');
                    var newFlowMaster = new FlowMaster();
                    newFlowMaster.Code = excelFlowMaster.Code;
                    newFlowMaster.Type = firstFlowItem.Type;
                    newFlowMaster.Description = firstFlowItem.FlowDescription;

                    newFlowMaster.IsListDet = true;
                    newFlowMaster.IsPrintOrder = true;
                    newFlowMaster.IsPrintAsn = true;
                    newFlowMaster.IsPrintRceipt = true;
                    newFlowMaster.IsShipExceed = true;
                    newFlowMaster.IsShipFifo = true;
                    newFlowMaster.IsAllowProvEstRec = true;
                    newFlowMaster.ReceiveGapTo = CodeMaster.ReceiveGapTo.AdjectLocFromInv;
                    //Code	Desc1	IsActive	Type	RefFlow	PartyFrom	PartyTo	ShipFrom	ShipTo	LocFrom	LocTo	BillAddr	
                    //PriceList	Routing	ReturnRouting	Dock	IsAutoCreate	IsAutoRelease	IsAutoStart	IsAutoShip	IsAutoReceive
                    //IsAutoBill	IsListDet	IsManualCreateDet	IsListPrice	IsPrintOrder	IsPrintAsn	IsPrintRcpt	IsShipExceed	
                    //IsRecExceed	IsOrderFulfillUC	IsShipFulfillUC	IsRecFulfillUC	IsShipScanHu	IsRecScanHu	IsCreatePL	
                    //IsInspect	IsShipFifo	IsRejInspect	IsRecFifo	IsShipByOrder	IsAsnUniqueRec	IsMRP	IsCheckPartyFromAuth	
                    //IsCheckPartyToAuth	RecGapTo	RecTemplate	OrderTemplate	AsnTemplate	HuTemplate	BillTerm	CreateHuOpt	
                    //MaxOrderCount	MRPOpt	IsPause	PauseTime	FlowStrategy	ExtraDmdSource	PickStrategy	CreateUser	CreateUserNm
                    //CreateDate	LastModifyUser	LastModifyUserNm	LastModifyDate	DAUAT	LastRefreshDate	ResourceGroup	
                    //IsAllowProvEstRec	UcDeviation	OrderDeviation


                    if (firstFlowItem.Type == CodeMaster.OrderType.Procurement
                        || firstFlowItem.Type == CodeMaster.OrderType.CustomerGoods
                        || firstFlowItem.Type == CodeMaster.OrderType.SubContract)
                    {
                        newFlowMaster.PartyFrom = flowCodeSplits[0];
                        var location = this.genericMgr.FindById<Location>(flowCodeSplits[1]);
                        newFlowMaster.PartyTo = location.Region;
                        if (firstFlowItem.Type == CodeMaster.OrderType.SubContract)
                        {
                            newFlowMaster.LocationFrom = newFlowMaster.PartyFrom;
                        }
                        newFlowMaster.LocationTo = location.Code;
                        newFlowMaster.BillAddress = newFlowMaster.PartyFrom;
                        newFlowMaster.PriceList = newFlowMaster.PartyFrom;
                        newFlowMaster.IsReceiveScanHu = true;
                        newFlowMaster.OrderTemplate = "ORD_Purchase.xls";
                        newFlowMaster.AsnTemplate = "ASN_Purchase.xls";
                        newFlowMaster.ReceiptTemplate = "REC_Receipt.xls";
                        newFlowMaster.HuTemplate = "BarCodePurchase2D.xls";
                        newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement;
                        newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None;
                        newFlowMaster.IsListPrice = true;
                        newFlowMaster.IsAsnUniqueReceive = true;
                        newFlowMaster.IsAllowProvEstRec = true;
                    }
                    else if (firstFlowItem.Type == CodeMaster.OrderType.Distribution
                        || firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer)
                    {
                        var location = this.genericMgr.FindById<Location>(flowCodeSplits[0]);
                        newFlowMaster.LocationFrom = location.Code;
                        newFlowMaster.PartyFrom = location.Region;
                        newFlowMaster.PartyTo = flowCodeSplits[1];
                        if (firstFlowItem.Type == CodeMaster.OrderType.SubContractTransfer)
                        {
                            newFlowMaster.LocationTo = newFlowMaster.PartyTo;
                            newFlowMaster.OrderTemplate = "ASN_Transfer.xls";
                            newFlowMaster.AsnTemplate = "ASN_Transfer.xls";
                            newFlowMaster.ReceiptTemplate = "REC_InvOut.xls";
                            newFlowMaster.HuTemplate = "BarCodeMI2D.xls";
                        }
                        else
                        {
                            newFlowMaster.BillAddress = newFlowMaster.PartyTo;
                            newFlowMaster.PriceList = newFlowMaster.PartyTo;
                            newFlowMaster.OrderTemplate = "ORD_Sale.xls";
                            newFlowMaster.AsnTemplate = "ASN_Sale.xls";
                            newFlowMaster.ReceiptTemplate = "REC_Sale.xls";
                            newFlowMaster.HuTemplate = "BarCodeFI2D.xls";
                            newFlowMaster.BillTerm = CodeMaster.OrderBillTerm.ReceivingSettlement;
                            newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None;
                        }
                        newFlowMaster.IsRejectInspect = true;
                        newFlowMaster.IsShipScanHu = true;
                        newFlowMaster.IsCreatePickList = false;

                    }
                    else if (firstFlowItem.Type == CodeMaster.OrderType.Production)
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheProdLineNotFound, excelFlowMaster.Code);
                    }
                    else if (firstFlowItem.Type == CodeMaster.OrderType.Transfer)
                    {
                        var locationFrom = this.genericMgr.FindById<Location>(flowCodeSplits[0]);
                        var locationTo = this.genericMgr.FindById<Location>(flowCodeSplits[1]);
                        newFlowMaster.PartyFrom = locationFrom.Region;
                        newFlowMaster.PartyTo = locationTo.Region;
                        newFlowMaster.LocationFrom = locationFrom.Code;
                        newFlowMaster.LocationTo = locationTo.Code;
                        newFlowMaster.IsShipScanHu = true;
                        newFlowMaster.IsReceiveScanHu = true;
                        newFlowMaster.IsCreatePickList = false;
                        newFlowMaster.OrderTemplate = "ASN_Transfer.xls";
                        newFlowMaster.AsnTemplate = "ASN_Transfer.xls";
                        newFlowMaster.ReceiptTemplate = "REC_InvOut.xls";
                        newFlowMaster.HuTemplate = "BarCodeEX2D.xls";
                        newFlowMaster.CreateHuOption = CodeMaster.CreateHuOption.None;
                    }
                    newFlowMaster.ShipFrom = newFlowMaster.PartyFrom;
                    newFlowMaster.ShipTo = newFlowMaster.PartyTo;
                    #endregion

                    #region 校验
                    bool isMark = false;
                    if (!allParty.ContainsKey(newFlowMaster.PartyFrom))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyFromNotFound, newFlowMaster.PartyFrom);
                        isMark = true;
                    }
                    if (!allParty.ContainsKey(newFlowMaster.PartyTo))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePartyToNotFound, newFlowMaster.PartyTo);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationFrom) && !allLocation.ContainsKey(newFlowMaster.LocationFrom))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocFromNotFound, newFlowMaster.LocationFrom);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.LocationTo) && !allLocation.ContainsKey(newFlowMaster.LocationTo))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheLocToNotFound, newFlowMaster.LocationTo);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.PriceList) && !allPriceList.ContainsKey(newFlowMaster.PriceList))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.ThePriceListNotFound, newFlowMaster.PriceList);
                        isMark = true;
                    }
                    if (!string.IsNullOrWhiteSpace(newFlowMaster.BillAddress) && !allAddress.ContainsKey(newFlowMaster.BillAddress))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheBillAddrNotFound, newFlowMaster.BillAddress);
                        isMark = true;
                    }
                    if (!allAddress.ContainsKey(newFlowMaster.ShipFrom))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipAddrNotFound, newFlowMaster.ShipFrom);
                        isMark = true;
                    }
                    if (!allAddress.ContainsKey(newFlowMaster.ShipTo))
                    {
                        errorMessage.AddMessage(Resources.EXT.ServiceLan.TheShipToNotFound, newFlowMaster.ShipTo);
                        isMark = true;
                    }
                    #endregion

                    if (!isMark && !errorMessage.HasMessage)
                    {
                        try
                        {
                            this.genericMgr.Create(newFlowMaster);
                        }
                        catch (Exception ex)
                        {
                            errorMessage.AddMessage(ex.Message);
                        }
                    }
                }
                else
                {
                    if (flowMaster.Description != firstFlowItem.FlowDescription && !errorMessage.HasMessage)
                    {
                        flowMaster.Description = firstFlowItem.FlowDescription;
                        this.genericMgr.Update(flowMaster);
                    }
                }
                #endregion

                #region FlowStrategy
                if (!errorMessage.HasMessage)
                {
                    if (flowStrategy == null)
                    {
                        //Flow	Strategy	Desc1	LeadTime	EmLeadTime	TimeUnit	
                        var newFlowStrategy = new FlowStrategy();
                        newFlowStrategy.Flow = excelFlowMaster.Code;
                        newFlowStrategy.Description = firstFlowItem.FlowDescription;
                        newFlowStrategy.LeadTime = firstFlowItem.LeadTime;
                        newFlowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour;
                        this.genericMgr.Create(newFlowStrategy);
                    }
                    else
                    {
                        flowStrategy.LeadTime = firstFlowItem.LeadTime;
                        this.genericMgr.Update(flowStrategy);
                    }
                }
                #endregion

                #region FlowDetail
                if (!errorMessage.HasMessage)
                {
                    var flowDetailDic = this.genericMgr.FindAllIn<FlowDetail>
                        ("from FlowDetail where Flow = ? and Item in(? ",
                        excelFlowMaster.List.Select(p => p.Item), new object[] { excelFlowMaster.Code })
                        .GroupBy(p => p.Item, (k, g) => new { Item = k, FlowDetails = g })
                        .ToDictionary(d => d.Item, d => d.FlowDetails);
                    var maxSeq = 10;
                    var maxItemSeq = this.genericMgr.FindAllIn<FlowDetail>
                        ("from FlowDetail where Flow = ? ", new object[] { excelFlowMaster.Code }).Select(p => p.Sequence).Max();
                    if (flowDetailDic.Values != null && flowDetailDic.Values.Count > 0)
                    {
                        maxSeq = flowDetailDic.Values.Max(p => p.Max(q => q.Sequence));
                    }
                    foreach (var flowItem in excelFlowMaster.List)
                    {
                        //Id	Flow	Seq	Item	RefItemCode	Uom	BaseUom	UC	UCDesc	MinUC	StartDate	EndDate	Bom	LocFrom	LocTo	
                        //BillAddr	PriceList	Routing	ReturnRouting	Strategy	ProdScan	Container	ContainerDesc	IsAutoCreate	
                        //IsInspect	IsRejInspect	SafeStock	MaxStock	MinLotSize	OrderLotSize	RecLotSize	BatchSize	RoundUpOpt	
                        //BillTerm	MrpWeight	MrpTotal	MrpTotalAdj	ExtraDmdSource	PickStrategy	EBELN	EBELP	CreateUser	
                        //CreateUserNm	CreateDate	LastModifyUser	LastModifyUserNm	LastModifyDate	BinTo	IsChangeUC	Machine	Uom1
                        //var item = this.genericMgr.FindById<Item>(flowItem.Item);
                        try
                        {
                            //todo check Details
                            var flowDetail = (flowDetailDic.ValueOrDefault(flowItem.Item) ?? new List<FlowDetail>())
                                .FirstOrDefault(p => p.UnitCount == flowItem.UnitCount);
                            if (flowDetail == null)
                            {
                                var newFlowDetail = new FlowDetail();
                                newFlowDetail.Flow = flowItem.Flow;
                                newFlowDetail.Item = flowItem.Item;
                                newFlowDetail.BaseUom = flowItem.BaseUom;
                                newFlowDetail.Uom = flowItem.Uom;
                                //newFlowDetail.ReferenceItemCode = flowItem.ReferenceCode;
                                newFlowDetail.UnitCount = flowItem.UnitCount;
                                newFlowDetail.MinUnitCount = flowItem.UnitCount;
                                newFlowDetail.UnitCountDescription = flowItem.UcDesc;
                                newFlowDetail.Sequence = maxSeq+maxItemSeq;
                                newFlowDetail.SafeStock = flowItem.MinStock;
                                newFlowDetail.MaxStock = flowItem.MaxStock;
                                newFlowDetail.MrpWeight = 1;
                                newFlowDetail.RoundUpOption = Sconit.CodeMaster.RoundUpOption.ToUp;
                                maxSeq += 10;
                                this.genericMgr.Create(newFlowDetail);
                            }
                            else
                            {
                                flowDetail.BaseUom = flowItem.BaseUom;
                                flowDetail.Uom = flowItem.Uom;
                                flowDetail.UnitCount = flowItem.UnitCount;
                                flowDetail.MinUnitCount = flowItem.UnitCount;
                                flowDetail.UnitCountDescription = flowItem.UcDesc;
                                flowDetail.SafeStock = flowItem.MinStock;
                                flowDetail.MaxStock = flowItem.MaxStock;
                                this.genericMgr.Update(flowDetail);
                            }
                        }
                        catch (Exception ex)
                        {
                            errorMessage.AddMessage(ex.Message);
                        }
                    }
                }
                #endregion
            }
            #endregion

            if (errorMessage.HasMessage)
            {
                throw errorMessage;
            }
        }
Пример #4
0
        public IList<SequenceMaster> CreateSequenceOrderByFlow(FlowStrategy flowStrategy, IList<object[]> orderDetailAryList)
        {
            try
            {
                if (orderDetailAryList != null && orderDetailAryList.Count > 0)
                {
                    //待排序队列
                    IList<object[]> waitOrderDetailAryList = new List<object[]>();

                    #region 把排序单中数量大于1的排序件拆分为每个排序件数量为1
                    foreach (object[] orderDetailAry in orderDetailAryList)
                    {
                        //待排序零件的数量
                        decimal thisOrderDetailQty = (decimal)orderDetailAry[48];
                        //已收货排序件的数量
                        decimal thisShippedQty = (decimal)orderDetailAry[49];
                        //已经生成排序装箱单单的数量
                        int thisSequencedQty = (int)orderDetailAry[50];

                        for (int i = 0; i < thisOrderDetailQty; i++)
                        {
                            //复制一条排序信息
                            //object[] waitOrderDetailAry = Mapper.Map<object[], object[]>(orderDetailAry);
                            object[] waitOrderDetailAry = new object[orderDetailAry.Length];
                            for (int j = 0; j < orderDetailAry.Length; j++)
                            {
                                waitOrderDetailAry[j] = orderDetailAry[j];
                            }

                            //数量置为1
                            waitOrderDetailAry[48] = (decimal)1;

                            //先占用已收货数量,不够在占用已排序数量
                            //如果剩余已收货数量大于零,收货数置为1,代表不需要在配送
                            if (thisShippedQty > 0)
                            {
                                //已收货数量设为1
                                waitOrderDetailAry[49] = (decimal)1;
                                //已排序数量设为0
                                waitOrderDetailAry[50] = (decimal)0;
                                thisShippedQty--;
                            }
                            else
                            {
                                //已收货数量设为0
                                waitOrderDetailAry[49] = (decimal)0;

                                //如果剩余已排序数量大于零,排序数置为1,代表不需要在配送
                                if (thisSequencedQty > 0)
                                {
                                    //已排序数量设为1
                                    waitOrderDetailAry[50] = (decimal)1;
                                    thisSequencedQty--;
                                }
                                else
                                {
                                    //已排序数量设为0
                                    waitOrderDetailAry[50] = (decimal)0;
                                }
                            }

                            //添加排序信息至等待列表中
                            waitOrderDetailAryList.Add(waitOrderDetailAry);
                        }
                    }
                    #endregion

                    IList<SequenceMaster> sequenceMasterList = new List<SequenceMaster>();

                    #region 旧逻辑
                    //#region 符合等待批量创建
                    //int count = waitOrderDetailAryList.Count / flowStrategy.WaitBatch;

                    //for (int i = 0; i < count; i++)
                    //{
                    //    IList<object[]> batchWaitOrderDetailAryList = waitOrderDetailAryList.Skip(flowStrategy.WaitBatch * i).Take(flowStrategy.WaitBatch).ToList();
                    //    SequenceMaster sequenceMaster = CreateSequenceOrder(batchWaitOrderDetailAryList);
                    //    if (sequenceMaster != null)
                    //    {
                    //        sequenceMasterList.Add(sequenceMaster);
                    //    }
                    //}
                    //#endregion

                    //#region 符合等待时间创建
                    //if (flowStrategy.WaitBatch * count < waitOrderDetailAryList.Count())
                    //{
                    //    IList<object[]> batchWaitOrderDetailAryList = waitOrderDetailAryList.Skip(count * flowStrategy.WaitBatch).Take(waitOrderDetailAryList.Count() - count * flowStrategy.WaitBatch).ToList();
                    //    //第一条不符合等待批量的订单
                    //    object[] firstWaitOrderDetailAry = batchWaitOrderDetailAryList.First();

                    //    if (firstWaitOrderDetailAry != null && (DateTime)firstWaitOrderDetailAry[4] < DateTime.Now)  //没有等待时间的概念,只要第一张订单的开始时间小于当前时间
                    //    {
                    //        SequenceMaster sequenceMaster = CreateSequenceOrder(batchWaitOrderDetailAryList);
                    //        if (sequenceMaster != null)
                    //        {
                    //            sequenceMasterList.Add(sequenceMaster);
                    //        }
                    //    }
                    //}
                    //#endregion
                    #endregion

                    #region 新逻辑
                    while (waitOrderDetailAryList != null && waitOrderDetailAryList.Count > 0)
                    {
                        object[] firstWaitOrderDetailAry = waitOrderDetailAryList.First();
                        if (firstWaitOrderDetailAry != null && (DateTime)firstWaitOrderDetailAry[4] < DateTime.Now)  //没有等待时间的概念,只要第一张订单的开始时间小于当前时间
                        {
                            SequenceMaster sequenceMaster = CreateSequenceOrder(waitOrderDetailAryList.Take(waitOrderDetailAryList.Count > flowStrategy.WaitBatch ? flowStrategy.WaitBatch : waitOrderDetailAryList.Count).ToList());
                            if (sequenceMaster != null)
                            {
                                sequenceMasterList.Add(sequenceMaster);
                                waitOrderDetailAryList = waitOrderDetailAryList.Skip(sequenceMaster.SequenceDetails.Count).ToList();
                            }
                            else
                            {
                                waitOrderDetailAryList = null;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    #endregion

                    this.genericMgr.FlushSession();

                    return sequenceMasterList;
                }
            }
            catch (Exception ex)
            {
                log.Error("Fail generate sequence order.", ex);
                this.genericMgr.CleanSession();
            }

            return null;
        }
Пример #5
0
        public void UpdateFlowStrategy(FlowStrategy flowstrategy)
        {
            FlowStrategy oldFlowStrategy = genericMgr.FindById<FlowStrategy>(flowstrategy.Flow);
            if (oldFlowStrategy.Strategy != flowstrategy.Strategy)
            {
                #region 反向更新FlowMaster上的策略
                FlowMaster flowMaster = genericMgr.FindById<FlowMaster>(flowstrategy.Flow);
                flowMaster.FlowStrategy = flowstrategy.Strategy;
                genericMgr.Update(flowMaster);
            }

            //默认取小时,以后再改
            Mapper.Map<FlowStrategy, FlowStrategy>(flowstrategy, oldFlowStrategy);
            //oldFlowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour;
            genericMgr.Update(oldFlowStrategy);

                #endregion
        }
Пример #6
0
        public void CreateFlow(FlowMaster flowMaster)
        {
            genericMgr.Create(flowMaster);

            #region flow strategy
            FlowStrategy flowStrategy = new FlowStrategy();
            flowStrategy.Flow = flowMaster.Code;
            flowStrategy.Strategy = flowMaster.FlowStrategy;
            flowStrategy.Description = flowMaster.Description;
            //默认取小时,以后再改
            flowStrategy.TimeUnit = CodeMaster.TimeUnit.Hour;
            genericMgr.Create(flowStrategy);
            #endregion
        }
        public ActionResult _Strategy(FlowStrategy flowStrategy)
        {
            ViewBag.WindowTimeType = flowStrategy.WindowTimeType;
            if (ModelState.IsValid)
            {
                var hasError = false;
                //if (flowStrategy.WindowTimeType == CodeMaster.WindowTimeType.FixedWindowTime)
                //{
                //    if (string.IsNullOrWhiteSpace(flowStrategy.WindowTime1) &&
                //    string.IsNullOrWhiteSpace(flowStrategy.WindowTime2) && string.IsNullOrWhiteSpace(flowStrategy.WindowTime3) &&
                //    string.IsNullOrWhiteSpace(flowStrategy.WindowTime4) && string.IsNullOrWhiteSpace(flowStrategy.WindowTime5) &&
                //    string.IsNullOrWhiteSpace(flowStrategy.WindowTime6) && string.IsNullOrWhiteSpace(flowStrategy.WindowTime7))
                //    {
                //        hasError = true;
                //        SaveErrorMessage(Resources.SCM.FlowStrategy.FlowStrategy_WhenCheckFixedTypeWindowTimeCanNotAllEmpty);
                //    }
                //}
                if (flowStrategy.WindowTimeType == CodeMaster.WindowTimeType.CycledWindowTime)
                {
                    if ((flowStrategy.Strategy == CodeMaster.FlowStrategy.JIT || flowStrategy.Strategy == CodeMaster.FlowStrategy.KB) && flowStrategy.WinTimeInterval <= 0)
                    {
                        hasError = true;
                        SaveErrorMessage(Resources.SCM.FlowStrategy.FlowStrategy_WinTimeIntervalCanNotLessThanZero);
                    }
                }

                if (!hasError)
                {
                    flowMgr.UpdateFlowStrategy(flowStrategy);
                    SaveSuccessMessage(Resources.SCM.FlowStrategy.FlowStrategy_Updated);
                }
            }
            return PartialView(flowStrategy);
        }
        public ActionResult ImportShipOrderTime(IEnumerable<HttpPostedFileBase> attachments)
        {
            try
            {
                IList<FlowStrategy> flowStrategyList = new List<FlowStrategy>();
                foreach (var file in attachments)
                {

                    if (file.InputStream.Length == 0)
                    {
                        throw new BusinessException("Import.Stream.Empty");
                    }

                    HSSFWorkbook workbook = new HSSFWorkbook(file.InputStream);

                    ISheet sheet = workbook.GetSheetAt(0);
                    IEnumerator rows = sheet.GetRowEnumerator();

                    BusinessException businessException = new BusinessException();

                    ImportHelper.JumpRows(rows, 10);

                    #region 列定义
                    int colWindowTime = 1;//窗口时间
                    int colRegion = 2;//区域
                    int colleadTime = 3;//发单提前期
                    int colWinTimeDiff = 4;// 进料提前期
                    int colSafeTime = 5;// 安全提前期
                    int colCalculateType = 6;//计算类型
                    #endregion

                    DateTime dateTimeNow = DateTime.Now;

                    int rowCount = 10;


                    while (rows.MoveNext())
                    {
                        rowCount++;
                        HSSFRow row = (HSSFRow)rows.Current;
                        if (!ImportHelper.CheckValidDataRow(row, 1, 6))
                        {
                            break;//边界
                        }
                        FlowStrategy flowStrategy = new FlowStrategy();
                        DateTime windowTime = System.DateTime.Now;
                        string regionCode = string.Empty;
                        decimal leadTime = 0;
                        decimal winTimeDiff = 0;
                        decimal safeTime = 0;
                        string calculateType = string.Empty;

                        #region 读取数据
                        #region 计算类型
                        calculateType = ImportHelper.GetCellStringValue(row.GetCell(colCalculateType));
                        if (string.IsNullOrWhiteSpace(calculateType))
                        {
                            businessException.AddMessage(string.Format("第{0}行:计算类型不能为空。", rowCount));
                            continue;
                        }
                        else
                        {
                            flowStrategy.CalculateType = calculateType;
                        }
                        #endregion

                        #region 读取区域
                        regionCode = ImportHelper.GetCellStringValue(row.GetCell(colRegion));
                        if (string.IsNullOrWhiteSpace(regionCode))
                        {
                            businessException.AddMessage(string.Format("第{0}行:区域不能为空。", rowCount));
                            flowStrategyList.Add(flowStrategy);
                            continue;
                        }
                        else
                        {
                            IList<Region> regionList = genericMgr.FindAll<Region>("select l from Region as l where l.Code=?", regionCode);
                            if (regionList != null && regionList.Count > 0)
                            {
                                flowStrategy.Region = regionCode;
                            }
                            else
                            {
                                businessException.AddMessage(string.Format("第{0}行:区域{1}不存在", rowCount, regionCode));
                                flowStrategyList.Add(flowStrategy);
                                continue;
                            }
                        }

                        #endregion

                        #region 窗口时间

                        string readWindowTime = ImportHelper.GetCellStringValue(row.GetCell(colWindowTime));
                        if (string.IsNullOrWhiteSpace(readWindowTime))
                        {
                            businessException.AddMessage(string.Format("第{0}行:窗口时间不能为空。", rowCount));
                            flowStrategyList.Add(flowStrategy);
                            continue;
                        }
                        else
                        {
                            if (!DateTime.TryParse(readWindowTime, out windowTime))
                            {
                                businessException.AddMessage(string.Format("第{0}行:窗口时间{1}填写有误", rowCount, readWindowTime));
                                flowStrategyList.Add(flowStrategy);
                                continue;
                            }
                            var workingCalendars = this.genericMgr.FindAll<WorkingCalendar>(" select w from WorkingCalendar as w where w.Region=? and w.WorkingDate=? ", new object[] { regionCode, windowTime.Date });
                            if (workingCalendars != null && workingCalendars.Count > 0)
                            {
                                if (workingCalendars.First().Type == com.Sconit.CodeMaster.WorkingCalendarType.Rest)
                                {
                                    businessException.AddMessage(string.Format("第{0}行:窗口时间{1}是休息时间,请确认。", rowCount, readWindowTime));
                                    flowStrategyList.Add(flowStrategy);
                                    continue;
                                }
                                var shiftDet = this.genericMgr.FindAll<ShiftDetail>(" select s from ShiftDetail as s where s.Shift=? ", new object[] { workingCalendars.FirstOrDefault().Shift });
                                if (shiftDet != null || shiftDet.Count > 0)
                                {
                                    DateTime nowTime = windowTime;
                                    bool isTure = false;
                                    foreach (var det in shiftDet)
                                    {
                                        DateTime prevTime = this.ParseDateTime(det.StartTime, windowTime);
                                        DateTime nextTime = this.ParseDateTime(det.EndTime, windowTime);
                                        if (nextTime < prevTime) nextTime = nextTime.AddDays(1);
                                        if (nowTime >= prevTime && nowTime <= nextTime)
                                        {
                                            isTure = true;
                                            break;
                                        }

                                    }
                                    if (!isTure)
                                    {
                                        businessException.AddMessage(string.Format("窗口时间{0}是休息时间,请确认。", windowTime));
                                        flowStrategyList.Add(flowStrategy);
                                        continue;
                                    }
                                }
                                else
                                {
                                    businessException.AddMessage(string.Format("没有找到区域的工作日历。"));
                                }
                            }
                        }
                        flowStrategy.WindowTime = windowTime;
                        #endregion

                        if (flowStrategy.CalculateType == "0")
                        {
                            #region 发单提前期
                            try
                            {
                                string leadTimeRead = ImportHelper.GetCellStringValue(row.GetCell(colleadTime));
                                leadTime = Convert.ToDecimal(leadTimeRead);
                                flowStrategy.LeadTime = leadTime;
                                if (windowTime <= windowTime.Date.AddHours(8) && windowTime >= windowTime.Date) { windowTime = windowTime.AddDays(-1); }
                                flowStrategy.ShipOrderTime = GetShipOrderTime(windowTime, Convert.ToDouble(leadTime) * 60, regionCode, flowStrategy.CalculateType);
                                //IList<WorkingCalendarView> workingCalendarViewList = this.workingCalendarMgr.GetWorkingCalendarView(regionCode, windowTime.Add(TimeSpan.FromDays(-7)), windowTime);
                                //flowStrategy.ShipOrderTime = this.workingCalendarMgr.GetStartTimeAtWorkingDate(windowTime, Convert.ToDouble(leadTime), CodeMaster.TimeUnit.Hour, regionCode, workingCalendarViewList);
                            }
                            catch
                            {
                                businessException.AddMessage(string.Format("第{0}行:发单提前期{1}填写有误", rowCount, leadTime));
                                flowStrategyList.Add(flowStrategy);
                                continue;
                            }
                            #endregion
                        }
                        else if (flowStrategy.CalculateType == "1")
                        {
                            #region 进料提前期
                            try
                            {
                                winTimeDiff = Convert.ToDecimal(ImportHelper.GetCellStringValue(row.GetCell(colWinTimeDiff)));
                                flowStrategy.WinTimeDiff = winTimeDiff;
                                if (windowTime <= windowTime.Date.AddHours(8) && windowTime >= windowTime.Date) { windowTime = windowTime.AddDays(-1); }
                                flowStrategy.ReqStartTime = GetShipOrderTime(windowTime, Convert.ToDouble(winTimeDiff) * 60, regionCode, flowStrategy.CalculateType);
                                //IList<WorkingCalendarView> workingCalendarViewList = this.workingCalendarMgr.GetWorkingCalendarView(regionCode, windowTime, windowTime.Add(TimeSpan.FromDays(7)));
                                //flowStrategy.ShipOrderTime = this.workingCalendarMgr.GetStartTimeAtWorkingDate(windowTime, Convert.ToDouble(-winTimeDiff), CodeMaster.TimeUnit.Hour, regionCode, workingCalendarViewList);

                            }
                            catch
                            {
                                businessException.AddMessage(string.Format("第{0}行:进料提前期{1}填写有误", rowCount, winTimeDiff));
                                flowStrategyList.Add(flowStrategy);
                                continue;
                            }
                            #endregion

                        }
                        else if (flowStrategy.CalculateType == "2")
                        {
                            #region 进料提前期
                            try
                            {
                                winTimeDiff = Convert.ToDecimal(ImportHelper.GetCellStringValue(row.GetCell(colWinTimeDiff)));
                                flowStrategy.WinTimeDiff = winTimeDiff;
                            }
                            catch
                            {
                                businessException.AddMessage(string.Format("第{0}行:进料提前期{1}填写有误", rowCount, winTimeDiff));
                                flowStrategyList.Add(flowStrategy);
                                continue;
                            }
                            #endregion

                            #region 安全提前期
                            try
                            {
                                safeTime = Convert.ToDecimal(ImportHelper.GetCellStringValue(row.GetCell(colSafeTime)));
                                flowStrategy.SafeTime = safeTime;
                            }
                            catch
                            {
                                businessException.AddMessage(string.Format("第{0}行:安全提前期{1}填写有误", rowCount, safeTime));
                                flowStrategyList.Add(flowStrategy);
                                continue;
                            }
                            #endregion

                            if (windowTime <= windowTime.Date.AddHours(8) && windowTime >= windowTime.Date) { windowTime = windowTime.AddDays(-1); }
                            flowStrategy.ReqEndTime = GetShipOrderTime(windowTime, Convert.ToDouble(flowStrategy.WinTimeDiff + flowStrategy.SafeTime) * 60, regionCode, flowStrategy.CalculateType);
                        }

                        #region 填充数据
                        flowStrategyList.Add(flowStrategy);
                        #endregion

                    }

                        #endregion
                    TempData["ShipOrderTimeView"] = flowStrategyList;

                    if (businessException.HasMessage)
                    {
                        throw businessException;
                    }
                }
            }
            catch (BusinessException ex)
            {
                SaveBusinessExceptionMessage(ex);
            }
            catch (Exception ex)
            {
                SaveErrorMessage("导入失败。 - " + ex.Message);
            }
            return Content(string.Empty);
        }
        public ActionResult _Strategy(FlowStrategy flowStrategy)
        {
            ViewBag.WindowTimeType = flowStrategy.WindowTimeType;
            if (ModelState.IsValid)
            {
                var hasError = false;
                if (flowStrategy.Strategy == CodeMaster.FlowStrategy.JIT || flowStrategy.Strategy == CodeMaster.FlowStrategy.KB)
                {
                    if (flowStrategy.WindowTimeType == CodeMaster.WindowTimeType.FixedWindowTime)
                    {
                        if (string.IsNullOrWhiteSpace(flowStrategy.WindowTime1) &&
                        string.IsNullOrWhiteSpace(flowStrategy.WindowTime2) && string.IsNullOrWhiteSpace(flowStrategy.WindowTime3) &&
                        string.IsNullOrWhiteSpace(flowStrategy.WindowTime4) && string.IsNullOrWhiteSpace(flowStrategy.WindowTime5) &&
                        string.IsNullOrWhiteSpace(flowStrategy.WindowTime6) && string.IsNullOrWhiteSpace(flowStrategy.WindowTime7))
                        {
                            hasError = true;
                            SaveErrorMessage(Resources.SCM.FlowStrategy.FlowStrategy_WhenCheckFixedTypeWindowTimeCanNotAllEmpty);
                        }
                    }
                    else
                    {
                        if (flowStrategy.WeekInterval <= 0)
                        {
                            hasError = true;
                            SaveErrorMessage(Resources.SCM.FlowStrategy.FlowStrategy_WeekIntervalCanNotLessThanZero);
                        }
                    }
                }

                if (flowStrategy.Strategy == CodeMaster.FlowStrategy.SEQ)
                {
                    if (string.IsNullOrWhiteSpace(flowStrategy.SeqGroup))
                    {
                        hasError = true;
                        SaveErrorMessage(Resources.ErrorMessage.Errors_Common_FieldRequired, Resources.SCM.FlowStrategy.FlowStrategy_SeqGroup);
                    }
                }

                if (!hasError)
                {
                    flowMgr.UpdateFlowStrategy(flowStrategy);
                    SaveSuccessMessage(Resources.SCM.FlowStrategy.FlowStrategy_Updated);
                }
            }
            return PartialView(flowStrategy);
        }