113 lines
3.2 KiB
C#
113 lines
3.2 KiB
C#
![]() |
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Collections.ObjectModel;
|
||
|
using System.IO;
|
||
|
using System.Linq;
|
||
|
using Avalonia.Controls;
|
||
|
using Avalonia.Interactivity;
|
||
|
using Avalonia.Media.Imaging;
|
||
|
using dmeo040225.Models;
|
||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Query.ExpressionTranslators.Internal;
|
||
|
|
||
|
namespace dmeo040225;
|
||
|
|
||
|
public partial class MainWindow : Window
|
||
|
{
|
||
|
private bool _isPasswordVisible;
|
||
|
private List<User>? users;
|
||
|
public MainWindow()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
using var context = new DatabaseContext();
|
||
|
|
||
|
users = context.Users.Select(it => new User
|
||
|
{
|
||
|
Id = it.Id,
|
||
|
Role = it.Role,
|
||
|
Fio = it.Fio,
|
||
|
Login = it.Login,
|
||
|
Password = it.Password,
|
||
|
}).ToList();
|
||
|
PasswordName.PasswordChar = '*';
|
||
|
}
|
||
|
|
||
|
public class UserPresenter() : User
|
||
|
{
|
||
|
Bitmap? Image
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string absolutePath = Path.Combine(AppContext.BaseDirectory, Photopath);
|
||
|
return new Bitmap(absolutePath);
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Authorization(object? sender, RoutedEventArgs e)
|
||
|
{
|
||
|
var login = LoginName.Text;
|
||
|
var password = PasswordName.Text;
|
||
|
|
||
|
using var context = new DatabaseContext();
|
||
|
var user = context.Users.FirstOrDefault(it => it.Login == login);
|
||
|
if (user.Password == password)
|
||
|
{
|
||
|
user.Lastlogin = DateTime.Now;
|
||
|
user.Logorno = true;
|
||
|
context.Users.Update(user);
|
||
|
context.SaveChanges();
|
||
|
Console.WriteLine($"Success {user.Fio}");
|
||
|
|
||
|
switch (user.RoleId)
|
||
|
{
|
||
|
case 1:
|
||
|
ClientWindow clientWindow = new ClientWindow();
|
||
|
clientWindow.ShowDialog(this);
|
||
|
break;
|
||
|
case 2:
|
||
|
SellerWindow sellerWindow = new SellerWindow(user);
|
||
|
sellerWindow.ShowDialog(this);
|
||
|
break;
|
||
|
case 3:
|
||
|
OlderWindow olderWindow = new OlderWindow(user);
|
||
|
olderWindow.ShowDialog(this);
|
||
|
break;
|
||
|
case 4:
|
||
|
AdminWindow adminWindow = new AdminWindow(user);
|
||
|
adminWindow.ShowDialog(this);
|
||
|
break;
|
||
|
};
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
user.Lastlogin = DateTime.Now;
|
||
|
user.Logorno = false;
|
||
|
context.Users.Update(user);
|
||
|
context.SaveChanges();
|
||
|
Console.WriteLine("nah");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void TogglePasswordVisibilityClick(object? sender, RoutedEventArgs e)
|
||
|
{
|
||
|
_isPasswordVisible = !_isPasswordVisible;
|
||
|
|
||
|
if (_isPasswordVisible)
|
||
|
{
|
||
|
PasswordName.PasswordChar = '\0';
|
||
|
TogglePasswordVisibility.Content = "Hide";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
PasswordName.PasswordChar = '•';
|
||
|
TogglePasswordVisibility.Content = "Show";
|
||
|
}
|
||
|
}
|
||
|
}
|