Auth.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 TrainingBeforeExams
  15. {
  16. /// <summary>
  17. /// Interaction logic for Auth.xaml
  18. /// </summary>
  19. public partial class Auth : Window
  20. {
  21. testEntities entity;
  22. public Auth()
  23. {
  24. InitializeComponent();
  25. entity = new testEntities();
  26. }
  27. private void Button_Click(object sender, RoutedEventArgs e)
  28. {
  29. if(string.IsNullOrWhiteSpace(loginBox.Text) || string.IsNullOrWhiteSpace(passBox.Text))
  30. {
  31. MessageBox.Show("Поля не заполнены.");
  32. return;
  33. }
  34. if (entity.User.Select(x => x.Login + "" + x.Password).Contains(loginBox.Text + "" + passBox.Text))
  35. {
  36. var id = entity.User.Where(x => x.Login == loginBox.Text).Select(x => x.IdUser).FirstOrDefault();
  37. var role = entity.User.Where(x => x.Login == loginBox.Text).Select(x => x.RoleID).FirstOrDefault();
  38. if(role == 1)
  39. {
  40. WaiterWindow waiterWindow = new WaiterWindow(loginBox.Text, id);
  41. waiterWindow.Show();
  42. this.Hide();
  43. }
  44. if(role == 2)
  45. {
  46. CookerWindow cookerWindow = new CookerWindow();
  47. cookerWindow.Show();
  48. this.Hide();
  49. }
  50. if(role == 3)
  51. {
  52. MainWindow mainWindow = new MainWindow();
  53. mainWindow.Show();
  54. this.Hide();
  55. }
  56. }
  57. else
  58. {
  59. MessageBox.Show("Логин или пароль не совпадают.");
  60. return;
  61. }
  62. }
  63. }
  64. }