// End of Button Add Book: Click event private void BtnCheckout_Click(object sender, EventArgs e) { if (listboxCart.Items.Count > 0) { string name = ""; while (name == "") { name = Interaction.InputBox("Please enter your name:", "What is your name?"); } // Got the customer's name! List <CartItem> cart = new List <CartItem>(); foreach (object item in listboxCart.Items) { cart.Add(item as CartItem); // And, transferred the cart to a fresh List. } // End of Foreach Customer output = new Customer(name, cart); // Now we can get a full-on Receipt! DialogResult result = MessageBox.Show(output.Receipt(), "Confirm Receipt", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { MessageBox.Show("Receipt saved and cart cleared! Please shop with us again!"); DataMan.SaveReceipt(output); } else { MessageBox.Show("Cart cleared! Please shop with us again!"); } // End of If/Else statement listboxCart.Items.Clear(); } else { MessageBox.Show("You need to pick some items out first!"); } // End of If/Else statement }
// End of Initialization private void FormStore_Load(object sender, EventArgs e) { List <Book> books = DataMan.GetBooks(); List <Game> games = DataMan.GetGames(); listboxBooks.Items.Clear(); foreach (Book book in books) { listboxBooks.Items.Add(book); } // End of Foreach listboxGames.Items.Clear(); foreach (Game game in games) { listboxGames.Items.Add(game); } // End of Foreach }