Exemple #1
0
        private void Calculate()
        {
            if (!_loaded)
            {
                return;
            }
            double value     = 0.0;
            double tolerance = 0.0;

            switch (TabType.SelectedIndex)
            {
            case 0:
                value     = ((band41.Value * 10) + band42.Value) * band4m.Value;
                tolerance = band4t.Value;
                break;

            case 1:
                value     = ((band51.Value * 100) + (band52.Value * 10) + band53.Value) * band5m.Value;
                tolerance = band5t.Value;
                break;

            case 2:
                value     = ((band61.Value * 100) + (band62.Value * 10) + band63.Value) * band6m.Value;
                tolerance = band6t.Value;
                break;
            }

            switch (TabType.SelectedIndex)
            {
            case 0:
            case 1:
                TbResult.Text = string.Format("{0} Ω ± {1} %", _prefixes.DivideToPrefix(value), tolerance);
                break;

            case 2:
                TbResult.Text = string.Format("{0} Ω ± {1} % {2} ppm", _prefixes.DivideToPrefix(value), tolerance, band6temp.Value);
                break;
            }
        }
Exemple #2
0
 private void DisplayChange(object sender, RoutedEventArgs e)
 {
     string message = "Complex, Vector, Fraction and Matrix values not supported";
     var s = (sender as MenuItem)?.Name;
     try
     {
         switch (s)
         {
             case "DispNumSys":
                 var nd = new NumberSystemDisplayDialog();
                 nd.SetDisplay(Engine.Ans);
                 MainWindow.ShowDialog(nd);
                 return;
             case "DispText":
                 var ntd = new NumberToTextDialog();
                 ntd.SetNumber(Engine.Ans);
                 MainWindow.ShowDialog(ntd);
                 return;
             case "DispFractions":
                 if (!Helpers.IsSpecialType(Engine.Ans))
                 {
                     var f = new Fraction((double)Engine.Ans);
                     message = f.ToString();
                 }
                 break;
             case "DispFileSize":
                 if (!Helpers.IsSpecialType(Engine.Ans))
                 {
                     double x = Convert.ToDouble(Engine.Ans);
                     message = Helpers.DivideToFileSize(x);
                 }
                 break;
             case "DispPercent":
                 if (!Helpers.IsSpecialType(Engine.Ans))
                 {
                     double x = Convert.ToDouble(Engine.Ans);
                     x *= 100;
                     message = string.Format("{0}%", x);
                 }
                 break;
             case "DispPrefixes":
                 if (!Helpers.IsSpecialType(Engine.Ans))
                 {
                     var prefixes = new PrefixDictionary();
                     double x = Convert.ToDouble(Engine.Ans);
                     message = prefixes.DivideToPrefix(x);
                 }
                 break;
             default:
                 message = "Operation is not yet implemented in code. Sorry";
                 break;
         }
     }
     catch (Exception)
     {
         message = "Operation is not possible";
     }
     MainWindow.ShowDialog("Result as Fraction", message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative);
 }
