Beispiel #1
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            BodyMassIndex bmi = new BodyMassIndex((double)numWeight.Value, (double)numHeight.Value);

            bmi.CalculateBMI();
            lblBMI.Text = bmi.getBMI().ToString();
        }
Beispiel #2
0
        private void btn_calculate_Click(object sender, EventArgs e)
        {
            string[] s = new string[] { txtHeight.Text, txtWeight.Text };

            if (!FormUtils.ValidChamps(s))
            {
                if (FormUtils.EmptyText(txtHeight.Text))
                {
                    errorProvider1.SetError(txtHeight, FormUtils.loadConfigs("EMPTY_HEIGHT"));
                }

                else if (FormUtils.EmptyText(txtWeight.Text))
                {
                    errorProvider1.SetError(txtWeight, FormUtils.loadConfigs("EMPTY_WEIGHT"));
                }

                else
                {
                    try
                    {
                        btn_save.Enabled = true;
                        mapping();
                        this.labResult.Text = "" + bmi.getBMI(bmi.getHeight(), bmi.getWeight());

                        switch (bmi.evaluate())
                        {
                        case "Underweight":
                            changeLabelColor(labResult, Color.Red);
                            break;

                        case "Normal":
                            changeLabelColor(labResult, Color.Green);
                            break;

                        case "Overweight":
                            changeLabelColor(labResult, Color.Red);
                            break;

                        case "Obese":
                            changeLabelColor(labResult, Color.Red);
                            break;

                        case "Severly Obese":
                            changeLabelColor(labResult, Color.Red);
                            break;

                        default:
                            changeLabelColor(labResult, Color.Red);
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        FormUtils.showErrorMessage("Error", ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }

            else
            {
                errorProvider1.SetError(txtHeight, "Please fill your height.");
                errorProvider1.SetError(txtWeight, "Please fill your weight.");
            }
        }