gr682_bpv 4 years ago
parent
commit
6db741cd45

+ 5 - 2
HotelCalifornia/Client.xaml

@@ -14,13 +14,13 @@
                 <GradientStop Color="#383E7A" Offset="0"/>
             </LinearGradientBrush>
         </Grid.Background>
-        <Label Content="Информация о клиентах" Foreground="White" FontSize="35" FontFamily="Century Gothic" HorizontalAlignment="Center" Margin="148,54,148,336.6"/>
+        <Label Content="Клиенты" Foreground="White" FontSize="35" FontFamily="Century Gothic" HorizontalAlignment="Center" Margin="148,54,148,336.6"/>
         <StackPanel Margin="6,134,547,58.6" Orientation="Vertical">
             <TextBox Name="familiatxt" Margin="10,0,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="15"
   materialDesign:HintAssist.Hint="Фамилия клиента"/>
             <TextBox Name="nametxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="15"
   materialDesign:HintAssist.Hint="Имя клиента"/>
-            <TextBox Name="otchestvotxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="25"
+            <TextBox Name="otchestvotxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="15"
   materialDesign:HintAssist.Hint="Отчество клиента"/>
             <ComboBox Margin="10,10,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
              materialDesign:ColorZoneAssist.Mode="Inverted" materialDesign:HintAssist.Hint="Страна">
@@ -36,7 +36,10 @@
     Content="Казахстан" />
                 <ComboBoxItem
     Content="Белоруссия" />
+                <ComboBoxItem
+    Content="Другая..." />
             </ComboBox>
+            
         </StackPanel>
         <StackPanel Margin="0,320,547,43.6" Orientation="Horizontal">
             <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Добавить" Margin="25,0,0,0">

+ 26 - 3
HotelCalifornia/MainWindow.xaml.cs

@@ -13,6 +13,8 @@ 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
 {
@@ -25,6 +27,8 @@ namespace HotelCalifornia
         {
             InitializeComponent();        
         }
+
+        SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=kursah;Integrated Security=True");
  
         //Перетаскивание окна
         private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
@@ -57,9 +61,28 @@ namespace HotelCalifornia
                 }
                 else
                 {
-                    Variant variant = new Variant();
-                    this.Close();
-                    variant.Show();
+                    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)
+                    {
+                        Variant variant = new Variant();                    
+                        string username = dataSet.Tables[0].Rows[0]["ID_Administrator"].ToString();
+                        variant.idadmintxt.Text = username;
+                        con.Close();
+                        MessageBox.Show("Добро пожаловать!", "Вход", MessageBoxButton.OK, MessageBoxImage.Information);
+                        variant.Show();
+                        this.Close();
+                    }
+                    else
+                    {
+                        con.Close();
+                        MessageBox.Show("Такого Администратора нет в системе!", "Вход", MessageBoxButton.OK, MessageBoxImage.Information);
+                    }
                 }
             }
             catch (Exception ex)

+ 7 - 3
HotelCalifornia/Room.xaml

@@ -7,7 +7,7 @@
         xmlns:local="clr-namespace:HotelCalifornia"
         mc:Ignorable="d"
         Title="Room" Height="450" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" Icon="image/h1.png">
-    <Grid MouseDown="Grid_MouseDown" >
+    <Grid MouseDown="Grid_MouseDown" Loaded="Grid_Loaded" >
         <Grid.Background>
             <LinearGradientBrush StartPoint="0.1,0" EndPoint="0.9,1">
                 <GradientStop Color="#7E42F5" Offset="1" />
@@ -15,7 +15,7 @@
             </LinearGradientBrush>
         </Grid.Background>
         <Label Content="Комнаты" Foreground="White" FontSize="35" FontFamily="Century Gothic" HorizontalAlignment="Center" Margin="167,46,167,344.6"/>
-        <DataGrid Name="dataroom" IsReadOnly="True" HorizontalAlignment="Left" Height="257" Margin="293,138,0,0" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Top" Width="497" />
+        <DataGrid Name="dataroom" IsReadOnly="True" HorizontalAlignment="Left" Height="257" Margin="293,138,0,0" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Top" Width="497" SelectionChanged="dataroom_SelectionChanged" />
         <StackPanel Margin="6,124,547,175.6" Orientation="Vertical">
             <TextBox Name="numbertxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="3"
   materialDesign:HintAssist.Hint="Номер комнаты" PreviewTextInput="numbertxt_PreviewTextInput" PreviewKeyDown="numbertxt_PreviewKeyDown"/>
