|
@@ -25,52 +25,44 @@ namespace HotelCalifornia
|
|
|
public Staff()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- DispatcherTimer timer = new DispatcherTimer();
|
|
|
+ //Таймер на обновление времени
|
|
|
+ DispatcherTimer timer = new DispatcherTimer();
|
|
|
timer.Tick += new EventHandler(Update_Timer_Tick);
|
|
|
timer.Interval = new TimeSpan(0, 0, 1);
|
|
|
timer.Start();
|
|
|
}
|
|
|
|
|
|
+ //Строка подключения
|
|
|
SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=kursah;Integrated Security=True");
|
|
|
|
|
|
+ //Вывод даты и время в textblock
|
|
|
private void Update_Timer_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
timetxt.Text = DateTime.Now.ToString();
|
|
|
}
|
|
|
|
|
|
+ //Выход из приложения
|
|
|
private void Close(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- MessageBoxResult result = MessageBox.Show("Вы хотите выйти из приложения?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- switch (result)
|
|
|
- {
|
|
|
- case MessageBoxResult.Yes:
|
|
|
- Application.Current.Shutdown();
|
|
|
- break;
|
|
|
- case MessageBoxResult.No:
|
|
|
- break;
|
|
|
- }
|
|
|
+ Application.Current.Shutdown();
|
|
|
}
|
|
|
|
|
|
+ //Свернуть окно
|
|
|
private void WindMin_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
this.WindowState = WindowState.Minimized;
|
|
|
}
|
|
|
|
|
|
+ //Возврат к окну выбора функции
|
|
|
private void Back(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- MessageBoxResult result = MessageBox.Show("Вы хотите вернуться к предыдущему окну?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
|
|
- switch (result)
|
|
|
- {
|
|
|
- case MessageBoxResult.Yes:
|
|
|
- Variant variant = new Variant();
|
|
|
- this.Close();
|
|
|
- variant.Show();
|
|
|
- break;
|
|
|
- case MessageBoxResult.No:
|
|
|
- break;
|
|
|
- }
|
|
|
+ Variant variant = new Variant();
|
|
|
+ variant.idadmintxt.Text = idadmintxt.Text;
|
|
|
+ this.Close();
|
|
|
+ variant.Show();
|
|
|
}
|
|
|
|
|
|
+ //Выбор строки из БД
|
|
|
private void datastaff_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
try
|
|
@@ -84,7 +76,7 @@ namespace HotelCalifornia
|
|
|
familiyatxt.Text = rowView["LastName"].ToString();
|
|
|
otchestvotxt.Text = rowView["MiddleName"].ToString();
|
|
|
logintxt.Text = rowView["Login"].ToString();
|
|
|
- passwordtxt.Text = rowView["Password"].ToString();
|
|
|
+ passwordtxt.Password = rowView["Password"].ToString();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -93,9 +85,10 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Добавление администратора
|
|
|
private void Add_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Text == "")
|
|
|
+ if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Password == "")
|
|
|
{
|
|
|
MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -117,8 +110,8 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string reg = "INSERT INTO Administrator (LastName,FirstName,MiddleName,Login,Password) VALUES('" + familiyatxt.Text + "','" + nametxt.Text + "','" + otchestvotxt.Text + "','" + logintxt.Text + "','" + passwordtxt.Text + "')";
|
|
|
- SqlDataAdapter dataAdapter = new SqlDataAdapter(reg, con);
|
|
|
+ string sql = "INSERT INTO Administrator (LastName,FirstName,MiddleName,Login,Password) VALUES('" + familiyatxt.Text + "','" + nametxt.Text + "','" + otchestvotxt.Text + "','" + logintxt.Text + "','" + passwordtxt.Password + "')";
|
|
|
+ SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
con.Close();
|
|
|
showgrid();
|
|
@@ -127,7 +120,7 @@ namespace HotelCalifornia
|
|
|
familiyatxt.Text = "";
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
- passwordtxt.Text = "";
|
|
|
+ passwordtxt.Password = "";
|
|
|
MessageBox.Show("Администратор был добавлен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
}
|
|
@@ -139,13 +132,14 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Обновление администратора
|
|
|
private void Update_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (idtxt.Text == "")
|
|
|
{
|
|
|
MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
- else if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Text == "")
|
|
|
+ else if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Password == "")
|
|
|
{
|
|
|
MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -154,7 +148,7 @@ namespace HotelCalifornia
|
|
|
try
|
|
|
{
|
|
|
con.Open();
|
|
|
- string sql = "Update Administrator set FirstName ='" + nametxt.Text + "', LastName = '" + familiyatxt.Text + "', MiddleName = '" + otchestvotxt.Text + "', Login = '" + logintxt.Text + "', Password = '" + passwordtxt.Text + "' where ID_Administrator = '" + idtxt.Text + "'";
|
|
|
+ string sql = "Update Administrator set FirstName ='" + nametxt.Text + "', LastName = '" + familiyatxt.Text + "', MiddleName = '" + otchestvotxt.Text + "', Login = '" + logintxt.Text + "', Password = '" + passwordtxt.Password + "' where ID_Administrator = '" + idtxt.Text + "'";
|
|
|
SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
con.Close();
|
|
@@ -163,7 +157,7 @@ namespace HotelCalifornia
|
|
|
familiyatxt.Text = "";
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
- passwordtxt.Text = "";
|
|
|
+ passwordtxt.Password = "";
|
|
|
showgrid();
|
|
|
MessageBox.Show("Администратор был изменен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -175,6 +169,7 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Удаление администратора
|
|
|
private void Delete_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (idtxt.Text == "")
|
|
@@ -195,7 +190,7 @@ namespace HotelCalifornia
|
|
|
familiyatxt.Text = "";
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
- passwordtxt.Text = "";
|
|
|
+ passwordtxt.Password = "";
|
|
|
showgrid();
|
|
|
MessageBox.Show("Администратор удален!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -207,6 +202,8 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Ограничение для ввода текста
|
|
|
+ #region Ограничение
|
|
|
private void nametxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
{
|
|
|
if (sender is TextBox textBox)
|
|
@@ -243,7 +240,7 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void passwordtxt_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
+ private void passwordtxt_PasswordChanged(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (sender is TextBox textBox)
|
|
|
{
|
|
@@ -251,19 +248,16 @@ namespace HotelCalifornia
|
|
|
(textBox.Text.Where(ch => (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')).ToArray());
|
|
|
}
|
|
|
}
|
|
|
+ #endregion
|
|
|
|
|
|
- private void Grid_Loaded(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- showgrid();
|
|
|
- }
|
|
|
-
|
|
|
+ //Фомировка данных из БД
|
|
|
void showgrid()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
con.Open();
|
|
|
- string rke = "SELECT * From Administrator";
|
|
|
- SqlDataAdapter dataAdapter = new SqlDataAdapter(rke, con);
|
|
|
+ string sql = "SELECT * From Administrator";
|
|
|
+ SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
DataTable data = new DataTable("Administrator");
|
|
|
dataAdapter.Fill(data);
|
|
|
datastaff.ItemsSource = data.DefaultView;
|
|
@@ -274,15 +268,17 @@ namespace HotelCalifornia
|
|
|
datastaff.Columns[2].Header = "Имя";
|
|
|
datastaff.Columns[3].Header = "Отчество";
|
|
|
datastaff.Columns[4].Header = "Логин";
|
|
|
- datastaff.Columns[5].Header = "Пароль";
|
|
|
+ datastaff.Columns[5].Visibility = Visibility.Collapsed;
|
|
|
datastaff.Columns[0].Visibility = Visibility.Collapsed;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
+ con.Close();
|
|
|
MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //Обновление
|
|
|
private void Refresh_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
showgrid();
|
|
@@ -291,7 +287,19 @@ namespace HotelCalifornia
|
|
|
familiyatxt.Text = "";
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
- passwordtxt.Text = "";
|
|
|
+ passwordtxt.Password = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ //Перетаскивание окна
|
|
|
+ private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
|
|
|
+ {
|
|
|
+ DragMove();
|
|
|
+ }
|
|
|
+
|
|
|
+ //Запуск в самом начале
|
|
|
+ private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ showgrid();
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|