using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Data.SqlClient; using System.Data; namespace HotelCalifornia { /// /// Логика взаимодействия для MainWindow.xaml /// public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } //Строка подключения SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=kursah;Integrated Security=True"); //Перетаскивание окна private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { try { DragMove(); } catch { } } //Выход из приложения private void Close(object sender, RoutedEventArgs e) { Application.Current.Shutdown(); } //Авторизация пользователя private void Vhod(object sender, RoutedEventArgs e) { try { if (logintxt.Text == "" || passwordtxt.Password == "") { MessageBox.Show("Поля не могут быть пустыми!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information); } else { con.Open(); SqlCommand cmd = new SqlCommand("Select * from Administrator where Login ='" + logintxt.Text + "' and Password ='" + passwordtxt.Password + "'", con); cmd.CommandType = CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = cmd; DataSet dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count > 0) { string idrole = dataSet.Tables[0].Rows[0]["ID_Role"].ToString(); string username = dataSet.Tables[0].Rows[0]["ID_Administrator"].ToString(); if (idrole.ToString() == "1") { Variant variant = new Variant(); variant.idadmintxt.Text = username; con.Close(); variant.Show(); this.Close(); } else { Staff staff = new Staff(); staff.idadmintxt.Text = username; con.Close(); staff.Show(); this.Close(); } } else { con.Close(); logintxt.Text = ""; passwordtxt.Password = ""; MessageBox.Show("Такого Администратора нет в системе!", "Вход", MessageBoxButton.OK, MessageBoxImage.Information); } } } catch (Exception ex) { con.Close(); MessageBox.Show("Возникла ошибка! " + ex.ToString(),"Ошибка",MessageBoxButton.OK, MessageBoxImage.Error); } } //Ограничение для ввода текста #region Ограничения //Запрет пробела private void logintxt_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Space) { e.Handled = true; } } //Запрет пробела private void passwordtxt_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Space) { e.Handled = true; } } //Определенные символы private void logintxt_TextChanged(object sender, TextChangedEventArgs e) { if (sender is TextBox textBox) { textBox.Text = new string (textBox.Text.Where(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')).ToArray()); } } //Определенные символы private void passwordtxt_PreviewTextInput(object sender, TextCompositionEventArgs e) { bool a = new Regex("[^A-Z]+").IsMatch(e.Text); bool b = new Regex("[^a-z]+").IsMatch(e.Text); bool c = new Regex("[^0-9]+").IsMatch(e.Text); e.Handled = a && b && c; } #endregion //Свернуть окно private void WindMin_Click(object sender, RoutedEventArgs e) { this.WindowState = WindowState.Minimized; } } }