Пример #1
0
        // Метод для объединения цифровых значений в одну строку textBlockLine1.
        public void UnificationLine1(string number)
        {
            string content1 = textBlockLine1.Text;
            string content2 = textBlockLine2.Text;

            if (number == "/")
            {
                stacknumber.Push(number);
            }
            if (number == "*")
            {
                stacknumber.Push(number);
            }
            if (number == "-")
            {
                stacknumber.Push(number);
            }
            if (number == "+")
            {
                stacknumber.Push(number);
            }
            if (number == "=")
            {
                stacknumber.Push(number);
            }
            string[] arraynumber = new string[stacknumber.Count];
            stacknumber.CopyTo(arraynumber, 0);
            if (number == "CE" || number == "C")
            {
                textBlockLine1.Text   = "";
                textBlockLine2.Text   = "0";
                value1division        = "";
                value2division        = "0";
                counterdivision       = 1;
                value1multiplication  = "";
                value2multiplication  = "0";
                countermultiplication = 1;
                value1minus           = "";
                value2minus           = "0";
                counterminus          = 1;
                value1plus            = "";
                value2plus            = "0";
                counterplus           = 1;
                value1equl            = "";
                value2equl            = "0";
                counterequl           = 1;
                return;
            }
            if (content1.Length >= 70)
            {
                return;
            }
            if (number == "/" && value1division != textBlockLine2.Text)
            {
                string temp = content1 + content2 + "/";
                textBlockLine1.Text = temp;
                MathUWP mathUWP = new MathUWP();
                switch (counterdivision)
                {
                case 1:
                    try
                    {
                        if (arraynumber[1] == "+")
                        {
                            value2plus          = textBlockLine2.Text;
                            resultplus          = mathUWP.Plus(value1plus, value2plus);
                            textBlockLine2.Text = resultplus;                  // Вывод результата.
                            value1plus          = resultplus;
                            value1division      = value1plus;
                            counterdivision     = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "-")
                        {
                            value2minus         = textBlockLine2.Text;
                            resultminus         = mathUWP.Minus(value1minus, value2minus);
                            textBlockLine2.Text = resultminus;                  // Вывод результата.
                            value1minus         = resultminus;
                            value1division      = value1minus;
                            counterdivision     = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "*")
                        {
                            value2multiplication = textBlockLine2.Text;
                            resultmultiplication = mathUWP.Multiplication(value1multiplication, value2multiplication);
                            textBlockLine2.Text  = resultmultiplication;                 // Вывод результата.
                            value1multiplication = resultmultiplication;
                            value1division       = value1multiplication;
                            counterdivision      = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    value1division  = textBlockLine2.Text;
                    counterdivision = 2;
                    break;

                case 2:
                    value2division      = textBlockLine2.Text;
                    resultdivision      = mathUWP.Division(value1division, value2division);
                    textBlockLine2.Text = resultdivision;                  // Вывод результата.
                    value1division      = resultdivision;
                    break;
                }
            }
            if (number == "*" && value1multiplication != textBlockLine2.Text)
            {
                string temp = content1 + content2 + "*";
                textBlockLine1.Text = temp;
                MathUWP mathUWP = new MathUWP();
                switch (countermultiplication)
                {
                case 1:
                    try
                    {
                        if (arraynumber[1] == "+")
                        {
                            value2plus            = textBlockLine2.Text;
                            resultplus            = mathUWP.Plus(value1plus, value2plus);
                            textBlockLine2.Text   = resultplus;                // Вывод результата.
                            value1plus            = resultplus;
                            value1multiplication  = value1plus;
                            countermultiplication = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "-")
                        {
                            value2minus           = textBlockLine2.Text;
                            resultminus           = mathUWP.Minus(value1minus, value2minus);
                            textBlockLine2.Text   = resultminus;                // Вывод результата.
                            value1minus           = resultminus;
                            value1multiplication  = value1minus;
                            countermultiplication = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "/")
                        {
                            value2division        = textBlockLine2.Text;
                            resultdivision        = mathUWP.Division(value1division, value2division);
                            textBlockLine2.Text   = resultdivision;                // Вывод результата.
                            value1division        = resultdivision;
                            value1multiplication  = value1division;
                            countermultiplication = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    value1multiplication  = textBlockLine2.Text;
                    countermultiplication = 2;
                    break;

                case 2:
                    value2multiplication = textBlockLine2.Text;
                    resultmultiplication = mathUWP.Multiplication(value1multiplication, value2multiplication);
                    textBlockLine2.Text  = resultmultiplication;                 // Вывод результата.
                    value1multiplication = resultmultiplication;
                    break;
                }
            }
            if (number == "-" && value1minus != textBlockLine2.Text)
            {
                string temp = content1 + content2 + "-";
                textBlockLine1.Text = temp;
                MathUWP mathUWP = new MathUWP();
                switch (counterminus)
                {
                case 1:
                    try
                    {
                        if (arraynumber[1] == "+")
                        {
                            value2plus          = textBlockLine2.Text;
                            resultplus          = mathUWP.Plus(value1plus, value2plus);
                            textBlockLine2.Text = resultplus;                  // Вывод результата.
                            value1plus          = resultplus;
                            value1minus         = value1plus;
                            counterminus        = 2;
                            break;
                        }
                    } catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "*")
                        {
                            value2multiplication = textBlockLine2.Text;
                            resultmultiplication = mathUWP.Multiplication(value1multiplication, value2multiplication);
                            textBlockLine2.Text  = resultmultiplication;                 // Вывод результата.
                            value1multiplication = resultmultiplication;
                            value1minus          = value1multiplication;
                            counterminus         = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "/")
                        {
                            value2division      = textBlockLine2.Text;
                            resultdivision      = mathUWP.Division(value1division, value2division);
                            textBlockLine2.Text = resultdivision;                  // Вывод результата.
                            value1division      = resultdivision;
                            value1minus         = value1division;
                            counterminus        = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    value1minus  = textBlockLine2.Text;
                    counterminus = 2;
                    break;

                case 2:
                    value2minus         = textBlockLine2.Text;
                    resultminus         = mathUWP.Minus(value1minus, value2minus);
                    textBlockLine2.Text = resultminus;                  // Вывод результата.
                    value1minus         = resultminus;
                    break;
                }
            }
            if (number == "+" && value1plus != textBlockLine2.Text)
            {
                string temp = content1 + content2 + "+";
                textBlockLine1.Text = temp;
                MathUWP mathUWP = new MathUWP();
                switch (counterplus)
                {
                case 1:
                    try
                    {
                        if (arraynumber[1] == "-")
                        {
                            value2minus         = textBlockLine2.Text;
                            resultminus         = mathUWP.Minus(value1minus, value2minus);
                            textBlockLine2.Text = resultminus;                  // Вывод результата.
                            value1minus         = resultminus;
                            value1plus          = value1minus;
                            counterplus         = 2;
                            break;
                        }
                    } catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "*")
                        {
                            value2multiplication = textBlockLine2.Text;
                            resultmultiplication = mathUWP.Multiplication(value1multiplication, value2multiplication);
                            textBlockLine2.Text  = resultmultiplication;                 // Вывод результата.
                            value1multiplication = resultmultiplication;
                            value1plus           = value1multiplication;
                            counterplus          = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "/")
                        {
                            value2division      = textBlockLine2.Text;
                            resultdivision      = mathUWP.Division(value1division, value2division);
                            textBlockLine2.Text = resultdivision;                  // Вывод результата.
                            value1division      = resultdivision;
                            value1plus          = value1division;
                            counterplus         = 2;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    value1plus  = textBlockLine2.Text;
                    counterplus = 2;
                    break;

                case 2:
                    value2plus          = textBlockLine2.Text;
                    resultplus          = mathUWP.Plus(value1plus, value2plus);
                    textBlockLine2.Text = resultplus;                  // Вывод результата.
                    value1plus          = resultplus;
                    break;
                }
            }
            if (number == "=" && value1equl.IndexOf("=") == -1)
            {
                string tempequl = content1 + content2 + "=";
                value1equl          = tempequl;
                textBlockLine1.Text = tempequl;
                MathUWP mathUWP = new MathUWP();
                switch (counterequl)
                {
                case 1:
                    try
                    {
                        if (arraynumber[1] == "+")
                        {
                            value2plus          = textBlockLine2.Text;
                            resultplus          = mathUWP.Plus(value1plus, value2plus);
                            textBlockLine2.Text = resultplus;                  // Вывод результата.
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "-")
                        {
                            value2minus         = textBlockLine2.Text;
                            resultminus         = mathUWP.Minus(value1minus, value2minus);
                            textBlockLine2.Text = resultminus;                  // Вывод результата.
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "*")
                        {
                            value2multiplication = textBlockLine2.Text;
                            resultmultiplication = mathUWP.Multiplication(value1multiplication, value2multiplication);
                            textBlockLine2.Text  = resultmultiplication;                 // Вывод результата.
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    try
                    {
                        if (arraynumber[1] == "/")
                        {
                            value2division      = textBlockLine2.Text;
                            resultdivision      = mathUWP.Division(value1division, value2division);
                            textBlockLine2.Text = resultdivision;                  // Вывод результата.
                        }
                    }
                    catch (Exception ex)
                    {
                        string debug = ex.Message;
                    }
                    break;
                }
            }
        }
Пример #2
0
 // Метод для фильтрации и вывода в TextBlock.
 public void Filter(string text)
 {
     if (text == "%")
     {
         string value = textBlockLine1.Text;
         value = value.Remove((value.Length - 1), 1);
         string  percent = textBlockLine2.Text;
         MathUWP mathUWP = new MathUWP();
         string  result  = mathUWP.Percent(value, percent);
         textBlockLine2.Text = result;
         return;
     }
     if (text == "CE")
     {
         UnificationLine1("CE");
         UnificationLine2("CE");
         return;
     }
     if (text == "C")
     {
         UnificationLine1("C");
         UnificationLine2("C");
         return;
     }
     if (text == "Delete")
     {
         UnificationLine2("Delete");
         return;
     }
     if (text == "1/x")
     {
         string  value   = textBlockLine2.Text;
         MathUWP mathUWP = new MathUWP();
         string  result  = mathUWP.One(value);
         textBlockLine1.Text = "1/(" + value + ")";
         textBlockLine2.Text = result;
         return;
     }
     if (text == "x^2")
     {
         string  value   = textBlockLine2.Text;
         MathUWP mathUWP = new MathUWP();
         string  result  = mathUWP.Degree(value);
         textBlockLine1.Text = "sqr(" + value + ")";
         textBlockLine2.Text = result;
         return;
     }
     if (text == "sqrt(x)")
     {
         string  value   = textBlockLine2.Text;
         MathUWP mathUWP = new MathUWP();
         string  result  = mathUWP.SQRT(value);
         textBlockLine1.Text = "sqrt(" + value + ")";
         textBlockLine2.Text = result;
         return;
     }
     if (text == "/")
     {
         UnificationLine1("/");
         return;
     }
     if (text == "7")
     {
         UnificationLine2("7");
         return;
     }
     if (text == "8")
     {
         UnificationLine2("8");
         return;
     }
     if (text == "9")
     {
         UnificationLine2("9");
         return;
     }
     if (text == "*")
     {
         UnificationLine1("*");
         return;
     }
     if (text == "4")
     {
         UnificationLine2("4");
         return;
     }
     if (text == "5")
     {
         UnificationLine2("5");
         return;
     }
     if (text == "6")
     {
         UnificationLine2("6");
         return;
     }
     if (text == "-")
     {
         UnificationLine1("-");
         return;
     }
     if (text == "1")
     {
         UnificationLine2("1");
         return;
     }
     if (text == "2")
     {
         UnificationLine2("2");
         return;
     }
     if (text == "3")
     {
         UnificationLine2("3");
         return;
     }
     if (text == "+")
     {
         UnificationLine1("+");
         return;
     }
     if (text == "+/-")
     {
         UnificationLine2("+/-");
         return;
     }
     if (text == "0")
     {
         UnificationLine2("0");
         return;
     }
     if (text == ",")
     {
         UnificationLine2(",");
         return;
     }
     if (text == "=")
     {
         UnificationLine1("=");
         return;
     }
 }