Beispiel #1
0
 private void refresh()
 {
     using (MobileContext db = new MobileContext())
     {
         exerciseList.ItemsSource = db.Exercises.OrderBy(r => r.Name).ToList();
     }
 }
Beispiel #2
0
 private void calendar_SelectedDatesChanged(CalendarView sender, CalendarViewSelectedDatesChangedEventArgs args)
 {
     if (calendar.SelectedDates == null)
     {
         return;
     }
     try
     {
         DateTime date = calendar.SelectedDates.First().Date;
         if (dates.Contains(date))
         {
             using (MobileContext db = new MobileContext())
             {
                 exercisesList = db.Exercises.ToList();
                 trainList     = new ObservableCollection <Training>(db.Trainings.Where(r => r.Date.Date == date).Include(x => x.ex).ToList());
             }
             List.ItemsSource = trainList;
         }
         else
         {
             List.ItemsSource = null;
         }
     }
     catch { }
 }
Beispiel #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            using (MobileContext db = new MobileContext())
            {
                cmbTraining.ItemsSource       = db.Exercises.OrderBy(r => r.Name).ToList();
                cmbTraining.DisplayMemberPath = "Name";
                cmbTraining.SelectedValuePath = "Id";
            }
            if (e.Parameter != null)
            {
                int id = (int)e.Parameter;
                using (MobileContext db = new MobileContext())
                {
                    tr = db.Trainings.FirstOrDefault(c => c.Id == id);
                }
            }

            if (tr != null)
            {
                headerBlock.Text          = "Редактирование подхода";
                cmbTraining.SelectedValue = tr.ExerciseId;
                tbWeight.Text             = tr.Weight.ToString();
                tbIteration.Text          = tr.Iteration.ToString();
            }
        }
Beispiel #4
0
 public history()
 {
     this.InitializeComponent();
     using (MobileContext db = new MobileContext())
     {
         dates = db.Trainings.Select(x => x.Date).Distinct().ToList();
     }
 }
Beispiel #5
0
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     using (MobileContext db = new MobileContext())
     {
         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;
 }
Beispiel #6
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();
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                int id = (int)e.Parameter;
                using (MobileContext db = new MobileContext())
                {
                    ex = db.Exercises.FirstOrDefault(c => c.Id == id);
                }
            }

            if (ex != null)
            {
                headerBlock.Text = "Редактирование упражнения";
                tbName.Text      = ex.Name;
            }
        }
Beispiel #8
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();
             }
         }
     }
 }
Beispiel #9
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;
             }
         }
     }
 }
 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();
 }