CalculatorViewModel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using Captcha.Views;
  3. using System.Collections.Generic;
  4. using ReactiveUI;
  5. using Tmds.DBus.Protocol;
  6. namespace Captcha.ViewModels
  7. {
  8. public class CalculatorViewModel : ReactiveObject
  9. {
  10. string valueselect = "";
  11. double first = 0;
  12. double second = 0;
  13. double result = 0;
  14. string plus = "+";
  15. string minus = "-";
  16. string pow = "*";
  17. string del = "/";
  18. public List<string> Arifmetica
  19. {
  20. get => Models.ArifmClass.Do;
  21. }
  22. public double FirstCount
  23. {
  24. get => first;
  25. set
  26. {
  27. this.RaiseAndSetIfChanged(ref first, value);
  28. }
  29. }
  30. public double SecondCount
  31. {
  32. get => second;
  33. set
  34. {
  35. this.RaiseAndSetIfChanged(ref second, value);
  36. }
  37. }
  38. public void Process()
  39. {
  40. if(Does == plus)
  41. {
  42. result = FirstCount + SecondCount;
  43. Result++;
  44. Result--;
  45. }
  46. else if (Does == minus)
  47. {
  48. result = FirstCount - SecondCount;
  49. Result++;
  50. Result--;
  51. }
  52. else if (Does == pow)
  53. {
  54. result = FirstCount * SecondCount;
  55. Result++;
  56. Result--;
  57. }
  58. else if (Does == del)
  59. {
  60. result = FirstCount / SecondCount;
  61. Result++;
  62. Result--;
  63. }
  64. }
  65. public double Result
  66. {
  67. get => result;
  68. set
  69. {
  70. this.RaiseAndSetIfChanged(ref result, value);
  71. }
  72. }
  73. public string Does
  74. {
  75. get => valueselect;
  76. set
  77. {
  78. if (value == "Сумма")
  79. {
  80. this.RaiseAndSetIfChanged(ref valueselect, plus);
  81. }
  82. else if (value == "Разность")
  83. {
  84. this.RaiseAndSetIfChanged(ref valueselect, minus);
  85. }
  86. else if (value == "Умножение")
  87. {
  88. this.RaiseAndSetIfChanged(ref valueselect, pow);
  89. }
  90. else if (value == "Деление")
  91. {
  92. this.RaiseAndSetIfChanged(ref valueselect, del);
  93. }
  94. }
  95. }
  96. }
  97. }