EditorPageViewModel.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using Avalonia.Controls;
  6. using Avalonia.Platform.Storage;
  7. using CommunityToolkit.Mvvm.ComponentModel;
  8. using CommunityToolkit.Mvvm.Input;
  9. using EntranseTesting.Models;
  10. using MsBox.Avalonia;
  11. using MsBox.Avalonia.Enums;
  12. using ReactiveUI;
  13. namespace EntranseTesting.ViewModels
  14. {
  15. public partial class EditorPageViewModel : ObservableObject
  16. {
  17. [ObservableProperty] private UserControl editorUC = new TestSettings();
  18. [ObservableProperty] private TestSettingsViewModel settingsApp;
  19. [ObservableProperty] private TaskEditorViewModel taskEditorPage;
  20. [ObservableProperty] private ResultMainViewModel results;
  21. [ObservableProperty] private TaskMainViewModel taskMainPage;
  22. [ObservableProperty] bool enabledSettings = false;
  23. [ObservableProperty] bool enabledTaskMain = true;
  24. [ObservableProperty] bool enabledResults = true;
  25. [ObservableProperty] private bool _editingVisible = false;
  26. public EditorPageViewModel(bool Editor)
  27. {
  28. SettingsApp = new TestSettingsViewModel();
  29. if (Editor) ClickToTaskMain();
  30. }
  31. [RelayCommand]
  32. private void ClickToSettings()
  33. {
  34. EnabledSettings = false;
  35. EnabledTaskMain = true;
  36. EnabledResults = true;
  37. EditingVisible = false;
  38. if(Results != null)Results.Timer.Stop();
  39. SettingsApp = new TestSettingsViewModel();
  40. EditorUC = new TestSettings();
  41. }
  42. [RelayCommand]
  43. private void ClickToTaskMain()
  44. {
  45. EnabledTaskMain = false;
  46. EnabledSettings = true;
  47. EnabledResults = true;
  48. EditingVisible = true;
  49. if (Results != null) Results.Timer.Stop();
  50. TaskMainPage = new TaskMainViewModel();
  51. EditorUC = new TaskMain();
  52. }
  53. [RelayCommand]
  54. private void ClickToUserResults()
  55. {
  56. EnabledTaskMain = true;
  57. EnabledSettings = true;
  58. EnabledResults = false;
  59. EditingVisible = false;
  60. Results = new ResultMainViewModel();
  61. EditorUC = new ResultMain();
  62. }
  63. [RelayCommand]
  64. private async void SaveSettings()
  65. {
  66. try
  67. {
  68. //ïðîâåðêà íà ïóñòîå íà÷åíèå
  69. if (SettingsApp.Settings is null)
  70. {
  71. await MessageBoxManager.GetMessageBoxStandard("", "Çíà÷åíèå îêàçàëîñü ïóñòûì", ButtonEnum.Ok).ShowAsync();
  72. return;
  73. }
  74. string mess = checkSetting();
  75. if(mess != "")
  76. {
  77. var resultat = await MessageBoxManager.GetMessageBoxStandard("", mess, ButtonEnum.OkCancel).ShowAsync();
  78. switch (resultat)
  79. {
  80. case ButtonResult.Ok:
  81. break;
  82. case ButtonResult.Cancel:
  83. return;
  84. }
  85. }
  86. //ñîõðàíÿåì â áàçå
  87. EntranceTestingContext baseConnection = new EntranceTestingContext();
  88. baseConnection.AppSettings.Add(SettingsApp.Settings);
  89. baseConnection.SaveChanges();
  90. await MessageBoxManager.GetMessageBoxStandard("", "Òåêóùèå íàñòðîéêè òåñòà ñîõðàíåíû", ButtonEnum.Ok).ShowAsync();
  91. SettingsApp = new TestSettingsViewModel();
  92. #if DEBUG
  93. Debug.WriteLine("Äàííûå î íàñòðîéêàõ òåñòà óñïåøíî ñîõðàíåíû");
  94. #endif
  95. }
  96. catch (Exception ex)
  97. {
  98. await MessageBoxManager.GetMessageBoxStandard("", "Ïî êàêîé-òî ïðè÷èíå íå óäàëîñü ñîõðàíèòü äàííûå", ButtonEnum.Ok).ShowAsync();
  99. #if DEBUG
  100. Debug.WriteLine(ex.Message);
  101. #endif
  102. }
  103. }
  104. private string checkSetting()
  105. {
  106. string mess = "";
  107. string erMess = "";
  108. AppSetting _set = SettingsApp.Settings;
  109. _set.Id = 0;
  110. _set.DateOfChanging = DateTime.Now;
  111. //íàñòðîéêà ïîäñêàçîê
  112. if (!_set.HintVisibility)
  113. {
  114. _set.CountOfHints = 0;
  115. }
  116. else if (_set.CountOfHints == 0)
  117. {
  118. mess += "Âû âêëþ÷èëè ôóíêöèþ ïîäñêàçîê, íî êîëè÷åñòâî ïîäñêàçîê = 0. Ïîýòîìó ôóíêöèÿ ïîäñêàçîê îòêëþ÷åíà\n";
  119. _set.HintVisibility = false;
  120. }
  121. //íàñòðîéêà îöåíèâàíèÿ
  122. if(_set.Raiting5 > _set.CountOfQuestions)
  123. {
  124. _set.Raiting5 = _set.CountOfQuestions;
  125. mess += "Êðèòåðèè îöåíèâàíèÿ äëÿ îöåíêè 5 èçìåíåíû, òàê êàê êîëè÷åñòâî âîïðîñîâ áûëî ìåíüøå ÷åì êîëè÷åñòâî òðåáóåìûõ áàëëîâ\n";
  126. }
  127. if (_set.Raiting4 >= _set.Raiting5)
  128. {
  129. _set.Raiting4 = _set.Raiting5 - 1;
  130. mess += "Êðèòåðèè îöåíèâàíèÿ äëÿ îöåíêè 4 èçìåíåíû, òàê êàê êîëè÷åñòâî áàëëîâ áîëüøå ÷åì äëÿ îöåíêè 5\n";
  131. }
  132. if (_set.Raiting3 >= _set.Raiting4)
  133. {
  134. _set.Raiting3 = _set.Raiting4 - 1;
  135. mess += "Êðèòåðèè îöåíèâàíèÿ äëÿ îöåíêè 3 èçìåíåíû, òàê êàê êîëè÷åñòâî áàëëîâ áîëüøå ÷åì äëÿ îöåíêè 4\n";
  136. }
  137. //ïðîâåðêà âðåìåíè äëÿ ïðîõîæäåíèÿ çàäàíèÿ
  138. if(_set.Time < new TimeSpan(0,0,45) * _set.CountOfQuestions)
  139. {
  140. erMess += "Âðåìåíè, êîòîðîå âûäåëåííî íà ïðîõîæäåíèå äàííîãî òåñòà ìîæåò íå õâàòèòü.\nÐåêóìåíäóåìîå âðåìÿ: " + (new TimeSpan(0, 0, 45) * _set.CountOfQuestions) + " (45 ñåêóíä íà çàäàíèå)";
  141. }
  142. SettingsApp.Settings = _set;
  143. mess = (mess == "") ? mess : "\tÈíôîðìàöèÿ îá èçìåíåíèÿõ*\n" + mess;
  144. erMess = (erMess == "") ? erMess : "\n\tÑïðàâî÷íàÿ èíôîðìàöèÿ\n" + erMess;
  145. return mess + erMess;
  146. }
  147. }
  148. }