private static void thumbnail_TabbedThumbnailClosed(object sender, TabbedThumbnailClosedEventArgs e)
        {
            //var layoutDoc = LayoutPane.Children.Where(x => x.Content == e.WindowsControl).SingleOrDefault();
            LayoutDocumentPaneGroup paneGroup = (LayoutDocumentPaneGroup)((LayoutPanel)dockManager.Layout.Children.ElementAt(0)).Children[0];
            LayoutContent           layoutDoc = null;

            foreach (LayoutDocumentPane a in paneGroup.Children)
            {
                layoutDoc = a.Children.Where(x => x.Content == e.WindowsControl).SingleOrDefault();
                if (layoutDoc != null)
                {
                    break;
                }
            }
            if (layoutDoc == null)
            {
                return;
            }
            var controlView = layoutDoc.Content as IControlView;

            if (controlView == null)
            {
                controlView = ((Frame)layoutDoc.Content).Content as IControlView;
            }
            if (controlView != null && controlView.IsModified)
            {
                BAMessageBox.ShowInfo(Strings.Message_MainWindow_ShowPage_ModifiedView);
            }
            layoutDoc.ContentId = "CodeRemoval";
            layoutDoc.Parent.RemoveChild(layoutDoc);
            SetActivePreview((UIElement)dockManager.ActiveContent);
        }
        public static void Show()
        {
            var ctrl = new ForgotPasswordControl();

            ctrl.ShowPopup(dlg =>
            {
                dlg.IsCancelVisible = true;
                dlg.Completed      += (a, s) =>
                {
                    if (s.PopUpResult == PopUpResult.Ok && !string.IsNullOrEmpty(ctrl.UserNameOrEmail))
                    {
                        //var service = ApplicationState.CreateService();
                        //service.AccountOperationAsync(ctrl.UserNameOrEmail, AccountOperationType.RestorePassword);
                        //BAMessageBox.ShowInfo(ApplicationStrings.ForgotPasswordControl_PasswordHasBeenSent);

                        var m = new ServiceManager <GetImageCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <GetImageCompletedEventArgs> operationCompleted)
                        {
                            client1.AccountOperationAsync(ctrl.UserNameOrEmail, AccountOperationType.RestorePassword);
                            BAMessageBox.ShowInfo(ApplicationStrings.ForgotPasswordControl_PasswordHasBeenSent);
                        });

                        m.Run(true);
                    }
                };
            });
        }
        protected void btnShowOldPrevious_Click(object sender, EventArgs e)
        {
            if (pivot.SelectedIndex == 2)
            {
                var list     = ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays.Values.SelectMany(x => x.TrainingDay.Objects).OrderByDescending(x => x.TrainingDay.TrainingDate).Where(x => x.GetType() == EntryType && !x.IsSame(Entry)).ToList();
                int position = -1;
                if (oldEntry != null)
                {
                    var currentItem = list.Where(x => x.IsSame(oldEntry)).SingleOrDefault();
                    position = list.IndexOf(currentItem);
                }

                if (list.Count == 0 || position == list.Count - 1)
                {
                    BAMessageBox.ShowInfo(ApplicationStrings.StrengthWorkoutPage_NoMoreTrainingsLoaded);
                }
                else
                {
                    var newEntry = list.ElementAt(position + 1);


                    displayOldEntry(newEntry);
                }
            }
        }
        void mnuShowMap_Click(object sender, EventArgs e)
        {
            var pointsBag = ApplicationState.Current.TrainingDay.GetGpsCoordinates(viewModel.Entry);

            if (!viewModel.Entry.HasCoordinates && (pointsBag == null || pointsBag.Points.Count == 0))
            {
                BAMessageBox.ShowInfo(ApplicationStrings.GPSTrackerPage_EntryWithoutGPSData);
                return;
            }
            this.Navigate("/Pages/MapPage.xaml");
        }
        private void btnAddToFavorites_Click(object sender, EventArgs e)
        {
            if (!UpgradeAccountControl.EnsureAccountType(ApplicationStrings.Feature_Premium_CreatingWorkoutPlans, this))
            {
                return;
            }
            progressBar.ShowProgress(true);
            var m = new ServiceManager <WorkoutPlanOperationCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <WorkoutPlanOperationCompletedEventArgs> operationCompleted)
            {
                var param           = new WorkoutPlanOperationParam();
                param.WorkoutPlanId = SelectedPlan.GlobalId;
                param.Operation     = SupplementsCycleDefinitionOperation.AddToFavorites;
                client1.WorkoutPlanOperationAsync(ApplicationState.Current.SessionData.Token, param);
                client1.WorkoutPlanOperationCompleted -= operationCompleted;
                client1.WorkoutPlanOperationCompleted += operationCompleted;
            });

            m.OperationCompleted += (s1, a1) =>
            {
                progressBar.ShowProgress(false);
                FaultException <BAServiceException> serviceEx = a1.Error as FaultException <BAServiceException>;
                if (serviceEx != null && serviceEx.Detail.ErrorCode == ErrorCode.LicenceException)
                {
                    BAMessageBox.ShowInfo(ApplicationStrings.ErrLicence);
                    return;
                }
                if (a1.Error != null)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrCannotAddPlanToFavorites);
                    return;
                }
                else
                {
                    ApplicationState.Current.Cache.TrainingPlans.Items.Add(SelectedPlan.GlobalId, SelectedPlan);
                }
                updateApplicationBar();
            };

            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Beispiel #6
