CululViewModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using Culusas.Models;
  2. using ReactiveUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Culusas.ViewModels
  9. {
  10. public class CululViewModel : ReactiveObject
  11. {
  12. public double result;
  13. public string prover = "";
  14. public string oper = "0000";
  15. public int indexA = -1;
  16. public List<string> deistV => PiusMinusITD.Deistvia;
  17. public double InitA
  18. {
  19. get => PiusMinusITD.a;
  20. set
  21. {
  22. this.RaiseAndSetIfChanged(ref PiusMinusITD.a, value);
  23. }
  24. }
  25. public double InitB
  26. {
  27. get => PiusMinusITD.b;
  28. set
  29. {
  30. this.RaiseAndSetIfChanged(ref PiusMinusITD.b, value);
  31. }
  32. }
  33. public double Resultat
  34. {
  35. get => result;
  36. set
  37. {
  38. this.RaiseAndSetIfChanged(ref result, value);
  39. }
  40. }
  41. public string Provertik
  42. {
  43. get => prover;
  44. set
  45. {
  46. this.RaiseAndSetIfChanged(ref prover, value);
  47. }
  48. }
  49. public string Operator
  50. {
  51. get => oper;
  52. set
  53. {
  54. this.RaiseAndSetIfChanged(ref oper, value);
  55. }
  56. }
  57. public int Index
  58. {
  59. get => indexA;
  60. set
  61. {
  62. this.RaiseAndSetIfChanged(ref indexA, value);
  63. switch (indexA)
  64. {
  65. case 0:
  66. Operator = "+";
  67. break;
  68. case 1:
  69. Operator = "-";
  70. break;
  71. case 2:
  72. Operator = "*";
  73. break;
  74. case 3:
  75. Operator = "/";
  76. break;
  77. default:
  78. Operator = "!";
  79. break;
  80. }
  81. }
  82. }
  83. public void DeistviaAandB()
  84. {
  85. switch (indexA)
  86. {
  87. case 0:
  88. Resultat = InitA + InitB;
  89. Provertik = Resultat.ToString();
  90. break;
  91. case 1:
  92. Resultat = InitA - InitB;
  93. Provertik = Resultat.ToString();
  94. break;
  95. case 2:
  96. Resultat = InitA * InitB;
  97. Provertik = Resultat.ToString();
  98. break;
  99. case 3:
  100. if (InitB != 0)
  101. {
  102. Resultat = InitA / InitB;
  103. Provertik = Resultat.ToString();
  104. }
  105. else
  106. Provertik = "Нельзя делить на 0!";
  107. break;
  108. default:
  109. Provertik = "Вы не заполнили поля или не выбрали действие!";
  110. break;
  111. }
  112. }
  113. }
  114. }