Esempio n. 1
0
        public override bool Equals(object value)
        {
            CartProduct product = value as CartProduct;

            return((product != null) &&
                   (this.id == product.getId()));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 private void AddProductToCart(int id, string name, decimal price)
 {
     if (cart.ContainsKey(id))
     {
         CartProduct product = cart[id];
         product.add();
         cart[id] = product;
         UpdateCart();
     }
     else
     {
         CartProduct product = new CartProduct(id, name, price);
         cart.Add(id, product);
         UpdateCart();
     }
 }
Esempio n. 5
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();
        }
Esempio n. 6
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);
         }
     }
 }
Esempio n. 7
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());
            }
        }