0
        private void rbtnStartCycle_Click(object sender, RoutedEventArgs e)
        {
            if (!UIHelper.EnsurePremiumLicence())
            {
                return;
            }
            StartSupplementsCycleWindow dlg = new StartSupplementsCycleWindow();

            dlg.SelectedCycleDefinition = SelectedDefinition;
            if (dlg.ShowDialog() == true)
            {
                BAMessageBox.ShowInfo("Info_usrSupplementsCyclesView_rbtnStartCycle_Click_StartedCycle".TranslateSupple());
            }
        }
        void ensureNewEntry()
        {
            var emptyEntry = isEmptyEntry();

            if (emptyEntry)
            {
                if (Settings.LocationServices)
                {
                    myWatcher.Start();
                }
                else
                {
                    BAMessageBox.ShowInfo(ApplicationStrings.GPSTrackerPage_InfoLocationServiceDisabled);
                }
                var existingCoordinates = ApplicationState.Current.TrainingDay.GetGpsCoordinates(Entry);
                if (existingCoordinates == null)
                {
                    ApplicationState.Current.TrainingDay.SetGpsCoordinates(Entry, new List <GPSPoint>(), false);
                }
            }
            else
            {
                //when user press save after the training, he can no longer continue it so we can stop timer and gps
                cleanUp();
            }

            viewModel           = new GPSTrackerViewModel(Entry);
            viewModel.GpsSignal = GpsNotReady;
            DataContext         = viewModel;

            if (emptyEntry)
            {
                pivot.Items.Remove(tpSummary);
                if (SelectedExercise != null)
                {//set a new exercise
                    viewModel.Entry.Exercise = SelectedExercise;
                    SelectedExercise         = null;
                }
                if (viewModel.Entry.Exercise != null)
                {
                    btnExercise.Content = viewModel.Entry.Exercise.Name;
                }
                pnlWorkoutData.Visibility = viewModel.Entry.Exercise != null ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                fillInfo();
            }
        }
Beispiel #8
0
        public void StartSupplementsCycle()
        {
            if (!UIHelper.EnsureInstructorLicence())
            {
                return;
            }
            var dlg = new StartSupplementsCycleWindow();

            dlg.AllowChangePlan = true;
            dlg.Customer        = SelectedItem;
            if (dlg.ShowDialog() == true)
            {
                BAMessageBox.ShowInfo("Info_usrSupplementsCyclesView_rbtnStartCycle_Click_StartedCycle".TranslateSupple());
            }
        }
