Ejemplo n.º 1
0
        /**********************************************************/

        /** profileButton_Click: Event handler for the profile button
        **/
        /** Preconditions: None
        **/
        /** Postconditions: Displays the profile form
        **/
        /** Parameters: object sender, EventArgs e
        **/
        /** Return: void
        **/
        /**********************************************************/
        private void profileButton_Click(object sender, EventArgs e)
        {
            // Displays the profile of the user
            myProfileForm myprofile = new myProfileForm();

            // calls the form’s constructor.
            // Must match the form name exactly
            myprofile.ShowDialog();
            //shows the form as a dialog
        }
Ejemplo n.º 2
0
        /**********************************************************/

        /** calculateButton_Click: Event handler for the Calculate button
        **/
        /** Preconditions: None
        **/
        /** Postconditions: Opens the profile page, then calculates
         * the user's BMR based on their information on the profile form
         **/
        /** Parameters: object sender, EventArgs e
        **/
        /** Return: void
        **/
        /**********************************************************/
        private void calculateButton_Click(object sender, EventArgs e)
        {
            myProfileForm profile = new myProfileForm();

            profile.ShowDialog();

            // Constants for BMR calculation
            const double MALE_WEIGHT_MULT = 6.23;
            const double MALE_HEIGHT_MULT = 12.7;
            const double MALE_AGE_MULT    = 6.8;
            const double MALE_BASE_VALUE  = 66;

            const double FEMALE_WEIGHT_MULT = 4.35;
            const double FEMALE_HEIGHT_MULT = 4.7;
            const double FEMALE_AGE_MULT    = 4.7;
            const double FEMALE_BASE_VALUE  = 655;

            const double LITTLE_ACTIVITY_LEVEL_MULT   = 1.2;
            const double LIGHT_ACTIVITY_LEVEL_MULT    = 1.375;
            const double MODERATE_ACTIVITY_LEVEL_MULT = 1.55;
            const double HEAVY_ACTIVITY_LEVEL_MULT    = 1.725;
            const double EXTREME_ACTIVITY_LEVEL_MULT  = 1.9;

            // Grab the data from the profiles properties
            int weight = profile.Weight;
            int height = profile.Height;
            int age    = profile.Age;

            double calculated_bmr      = 0;
            double activity_multiplier = 0;

            // Calculate the MBR for MALE/FEMALE
            if (maleRadio.Checked)
            {
                calculated_bmr = (MALE_BASE_VALUE + (MALE_WEIGHT_MULT * weight) + (MALE_HEIGHT_MULT * height) - (MALE_AGE_MULT * age));
            }
            else
            {
                calculated_bmr = (FEMALE_BASE_VALUE + (FEMALE_WEIGHT_MULT * weight) + (FEMALE_HEIGHT_MULT * height) - (FEMALE_AGE_MULT * age));
            }

            switch (exerciseLevelListbox.SelectedIndex)
            {
            // Sets the exercise level multiplier based on the listbox selection
            case 0:
                activity_multiplier = LITTLE_ACTIVITY_LEVEL_MULT;
                break;

            case 1:
                activity_multiplier = LIGHT_ACTIVITY_LEVEL_MULT;
                break;

            case 2:
                activity_multiplier = MODERATE_ACTIVITY_LEVEL_MULT;
                break;

            case 3:
                activity_multiplier = HEAVY_ACTIVITY_LEVEL_MULT;
                break;

            case 4:
                activity_multiplier = EXTREME_ACTIVITY_LEVEL_MULT;
                break;

            default:
                // If something goes wrong, it will result in a zero, so the user
                // isn't getting bad information
                activity_multiplier = 0;
                break;
            }

            // Multiply the bmr by the activity multiplier
            calculated_bmr = (calculated_bmr * activity_multiplier);

            if (calculated_bmr > 0)
            {
                // Put the newly calculated BMR data in the labels
                bmrOutput.Text = calculated_bmr.ToString("0.00");
            }
            else
            {
                // Something went wrong with the listbox
                MessageBox.Show("There was an error with the activity level -- please select one of the 5 options; contact an administrator if this error persists.");
            }
        }