コード例 #1
0
        // 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;
        }
コード例 #2
0
        /// <summary>
        /// Manage the Tile. Change its count, backTitle and backContent.
        /// </summary>
        /// <param name="count">The tile count</param>
        /// <param name="backTitle">The tile backTitle</param>
        /// <param name="backContent">The tile backContent</param>
        public void changeBackTile(double imc, double currentHeight, double currentWeight, string backContent)
        {
            IMCCalculatorManager imcManager = new IMCCalculatorManager();
            string backTitle = "";
            string backBackgroundImageName = "";
            if (imc < 18.5)
            {
                backTitle = imcManager.weightToGainFromIMC(imc, currentHeight, currentWeight);
                backBackgroundImageName = "thumbs-down.png";
            }
            if (imc > 25)
            {
                backTitle = imcManager.weightToLoseFromIMC(imc, currentHeight, currentWeight);
                backBackgroundImageName = "thumbs-down.png";
            }
            if (18.5 <= imc && imc <= 25)
            {
                backTitle = "Ne changez rien.";
                backBackgroundImageName = "thumbs-up.png";
            }

            // Application Tile is always the first Tile, even if it is not pinned to Start.
            ShellTile TileToFind = ShellTile.ActiveTiles.First();

            // Application should always be found
            if (TileToFind != null)
            {
                createImageForBackTile();

                // Set the properties to update for the Application Tile.
                // Empty strings for the text values and URIs will result in the property being cleared.
                StandardTileData NewTileData = new StandardTileData
                {
                    // Title = "Mon title",
                    // BackgroundImage = new Uri(textBoxBackgroundImage.Text, UriKind.Relative),
                    Count = Convert.ToInt32(imc),
                    BackTitle = backTitle,
                    BackBackgroundImage = new Uri("isostore:/Shared/ShellContent/tile.jpg", UriKind.Absolute),
                    BackContent = backContent
                };

                // Update the Application Tile
                TileToFind.Update(NewTileData);
            }
        }
コード例 #3
0
        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.";
            }
        }
コード例 #4
0
 /// <summary>
 /// Display info on how many kilo to lose in order to be in normal zone.
 /// </summary>
 /// <param name="currentImc">The current imc</param>
 /// <param name="currentHeight">The current height in cm</param>
 /// <param name="currentWeight">The current weight in kg</param>
 private void displayLoseWeightTextBlockFromIMC(double currentImc, double currentHeight, double currentWeight)
 {
     IMCCalculatorManager manager = new IMCCalculatorManager();
     LoseKilosToNormalWeightTextBlock.Text = manager.weightToLoseFromIMC(currentImc, currentHeight, currentWeight);
     LoseKilosToNormalWeightTextBlock.Visibility = Visibility.Visible;
 }