CalculatorViewModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using Avalonia.Controls;
  2. using avaloniaPr.Models;
  3. using ReactiveUI;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace avaloniaPr.ViewModels
  10. {
  11. public class CalculatorViewModel : ViewModelBase
  12. {
  13. string textCalculator = "Выберите арифметическую операцию:";
  14. string textButton = "Вычислить";
  15. string selectItem = "";
  16. double result;
  17. double oneNum;
  18. double twoNum;
  19. public string TextCalculator
  20. {
  21. get => textCalculator;
  22. set => this.RaiseAndSetIfChanged(ref textCalculator, value);
  23. }
  24. public string TextButton
  25. {
  26. get => textButton;
  27. set => this.RaiseAndSetIfChanged(ref textButton, value);
  28. }
  29. public List<string> ListItem
  30. {
  31. get => Models.ItemsOperation.Items;
  32. }
  33. public string SV
  34. {
  35. get => selectItem;
  36. set
  37. {
  38. if (value == "Сумма")
  39. {
  40. this.RaiseAndSetIfChanged(ref selectItem, "+");
  41. }
  42. else if (value == "Разность")
  43. {
  44. this.RaiseAndSetIfChanged(ref selectItem, "-");
  45. }
  46. else if (value == "Умножение")
  47. {
  48. this.RaiseAndSetIfChanged(ref selectItem, "*");
  49. }
  50. else if (value == "Деление")
  51. {
  52. this.RaiseAndSetIfChanged(ref selectItem, "/");
  53. }
  54. }
  55. }
  56. public double OneNum
  57. {
  58. get => oneNum;
  59. set
  60. {
  61. this.RaiseAndSetIfChanged(ref oneNum, value);
  62. }
  63. }
  64. public double TwoNum
  65. {
  66. get => twoNum;
  67. set
  68. {
  69. this.RaiseAndSetIfChanged(ref twoNum, value);
  70. }
  71. }
  72. public void CommandCalculator()
  73. {
  74. switch (SV)
  75. {
  76. case "+":
  77. {
  78. result = OneNum + TwoNum;
  79. Result++;
  80. Result--;
  81. }
  82. break;
  83. case "-":
  84. {
  85. result = OneNum - TwoNum;
  86. Result++;
  87. Result--;
  88. }
  89. break;
  90. case "*":
  91. {
  92. result = OneNum * TwoNum;
  93. Result++;
  94. Result--;
  95. }
  96. break;
  97. case "/":
  98. {
  99. result = OneNum / TwoNum;
  100. Result++;
  101. Result--;
  102. }
  103. break;
  104. }
  105. }
  106. public double Result
  107. {
  108. get => result;
  109. set
  110. {
  111. this.RaiseAndSetIfChanged(ref result, value);
  112. }
  113. }
  114. }
  115. }