private void dAdd_Click(object sender, EventArgs e)
        {
            Regex pattern = new Regex(@"^([0-9]*[1-9][0-9]*(\.[0-9]+)?|[0]+\.[0-9]*[1-9][0-9]*)$");

            if (Calories.Text.Length > 0 &&
                Fats.Text.Length > 0 &&
                Proteins.Text.Length > 0 &&
                Carbohydrates.Text.Length > 0 &&
                Name1.Text.Length > 0 &&
                pattern.IsMatch(Calories.Text) &&
                pattern.IsMatch(Fats.Text) &&
                pattern.IsMatch(Proteins.Text) &&
                pattern.IsMatch(Carbohydrates.Text))
            {
                double fats          = Convert.ToDouble(Fats.Text);
                double proteins      = Convert.ToDouble(Proteins.Text);
                double carbohydrates = Convert.ToDouble(Carbohydrates.Text);
                double calories      = Convert.ToDouble(Calories.Text);
                string name          = Name1.Text.ToUpper();
                name = (" " + name);
                Dish tDish = new Dish(name, proteins, fats, carbohydrates, calories);
                int  comp  = 0;
                for (int j = 0; j < 5; j++)
                {
                    for (int i = 0; i < _dishList.LengthListDish(j); i++)
                    {
                        _dish = _dishList.GetDish(j, i);
                        if (name == _dish.Name)
                        {
                            comp++;
                        }
                    }
                }


                if (comp == 0)
                {
                    _dbController.AddDish(tDish, dishType2.SelectedIndex);
                    MessageBox.Show(@"Блюдо успешно добавлено");
                    _dishList = _dbController.GeDishList();
                    UpdateList();
                }
                else
                {
                    MessageBox.Show(@"Такое блюдо уже есть");
                }
            }
            else
            {
                MessageBox.Show(@"Введите данные ещё раз");
            }
        }
        public DishList GeDishList()
        {
            DishList      dishList = new DishList(DishType.Length);
            SQLiteCommand cmd      = Db.CreateCommand();

            for (int i = 0; i < DishType.Length; i++)
            {
                cmd.CommandText = "select * from Dish where type ='" + DishType[i] + "'";
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Dish dish = new Dish(reader["Name"].ToString().ToUpper(), Convert.ToDouble(reader["Proteins"]), Convert.ToDouble(reader["Fats"]), Convert.ToDouble(reader["Carbohydrates"]), Convert.ToDouble(reader["Calories"]));
                    dishList.AddDish(dish, i);
                }
                reader.Close();
            }
            return(dishList);
        }
 public void MainWindowLoad(object sender, EventArgs e)
 {
     toEatFoodLabel.Text     = "";
     toRejectFoodLabel.Text  = "";
     suggestNameLabel.Text   = "";
     suggestWeightLabel.Text = "";
     weightLabel.Text        = "";
     heightLabel.Text        = "";
     ageLabel.Text           = "";
     resultLabel.Text        = "";
     caloriesLabel.Text      = "";
     checkToEatWeight.Text   = "";
     label21.Text            = "";
     label22.Text            = "";
     label23.Text            = "";
     label24.Text            = "";
     tabPage1.Enabled        = false;
     tabPage2.Enabled        = false;
     tabPage3.Enabled        = false;
     tabPage4.Enabled        = false;
     tabPage5.Enabled        = false;
     tabPage7.Enabled        = false;
     tabPage8.Enabled        = false;
     buttonCalculate.Enabled = true;
     _human        = new Human();
     _dbController = new DbController();
     _dbController.ConnectDb();
     _foodList = new FoodList(_dbController.GetFoodTypeLength());
     _foodList = _dbController.GetFoodList();
     _dishList = new DishList(_dbController.GetDishTypeLength());
     _dishList = _dbController.GeDishList();
     for (int i = 0; i < _foodList.LengthListFood(0); i++)
     {
         ListViewItem item = new ListViewItem(_foodList.GetFood(0, i).Name);
         item.SubItems.Add(_foodList.GetFood(0, i).Proteins.ToString());
         item.SubItems.Add(_foodList.GetFood(0, i).Fats.ToString());
         item.SubItems.Add(_foodList.GetFood(0, i).Carbohydrates.ToString());
         item.SubItems.Add(_foodList.GetFood(0, i).Calories.ToString());
         toEatListView.Items.Add(item);
     }
 }
Exemple #4
0
 public MenuMaker(DishList dishList, Human human)
 {
     _human   = human;
     DishList = dishList;
     MenuList = new DishList(3);
 }