Beispiel #1
0
        /// <summary>
        /// To find the percentage, if other additional operations are applied
        /// </summary>
        /// <remarks>
        /// <para>For operations that do not have a character notation in the expression</para>
        /// <para>In the case of the " % " operation, the change is that the last number or sequence of operations is replaced with a specific percentage of the rest of the expression</para>
        /// </remarks>
        /// <returns>
        /// The string of the current expression with the percentage found
        /// </returns>
        private string ChangeTheSetOfRecentAdditionalOperations(string currentExpression)
        {
            int           pos;
            string        copiedFragment;
            StringBuilder stringBuilderCurExpr = CurrentExpressionChange(currentExpression, out pos, out copiedFragment);
            Calculate     calculate            = new Calculate();
            double        number;

            if (Common.MathSignCheck(currentExpression))
            {
                number = calculate.CalcPercentage(copiedFragment, stringBuilderCurExpr.ToString().Remove(stringBuilderCurExpr.Length - 3, 3));
            }
            else
            {
                number = calculate.CalcPercentage(copiedFragment, stringBuilderCurExpr.ToString());
            }

            if (NumberStandardization.NumberCheck(number.ToString()))
            {
                stringBuilderCurExpr.Insert(pos, number.ToString());
            }
            else
            {
                stringBuilderCurExpr.Insert(pos, ((int)Digits.Zero).ToString());
            }

            return(stringBuilderCurExpr.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// To change the current expression depending on the pressed operation and the state of the buttons
        /// </summary>
        private string NewCurrentExpression()
        {
            if (buttonsState.EqualBtnPressed)
            {
                buttonsState.NumberPadBtnPressed_Change(true);
                buttonsState.AdditionalOperationBtnPressed_Change(false);
                buttonsState.EqualBtnPressed_Change(false);

                return(NumberStandardization.Standardization(calculate.CalcPercentage(NumberStandardization.Standardization(currentData.CurrentNumber), currentData.CurrentExpression.Remove(currentData.CurrentExpression.Length - 3, 3)).ToString()));
            }
            else
            {
                if (currentData.CurrentExpression != string.Empty)
                {
                    if (buttonsState.AdditionalOperationBtnPressed)
                    {
                        return(ChangeTheSetOfRecentAdditionalOperations(currentData.CurrentExpression));
                    }
                    else
                    {
                        return(currentData.CurrentExpression + NumberStandardization.Standardization(calculate.CalcPercentage(NumberStandardization.Standardization(currentData.CurrentNumber), currentData.CurrentExpression.Remove(currentData.CurrentExpression.Length - 3, 3)).ToString()));
                    }
                }
                else
                {
                    return(currentData.CurrentExpression + NumberStandardization.Standardization(calculate.CalcPercentage(NumberStandardization.Standardization(currentData.CurrentNumber), ((int)Digits.Zero).ToString()).ToString()));
                }
            }
        }
 /// <summary>
 /// To change the current expression depending on the pressed operation and the state of the buttons
 /// </summary>
 private string NewCurrentExpression(BasicMathOperations pressedOperation)
 {
     //If the expression was calculated and "=" was pressed again
     if (buttonsState.EqualBtnPressed && (pressedOperation == BasicMathOperations.Equal) && Common.MathSignCheck(currentData.CurrentExpression))
     {
         return(NumberStandardization.Standardization(currentData.CurrentNumber) + CopyLastOperation(currentData.CurrentExpression.Remove(currentData.CurrentExpression.Length - 3, 3)) + SetSelectedBasicMathOperation(pressedOperation));
     }
     else if (pressedOperation == BasicMathOperations.Sqr)
     {
         return(SetSelectedBasicMathOperation(pressedOperation) + NumberStandardization.StandardizationSqr(currentData.CurrentNumber));
     }
     else if (pressedOperation == BasicMathOperations.Sqrt)
     {
         return(SetSelectedBasicMathOperation(pressedOperation) + NumberStandardization.StandardizationSqr(currentData.CurrentNumber));
     }
     else if (pressedOperation == BasicMathOperations.PartOfTheWhole)
     {
         return(SetSelectedBasicMathOperation(pressedOperation) + NumberStandardization.StandardizationSqr(currentData.CurrentNumber));
     }
     else if (buttonsState.NumberPadBtnPressed)
     {
         return(currentData.CurrentExpression + NumberStandardization.Standardization(currentData.CurrentNumber) + SetSelectedBasicMathOperation(pressedOperation));
     }
     //Сhanging the basic math operation sign
     else
     {
         return(ChangeOperation(currentData.CurrentExpression, SetSelectedBasicMathOperation(pressedOperation)));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Clears the last digit entered in the current number
 /// </summary>
 public void Backspace()
 {
     if (buttonsState.EqualBtnPressed)
     {
         if (NumberStandardization.NumberCheck(currentData.CurrentNumber))
         {
             currentData.CurrentExpression = ClearExpression(currentData.CurrentExpression);
             buttonsState.NumberPadBtnPressed_Change(true);
             buttonsState.AdditionalOperationBtnPressed_Change(false);
             buttonsState.EqualBtnPressed_Change(false);
         }
         else
         {
             ClearAll();
         }
     }
     else
     {
         currentData.CurrentNumber = Backspace(currentData.CurrentNumber);
     }
 }
Beispiel #5
0
 /// <summary>
 /// To change the current expression depending on the pressed operation and the state of the buttons
 /// </summary>
 private string NewCurrentExpression(BasicMathOperations pressedOperation)
 {
     //If the expression was calculated and "=" was pressed again
     if (buttonsState.EqualBtnPressed && (pressedOperation == BasicMathOperations.Equal) && Common.MathSignCheck(currentData.CurrentExpression))
     {
         return(NumberStandardization.Standardization(currentData.CurrentNumber) + CopyLastOperation(currentData.CurrentExpression.Remove(currentData.CurrentExpression.Length - 3, 3)) + SetSelectedBasicMathOperation(pressedOperation));
     }
     //If the number and additional operation were pressed
     else if (buttonsState.NumberPadBtnPressed && buttonsState.AdditionalOperationBtnPressed)
     {
         return(currentData.CurrentExpression + SetSelectedBasicMathOperation(pressedOperation));
     }
     //If a number was pressed, but not an additional operation
     else if (buttonsState.NumberPadBtnPressed && !buttonsState.AdditionalOperationBtnPressed)
     {
         return(currentData.CurrentExpression + NumberStandardization.Standardization(currentData.CurrentNumber) + SetSelectedBasicMathOperation(pressedOperation));
     }
     //Сhanging the basic math operation sign
     else
     {
         return(ChangeOperation(currentData.CurrentExpression, SetSelectedBasicMathOperation(pressedOperation)));
     }
 }
Beispiel #6
0
 /// <summary>
 /// To change the current expression depending on the pressed operation and the state of the buttons
 /// </summary>
 private string NewCurrentExpression(AdditionalOperations pressedOperation)
 {
     //If an additional operation is not used for the first time
     if (buttonsState.AdditionalOperationBtnPressed)
     {
         return(ChangeTheSetOfRecentAdditionalOperations(currentData.CurrentExpression, SetSelectedAdditionalOperation(pressedOperation)));
     }
     else
     {
         return(currentData.CurrentExpression + SetSelectedAdditionalOperation(pressedOperation) + '(' + NumberStandardization.Standardization(currentData.CurrentNumber) + ')');
     }
 }