Beispiel #9
0
        private async void btnCheckUserNameAvailability_Click(object sender, RoutedEventArgs e)
        {
            btnCheckUsername.IsEnabled = false;
            var result = await BAService.CheckProfileNameAvailabilityAsync(txtUserName.Text);

            if (result)
            {
                BAMessageBox.ShowInfo(ApplicationStrings.CreateProfilePage_InfoUsernameAvailable);
            }
            else
            {
                BAMessageBox.ShowWarning(ApplicationStrings.CreateProfilePage_InfoUsernameNotAvailable);
            }
            btnCheckUsername.IsEnabled = true;
        }
Beispiel #10
0
        private void goToOffline(bool automatic)
        {
            showProgress(true, true);
            progressBar.ShowProgress(true, ApplicationStrings.Login_ProgressOfflineModeStart);
            ThreadPool.QueueUserWorkItem(delegate
            {
                try
                {
                    ApplicationState.GoToOfflineMode();

                    Deployment.Current.Dispatcher.BeginInvoke(delegate
                    {
                        progressBar.ShowProgress(false);

                        onLoggingChanged();
                        if (!Settings.InfoOfflineMode)
                        {
                            Settings.InfoOfflineMode = true;
                            BAMessageBox.ShowInfo(ApplicationStrings.MessageOfflineModeDescription);
                        }
                    });
                }
                catch (InvalidOperationException ex)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => showProgress(false, true));
                    if (automatic)
                    {
                        BAMessageBox.ShowError(ApplicationStrings.ErrDuringLogin);
                    }
                    else
                    {
                        BAMessageBox.ShowWarning(ApplicationStrings.Login_ErrGoOffline_MustLoginFirst, true);
                    }
                }
                catch
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => showProgress(false, true));
                    if (automatic)
                    {
                        BAMessageBox.ShowError(ApplicationStrings.ErrDuringLogin);
                    }
                    else
                    {
                        BAMessageBox.ShowError(ApplicationStrings.Login_ErrGoOfflineMode);
                    }
                }
            });
        }
Beispiel #11
0
        private void previousNextEntry(TrainingDayDTO currentDay, GetOperation operationType, string limitMessage)
        {
            CancelEventArgs e = new CancelEventArgs();

            onTrainingDayChanging(e);
            if (e.Cancel)
            {
                return;
            }
            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();

            operation.Operation = operationType;
            operation.UserId    = User.GlobalId;
            if (Customer != null)
            {
                operation.CustomerId = Customer.GlobalId;
            }
            operation.WorkoutDateTime = currentDay.TrainingDate;
            ParentWindow.RunAsynchronousOperation(delegate(OperationContext context)
            {
                var day = ServiceManager.GetTrainingDay(operation);
                context.CancellatioToken.ThrowIfCancellationRequested();
                UIHelper.BeginInvoke(new Action(delegate
                {
                    if (day != null)
                    {
                        if (day.TrainingDate.IsFuture() && !UIHelper.EnsurePremiumLicence())
                        {
                            return;
                        }
                        DateTime oldDate           = CurrentDay.TrainingDate;
                        TrainingDayPageContext.Day = day;
                        Fill();
                        //populateFromContext();
                        //Fill(day, User, Customer, EntryObjectBuilder);
                        onTrainingDayChanged(new TrainingDayChangedEventArgs(oldDate, CurrentDay.TrainingDate));
                    }
                    else
                    {
                        BAMessageBox.ShowInfo(limitMessage);//ApplicationStrings.InfoNextEntryLimit);
                    }
                }), Dispatcher);
            }, delegate(OperationContext ctx)
            {
                CanNext = CanPrevious = ctx.State != OperationState.Started;
            });
        }
        public void GoToTheFirstEntry()
        {
            WorkoutDayGetOperation operation = new WorkoutDayGetOperation();

            operation.UserId    = User.GlobalId;
            operation.Operation = GetOperation.First;
            TrainingDayDTO day = ServiceManager.GetTrainingDay(operation);

            if (day != null)
            {
                entriesViewer.CalendarControl.DisplayDate = day.TrainingDate;
            }
            else
            {
                BAMessageBox.ShowInfo("InfoNoTrainingDayEntires".TranslateStrings());
            }
        }
        public void SaveAndCopy()
        {
            if (!UIHelper.EnsureInstructorLicence())
            {
                return;
            }
            SaveScheduleEntryRangeParam param = createSaveParam();
            var dlg = new SaveScheduleEntriesWindow(param);

            if (dlg.ShowDialog() == true)
            {
                //refresh reminders
                ReminderItemsReposidory.Instance.ClearCache();
                ChampionshipsReposidory.Instance.Reset();
                BAMessageBox.ShowInfo("ScheduleEntriesDesignViewModel_SaveAndCopy_Finished".TranslateInstructor(), dlg.Result.Count);
            }
        }
        private void lstRecords_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var list = (ListBox)sender;

            if (e.AddedItems.Count > 0)
            {
                var item = (ExerciseRecordViewModel)e.AddedItems[0];
                if (item.CalendarAvailable)
                {
                    retrieveTrainingDay(item.Item.TrainingDate, item.Item.User);
                }
                else
                {
                    BAMessageBox.ShowInfo(ApplicationStrings.FeaturedPage_InfoPrivateCalendar);
                }
            }
            list.SelectedIndex = -1;
        }
 private void fillCalendar(DateTime monthDate)
 {
     if (!ApplicationState.Current.CurrentBrowsingTrainingDays.IsMonthLoaded(monthDate))
     {
         if (ApplicationState.Current.IsOffline)
         {
             fillCalendarData(monthDate, ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays);
             BAMessageBox.ShowInfo(ApplicationStrings.CalendarPage_EntriesNotRetrieved);
         }
         else
         {
             getCurrentTrainingDays(monthDate);
         }
     }
     else
     {
         fillCalendarData(monthDate, ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays);
     }
 }
