From f460644572558b80f36c5a8a6f568f2e413fbcbc Mon Sep 17 00:00:00 2001 From: oreshki Date: Fri, 10 Apr 2026 16:11:16 +0500 Subject: [PATCH] Work almost done --- .../Labaratory/Models/Model1.Designer.cs | 2 +- Labaratory/Labaratory/Services/AuthService.cs | 40 ++++++++++ .../Services/StringToImageConverter.cs | 12 ++- .../Labaratory/ViewModels/AdminModel.cs | 74 ++++++++++++++++++- Labaratory/Labaratory/ViewModels/Laborant.cs | 56 ++++++++++++++ .../Labaratory/ViewModels/LoginViewModel.cs | 1 - Labaratory/Labaratory/Views/AdminWindow.xaml | 59 ++++++++++++++- .../Labaratory/Views/LaborantWindow.xaml | 11 ++- 8 files changed, 237 insertions(+), 18 deletions(-) diff --git a/Labaratory/Labaratory/Models/Model1.Designer.cs b/Labaratory/Labaratory/Models/Model1.Designer.cs index e29ec55..4cfa274 100644 --- a/Labaratory/Labaratory/Models/Model1.Designer.cs +++ b/Labaratory/Labaratory/Models/Model1.Designer.cs @@ -1,4 +1,4 @@ -// Создание кода T4 для модели "C:\Users\usersql\source\repos\UP01TASK3\Labaratory\Labaratory\Models\Model1.edmx" включено. +// Создание кода T4 для модели "C:\Users\usersql\Source\Repos\UP01TASK3\Labaratory\Labaratory\Models\Model1.edmx" включено. // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель // открыта в конструкторе. diff --git a/Labaratory/Labaratory/Services/AuthService.cs b/Labaratory/Labaratory/Services/AuthService.cs index 0ef039e..d64611f 100644 --- a/Labaratory/Labaratory/Services/AuthService.cs +++ b/Labaratory/Labaratory/Services/AuthService.cs @@ -1,6 +1,9 @@ using Labaratory.Models; +using Microsoft.Win32; using System; using System.Collections.Generic; +using System.IO; +using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,5 +25,42 @@ namespace Labaratory.Services db.SaveChanges(); } } + public static string UpdatePhoto(string currentAvatarName) + { + OpenFileDialog openFile = new OpenFileDialog(); + openFile.Filter = "Image files (*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg"; + + if (openFile.ShowDialog() == true) + { + try + { + string fileName = Path.GetFileName(openFile.FileName); + // Формируем путь к папке Images в директории запущенного приложения + string imagesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images"); + string destPath = Path.Combine(imagesFolder, fileName); + + // Создаем папку Images, если её еще не существует + if (!Directory.Exists(imagesFolder)) + { + Directory.CreateDirectory(imagesFolder); + } + + // Копируем файл, если его еще нет в целевой папке + if (!File.Exists(destPath)) + { + File.Copy(openFile.FileName, destPath); + } + + return fileName; // Возвращаем имя нового файла + } + catch (Exception ex) + { + MessageBox.Show($"Ошибка при загрузке фото: {ex.Message}"); + return currentAvatarName; + } + } + + return currentAvatarName; // Возвращаем старое имя, если пользователь закрыл окно + } } } diff --git a/Labaratory/Labaratory/Services/StringToImageConverter.cs b/Labaratory/Labaratory/Services/StringToImageConverter.cs index 5bbc254..442647a 100644 --- a/Labaratory/Labaratory/Services/StringToImageConverter.cs +++ b/Labaratory/Labaratory/Services/StringToImageConverter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,12 +11,10 @@ namespace Labaratory.Services { public class StringToImageConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string imageName = value as string; - - if (string.IsNullOrWhiteSpace(imageName)) - return null; + if (string.IsNullOrEmpty(imageName)) imageName = "Admin.png"; try { @@ -23,11 +22,10 @@ namespace Labaratory.Services } catch { - return null; + return new BitmapImage(new Uri("pack://application:,,,/Images/Admin.png")); } } - public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) - => throw new NotImplementedException(); + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => null; } } diff --git a/Labaratory/Labaratory/ViewModels/AdminModel.cs b/Labaratory/Labaratory/ViewModels/AdminModel.cs index 5035eab..8b073df 100644 --- a/Labaratory/Labaratory/ViewModels/AdminModel.cs +++ b/Labaratory/Labaratory/ViewModels/AdminModel.cs @@ -9,6 +9,9 @@ using System.Windows.Input; using Wpf.Ui.Input; using Labaratory.Models; using System.Collections.ObjectModel; +using Microsoft.Win32; +using System.IO; +using System.Windows.Controls; namespace Labaratory.ViewModels { @@ -19,12 +22,36 @@ namespace Labaratory.ViewModels public AdminModel(Models.User user) { CurrentUser = user; + RoleName = CurrentUser.Role1?.RoleName ?? "Роль не назначена"; + LoadData(); + + } + public string RoleName + { + get => nameRole; + set { nameRole = value; OnPropertyChanged(); } } private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities(); private string _filterLogin; + private string nameRole; + private List _roles; + public List Roles + { + get => _roles; + set { _roles = value; OnPropertyChanged(); } + } private List _allLogs; - + private ICommand _updatePhotoCommand; + public ICommand UpdatePhotoCommand + { + get + { + if (_updatePhotoCommand == null) + _updatePhotoCommand = new RelayCommand(obj => AuthService.UpdatePhoto("Admin.png")); + return _updatePhotoCommand; + } + } public string FilterLogin { get => _filterLogin; @@ -41,6 +68,8 @@ namespace Labaratory.ViewModels { _allLogs = db.LoggnHistories.OrderByDescending(h => h.AttemptTime).ToList(); History = new ObservableCollection(_allLogs); + Roles = db.Roles.ToList(); + } private void ApplyFilter() @@ -54,5 +83,48 @@ namespace Labaratory.ViewModels History = new ObservableCollection(filtered); } + + private User _newUser = new User(); + public User NewUser + { + get => _newUser; + set { _newUser = value; OnPropertyChanged(); } + } + private ICommand _saveUserCommand; + public ICommand SaveUserCommand + { + get + { + if (_saveUserCommand == null) + { + _saveUserCommand = new RelayCommand(obj => SaveUser()); + } + return _saveUserCommand; + } + } + + private void SaveUser() + { + if (string.IsNullOrWhiteSpace(NewUser.Login) || string.IsNullOrWhiteSpace(NewUser.Password)) + { + MessageBox.Show("Заполните логин и пароль!"); + return; + } + + try + { + db.Users.Add(NewUser); + db.SaveChanges(); + + MessageBox.Show("Пользователь успешно добавлен"); + + // Сбрасываем форму для нового ввода + NewUser = new User(); + } + catch (Exception ex) + { + MessageBox.Show($"Ошибка: {ex.Message}"); + } + } } } diff --git a/Labaratory/Labaratory/ViewModels/Laborant.cs b/Labaratory/Labaratory/ViewModels/Laborant.cs index abf57ca..8c30691 100644 --- a/Labaratory/Labaratory/ViewModels/Laborant.cs +++ b/Labaratory/Labaratory/ViewModels/Laborant.cs @@ -12,6 +12,8 @@ using System.Collections.ObjectModel; using System.Windows.Input; using Wpf.Ui.Input; using Labaratory.Views; +using Org.BouncyCastle.Tls; +using System.Windows.Threading; namespace Labaratory.ViewModels { @@ -23,6 +25,7 @@ namespace Labaratory.ViewModels { CurrentUser = user; CalculateNextNumber(); + StartTimer(); ProcessOrderCommand = new RelayCommand(execute => ProcessOrder()); } private string _barcodeInput; @@ -31,7 +34,60 @@ namespace Labaratory.ViewModels private Patient _selectedPatient; private ObservableCollection _selectedServices = new ObservableCollection(); private decimal _totalCost; + private string nameRole; + private DispatcherTimer _timer; + private TimeSpan _timeSpan = TimeSpan.FromMinutes(2.5); + private string _time; + public string Time + { + get => _time; + set { _time = value; OnPropertyChanged(); } + } + public void StartTimer() + { + _timer = new DispatcherTimer(); + _timer.Interval = TimeSpan.FromSeconds(1); + _timer.Tick += Timer_Tick; + _timer.Start(); + } + + private void Timer_Tick(object sender, EventArgs e) + { + if (_timeSpan.TotalSeconds > 0) + { + _timeSpan = _timeSpan.Subtract(TimeSpan.FromSeconds(1)); + Time = _timeSpan.ToString(@"mm\:ss"); + + if (_timeSpan.TotalSeconds == 30) + { + MessageBox.Show("Время на исходе!"); + } + } + else + { + _timer.Stop(); + Time = "00:00"; + MessageBox.Show("Время сессии истекло!"); + foreach (Window window in Application.Current.Windows) + { + // Проверяем по типу или по активности + if (window is Views.Laborant || window.IsActive) + { + // Если нужно открыть окно логина перед закрытием: + // new LoginWindow().Show(); + + window.Close(); + break; + } + } + } + } + public string RoleName + { + get => nameRole; + set { nameRole = value; OnPropertyChanged(); } + } public List AllServices => db.Services.ToList(); public ICommand ProcessOrderCommand { get; } public Patient SelectedPatient diff --git a/Labaratory/Labaratory/ViewModels/LoginViewModel.cs b/Labaratory/Labaratory/ViewModels/LoginViewModel.cs index e48abdc..466bc18 100644 --- a/Labaratory/Labaratory/ViewModels/LoginViewModel.cs +++ b/Labaratory/Labaratory/ViewModels/LoginViewModel.cs @@ -21,7 +21,6 @@ namespace Labaratory private string _captchaInput; private bool _isCaptchaValid; private bool _isLoginEnabled = true; - private int _failedAttempts = 0; private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities(); private Visibility _CapchaVisibility = Visibility.Hidden; diff --git a/Labaratory/Labaratory/Views/AdminWindow.xaml b/Labaratory/Labaratory/Views/AdminWindow.xaml index f9abaa6..764a25d 100644 --- a/Labaratory/Labaratory/Views/AdminWindow.xaml +++ b/Labaratory/Labaratory/Views/AdminWindow.xaml @@ -6,12 +6,36 @@ xmlns:local="clr-namespace:Labaratory.Views" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" x:Class="Labaratory.Views.AdminWindow" mc:Ignorable="d" - Title="AdminWindow" Height="450" Width="800" + Title="AdminWindow" Height="510" Width="800" Background="{ui:ThemeResource ApplicationBackgroundBrush}" - Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}"> + Foreground="{ui:ThemeResource TextFillColorPrimaryBrush}" + xmlns:services="clr-namespace:Labaratory.Services"> + + + + + - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + +