123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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;
- /// <summary>
- /// Логика взаимодействия для Authorization.xaml
- /// </summary>
- 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<Manager> 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);
- }
- }
- }
|