Ejemplo n.º 1
0
 protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
 {
     ExtensionMethods.BindFocusedTextBox();
     base.OnNavigatedFrom(e);
     State["ViewModel"] = viewModel;
     State["Country"]   = Country;
     //this.SaveState();
 }
Ejemplo n.º 2
0
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            ExtensionMethods.BindFocusedTextBox();
            base.OnNavigatedFrom(e);
            ApplicationState.Current.TrainingDaysRetrieved -= Current_TrainingDaysRetrieved;

            if (pivot != null)
            {
                this.State["PivotSelectedTab"] = pivot.SelectedIndex;
            }
        }
Ejemplo n.º 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ExtensionMethods.BindFocusedTextBox();
            if ((!string.IsNullOrEmpty(viewModel.Password1) || !string.IsNullOrEmpty(viewModel.Password2)) && viewModel.Password1 != viewModel.Password2)
            {
                BAMessageBox.ShowError(ApplicationStrings.ProfilePage_ErrDifferentPassword);
                return;
            }
            progressBar.ShowProgress(true, ApplicationStrings.ProfilePage_ProgressSave);


            if (picture != null)
            {
                uploadPictureAndSaveProfile();
            }
            else
            {
                saveProfile(null, null);
            }
        }
Ejemplo n.º 4
0
        private void createProfile()
        {
            if (viewModel.Country == null)
            {
                BAMessageBox.ShowError(ApplicationStrings.CreateProfilePage_ErrSelectCountry);
                return;
            }
            creating = true;
            updateGui();
            progressBar.ShowProgress(true, ApplicationStrings.CreateProfilePage_ProgressCreateAccount);
            ExtensionMethods.BindFocusedTextBox();
            IsHitTestVisible = false;



            var m = new ServiceManager <CreateProfileCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <CreateProfileCompletedEventArgs> operationCompleted)
            {
                var profile                 = new ProfileDTO();
                profile.Birthday            = viewModel.Birthday;
                profile.Gender              = viewModel.IsMale ? Gender.Male : Gender.Female;
                profile.CountryId           = viewModel.Country.GeoId;
                profile.UserName            = viewModel.Username;
                profile.Email               = viewModel.Email;
                profile.Settings            = new ProfileSettingsDTO();
                profile.Settings.LengthType = (Service.V2.Model.LengthType)lpLengthType.SelectedIndex;
                profile.Settings.WeightType = (Service.V2.Model.WeightType)lpWeightType.SelectedIndex;
                profile.Privacy             = new ProfilePrivacyDTO();
                profile.Password            = viewModel.Password.ToSHA1Hash();

                client1.CreateProfileAsync(Settings.GetClientInformation(), profile);
                client1.CreateProfileCompleted -= operationCompleted;
                client1.CreateProfileCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, y) =>
            {
                try
                {
                    if (cancel)
                    {
                        progressBar.ShowProgress(false);
                        IsHitTestVisible = true;
                        creating         = false;
                        updateGui();
                        return;
                    }
                    if (y.Error != null)
                    {
                        progressBar.ShowProgress(false);
                        IsHitTestVisible = true;
                        creating         = false;
                        updateGui();
                        FaultException <ValidationFault>    faultEx = y.Error as FaultException <ValidationFault>;
                        FaultException <BAServiceException> baEx    = y.Error as FaultException <BAServiceException>;

                        if (faultEx != null)
                        {
                            BAMessageBox.ShowError(faultEx.Detail.Details[0].Key + ":" + faultEx.Detail.Details[0].Message);
                            return;
                        }
                        if (baEx != null && baEx.Detail.ErrorCode == ErrorCode.UniqueException)
                        {
                            BAMessageBox.ShowWarning(ApplicationStrings.ErrUsernameOrEmailNotUnique);
                            return;
                        }
                        BugSenseHandler.Instance.SendExceptionAsync(y.Error);
                        BAMessageBox.ShowError(ApplicationStrings.CreateProfilePage_ErrCreateAccount);
                        return;
                    }
                    else
                    {
                        if (Settings.LiveTileEnabled && Settings.InitialAsk)
                        {
                            try
                            {
                                pushNotification.RegisterDevice(y.Result.Result.Profile.GlobalId);
                            }
                            catch
                            {
                            }
                        }
                        ApplicationState.Current             = new ApplicationState();
                        ApplicationState.Current.SessionData = y.Result.Result;
                        //ApplicationState.Current.MyDays = new TrainingDaysHolder(ApplicationState.Current.SessionData.Profile);
                        ApplicationState.Current.MyDays = new Dictionary <CacheKey, TrainingDaysHolder>();

                        ApplicationState.Current.TempUserName = viewModel.Username;
                        ApplicationState.Current.TempPassword = viewModel.Password.ToSHA1Hash();

                        Settings.UserName = viewModel.Username;
                        Settings.Password = viewModel.Password;
                        ApplicationState.Current.SessionData.Token.Language = ApplicationState.CurrentServiceLanguage;

                        ApplicationState.Current.Cache.Messages.Load();

                        getProfileInformation();
                    }
                }
                catch (Exception)
                {
                    progressBar.ShowProgress(false);
                    IsHitTestVisible = true;
                    creating         = false;
                    updateGui();
                    BAMessageBox.ShowError(ApplicationStrings.CreateProfilePage_ErrCreateAccount);
                }
            };

            if (!m.Run(true))
            {
                IsHitTestVisible = true;
                creating         = false;
                updateGui();
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Ejemplo n.º 5
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);
            //    }
            //}
        }