MainWindow.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.Navigation;
  14. using System.Windows.Shapes;
  15. namespace kursach_2._0
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для MainWindow.xaml
  19. /// </summary>
  20. public partial class MainWindow : Window
  21. {
  22. private dealerContext _context;
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. _context = new dealerContext();
  27. }
  28. private void AuthClick(object sender, RoutedEventArgs e)
  29. {
  30. if(string.IsNullOrWhiteSpace(log.Text) || string.IsNullOrWhiteSpace(pas.Password))
  31. {
  32. MessageBox.Show("Поля должны быть заполнены");
  33. return;
  34. }
  35. List<employees> users;
  36. try
  37. {
  38. users = _context.employees.Where(u => u.login == log.Text && u.password == pas.Password).ToList();
  39. }
  40. catch
  41. {
  42. MessageBox.Show("Произошла ошибка");
  43. return;
  44. }
  45. if (users.Count == 1)
  46. {
  47. // если все ок
  48. Windows.Menu menu = new Windows.Menu();
  49. menu.Show();
  50. Close();
  51. }
  52. else
  53. {
  54. MessageBox.Show("Неверный логин или пароль");
  55. return;
  56. }
  57. }
  58. }
  59. }