// IMC calculation. /// <summary> /// Calculate an IMC for metric height and weight value /// </summary> /// <param name="height">the user height in cm</param> /// <param name="weight"> the user weight in kg</param> /// <returns></returns> private double calculateMetricIMC(double height, double weight) { IMCCalculatorManager manager = new IMCCalculatorManager(); double imc = manager.calculateMetricIMC(height, weight); displayIMCinfo(imc); String s_imc = Math.Round(imc, 2).ToString("R"); // On prend toutes les valeurs de décimal. Si on ne les veut pas, il suffit de mettre F0 à la place de R. int nbDecimal = s_imc.Length - s_imc.IndexOf(","); s_imc = "Votre IMC est de " + s_imc + "\n" + manager.infoFromIMC(imc); if (imc < 18.5) { displayGainWeightTextBlockFromIMC(imc, height, weight); s_imc = s_imc + "\n" + manager.weightToGainFromIMC(imc, height, weight); } else if (imc > 25) { displayLoseWeightTextBlockFromIMC(imc, height, weight); s_imc = s_imc + "\n" + manager.weightToLoseFromIMC(imc, height, weight); } metricIMCResultTextBlock.Text = s_imc; return imc; }
private void clickCalculateMetricIMC(object sender, System.Windows.RoutedEventArgs e) { try { string s_height = metricHeightTextBox.Text; if (s_height.Contains(".")) s_height = s_height.Substring(0, s_height.IndexOf(".")); string s_weight = metricWeightTextBox.Text; if (s_weight.Contains(".")) s_weight = s_weight.Substring(0, s_weight.IndexOf(".")); Double height = Double.Parse(s_height); Double weight = Double.Parse(s_weight); Double imc = Math.Floor(calculateMetricIMC(height, weight)); defineFeedbackHeightandWeightTextBlocks(metricHeightTextBox.Text + " cm", metricWeightTextBox.Text + " kg"); // Manage the Tile according to the imc result. TileManager tileManager = new TileManager(); IMCCalculatorManager imcManager = new IMCCalculatorManager(); tileManager.changeBackTile(imc, height, weight, imcManager.infoFromIMC(imc)); } catch { metricIMCResultTextBlock.Text = "Un problème est survenu lors du calcul de votre IMC.\nVeuillez entrer à nouveau votre taille et votre poids."; } }