AuthWindow.xaml.cs 2.1 KB

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