Exemplo n.º 1
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            int id_train;

            if (Intensity_num != 0 && type_train != 0 && list_ex_id.Count != 0 && this.new_name.Text != "")
            {
                using (TrainingContext db = new TrainingContext())
                {
                    Training new_train = new Training {
                        Name_training = this.new_name.Text, Description = this.new_Disc.Text, Groupe = type_train, ID_training = 1, ID_type = user.ID_user, Img = "/Training/user_training.png", Intensity = Intensity_num, Time = time_ex_all
                    };
                    db.Trainings.Add(new_train);
                    db.SaveChanges();
                }

                using (TrainingContext db = new TrainingContext())
                {
                    db.Trainings.Load();
                    var list = db.Trainings.Local.ToBindingList();
                    id_train = list.Count;
                }

                using (ConnectionContext db = new ConnectionContext())
                {
                    foreach (var item in list_ex_id)
                    {
                        var new_con = new Connection {
                            ID_note = 1, ID_ex = item, ID_training = id_train
                        };
                        db.Connections.Add(new_con);
                    }
                    db.SaveChanges();
                }

                var win_user_train = new MainTrainWin(user);
                win_user_train.Show();
                win_c.Close();
            }
            else
            {
                var win_er = new ERRORWin();
                win_er.ChooseError("ERRORDataEntry");
                win_er.Show();
            }
        }
Exemplo n.º 2
0
        private void Button_Click_Update(object sender, RoutedEventArgs e)
        {
            if (flag2)
            {
                if (flag_ch)
                {
                    this.Weight.Visibility     = Visibility.Hidden;
                    this.Add_weight.Visibility = Visibility.Visible;
                    this.Button_update.Content = "Сохранить";
                    flag2 = false;
                }
                else
                {
                    var win_er = new ERRORWin();
                    win_er.ChooseError("ERRORNotTrain");
                    win_er.Show();
                }
            }
            else
            {
                this.Weight.Visibility     = Visibility.Visible;
                this.Add_weight.Visibility = Visibility.Hidden;
                Regex           reg     = new Regex(@"^[0-9]*[,]?[0-9]+$");
                MatchCollection matches = reg.Matches(this.Add_weight.Text);
                if (matches.Count > 0)
                {
                    this.Weight.Text           = this.Add_weight.Text;
                    this.Button_update.Content = "Обновить";

                    flag2 = true;

                    using (StaticsticContext db = new StaticsticContext())
                    {
                        db.Staticstics.Load();
                        var list = db.Staticstics.Local.ToBindingList();
                        int key  = 0;
                        foreach (var item in list)
                        {
                            if (item.ID_user == user.ID_user)
                            {
                                key = item.ID_session;
                            }
                        }
                        if (key != 0)
                        {
                            var item = db.Staticstics.Find(key);
                            if (item != null)
                            {
                                item.Weight_note = this.Add_weight.Text;
                                db.SaveChanges();
                            }
                        }
                    }
                    this.Add_weight.Text = "00,0";
                    var win_stat = new Statistics_train(user);
                    this.Main_Frame.Navigate(win_stat);
                }
                else
                {
                    this.Button_update.Content = "Обновить";
                    this.Add_weight.Text       = "00,0";
                    flag2 = true;
                    var win_a = new ERRORWin();
                    win_a.ChooseError("ERRORDataEntry");
                    win_a.Show();
                }
            }
        }
