Esempio n. 1
0
        /// <summary>
        /// increases the quantity of an order by one
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int index = LBox.SelectedIndex;
            int i     = 0;

            decrease.IsEnabled = true;
            foreach (Orders.OrderInfo s in Orders.ProductList)
            {
                this.branchName    = s.BranchName;
                this.productName   = s.ProductName;
                this.price         = s.ProductPrice;
                this.Quantity      = s.Quantity;
                this.totalQuantity = s.TotalQuantity;
                if (i == index)
                {
                    break;
                }
                else
                {
                    i++;
                }
            }
            if (index >= 0)
            {
                Orders.OrderInfo temp     = Orders.ProductList[index];
                float            newPrice = this.price;
                float[]          allPrice;
                LBox.Items.RemoveAt(index);
                this.Quantity++;
                temp.BranchName  = this.branchName;
                temp.ProductName = this.productName;

                temp.Quantity      = this.Quantity;
                temp.TotalQuantity = this.totalQuantity;

                int pID = Database.GetProductID(this.productName);
                allPrice = Orders.CalculatePrice(pID, this.Quantity);

                this.price                = allPrice[2];
                temp.ProductPrice         = this.price;
                newPrice                  = this.price - newPrice;
                Orders.ProductList[index] = temp;
                LBox.Items.Insert(index, productName + "\n" + "Purchased From " + branchName + "\nQuantity: " + this.Quantity.ToString() + "\t\t\t\t\tPrice: " + this.price.ToString());
                if (this.Quantity == this.totalQuantity)
                {
                    increase.IsEnabled = false;
                }
                CalculateSubTotal(newPrice);
            }
            decrease.IsEnabled = true;
            LBox.SelectedIndex = index;
            selectionIndex     = index;
        }
Esempio n. 2
0
        /// <summary>
        /// decreases the quantity of an order by one
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void decrease_Click(object sender, RoutedEventArgs e)
        {
            int  index = LBox.SelectedIndex;
            int  i     = 0;
            bool check = true;

            increase.IsEnabled = true;
            foreach (Orders.OrderInfo s in Orders.ProductList)
            {
                this.branchName  = s.BranchName;
                this.productName = s.ProductName;
                this.price       = s.ProductPrice;
                this.Quantity    = s.Quantity;
                if (i == index)
                {
                    break;
                }
                else
                {
                    i++;
                }
            }
            if (index >= 0)
            {
                Orders.OrderInfo temp     = Orders.ProductList[index];
                float            newPrice = this.price;
                float[]          allPrice;
                this.Quantity--;
                if (this.Quantity == 0)
                {
                    if (MessageBox.Show("Do you want to remove the item from your cart?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        check = false;
                    }
                    else
                    {
                        this.Quantity = 1;
                    }
                }
                LBox.Items.RemoveAt(index);

                if (check == true)
                {
                    temp.BranchName  = this.branchName;
                    temp.ProductName = this.productName;

                    temp.Quantity = this.Quantity;

                    int pID = Database.GetProductID(this.productName);
                    allPrice = Orders.CalculatePrice(pID, this.Quantity);

                    this.price                = allPrice[2];
                    temp.ProductPrice         = this.price;
                    newPrice                  = this.price - newPrice;
                    Orders.ProductList[index] = temp;
                    LBox.Items.Insert(index, productName + "\n" + "Purchased From " + branchName + "\nQuantity: " + this.Quantity.ToString() + "\t\t\t\t\tPrice: " + this.price.ToString());
                }
                else
                {
                    newPrice = this.price - newPrice;
                    Orders.ProductList.RemoveAt(index);
                }
                CalculateSubTotal(newPrice);
            }


            LBox.SelectedIndex = index;
            selectionIndex     = index;
        }