public override bool Equals(object value) { CartProduct product = value as CartProduct; return((product != null) && (this.id == product.getId())); }
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); }
private int GetCartQuantity() { int quantity = 0; foreach (KeyValuePair <int, CartProduct> cartProduct in cart) { CartProduct product = (CartProduct)cartProduct.Value; quantity = quantity + product.getQuantity(); } return(quantity); }
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(); } }
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(); }
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); } } }
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()); } }