Work almost done
This commit is contained in:
2
Labaratory/Labaratory/Models/Model1.Designer.cs
generated
2
Labaratory/Labaratory/Models/Model1.Designer.cs
generated
@@ -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". Это свойство доступно в окне "Свойства", если модель
|
||||
// открыта в конструкторе.
|
||||
|
||||
@@ -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; // Возвращаем старое имя, если пользователь закрыл окно
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Role> _roles;
|
||||
public List<Role> Roles
|
||||
{
|
||||
get => _roles;
|
||||
set { _roles = value; OnPropertyChanged(); }
|
||||
}
|
||||
private List<LoggnHistory> _allLogs;
|
||||
|
||||
private ICommand _updatePhotoCommand;
|
||||
public ICommand UpdatePhotoCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_updatePhotoCommand == null)
|
||||
_updatePhotoCommand = new RelayCommand<object>(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<LoggnHistory>(_allLogs);
|
||||
Roles = db.Roles.ToList();
|
||||
|
||||
}
|
||||
|
||||
private void ApplyFilter()
|
||||
@@ -54,5 +83,48 @@ namespace Labaratory.ViewModels
|
||||
|
||||
History = new ObservableCollection<LoggnHistory>(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<object>(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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<object>(execute => ProcessOrder());
|
||||
}
|
||||
private string _barcodeInput;
|
||||
@@ -31,7 +34,60 @@ namespace Labaratory.ViewModels
|
||||
private Patient _selectedPatient;
|
||||
private ObservableCollection<Service> _selectedServices = new ObservableCollection<Service>();
|
||||
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<Models.Service> AllServices => db.Services.ToList();
|
||||
public ICommand ProcessOrderCommand { get; }
|
||||
public Patient SelectedPatient
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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">
|
||||
<Window.Resources>
|
||||
<services:StringToImageConverter x:Key="ImgConv"/>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
|
||||
<TabControl>
|
||||
<TabItem Header="Orders" Background="Black">
|
||||
<TabItem Header="Профиль">
|
||||
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<ui:Card Padding="30">
|
||||
<StackPanel>
|
||||
<Ellipse Width="150" Height="150" Stroke="{ui:ThemeResource SystemAccentColorPrimaryBrush}" StrokeThickness="2">
|
||||
<Ellipse.Fill>
|
||||
<ImageBrush ImageSource="/Images/Admin.png"
|
||||
Stretch="UniformToFill"/>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
|
||||
<TextBlock Text="{Binding CurrentUser.FirstName}" FontSize="20" HorizontalAlignment="Center" Margin="0,15,0,0"/>
|
||||
<TextBlock Text="{Binding CurrentUser.Surname}" FontSize="24" HorizontalAlignment="Center" FontWeight="Bold"/>
|
||||
<TextBlock Text="{Binding RoleName}" Foreground="Gray" HorizontalAlignment="Center" Margin="0,5,0,0"/>
|
||||
</StackPanel>
|
||||
</ui:Card>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="История входа" Background="Black">
|
||||
<StackPanel>
|
||||
<TextBox
|
||||
Text="{Binding FilterLogin, UpdateSourceTrigger = PropertyChanged}"
|
||||
@@ -26,8 +50,35 @@
|
||||
</DataGrid>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Orders" Background="Black">
|
||||
<TabItem Header="Пользователи" Background="Black">
|
||||
<StackPanel Margin="10,15,0,15" MaxWidth="300" HorizontalAlignment="Left">
|
||||
<TextBlock Text="Добавление пользователя" Foreground="White" Margin="0,0,0,10" FontSize="16" FontWeight="Bold"/>
|
||||
|
||||
<TextBlock Text="Фамилия" Foreground="Gray" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding NewUser.Surname, UpdateSourceTrigger=PropertyChanged}" Margin="0,2"/>
|
||||
|
||||
<TextBlock Text="Имя" Foreground="Gray" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding NewUser.FirstName, UpdateSourceTrigger=PropertyChanged}" Margin="0,2"/>
|
||||
|
||||
<TextBlock Text="Логин" Foreground="Gray" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding NewUser.Login, UpdateSourceTrigger=PropertyChanged}" Margin="0,2"/>
|
||||
|
||||
<TextBlock Text="Пароль" Foreground="Gray" Margin="0,5,0,0"/>
|
||||
<TextBox Text="{Binding NewUser.Password, UpdateSourceTrigger=PropertyChanged}" Margin="0,2"/>
|
||||
|
||||
<TextBlock Text="Роль" Foreground="Gray" Margin="0,5,0,0"/>
|
||||
<ComboBox ItemsSource="{Binding Roles}"
|
||||
DisplayMemberPath="RoleName"
|
||||
SelectedValuePath="ID_Role"
|
||||
SelectedValue="{Binding NewUser.Role}"
|
||||
Margin="0,2"/>
|
||||
|
||||
<Button Content="Создать"
|
||||
Command="{Binding SaveUserCommand}"
|
||||
Margin="0,15"
|
||||
HorizontalAlignment="Stretch"
|
||||
Height="35"/>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<TabControl Margin="0,10,0,0">
|
||||
<Label HorizontalAlignment="Left" VerticalAlignment="Top" Content="{Binding Time}" Height="22" Width="72"/>
|
||||
<TabControl Margin="0,42,0,0">
|
||||
<!-- ВКЛАДКА 1: ОФОРМЛЕНИЕ -->
|
||||
<TabItem Header="Новый заказ">
|
||||
<Grid Margin="20">
|
||||
@@ -133,12 +134,14 @@
|
||||
<StackPanel>
|
||||
<Ellipse Width="150" Height="150" Stroke="{ui:ThemeResource SystemAccentColorPrimaryBrush}" StrokeThickness="2">
|
||||
<Ellipse.Fill>
|
||||
<ImageBrush ImageSource="{Binding CurrentUser.Photo, Converter={StaticResource StringToImageConverter}}" Stretch="UniformToFill"/>
|
||||
<ImageBrush ImageSource="/Images/Admin.png"
|
||||
Stretch="UniformToFill"/>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
|
||||
<TextBlock Text="{Binding CurrentUser.FirstName}" FontSize="20" HorizontalAlignment="Center" Margin="0,15,0,0"/>
|
||||
<TextBlock Text="{Binding CurrentUser.LastName}" FontSize="24" HorizontalAlignment="Center" FontWeight="Bold"/>
|
||||
<TextBlock Text="{Binding CurrentUser.Role.Name}" Foreground="Gray" HorizontalAlignment="Center" Margin="0,5,0,0"/>
|
||||
<TextBlock Text="{Binding CurrentUser.Surname}" FontSize="24" HorizontalAlignment="Center" FontWeight="Bold"/>
|
||||
<TextBlock Text="{Binding RoleName}" Foreground="Gray" HorizontalAlignment="Center" Margin="0,5,0,0"/>
|
||||
</StackPanel>
|
||||
</ui:Card>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user