Demka_kur/MainWindow.axaml.cs

77 lines
2.1 KiB
C#
Raw Permalink Normal View History

2025-02-04 11:35:26 +00:00
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;
2025-02-05 09:03:32 +00:00
2025-02-04 11:35:26 +00:00
private void InitializeComponent()
2025-02-05 09:03:32 +00:00
{
2025-02-04 11:35:26 +00:00
AvaloniaXamlLoader.Load(this);
}
2025-02-05 09:03:32 +00:00
2025-02-04 11:35:26 +00:00
public MainWindow()
{
InitializeComponent();
}
2025-02-05 09:03:32 +00:00
2025-02-04 11:35:26 +00:00
private void TogglePasswordButton_Click(object sender, RoutedEventArgs e)
{
_isPasswordVisible = !_isPasswordVisible;
PasswordTextBox.PasswordChar = _isPasswordVisible ? '\0' : '*';
}
2025-02-05 09:03:32 +00:00
private void LoginButton_Click(object sender, RoutedEventArgs e)
2025-02-04 11:35:26 +00:00
{
string username = UsernameTextBox.Text;
string password = PasswordTextBox.Text;
if (IsValidUser(username, password))
{
2025-02-05 09:03:32 +00:00
Window nextWindow = null;
switch (SotrudnikDao.Pozition)
{
case "Продавец":
nextWindow = new SellerWindow();
break;
case "Старший смены":
nextWindow = new StarshiyWindow();
break;
case "Администратор":
nextWindow = new AdminWindow();
break;
default:
2025-02-05 10:03:38 +00:00
ShowError("Неизвестная роль пользователя");
2025-02-05 09:03:32 +00:00
return;
}
nextWindow.Show();
2025-02-04 11:35:26 +00:00
this.Close();
}
else
2025-02-05 09:03:32 +00:00
{
2025-02-05 10:03:38 +00:00
ShowError("Неверный логин или пароль");
2025-02-04 11:35:26 +00:00
}
2025-02-05 09:03:32 +00:00
2025-02-05 10:03:38 +00:00
async void ShowError(string mes)
2025-02-04 11:35:26 +00:00
{
2025-02-05 09:03:32 +00:00
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;
}
2025-02-04 11:35:26 +00:00
}
}