private void ddlUnits_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var combo = (ComboBox)sender;
            var item  = (ComboBoxItem)combo.SelectedItem;

            //Next line of code is a trick to convert the string content
            //of the selected item into the emun.
            u = (SysOfUnits)Enum.Parse(typeof(SysOfUnits), item.Content.ToString());
            switch (u)
            {
            case SysOfUnits.Celsius:
                calculateButton.Background = new SolidColorBrush(Windows.UI.Colors.DarkRed);
                break;

            case SysOfUnits.Fahrenheit:
                calculateButton.Background = new SolidColorBrush(Windows.UI.Colors.DarkGreen);
                break;

            case SysOfUnits.Kelvin:
                calculateButton.Background = new SolidColorBrush(Windows.UI.Colors.DarkBlue);
                break;

            default:
                break;
            }
            CalculateTemp();
        }
 public MainPage()
 {
     this.InitializeComponent();
     if (correctBrush == null)
     {
         correctBrush = txtInput.Foreground;
     }
     u                 = SysOfUnits.Celsius;
     playSpeech        = false;
     speechIcon.Source = new BitmapImage(new Uri(this.BaseUri, "/Assets/speakerMuted.png"));
     talker            = new SpeechUtil();
 }
Пример #3
0
 public static double bmiValue(double height, double weight, SysOfUnits u, out string category)
 {
     if (height < 0 || weight < 0)
     {
         throw new ArgumentOutOfRangeException("Neither height nor weight can be negative.");
     }
     else
     {
         double _bmi = weight / Math.Pow(height, 2);
         if (u == SysOfUnits.Imperial)
         {
             _bmi *= 703;
         }
         //Set the category
         if (_bmi < 15)
         {
             category = "Very severely underweight.";
         }
         else if (_bmi <= 16)
         {
             category = "Severely underweight.";
         }
         else if (_bmi <= 18.5)
         {
             category = "Underweight.";
         }
         else if (_bmi <= 25)
         {
             category = "Normal.";
         }
         else if (_bmi <= 30)
         {
             category = "Overweight.";
         }
         else if (_bmi <= 35)
         {
             category = "Obese Class I (Moderately obese).";
         }
         else if (_bmi <= 40)
         {
             category = "Obese Class II (Severely obese).";
         }
         else
         {
             category = "Obese Class III (Very Severely obese).";
         }
         return(_bmi);
     }
 }
Пример #4
0
 public BMICalc(double height, double weight, SysOfUnits u)
 {
     if (height < 0 || weight < 0)
     {
         throw new ArgumentOutOfRangeException("Neither height nor weight can be negative.");
     }
     else
     {
         _bmi = weight / Math.Pow(height, 2);
         if (u == SysOfUnits.Imperial)
         {
             _bmi *= 703;
         }
     }
 }
Пример #5
0
 public TempConvert(decimal temp, SysOfUnits u)
 {
     if (u == SysOfUnits.Celsius)
     {
         t = temp;
     }
     else if (u == SysOfUnits.Kelvin)
     {
         t = temp - 273.15m;
     }
     else
     {
         t = (temp - 32m) * 5m / 9m;
     }
     if (t < -273.15m)
     {
         throw new ArgumentOutOfRangeException();
     }
 }