AuthorizationWindow.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 InteractiveKiosk
  15. {
  16. /// <summary>
  17. /// Interaction logic for AuthorizationWindow.xaml
  18. /// </summary>
  19. public partial class AuthorizationWindow : Window
  20. {
  21. InteractiveKioskEntities db = new InteractiveKioskEntities();
  22. public AuthorizationWindow()
  23. {
  24. InitializeComponent();
  25. }
  26. //public void TextBox_GotFocus(object sender, RoutedEventArgs e)
  27. //{
  28. // TextBox tb = (TextBox)sender;
  29. // tb.Text = string.Empty;
  30. // tb.GotFocus -= TextBox_GotFocus;
  31. //}
  32. private void username_TextChanged(object sender, RoutedEventArgs e)
  33. {
  34. if (username.Text == "Логин")
  35. {
  36. username.Foreground = Brushes.Gray;
  37. }
  38. else if (username.Text == "")
  39. {
  40. username.Foreground = Brushes.Black;
  41. }
  42. }
  43. private void password_TextChanged(object sender, RoutedEventArgs e)
  44. {
  45. if (password.Text == "Пароль")
  46. {
  47. password.Foreground = Brushes.Gray;
  48. }
  49. else if (password.Text == "")
  50. {
  51. password.Foreground = Brushes.Black;
  52. }
  53. }
  54. private const string defaultText = "Логин";
  55. private const string defaultText1 = "Пароль";
  56. private void Username_GotFocus(object sender, RoutedEventArgs e)
  57. {
  58. username.Text = username.Text == defaultText ?
  59. string.Empty : username.Text;
  60. }
  61. private void Password_GotFocus(object sender, RoutedEventArgs e)
  62. {
  63. password.Text = password.Text == defaultText1 ?
  64. string.Empty : password.Text;
  65. }
  66. private void Username_LostFocus(object sender, RoutedEventArgs e)
  67. {
  68. username.Text = username.Text == string.Empty ?
  69. defaultText : username.Text;
  70. }
  71. private void Password_LostFocus(object sender, RoutedEventArgs e)
  72. {
  73. password.Text = password.Text == string.Empty ?
  74. defaultText1 : password.Text;
  75. }
  76. private void LoginButton(object sender, RoutedEventArgs e)
  77. {
  78. if (username.Text == "" || password.Text == "")
  79. {
  80. MessageBox.Show("Введено неверное значение!");
  81. return;
  82. }
  83. if (db.ParkManagers.Select(item => item.Username + " " + item.Password).Contains(username.Text + " " + password.Text))
  84. {
  85. MessageBox.Show("Добро пожаловать, вы авторизированы");
  86. this.Close();
  87. }
  88. else
  89. {
  90. MessageBox.Show("Введено неверное значение логина/пароля1");
  91. }
  92. }
  93. }
  94. }