Beispiel #16
0
        private void tbsShareToFacebook_Click(object sender, RoutedEventArgs e)
        {
            //BUG FIX
            e.Handled = true;

            var selectedTab = (TabItemViewModel)xtraTabControl1.SelectedItem;

            if (selectedTab == null)
            {
                return;
            }
            var obj = selectedTab.EntryObject;

            if (obj.Status == EntryObjectStatus.Planned)
            {
                BAMessageBox.ShowInfo("TrainingDayWindow_ErrShareToFacebook_PlannedEntry".TranslateStrings());
                return;
            }

            //todo:add code where user hasnt' configured facebook account
            if (BAMessageBox.AskYesNo("Message_TrainingDayWindow_tbsShareToFacebook_Click".TranslateStrings()) == MessageBoxResult.Yes)
            {
                if (string.IsNullOrEmpty(Settings1.Default.FacebookToken))
                {
                    FacebookLoginWindow dlg = new FacebookLoginWindow();
                    if (dlg.ShowDialog() == false)
                    {
                        return;
                    }
                }

                SocialNetworkShare share = new SocialNetworkShare();
                if (share.PostEntryObject(obj))
                {
                    BAMessageBox.ShowInfo(Strings.TrainingDayWindow_MsgFacebokShareCompleted);
                }
                else
                {
                    BAMessageBox.ShowInfo(Strings.TrainingDayWindow_MsgFacebokShareNotImplemented);
                }
            }
        }
        private void usrProgressIndicatorButtons1_OkClick(object sender, CancellationSourceEventArgs e)
        {
            string username = null;

            SynchronizationContext.Send(delegate
            {
                username = txtUserNameEmail.Text;
            }, null);
            try
            {
                ServiceManager.AccountOperation(username, restorePassword ? AccountOperationType.RestorePassword : AccountOperationType.SendActivationEmail);
                string message = restorePassword
                                     ? Strings.ForgotPasswordWindow_PasswordChangedInfo
                                     : Strings.ForgotPasswordWindow_ActivatedEmailSent;
                BAMessageBox.ShowInfo(message);
                ThreadSafeClose(true);
            }
            catch (ProfileIsNotActivatedException ex)
            {
                TasksManager.SetException(ex);
                this.SynchronizationContext.Send(delegate
                {
                    ExceptionHandler.Default.Process(ex, Strings.ErrorProfileIsActivated, ErrorWindow.MessageBox);
                }, null);
            }
            catch (EMailSendException ex)
            {
                TasksManager.SetException(ex);
                this.SynchronizationContext.Send(delegate
                {
                    ExceptionHandler.Default.Process(ex, Strings.ErrProblemWithSendingEmail, ErrorWindow.MessageBox);
                }, null);
            }
            catch (ObjectNotFoundException ex)
            {
                TasksManager.SetException(ex);
                this.SynchronizationContext.Send(delegate
                {
                    ExceptionHandler.Default.Process(ex, Strings.ForgotPasswordWindow_ProfileNotFoundError, ErrorWindow.MessageBox);
                }, null);
            }
        }
