123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- 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
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- 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;
- }
- }
- }
|