Beispiel #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string s = txtSearch.Text.ToLower();

            if (s != "")
            {
                if (Program.ctlList.Count != 0)
                {
                    Burger.DisposeControl(this);
                }

                List <Dish> result = new List <Dish>();
                string[]    words  = s.Split(' ');
                foreach (string word in words)
                {
                    foreach (Dish dish in Program.dishlist)
                    {
                        string name        = dish.Name.ToLower();
                        string description = dish.Description.ToLower();
                        if (name.Contains(word) || description.Contains(word))
                        {
                            result.Add(dish);
                        }
                    }
                }
                result = result.Distinct().ToList();

                Search f = this;
                Burger.DisplayMenuItems(result, tablelaySeach.Bottom, f);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (done)
            {
                Burger.DisposeControl(this);
            }
            done          = true;
            customizeList = new List <Dish>();

            #region PRICE
            foreach (Dish dish in Program.dishlist)
            {
                if (dish.Price <= trbarPrice.Value)
                {
                    customizeList.Add(dish);
                }
            }
            #endregion

            //Calories
            List <Dish> templist = new List <Dish>(customizeList);
            foreach (Dish dish in templist)
            {
                if (dish.Calories > trbarCalories.Value)
                {
                    customizeList.Remove(dish);
                }
            }
            templist = new List <Dish>(customizeList);

            #region MENU TYPE
            templist = new List <Dish>(customizeList);
            foreach (Dish dish in templist)
            {
                if (!checkDishInMenu(dish.Menu, clbMenu))
                {
                    customizeList.Remove(dish);
                }
            }
            templist = new List <Dish>(customizeList);
            #endregion


            //Allergens -with tooltip
            templist = new List <Dish>(customizeList);
            foreach (Dish dish in templist)
            {
                foreach (string ingredient in dish.Allergens)
                {
                    for (int i = 0; i < clbAllergens.CheckedItems.Count; i++)
                    {
                        if (ingredient == clbAllergens.CheckedItems[i].ToString().ToLower())
                        {
                            customizeList.Remove(dish);
                            break;
                        }
                    }
                }
            }

            switch (comboBox1.SelectedIndex)
            {
            case 0:
                customizeList = customizeList.OrderBy(o => o.Name).ToList();
                break;

            case 1:
                customizeList = customizeList.OrderBy(o => o.Price).ToList();
                break;

            case 2:
                customizeList = customizeList.OrderBy(o => o.Calories).ToList();
                break;

            case 3:
                customizeList = customizeList.OrderBy(o => o.Preptime).ToList();
                break;
            }

            Burger.DisplayMenuItems(customizeList, groupBox1.Bottom + 20, this);
        }