private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (RegexAdmin(LoginBox.Text))
     {
         AdminWindow admin = new AdminWindow();
         admin.Show();
         Close();
     }
     else if (RegexLogin(LoginBox.Text))
     {
         DataTable find = SqlDB.Select($"select * from [Users] where login='******'");
         if (find.Rows.Count > 0)
         {
             SqlDB.GetUserId(LoginBox.Text);
             MainWindow mw = new MainWindow();
             mw.Show();
             Close();
             MessageBox.Show("Пользователь авторизовался");
         }
         else
         {
             SqlDB.Command($"insert into [Users] values ('{LoginBox.Text}')");
             MainWindow mw = new MainWindow();
             find = SqlDB.Select($"select * from [Users] where login='******'");
             SqlDB.GetUserId(LoginBox.Text);
             mw.Show();
             Close();
         }
     }
     else
     {
         MessageBox.Show("Введите E-mail");
     }
 }
        private void SetStatus()
        {
            DataTable     dt       = SqlDB.Select($"select * from Statuses");
            List <string> statuses = new List <string>();

            foreach (DataRow dr in dt.Rows)
            {
                statuses.Add(dr["name"].ToString());
            }
            Status.ItemsSource = statuses;
        }
Esempio n. 3
0
        public void SetIngredients()
        {
            List <Category> categories = new List <Category>();
            DataTable       dt         = SqlDB.Select("select * from Categories");

            foreach (DataRow dr in dt.Rows)
            {
                categories.Add(new Category {
                    Name = dr["name"].ToString()
                });
            }
            Table.ItemsSource = categories;
        }
        private void GetUserSettings()
        {
            DataTable dt = SqlDB.Select($"select * from Users_Setting join Statuses on Users_Setting.status_id = Statuses.id where user_id={SqlDB.UserID}");

            if (dt.Rows.Count != 0)
            {
                Status.Text = dt.Rows[0]["name"].ToString();
                Weight.Text = dt.Rows[0]["weight"].ToString();
                int height        = Convert.ToInt32(dt.Rows[0]["height"].ToString());
                int age           = Convert.ToInt32(dt.Rows[0]["height"].ToString());
                int weight        = Convert.ToInt32(Weight.Text);
                int calories_days = Convert.ToInt32(10 * weight + (6.25 * height) - (5 * age));
                DaysCalories.Text += calories_days.ToString();
            }
        }
        public void GetIngredients()
        {
            DataTable data = SqlDB.Select($"select Dishes.id, Categories.[name] as category, Dishes.[name], proteins, fats, carbohydrates, calories from Dishes join Categories on Categories.id = id_category");

            items = new List <Dish>();
            foreach (DataRow dr in data.Rows)
            {
                items.Add(new Dish()
                {
                    ID       = Convert.ToInt32(dr["id"]), Name = dr["name"].ToString(), Category = dr["category"].ToString(),
                    Calories = Convert.ToInt32(dr["calories"]), Proteins = Convert.ToInt32(dr["proteins"]),
                    Fats     = Convert.ToInt32(dr["fats"]), Carbohydrates = Convert.ToInt32(dr["carbohydrates"])
                });
            }
            Ingredients.ItemsSource = items;
        }
        private void UpdateAllOnClick(object sender, RoutedEventArgs e)
        {
            DataTable dt = SqlDB.Select($"select * from Dayily_Stats where id_user={SqlDB.UserID} and [date]=(select convert(varchar(10),(select getdate()), 120))");

            if (dt.Rows.Count <= 0)
            {
                MessageBox.Show("Продукты не добавлены");
                return;
            }
            DataRow    dr = dt.Rows[0];
            DailyStats ds = new DailyStats();

            ds = new DailyStats {
                Date     = dr["date"].ToString(), Water = Convert.ToInt32(dr["water"]),
                Calories = Convert.ToInt32(dr["calories"]), Fats = Convert.ToInt32(dr["fats"]),
                Proteins = Convert.ToInt32(dr["proteins"]), Carbohydrates = Convert.ToInt32(dr["carbohydrates"])
            };
            foreach (var series in Chart.Series)
            {
                foreach (var observable in series.Values.Cast <ObservableValue>())
                {
                    switch (series.Title)
                    {
                    case "Калории":
                        observable.Value = ds.Calories;
                        break;

                    case "Белки":
                        observable.Value = ds.Proteins;
                        break;

                    case "Жиры":
                        observable.Value = ds.Fats;
                        break;

                    case "Углеводы":
                        observable.Value = ds.Carbohydrates;
                        break;

                    case "Вода":
                        observable.Value = ds.Water;
                        break;
                    }
                }
            }
        }
        public void SetDishes()
        {
            List <Dish> dishes = new List <Dish>();
            DataTable   dt     = SqlDB.Select($"select Dishes.id, Categories.[name] as category, Dishes.[name], proteins, fats, carbohydrates, calories from Dishes join Categories on Categories.id = id_category");

            foreach (DataRow dr in dt.Rows)
            {
                dishes.Add(new Dish()
                {
                    Name          = dr["name"].ToString(),
                    Category      = dr["category"].ToString(),
                    Calories      = Convert.ToDouble(dr["calories"]),
                    Proteins      = Convert.ToDouble(dr["proteins"]),
                    Fats          = Convert.ToDouble(dr["fats"]),
                    Carbohydrates = Convert.ToDouble(dr["carbohydrates"])
                });
            }
            Table.ItemsSource = dishes;
        }
        public void SetIngredients()
        {
            List <Ingredient> ingredients = new List <Ingredient>();
            DataTable         dt          = SqlDB.Select("select * from Ingredients");

            foreach (DataRow dr in dt.Rows)
            {
                ingredients.Add(new Ingredient()
                {
                    Name          = dr["name"].ToString(),
                    Weight        = Convert.ToDouble(dr["weight"]),
                    Calories      = Convert.ToDouble(dr["calories"]),
                    Proteins      = Convert.ToDouble(dr["proteins"]),
                    Fats          = Convert.ToDouble(dr["fats"]),
                    Carbohydrates = Convert.ToDouble(dr["carbohydrates"])
                });
            }
            Table.ItemsSource = ingredients;
        }