Beispiel #18
0
 private void btnResetAll_Click(object sender, EventArgs e)
 {
     if (BAMessageBox.AskYesNo(Strings.QResetAllOptions) == MessageBoxResult.Yes)
     {
         //TODO: maybe clear cache should be under another button
         try
         {
             PicturesCache.Instance.Cache.Flush();
             TranslationsCache.Instance.Cache.Flush();
             UserContext.Current.Settings.Reset();
             fillSettings();
             File.Delete(Constants.AvalonLayoutFile);
             MainWindow.Instance.SaveSizeAndLocation = false;
             BAMessageBox.ShowInfo(Strings.OptionsWindow_MsgApplyResetLayoutSettings);
         }
         catch (Exception)
         {
             BAMessageBox.ShowError(Strings.OptionsWindow_ErrResetLayoutSettings);
         }
     }
 }
Beispiel #19
0
        private void btnUseInToday_Click(object sender, RoutedEventArgs e)
        {
            buttonPressed = true;
            var button = (RoundButton)sender;
            InGroup <TrainingPlanEntryViewModel> group = (InGroup <TrainingPlanEntryViewModel>)button.Tag;
            TrainingPlanDay planDay     = (TrainingPlanDay)group.Tag;
            var             workoutPlan = planDay.TrainingPlan;

            if (!workoutPlan.IsFavorite && !workoutPlan.IsMine)
            {
                BAMessageBox.ShowInfo(ApplicationStrings.WorkoutPlanViewControl_ErrMustAddPlanToFavorites);
                return;
            }

            if (BAMessageBox.Ask(ApplicationStrings.WorkoutPlanViewControl_btnUseInToday_QUsePlanInCalendar) == MessageBoxResult.Cancel)
            {
                return;
            }

            fillStrengthTrainingEntryWithPlan(planDay);
        }
Beispiel #20
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            bool restartRequired = false;

            foreach (ImageSourceListItem <IOptionsControl> tabPage in xtraTabControl1.Items)
            {
                IOptionsControl optionsControl = tabPage.Value;
                optionsControl.Save();
                if (optionsControl.RestartRequired)
                {
                    restartRequired = true;
                }
            }

            UserContext.Current.Settings.GuiState.Save();
            if (restartRequired)
            {
                BAMessageBox.ShowInfo(Strings.OptionsRestartRequiredMsg);
            }
            DialogResult = true;
            Close();
        }
Beispiel #21
0
        private void mnuPinToStart_Click(object sender, RoutedEventArgs e)
        {
            var       tag  = (HubTile)((MenuItem)sender).Tag;
            var       type = getEntryType(tag.Tag);
            ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("EntryType=" + type.Name));

            if (Tile != null)
            {
                BAMessageBox.ShowInfo(ApplicationStrings.TrainingDaySelectorControl_ErrSecondaryLiveTileExists);
                return;
            }
            StandardTileData tileData = new StandardTileData
            {
                Title               = tag.Title,
                BackgroundImage     = getImageUri(type),
                BackBackgroundImage = new Uri("/WP7TileImage.png", UriKind.RelativeOrAbsolute),
                BackTitle           = "BodyArchitect"
            };

            Uri tileUri = new Uri("/Pages/MainPage.xaml?EntryType=" + type.Name, UriKind.Relative);

            ShellTile.Create(tileUri, tileData);
        }
