Authorization.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Timers;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace WPF01.pages
  17. {
  18. using db;
  19. /// <summary>
  20. /// Логика взаимодействия для Authorization.xaml
  21. /// </summary>
  22. public partial class Authorization : Page
  23. {
  24. // Количество неверно веденного пароля
  25. int count = 0;
  26. Timer timer = new Timer();
  27. public Authorization()
  28. {
  29. InitializeComponent();
  30. timer.Interval = 5000;
  31. timer.Elapsed += new ElapsedEventHandler(Timeout);
  32. }
  33. void Timeout(object sender, ElapsedEventArgs e)
  34. {
  35. Dispatcher.Invoke(new Action(() =>
  36. {
  37. buttonLogin.IsEnabled = true;
  38. timer.Stop();
  39. }));
  40. }
  41. private void ButtonClick(object sender, RoutedEventArgs e)
  42. {
  43. string login = textBoxLogin.Text;
  44. string password = textBoxPassword.Password;
  45. if (login.Length < 4 || password.Length < 4)
  46. {
  47. return;
  48. }
  49. IQueryable<Manager> man = Database.Context.Manager.Where(
  50. m => m.Login == login && m.Password == password);
  51. Database.User = man.FirstOrDefault();
  52. if (Database.User == null)
  53. {
  54. MessageBox.Show("Неверный логин/пароль");
  55. count++;
  56. if (count >= 3)
  57. {
  58. buttonLogin.IsEnabled = false;
  59. timer.Start();
  60. }
  61. return;
  62. }
  63. switch (Database.User.Role)
  64. {
  65. case "Директор":
  66. NavigationService.Navigate(PageNavigation.director);
  67. break;
  68. case "Менеджер":
  69. NavigationService.Navigate(PageNavigation.mainPage);
  70. break;
  71. case "Администратор":
  72. NavigationService.Navigate(PageNavigation.mainPage);
  73. break;
  74. default:
  75. NavigationService.Navigate(PageNavigation.mainPage);
  76. break;
  77. }
  78. PageNavigation.mainWindow.userInfoButton.Visibility = Visibility.Visible;
  79. }
  80. private void TextBoxInput(object sender, KeyEventArgs e)
  81. {
  82. if (textBoxLogin.Text.Length >= 4 && textBoxPassword.Password.Length >= 4)
  83. {
  84. buttonLogin.IsEnabled = true;
  85. }
  86. else
  87. {
  88. buttonLogin.IsEnabled = false;
  89. }
  90. }
  91. private void Label_MouseUp(object sender, MouseButtonEventArgs e)
  92. {
  93. NavigationService.Navigate(PageNavigation.registration);
  94. }
  95. }
  96. }