示例#1
0
        private void bnShowWishlist_Click(object sender, EventArgs e)
        {
            // XXX Show WishList Button event handler

            while (true)
            {
                try
                {
                    // to capture an excepton by SelectedItem/SelectedIndex of wishListDialog
                    wishListDialog.ClearDisplayItems();
                    //wishListDialog.AddDisplayItems(null); // XXX null is a dummy argument

                    if (!BookShopControl.isCustomerLoggedIn)
                    {
                        throw new BookShopException("You are not logged in.");
                    }
                    if (BookShopControl.LoggedinCustomer.howManyItemsOnWishList <= 0)
                    {
                        throw new BookShopException("There are no items on your wishlist.");
                    }

                    BookShopControl.updateWishListDialog(wishListDialog);

                    if (wishListDialog.Display() == DialogReturn.Done)
                    {
                        return;
                    }
                    // select is pressed
                    //XXX
                    BookShopControl.updateWishListDialog(bookInWishListDialog, wishListDialog);

                    switch (bookInWishListDialog.Display())
                    {
                    case DialogReturn.AddToCart:
                        // XXX
                        BookShopControl.addBookToCustomerCart(BookShopControl.LoggedinCustomer.wishList[wishListDialog.SelectedIndex].isbn);
                        continue;

                    case DialogReturn.Remove:
                        // XXX
                        BookShopControl.removeBookFromCustomerWishList(BookShopControl.LoggedinCustomer.wishList[wishListDialog.SelectedIndex].isbn);
                        continue;

                    case DialogReturn.Done:     // Done
                        continue;
                    }
                }
                catch (BookShopException bsex)
                {
                    MessageBox.Show(this, bsex.ErrorMessage);
                    return;
                }
                catch (NullReferenceException nex)
                {
                    //throw new BookShopException("There are no items on your wishlist.");
                    return;
                }
            }
        }