Пример #1
0
        private void PowBtnCommandExecute(OperatorCommandParameter commandParameter)
        {
            if (_calculatorStorageService.LastUserInteractionType == UserInteractionType.EqualBtnPressed)
            {
                _calculatorStorageService.AddValueToQueue(_calculatorStorageService.Ans.ToString(CultureInfo.CurrentCulture));

                SeriesOfComputerTextBoxValue = $"{Operations.GetOperationText(OperationType.Ans)}";
            }

            if (_calculatorStorageService.LastUserInteractionType == UserInteractionType.AnsBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.EqualBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.EFunctionBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.ModOperatorBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.FactOperatorBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.SquareOfXNumberBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.RightParenthesisBtnPressed)

            {
                _calculatorStorageService.AddOperatorToStack(commandParameter.OperatorText, commandParameter.OperatorType);

                SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {commandParameter.OperatorText}";
            }
            else
            {
                _calculatorStorageService.AddValueToQueue(NumberTextBoxValue);
                _calculatorStorageService.AddOperatorToStack(commandParameter.OperatorText, commandParameter.OperatorType);

                SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {NumberTextBoxValue} {commandParameter.OperatorText}";
            }

            NumberTextBoxValue = default(int).ToString();

            _calculatorStorageService.SetLastUserInteractionType(commandParameter.UserInteractionType);
        }
        private void LeftParenthesisBtnCommandExecute(OperatorCommandParameter commandParameter)
        {
            if (_calculatorStorageService.LastUserInteractionType == UserInteractionType.EqualBtnPressed)
            {
                NumberTextBoxValue           = default(int).ToString();
                SeriesOfComputerTextBoxValue = string.Empty;
            }

            if (_calculatorStorageService.LastUserInteractionType == UserInteractionType.AnsBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.EFunctionBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.ModOperatorBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.FactOperatorBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.SquareOfXNumberBtnPressed ||
                _calculatorStorageService.LastUserInteractionType == UserInteractionType.RightParenthesisBtnPressed)
            {
                string mulOperatorText = Operators.GetOperatorText(OperatorType.Multiplication);

                _calculatorStorageService.AddOperatorToStack(mulOperatorText, OperatorType.Multiplication);

                SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {mulOperatorText}";
            }

            _calculatorStorageService.AddLeftParenthesisOperatorToStack(commandParameter.OperatorText);

            SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {commandParameter.OperatorText}";

            _calculatorStorageService.SetLastUserInteractionType(commandParameter.UserInteractionType);
        }
Пример #3
0
        private void SquareOfNumberBtnCommandExecute(OperatorCommandParameter commandParameter)
        {
            const int SQUARE_VALUE = 2;

            if (_calculatorStorageService.LastUserInteractionType == UserInteractionType.EqualBtnPressed)
            {
                _calculatorStorageService.AddValueToQueue(_calculatorStorageService.Ans.ToString(CultureInfo.CurrentCulture));

                SeriesOfComputerTextBoxValue = $"{Operations.GetOperationText(OperationType.Ans)}";
            }

            if (_calculatorStorageService.LastUserInteractionType != UserInteractionType.AnsBtnPressed &&
                _calculatorStorageService.LastUserInteractionType != UserInteractionType.EqualBtnPressed &&
                _calculatorStorageService.LastUserInteractionType != UserInteractionType.EFunctionBtnPressed &&
                _calculatorStorageService.LastUserInteractionType != UserInteractionType.ModOperatorBtnPressed &&
                _calculatorStorageService.LastUserInteractionType != UserInteractionType.FactOperatorBtnPressed &&
                _calculatorStorageService.LastUserInteractionType != UserInteractionType.SquareOfXNumberBtnPressed &&
                _calculatorStorageService.LastUserInteractionType != UserInteractionType.RightParenthesisBtnPressed)
            {
                _calculatorStorageService.AddValueToQueue(NumberTextBoxValue);

                SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {NumberTextBoxValue}";
            }

            _calculatorStorageService.AddValueToQueue(Convert.ToString(SQUARE_VALUE));
            _calculatorStorageService.AddOperatorToStack(commandParameter.OperatorText, commandParameter.OperatorType);

            SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {commandParameter.OperatorText} {SQUARE_VALUE}";
            NumberTextBoxValue           = string.Empty;

            _calculatorStorageService.SetLastUserInteractionType(commandParameter.UserInteractionType);
        }
