コード例 #1
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            Exercise _ex = cmbTraining.SelectedItem as Exercise;

            if (_ex == null)
            {
                return;
            }

            bool isRecord = false;

            using (MobileContext db = new MobileContext())
            {
                if (tr != null)
                {
                    tr.ExerciseId = Int32.Parse(cmbTraining.SelectedValue.ToString());
                    tr.Weight     = short.Parse(tbWeight.Text.ToString());
                    tr.Iteration  = short.Parse(tbIteration.Text.ToString());
                    tr.ex         = _ex;
                    db.Trainings.Update(tr);
                    db.SaveChanges();
                }
                else
                {
                    Training tr = new Training
                    {
                        Date       = DateTime.Now.Date,
                        Weight     = Int16.Parse(tbWeight.Text.ToString()),
                        Iteration  = Int16.Parse(tbIteration.Text.ToString()),
                        ExerciseId = Int32.Parse(cmbTraining.SelectedValue.ToString()),
                        ex         = _ex
                    };
                    db.Exercises.Attach(_ex);
                    db.Trainings.Add(tr);

                    if ((tr.Weight > _ex.Weight) || (tr.Weight == _ex.Weight && tr.Iteration > _ex.Iteration))
                    {
                        _ex.Weight    = tr.Weight;
                        _ex.Iteration = tr.Iteration;
                        isRecord      = true;
                    }
                    db.SaveChanges();
                }
            }
            if (isRecord)
            {
                Frame.Navigate(typeof(congratulations));
            }
            else
            {
                GoToMainPage();
            }
        }
コード例 #2
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     // получаем выделеный пункт меню
     if (exerciseList.SelectedItem != null)
     {
         Exercise ex = exerciseList.SelectedItem as Exercise;
         if (ex != null)
         {
             using (MobileContext db = new MobileContext())
             {
                 db.Exercises.Remove(ex);
                 db.SaveChanges();
                 exerciseList.ItemsSource = db.Exercises.ToList();
             }
         }
     }
 }
コード例 #3
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     // получаем выделеный пункт меню
     if (tList.SelectedItem != null)
     {
         Training tr = tList.SelectedItem as Training;
         if (tr != null)
         {
             using (MobileContext db = new MobileContext())
             {
                 db.Trainings.Remove(tr);
                 db.SaveChanges();
                 exercisesList     = db.Exercises.ToList();
                 list              = new ObservableCollection <Training>(db.Trainings.Where(r => r.Date.Date == DateTime.Now.Date).Include(x => x.ex).ToList());
                 tList.ItemsSource = list;
             }
         }
     }
 }
コード例 #4
0
 private void Save_Click(object sender, RoutedEventArgs e)
 {
     using (MobileContext db = new MobileContext())
     {
         if (ex != null)
         {
             ex.Name = tbName.Text;
             db.Exercises.Update(ex);
         }
         else
         {
             db.Exercises.Add(new Exercise {
                 Name = tbName.Text
             });
         }
         db.SaveChanges();
     }
     GoToMainPage();
 }