Authorization.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace Control_DB_Railway
  15. {
  16. /// <summary>
  17. /// Логика взаимодействия для Authorization.xaml
  18. /// </summary>
  19. public partial class Authorization : Window
  20. {
  21. Entities entities = new Entities();
  22. public Authorization()
  23. {
  24. InitializeComponent();
  25. }
  26. /* Кнопка авторизации в системе */
  27. private void buttonLoginSystem_Click(object sender, RoutedEventArgs e)
  28. {
  29. // Переменные для MessageBox
  30. string m_aut = "Аутентификация";
  31. string m_errorincor = "Ошибка! Проверьте правильность данных!";
  32. if (textBox_login.Text != "" && textBox_login.Text == null ||
  33. passwordBox_password.Password != "" && passwordBox_password.Password != null)
  34. {
  35. string Login = textBox_login.Text;
  36. string Password = passwordBox_password.Password;
  37. bool flag = false;
  38. // Просмотр записей в таблице
  39. foreach (var record in entities.AuthorizationTable)
  40. {
  41. if (Login == record.login)
  42. {
  43. if (Password == record.password)
  44. {
  45. flag = true;
  46. if (Login == "admin")
  47. {
  48. MainWindow showMainWindow = new MainWindow();
  49. showMainWindow.button_AddRecord_Station.IsEnabled = true;
  50. showMainWindow.button_AddRecord_TypeStation.IsEnabled = true;
  51. showMainWindow.button_AddRecord_Road.IsEnabled = true;
  52. showMainWindow.button_DeleteRecord_Station.IsEnabled = true;
  53. showMainWindow.button_DeleteRecord_TypeStation.IsEnabled = true;
  54. showMainWindow.button_DeleteRecord_Road.IsEnabled = true;
  55. showMainWindow.ShowDialog();
  56. }
  57. else if (Login == "user")
  58. {
  59. MainWindow showMainWindow = new MainWindow();
  60. showMainWindow.button_AddRecord_Station.IsEnabled = true;
  61. showMainWindow.button_AddRecord_TypeStation.IsEnabled = true;
  62. showMainWindow.button_AddRecord_Road.IsEnabled = true;
  63. showMainWindow.button_DeleteRecord_Station.IsEnabled = false;
  64. showMainWindow.button_DeleteRecord_TypeStation.IsEnabled = false;
  65. showMainWindow.button_DeleteRecord_Road.IsEnabled = false;
  66. showMainWindow.ShowDialog();
  67. }
  68. Close();
  69. break;
  70. }
  71. }
  72. }
  73. if (!flag)
  74. // Если пользователь не существует, то:
  75. MessageBox.Show(m_errorincor, m_aut, MessageBoxButton.OK, MessageBoxImage.Error);
  76. }
  77. else
  78. // Если данные в элементах пустые
  79. MessageBox.Show(m_errorincor, m_aut, MessageBoxButton.OK, MessageBoxImage.Warning);
  80. }
  81. }
  82. }