demo_hard/FunctionWindow.axaml.cs

108 lines
2.8 KiB
C#
Raw Permalink Normal View History

2025-02-05 10:07:55 +00:00
using System;
using System.IO;
2025-02-12 11:54:49 +00:00
using System.Threading.Tasks;
2025-02-04 12:27:32 +00:00
using Avalonia;
using Avalonia.Controls;
2025-02-05 10:07:55 +00:00
using Avalonia.Interactivity;
2025-02-04 12:27:32 +00:00
using Avalonia.Markup.Xaml;
2025-02-05 10:07:55 +00:00
using Avalonia.Media.Imaging;
2025-02-11 13:17:16 +00:00
using demo_hard.Model;
2025-02-04 12:27:32 +00:00
namespace demo_hard;
public partial class FunctionWindow : Window
{
2025-02-12 11:54:49 +00:00
private readonly TimeSpan sessionDuration = TimeSpan.FromMinutes(10);
private readonly TimeSpan warningTime = TimeSpan.FromMinutes(5);
//private readonly TimeSpan lockoutDuration = TimeSpan.FromMinutes(1);
private DateTime sessionStartTime;
private bool warningShow = false;
2025-02-05 10:07:55 +00:00
public FunctionWindow(Employee user)
{
InitializeComponent();
DataContext = new ImageEmployee()
{
EmployeId = user.EmployeId,
Fio = user.Fio,
EmployeLogin = user.EmployeLogin,
EmployePassword = user.EmployePassword,
RoleId = user.RoleId,
EmployePhoto = user.EmployePhoto
};
2025-02-12 11:54:49 +00:00
sessionStartTime = DateTime.Now;
StartSessionTimer();
2025-02-05 10:07:55 +00:00
}
2025-02-04 12:27:32 +00:00
public FunctionWindow()
{
InitializeComponent();
2025-02-05 10:07:55 +00:00
}
2025-02-12 11:54:49 +00:00
private async void StartSessionTimer()
{
while (true)
{
TimeSpan elapsedTime = DateTime.Now - sessionStartTime;
TimeSpan remainingTime = sessionDuration - elapsedTime;
this.FindControl<TextBlock>("SessionTimer").Text = $"Осталось: {remainingTime.Minutes}:{remainingTime.Seconds}";
if (!warningShow && remainingTime <= warningTime)
{
warningShow = true;
WarningBlock.Text = "Внимание! Ваш сеанс закончится через 5 минут!";
}
if (remainingTime <= TimeSpan.Zero)
{
EndSession();
break;
}
await Task.Delay(1000);
}
}
2025-02-05 10:07:55 +00:00
2025-02-12 11:54:49 +00:00
private async void EndSession()
{
this.Close();
}
2025-02-05 10:07:55 +00:00
private void Back_Button(object? sender, RoutedEventArgs e)
{
new MainWindow().ShowDialog(this);
}
private void Next_Function_Button(object? sender, RoutedEventArgs e)
{
new SallerWindow().ShowDialog(this);
}
public class ImageEmployee: Employee
{
Bitmap? Image
{
get
{
try
{
string absolutePath = Path.Combine(AppContext.BaseDirectory, EmployePhoto);
return new Bitmap(absolutePath);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
}
2025-02-04 12:27:32 +00:00
}
2025-02-12 11:54:49 +00:00
private void History_Button(object? sender, RoutedEventArgs e)
{
new HistoryWindow().ShowDialog(this);
}
2025-02-04 12:27:32 +00:00
}