CalculatorViewModel.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using ReactiveUI;
  4. using Tmds.DBus.Protocol;
  5. namespace AuthAndCaptcha.ViewModels
  6. {
  7. public class CalculatorViewModel : ReactiveObject
  8. {
  9. public static List<string> calcOptions => new List<string>() {"Ñëîæåíèå", "Âû÷èòàíèå", "Óìíîæåíèå", "Äåëåíèå"};
  10. string selectedOption = calcOptions[0];
  11. public string SelectedOption { get => selectedOption; set { this.RaiseAndSetIfChanged(ref selectedOption, value); ChangeSign(); } }
  12. char sign = '+';
  13. public char Sign { get => sign; set => this.RaiseAndSetIfChanged(ref sign, value); }
  14. int n, m, result;
  15. public int N { get => n; set => n = value; }
  16. public int M { get => m; set => m = value; }
  17. public int Result { get => result; set => this.RaiseAndSetIfChanged(ref result, value); }
  18. public void ChangeSign()
  19. {
  20. if (SelectedOption == "Ñëîæåíèå") Sign = '+';
  21. else if (SelectedOption == "Âû÷èòàíèå") Sign = '-';
  22. else if (SelectedOption == "Óìíîæåíèå") Sign = '*';
  23. else if (SelectedOption == "Äåëåíèå") Sign = '/';
  24. }
  25. public void Calculation()
  26. {
  27. if (SelectedOption == "Ñëîæåíèå") Result = N + M;
  28. else if (SelectedOption == "Âû÷èòàíèå") Result = N - M;
  29. else if (SelectedOption == "Óìíîæåíèå") Result = N * M;
  30. else if (SelectedOption == "Äåëåíèå") Result = N / M;
  31. }
  32. }
  33. }