Exemplo n.º 1
0
        private void buttonAddToTheCart_Click(object sender, EventArgs e)
        {
            if (PartsList.FocusedItem != null && PartsList.SelectedItems.Count > 0)
            {
                for (int i = 0; i < Cart.Count; i++)
                {
                    if (Cart[i].Element == DisplayedParts[PartsList.FocusedItem.Index])
                    {
                        Cart[i].Amount++;
                        var columnAmountIndex = 3;
                        listViewCart
                        .Items[i]
                        .SubItems
                        .Insert(
                            columnAmountIndex,
                            new ListViewItem.ListViewSubItem(
                                listViewCart.Items[i],
                                Cart[i].Amount.ToString()));

                        CalculateTotalSum();
                        listViewCart.Refresh();

                        return;
                    }
                }

                Cart.Add(new CartElement(DisplayedParts[PartsList.FocusedItem.Index], 1));
                Classes.ShopElement lastElement = (Classes.ShopElement)Cart[Cart.Count - 1].Element;
                CalculateTotalSum();

                //Adding Item to the ListView
                //Is it a right way to do it?
                ListViewItem test = new ListViewItem(lastElement.ID.ToString());
                test.SubItems.Add(lastElement.Name);
                test.SubItems.Add(lastElement.Price.ToString());
                test.SubItems.Add(Cart[Cart.Count - 1].Amount.ToString());
                listViewCart.Items.Add(test);
            }
        }
Exemplo n.º 2
0
 public CartElement(Classes.ShopElement element, int amount)
 {
     Element = element;
     Amount  = amount;
 }