Пример #1
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            bool isOk = true;

            if (DataValidation.IsValidEmail(tbEmail))
            {
                txtEmailMsg.Text = "";
            }
            else
            {
                txtEmailMsg.Text = "Invalid email.";
                isOk = false;
            }

            if (isOk)
            {
                DailyCalsServiceV2Client dcsc = new DailyCalsServiceV2Client();
                dcsc.GetProfileCompleted += new EventHandler<GetProfileCompletedEventArgs>(dcsc_GetProfileCompleted);
                // Set progress bar, and clear some stuff.
                performanceProgressBar.Visibility = Visibility.Visible;
                btnSubmit.IsEnabled = false;
                tbEmail.IsEnabled = false;
                pwPassword.IsEnabled = false;
                // Run...
                dcsc.GetProfileAsync(tbEmail.Text);
            }
        }
Пример #2
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            bool isOk = true;

            if (DataValidation.IsValidEmail(tbEmail))
            {
                txtEmailMsg.Text = "";
            }
            else
            {
                txtEmailMsg.Text = "Invalid email.";
                isOk = false;
            }

            if (isOk)
            {
                // See if email is already in use by another profile.
                DailyCalsServiceV2Client dcsc = new DailyCalsServiceV2Client();
                dcsc.DoesProfileExistCompleted += new EventHandler<DoesProfileExistCompletedEventArgs>(dcsc_DoesProfileExistCompleted);
                // Set progress bar, and clear some stuff.
                performanceProgressBar.Visibility = Visibility.Visible;
                btnSubmit.IsEnabled = false;
                tbEmail.IsEnabled = false;
                pwPassword.IsEnabled = false;
                pwPasswordAgain.IsEnabled = false;
                tbEmail.Background = new SolidColorBrush(Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF));
                txtEmailMsg.Text = "";
                // Run...
                dcsc.DoesProfileExistAsync(tbEmail.Text);
            }
        }
Пример #3
0
        private void btnUpdateProfile_Click(object sender, RoutedEventArgs e)
        {
            // Get the application's profile data object.
            // TODO: need to consolidate the profile obj in PopulteForm
            //_profile = (Application.Current as DailyCals.App).ProfileDataObject;

            // Is this profile new?
            bool isNewProfile = false;

            // OK to update profile?
            bool isOkToUpdate = true;

            // Dirty bit.
            bool dirty_bit = false;

            // Date used for total days calculation.
            DateTime startDate = DailyCalories.GetToday();

            if (_profile == null)
            {
                // user has not created his or her profile yet.
                // create new record, and set flag.
                _profile = new RemoteProfileRecordV2();
                isNewProfile = true;
            }
            else
            {
                // Since there exists a profile record, use the setup
                // date as the dateForCalculations.
                startDate = _profile.startdate;
            }

            // Birthdate validation.
            if (DataValidation.IsValidBirthdate(dpBirthdate))
            {
                DateTime birthdate = (DateTime)dpBirthdate.Value;
                if (_profile.birthdate != birthdate)
                {
                    _profile.birthdate = birthdate;
                    dirty_bit = true;
                }
                txtBirthdateMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtBirthdateMsg.Text = "Chk birthdate.";
            }

            // Validate height.
            if (DataValidation.IsValidHeight(tbHeight))
            {
                double height = Convert.ToDouble(tbHeight.Text);
                if (_profile.height != height)
                {
                    _profile.height = height;
                    dirty_bit = true;
                }
                txtHeightMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtHeightMsg.Text = "Chk height.";
            }

            // Is user female?
            if ((bool)rbFemale.IsChecked)
            {
                if (_profile.isfemale == 0)
                {
                    _profile.isfemale = 1;
                    dirty_bit = true;
                }
            }
            else
            {
                if (_profile.isfemale == 1)
                {
                    _profile.isfemale = 0;
                    dirty_bit = true;
                }
            }

            // Validate start weight.
            if (DataValidation.IsValidWeight(tbStartWeight))
            {
                double startweight = Convert.ToDouble(tbStartWeight.Text);
                if (_profile.startweight != startweight)
                {
                    _profile.startweight = startweight;
                    dirty_bit = true;
                }
                txtStartWeightMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtStartWeightMsg.Text = "Weight must be greater than 0.";
            }

            // Validate goal weight.
            if (DataValidation.IsValidWeight(tbGoalWeight))
            {
                double goalweight = Convert.ToDouble(tbGoalWeight.Text);
                if (_profile.goalweight != goalweight)
                {
                    _profile.goalweight = goalweight;
                    dirty_bit = true;
                }
                txtGoalWeightMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtGoalWeightMsg.Text = "Weight must be greater than 0.";
            }

            // Validate start weight > goal weight. This happens only
            // after both weights have already been validated first.
            if (isOkToUpdate)
            {
                if (DataValidation.IsStartWeightGreaterThanGoalWeight(tbStartWeight, tbGoalWeight))
                {
                    txtGoalWeightMsg.Text = "";
                }
                else
                {
                    isOkToUpdate = false;
                    txtStartWeightMsg.Text = "Start weight must be larger than goal.";
                }
            }

            // Standard units?
            if ((bool)rbStandard.IsChecked)
            {
                if (_profile.isstandard == 0)
                {
                    _profile.isstandard = 1;
                    dirty_bit = true;
                }
            }
            else
            {
                if (_profile.isstandard == 1)
                {
                    _profile.isstandard = 0;
                    dirty_bit = true;
                }
            }

            // Validate goal date.
            if (DataValidation.IsValidGoalDate(dpGoalDate))
            {
                DateTime goaldate = (DateTime)dpGoalDate.Value;
                if (_profile.goaldate != goaldate)
                {
                    _profile.goaldate = goaldate;
                    dirty_bit = true;
                }
                txtGoalDateMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtGoalDateMsg.Text = "Goal date must be later than today.";
            }

            // Activity level.
            if (_profile.activitylevel != slActivityLevel.Value)
            {
                _profile.activitylevel = slActivityLevel.Value;
                dirty_bit = true;
            }

            // If everything is OK to update, then update the profile.
            // Otherwise, return the user to the My Profile page.
            if (isOkToUpdate && dirty_bit)
            {
                // If this is a new profile, set the setup date.
                if (isNewProfile)
                {
                    _profile.startdate = DailyCalories.GetToday();
                    _profile.email = CreateProfile.Email;
                    _profile.profilep = CreateProfile.Profilep;
                }

                // Save profile data to db.
                DailyCalsServiceV2Client dcsc = new DailyCalsServiceV2Client();
                // Set progress bar, and clear some stuff.
                performanceProgressBar.Visibility = Visibility.Visible;
                if (isNewProfile)
                {
                    dcsc.InsertProfileCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(dcsc_InsertProfileCompleted);
                    dcsc.InsertProfileAsync(_profile);
                }
                else
                {
                    dcsc.UpdateProfileCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(dcsc_UpdateProfileCompleted);
                    dcsc.UpdateProfileAsync(_profile);
                }
            }
            else if (isOkToUpdate && !dirty_bit)
            {
                // dirty it not set, just go back to main page
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }