Пример #1
0
        public void AddBox(Box box)
        {
            var xTreeNode = boxTree.Search(box.X, out BinarySearchTreeNode <YTree> xFather);

            if (xTreeNode != null)
            {
                var yTreeNode = xTreeNode.Value.Search(box.Y, out BinarySearchTreeNode <LinkedTreeBox> yFather);
                if (yTreeNode != null)
                {
                    yTreeNode.Value.BoxNode.Value.Quantity += box.Quantity;
                    dataBase.Save();
                }
                else
                {
                    box.LastTimeBought = DateTimeOffset.Now;

                    boxesByDate.AddLast(box);              // Add to Linked List
                    var newNode = new LinkedTreeBox();
                    newNode.BoxNode = boxesByDate.EndNode; // Take it from LinkedList

                    if (yFather == null)
                    {
                        xTreeNode.Value.Add(newNode);                  // Add to tree
                    }
                    else
                    {
                        xTreeNode.Value.Add(yFather, newNode);
                    }

                    dataBase.AddBox(box); // Add to database
                }
            }
            else
            {
                box.LastTimeBought = DateTimeOffset.Now;

                boxesByDate.AddLast(box);              // Add to Linked List
                var newNode = new LinkedTreeBox();
                newNode.BoxNode = boxesByDate.EndNode; // Take it from LinkedList

                var newYTree = new YTree(box.X);       // Create new Y Tree
                newYTree.Add(newNode);                 // Add to Y Tree

                if (xFather != null)
                {
                    boxTree.Add(xFather, newYTree);                  // Add to tree
                }
                else
                {
                    boxTree.Add(newYTree);
                }

                dataBase.AddBox(box); // Add to database
            }
        }
Пример #2
0
 public void Init()
 {
     boxesByDate = new LinkedList <Box>();
     col.IEnumerable <Box> boxes = dataBase.GetBoxes().OrderBy((b) => b.LastTimeBought);
     foreach (var box in boxes)
     {
         boxesByDate.AddLast(box);
         var linkedTreeBox = new LinkedTreeBox();
         linkedTreeBox.BoxNode = boxesByDate.EndNode;
         boxTree.AddBox(linkedTreeBox);
     }
 }
Пример #3
0
        public bool BoxExist(Box box, out LinkedTreeBox res)
        {
            res = null;
            var node = Search(box.X, out _);

            if (node == null)
            {
                return(false);
            }

            var linkTreeBox = node.Value.Search(box.Y, out _);

            if (linkTreeBox == null)
            {
                return(false);
            }

            res = linkTreeBox.Value;
            return(true);
        }
Пример #4
0
        public void AddBox(LinkedTreeBox box)
        {
            var node = Search(box.BoxNode.Value.X, out BinarySearchTreeNode <YTree> xFather);

            if (node == null)
            {
                var yTree = new YTree(box.BoxNode.Value.X);
                yTree.Add(box);

                if (xFather != null)
                {
                    Add(xFather, yTree);
                }
                else
                {
                    Add(yTree);
                }
            }
            else
            {
                var linkTreeBox = node.Value.Search(box.BoxNode.Value.Y, out BinarySearchTreeNode <LinkedTreeBox> yFather);
                if (linkTreeBox == null)
                {
                    if (yFather != null)
                    {
                        node.Value.Add(yFather, box);
                    }
                    else
                    {
                        node.Value.Add(box);
                    }
                }
                else
                {
                    throw new ArgumentException("Box all ready Exist.");
                }
            }
        }