Demka_kur/MainWindow.axaml.cs
2025-02-05 13:03:38 +03:00

77 lines
2.1 KiB
C#

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