@@ -49,6 +49,10 @@
   Style="{StaticResource MaterialDesignIconButton}" ToolTip="Свернуть окно" Margin="694,10,58,391.6" Click="WindMin_Click">
             <materialDesign:PackIcon Kind="WindowMinimize" Foreground="White"/>
         </Button>
-        <TextBlock Name="timetxt" HorizontalAlignment="Center" FontFamily="Century Gothic" Margin="561,105,10,0" TextWrapping="Wrap" Foreground="White" FontSize="22" VerticalAlignment="Top" Height="28" Width="229"/>
+        <TextBlock Name="timetxt" HorizontalAlignment="Center" FontFamily="Century Gothic" Margin="561,88,10,0" TextWrapping="Wrap" Foreground="White" FontSize="22" VerticalAlignment="Top" Height="28" Width="229"/>
+        <TextBlock Name="idroomtxt" Visibility="Hidden"/>
+        <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Обновить" Margin="508,76,244,325.6" Click="Refresh_Click">
+            <materialDesign:PackIcon Kind="Refresh" />
+        </Button>
     </Grid>
 </Window>

+ 156 - 5
HotelCalifornia/Room.xaml.cs

@@ -16,6 +16,7 @@ using System.Windows.Threading;
 using System.Data;
 using System.Data.SqlClient;
 
+
 namespace HotelCalifornia
 {
     /// <summary>
@@ -33,7 +34,8 @@ namespace HotelCalifornia
         }
 
         //Строка подключения
