CalcVM.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using Auth.Models;
  2. using Avalonia.Media;
  3. using Avalonia.Styling;
  4. using ReactiveUI;
  5. using System;
  6. using System.Drawing;
  7. using System.Security.Cryptography.X509Certificates;
  8. using Avalonia.Controls;
  9. using Avalonia.Controls.Shapes;
  10. using System.Linq;
  11. using Avalonia.Threading;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using Avalonia.Input;
  15. using System.Windows.Input;
  16. namespace Auth.ViewModels
  17. {
  18. public class CalcVM : ReactiveObject
  19. {
  20. public float? chislo1;
  21. public float? chislo2;
  22. public string result = "";
  23. public static List<string> _operation = Models.data.Operation;
  24. private string _selectedOperation = _operation[0];
  25. public string znaki = "+";
  26. public List<String> Operation
  27. {
  28. get
  29. {
  30. return _operation;
  31. }
  32. }
  33. public string Znaki
  34. {
  35. get
  36. {
  37. return znaki;
  38. }
  39. set
  40. {
  41. this.RaiseAndSetIfChanged(ref znaki, value);
  42. }
  43. }
  44. public string SelectedOperation
  45. {
  46. get => _selectedOperation;
  47. set
  48. {
  49. this.RaiseAndSetIfChanged(ref _selectedOperation, value);
  50. if (SelectedOperation == _operation[0])
  51. {
  52. Znaki = "+";
  53. }
  54. else if (SelectedOperation == _operation[1])
  55. {
  56. Znaki = "-";
  57. }
  58. else if (SelectedOperation == _operation[2])
  59. {
  60. Znaki = "*";
  61. }
  62. else if (SelectedOperation == _operation[3])
  63. {
  64. Znaki = "/";
  65. }
  66. }
  67. }
  68. public void Resultat()
  69. {
  70. switch (SelectedOperation)
  71. {
  72. case "Сложение":
  73. Result = (Chislo1 + Chislo2).ToString();
  74. break;
  75. case "Вычитание":
  76. Result = (Chislo1 - Chislo2).ToString();
  77. break;
  78. case "Умножение":
  79. Result = (Chislo1 * Chislo2).ToString();
  80. break;
  81. case "Деление":
  82. Result = Chislo2 != 0 ? (Chislo1 / Chislo2).ToString() : float.NaN.ToString();
  83. break;
  84. }
  85. }
  86. public string Result
  87. {
  88. get
  89. {
  90. return result;
  91. }
  92. set
  93. {
  94. this.RaiseAndSetIfChanged(ref result, value);
  95. }
  96. }
  97. public float? Chislo1
  98. {
  99. get => chislo1;
  100. set
  101. {
  102. this.RaiseAndSetIfChanged(ref chislo1, value);
  103. }
  104. }
  105. public float? Chislo2
  106. {
  107. get => chislo2;
  108. set
  109. {
  110. this.RaiseAndSetIfChanged(ref chislo2, value);
  111. }
  112. }
  113. }
  114. }