using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Timers;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WPF01.pages
{
using db;
///
/// Логика взаимодействия для Authorization.xaml
///
public partial class Authorization : Page
{
// Количество неверно веденного пароля
int count = 0;
Timer timer = new Timer();
public Authorization()
{
InitializeComponent();
timer.Interval = 5000;
timer.Elapsed += new ElapsedEventHandler(Timeout);
}
void Timeout(object sender, ElapsedEventArgs e)
{
Dispatcher.Invoke(new Action(() =>
{
buttonLogin.IsEnabled = true;
timer.Stop();
}));
}
private void ButtonClick(object sender, RoutedEventArgs e)
{
string login = textBoxLogin.Text;
string password = textBoxPassword.Password;
if (login.Length < 4 || password.Length < 4)
{
return;
}
IQueryable man = Database.Context.Manager.Where(
m => m.Login == login && m.Password == password);
Database.User = man.FirstOrDefault();
if (Database.User == null)
{
MessageBox.Show("Неверный логин/пароль");
count++;
if (count >= 3)
{
buttonLogin.IsEnabled = false;
timer.Start();
}
return;
}
switch (Database.User.Role)
{
case "Директор":
NavigationService.Navigate(PageNavigation.director);
break;
case "Менеджер":
NavigationService.Navigate(PageNavigation.mainPage);
break;
case "Администратор":
NavigationService.Navigate(PageNavigation.mainPage);
break;
default:
NavigationService.Navigate(PageNavigation.mainPage);
break;
}
PageNavigation.mainWindow.userInfoButton.Visibility = Visibility.Visible;
}
private void TextBoxInput(object sender, KeyEventArgs e)
{
if (textBoxLogin.Text.Length >= 4 && textBoxPassword.Password.Length >= 4)
{
buttonLogin.IsEnabled = true;
}
else
{
buttonLogin.IsEnabled = false;
}
}
private void Label_MouseUp(object sender, MouseButtonEventArgs e)
{
NavigationService.Navigate(PageNavigation.registration);
}
}
}