Пример #4
0
        private void EqualBtnCommandExecute(OperatorCommandParameter commandParameter)
        {
            if (_calculatorStorageService.LastUserInteractionType != UserInteractionType.EqualBtnPressed)
            {
                while (_calculatorStorageService.LeftParenthesisNumber > 0)
                {
                    RightParenthesisBtnCommand.Execute(new OperatorCommandParameter(UserInteractionType.RightParenthesisBtnPressed, OperatorType.RightParenthesis));
                }

                try
                {
                    if (_calculatorStorageService.LastUserInteractionType != UserInteractionType.AnsBtnPressed &&
                        _calculatorStorageService.LastUserInteractionType != UserInteractionType.EFunctionBtnPressed &&
                        _calculatorStorageService.LastUserInteractionType != UserInteractionType.ModOperatorBtnPressed &&
                        _calculatorStorageService.LastUserInteractionType != UserInteractionType.FactOperatorBtnPressed &&
                        _calculatorStorageService.LastUserInteractionType != UserInteractionType.SquareOfXNumberBtnPressed &&
                        _calculatorStorageService.LastUserInteractionType != UserInteractionType.RightParenthesisBtnPressed)
                    {
                        _calculatorStorageService.AddValueToQueue(NumberTextBoxValue);

                        SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {NumberTextBoxValue}";
                    }

                    SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {commandParameter.OperatorText}";

                    _calculatorStorageService.AddAllItemsInTheStackToTheQueue();

                    double calculateResult = _calculateService.Calculate(_calculatorStorageService.Queue, _selectedAngleUnit);

                    NumberTextBoxValue = calculateResult.ToString(CultureInfo.CurrentCulture);

                    _calculatorStorageService.SetAns(calculateResult);
                }
                catch (DivideByZeroException)
                {
                    NumberTextBoxValue = "Infinity";
                }
                catch (NotFiniteNumberException)
                {
                    NumberTextBoxValue = "Infinity";
                }
                catch (SyntaxErrorException)
                {
                    NumberTextBoxValue = "Syntax ERROR";
                }
                finally
                {
                    _calculatorStorageService.ClearQueue();
                    _calculatorStorageService.ClearStack();
                    _calculatorStorageService.ClearLeftParenthesisNumber();

                    _calculatorStorageService.SetLastUserInteractionType(UserInteractionType.EqualBtnPressed);
                }
            }
        }
        private void RightParenthesisBtnCommandExecute(OperatorCommandParameter commandParameter)
        {
            if (_calculatorStorageService.LeftParenthesisNumber > 0)
            {
                if (_calculatorStorageService.LastUserInteractionType != UserInteractionType.AnsBtnPressed &&
                    _calculatorStorageService.LastUserInteractionType != UserInteractionType.EFunctionBtnPressed &&
                    _calculatorStorageService.LastUserInteractionType != UserInteractionType.ModOperatorBtnPressed &&
                    _calculatorStorageService.LastUserInteractionType != UserInteractionType.FactOperatorBtnPressed &&
                    _calculatorStorageService.LastUserInteractionType != UserInteractionType.SquareOfXNumberBtnPressed &&
                    _calculatorStorageService.LastUserInteractionType != UserInteractionType.RightParenthesisBtnPressed)
                {
                    _calculatorStorageService.AddValueToQueue(NumberTextBoxValue);

                    SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {NumberTextBoxValue}";
                }

                _calculatorStorageService.AddRightParenthesisOperatorToStack(commandParameter.OperatorText);

                SeriesOfComputerTextBoxValue = $"{SeriesOfComputerTextBoxValue.Trim()} {commandParameter.OperatorText}";
                NumberTextBoxValue           = string.Empty;

                _calculatorStorageService.SetLastUserInteractionType(commandParameter.UserInteractionType);
            }
        }