Authorisation.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using ProjectCafe.Properties;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  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 ProjectCafe
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для Authorisation.xaml
  20. /// </summary>
  21. public partial class Authorisation : Page
  22. {
  23. gr672_bdaEntities db = new gr672_bdaEntities();
  24. public Authorisation()
  25. {
  26. InitializeComponent();
  27. }
  28. private void Auth_Ckick(object sender, RoutedEventArgs e)
  29. {
  30. if (txtLogin == null || txtPassword == null)
  31. {
  32. MessageBox.Show("Не все поля заполнены");
  33. }
  34. using (var db = new gr672_bdaEntities())
  35. {
  36. var user = db.EmployeeCafe
  37. .AsNoTracking()
  38. .FirstOrDefault(u => u.Login == txtLogin.Text && u.Password == txtPassword.Password);
  39. if (user == null)
  40. {
  41. MessageBox.Show("Пользователь с таким именем не найден!");
  42. }
  43. int IdEmployee = user.IdEmployee;
  44. Application.Current.Properties["IdEmployee"] = IdEmployee;
  45. switch (user.RoleEmployee.IdRole)
  46. {
  47. case 1:
  48. FrameClass.MainFrame.Navigate(new Cook());
  49. break;
  50. case 2:
  51. FrameClass.MainFrame.Navigate(new EmployeePage());
  52. break;
  53. case 3:
  54. FrameClass.MainFrame.Navigate(new Administrator());
  55. break;
  56. }
  57. }
  58. }
  59. }
  60. }