コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        private void bnShowCart_Click(object sender, EventArgs e)
        {
            // XXX Show Cart Button event handler
            while (true)
            {
                try
                {
                    // to capture an exception from SelectedIndex/SelectedItem of carDisplay
                    cartDialog.ClearDisplayItems();
                    //cartDialog.AddDisplayItems(null); // null is a dummy argument

                    BookShopControl.showCartInformation(cartDialog);
                    switch (cartDialog.Display())
                    {
                    case DialogReturn.CheckOut:     // check out
                        // XXX
                        BookShopControl.checkOutCustomer();
                        return;

                    case DialogReturn.ReturnBook:     // remove a book
                        // XXX
                        BookShopControl.removeBookFromCustomerCart(BookShopControl.LoggedinCustomer.currentCart.itemsPurchased[cartDialog.SelectedIndex].purchaseBook.isbn);
                        continue;

                    case DialogReturn.Done:     // cancel
                        return;
                    }
                }
                catch (BookShopException bsex)
                {
                    MessageBox.Show(this, bsex.ErrorMessage);
                    continue;
                }
                catch (NullReferenceException nex)
                {
                    MessageBox.Show(this, nex.Message);
                    return;
                }
            }
        }
コード例 #3
0
        private void bnShowCart_Click(object sender, EventArgs e)
        {
            // XXX Show Cart Button event handler
            while (true)
            {
                try
                {  // to capture an exception from SelectedIndex/SelectedItem of carDisplay
                    cartDialog.ClearDisplayItems();
                    controller.ListCart(ref cartDialog);
                    //cartDialog.AddDisplayItems("====================================================");
                    //cartDialog.AddDisplayItems("Total Price: $" + controller.CurrentCustomer.CurrentCart.Price);
                    //cartDialog.AddDisplayItems(null); // null is a dummy argument
                    switch (cartDialog.Display())
                    {
                    case DialogReturn.CheckOut:      // check out
                        controller.CheckOut();
                        // XXX

                        return;

                    case DialogReturn.ReturnBook:     // remove a book
                        controller.RemoveFromCart(controller.CurrentCustomer.CurrentCart.Cart[cartDialog.SelectedIndex].Book.ISBN);
                        // XXX

                        continue;

                    case DialogReturn.Done:     // cancel
                        return;
                    }
                }
                catch (BookShopException bsex)
                {
                    MessageBox.Show(this, bsex.ErrorMessage);
                    return;
                }
            }
        }