-        SqlConnection con = new SqlConnection("");
+        SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=kursah;Integrated Security=True");
+        string status = "";
 
         private void Update_Timer_Tick(object sender, EventArgs e)
         {
@@ -115,16 +117,48 @@ namespace HotelCalifornia
                 {
                     MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
                 }
+                else if (numbertxt.Text.Length < 3 || telephonetxt.Text.Length < 9)
+                {
+                    MessageBox.Show("Поля не полностью заполены!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
                 else
                 {
-                    MessageBox.Show("Комната добавлена!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                    con.Open();
+                    SqlCommand cmd = new SqlCommand("Select * from Room where Number_Room ='" + numbertxt.Text + "'", 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)
+                    {
+                        MessageBox.Show("Такая комната уже есть!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                        con.Close();
+                    }
+                    else
+                    {
+                        if (yescheck.IsChecked == true)
+                            status = "1";
+                        else
+                            status = "2";
+                        string reg = "INSERT INTO Room (Number_Room,Telephone_Room,Status_Room) VALUES('" + numbertxt.Text + "','" + telephonetxt.Text + "','" + status.ToString() + "')";
+                        SqlDataAdapter dataAdapter = new SqlDataAdapter(reg, con);
+                        dataAdapter.SelectCommand.ExecuteNonQuery();
+                        con.Close();
+                        idroomtxt.Text = "";
+                        numbertxt.Text = "";
+                        telephonetxt.Text = "";
+                        yescheck.IsChecked = true;
+                        showgrid();
+                        MessageBox.Show("Комната добавлена!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                    }
                 }
             }
             catch (Exception ex)
             {
+                con.Close();
                 MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
             }
-
         }
 
         private void WindMin_Click(object sender, RoutedEventArgs e)
@@ -136,13 +170,43 @@ namespace HotelCalifornia
         {
             try
             {
-                if (numbertxt.Text == "" || telephonetxt.Text == "")
+                if (idroomtxt.Text == "")
+                {
+                    MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
+                else if (numbertxt.Text == "" || telephonetxt.Text == "")
                 {
                     MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
                 }
+                else if (numbertxt.Text.Length < 3 || telephonetxt.Text.Length < 9)
+                {
+                    MessageBox.Show("Поля не полностью заполены!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
                 else
                 {
-                    MessageBox.Show("Комната добавлена!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                    try
+                    {
+                        if (yescheck.IsChecked == true)
+                            status = "1";
+                        else
+                            status = "2";
+                        con.Open();
+                        string sql = "Update Room set Number_Room ='" + numbertxt.Text + "', Telephone_Room = '" + telephonetxt.Text + "', Status_Room = '" + status.ToString() + "' where ID_Room = '" + idroomtxt.Text + "'";
+                        SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
+                        dataAdapter.SelectCommand.ExecuteNonQuery();
+                        con.Close();
+                        idroomtxt.Text = "";
+                        numbertxt.Text = "";
+                        telephonetxt.Text = "";
+                        yescheck.IsChecked = true;
+                        showgrid();
+                        MessageBox.Show("Комната изменена!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                    }
+                    catch (Exception ex)
+                    {
+                        con.Close();
+                        MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                    }
                 }
             }
             catch (Exception ex)
@@ -153,7 +217,94 @@ namespace HotelCalifornia
 
         private void Delete_Click(object sender, RoutedEventArgs e)
         {
+            if (idroomtxt.Text == "")
+            {
+                MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+            else
+            {
+                try
+                {
+                    con.Open();
+                    string sql = "DELETE FROM Room WHERE ID_Room = '" + idroomtxt.Text + "'";
+                    SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
+                    dataAdapter.SelectCommand.ExecuteNonQuery();
+                    con.Close();
+                    idroomtxt.Text = "";
+                    numbertxt.Text = "";
+                    telephonetxt.Text = "";
+                    yescheck.IsChecked = true;
+                    showgrid();
+                    MessageBox.Show("Комната удалена!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
+                catch (Exception ex)
+                {
+                    con.Close();
+                    MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                }
+            }
+        }
+
+        private void Grid_Loaded(object sender, RoutedEventArgs e)
+        {
+            showgrid();
+        }
+
+        void showgrid()
+        {
+            try
+            {
+                con.Open();
+                string rke = "SELECT ID_Room, Number_Room, Telephone_Room, RoomStatus.Status From Room inner join RoomStatus on RoomStatus.ID_Status = Room.Status_Room";
+                SqlDataAdapter dataAdapter = new SqlDataAdapter(rke, con);
+                DataTable data = new DataTable("Room");
+                dataAdapter.Fill(data);
+                dataroom.ItemsSource = data.DefaultView;
+                dataAdapter.Update(data);
+                con.Close();
+                dataroom.Columns[0].Header = "ID";
+                dataroom.Columns[1].Header = "Номер комнты";
+                dataroom.Columns[2].Header = "Телефон комнаты";
+                dataroom.Columns[3].Header = "Статус комнаты";
+                dataroom.Columns[0].Visibility = Visibility.Collapsed;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+        }
+
+        private void dataroom_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            try
+            {
+                DataGrid gd = (DataGrid)sender;
+                DataRowView rowView = gd.SelectedItem as DataRowView;
+                if (rowView != null)
+                {
+                    idroomtxt.Text = rowView["ID_Room"].ToString();
+                    numbertxt.Text = rowView["Number_Room"].ToString();
+                    telephonetxt.Text = rowView["Telephone_Room"].ToString();
+                    status = rowView["Status"].ToString();
+                    if (status == "Свободна")
+                        yescheck.IsChecked = true;
+                    else
+                        nocheck.IsChecked = true;
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+        }
 
+        private void Refresh_Click(object sender, RoutedEventArgs e)
+        {
+            showgrid();
+            idroomtxt.Text = "";
+            numbertxt.Text = "";
+            telephonetxt.Text = "";
+            yescheck.IsChecked = true;
         }
     }
 }

+ 13 - 8
HotelCalifornia/Staff.xaml

@@ -7,7 +7,7 @@
         xmlns:local="clr-namespace:HotelCalifornia"
         mc:Ignorable="d"
         Title="Staff" Height="450" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" Icon="image/h1.png">
-    <Grid>
+    <Grid Loaded="Grid_Loaded">
         <Grid.Background>
             <LinearGradientBrush StartPoint="0.1,0" EndPoint="0.9,1">
                 <GradientStop Color="#7E42F5" Offset="1" />
@@ -26,16 +26,16 @@
             <materialDesign:PackIcon Kind="Backburger"  Foreground="White"/>
         </Button>
         <StackPanel Margin="6,124,547,85.6" Orientation="Vertical">
-            <TextBox x:Name="nametxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="10"
-                materialDesign:HintAssist.Hint="Имя работника"/>
             <TextBox x:Name="familiyatxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="15"
-                materialDesign:HintAssist.Hint="Фамилия работника"/>
+                materialDesign:HintAssist.Hint="Фамилия работника" TextChanged="familiyatxt_TextChanged"/>
+            <TextBox x:Name="nametxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="10"
+                materialDesign:HintAssist.Hint="Имя работника" TextChanged="nametxt_TextChanged"/>
             <TextBox x:Name="otchestvotxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="15"
-                materialDesign:HintAssist.Hint="Отчество работника"/>
+                materialDesign:HintAssist.Hint="Отчество работника" TextChanged="otchestvotxt_TextChanged"/>
             <TextBox x:Name="logintxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="10"
-                materialDesign:HintAssist.Hint="Логин работника"/>
+                materialDesign:HintAssist.Hint="Логин работника" TextChanged="logintxt_TextChanged"/>
             <TextBox x:Name="passwordtxt" Margin="10,15,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" MaxLength="10"
-                materialDesign:HintAssist.Hint="Пароль работника"/>
+                materialDesign:HintAssist.Hint="Пароль работника" TextChanged="passwordtxt_TextChanged"/>
         </StackPanel>
         <StackPanel Margin="6,364,547,-0.4" Orientation="Horizontal">
             <Button x:Name="Add" Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Добавить" Margin="25,0,0,0" Click="Add_Click">
@@ -48,6 +48,11 @@
                 <materialDesign:PackIcon Kind="Delete" />
             </Button>
         </StackPanel>
-        <DataGrid Name="datastaff" IsReadOnly="True" HorizontalAlignment="Left" Height="273" Margin="258,124,0,0" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Top" Width="532" SelectionChanged="datastaff_SelectionChanged" />
+        <DataGrid Name="datastaff" IsReadOnly="True" HorizontalAlignment="Left" Height="273" Margin="258,130,0,0" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Top" Width="532" SelectionChanged="datastaff_SelectionChanged"/>
+        <TextBlock Name="timetxt" HorizontalAlignment="Center" FontFamily="Century Gothic" Margin="561,88,10,0" TextWrapping="Wrap" Foreground="White" FontSize="22" VerticalAlignment="Top" Height="28" Width="229"/>
+        <TextBlock Name="idtxt" Visibility="Hidden"/>
+        <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Обновить" Margin="508,76,244,325.6" Click="Refresh_Click">
+            <materialDesign:PackIcon Kind="Refresh" />
+        </Button>
     </Grid>
 </Window>

+ 229 - 4
HotelCalifornia/Staff.xaml.cs

@@ -11,6 +11,9 @@ using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Shapes;
+using System.Windows.Threading;
+using System.Data.SqlClient;
+using System.Data;
 
 namespace HotelCalifornia
 {
@@ -22,11 +25,30 @@ namespace HotelCalifornia
         public Staff()
         {
             InitializeComponent();
+            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");
+
+        private void Update_Timer_Tick(object sender, EventArgs e)
+        {
+            timetxt.Text = DateTime.Now.ToString();
         }
 
         private void Close(object sender, RoutedEventArgs e)
         {
-            Application.Current.Shutdown();
+            MessageBoxResult result = MessageBox.Show("Вы хотите выйти из приложения?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
+            switch (result)
+            {
+                case MessageBoxResult.Yes:
+                    Application.Current.Shutdown();
+                    break;
+                case MessageBoxResult.No:
+                    break;
+            }
         }
 
         private void WindMin_Click(object sender, RoutedEventArgs e)
@@ -51,22 +73,225 @@ namespace HotelCalifornia
 
         private void datastaff_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-
+            try
+            {
+                DataGrid gd = (DataGrid)sender;
+                DataRowView rowView = gd.SelectedItem as DataRowView;
+                if (rowView != null)
+                {
+                    idtxt.Text = rowView["ID_Administrator"].ToString();
+                    nametxt.Text = rowView["FirstName"].ToString();
+                    familiyatxt.Text = rowView["LastName"].ToString();
+                    otchestvotxt.Text = rowView["MiddleName"].ToString();
+                    logintxt.Text = rowView["Login"].ToString();
+                    passwordtxt.Text = rowView["Password"].ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
         }
 
         private void Add_Click(object sender, RoutedEventArgs e)
         {
-
+            if (familiyatxt.Text == "" || nametxt.Text == "" || otchestvotxt.Text == "" || logintxt.Text == "" || passwordtxt.Text == "")
+            {
+                MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+            else
+            {
+                try
+                {
+                    con.Open();
+                    SqlCommand cmd = new SqlCommand("Select * from Administrator where Login ='" + logintxt.Text + "'", 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)
+                    {
+                        MessageBox.Show("Такой Администратор уже создан!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                        con.Close();
+                    }
+                    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);
+                        dataAdapter.SelectCommand.ExecuteNonQuery();
+                        con.Close();
+                        showgrid();
+                        idtxt.Text = "";
+                        nametxt.Text = "";
+                        familiyatxt.Text = "";
+                        otchestvotxt.Text = "";
+                        logintxt.Text = "";
+                        passwordtxt.Text = "";
+                        MessageBox.Show("Администратор был добавлен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    con.Close();
+                    MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                }
+            }
         }
 
         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 == "")
+            {
+                MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+            else
+            {
+                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 + "'";
+                    SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
+                    dataAdapter.SelectCommand.ExecuteNonQuery();
+                    con.Close();
+                    idtxt.Text = "";
+                    nametxt.Text = "";
+                    familiyatxt.Text = "";
+                    otchestvotxt.Text = "";
+                    logintxt.Text = "";
+                    passwordtxt.Text = "";
+                    showgrid();
+                    MessageBox.Show("Администратор был изменен!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
+                catch (Exception ex)
+                {
+                    con.Close();
+                    MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                }
+            }
         }
 
         private void Delete_Click(object sender, RoutedEventArgs e)
         {
+            if (idtxt.Text == "")
+            {
+                MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+            else
+            {
+                try
+                {
+                    con.Open();
+                    string sql = "DELETE FROM Administrator WHERE ID_Administrator = '" + idtxt.Text + "'";
+                    SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
+                    dataAdapter.SelectCommand.ExecuteNonQuery();
+                    con.Close();
+                    idtxt.Text = "";
+                    nametxt.Text = "";
+                    familiyatxt.Text = "";
+                    otchestvotxt.Text = "";
+                    logintxt.Text = "";
+                    passwordtxt.Text = "";
+                    showgrid();
+                    MessageBox.Show("Администратор удален!", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
+                catch (Exception ex)
+                {
+                    con.Close();
+                    MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                }
+            }
+        }
 
+        private void nametxt_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (sender is TextBox textBox)
+            {
+                textBox.Text = new string
+               (textBox.Text.Where(ch => (ch >= 'А' && ch <= 'Я') || (ch >= 'а' && ch <= 'я')).ToArray());
+            }
+        }
+
+        private void familiyatxt_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (sender is TextBox textBox)
+            {
+                textBox.Text = new string
+               (textBox.Text.Where(ch => (ch >= 'А' && ch <= 'Я') || (ch >= 'а' && ch <= 'я')).ToArray());
+            }
+        }
+
+        private void otchestvotxt_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (sender is TextBox textBox)
+            {
+                textBox.Text = new string
+               (textBox.Text.Where(ch => (ch >= 'А' && ch <= 'Я') || (ch >= 'а' && ch <= 'я')).ToArray());
+            }
+        }
+
+        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_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 Grid_Loaded(object sender, RoutedEventArgs e)
+        {
+            showgrid();
+        }
+
+        void showgrid()
+        {
+            try
+            {
+                con.Open();
+                string rke = "SELECT * From Administrator";
+                SqlDataAdapter dataAdapter = new SqlDataAdapter(rke, con);
+                DataTable data = new DataTable("Administrator");
+                dataAdapter.Fill(data);
+                datastaff.ItemsSource = data.DefaultView;
+                dataAdapter.Update(data);
+                con.Close();
+                datastaff.Columns[0].Header = "ID";
+                datastaff.Columns[1].Header = "Фамилия";
+                datastaff.Columns[2].Header = "Имя";
+                datastaff.Columns[3].Header = "Отчество";
+                datastaff.Columns[4].Header = "Логин";
+                datastaff.Columns[5].Header = "Пароль";
+                datastaff.Columns[0].Visibility = Visibility.Collapsed;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+        }
+
+        private void Refresh_Click(object sender, RoutedEventArgs e)
+        {
+            showgrid();
+            idtxt.Text = "";
+            nametxt.Text = "";
+            familiyatxt.Text = "";
+            otchestvotxt.Text = "";
+            logintxt.Text = "";
+            passwordtxt.Text = "";
         }
     }
 }

+ 1 - 0
HotelCalifornia/Variant.xaml

@@ -68,5 +68,6 @@
             <materialDesign:PackIcon
     Kind="WindowMinimize" Foreground="White"/>
         </Button>
+        <TextBlock Name="idadmintxt" Visibility="Hidden"/>
     </Grid>
 </Window>

+ 1 - 1
HotelCalifornia/Variant.xaml.cs

@@ -112,7 +112,7 @@ namespace HotelCalifornia
         //Переход к окну работников
         private void StaffGO_Click(object sender, RoutedEventArgs e)
         {
-            MessageBoxResult result = MessageBox.Show("Вы хотите перейти к окну комнат?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
+            MessageBoxResult result = MessageBox.Show("Вы хотите перейти к окну работников?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
             switch (result)
             {
                 case MessageBoxResult.Yes: