Пример #1
0
        /// <summary>
        /// Switches calculator to complex calculation mode.
        /// </summary>
        private void Complex_Calculations_Button_Checked(object sender, RoutedEventArgs e)
        {
            Options.Set_Calculation_Method(Calculation_Method.Complex);

            string newWorkSpaceText = "";

            if (no_First_Number_In_Equation_Single == false)
            {
                newWorkSpaceText += Back_Parser.Parse_Back(First_Number_In_Equation_Single);
            }

            if (no_operand_Sign_Single == false)
            {
                newWorkSpaceText += Operand_Sign_Single.ToString();
            }

            newWorkSpaceText += WorkSpace.Text;

            Reset_WorkSpace_Text(newWorkSpaceText);

            no_operand_Sign_Single             = true;
            no_First_Number_In_Equation_Single = true;

            Set_Specialized_Buttons();
        }
Пример #2
0
        /// <summary>
        /// Controls proper perfoming of operation button according to whether some operation were perfomed ealier.
        /// </summary>
        private void Basic_Calculation_Single(IOperand symbol)
        {
            // To rebuild after rebuilding exceptions thrown by Parser.

            string new_ResultSpace_Text;

            if (no_operand_Sign_Single == true)
            {
                if (no_First_Number_In_Equation_Single == true)
                {
                    First_Number_In_Equation_Single = Parse_WorkSpace();

                    new_ResultSpace_Text =
                        Back_Parser.Parse_Back(first_Number_In_Equation_Single) + symbol.ToString();
                }
                else
                {
                    new_ResultSpace_Text =
                        Back_Parser.Parse_Back(first_Number_In_Equation_Single) + symbol.ToString();
                }
            }
            else if ((String.IsNullOrEmpty(WorkSpace.Text) ||
                      String.IsNullOrWhiteSpace(WorkSpace.Text)) == true)
            {
                try
                {
                    first_Number_In_Equation_Single =
                        _Calculator.Operand_Selector(Operand_Sign_Single, first_Number_In_Equation_Single, Parse_WorkSpace());

                    new_ResultSpace_Text =
                        Back_Parser.Parse_Back(first_Number_In_Equation_Single);
                }
                catch (DivideByZeroException)
                {
                    new_ResultSpace_Text = "Dividing by zero is not allowed";

                    no_operand_Sign_Single = true;

                    no_First_Number_In_Equation_Single = true;
                }
                catch
                {
                    new_ResultSpace_Text = ResultSpace.Text;

                    symbol = Operand_Sign_Single;
                }
            }
            else
            {
                new_ResultSpace_Text = ResultSpace.Text;
            }

            Reset_ResultSpace_Text(new_ResultSpace_Text);

            Operand_Sign_Single = symbol;

            Clear_WorkSpace();
        }
        internal void Button_Invert_Number_Action()
        {
            Number WorkSpace_Number = Parse_WorkSpace();

            if (WorkSpace_Number.Value != 0)
            {
                WorkSpace_Number = _Calculator.Operand_Selector(new Division(), new Number(1), WorkSpace_Number);
            }

            Reset_WorkSpace_Text(Back_Parser.Parse_Back(WorkSpace_Number));
        }
Пример #4
0
        /// <summary>
        /// Controlls action after pressing equals button when option for single calculations is on.
        /// </summary>
        private void Equals_Single( )
        {
            string new_ResultSpace_Text;

            try
            {
                Number calculation_Result;

                if (no_First_Number_In_Equation_Single == true)
                {
                    return;
                }

                calculation_Result = _Calculator.Operand_Selector(Operand_Sign_Single, first_Number_In_Equation_Single, Parse_WorkSpace());

                new_ResultSpace_Text = Back_Parser.Parse_Back(calculation_Result);

                First_Number_In_Equation_Single = calculation_Result;
            }
            catch (DivideByZeroException)
            {
                new_ResultSpace_Text = "Dividing by zero is not allowed";
            }
            catch (Exception)
            {
                new_ResultSpace_Text = "Unknown error occur";
            }
            finally
            {
                no_operand_Sign_Single = true;
                //no_First_Number_In_Equation_Single = true;
                Clear_WorkSpace();
            }

            Reset_ResultSpace_Text(new_ResultSpace_Text);
        }
Пример #5
0
 /// <summary>
 /// Controlls action after pressing equals button when option for complex calculations is on.
 /// </summary>
 private void Equals_Complex(string equation)
 {
     Equation = new Equation(equation, Current_Numeral_System, Options.Commas_Type_Array);
     Reset_ResultSpace_Text(Back_Parser.Parse_Back(Equation.Solved_Number));
 }