123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using Avalonia.Controls;
- using Avalonia.Platform.Storage;
- using CommunityToolkit.Mvvm.ComponentModel;
- using CommunityToolkit.Mvvm.Input;
- using EntranseTesting.Models;
- using MsBox.Avalonia;
- using MsBox.Avalonia.Enums;
- using ReactiveUI;
- namespace EntranseTesting.ViewModels
- {
- public partial class EditorPageViewModel : ObservableObject
- {
- [ObservableProperty] private UserControl editorUC = new TestSettings();
- [ObservableProperty] private TestSettingsViewModel settingsApp;
- [ObservableProperty] private TaskEditorViewModel taskEditorPage;
- [ObservableProperty] private ResultMainViewModel results;
- [ObservableProperty] private TaskMainViewModel taskMainPage;
- [ObservableProperty] bool enabledSettings = false;
- [ObservableProperty] bool enabledTaskMain = true;
- [ObservableProperty] bool enabledResults = true;
- [ObservableProperty] private bool _editingVisible = false;
- public EditorPageViewModel(bool Editor)
- {
- SettingsApp = new TestSettingsViewModel();
- if (Editor) ClickToTaskMain();
- }
- [RelayCommand]
- private void ClickToSettings()
- {
- EnabledSettings = false;
- EnabledTaskMain = true;
- EnabledResults = true;
- EditingVisible = false;
- if(Results != null)Results.Timer.Stop();
- SettingsApp = new TestSettingsViewModel();
- EditorUC = new TestSettings();
- }
- [RelayCommand]
- private void ClickToTaskMain()
- {
- EnabledTaskMain = false;
- EnabledSettings = true;
- EnabledResults = true;
- EditingVisible = true;
- if (Results != null) Results.Timer.Stop();
- TaskMainPage = new TaskMainViewModel();
- EditorUC = new TaskMain();
- }
- [RelayCommand]
- private void ClickToUserResults()
- {
- EnabledTaskMain = true;
- EnabledSettings = true;
- EnabledResults = false;
- EditingVisible = false;
- Results = new ResultMainViewModel();
- EditorUC = new ResultMain();
- }
- [RelayCommand]
- private async void SaveSettings()
- {
- try
- {
- //ïðîâåðêà íà ïóñòîå íà÷åíèå
- if (SettingsApp.Settings is null)
- {
- await MessageBoxManager.GetMessageBoxStandard("", "Çíà÷åíèå îêàçàëîñü ïóñòûì", ButtonEnum.Ok).ShowAsync();
- return;
- }
-
- string mess = checkSetting();
- if(mess != "")
- {
- var resultat = await MessageBoxManager.GetMessageBoxStandard("", mess, ButtonEnum.OkCancel).ShowAsync();
- switch (resultat)
- {
- case ButtonResult.Ok:
- break;
- case ButtonResult.Cancel:
- return;
- }
- }
- //ñîõðàíÿåì â áàçå
- EntranceTestingContext baseConnection = new EntranceTestingContext();
- baseConnection.AppSettings.Add(SettingsApp.Settings);
- baseConnection.SaveChanges();
- await MessageBoxManager.GetMessageBoxStandard("", "Òåêóùèå íàñòðîéêè òåñòà ñîõðàíåíû", ButtonEnum.Ok).ShowAsync();
- SettingsApp = new TestSettingsViewModel();
- #if DEBUG
- Debug.WriteLine("Äàííûå î íàñòðîéêàõ òåñòà óñïåøíî ñîõðàíåíû");
- #endif
- }
- catch (Exception ex)
- {
- await MessageBoxManager.GetMessageBoxStandard("", "Ïî êàêîé-òî ïðè÷èíå íå óäàëîñü ñîõðàíèòü äàííûå", ButtonEnum.Ok).ShowAsync();
- #if DEBUG
- Debug.WriteLine(ex.Message);
- #endif
- }
- }
- private string checkSetting()
- {
- string mess = "";
- string erMess = "";
- AppSetting _set = SettingsApp.Settings;
- _set.Id = 0;
- _set.DateOfChanging = DateTime.Now;
- //íàñòðîéêà ïîäñêàçîê
- if (!_set.HintVisibility)
- {
- _set.CountOfHints = 0;
- }
- else if (_set.CountOfHints == 0)
- {
- mess += "Âû âêëþ÷èëè ôóíêöèþ ïîäñêàçîê, íî êîëè÷åñòâî ïîäñêàçîê = 0. Ïîýòîìó ôóíêöèÿ ïîäñêàçîê îòêëþ÷åíà\n";
- _set.HintVisibility = false;
- }
-
- //íàñòðîéêà îöåíèâàíèÿ
- if(_set.Raiting5 > _set.CountOfQuestions)
- {
- _set.Raiting5 = _set.CountOfQuestions;
- mess += "Êðèòåðèè îöåíèâàíèÿ äëÿ îöåíêè 5 èçìåíåíû, òàê êàê êîëè÷åñòâî âîïðîñîâ áûëî ìåíüøå ÷åì êîëè÷åñòâî òðåáóåìûõ áàëëîâ\n";
- }
- if (_set.Raiting4 >= _set.Raiting5)
- {
- _set.Raiting4 = _set.Raiting5 - 1;
- mess += "Êðèòåðèè îöåíèâàíèÿ äëÿ îöåíêè 4 èçìåíåíû, òàê êàê êîëè÷åñòâî áàëëîâ áîëüøå ÷åì äëÿ îöåíêè 5\n";
- }
- if (_set.Raiting3 >= _set.Raiting4)
- {
- _set.Raiting3 = _set.Raiting4 - 1;
- mess += "Êðèòåðèè îöåíèâàíèÿ äëÿ îöåíêè 3 èçìåíåíû, òàê êàê êîëè÷åñòâî áàëëîâ áîëüøå ÷åì äëÿ îöåíêè 4\n";
- }
- //ïðîâåðêà âðåìåíè äëÿ ïðîõîæäåíèÿ çàäàíèÿ
- if(_set.Time < new TimeSpan(0,0,45) * _set.CountOfQuestions)
- {
- erMess += "Âðåìåíè, êîòîðîå âûäåëåííî íà ïðîõîæäåíèå äàííîãî òåñòà ìîæåò íå õâàòèòü.\nÐåêóìåíäóåìîå âðåìÿ: " + (new TimeSpan(0, 0, 45) * _set.CountOfQuestions) + " (45 ñåêóíä íà çàäàíèå)";
- }
- SettingsApp.Settings = _set;
-
- mess = (mess == "") ? mess : "\tÈíôîðìàöèÿ îá èçìåíåíèÿõ*\n" + mess;
- erMess = (erMess == "") ? erMess : "\n\tÑïðàâî÷íàÿ èíôîðìàöèÿ\n" + erMess;
- return mess + erMess;
- }
- }
- }
|