Exemplo n.º 1
0
        //the method below will highlight the BMI result in data grid
        private void focusResultInDataGrid(List <BMIData> bmiDataList, BMIData resultBmiData)
        {
            int resultIndex = bmiDataList.IndexOf(resultBmiData);

            bmiChartGridView.CurrentCell = this.bmiChartGridView[0, resultIndex];
            bmiChartGridView.Rows[resultIndex].DefaultCellStyle.BackColor = Color.Aquamarine;
        }
Exemplo n.º 2
0
        //Calculate button event
        private void CalculateButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Weight in kg
                double weight = GetWeight();

                // Height in cm
                double height = GetHeight();

                double bmi = BMIUtility.calculateBmi(weight, height);
                bmiTextBox.Text = Convert.ToString(Math.Round(bmi, 2));

                Gender gender = GetGender();

                double idealWeight = BMIUtility.calculateIdealBodyWeight(gender, height);
                recommendationTextBox.Text = $"Your ideal weight is {idealWeight}";

                List <BMIData> bmiDataList   = BMIData.getBMIDataList();
                BMIData        resultBmiData = GetBmiData(bmi, bmiDataList);

                resultsTextBox.Text = resultBmiData.Category;
                unfocusResultInDataGrid();
                focusResultInDataGrid(bmiDataList, resultBmiData);
            } catch (Exception ex)
            {
                MessageBox.Show("Exception occurred: " + ex.Message);
            }
        }
Exemplo n.º 3
0
        //this method will find the appropriate BMI category based on BMI value
        private static BMIData GetBmiData(double bmi, List <BMIData> dataList)
        {
            IEnumerable <BMIData> bMiDataQuery =
                from bmiData in dataList
                where bmiData.BMI_Lower_Bound <= bmi && bmi < bmiData.BMI_Upper_Bound
                select bmiData;

            BMIData resultBmiData = bMiDataQuery.Any() ?
                                    bMiDataQuery.First() : dataList[dataList.Count() - 1];

            return(resultBmiData);
        }
Exemplo n.º 4
0
        // Given below is a method which will initialize the BMI list data
        public static List <BMIData> getBMIDataList()
        {
            List <BMIData> bMIDataList = new List <BMIData>(5);
            BMIData        data1       = new BMIData("Severe Thinness", 0, 16);
            BMIData        data2       = new BMIData("Moderate Thinness", 16, 17);
            BMIData        data3       = new BMIData("Mild Thinness", 17, 18.5);
            BMIData        data4       = new BMIData("Normal", 18.5, 25);
            BMIData        data5       = new BMIData("Overweight", 25, 30);
            BMIData        data6       = new BMIData("Obese Class I", 30, 35);
            BMIData        data7       = new BMIData("Obese Class II", 35, 40);
            BMIData        data8       = new BMIData("Obese Class III", 40, 99);

            bMIDataList.Add(data1);
            bMIDataList.Add(data2);
            bMIDataList.Add(data3);
            bMIDataList.Add(data4);
            bMIDataList.Add(data5);
            bMIDataList.Add(data6);
            bMIDataList.Add(data7);
            bMIDataList.Add(data8);
            return(bMIDataList);
        }
Exemplo n.º 5
0
        // This method is used to compare and return a bool
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            BMIData other = (BMIData)obj;

            if (!Category.Equals(other.Category))
            {
                return(false);
            }

            if (!BMI_Lower_Bound.Equals(other.BMI_Lower_Bound))
            {
                return(false);
            }

            if (!BMI_Upper_Bound.Equals(other.BMI_Upper_Bound))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
 public BMIForm()
 {
     InitializeComponent();
     bmiChartGridView.DataSource = BMIData.getBMIDataList();
 }