예제 #1
0
        public decimal CalculateCartTotal()
        {
            decimal total = 0;

            foreach (KeyValuePair <int, CartProduct> cartProduct in cart)
            {
                CartProduct product = (CartProduct)cartProduct.Value;
                total = total + (product.getPrice() * product.getQuantity());
            }
            return(total);
        }
예제 #2
0
        private int GetCartQuantity()
        {
            int quantity = 0;

            foreach (KeyValuePair <int, CartProduct> cartProduct in cart)
            {
                CartProduct product = (CartProduct)cartProduct.Value;
                quantity = quantity + product.getQuantity();
            }
            return(quantity);
        }
예제 #3
0
 private void SubtractFromCart(int id)
 {
     if (cart.ContainsKey(id))
     {
         CartProduct product = cart[id];
         if (product.getQuantity() > 1)
         {
             product.subtract();
             cart[id] = product;
             UpdateCart();
         }
         else
         {
             //remove from cart
             RemoveFromCart(id);
         }
     }
 }
예제 #4
0
        private void UpdateCart()
        {
            //Réinitialisation du cart
            cartDataGridView.Rows.Clear();
            cartDataGridView.Refresh();

            //Ajout des produits du panier dans le datagridview
            foreach (KeyValuePair <int, CartProduct> cartProduct in cart)
            {
                CartProduct product = (CartProduct)cartProduct.Value;
                cartDataGridView.Rows.Add(cartProduct.Key, product.getName(), product.getPrice(), product.getQuantity());
            }

            //Mise à jour du nombre de produits dans le panier et le total
            labelCartQuantity.Text = GetCartQuantity().ToString();
            labelCartTotal.Text    = CalculateCartTotal().ToString();
        }
예제 #5
0
        private void ConfirmOrder(Int32 id)
        {
            // On initialise notre dataset
            DataSetContains containsDataSet = new DataSetContains();

            DataSetContainsTableAdapters.EATFAST_CONTAINSTableAdapter containsTableAdapter =
                new DataSetContainsTableAdapters.EATFAST_CONTAINSTableAdapter();

            //Récupération du panier
            SortedList <int, CartProduct> cart = Homepage.getInstance().GetCart();

            foreach (KeyValuePair <int, CartProduct> cartProduct in cart)
            {
                CartProduct product = (CartProduct)cartProduct.Value;

                //Ajout de chaque produit dans la commande
                containsTableAdapter.AddToOrder(id, product.getId(), product.getPrice(), product.getQuantity());
            }
        }