예제 #1
0
 private void CtoF_click(object sender, RoutedEventArgs e)
 {
     if (MathExp.Any())
     {
         Expression cToF
             = new Expression($"(({MathExp}) * 9/5) + 32");
         var ans = cToF.calculate().ToString();
         DisplayResult(ans);
         ClearAll();
     }
 }
예제 #2
0
 private void FtoC_click(object sender, RoutedEventArgs e)
 {
     if (MathExp.Any())
     {
         Expression fTOc
             = new Expression($"(({MathExp}) - 32) * 5/9");
         var ans = fTOc.calculate().ToString();
         DisplayResult(ans);
         ClearAll();
     }
 }
예제 #3
0
 private void Sqrt_Click(object sender, RoutedEventArgs e)
 {
     if (MathExp.Any())
     {
         Expression sqrtMath
             = new Expression($"sqrt(({MathExp}))");
         var ans = sqrtMath.calculate().ToString();
         DisplayResult(ans);
         ClearAll();
     }
     else
     {
         DisplayResult("Need a number at first!");
     }
 }
예제 #4
0
        private void Conversion_click(object sender, RoutedEventArgs e)
        {
            if (MathExp.Any())
            {
                var detailSelectedStr = "question";

                if (Conversion_ask.SelectedValue.ToString() == "uo_length")
                {
                    var inputUnit = Units_length.SelectedValue;
                    if (inputUnit.ToString() != detailSelectedStr)
                    {
                        Expression mm = new Expression($"(({MathExp})*[{inputUnit}])/[mm]");
                        WinCnversion.FeedTxt1($"Millimetre: {mm.calculate()}");
                        WinCnversion.ShowTxt1();
                        Expression cm = new Expression($"(({MathExp})*[{inputUnit}])/[cm]");
                        WinCnversion.FeedTxt2($"Centimeter: {cm.calculate()}");
                        WinCnversion.ShowTxt2();
                        Expression m = new Expression($"(({MathExp})*[{inputUnit}])/[m]");
                        WinCnversion.FeedTxt3($"Meter: {m.calculate()}");
                        WinCnversion.ShowTxt3();
                        Expression km = new Expression($"(({MathExp})*[{inputUnit}]) / [km]");
                        WinCnversion.FeedTxt4($"Kilometer: {km.calculate()}");
                        WinCnversion.ShowTxt4();
                        Expression inch = new Expression($"(({MathExp})*[{inputUnit}])/[inch]");
                        WinCnversion.FeedTxt5($"Inch: {inch.calculate()}");
                        WinCnversion.ShowTxt5();
                        Expression ft = new Expression($"(({MathExp})*[{inputUnit}])/[ft]");
                        WinCnversion.FeedTxt6($"Foot: {ft.calculate()}");
                        WinCnversion.ShowTxt6();
                    }
                    else
                    {
                        DisplayResult("Select a unit");
                    }
                }
                else if (Conversion_ask.SelectedValue.ToString() == "uo_mass")
                {
                    var inputUnit = Units_mass.SelectedValue;

                    if (inputUnit.ToString() != detailSelectedStr)
                    {
                        Expression mg = new Expression($"(({MathExp})*[{inputUnit}])/[mg]");
                        WinCnversion.output_1b.Text       = $"Milligram: {mg.calculate()}";
                        WinCnversion.output_1b.Visibility = Visibility.Visible;
                        Expression gr = new Expression($"(({MathExp})*[{inputUnit}])/[gr]");
                        WinCnversion.output_2b.Text       = $"Gram: {gr.calculate()}";
                        WinCnversion.output_2b.Visibility = Visibility.Visible;
                        Expression kg = new Expression($"(({MathExp})*[{inputUnit}])/[kg]");
                        WinCnversion.output_3b.Text       = $"Kilogram: {kg.calculate()}";
                        WinCnversion.output_3b.Visibility = Visibility.Visible;
                        Expression oz = new Expression($"(({MathExp})*[{inputUnit}])/[oz]");
                        WinCnversion.output_4b.Text       = $"Ounce: {oz.calculate()}";
                        WinCnversion.output_4b.Visibility = Visibility.Visible;
                        Expression lb = new Expression($"(({MathExp})*[{inputUnit}])/[lb]");
                        WinCnversion.output_5b.Text       = $"Pound: {lb.calculate()}";
                        WinCnversion.output_5b.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        DisplayResult("Select a unit");
                    }
                }
                else if (Conversion_ask.SelectedValue.ToString() == "uo_info")
                {
                    var inputUnit = Units_info.SelectedValue;

                    if (inputUnit.ToString() != detailSelectedStr)
                    {
                        Expression b = new Expression($"(({MathExp})*[{inputUnit}])/[B]");
                        WinCnversion.output_1b.Text       = $"Byte: {b.calculate()}";
                        WinCnversion.output_1b.Visibility = Visibility.Visible;
                        Expression kb = new Expression($"(({MathExp})*[{inputUnit}])/[kB]");
                        WinCnversion.output_2b.Text       = $"Kilobyte: {kb.calculate()}";
                        WinCnversion.output_2b.Visibility = Visibility.Visible;
                        Expression mb = new Expression($"(({MathExp})*[{inputUnit}])/[MB]");
                        WinCnversion.output_3b.Text       = $"Megabyte: {mb.calculate()}";
                        WinCnversion.output_3b.Visibility = Visibility.Visible;
                        Expression gb = new Expression($"(({MathExp})*[{inputUnit}])/[GB]");
                        WinCnversion.output_4b.Text       = $"Gigabyte: {gb.calculate()}";
                        WinCnversion.output_4b.Visibility = Visibility.Visible;
                        Expression tb = new Expression($"(({MathExp})*[{inputUnit}])/[TB]");
                        WinCnversion.output_5b.Text       = $"Terabyte: {tb.calculate()}";
                        WinCnversion.output_5b.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        DisplayResult("Select a unit");
                    }
                }
                else if (Conversion_ask.SelectedValue.ToString() == "uo_time")
                {
                    var inputUnit = Units_time.SelectedValue;
                    if (inputUnit.ToString() != detailSelectedStr)
                    {
                        Expression sec = new Expression($"(({MathExp})*[{inputUnit}])/[s]");
                        WinCnversion.output_1b.Text       = $"Second: {sec.calculate()}";
                        WinCnversion.output_1b.Visibility = Visibility.Visible;
                        Expression min = new Expression($"(({MathExp})*[{inputUnit}])/[min]");
                        WinCnversion.output_2b.Text       = $"Minute: {min.calculate()}";
                        WinCnversion.output_2b.Visibility = Visibility.Visible;
                        Expression mb = new Expression($"(({MathExp})*[{inputUnit}])/[h]");
                        WinCnversion.output_3b.Text       = $"Hour: {mb.calculate()}";
                        WinCnversion.output_3b.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        DisplayResult("Select a unit");
                    }
                }
                else if (Conversion_ask.SelectedValue.ToString() == "uo_percent")
                {
                    Expression regularMath = new Expression(MathExp);
                    var        single      = regularMath.calculate();

                    Expression toBig = new Expression($"{single}*100");
                    WinCnversion.output_1b.Text       = $"{single} is {toBig.calculate()}%";
                    WinCnversion.output_1b.Visibility = Visibility.Visible;
                    Expression toSm = new Expression($"{single}/100");
                    WinCnversion.output_2b.Text       = $"{single}% is {toSm.calculate()}";
                    WinCnversion.output_2b.Visibility = Visibility.Visible;
                    ClearAll();
                }
                else if (Conversion_ask.SelectedValue.ToString() == "uo_number")
                {
                    bool success = int.TryParse(MathExp, out int my_regular);
                    if (success)
                    {
                        WinCnversion.output_1b.Text       = $"Integer: {my_regular}";
                        WinCnversion.output_1b.Visibility = Visibility.Visible;

                        var my_bin = ToBinary(my_regular);
                        WinCnversion.output_2b.Text       = $"Binary: {my_bin}";
                        WinCnversion.output_2b.Visibility = Visibility.Visible;
                        var my_oct = Convert.ToString(my_regular, 8);
                        WinCnversion.output_3b.Text       = $"Octal: {my_oct}";
                        WinCnversion.output_3b.Visibility = Visibility.Visible;
                        var my_hex = Convert.ToString(my_regular, 16);
                        WinCnversion.output_4b.Text       = $"Hexadecimal: {my_hex}";
                        WinCnversion.output_4b.Visibility = Visibility.Visible;
                        ClearAll();
                    }
                    else
                    {
                        WinCnversion.output_1b.Text       = $"Not a integer or other errors";
                        WinCnversion.output_1b.Visibility = Visibility.Visible;
                    }
                }
            }
            else
            {
                var warningMsg = "An input number required";
                DisplayResult(warningMsg);
            }
        }