コード例 #1
0
 public void Take_Stat()
 {
     using (StaticsticContext db = new StaticsticContext())
     {
         string weight = null;
         db.Staticstics.Load();
         var list = db.Staticstics.Local.ToBindingList();
         foreach (var item in list)
         {
             if (item.ID_user == user.ID_user)
             {
                 weight = item.Weight_note;
             }
             else
             {
                 weight = user.Weight_start;
             }
             if (item.ID_user == user.ID_user && item.ID_training == train.ID_training)
             {
                 day++;
             }
         }
         day++;
         DateTime data     = DateTime.Now;
         var      new_stat = new Staticstic {
             ID_session = 1, ID_training = train.ID_training, ID_user = user.ID_user, Time = train.Time, Weight_note = weight, Data_traning = data.ToString()
         };
         db.Staticstics.Add(new_stat);
         db.SaveChanges();
     }
     Fiil_progress(day); //в днях
     if (day == 21)
     {
         var win_ano = new ANNOUNCEMENTWorkoutFinale();
         win_ano.Show();
     }
 }
コード例 #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();
                }
            }
        }