Esempio n. 9
0
        public void SetStatistic()
        {
            DataTable         dt    = SqlDB.Select($"select * from Dayily_Stats where id_user={SqlDB.UserID}");
            List <DailyStats> stats = new List <DailyStats>();

            foreach (DataRow dr in dt.Rows)
            {
                stats.Add(new DailyStats {
                    ID            = Convert.ToInt32(dr["id"]),
                    Date          = dr["date"].ToString(),
                    Water         = Convert.ToInt32(dr["water"]),
                    Proteins      = Convert.ToDouble(dr["proteins"]),
                    Fats          = Convert.ToDouble(dr["fats"]),
                    Carbohydrates = Convert.ToDouble(dr["carbohydrates"]),
                    Calories      = Convert.ToDouble(dr["calories"])
                });
            }
            Statistic.ItemsSource = stats;
        }
Esempio n. 10
0
        private void Statistic_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Statistic.SelectedItem = sender;
            DailyStats  daily  = (DailyStats)Statistic.SelectedItem;
            DateTime    result = DateTime.ParseExact(daily.Date.Substring(0, 10), "dd.MM.yyyy", CultureInfo.InvariantCulture);
            string      date   = result.ToString("yyyy-MM-dd");
            DataTable   dt     = SqlDB.Select($"select Dishes.[name], proteins, fats, carbohydrates, calories from Users_Dishes join Dishes on Dishes.id = id_dish where id_user={SqlDB.UserID} and [date]='{date}'");
            List <Dish> dishes = new List <Dish>();

            foreach (DataRow dr in dt.Rows)
            {
                dishes.Add(new Dish
                {
                    Name          = dr["name"].ToString(),
                    Proteins      = Convert.ToDouble(dr["proteins"]),
                    Fats          = Convert.ToDouble(dr["fats"]),
                    Carbohydrates = Convert.ToDouble(dr["carbohydrates"]),
                    Calories      = Convert.ToDouble(dr["calories"])
                });
            }
            Table.ItemsSource = dishes;
        }