예제 #1
0
        public virtual IList <PackSet> Pack(OrderInfo orderInfo)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Dictionary <int, List <INItemBoxEx> > boxesByInventory = new Dictionary <int, List <INItemBoxEx> >();

            foreach (ItemInfo itemInfo in orderInfo.Lines)
            {
                boxesByInventory.Add(itemInfo.InventoryID, GetBoxesByInventoryID(itemInfo.InventoryID, orderInfo.CarrierID));
            }

            Dictionary <int, PackSet> list = new Dictionary <int, PackSet>();

            foreach (ItemStats stat in orderInfo.Stats)
            {
                PackSet ps = null;
                if (list.ContainsKey(stat.SiteID.Value))
                {
                    ps = list[stat.SiteID.Value];
                }
                else
                {
                    ps = new PackSet(stat.SiteID.Value);
                    list.Add(ps.SiteID, ps);
                }

                if (stat.PackOption == INPackageOption.Quantity)
                {
                    List <INItemBoxEx> boxes = boxesByInventory[stat.InventoryID.Value];
                    ps.Packages.AddRange(PackByQty(boxes, stat));
                }

                if (stat.PackOption == INPackageOption.Weight || stat.PackOption == INPackageOption.WeightAndVolume)
                {
                    if (stat.InventoryID == ItemStats.Mixed)
                    {
                        Dictionary <string, INItemBoxEx> allboxes      = new Dictionary <string, INItemBoxEx>();
                        Dictionary <string, List <int> > boxItemLookup = new Dictionary <string, List <int> >();

                        foreach (ItemInfo item in stat.Lines)
                        {
                            List <INItemBoxEx> boxes = boxesByInventory[item.InventoryID];
                            foreach (INItemBoxEx box in boxes)
                            {
                                if (!allboxes.ContainsKey(box.BoxID))
                                {
                                    allboxes.Add(box.BoxID, box);
                                }

                                if (!boxItemLookup.ContainsKey(box.BoxID))
                                {
                                    boxItemLookup.Add(box.BoxID, new List <int>());
                                }
                                boxItemLookup[box.BoxID].Add(item.InventoryID);
                            }
                        }


                        ps.Packages.AddRange(PackByWeightMixedItems(new List <INItemBoxEx>(allboxes.Values), new List <ItemInfo>(stat.Lines), boxesByInventory, boxItemLookup, stat.PackOption == INPackageOption.WeightAndVolume, stat.SiteID, stat.DeclaredValue));
                    }
                    else
                    {
                        List <INItemBoxEx> boxes = boxesByInventory[stat.InventoryID.Value];
                        ps.Packages.AddRange(PackByWeight(boxes, stat));
                    }
                }
            }

            sw.Stop();
            Debug.Print("SOPackageEngine.Pack() in {0} millisec.", sw.ElapsedMilliseconds);
            return(list.Values.ToList());
        }
예제 #2
0
		public virtual IList<PackSet> Pack(OrderInfo orderInfo)
		{
			Stopwatch sw = new Stopwatch();
			sw.Start();

			Dictionary<int, List<INItemBoxEx>> boxesByInventory = new Dictionary<int, List<INItemBoxEx>>();
			
			foreach (ItemInfo itemInfo in orderInfo.Lines)
			{
				boxesByInventory.Add( itemInfo.InventoryID, GetBoxesByInventoryID(itemInfo.InventoryID, orderInfo.CarrierID));
			}
			
			Dictionary<int, PackSet> list = new Dictionary<int, PackSet>();

			foreach (ItemStats stat in orderInfo.Stats)
			{
				PackSet ps = null;
				if (list.ContainsKey(stat.SiteID.Value))
				{
					ps = list[stat.SiteID.Value];
				}
				else
				{
					ps = new PackSet(stat.SiteID.Value);
					list.Add(ps.SiteID, ps);
				}

				if (stat.PackOption == INPackageOption.Quantity)
				{
					List<INItemBoxEx> boxes = boxesByInventory[stat.InventoryID.Value];
					ps.Packages.AddRange(PackByQty(boxes, stat));
				}

				if (stat.PackOption == INPackageOption.Weight || stat.PackOption == INPackageOption.WeightAndVolume)
				{
					if (stat.InventoryID == ItemStats.Mixed)
					{
						Dictionary<string, INItemBoxEx> allboxes = new Dictionary<string, INItemBoxEx>();
						Dictionary<string, List<int>> boxItemLookup = new Dictionary<string, List<int>>();

						foreach (ItemInfo item in stat.Lines)
						{
							List<INItemBoxEx> boxes = boxesByInventory[item.InventoryID];
							foreach (INItemBoxEx box in boxes)
							{
								if (!allboxes.ContainsKey(box.BoxID))
								{
									allboxes.Add(box.BoxID, box);
								}

								if (!boxItemLookup.ContainsKey(box.BoxID))
								{
									boxItemLookup.Add(box.BoxID, new List<int>());
								}
								boxItemLookup[box.BoxID].Add(item.InventoryID);
							}
						}


						ps.Packages.AddRange(PackByWeightMixedItems(new List<INItemBoxEx>(allboxes.Values), new List<ItemInfo>(stat.Lines), boxesByInventory, boxItemLookup, stat.PackOption == INPackageOption.WeightAndVolume, stat.SiteID));
					}
					else
					{
						List<INItemBoxEx> boxes = boxesByInventory[stat.InventoryID.Value];
						ps.Packages.AddRange(PackByWeight(boxes, stat));
					}
				}
			}

			sw.Stop();
			Debug.Print("SOPackageEngine.Pack() in {0} millisec.", sw.ElapsedMilliseconds);
			return list.Values.ToList();
		}