コード例 #1
0
    public void SetOrderBST(string customerName, List <Item> orderItems)
    {
        int     orderId = customerName.GetHashCode();
        BSTNode node    = tree.Find(orderId);

        if (node == null)
        {
            Order order = new Order()
            {
                id         = orderId,
                clientName = customerName,
                items      = new List <Item>()
            };

            tree.Insert(orderId, order);
        }
        else
        {
            orderId = node.GetData <Order>().clientName.GetHashCode();
            node.SetData(new Order
            {
                id         = orderId,
                clientName = customerName,
                items      = orderItems
            }, orderId);
        }
        List <Order> nodes = new List <Order>();

        tree.PreorderTraversal(nodes);
        OrderDataManager.UpdateOrders(nodes);
    }
コード例 #2
0
    public Order GetOrderBST(string customerName)
    {
        int     orderID = customerName.GetHashCode();
        BSTNode node    = tree.Find(orderID);

        if (node != null)
        {
            return(node.GetData <Order>());
        }
        return(null);
    }
コード例 #3
0
    public Item GetItemBST(string itemName)
    {
        int     itemID = itemName.GetHashCode();
        BSTNode node   = tree.Find(itemID);

        if (node != null)
        {
            return(node.GetData <Item>());
        }
        return(null);
    }
コード例 #4
0
    public void SetItemBST(string itemName, int itemQuantity, float itemPrice, bool isOnSale, float salePercent)
    {
        int     itemID = itemName.GetHashCode();
        BSTNode node   = tree.Find(itemID);

        if (node == null)
        {
            Item item = new Item()
            {
                id          = itemID,
                name        = itemName,
                price       = itemPrice,
                quantity    = itemQuantity,
                isOnSale    = isOnSale,
                salePercent = salePercent
            };
            tree.Insert(itemID, item);
        }
        else
        {
            itemID = node.GetData <Item>().name.GetHashCode();
            node.SetData(new Item
            {
                id          = itemID,
                name        = node.GetData <Item>().name,
                price       = itemPrice,
                quantity    = itemQuantity,
                isOnSale    = isOnSale,
                salePercent = salePercent
            }, itemID);
        }
        List <Item> nodes = new List <Item>();

        tree.PreorderTraversal(nodes);
        StockDataManager.UpdateStock(nodes);
    }