Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    age;
            double BMR, DCR;
            string activ;

            if (!int.TryParse(textBox1.Text, out age))
            {
                errorProvider1.SetError(this.textBox1, "Enter Number");
            }

            else if (comboBox1.Text == "" || comboBox1.Text != "1.Sedentary" && comboBox1.Text != "2.Light Exercise(1-3 days / week)" && comboBox1.Text != "3.Moderate Exercise(3-5 days / week)" && comboBox1.Text != "4.Intense Exercise(6-7 days / week)" && comboBox1.Text != "5.Very Intense Exercise (2 extreme workouts per day)")
            {
                errorProvider1.SetError(this.comboBox1, "Chose menu");
            }


            else
            {
                age = Convert.ToInt32(textBox1.Text);
                BMR = BasalMetabolicRate(weight, height, age, gender);

                activ = comboBox1.SelectedItem.ToString();
                DCR   = ActivityLevel(BMR, activ);

                ListViewItem item = new ListViewItem(BMR.ToString());
                item.SubItems.Add(DCR.ToString());
                listView1.Items.Add(item);
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text != "") && (textBox2.Text != "") && (textBox3.Text != ""))
            {
                double wzrost = Convert.ToDouble(textBox1.Text);
                Debug.WriteLine(wzrost);
                double waga = Convert.ToDouble(textBox2.Text);
                Debug.WriteLine(waga);
                double wiek = Convert.ToDouble(textBox3.Text);
                Debug.WriteLine(wiek);

                double BMR;

                if (radioButton1.Checked)
                {
                    BMR             = (9.99 * waga) + (6.25 * wzrost) - (4.92 * wiek + 5);
                    wynik.Text      = BMR.ToString();
                    wynik.ForeColor = Color.Black;
                }
                else
                {
                    BMR             = (9.99 * waga) + (6.25 * wzrost) - (4.92 * wiek - 161);
                    wynik.Text      = BMR.ToString();
                    wynik.ForeColor = Color.Black;
                }
            }
            else
            {
                wynik.ForeColor = Color.Red;
                wynik.Text      = "Brak Danych!";
            }
        }
