MainWindow.xaml.cs 1.7 KB

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