Exemple #1
0
        public void CreateBreakfast()
        {
            int good = 0;

            while (good == 0)
            {
                Dish   dish1, dish2;
                Random rnd   = new Random();
                int    first = rnd.Next(0, 10000000);
                first = first % DishList.LengthListDish(0);
                dish1 = DishList.GetDish(0, first);
                int second = rnd.Next(0, 10000000);
                second = second % DishList.LengthListDish(1);
                dish2  = DishList.GetDish(1, second);
                double calories = 0.85 * 3 / 8 * _human.Calories;
                double weight1, weight2;
                weight1 = calories * 0.7 / dish1.Calories * 100;
                weight2 = calories * 0.3 / dish2.Calories * 100;
                if ((weight1 < _kashaWeight[1]) && (weight1 > _kashaWeight[0]) && (weight2 < _zakuskaWeight[1]) &&
                    (weight2 > _zakuskaWeight[0]))
                {
                    good         = 1;
                    dish1.Weight = Math.Round(weight1, MidpointRounding.AwayFromZero);
                    dish2.Weight = Math.Round(weight2, MidpointRounding.AwayFromZero);
                    MenuList.AddDish(dish1, 0);
                    MenuList.AddDish(dish2, 0);
                }
            }
        }
        private void UpdateList()
        {
            toEatListView.Items.Clear();
            string type  = foodType.Text;
            int    index = _foodList.IndexListFood(type);

            if (index == 0)
            {
                for (int i = 0; i < _foodList.LengthListFood(index); i++)
                {
                    ListViewItem item = new ListViewItem(_foodList.GetFood(index, i).Name);
                    item.SubItems.Add(_foodList.GetFood(index, i).Proteins.ToString());
                    item.SubItems.Add(_foodList.GetFood(index, i).Fats.ToString());
                    item.SubItems.Add(_foodList.GetFood(index, i).Carbohydrates.ToString());
                    item.SubItems.Add(_foodList.GetFood(index, i).Calories.ToString());
                    toEatListView.Items.Add(item);
                }
            }
            else
            {
                if (index < 9)
                {
                    for (int i = 0; i < _foodList.LengthListFood(index); i++)
                    {
                        ListViewItem item = new ListViewItem(_foodList.GetFood(index, i).Name);
                        item.SubItems.Add(_foodList.GetFood(index, i).Proteins.ToString());
                        item.SubItems.Add(_foodList.GetFood(index, i).Fats.ToString());
                        item.SubItems.Add(_foodList.GetFood(index, i).Carbohydrates.ToString());
                        item.SubItems.Add(_foodList.GetFood(index, i).Calories.ToString());
                        toEatListView.Items.Add(item);
                    }
                }
                else
                {
                    int j = index - 9;
                    for (int i = 0; i < _dishList.LengthListDish(j); i++)
                    {
                        ListViewItem item = new ListViewItem(_dishList.GetDish(j, i).Name);
                        item.SubItems.Add(_dishList.GetDish(j, i).Proteins.ToString());
                        item.SubItems.Add(_dishList.GetDish(j, i).Fats.ToString());
                        item.SubItems.Add(_dishList.GetDish(j, i).Carbohydrates.ToString());
                        item.SubItems.Add(_dishList.GetDish(j, i).Calories.ToString());
                        toEatListView.Items.Add(item);
                    }
                }
            }
        }