From d5f0b2a53214a9a015b511753f947b7ce2373b84 Mon Sep 17 00:00:00 2001 From: RomanKamen Date: Wed, 29 Apr 2026 16:03:47 +0500 Subject: [PATCH] Fixes --- Labaratory/Labaratory/App.config | 2 +- Labaratory/Labaratory/Labaratory.csproj | 4 + .../Labaratory/Models/Model11.Designer.cs | 2 +- .../Labaratory/Services/DelegateCommand.cs | 29 ++++++ .../Services/InverseBoolToVisConverter.cs | 18 ++++ .../Services/InverseBooleanConverter.cs | 16 ++++ .../Services/NullToVisibilityConverter.cs | 18 ++++ .../Labaratory/ViewModels/AdminModel.cs | 4 +- .../Labaratory/ViewModels/ByhalterModel.cs | 6 +- .../Labaratory/ViewModels/LaborantExplorer.cs | 81 ++++++++++++++++- .../Labaratory/Views/ByhalterWindow.xaml | 11 +-- .../Labaratory/Views/LaborantExplorer.xaml | 91 +++++++++++++++++-- 12 files changed, 257 insertions(+), 25 deletions(-) create mode 100644 Labaratory/Labaratory/Services/DelegateCommand.cs create mode 100644 Labaratory/Labaratory/Services/InverseBoolToVisConverter.cs create mode 100644 Labaratory/Labaratory/Services/InverseBooleanConverter.cs create mode 100644 Labaratory/Labaratory/Services/NullToVisibilityConverter.cs diff --git a/Labaratory/Labaratory/App.config b/Labaratory/Labaratory/App.config index 27e1bcc..be561b4 100644 --- a/Labaratory/Labaratory/App.config +++ b/Labaratory/Labaratory/App.config @@ -13,6 +13,6 @@ - + \ No newline at end of file diff --git a/Labaratory/Labaratory/Labaratory.csproj b/Labaratory/Labaratory/Labaratory.csproj index 7a41978..f816495 100644 --- a/Labaratory/Labaratory/Labaratory.csproj +++ b/Labaratory/Labaratory/Labaratory.csproj @@ -156,6 +156,10 @@ Model1.tt + + + + diff --git a/Labaratory/Labaratory/Models/Model11.Designer.cs b/Labaratory/Labaratory/Models/Model11.Designer.cs index 0e84e9f..e4d3226 100644 --- a/Labaratory/Labaratory/Models/Model11.Designer.cs +++ b/Labaratory/Labaratory/Models/Model11.Designer.cs @@ -1,4 +1,4 @@ -// Создание кода T4 для модели "D:\Projects\TASK3UP01\Labaratory\Labaratory\Models\Model1.edmx" включено. +// Создание кода T4 для модели "C:\Users\student1\Source\Repos\UP01TASK3\Labaratory\Labaratory\Models\Model1.edmx" включено. // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель // открыта в конструкторе. diff --git a/Labaratory/Labaratory/Services/DelegateCommand.cs b/Labaratory/Labaratory/Services/DelegateCommand.cs new file mode 100644 index 0000000..a665df9 --- /dev/null +++ b/Labaratory/Labaratory/Services/DelegateCommand.cs @@ -0,0 +1,29 @@ +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/Services/InverseBoolToVisConverter.cs b/Labaratory/Labaratory/Services/InverseBoolToVisConverter.cs new file mode 100644 index 0000000..501794c --- /dev/null +++ b/Labaratory/Labaratory/Services/InverseBoolToVisConverter.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows; + +namespace Labaratory.Services +{ + public class InverseBoolToVisConverter : IValueConverter + { + public object Convert(object v, Type t, object p, CultureInfo c) => + (bool)v ? Visibility.Collapsed : Visibility.Visible; + public object ConvertBack(object v, Type t, object p, CultureInfo c) => throw new NotImplementedException(); + } +} diff --git a/Labaratory/Labaratory/Services/InverseBooleanConverter.cs b/Labaratory/Labaratory/Services/InverseBooleanConverter.cs new file mode 100644 index 0000000..532a903 --- /dev/null +++ b/Labaratory/Labaratory/Services/InverseBooleanConverter.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Labaratory.Services +{ + public class InverseBooleanConverter : IValueConverter + { + public object Convert(object v, Type t, object p, CultureInfo c) => !(bool)v; + public object ConvertBack(object v, Type t, object p, CultureInfo c) => !(bool)v; + } +} diff --git a/Labaratory/Labaratory/Services/NullToVisibilityConverter.cs b/Labaratory/Labaratory/Services/NullToVisibilityConverter.cs new file mode 100644 index 0000000..826531f --- /dev/null +++ b/Labaratory/Labaratory/Services/NullToVisibilityConverter.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows; + +namespace Labaratory.Services +{ + public class NullToVisibilityConverter : IValueConverter + { + public object Convert(object v, Type t, object p, CultureInfo c) => + (v == null || string.IsNullOrEmpty(v.ToString())) ? Visibility.Collapsed : Visibility.Visible; + public object ConvertBack(object v, Type t, object p, CultureInfo c) => throw new NotImplementedException(); + } +} diff --git a/Labaratory/Labaratory/ViewModels/AdminModel.cs b/Labaratory/Labaratory/ViewModels/AdminModel.cs index 8b073df..9682ca7 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 RelayCommand(obj => AuthService.UpdatePhoto("Admin.png")); + _updatePhotoCommand = new Services.RelayCommand(obj => AuthService.UpdatePhoto("Admin.png")); return _updatePhotoCommand; } } @@ -97,7 +97,7 @@ namespace Labaratory.ViewModels { if (_saveUserCommand == null) { - _saveUserCommand = new RelayCommand(obj => SaveUser()); + _saveUserCommand = new Services.RelayCommand(obj => SaveUser()); } return _saveUserCommand; } diff --git a/Labaratory/Labaratory/ViewModels/ByhalterModel.cs b/Labaratory/Labaratory/ViewModels/ByhalterModel.cs index 4ba81fe..4f455f9 100644 --- a/Labaratory/Labaratory/ViewModels/ByhalterModel.cs +++ b/Labaratory/Labaratory/ViewModels/ByhalterModel.cs @@ -4,7 +4,7 @@ using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Input; -using System.Data.Entity; // Для .Include() в старых версиях EF +using System.Data.Entity; using Wpf.Ui.Input; namespace Labaratory.ViewModels @@ -45,7 +45,7 @@ namespace Labaratory.ViewModels public ByhalterModel(Models.User user) { CurrentUser = user; - _db = new LaboratoryDBEntities(); // Используем ваш контекст + _db = new LaboratoryDBEntities(); LoadInitialData(); @@ -63,7 +63,7 @@ namespace Labaratory.ViewModels private void GenerateRevenueReport() { var data = _db.Rendered_Services - .Include(s => s.OrderItem) + .Include(s => s.Order_Items) .OrderByDescending(s => s.ExecutionDate) .ToList(); diff --git a/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs b/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs index b43db61..ec4af95 100644 --- a/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs +++ b/Labaratory/Labaratory/ViewModels/LaborantExplorer.cs @@ -1,18 +1,93 @@ using System; -using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; -using System.Text; using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; +using Labaratory.Models; +using Labaratory.Services; namespace Labaratory.ViewModels { public class LaborantExplorer : BaseViewModel { + private LaboratoryDBEntities _db = new LaboratoryDBEntities(); // Ваш контекст Entity Framework + private Analyzer _selectedAnalyzer; + public Models.User CurrentUser { get; set; } + // Список доступных анализаторов + public ObservableCollection Analyzers { get; set; } + + // Список услуг для выбранного анализатора + public ObservableCollection PendingServices { get; set; } + + public Analyzer SelectedAnalyzer + { + get => _selectedAnalyzer; + set + { + _selectedAnalyzer = value; + OnPropertyChanged(); + LoadServices(); // Загружаем услуги при выборе прибора + } + } + public LaborantExplorer(Models.User user) { CurrentUser = user; + LoadInitialData(); } + + private void LoadInitialData() + { + // Загрузка анализаторов из БД + Analyzers = new ObservableCollection(_db.Analyzers.ToList()); + } + + private void LoadServices() + { + var services = _db.Services.ToList(); + + PendingServices = new ObservableCollection(services); + OnPropertyChanged(nameof(PendingServices)); + } + + public ICommand SendToResearchCommand => new DelegateCommand(async (service) => + { + if (SelectedAnalyzer.IsBusy) + { + MessageBox.Show("Анализатор занят!"); + return; + } + + 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; + }); + }); } -} +} \ No newline at end of file diff --git a/Labaratory/Labaratory/Views/ByhalterWindow.xaml b/Labaratory/Labaratory/Views/ByhalterWindow.xaml index 85d55ce..1f08c94 100644 --- a/Labaratory/Labaratory/Views/ByhalterWindow.xaml +++ b/Labaratory/Labaratory/Views/ByhalterWindow.xaml @@ -1,4 +1,4 @@ - - + @@ -66,13 +66,6 @@ - - - - - - - diff --git a/Labaratory/Labaratory/Views/LaborantExplorer.xaml b/Labaratory/Labaratory/Views/LaborantExplorer.xaml index c4f35c2..681586e 100644 --- a/Labaratory/Labaratory/Views/LaborantExplorer.xaml +++ b/Labaratory/Labaratory/Views/LaborantExplorer.xaml @@ -1,12 +1,91 @@  + xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:services="clr-namespace:Labaratory.Services" + Title="Рабочее бугхалтера" Height="700" Width="900" + Background="{ui:ThemeResource ApplicationBackgroundBrush}" + Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}"> + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +