From 2bb648a137c2cab3ebff2ded89ead6bd4ce7fbbb Mon Sep 17 00:00:00 2001 From: RomanKamen Date: Wed, 29 Apr 2026 17:19:25 +0500 Subject: [PATCH] Final --- Labaratory/Labaratory/Labaratory.csproj | 1 - .../Labaratory/Services/DelegateCommand.cs | 29 ---- .../Labaratory/ViewModels/AdminModel.cs | 4 +- .../Labaratory/ViewModels/LaborantExplorer.cs | 91 ++++-------- .../Labaratory/Views/LaborantExplorer.xaml | 135 ++++++++++-------- 5 files changed, 101 insertions(+), 159 deletions(-) delete mode 100644 Labaratory/Labaratory/Services/DelegateCommand.cs diff --git a/Labaratory/Labaratory/Labaratory.csproj b/Labaratory/Labaratory/Labaratory.csproj index f816495..ae928e7 100644 --- a/Labaratory/Labaratory/Labaratory.csproj +++ b/Labaratory/Labaratory/Labaratory.csproj @@ -156,7 +156,6 @@ Model1.tt - diff --git a/Labaratory/Labaratory/Services/DelegateCommand.cs b/Labaratory/Labaratory/Services/DelegateCommand.cs deleted file mode 100644 index a665df9..0000000 --- a/Labaratory/Labaratory/Services/DelegateCommand.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Input; - -namespace Labaratory.Services -{ - public class RelayCommand : ICommand - { - private readonly Action _execute; - private readonly Predicate _canExecute; - - public RelayCommand(Action execute, Predicate canExecute = null) - { - _execute = execute ?? throw new ArgumentNullException(nameof(execute)); - _canExecute = canExecute; - } - - public bool CanExecute(object parameter) => _canExecute == null || _canExecute((T)parameter); - public void Execute(object parameter) => _execute((T)parameter); - public event EventHandler CanExecuteChanged - { - add => CommandManager.RequerySuggested += value; - remove => CommandManager.RequerySuggested -= value; - } - } -} diff --git a/Labaratory/Labaratory/ViewModels/AdminModel.cs b/Labaratory/Labaratory/ViewModels/AdminModel.cs index 9682ca7..8b073df 100644 --- a/Labaratory/Labaratory/ViewModels/AdminModel.cs +++ b/Labaratory/Labaratory/ViewModels/AdminModel.cs @@ -48,7 +48,7 @@ namespace Labaratory.ViewModels get { if (_updatePhotoCommand == null) - _updatePhotoCommand = new Services.RelayCommand(obj => AuthService.UpdatePhoto("Admin.png")); + _updatePhotoCommand = new RelayCommand(obj => AuthService.UpdatePhoto("Admin.png")); return _updatePhotoCommand; } } @@ -97,7 +97,7 @@ namespace Labaratory.ViewModels { if (_saveUserCommand == null) { - _saveUserCommand = new Services.RelayCommand(obj => SaveUser()); + _saveUserCommand = new RelayCommand(obj => SaveUser()); } return _saveUserCommand; } diff --git a/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs b/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs index ec4af95..41ab9d3 100644 --- a/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs +++ b/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs @@ -2,92 +2,53 @@ using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; -using System.Windows; using System.Windows.Input; using Labaratory.Models; using Labaratory.Services; +using Wpf.Ui.Input; namespace Labaratory.ViewModels { public class LaborantExplorer : BaseViewModel { - private LaboratoryDBEntities _db = new LaboratoryDBEntities(); // Ваш контекст Entity Framework - private Analyzer _selectedAnalyzer; - - public Models.User CurrentUser { get; set; } - - // Список доступных анализаторов + private LaboratoryDBEntities _db = new LaboratoryDBEntities(); + public ObservableCollection Services { get; set; } public ObservableCollection Analyzers { get; set; } - // Список услуг для выбранного анализатора - public ObservableCollection PendingServices { get; set; } + // Свойства для привязки выбора + public Service SelectedService { get; set; } + public Analyzer SelectedAnalyzer { get; set; } - public Analyzer SelectedAnalyzer - { - get => _selectedAnalyzer; - set - { - _selectedAnalyzer = value; - OnPropertyChanged(); - LoadServices(); // Загружаем услуги при выборе прибора - } - } + // Свойства для прогресса + private double _progress; + public double Progress { get => _progress; set { _progress = value; OnPropertyChanged(); } } - public LaborantExplorer(Models.User user) - { - CurrentUser = user; - LoadInitialData(); - } + private bool _isBusy; + public bool IsBusy { get => _isBusy; set { _isBusy = value; OnPropertyChanged(); } } - private void LoadInitialData() + public LaborantExplorer(User user) { - // Загрузка анализаторов из БД + Services = new ObservableCollection(_db.Services.ToList()); Analyzers = new ObservableCollection(_db.Analyzers.ToList()); + + StartCommand = new RelayCommand(async (p) => await RunTimer()); } - private void LoadServices() - { - var services = _db.Services.ToList(); + public ICommand StartCommand { get; } - PendingServices = new ObservableCollection(services); - OnPropertyChanged(nameof(PendingServices)); - } - - public ICommand SendToResearchCommand => new DelegateCommand(async (service) => + private async Task RunTimer() { - if (SelectedAnalyzer.IsBusy) + if (SelectedService == null || SelectedAnalyzer == null || IsBusy) return; + + IsBusy = true; + for (int i = 0; i <= 100; i++) { - MessageBox.Show("Анализатор занят!"); - return; + Progress = i; + await Task.Delay(600); } + IsBusy = false; - service.IsProcessing = true; - SelectedAnalyzer.IsBusy = true; - - await Task.Run(async () => - { - Random rng = new Random(); - for (int i = 0; i <= 100; i += 10) - { - service.Progress = i; - await Task.Delay(500); - } - - // Имитация получения результата - double resultValue = rng.NextDouble() * 100; - service.ResultValue = resultValue.ToString("F2"); - - // Логика проверки на сбой (отклонение в 3 раза от среднего) - double average = 20.0; // В реальности берем из БД - if (resultValue > average * 3 || resultValue < average / 3) - { - Application.Current.Dispatcher.Invoke(() => - MessageBox.Show("Внимание: возможен сбой или некачественный биоматериал!")); - } - - service.IsProcessing = false; - SelectedAnalyzer.IsBusy = false; - }); - }); + System.Windows.MessageBox.Show("Готово!"); + } } } \ No newline at end of file diff --git a/Labaratory/Labaratory/Views/LaborantExplorer.xaml b/Labaratory/Labaratory/Views/LaborantExplorer.xaml index 681586e..5eacfbe 100644 --- a/Labaratory/Labaratory/Views/LaborantExplorer.xaml +++ b/Labaratory/Labaratory/Views/LaborantExplorer.xaml @@ -13,6 +13,25 @@ + + + + + + + + + + + + + + + + + @@ -20,70 +39,62 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + +