Пример #1
0
		public virtual List<BoxInfo> PackByWeight(List<INItemBoxEx> boxes, decimal baseWeight)
		{
			boxes.Sort((INItemBoxEx x, INItemBoxEx y) => decimal.Compare(x.MaxWeight.GetValueOrDefault(), y.MaxWeight.GetValueOrDefault()));

			List<BoxInfo> list = new List<BoxInfo>();
			if (baseWeight > 0 && boxes.Count > 0)
			{
				INItemBoxEx box = GetBoxThatCanFitWeight(boxes, baseWeight);
				if (box != null)
				{
					BoxInfo p = new BoxInfo();
					p.Box = box;
					p.Value = baseWeight;
					list.Add(p);
				}
				else
				{
					//Distribute qty among Biggest boxes available: 
					INItemBoxEx biggestBox = boxes[boxes.Count - 1];
					int numberOfMaxBoxes = (int)Math.Floor(baseWeight / (biggestBox.MaxWeight.Value - biggestBox.BoxWeight.GetValueOrDefault()));

					for (int i = 0; i < numberOfMaxBoxes; i++)
					{
						BoxInfo p = new BoxInfo();
						p.Box = biggestBox;
						p.Value = biggestBox.MaxWeight.Value;
						list.Add(p);

						baseWeight -= (biggestBox.MaxWeight.Value - biggestBox.BoxWeight.GetValueOrDefault());
					}

					//remainder
					list.AddRange(PackByWeight(boxes, baseWeight));
				}
			}

			return list;
		}
Пример #2
0
 public void AddOneBox(BoxInfo info)
 {
     if (m_listReward != null)
     {
         m_listReward.Add(info);
     }
 }