Exemple #3
0
 private string FormatDouble(double input)
 {
     if (PreferPrefixes)
     {
         var pfx = new PrefixDictionary();
         return(pfx.DivideToPrefix(input));
     }
     if (GroupByThousands)
     {
         string gchar = " ";
         string fchar = ".";
         if (double.IsNaN(input) || double.IsInfinity(input))
         {
             return(input.ToString(CultureInfo.InvariantCulture));
         }
         var    sb     = new StringBuilder();
         bool   passed = false;
         int    j      = 1;
         int    i;
         char[] ar;
         string text = input.ToString();
         if (text.Contains(fchar))
         {
             for (i = text.Length - 1; i >= 0; i--)
             {
                 if (!passed && text[i] != fchar[0])
                 {
                     sb.Append(text[i]);
                 }
                 else if (text[i] == fchar[0])
                 {
                     sb.Append(text[i]);
                     passed = true;
                 }
                 if (passed && text[i] != fchar[0])
                 {
                     sb.Append(text[i]);
                     if (j % 3 == 0)
                     {
                         sb.Append(gchar);
                     }
                     j++;
                 }
             }
             ar = sb.ToString().ToCharArray();
             Array.Reverse(ar);
             return(new string(ar).Trim());
         }
         else
         {
             for (i = text.Length - 1; i >= 0; i--)
             {
                 sb.Append(text[i]);
                 if (j % 3 == 0)
                 {
                     sb.Append(gchar);
                 }
                 j++;
             }
             ar = sb.ToString().ToCharArray();
             Array.Reverse(ar);
             return(new string(ar).Trim());
         }
     }
     else
     {
         return(input.ToString(CultureInfo.InvariantCulture));
     }
 }
 private string FormatDouble(double input)
 {
     if (PreferPrefixes)
     {
         var pfx = new PrefixDictionary();
         return pfx.DivideToPrefix(input);
     }
     if (GroupByThousands)
     {
         string gchar = " ";
         string fchar = ".";
         if (double.IsNaN(input) || double.IsInfinity(input)) return input.ToString(CultureInfo.InvariantCulture);
         var sb = new StringBuilder();
         bool passed = false;
         int j = 1;
         int i;
         char[] ar;
         string text = input.ToString();
         if (text.Contains(fchar))
         {
             for (i = text.Length - 1; i >= 0; i--)
             {
                 if (!passed && text[i] != fchar[0]) sb.Append(text[i]);
                 else if (text[i] == fchar[0])
                 {
                     sb.Append(text[i]);
                     passed = true;
                 }
                 if (passed && text[i] != fchar[0])
                 {
                     sb.Append(text[i]);
                     if (j % 3 == 0) sb.Append(gchar);
                     j++;
                 }
             }
             ar = sb.ToString().ToCharArray();
             Array.Reverse(ar);
             return new string(ar).Trim();
         }
         else
         {
             for (i = text.Length - 1; i >= 0; i--)
             {
                 sb.Append(text[i]);
                 if (j % 3 == 0) sb.Append(gchar);
                 j++;
             }
             ar = sb.ToString().ToCharArray();
             Array.Reverse(ar);
             return new string(ar).Trim();
         }
     }
     else return input.ToString(CultureInfo.InvariantCulture);
 }
Exemple #5
0
        private void DisplayChange(object sender, RoutedEventArgs e)
        {
            string message = "Complex, Vector, Fraction and Matrix values not supported";
            var    s       = (sender as MenuItem)?.Name;

            try
            {
                switch (s)
                {
                case "DispNumSys":
                    var nd = new NumberSystemDisplayDialog();
                    nd.SetDisplay(Engine.Ans);
                    MainWindow.ShowDialog(nd);
                    return;

                case "DispText":
                    var ntd = new NumberToTextDialog();
                    ntd.SetNumber(Engine.Ans);
                    MainWindow.ShowDialog(ntd);
                    return;

                case "DispFractions":
                    if (!Helpers.IsSpecialType(Engine.Ans))
                    {
                        var f = new Fraction((double)Engine.Ans);
                        message = f.ToString();
                    }
                    break;

                case "DispFileSize":
                    if (!Helpers.IsSpecialType(Engine.Ans))
                    {
                        double x = Convert.ToDouble(Engine.Ans);
                        message = Helpers.DivideToFileSize(x);
                    }
                    break;

                case "DispPercent":
                    if (!Helpers.IsSpecialType(Engine.Ans))
                    {
                        double x = Convert.ToDouble(Engine.Ans);
                        x      *= 100;
                        message = string.Format("{0}%", x);
                    }
                    break;

                case "DispPrefixes":
                    if (!Helpers.IsSpecialType(Engine.Ans))
                    {
                        var    prefixes = new PrefixDictionary();
                        double x        = Convert.ToDouble(Engine.Ans);
                        message = prefixes.DivideToPrefix(x);
                    }
                    break;

                default:
                    message = "Operation is not yet implemented in code. Sorry";
                    break;
                }
            }
            catch (Exception)
            {
                message = "Operation is not possible";
            }
            MainWindow.ShowDialog("Result as Fraction", message, MahApps.Metro.Controls.Dialogs.MessageDialogStyle.Affirmative);
        }