using System; using System.IO; using System.Net.Mime; using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Media.Imaging; using Hard_Demo.Models; namespace Hard_Demo; public partial class FunctionWindow : Window { private readonly TimeSpan sessionDuration = TimeSpan.FromMinutes(10); private readonly TimeSpan warningTime = TimeSpan.FromMinutes(5); private DateTime sessionStartTime; private bool warningShow = false; 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 }; sessionStartTime = DateTime.Now; StartSessionTimer(); } private async void StartSessionTimer() { while (true) { TimeSpan ellapsedTime = DateTime.Now - sessionStartTime; TimeSpan remainingTime = sessionDuration - ellapsedTime; this.FindControl("Timer").Text = $"Осталось: {remainingTime.Minutes}:{remainingTime.Seconds}"; if (!warningShow && remainingTime <= warningTime) { warningShow = true; WarningBlock.Text = "Ваш сеанс закончится через 5 минут."; } if (remainingTime <= TimeSpan.Zero) { EndSession(); break; } await Task.Delay(1000); } } private async void EndSession() { this.Close(); } public FunctionWindow() { InitializeComponent(); } private void Back_Button(object? sender, RoutedEventArgs e) { new MainWindow().ShowDialog(this); } private void Next_Function_Button(object? sender, RoutedEventArgs e) { new EnterHistoryWindow().ShowDialog(this); } private void newOrder_OnClick(object? sender, RoutedEventArgs e) { new OrderWindow().ShowDialog(this); } public class ImageEmployee: Employee { public bool IsRole2 => RoleId == 2; Bitmap? Image { get { try { string absolutePath = Path.Combine(AppContext.BaseDirectory, EmployePhoto); return new Bitmap(absolutePath); } catch(Exception e) { Console.WriteLine(e.Message); return null; } } } } }