Esempio n. 3
0
        /// <summary>
        /// click event for Calculate BMR button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBMRCalc_Click(object sender, EventArgs e)
        {
            //call form's constructor and assign variable
            MyProfileForm profile = new MyProfileForm();

            //display MyProfile form
            profile.ShowDialog();

            //declare variables for BMR and activity level
            double BMR;
            int    activityLevel = lstBoxActivityLevel.SelectedIndex;

            //validate which radio button is checked
            if (rBtnMale.Checked)
            {
                //calculate Male BMR, based on input from profile form
                BMR = MALE_ADDITION + (MALE_WEIGHT_MULTIPLIER * profile.WEIGHT) + (MALE_HEIGHT_MULTIPLIER * profile.HEIGHT) - (MALE_AGE_MULTIPLIER * profile.AGE);
            }
            else
            {
                //calculate Female BMR, based on input from profile form
                BMR = FEMALE_ADDITION + (FEMALE_WEIGHT_MULTIPLIER * profile.WEIGHT) + (FEMALE_HEIGHT_MULTIPLIER * profile.HEIGHT) - (FEMALE_AGE_MULTIPLIER * profile.AGE);
            }

            //switch statement for activity level
            switch (activityLevel)
            {
            case 0:
                BMR *= LITTLE_EXCERCISE;
                break;

            case 1:
                BMR *= LIGHT_EXCERCISE;
                break;

            case 2:
                BMR *= MODERATE_EXCERCISE;
                break;

            case 3:
                BMR *= HEAVY_EXCERCISE;
                break;

            case 4:
                BMR *= VHEAVY_EXCERCISE;
                break;

            default:
                MessageBox.Show("Don't forget to select an activity level!", "Activity Level Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //don't close form
                this.DialogResult = DialogResult.None;
                break;
            }

            //display results of the calculation in respective lables
            txtBoxBMR.Text = BMR.ToString("n2");
        }
        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Name          = Name_textbox.Text;
                Surname       = Surname_textbox.Text;
                Sex           = SexCheck;
                Age           = Convert.ToUInt32(Age_textbox.Text);
                Height        = Convert.ToDouble(Height_textbox.Text.Replace('.', ','));
                Weight        = Convert.ToDouble(Weight_textbox.Text.Replace('.', ','));
                ActivityLevel = Convert.ToUInt32(ActivityLevel_combobox.SelectedIndex);
                Goal          = Convert.ToUInt32(Goal_combobox.SelectedIndex);
                DietType      = Convert.ToUInt32(DietCheck());
                MealCount     = Convert.ToUInt32(MealsCount_combobox.SelectedItem);
                BMI           = MathOperations.getBMI(Height, Weight);
                BMR           = MathOperations.getBMR(Height, Weight, Convert.ToInt32(Age), Sex);
                TMR           = MathOperations.getTMR(Convert.ToInt32(ActivityLevel), BMR);
                DailyCalories = MathOperations.getDailyCalories(Convert.ToInt32(Goal), TMR);

                BMI_textblock.Text           = BMI.ToString("0.##");
                BMR_textblock.Text           = BMR.ToString();
                TMR_textblock.Text           = TMR.ToString();
                DailyCalories_textblock.Text = DailyCalories.ToString();

                Meals meals = new Meals(Convert.ToInt32(MealCount), DailyCalories,
                                        Convert.ToInt32(DietType), Convert.ToInt32(Goal), Weight);

                uint sex;
                if (Sex)
                {
                    sex = 1;
                }
                else
                {
                    sex = 0;
                }

                Users user = new Users(Login.UserLogin, Name, Surname, Age, Height, Weight, Goal,
                                       sex, ActivityLevel, DailyCalories, DietType, MealCount);

                UsersRepos.Update(user);
            }
            catch
            {
                MessageBox.Show(Properties.Resources.errorEmptyDatas, Properties.Resources.warning);
            }
            show();
        }
        private void SetData()
        {
            var UserList = UsersRepos.GetAll();

            Users User = null;

            foreach (var user in UserList)
            {
                if (Login.UserLogin == user.Login)
                {
                    User = new Users(user);
                    break;
                }
            }

            if (User != null)
            {
                Name_textbox.Text                    = User.Name;
                Surname_textbox.Text                 = User.Surname;
                Age_textbox.Text                     = User.Age.ToString();
                Height_textbox.Text                  = User.Height.ToString();
                Weight_textbox.Text                  = User.Weight.ToString();
                DailyCalories_textblock.Text         = User.Kcal.ToString();
                MealsCount_combobox.SelectedItem     = Convert.ToInt32(User.MealsCount);
                ActivityLevel_combobox.SelectedIndex = Convert.ToInt32(User.ActivityLevel);
                Goal_combobox.SelectedIndex          = Convert.ToInt32(User.Goal);

                if (User.Sex == 0)
                {
                    woman_radiobutton.IsChecked = true;
                    Sex = false;
                }
                if (User.Sex == 1)
                {
                    man_radiobutton.IsChecked = true;
                    Sex = true;
                }

                if (User.DietType == 0)
                {
                    normal_radiobutton.IsChecked = true;
                }
                if (User.DietType == 1)
                {
                    vegetarian_radiobutton.IsChecked = true;
                }
                if (User.DietType == 2)
                {
                    vegan_radiobutton.IsChecked = true;
                }

                Height        = Convert.ToDouble(User.Height);
                Weight        = Convert.ToDouble(User.Weight);
                Age           = Convert.ToUInt32(User.Age);
                ActivityLevel = Convert.ToUInt32(User.ActivityLevel);
                DietType      = Convert.ToUInt32(DietCheck());

                BMI = MathOperations.getBMI(Height, Weight);
                BMR = MathOperations.getBMR(Height, Weight, Convert.ToInt32(Age), Sex);
                TMR = MathOperations.getTMR(Convert.ToInt32(ActivityLevel), BMR);

                BMI_textblock.Text = BMI.ToString("0.##");
                BMR_textblock.Text = BMR.ToString();
                TMR_textblock.Text = TMR.ToString();

                Login.CurrentUser = User;
            }
        }
Esempio n. 6
0
 override public string ToString()
 {
     return(bmr.ToString() + ":" + prop + mask.ToString("X8"));
 }