public RoomServiceForm() { InitializeComponent(); cust = (Customer)cbxCustomer.SelectedValue; roomService = new RoomService(cust, lstFoodItems); lstFoodItems = new List <FoodItems>(); seafood = FoodType.Seafood; pizza = FoodType.Pizza; pasta = FoodType.Pasta; meat = FoodType.Meat; soups = FoodType.Soups; sandwiches = FoodType.Sandwiches; prawn = new FoodItems(seafood, quantity, "Prawn Platter", 15.25); margerita = new FoodItems(pizza, quantity, "Margerita Pizza", 9.50); tortellini = new FoodItems(pasta, quantity, "Tortellini", 12.30); beef = new FoodItems(meat, quantity, "250g Of Beef", 25.75); peasoup = new FoodItems(soups, quantity, "Pea Soup", 8.23); hamSandwich = new FoodItems(sandwiches, quantity, "Ham And Cheese Sandwich", 4.35); cbxFood.Items.Add(prawn.GetInfo()); cbxFood.Items.Add(margerita.GetInfo()); cbxFood.Items.Add(tortellini.GetInfo()); cbxFood.Items.Add(beef.GetInfo()); cbxFood.Items.Add(peasoup.GetInfo()); cbxFood.Items.Add(hamSandwich.GetInfo()); }
private void btnShowAll_Click(object sender, EventArgs e) { foreach (ConsumableItems i in item) // Looping for each consumable Items { if (i.GetType() == typeof(FoodItems)) // If item is of type Food { FoodItems tmp = (FoodItems)i; // Parsing from consumable items tp Food MessageBox.Show(tmp.GetInfo()); // POLYMORPHISM (Shows All info) } if (i.GetType() == typeof(BarItems)) // If the item is of type drinks { BarItems tmp = (BarItems)i; //Parsing from consumable items to food MessageBox.Show(tmp.GetInfo()); // POLYMORPHISM (Shows All info) Method Chnages Form } } }
private void btnAdd_Click(object sender, EventArgs e) { if (cbxFood.SelectedIndex == 0 && Int32.TryParse(txtQuantity.Text, out quantity)) { prawn = new FoodItems(seafood, quantity, "Prawn Platter", 15.25); lstFoodItems.Add(prawn); lstFood.Items.Add(prawn.GetInfo() + " Type: " + prawn.Typ.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + prawn.GetPrice(quantity).ToString()); } if (cbxFood.SelectedIndex == 1 && Int32.TryParse(txtQuantity.Text, out quantity)) { margerita = new FoodItems(pizza, quantity, "Margerita Pizza", 9.50); lstFoodItems.Add(margerita); lstFood.Items.Add(margerita.GetInfo() + " Type: " + margerita.Typ.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + margerita.GetPrice(quantity).ToString()); } if (cbxFood.SelectedIndex == 2 && Int32.TryParse(txtQuantity.Text, out quantity)) { tortellini = new FoodItems(pasta, quantity, "Tortellini", 12.30); lstFoodItems.Add(tortellini); lstFood.Items.Add(tortellini.GetInfo() + " Type: " + tortellini.Typ.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + tortellini.GetPrice(quantity).ToString()); } if (cbxFood.SelectedIndex == 3 && Int32.TryParse(txtQuantity.Text, out quantity)) { beef = new FoodItems(meat, quantity, "250g Of Beef", 25.75); lstFoodItems.Add(beef); lstFood.Items.Add(beef.GetInfo() + " Type: " + beef.Typ.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + beef.GetPrice(quantity).ToString()); } if (cbxFood.SelectedIndex == 4 && Int32.TryParse(txtQuantity.Text, out quantity)) { peasoup = new FoodItems(soups, quantity, "Pea Soup", 8.23); lstFoodItems.Add(peasoup); lstFood.Items.Add(peasoup.GetInfo() + " Type: " + peasoup.Typ.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + peasoup.GetPrice(quantity).ToString()); } if (cbxFood.SelectedIndex == 5 && Int32.TryParse(txtQuantity.Text, out quantity)) { hamSandwich = new FoodItems(sandwiches, quantity, "Ham And Cheese Sandwich", 4.35); lstFoodItems.Add(hamSandwich); lstFood.Items.Add(hamSandwich.GetInfo() + " Type: " + hamSandwich.Typ.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + hamSandwich.GetPrice(quantity).ToString()); } }