MainWindow.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  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 HotelCalifornia
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для MainWindow.xaml
  20. /// </summary>
  21. public partial class MainWindow : Window
  22. {
  23. public MainWindow()
  24. {
  25. InitializeComponent();
  26. }
  27. //Перетаскивание окна
  28. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  29. {
  30. DragMove();
  31. }
  32. //Выход из приложения
  33. private void Close(object sender, RoutedEventArgs e)
  34. {
  35. MessageBoxResult result = MessageBox.Show("Вы хотите выйти из приложения?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
  36. switch (result)
  37. {
  38. case MessageBoxResult.Yes:
  39. Application.Current.Shutdown();
  40. break;
  41. case MessageBoxResult.No:
  42. break;
  43. }
  44. }
  45. //Авторизация пользователя
  46. private void Vhod(object sender, RoutedEventArgs e)
  47. {
  48. try
  49. {
  50. if (logintxt.Text == "" || passwordtxt.Password == "")
  51. {
  52. MessageBox.Show("Поля не могут быть пустыми!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
  53. }
  54. else
  55. {
  56. Variant variant = new Variant();
  57. this.Close();
  58. variant.Show();
  59. }
  60. }
  61. catch (Exception ex)
  62. {
  63. MessageBox.Show("Возникла ошибка! " + ex.ToString(),"Ошибка",MessageBoxButton.OK, MessageBoxImage.Error);
  64. }
  65. }
  66. //Запрет пробела
  67. private void logintxt_PreviewKeyDown(object sender, KeyEventArgs e)
  68. {
  69. if (e.Key == Key.Space)
  70. {
  71. e.Handled = true;
  72. }
  73. }
  74. //Запрет пробела
  75. private void passwordtxt_PreviewKeyDown(object sender, KeyEventArgs e)
  76. {
  77. if (e.Key == Key.Space)
  78. {
  79. e.Handled = true;
  80. }
  81. }
  82. //Определенные символы
  83. private void logintxt_TextChanged(object sender, TextChangedEventArgs e)
  84. {
  85. if (sender is TextBox textBox)
  86. {
  87. textBox.Text = new string
  88. (textBox.Text.Where(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')).ToArray());
  89. }
  90. }
  91. //Определенные символы
  92. private void passwordtxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
  93. {
  94. bool a = new Regex("[^A-Z]+").IsMatch(e.Text);
  95. bool b = new Regex("[^a-z]+").IsMatch(e.Text);
  96. bool c = new Regex("[^0-9]+").IsMatch(e.Text);
  97. e.Handled = a && b && c;
  98. }
  99. private void WindMin_Click(object sender, RoutedEventArgs e)
  100. {
  101. this.WindowState = WindowState.Minimized;
  102. }
  103. }
  104. }