2025-02-11 10:23:14 +00:00
|
|
|
using Avalonia.Controls;
|
|
|
|
using Avalonia.Interactivity;
|
2025-02-12 07:50:05 +00:00
|
|
|
using Demka_Snova_1.Hardik.Conect;
|
2025-02-11 10:23:14 +00:00
|
|
|
using Demka_Snova_1.OknaRoley;
|
2025-02-12 07:50:05 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2025-02-11 10:23:14 +00:00
|
|
|
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)
|
|
|
|
{
|
2025-03-05 09:12:58 +00:00
|
|
|
var login = new AdminWindow();
|
2025-02-11 10:23:14 +00:00
|
|
|
login.Show();
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
2025-02-12 07:50:05 +00:00
|
|
|
private async void LoginButton_Click(object sender, RoutedEventArgs e)
|
2025-02-11 10:23:14 +00:00
|
|
|
{
|
|
|
|
string username = UsernameTextBox.Text;
|
|
|
|
string password = PasswordTextBox.Text;
|
|
|
|
|
2025-02-12 07:50:05 +00:00
|
|
|
using (var context = new AppDbContext())
|
2025-02-11 10:23:14 +00:00
|
|
|
{
|
2025-02-12 07:50:05 +00:00
|
|
|
var user = await context.sotrudnik
|
|
|
|
.FirstOrDefaultAsync(u => u.Login == username && u.Pass == password);
|
2025-02-11 10:23:14 +00:00
|
|
|
|
2025-02-12 07:50:05 +00:00
|
|
|
if (user != null)
|
2025-02-11 10:23:14 +00:00
|
|
|
{
|
2025-02-12 07:50:05 +00:00
|
|
|
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;
|
|
|
|
}
|
2025-02-11 10:23:14 +00:00
|
|
|
|
2025-02-12 07:50:05 +00:00
|
|
|
nextWindow.Show();
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
await ShowError("Неверный логин или пароль");
|
|
|
|
}
|
2025-02-11 10:23:14 +00:00
|
|
|
}
|
2025-02-12 07:50:05 +00:00
|
|
|
}
|
2025-02-11 10:23:14 +00:00
|
|
|
|
2025-02-12 07:50:05 +00:00
|
|
|
private async Task ShowError(string message)
|
|
|
|
{
|
|
|
|
var dialog = new Window
|
|
|
|
{
|
|
|
|
Title = "Ошибка",
|
|
|
|
Content = message,
|
|
|
|
Width = 300,
|
|
|
|
Height = 200
|
|
|
|
};
|
|
|
|
await dialog.ShowDialog(this);
|
2025-02-11 10:23:14 +00:00
|
|
|
}
|
|
|
|
}
|