/* * CloudPos_ItemRemoved is raised when an item is removed from the Basket. * * Again, we update listBasket, by removing the matching item. */ private void CloudPos_ItemRemoved(object sender, BasketItem item) { UpdateGUI(() => { foreach (ListViewItem lvItem in listBasket.Items) { if (lvItem.Tag.ToString() == item.Id.ToString()) { lvItem.Remove(); break; } } RefreshButtonStates(); }); if (item.Type == "PURCHASE") { PurchaseBasketItem p = (PurchaseBasketItem)item; Log(item.Type + " Removed: " + p.Product.Description); } else if (item.Type == "REFUND") { RefundBasketItem r = (RefundBasketItem)item; Log(item.Type + " Removed: " + r.Product.Description); } }
/* * CloudPos_ItemAdded is raised when an item is added to the Basket, including * both PURCHASE items and REFUND items. * * Here, we update listBasket with the new item. * * NOTE: If the BasketItem to be added contains SubItems (within .Product.Items), * we iterate through the .Product.Items collection and add each SubItem to the POS * basket, rather than the parent Product. This is true even if the .Product.Items * collection contains just one SubItem. This is because we use this as a way of * overriding the EAN and/or Description of the product to be added to the basket. */ private void CloudPos_ItemAdded(object sender, BasketItem item) { UpdateGUI(() => { if (item.Type == "PURCHASE") { PurchaseBasketItem purchase = (PurchaseBasketItem)item; if (purchase.Product.Items == null || purchase.Product.Items.Count == 0) { ListViewItem lvItem = new ListViewItem(purchase.Product.Description); lvItem.Tag = purchase.Id; lvItem.SubItems.Add(purchase.Product.Price.Amount.ToString("C")); lvItem.SubItems.Add(purchase.Product.Ean); lvItem.SubItems.Add(purchase.Id.ToString()); listBasket.Items.Add(lvItem); } else // we have at least one SubItem in the .Product.Items collection { foreach (SubItem subItem in purchase.Product.Items) { ListViewItem lvItem = new ListViewItem(subItem.Description); lvItem.Tag = purchase.Id; lvItem.SubItems.Add(subItem.Amount.ToString("C")); lvItem.SubItems.Add(subItem.Ean); lvItem.SubItems.Add(purchase.Id.ToString()); listBasket.Items.Add(lvItem); } } } else if (item.Type == "REFUND") { RefundBasketItem refund = (RefundBasketItem)item; if (refund.Product.Items == null || refund.Product.Items.Count == 0) { ListViewItem lvItem = new ListViewItem(refund.Product.Description); lvItem.Tag = refund.Id; lvItem.SubItems.Add(refund.Product.Price.Amount.ToString("C")); lvItem.SubItems.Add(refund.Product.Ean); lvItem.SubItems.Add(refund.Id.ToString()); listBasket.Items.Add(lvItem); } else // we have at least one SubItem in the .Product.Items collection { foreach (SubItem subItem in refund.Product.Items) { ListViewItem lvItem = new ListViewItem(subItem.Description); lvItem.Tag = refund.Id; lvItem.SubItems.Add(subItem.Amount.ToString("C")); lvItem.SubItems.Add(subItem.Ean); lvItem.SubItems.Add(refund.Id.ToString()); listBasket.Items.Add(lvItem); } } } RefreshButtonStates(); }); if (item.Type == "PURCHASE") { PurchaseBasketItem p = (PurchaseBasketItem)item; Log(item.Type + ": " + p.Product.Description); } else if (item.Type == "REFUND") { RefundBasketItem r = (RefundBasketItem)item; Log(item.Type + ": " + r.Product.Description); } }