Esempio n. 1
0
        public bool GetGiftBox(double x, double y, out double xx, out double yy)
        {
            xx = 0;
            yy = 0;
            if (x <= 0 || y <= 0)
            {
                _notifier.OnError("Invalid box size");
                return(false);
            }
            BoxBase val = new BoxBase(x, true);

            _mainTree.SearchBiggerOrEquelTo(val, out BoxBase founded);
            while (founded != null)
            {
                if (founded.HeightTree.SearchBiggerOrEquelTo(new BoxHeight(y), out BoxHeight foundedHeight))
                {
                    xx = founded.BaseSize;
                    yy = foundedHeight.Height;
                    foundedHeight.Count--;
                    if (foundedHeight.Count == 0)
                    {
                        _notifier.OnEmptyStock($"Boxes stock of ({founded.BaseSize},{foundedHeight.Height}) is over");
                        //delete from list.
                        _boxesList.RemoveNode(foundedHeight.DataNode, out MyLinkedList <BoxData> .Node save);
                        //delete from height tree
                        founded.HeightTree.Remove(foundedHeight);
                        if (founded.HeightTree.IsEmpty())
                        {
                            _mainTree.Remove(founded);
                        }
                        return(true);
                    }
                    if (foundedHeight.Count < _lowAmountAlert)
                    {
                        _notifier.OnLowSuplly($"Boxes stock of ({founded.BaseSize},{foundedHeight.Height}) is low, please renew the supply");
                    }
                    //update time;
                    _boxesList.ModifyNode(foundedHeight.DataNode, dn =>
                    {
                        dn.data.LastUpdate = DateTime.Now;
                    });
                    return(true);
                }
                if (_mainTree.SearchBiggerThan(founded, out BoxBase newVal))
                {
                    founded = newVal;
                }
                else
                {
                    _notifier.OnError("Suited box not available");
                    return(false);
                }
            }
            _notifier.OnError("Suited box not available");
            return(false);
        }
Esempio n. 2
0
 public void UpdateSupply(double x, double y, int amount)
 {
     if (x <= 0 || y <= 0 || amount <= 0)
     {
         _notifier.OnError("Invalid box size or amount");
     }
     else
     {
         if (amount > _maxBoxesNumber)
         {
             amount = _maxBoxesNumber;
         }
         BoxBase tmp = new BoxBase(x);
         if (_mainTree.Search(tmp, out BoxBase foundedBase))
         {
             BoxHeight node = new BoxHeight(y);
             if (foundedBase.HeightTree.Search(node, out BoxHeight foundedHeight))
             {
                 //box exist
                 if (foundedHeight.Count + amount < _maxBoxesNumber)
                 {
                     foundedHeight.Count += amount;
                     _notifier.OnSuccess($"{amount} units of Box ({x},{y}) was added successfully");
                 }
                 else
                 {
                     foundedHeight.Count = _maxBoxesNumber;
                     _notifier.OnSuccess($"Box ({x},{y}) has reach the limit of {_maxBoxesNumber}");
                 }
             }
             else
             {
                 _boxesList.AddLast(new BoxData(foundedBase));
                 foundedBase.HeightTree.Add(new BoxHeight(y, false, amount, _boxesList.End));
                 _boxesList.End.data.HeightData = foundedBase.HeightTree.LastUpdate.data;
                 _notifier.OnSuccess($"{amount} units of Box ({x},{y}) was added successfully");
             }
         }
         else
         {
             BoxBase node = new BoxBase(x, false);
             _boxesList.AddLast(new BoxData(node));
             node.HeightTree.Add(new BoxHeight(y, false, amount, _boxesList.End));
             _boxesList.End.data.HeightData = node.HeightTree.LastUpdate.data;
             _mainTree.Add(node);
             _notifier.OnSuccess($"{amount} units of Box ({x},{y}) was added successfully");
         }
     }
 }
Esempio n. 3
0
 internal BoxData(BoxBase boxBase)
 {
     LastUpdate = DateTime.Now;
     BaseData   = boxBase;
 }