Example #1
0
        private List <DrinksGroup> ConvertBeerRowsToGroups(List <DrinkDisplayRow> beerRows)
        {
            List <DrinksGroup> groups             = new List <DrinksGroup>();
            DrinksGroup        displayDraftsPints = new DrinksGroup("Pints");

            groups.Add(displayDraftsPints);
            DrinksGroup displayDraftsPitchers = new DrinksGroup("Pitchers");

            groups.Add(displayDraftsPitchers);

            foreach (var row in beerRows)
            {
                if (row.RowDrinks[0].DrinkSize == DrinkSize.Pint)
                {
                    displayDraftsPints.Add(row);
                }
                else if (row.RowDrinks[0].DrinkSize == DrinkSize.Pitcher)
                {
                    displayDraftsPitchers.Add(row);
                }
            }

            return(groups);
        }
Example #2
0
        /// <summary>
        /// A method that is called when a customer click on a dish in menu
        /// <remarks>It connects to the database and put info in appropriate place</remarks>
        /// </summary>
        /// <param name="linklabel">Current linklabel which customer clicked on</param>
        private void DishChosen(LinkLabel linklabel)
        {
            try
            {
                //connect to the local database
                dB.OpenConnection();
                //command string
                string          sqlWeight = $"SELECT * FROM dish WHERE Name = '{linklabel.Text}'";
                MySqlCommand    command   = new(sqlWeight, dB.connection);
                MySqlDataReader reader    = command.ExecuteReader();
                //read while there is an info for the reader condition
                while (reader.Read())
                {
                    //reading info about dish: weight, price, ingredients and ID
                    weight.Add(Convert.ToInt32(reader["Weight"]));
                    price.Add(Convert.ToInt32(reader["Price"]));
                    productsTemp.Add(reader["Ingredients"].ToString());
                    id = Convert.ToInt32(reader["ID"]);
                }
                //close reader and connections
                reader.Close();
                dB.CloseConnection();

                foreach (var item in productsTemp)
                {
                    //creating product-class ingredients
                    products.Add(new Product(item));
                }
                productsTemp.Clear();
            }
            catch (Exception)
            {
                throw;
            }
            try
            {
                //check the restaurant limitation of max. 10 dishes for one order
                if (listBox1.Items.Count < 10)
                {
                    //check if the dish exists in the order
                    if (listBox1.Items.Contains(linklabel.Text))
                    {
                        //variable to store a dish and index of them
                        string countOfExistingDish = "";
                        int    indexOfExistingDish = 0;
                        for (int i = 0; i < order.order.Count; i++)
                        {
                            if (order.order[i].Name == linklabel.Text)
                            {
                                indexOfExistingDish  = i;
                                countOfExistingDish += i.ToString();
                            }
                        }
                        //check if it possible for the dish to exist more than once in the order
                        if (order.order[indexOfExistingDish]._weight.Count == countOfExistingDish.Length)
                        {
                            throw new AlreadyExistException();
                        }
                    }
                    //make the number of dish in order greater
                    countOfDishes++;
                    //block using changing methods for comboBoxes and numUpDowns
                    ifChange = false;
                    //show appropriate elements on the form
                    comboBoxes[countOfDishes - 1].Show(); upDowns[countOfDishes - 1].Show();
                    button4.Show();
                    //the listBox1 and listBox2 bigger if it is necessary
                    if (listBox1.Items.Count > 0)
                    {
                        listBox1.Height += 35;
                        listBox2.Height += 35;
                    }
                    //if a customer added one of the special dish group, refer dish to them
                    Dish dish;
                    if (id >= 1 && id <= 7)
                    {
                        dish = new SoupGroup(linklabel.Text, weight, price);
                    }
                    else if (id >= 18 && id <= 22)
                    {
                        dish = new MeatGroup(linklabel.Text, weight, price);
                    }
                    else if (id >= 28 && id <= 31)
                    {
                        dish = new DrinksGroup(linklabel.Text, weight, price);
                    }
                    else
                    {
                        dish = new(linklabel.Text, weight, price);
                    }
                    //forming ingredients of the dish and add it to the order
                    dish.AddIngredient(products);
                    order.OrderAdd(dish);

                    listBox1.Items.Add(linklabel.Text);

                    if (comboBoxes[countOfDishes - 1].Items.Count > 0)
                    {
                        comboBoxes[countOfDishes - 1].Items.Clear();
                    }
                    //adding new data to current comboBox
                    foreach (var item in weight)
                    {
                        comboBoxes[countOfDishes - 1].Items.Add(item);
                    }
                    //show the first possible value of weight in comboBox
                    comboBoxes[countOfDishes - 1].SelectedItem = weight[0];
                    //count the sum of current dish according to the weight and price
                    listBox2.Items.Add(order.order[countOfDishes - 1]._price[0] * upDowns[countOfDishes - 1].Value);

                    //allow using changing methods for comboBoxes and numUpDowns
                    ifChange = true;
                    //clear temporary elements
                    id = 0;
                    weight.Clear();
                    price.Clear();
                    products.Clear();
                }
                else
                {
                    throw new LimitReachedException();
                }
            }
            //catch all necessary exceptions
            catch (LimitReachedException arg1)
            {
                MessageBox.Show(arg1.Message);
            }
            catch (AlreadyExistException arg2)
            {
                MessageBox.Show(arg2.Message);
            }
        }