Example #1
0
 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
         }
     }
 }
Example #2
0
        public BarForm()
        {
            InitializeComponent();
            cust     = (Customer)cbxCustomer.SelectedValue;                     // Getting the values to the combo box.
            bar      = new Bar(cust, lstItems);                                 // Initializing a new bar.
            lstItems = new List <BarItems>();                                   // Items in the bar.

            nonAlcholicTyp = BarItemType.NonAlcaholic;                          // Enums
            alcholicTyp    = BarItemType.Alcaholic;                             // Enums

            cola   = new BarItems(nonAlcholicTyp, quantity, "Coca Cola", 1.20); // Items
            sprite = new BarItems(nonAlcholicTyp, quantity, "Sprite", 1.20);    // Items
            vodka  = new BarItems(alcholicTyp, quantity, "Vodka", 2.50);        // Items

            cbxItem.Items.Add(cola.GetInfo());                                  // Adding the items in the combo box.
            cbxItem.Items.Add(sprite.GetInfo());                                // Adding the items in the combo box.
            cbxItem.Items.Add(vodka.GetInfo());                                 // Adding the items in the combo box.
        }
Example #3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (cbxItem.SelectedIndex == 0 && Int32.TryParse(txtQuantity.Text, out quantity)) // checking for selected index and getting the quantity
            {
                cola = new BarItems(nonAlcholicTyp, quantity, "Coca Cola", 1.20);
                lstItems.Add(cola);                                                                                                                                                   // adding cola to list of the bar
                barLst.Items.Add(cola.GetInfo() + " Type: " + cola.Type.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + cola.GetPrice(quantity).ToString()); // adding the items to the list and appears in the list of the form
            }

            if (cbxItem.SelectedIndex == 1 && Int32.TryParse(txtQuantity.Text, out quantity))
            {
                sprite = new BarItems(nonAlcholicTyp, quantity, "Sprite", 1.20);
                lstItems.Add(sprite);
                barLst.Items.Add(sprite.GetInfo() + " Type: " + sprite.Type.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + sprite.GetPrice(quantity).ToString());
            }
            if (cbxItem.SelectedIndex == 2 && Int32.TryParse(txtQuantity.Text, out quantity))
            {
                vodka = new BarItems(alcholicTyp, quantity, "Vodka", 2.50);
                lstItems.Add(vodka);
                barLst.Items.Add(vodka.GetInfo() + " Type: " + vodka.Type.ToString() + " Quantity: " + quantity.ToString() + "\n Total Price: €" + vodka.GetPrice(quantity).ToString());
            }
        }