예제 #1
0
        void editTrainingPlan(BodyArchitect.Service.Model.TrainingPlans.TrainingPlan plan)
        {
            ControlHelper.RunWithExceptionHandling(delegate
            {
                WorkoutPlanDTO planDto       = (WorkoutPlanDTO)plan.Tag;
                TrainingPlanEditorWindow wnd = new TrainingPlanEditorWindow();
                wnd.Fill(plan);
                if (wnd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    ParentWindow.RunAsynchronousOperation(delegate
                    {
                        TrainingPlanChecker checker = new TrainingPlanChecker();
                        checker.Process(wnd.TrainingPlan);
                        planDto.SetTrainingPlan(wnd.TrainingPlan);

                        XmlSerializationTrainingPlanFormatter formatter = new XmlSerializationTrainingPlanFormatter();
                        planDto.PlanContent = formatter.ToXml(wnd.TrainingPlan).ToString();

                        planDto.Profile = UserContext.CurrentProfile;
                        ServiceManager.SaveTrainingPlan(planDto);
                        ObjectsReposidory.ClearWorkoutPlansCache();
                        ParentWindow.SynchronizationContext.Send(delegate
                        {
                            Fill();
                        }, null);
                    });
                }
            });
        }
예제 #2
0
        private void rbtnSave_Click(object sender, RoutedEventArgs e)
        {
            var context = Context;

            context.Item.Profile = UserContext.Current.CurrentProfile;

            if (!ensurePlanCorrect(context.Item))
            {
                return;
            }

            PleaseWait.Run(delegate
            {
                try
                {
                    TrainingPlanChecker checker = new TrainingPlanChecker();
                    checker.Process(context.Item);

                    context.Item = ServiceManager.SaveTrainingPlan(context.Item);
                    WorkoutPlansReposidory.Instance.AddOrUpdate(context.Item);

                    Dispatcher.BeginInvoke(new Action(Fill));
                }
                catch (Exception ex)
                {
                    Dispatcher.BeginInvoke(new Action(() => ExceptionHandler.Default.Process(ex, StrengthTrainingEntryStrings.TrainingPlanEditorWindow_ErrSaveWorkoutPlan, ErrorWindow.EMailReport)));
                }
            });
        }
        private void btnJoin_Click(object sender, RoutedEventArgs e)
        {
            TrainingPlanDay day = null;

            foreach (TrainingPlanSetEditorItemViewModel selectedItem in lvExercises.SelectedItems)
            {
                TrainingPlanEntry entry = selectedItem.Entry;
                if (day != null && entry.Day != day)
                {
                    BAMessageBox.ShowError(StrengthTrainingEntryStrings.ErrorCannotCreateSuperSetDifferentDays);
                    return;
                }
                day = entry.Day;
            }

            //foreach (TrainingPlanSetEditorItemViewModel selectedItem in lvExercises.SelectedItems)
            //{
            //    TrainingPlanEntry entry = selectedItem.Entry;
            //    var superSet = day.GetSuperSet(entry);
            //    if (superSet != null)
            //    {
            //        superSet.SuperSets.Remove(entry);
            //    }
            //}
            var superSetGroup   = Guid.NewGuid();//TODO:Change this to some better name (at least in display)
            var selectedEntries = lvExercises.SelectedItems.Cast <TrainingPlanSetEditorItemViewModel>().Select(x => x.Entry);

            foreach (var trainingPlanEntry in selectedEntries)
            {
                trainingPlanEntry.GroupName = superSetGroup.ToString();
            }

            //SuperSet newSet = new SuperSet();
            //foreach (TrainingPlanSetEditorItemViewModel selectedItem in lvExercises.SelectedItems)
            //{
            //    TrainingPlanEntry entry = selectedItem.Entry;
            //    newSet.SuperSets.Add(entry);
            //}
            //day.SuperSets.Add(newSet);

            //clear empty supersets or with only one exercise
            TrainingPlanChecker checker = new TrainingPlanChecker();

            checker.Process(plan);

            Fill(plan);
        }
        private void mnuRemoveSuperSet_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem selectedItem in exercisesTrainingPlanListView1.SelectedItems)
            {
                TrainingPlanEntry entry = (TrainingPlanEntry)selectedItem.Tag;
                var superSet            = entry.Day.GetSuperSet(entry);
                if (superSet != null)
                {
                    superSet.SuperSets.Remove(entry);
                }
            }

            //clear empty supersets or with only one exercise
            TrainingPlanChecker checker = new TrainingPlanChecker();

            checker.Process(plan);
            exercisesTrainingPlanListView1.Fill(plan);
        }
        private void mnuJoinSuperSet_Click(object sender, EventArgs e)
        {
            TrainingPlanDay day = null;

            foreach (ListViewItem selectedItem in exercisesTrainingPlanListView1.SelectedItems)
            {
                TrainingPlanEntry entry = (TrainingPlanEntry)selectedItem.Tag;
                if (day != null && entry.Day != day)
                {
                    FMMessageBox.ShowError(StrengthTrainingEntryStrings.ErrorCannotCreateSuperSetDifferentDays);
                    return;
                }
                day = entry.Day;
            }

            foreach (ListViewItem selectedItem in exercisesTrainingPlanListView1.SelectedItems)
            {
                TrainingPlanEntry entry = (TrainingPlanEntry)selectedItem.Tag;
                var superSet            = day.GetSuperSet(entry);
                if (superSet != null)
                {
                    superSet.SuperSets.Remove(entry);
                }
            }

            SuperSet newSet = new SuperSet();

            foreach (ListViewItem selectedItem in exercisesTrainingPlanListView1.SelectedItems)
            {
                TrainingPlanEntry entry = (TrainingPlanEntry)selectedItem.Tag;
                newSet.SuperSets.Add(entry);
            }
            day.SuperSets.Add(newSet);

            //clear empty supersets or with only one exercise
            TrainingPlanChecker checker = new TrainingPlanChecker();

            checker.Process(plan);

            exercisesTrainingPlanListView1.Fill(plan);
        }
        private void btnSplit_Click(object sender, RoutedEventArgs e)
        {
            //foreach (TrainingPlanSetEditorItemViewModel selectedItem in lvExercises.SelectedItems)
            //{
            //    TrainingPlanEntry entry = selectedItem.Entry;
            //    var superSet = entry.Day.GetSuperSet(entry);
            //    if (superSet != null)
            //    {
            //        superSet.SuperSets.Remove(entry);
            //    }
            //}
            var selectedEntries = lvExercises.SelectedItems.Cast <TrainingPlanSetEditorItemViewModel>().Select(x => x.Entry);

            foreach (var trainingPlanEntry in selectedEntries)
            {
                trainingPlanEntry.GroupName = null;
            }

            //clear empty supersets or with only one exercise
            TrainingPlanChecker checker = new TrainingPlanChecker();

            checker.Process(plan);
            Fill(plan);
        }