|
@@ -56,10 +56,9 @@ namespace HotelCalifornia
|
|
|
//Возврат к окну выбора функции
|
|
|
private void Back(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- Variant variant = new Variant();
|
|
|
- variant.idadmintxt.Text = idadmintxt.Text;
|
|
|
+ MainWindow mainWindow = new MainWindow();
|
|
|
this.Close();
|
|
|
- variant.Show();
|
|
|
+ mainWindow.Show();
|
|
|
}
|
|
|
|
|
|
//Выбор строки из БД
|
|
@@ -77,6 +76,7 @@ namespace HotelCalifornia
|
|
|
otchestvotxt.Text = rowView["MiddleName"].ToString();
|
|
|
logintxt.Text = rowView["Login"].ToString();
|
|
|
passwordtxt.Password = rowView["Password"].ToString();
|
|
|
+ rolecombo.Text = rowView["Name_Role"].ToString();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -88,7 +88,7 @@ namespace HotelCalifornia
|
|
|
//Добавление администратора
|
|
|
private void Add_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Password == "")
|
|
|
+ if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Password == "" || rolecombo.Text == "")
|
|
|
{
|
|
|
MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -110,7 +110,12 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string sql = "INSERT INTO Administrator (LastName,FirstName,MiddleName,Login,Password) VALUES('" + familiyatxt.Text + "','" + nametxt.Text + "','" + otchestvotxt.Text + "','" + logintxt.Text + "','" + passwordtxt.Password + "')";
|
|
|
+ string idrole = "";
|
|
|
+ if (rolecombo.Text == "Администратор")
|
|
|
+ idrole = "1";
|
|
|
+ else
|
|
|
+ idrole = "2";
|
|
|
+ string sql = "INSERT INTO Administrator (LastName,FirstName,MiddleName,Login,Password,ID_Role) VALUES('" + familiyatxt.Text + "','" + nametxt.Text + "','" + otchestvotxt.Text + "','" + logintxt.Text + "','" + passwordtxt.Password + "', '" + idrole.ToString() + "')";
|
|
|
SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
con.Close();
|
|
@@ -121,6 +126,7 @@ namespace HotelCalifornia
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
passwordtxt.Password = "";
|
|
|
+ rolecombo.Text = "";
|
|
|
MessageBox.Show("Администратор был добавлен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
}
|
|
@@ -139,7 +145,7 @@ namespace HotelCalifornia
|
|
|
{
|
|
|
MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
- else if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Password == "")
|
|
|
+ else if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Password == "" || rolecombo.Text == "")
|
|
|
{
|
|
|
MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -148,7 +154,12 @@ namespace HotelCalifornia
|
|
|
try
|
|
|
{
|
|
|
con.Open();
|
|
|
- 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 + "'";
|
|
|
+ string idrole = "";
|
|
|
+ if (rolecombo.Text == "Администратор")
|
|
|
+ idrole = "1";
|
|
|
+ else
|
|
|
+ idrole = "2";
|
|
|
+ string sql = "Update Administrator set FirstName ='" + nametxt.Text + "', LastName = '" + familiyatxt.Text + "', MiddleName = '" + otchestvotxt.Text + "', Login = '" + logintxt.Text + "', Password = '" + passwordtxt.Password + "', ID_Role = '"+idrole.ToString()+"' where ID_Administrator = '" + idtxt.Text + "'";
|
|
|
SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
dataAdapter.SelectCommand.ExecuteNonQuery();
|
|
|
con.Close();
|
|
@@ -158,6 +169,7 @@ namespace HotelCalifornia
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
passwordtxt.Password = "";
|
|
|
+ rolecombo.Text = "";
|
|
|
showgrid();
|
|
|
MessageBox.Show("Администратор был изменен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -191,6 +203,7 @@ namespace HotelCalifornia
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
passwordtxt.Password = "";
|
|
|
+ rolecombo.Text = "";
|
|
|
showgrid();
|
|
|
MessageBox.Show("Администратор удален!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
@@ -256,7 +269,7 @@ namespace HotelCalifornia
|
|
|
try
|
|
|
{
|
|
|
con.Open();
|
|
|
- string sql = "SELECT * From Administrator";
|
|
|
+ string sql = "SELECT ID_Administrator,LastName, FirstName, MiddleName, Login, Password, [Name_Role] From Administrator inner join Role on Administrator.ID_Role = Role.ID_Role";
|
|
|
SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
|
|
|
DataTable data = new DataTable("Administrator");
|
|
|
dataAdapter.Fill(data);
|
|
@@ -268,6 +281,7 @@ namespace HotelCalifornia
|
|
|
datastaff.Columns[2].Header = "Имя";
|
|
|
datastaff.Columns[3].Header = "Отчество";
|
|
|
datastaff.Columns[4].Header = "Логин";
|
|
|
+ datastaff.Columns[6].Header = "Роль";
|
|
|
datastaff.Columns[5].Visibility = Visibility.Collapsed;
|
|
|
datastaff.Columns[0].Visibility = Visibility.Collapsed;
|
|
|
}
|
|
@@ -278,6 +292,32 @@ namespace HotelCalifornia
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void fillrolecombo()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ rolecombo.Items.Clear();
|
|
|
+ con.Open();
|
|
|
+ SqlCommand sql = con.CreateCommand();
|
|
|
+ sql.CommandType = CommandType.Text;
|
|
|
+ sql.CommandText = "Select Name_Role from Role";
|
|
|
+ sql.ExecuteNonQuery();
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ SqlDataAdapter da = new SqlDataAdapter(sql);
|
|
|
+ da.Fill(dt);
|
|
|
+ foreach (DataRow dr in dt.Rows)
|
|
|
+ {
|
|
|
+ rolecombo.Items.Add(dr["Name_Role"].ToString());
|
|
|
+ }
|
|
|
+ con.Close();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ con.Close();
|
|
|
+ MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//Обновление
|
|
|
private void Refresh_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
@@ -288,18 +328,26 @@ namespace HotelCalifornia
|
|
|
otchestvotxt.Text = "";
|
|
|
logintxt.Text = "";
|
|
|
passwordtxt.Password = "";
|
|
|
+ rolecombo.Text = "";
|
|
|
}
|
|
|
|
|
|
//Перетаскивание окна
|
|
|
private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
|
|
|
{
|
|
|
- DragMove();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ DragMove();
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//Запуск в самом начале
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
showgrid();
|
|
|
+ fillrolecombo();
|
|
|
}
|
|
|
}
|
|
|
}
|