using Avalonia.Controls; using Avalonia.Interactivity; using Demka_Snova_1.Hardik.Conect; using Demka_Snova_1.OknaRoley; using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; namespace Demka_Snova_1; public partial class MainWindow : Window { private bool _isPasswordVisible = false; public MainWindow() { InitializeComponent(); } private void TogglePasswordButton_Click(object sender, RoutedEventArgs e) { _isPasswordVisible = !_isPasswordVisible; PasswordTextBox.PasswordChar = _isPasswordVisible ? '\0' : '*'; } private void SelerTest_Click(object sender, RoutedEventArgs e) { var login = new AdminWindow(); login.Show(); this.Close(); } private async void LoginButton_Click(object sender, RoutedEventArgs e) { string username = UsernameTextBox.Text; string password = PasswordTextBox.Text; using (var context = new AppDbContext()) { var user = await context.sotrudnik .FirstOrDefaultAsync(u => u.Login == username && u.Pass == password); if (user != null) { Window nextWindow = null; switch (user.Pozition) { case "Продавец": nextWindow = new SellerWindow(); break; case "Старший смены": nextWindow = new StarshiyWindow(); break; case "Администратор": nextWindow = new AdminWindow(); break; default: await ShowError("Неизвестная роль пользователя"); return; } nextWindow.Show(); this.Close(); } else { await ShowError("Неверный логин или пароль"); } } } private async Task ShowError(string message) { var dialog = new Window { Title = "Ошибка", Content = message, Width = 300, Height = 200 }; await dialog.ShowDialog(this); } }