Beispiel #22
0
        protected void CopyEntryToToday()
        {
            //copy only if selected entry is not today entry
            if (ApplicationState.Current.CurrentBrowsingTrainingDays.IsMine && ApplicationState.Current.TrainingDay.TrainingDay.TrainingDate != DateTime.Now.Date)
            {
                //var origEntry = ApplicationState.Current.TrainingDay.TrainingDay.GetEntry(EntryType);
                var origEntry = Entry;
                var entry     = origEntry.Copy(true);

                if (!EnsureRemoveEntryTypeFromToday(EntryType))
                {//cancel overwrite
                    return;
                }
                PrepareCopiedEntry(origEntry, entry);


                ApplicationState.Current.TrainingDay.TrainingDay.Objects.Add(entry);
                entry.TrainingDay = ApplicationState.Current.TrainingDay.TrainingDay;
                ApplicationState.Current.CurrentEntryId = new LocalObjectKey(entry);
                show(true);
                BAMessageBox.ShowInfo(ApplicationStrings.EntryObjectPageBase_CopyEntryToTodayCompleted);
            }
        }
        public override void UpdateEntryObject(EntryObjectDTO entryDto)
        {
            A6WDay?day = a6wControl.GetSelectedA6wDay();

            if (day == null)
            {
                return;
            }
            A6WEntryDTO entry = (A6WEntryDTO)entryDto;

            entry.Day       = day.Value;
            entry.Completed = rbCompleted.IsChecked.Value;
            entry.Comment   = txtComment.Text;
            usrReportStatus1.Save(entry);
            if (entry.Status == EntryObjectStatus.Planned)
            {
                entry.Completed = false;
            }
            else
            {
                if (!entry.Completed)
                {
                    usrA6WPartialCompleted1.Save(entry);
                }
                else
                {
                    entry.Set1 = entry.Set2 = entry.Set3 = null;
                }
            }

            if (entry.Day.DayNumber == A6WManager.LastDay.DayNumber && entry.MyTraining.TrainingEnd == TrainingEnd.NotEnded)
            {
                entry.MyTraining.Complete();
                BAMessageBox.ShowInfo(EnumLocalizer.Default.GetUIString("BodyArchitect.Client.Module.A6W:A6WEntryStrings:TrainingCompletedText"));
            }
        }
Beispiel #24
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            CreateProfileWindow dlg = new CreateProfileWindow();

            if (dlg.ShowDialog() == true)
            {
                loggedSessionData = dlg.CreatedSessionData;
                if (loggedSessionData != null)
                {//we allow to login without activation
                    UserContext.CreateUserContext(loggedSessionData);
                    if (LoginSuccessful != null)
                    {
                        LoginSuccessful(this, EventArgs.Empty);
                    }
                    Close();
                }
                else
                {
                    //lblSendActivationEmail.Visible = true;//TODO:Finish?

                    BAMessageBox.ShowInfo(EnumLocalizer.Default.GetStringsString("ErrorMustActivateProfile"));
                }
            }
        }