Exemplo n.º 3
0
        private void Button_Click_Next_Regist(object sender, RoutedEventArgs e)
        {
            if (!flag2)
            {
                using (UserContext db = new UserContext())
                {
                    var user_linq = db.Users.Where(p => p.Login == this.new_login.Text).ToList();

                    if (user_linq.Count != 0)
                    {
                        var win_c = new ERRORWin();
                        win_c.ChooseError("ERRORLoginClose");
                        win_c.Show();
                    }
                    else
                    {
                        if (this.new_login.Text == "")
                        {
                            var win_a = new ERRORWin();
                            win_a.ChooseError("ERRORDataEntry");
                            win_a.Show();
                        }
                        else
                        {
                            flag2 = true;
                        }
                    }
                }
            }

            if (flag2)
            {
                Regex           reg     = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])\S{1,8}$");
                MatchCollection matches = reg.Matches(this.new_password.Text);
                if (matches.Count > 0)
                {
                    flag3 = true;
                }
                else
                {
                    var win_a = new ERRORWin();
                    win_a.ChooseError("ERRORDataEntry");
                    win_a.Show();
                    flag2 = false;
                }
            }

            if (flag2 && flag3)
            {
                if (flag)
                {
                    progress_bar_step++;
                    flag = false;
                }

                flag4 = false;

                switch (progress_bar_step)
                {
                case 1:
                    this.Progress_bar_registr.Value = 25;
                    this.Grid__regist_1.Visibility  = Visibility.Visible;
                    this.Grid_regist_2.Visibility   = Visibility.Hidden;
                    this.Grid_regist_3.Visibility   = Visibility.Hidden;
                    this.noti.Visibility            = Visibility.Hidden;
                    progress_bar_step++;
                    break;

                case 2:
                    this.Progress_bar_registr.Value = 50;
                    this.Grid__regist_1.Visibility  = Visibility.Hidden;
                    this.Grid_regist_2.Visibility   = Visibility.Visible;
                    this.Grid_regist_3.Visibility   = Visibility.Hidden;
                    this.noti.Visibility            = Visibility.Hidden;
                    progress_bar_step++;
                    break;

                case 3:


                    if (this.new_name.Text == "")
                    {
                        this.Progress_bar_registr.Value = 50;
                        var win_er = new ERRORWin();
                        win_er.ChooseError("ERRORDataEntry");
                        win_er.Show();
                    }
                    else
                    {
                        this.Progress_bar_registr.Value = 75;
                        this.Grid__regist_1.Visibility  = Visibility.Hidden;
                        this.Grid_regist_2.Visibility   = Visibility.Hidden;
                        this.Grid_regist_3.Visibility   = Visibility.Visible;
                        this.noti.Visibility            = Visibility.Hidden;
                        progress_bar_step++;
                    }
                    break;

                case 4:

                    Regex           reg      = new Regex(@"^[0-9]*[,]?[0-9]+$");
                    MatchCollection matches1 = reg.Matches(this.new_w_s.Text);
                    MatchCollection matches2 = reg.Matches(this.new_w_g.Text);
                    if (matches1.Count == 0 || matches2.Count == 0)
                    {
                        this.Progress_bar_registr.Value = 75;
                        var win_er = new ERRORWin();
                        win_er.ChooseError("ERRORDataEntry");
                        win_er.Show();
                    }
                    else
                    {
                        this.Progress_bar_registr.Value = 100;
                        this.Grid__regist_1.Visibility  = Visibility.Hidden;
                        this.Grid_regist_2.Visibility   = Visibility.Hidden;
                        this.Grid_regist_3.Visibility   = Visibility.Hidden;
                        this.noti.Visibility            = Visibility.Visible;
                        progress_bar_step++;
                    }

                    break;

                case 5:
                    DateTime data = DateTime.Now;
                    using (UserContext db = new UserContext())
                    {
                        new_user = new User {
                            ID_user = 1, Name = this.new_name.Text, Age = Convert.ToInt32(this.new_age.Text), Weight_start = this.new_w_s.Text, Weight_goal = this.new_w_g.Text, Data_start = data.ToString(), Login = this.new_login.Text, Password = this.new_password.Text
                        };
                        db.Users.Add(new_user);
                        db.SaveChanges();
                        MainTrainWin win = new MainTrainWin(new_user);
                        win.Show();
                        this.Close();
                    }
                    break;
                }
            }
        }