/* * Bryan * I'm a lemon! */ using System; using System.ComponentModel; using System.Linq; using System.Windows.Forms; namespace bryan_coffeeShop { public partial class CoffeeShopForm : Form { /// <summary> /// coffeeFlavors, using bindinglists so they auto update /// </summary> private BindingList<string> coffeeFlavors = new BindingList<string> { "", "Espresso", "Latte", "Cappuccino", "Mocha", "Americana" }; /// <summary> /// syrupFlavors, using bindinglists so they auto update /// </summary> private BindingList<string> syrupFlavors = new BindingList<string> { "Almond", "Amaretto", "Caramel", "Chocolate Milano", "Cinnamon" }; // You wanted two arrays for prices, here you go. private double[] coffeeFlavorPrice = new double[] { 5.15 }; private double[] syrupFlavorPrice = new double[] { 2.50 }; /// <summary> /// Main initialize /// </summary> public CoffeeShopForm() { InitializeComponent(); // Set up the data sources, since they are binding lists, they auto update! cb_CoffeeFlavors.DataSource = coffeeFlavors; list_SyrupFlavors.DataSource = syrupFlavors; // Unselect the listbox list_SyrupFlavors.SelectedIndex = -1; } /// <summary> /// Add flavor EH /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_AddFlavor_Click(object sender, EventArgs e) { // Make sure it's not empty and we don't already have this flavor if (!tb_AddFlavor.Text.Equals("") && !coffeeFlavors.Contains(tb_AddFlavor.Text, StringComparer.OrdinalIgnoreCase)) { // Add the list coffeeFlavors.Add(tb_AddFlavor.Text); // Clear out the text tb_AddFlavor.Text = ""; } } /// <summary> /// Remove flavor EH /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_RemoveFlavor_Click(object sender, EventArgs e) { if (!cb_CoffeeFlavors.Text.Equals("")) coffeeFlavors.Remove(cb_CoffeeFlavors.Text); } /// <summary> /// Menu item, exits application /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smi_File_Exit_Click(object sender, EventArgs e) { Application.Exit(); } /// <summary> /// Menu item, clear text? There was no specification of what exactly this is suppose to do /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smi_File_Clear_Click(object sender, EventArgs e) { tb_AddFlavor.Text = ""; } /// <summary> /// Display about form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smi_File_About_Click(object sender, EventArgs e) { Help helpForm = new Help(); helpForm.Show(); } /// <summary> /// Clear out all the flavors /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smi_Coffee_Clear_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to clear all the flavors?", "Confirm Clear", MessageBoxButtons.YesNo) == DialogResult.Yes) { coffeeFlavors.Clear(); MessageBox.Show("The coffee flavors have been cleared"); } } /// <summary> /// Show the count of the flavors /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smi_Coffee_Count_Click(object sender, EventArgs e) { MessageBox.Show($"The coffee flavors list contains {coffeeFlavors.Count} items"); } /// <summary> /// Enable based on if the text is empty and the list doesn't contain the items /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tb_AddFlavor_KeyUp(object sender, KeyEventArgs e) { btn_AddFlavor.Enabled = (!tb_AddFlavor.Text.Equals("") && !coffeeFlavors.Contains(tb_AddFlavor.Text, StringComparer.OrdinalIgnoreCase)); } /// <summary> /// Enables or disables the listbox and button. Also display the price for some reason? /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cb_CoffeeFlavors_SelectedIndexChanged(object sender, EventArgs e) { btn_RemoveFlavor.Enabled = !cb_CoffeeFlavors.Text.Equals(""); list_SyrupFlavors.Enabled = !cb_CoffeeFlavors.Text.Equals(""); if (!cb_CoffeeFlavors.Text.Equals("")) MessageBox.Show($"Total Price: {coffeeFlavorPrice[0] + (syrupFlavorPrice[0] * (list_SyrupFlavors.SelectedItems.Count)):c}"); } /// <summary> /// Display the updated price for some reason? /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void list_SyrupFlavors_SelectedIndexChanged(object sender, EventArgs e) { if (!cb_CoffeeFlavors.Text.Equals("")) MessageBox.Show($"Total Price: {coffeeFlavorPrice[0] + (syrupFlavorPrice[0] * (list_SyrupFlavors.SelectedItems.Count)):c}"); } } }