Beispiel #25
0
        async protected Task saveToTheDb(bool goBack = false)
        {
            if (ApplicationState.Current == null)
            {
                return;
            }

            if (ReadOnly)
            {
                //Translation i huj wie co
                BAMessageBox.ShowError("Cannot modify entry for another user");
                return;
            }
            ExtensionMethods.BindFocusedTextBox();
            if (!ValidateBeforeSave())
            {
                return;
            }

            progressBar.ShowProgress(true, ApplicationStrings.EntryObjectPageBase_ProgressUpdating);
            BeforeSaving();
            DateTime date = ApplicationState.Current.TrainingDay.TrainingDay.TrainingDate;

            //first save a copy to the local storage
            ThreadPool.QueueUserWorkItem(delegate
            {
                var copy        = ApplicationState.Current.TrainingDay.Copy();
                copy.IsModified = true;
                ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[copy.TrainingDay.TrainingDate] = copy;
            });

            try
            {
                var entryBeforeSave = Entry;//see the comment where this is used belove
                var result          = await BAService.SaveTrainingDayAsync(ApplicationState.Current.TrainingDay.TrainingDay);

                if (result.TrainingDay != null)
                {
                    var savedDay = result.TrainingDay;
                    savedDay.FillInstaneId(ApplicationState.Current.TrainingDay.TrainingDay);
                    savedDay.TrainingDate = date;//bug fixing: web service converts date to local or something like this. but this is only in SaveTrainingDay method
                    var tdi = ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[savedDay.TrainingDate];
                    tdi.TrainingDay = savedDay;
                    tdi.IsModified  = false;
                    ApplicationState.Current.TrainingDay = tdi.Copy();

                    //if we use instance id for determining current entry then after save we should always use globalid
                    if (Entry != null)
                    {
                        ApplicationState.Current.CurrentEntryId = new LocalObjectKey(Entry);
                    }

                    await SavingCompleted();

                    progressBar.ShowProgress(false);
                    if (result.NewRecords.Count > 0)
                    {
                        BAMessageBox.ShowInfo(ApplicationStrings.MessageNewRecords, new Uri("/Images/Records32.png", UriKind.RelativeOrAbsolute));
                    }
                }
                else
                {
                    progressBar.ShowProgress(false);
                    //if (ApplicationState.Current.TrainingDay != null && ApplicationState.Current.TrainingDay.TrainingDay.TrainingDate == date)
                    //{
                    //    ApplicationState.Current.TrainingDay = null;
                    //}
                    if (!goBack)
                    {//user remove all data from the trainig day so on the server this day is removed. so on the client we "mark" this item as a new item
                        ApplicationState.Current.TrainingDay.TrainingDay.GlobalId = Guid.Empty;
                        var tmpEntry = Entry;
                        tmpEntry.GlobalId = Guid.Empty;
                        tmpEntry.Version  = 0;
                        ApplicationState.Current.CurrentEntryId = new LocalObjectKey(tmpEntry);
                    }
                    ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays.Remove(date);
                }
                if (ApplicationState.Current.TrainingDay != null && !IsClosing && !goBack)
                {
                    if (Entry == null && !ApplicationState.Current.TrainingDay.TrainingDay.Objects.Contains(entryBeforeSave))
                    {//this is invoked when for example user saved empty supplements entry so on the server this entry is removed and therefore after save Entry returns null. so we must restore the entry before saving operation (this is a special case)
                        ApplicationState.Current.TrainingDay.TrainingDay.Objects.Add(entryBeforeSave);
                        entryBeforeSave.TrainingDay = ApplicationState.Current.TrainingDay.TrainingDay;
                        entryBeforeSave.GlobalId    = Guid.Empty;
                        entryBeforeSave.Version     = 0;
                    }
                    show(true);
                }

                if (goBack)
                {
                    ApplicationState.Current.TrainingDay = null;
                    if (NavigationService.CanGoBack && !IsClosing)
                    {
                        NavigationService.GoBack();
                    }
                }
            }
            catch (NetworkException)
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowWarning(ApplicationStrings.EntryObjectPageBase_SavedLocallyOnly);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
            catch (ValidationException validEx)
            {
                progressBar.ShowProgress(false);
                if (IsClosing)
                {
                    return;
                }
                BAMessageBox.ShowError(validEx.Results.First().Key + ":" + validEx.Results.First().Message);
            }
            catch (OldDataException oldData)
            {
                progressBar.ShowProgress(false);
                if (IsClosing)
                {
                    return;
                }
                BAMessageBox.ShowError(ApplicationStrings.ErrOldData);
            }
            catch (LicenceException licence)
            {
                progressBar.ShowProgress(false);
                if (IsClosing)
                {
                    return;
                }
                BAMessageBox.ShowError(ApplicationStrings.ErrLicence);
            }
            catch (Exception ex)
            {
                progressBar.ShowProgress(false);
                BugSenseHandler.Instance.SendExceptionAsync(ex);
                if (IsClosing)
                {
                    return;
                }

                BAMessageBox.ShowWarning(ApplicationStrings.EntryObjectPageBase_SavedLocallyOnly);
            }



            //var m = new ServiceManager<SaveTrainingDayCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler<SaveTrainingDayCompletedEventArgs> operationCompleted)
            //{
            //    client1.SaveTrainingDayCompleted -= operationCompleted;
            //    client1.SaveTrainingDayCompleted += operationCompleted;
            //    client1.SaveTrainingDayAsync(ApplicationState.Current.SessionData.Token, ApplicationState.Current.TrainingDay.TrainingDay);

            //});


            //m.OperationCompleted += async (s, a) =>
            //{
            //    if (a.Error != null)
            //    {
            //        progressBar.ShowProgress(false);
            //        if(IsClosing)
            //        {
            //            return;
            //        }
            //        FaultException<ValidationFault> faultEx = a.Error as FaultException<ValidationFault>;
            //        FaultException<BAServiceException> serviceEx = a.Error as FaultException<BAServiceException>;
            //        if (faultEx != null)
            //        {
            //            BAMessageBox.ShowError(faultEx.Detail.Details[0].Key + ":" + faultEx.Detail.Details[0].Message);
            //            return;
            //        }
            //        if (serviceEx!=null)
            //        {
            //            if(serviceEx.Detail.ErrorCode==ErrorCode.OldDataException)
            //            {
            //                BAMessageBox.ShowError(ApplicationStrings.ErrOldData);
            //                return;
            //            }
            //            else if(serviceEx.Detail.ErrorCode==ErrorCode.LicenceException)
            //            {
            //                BAMessageBox.ShowError(ApplicationStrings.ErrLicence);
            //                return;
            //            }
            //        }

            //        BAMessageBox.ShowWarning(ApplicationStrings.EntryObjectPageBase_SavedLocallyOnly);
            //        return;
            //    }
            //    else
            //    {
            //        if (a.Result.Result.TrainingDay != null)
            //        {
            //            var savedDay = a.Result.Result.TrainingDay;
            //            //savedDay.InstanceId = dayInstanceId;
            //            //var savedEntry=savedDay.GetEntry(EntryType);
            //            //if (savedEntry != null)
            //            //{
            //            //    savedEntry.InstanceId = entryInstanceId;
            //            //}
            //            savedDay.FillInstaneId(ApplicationState.Current.TrainingDay.TrainingDay);
            //            savedDay.TrainingDate = date;//bug fixing: web service converts date to local or something like this. but this is only in SaveTrainingDay method
            //            var tdi=ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[savedDay.TrainingDate];
            //            tdi.TrainingDay = savedDay;
            //            tdi.IsModified = false;
            //            ApplicationState.Current.TrainingDay = tdi.Copy();
            //            await SavingCompleted();

            //            progressBar.ShowProgress(false);
            //            if(a.Result.Result.NewRecords.Count>0)
            //            {
            //                BAMessageBox.ShowInfo(ApplicationStrings.MessageNewRecords, new Uri("/Images/Records32.png", UriKind.RelativeOrAbsolute));
            //            }
            //        }
            //        else
            //        {
            //            progressBar.ShowProgress(false);
            //            if (ApplicationState.Current.TrainingDay != null && ApplicationState.Current.TrainingDay.TrainingDay.TrainingDate == date)
            //            {
            //                ApplicationState.Current.TrainingDay = null;
            //            }
            //            ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays.Remove(date);
            //        }
            //        if (ApplicationState.Current.TrainingDay != null && !IsClosing)
            //        {
            //            show(ApplicationState.Current.TrainingDay.TrainingDay, true);
            //        }

            //        if (goBack)
            //        {
            //            ApplicationState.Current.TrainingDay = null;
            //            if (NavigationService.CanGoBack && !IsClosing)
            //            {
            //                NavigationService.GoBack();
            //            }
            //        }
            //    }

            //};

            //if(!m.Run())
            //{
            //    progressBar.ShowProgress(false);
            //    if (ApplicationState.Current.IsOffline)
            //    {
            //        BAMessageBox.ShowWarning(ApplicationStrings.EntryObjectPageBase_SavedLocallyOnly);
            //    }
            //    else
            //    {
            //        BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
            //    }
            //}
        }
Beispiel #26
0
 private void rbtnNew_Click(object sender, RoutedEventArgs e)
 {
     BAMessageBox.ShowInfo(InstructorStrings.ChampionshipsView_CreateNew_Message);
 }