/// <summary> /// Default constructor /// </summary> public StandardCalculatorViewModel() { #region Initialization currentData = new CurrentData(); buttonsState = new ButtonsState(); clearData = new ClearData(currentData, buttonsState); numberFormation = new NumberFormation(currentData, buttonsState, clearData); expressionFormation = new ExpressionFormation(currentData, buttonsState, clearData); memory = new Memory(); #endregion #region Create commands #region Commands for memory operations MemorySaveCommand = new RelayCommand(() => { memory.MemorySave(CurrentNumber); UpdateMainProperties(); }); MemoryClearCommand = new RelayCommand(() => { memory.MemoryClear(); UpdateMainProperties(); }); MemoryReadCommand = new RelayCommand(() => { memory.MemoryRead(CurrentNumber); UpdateMainProperties(); }); MemoryPlusCommand = new RelayCommand(() => { memory.MemoryPlus(CurrentNumber); UpdateMainProperties(); }); MemoryMinusCommand = new RelayCommand(() => { memory.MemoryMinus(CurrentNumber); UpdateMainProperties(); }); #endregion #region Commands for clearing data ClearCommand = new RelayCommand(() => { clearData.ClearAll(); UpdateMainProperties(); }); ClearEntryCommand = new RelayCommand(() => { clearData.ClearEntry(); UpdateMainProperties(); }); BackspaceCommand = new RelayCommand(() => { clearData.Backspace(); UpdateMainProperties(); }); #endregion #region Commands for basic math operations /// <summary> /// Adds a "+" operation to the current expression /// </summary> AdditionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Addition); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "-" operation to the current expression /// </summary> SubtractionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Subtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "*" operation to the current expression /// </summary> MultiplyCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Multiply); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "/" operation to the current expression /// </summary> DivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Division); UpdateMainProperties(); }); /// <summary> /// Adds a "%" operation to the current expression /// </summary> ModuleDivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.ModuleDivision); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "=" operation to the current expression /// </summary> EqualCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Equal); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Commands for math operations /// <summary> /// Adds a "1/x" operation to the current expression /// </summary> PartOfTheWholeCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.PartOfTheWhole); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "x²" operation to the current expression /// </summary> SqrCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Sqr); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); /// <summary> /// Adds a "√x" operation to the current expression /// </summary> SqrtCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Sqrt); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Number pad commands DigitZeroCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Zero); UpdateMainProperties(); }); DigitOneCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.One); UpdateMainProperties(); }); DigitTwoCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Two); UpdateMainProperties(); }); DigitThreeCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Three); UpdateMainProperties(); }); DigitFourCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Four); UpdateMainProperties(); }); DigitFiveCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Five); UpdateMainProperties(); }); DigitSixCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Six); UpdateMainProperties(); }); DigitSevenCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Seven); UpdateMainProperties(); }); DigitEightCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Eight); UpdateMainProperties(); }); DigitNineCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Nine); UpdateMainProperties(); }); InvertNumberCommand = new RelayCommand(() => { numberFormation.InvertNumber(); UpdateMainProperties(); }); CommaCommand = new RelayCommand(() => { numberFormation.AddComma(); UpdateMainProperties(); }); #endregion #endregion }
/// <summary> /// Default constructor /// </summary> public StandardCalculatorViewModel() { #region Initialization currentData = new CurrentData(); buttonsState = new ButtonsState(); clearData = new ClearData(currentData, buttonsState); numberFormation = new NumberFormation(currentData, buttonsState, clearData); expressionFormation = new ExpressionFormation(currentData, buttonsState, clearData); memory = new Memory(); #endregion #region Create commands #region Commands for clearing data ClearCommand = new RelayCommand(() => { clearData.ClearAll(); UpdateMainProperties(); }); ClearEntryCommand = new RelayCommand(() => { clearData.ClearEntry(); UpdateMainProperties(); }); BackspaceCommand = new RelayCommand(() => { clearData.Backspace(); UpdateMainProperties(); }); #endregion #region Commands for basic math operations AdditionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Addition); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SubtractionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Subtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MultiplyCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Multiplication); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); DivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Division); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); ModuleDivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.ModuleDivision); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); EqualCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Equal); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Number pad commands DigitZeroCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Zero); UpdateMainProperties(); }); DigitOneCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.One); UpdateMainProperties(); }); DigitTwoCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Two); UpdateMainProperties(); }); DigitThreeCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Three); UpdateMainProperties(); }); DigitFourCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Four); UpdateMainProperties(); }); DigitFiveCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Five); UpdateMainProperties(); }); DigitSixCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Six); UpdateMainProperties(); }); DigitSevenCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Seven); UpdateMainProperties(); }); DigitEightCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Eight); UpdateMainProperties(); }); DigitNineCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Nine); UpdateMainProperties(); }); InvertNumberCommand = new RelayCommand(() => { numberFormation.InvertNumber(); UpdateMainProperties(); }); CommaCommand = new RelayCommand(() => { numberFormation.AddComma(); UpdateMainProperties(); }); #endregion #endregion }
/// <summary> /// Default constructor /// </summary> public StandardCalculatorViewModel() { #region Initialization currentData = new CurrentData(); buttonsState = new ButtonsState(); clearData = new ClearData(currentData, buttonsState); numberFormation = new NumberFormation(currentData, buttonsState, clearData); expressionFormation = new ExpressionFormation(currentData, buttonsState, clearData); memory = new Memory(); #endregion #region Create commands #region Commands for memory operations MemoryClearCommand = new RelayParameterizedCommand((obj) => { memory.MemoryClear(); }, (obj) => MemoryBtnLockCondition()); MemoryReadCommand = new RelayParameterizedCommand((obj) => { if (buttonsState.EqualBtnPressed) { clearData.ClearAll(); } else if (buttonsState.AdditionalOperationBtnPressed) { currentData.CurrentExpression = clearData.ClearLastAdditionalOperation(currentData.CurrentExpression); buttonsState.AdditionalOperationBtnPressed_Change(false); } currentData.CurrentNumber = memory.CurrentValue.ToString(); buttonsState.NumberPadBtnPressed_Change(true); UpdateMainProperties(); }, (obj) => MemoryBtnLockCondition()); MemoryPlusCommand = new RelayParameterizedCommand((obj) => { memory.MemoryPlus(CurrentNumber); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MemoryMinusCommand = new RelayParameterizedCommand((obj) => { memory.MemoryMinus(CurrentNumber); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MemorySaveCommand = new RelayParameterizedCommand((obj) => { memory.MemorySave(CurrentNumber); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MemoryStorageCommand = new RelayParameterizedCommand((obj) => { System.Windows.MessageBox.Show(memory.CurrentValue.ToString()); }, (obj) => MemoryBtnLockCondition()); #endregion #region Commands for clearing data ClearCommand = new RelayCommand(() => { clearData.ClearAll(); UpdateMainProperties(); }); ClearEntryCommand = new RelayCommand(() => { clearData.ClearEntry(); UpdateMainProperties(); }); BackspaceCommand = new RelayCommand(() => { clearData.Backspace(); UpdateMainProperties(); }); #endregion #region Commands for additional operations FindPercentageCommand = new RelayParameterizedCommand((obj) => { expressionFormation.FindPercentage(); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); PartOfTheWholeCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetAdditionalOperation(AdditionalOperations.PartOfTheWhole); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SqrCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetAdditionalOperation(AdditionalOperations.Exponentiation); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SqrtCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetAdditionalOperation(AdditionalOperations.RootExtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Commands for basic math operations AdditionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Addition); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); SubtractionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Subtraction); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); MultiplyCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Multiplication); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); DivisionCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Division); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); EqualCommand = new RelayParameterizedCommand((obj) => { expressionFormation.SetBasicMathOperation(BasicMathOperations.Equal); UpdateMainProperties(); }, (obj) => NumberStandardization.NumberCheck(currentData.CurrentNumber)); #endregion #region Number pad commands DigitZeroCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Zero); UpdateMainProperties(); }); DigitOneCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.One); UpdateMainProperties(); }); DigitTwoCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Two); UpdateMainProperties(); }); DigitThreeCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Three); UpdateMainProperties(); }); DigitFourCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Four); UpdateMainProperties(); }); DigitFiveCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Five); UpdateMainProperties(); }); DigitSixCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Six); UpdateMainProperties(); }); DigitSevenCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Seven); UpdateMainProperties(); }); DigitEightCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Eight); UpdateMainProperties(); }); DigitNineCommand = new RelayCommand(() => { numberFormation.AddDigit(Digits.Nine); UpdateMainProperties(); }); InvertNumberCommand = new RelayCommand(() => { numberFormation.InvertNumber(); UpdateMainProperties(); }); CommaCommand = new RelayCommand(() => { numberFormation.AddComma(); UpdateMainProperties(); }); #endregion #endregion }