private void bnShowCart_Click(object sender, EventArgs e) { // XXX Show Cart Button event handler if (!_attachedControl.IsLoggedIn()) { MessageBox.Show("Customer not logged in."); return; } while (true) { try { // to capture an exception from SelectedIndex/SelectedItem of carDisplay cartDialog.ClearDisplayItems(); cartDialog.AddDisplayItems(_attachedControl.CurrentCustomer.Cart.BookList.ToArray()); // null is a dummy argument cartDialog.AddDisplayItems(_attachedControl.CurrentCustomer.Cart.CartTotalArray()); //foreach (OrderItem oi in _attachedControl.CurrentCustomer.Cart.BookList) //{ // if (oi == selectedObject) // { // targetObject = oi; // } //} switch (cartDialog.Display()) { case DialogReturn.CheckOut: // check out // XXX _attachedControl.CheckOutCurrentCustomer(); return; case DialogReturn.ReturnBook: // remove a book // XXX object selectedObject = cartDialog.SelectedItem; // picked up a string or an OrderItem object if (!(selectedObject is OrderItem)) { MessageBox.Show(this, "an extra line was selected"); continue; } OrderItem targetObject = (OrderItem)selectedObject; _attachedControl.ReturnBook(_attachedControl.CurrentCustomer, _attachedControl.CurrentCustomer.Cart, targetObject); continue; case DialogReturn.Done: // cancel return; } } catch (BookShopException bsex) { MessageBox.Show(this, bsex.ErrorMessage); continue; } } }
public void showCartInformation(CartDialog cart) { if (!isCustomerLoggedIn) { throw new NullReferenceException("You are not logged in."); } if (LoggedinCustomer.currentCart.subTransactionCount <= 0) { throw new NullReferenceException("There are no items in your cart."); } for (int i = 0; i < LoggedinCustomer.currentCart.subTransactionCount; i++) { cart.AddDisplayItems(LoggedinCustomer.currentCart.itemsPurchased[i].ToString()); } cart.AddDisplayItems("======================================================="); cart.AddDisplayItems("Total Price : $" + LoggedinCustomer.currentCart.totalPrice); }
public void ListCart(ref CartDialog cd) { if (!loggedOn) { throw new BookShopException("This operation requires login."); } currentCustomer.showCart(ref cd); cd.AddDisplayItems("====================================================", "Total Price: $" + CurrentCustomer.CurrentCart.Price); }
public void showCart(ref CartDialog cd) { cd.AddDisplayItems(currentCart.Cart.ToArray()); }