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; } } }
void initial_Load() { //temporary variables //TODO change this to work directly with the class List<Customer> listOfCustomers = new List<Customer>(); List<Book> listOfBooks = new List<Book>(); List<Transaction> listOfPendingTransactions = new List<Transaction>(); List<Transaction> listOfCompleteTransactions = new List<Transaction>(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "BookStore Data Files|*.bdf"; openFileDialog.InitialDirectory = Application.StartupPath; if (openFileDialog.ShowDialog() == DialogResult.OK) { TextReader trs = new StreamReader(openFileDialog.FileName); string s; List<string> words; int stringIndex; while (((s = trs.ReadLine()) != null) && (s != "")) { words = new List<string>(); while (true) { if ((stringIndex = s.IndexOf('#')) == -1) break; words.Add(s.Substring(0, stringIndex).Trim()); s = s.Substring(stringIndex + 1); } if (words.Count > 0) { try { // to catprue an exception from getInt( ) getDecimal switch (words[0]) { case "AddBook": decimal price = getDecimal(words[5]); int stock = getInt(words[7]); // XXX use words[1]~words[4], price, words[6], and stock to register a book ControlShop.listOfBooks.Add(new Book(words[1], words[2], words[3], words[4], price, words[6], stock)); break; case "AddCustomer": // XXX use words[1]~words[7] to register a customer ControlShop.listOfCustomers.Add(new Customer(words[1], words[2], words[3], words[4], words[5], words[6], words[7])); //ControlShop.addCustomerTodictionary(words[3], ); break; case "Login": // XXX use words[1] and words[2] to login a customer ControlShop.findCustomerLogin(words[1], words[2]); customerWindow.updateLabel = ControlShop.LoggedinCustomer.userName; break; case "AddBookToWishList": // XXX use words[1] (ISBN) to register the book in the current customer's wishlist ControlShop.addBookToCustomerWishList(words[1]); break; case "AddBookToCart": // XXX use words[1] (ISBN) to add the book in the current customer's cart ControlShop.addBookToCustomerCart(words[1]); break; case "CheckOut": // XXX check out the current customer's cart ControlShop.checkOutCustomer(); break; case "ProcessPendingTransaction": // XXX use words[1] (index of the pending transactions) to identify the pending // transaction to approve ControlShop.approveTransaction(ControlShop.listOfPendingTransactions[Int32.Parse(words[1])]); break; default: MessageBox.Show(this, "Unknown Operation : " + words[0]); break; } } catch (BookShopException ex) { MessageBox.Show(this, ex.ErrorMessage); } } } } //ControlShop.updateObject(listOfCustomers, listOfBooks, listOfPendingTransactions, listOfCompleteTransactions); //ControlShop.LoggedinCustomer = null; }