gr682_bpv 4 rokov pred
rodič
commit
6bba0c8480
2 zmenil súbory, kde vykonal 35 pridanie a 15 odobranie
  1. 3 3
      HotelCalifornia/Rezerv.xaml
  2. 32 12
      HotelCalifornia/Rezerv.xaml.cs

+ 3 - 3
HotelCalifornia/Rezerv.xaml

@@ -26,16 +26,16 @@
             <materialDesign:PackIcon
     Kind="WindowMinimize" Foreground="White"/>
         </Button>
-        <StackPanel Margin="6,158,534,86.6" Orientation="Vertical">
+        <StackPanel Margin="6,158,534,66.6" Orientation="Vertical">
             <ComboBox BorderBrush="White" Name="clientcombo" Margin="10,0,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
              materialDesign:ColorZoneAssist.Mode="Inverted" materialDesign:HintAssist.Hint="Клиент" Height="48"/>
             <ComboBox BorderBrush="White" Name="roomcombo" Margin="10,0,0,0" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
              materialDesign:ColorZoneAssist.Mode="Inverted" materialDesign:HintAssist.Hint="Комната" Height="48"/>
             <DatePicker Name="datein" Foreground="White" BorderBrush="White"  Margin="10,10,0,0" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" FontSize="18" FontFamily="Century Gothic" SelectedDateFormat="Short" materialDesign:HintAssist.Hint="Дата прибытия"/>
-            <DatePicker Name="dateout" Foreground="White" BorderBrush="White"  Margin="10,15,0,0" Style="{StaticResource MaterialDesignDatePicker}" FontSize="18" FontFamily="Century Gothic" SelectedDateFormat="Short" materialDesign:HintAssist.Hint="Дата отъезда"/>
+            <DatePicker Name="dateout" Foreground="White" BorderBrush="White"  Margin="10,15,0,0" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" FontSize="18" FontFamily="Century Gothic" SelectedDateFormat="Short" materialDesign:HintAssist.Hint="Дата отъезда"/>
         </StackPanel>
         <DataGrid Name="datarezerv" IsReadOnly="True" HorizontalAlignment="Left" Height="257" Margin="290,158,0,0" VerticalAlignment="Top" Width="497" SelectionChanged="datarezerv_SelectionChanged" />
-        <StackPanel Margin="13,362,534,1.6" Orientation="Horizontal">
+        <StackPanel Margin="15,374,532,-10.4" Orientation="Horizontal">
             <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Добавить" Margin="25,0,0,0" Click="Add_Click">
                 <materialDesign:PackIcon Kind="Add" />
             </Button>

+ 32 - 12
HotelCalifornia/Rezerv.xaml.cs

@@ -30,6 +30,9 @@ namespace HotelCalifornia
             timer.Tick += new EventHandler(Update_Timer_Tick);
             timer.Interval = new TimeSpan(0, 0, 1);
             timer.Start();
+            //Начало даты
+            datein.DisplayDateStart = DateTime.Now;
+            dateout.DisplayDateStart = DateTime.Now;
         }
 
         //Строка подключения
@@ -80,6 +83,8 @@ namespace HotelCalifornia
                     numbroomtxt.Text = rowView["Number_Room"].ToString();
                     datein.Text = rowView["Date_in"].ToString();
                     dateout.Text = rowView["Date_out"].ToString();
+                    clientcombo.Text = rowView["LastName_Client"].ToString();
+                    roomcombo.Text = rowView["Number_Room"].ToString();
                     roomcombo.IsEnabled = false;
                     clientcombo.IsEnabled = false;
                 }
@@ -187,6 +192,10 @@ namespace HotelCalifornia
             {
                 MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
             }
+            else if (datein.SelectedDate >= dateout.SelectedDate)
+            {
+                MessageBox.Show("Дата указана неверно!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
             else
             {
                 try
@@ -201,7 +210,7 @@ namespace HotelCalifornia
                     if (dataSet.Tables[0].Rows.Count > 0)
                     {
                         string stridclient = dataSet.Tables[0].Rows[0]["ID_Client"].ToString();
-                        SqlCommand cmd2 = new SqlCommand("Select * from Rezervirovanie where ID_Client = '" + stridclient.ToString() + "'", con);
+                        SqlCommand cmd2 = new SqlCommand("Select * from Rezervirovanie where ID_Client = '" + stridclient.ToString() + "'; Select * from RoomClient where ID_Client = '" + stridclient.ToString() + "'", con);
                         cmd2.CommandType = CommandType.Text;
                         SqlDataAdapter adapter2 = new SqlDataAdapter();
                         adapter2.SelectCommand = cmd2;
@@ -210,7 +219,12 @@ namespace HotelCalifornia
                         if (dataSet2.Tables[0].Rows.Count > 0)
                         {
                             con.Close();
-                            MessageBox.Show("Клиент уже забронировал комнату", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                            MessageBox.Show("Клиент уже забронировал комнату!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                        }
+                        else if (dataSet2.Tables[1].Rows.Count > 0)
+                        {
+                            con.Close();
+                            MessageBox.Show("Клиент уже заселён!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
                         }
                         else
                         {
@@ -228,18 +242,19 @@ namespace HotelCalifornia
                                 SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
                                 dataAdapter.SelectCommand.ExecuteNonQuery();
                                 con.Close();
-                                fillcomboroom();
-                                fill1comboroom();
-                                roomcombo.Text = "";
-                                clientcombo.Text = "";
-                                datein.SelectedDate = null;
-                                dateout.SelectedDate = null;
-                                showgrid();
                                 MessageBox.Show("Бронирование успешно создано!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
                             }
                         }
+                    }
+                    fillcomboroom();
+                    fill1comboroom();
+                    roomcombo.Text = "";
+                    clientcombo.Text = "";
+                    datein.SelectedDate = null;
+                    dateout.SelectedDate = null;
+                    showgrid();
                 }             
-            }
+            
                 catch (Exception ex)
                 {
                     con.Close();
@@ -259,6 +274,10 @@ namespace HotelCalifornia
             {
                 MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
             }
+            else if (datein.SelectedDate >= dateout.SelectedDate)
+            {
+                MessageBox.Show("Дата указана неверно!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
             else
             {
                 try
@@ -308,7 +327,7 @@ namespace HotelCalifornia
                 try
                 {
                     con.Open();
-                    SqlCommand cmd1 = new SqlCommand("Select ID_Room from Room where Number_Room = '" + numbroomtxt.Text + "'", con);
+                    SqlCommand cmd1 = new SqlCommand("Select ID_Room from Room where Number_Room = '" + numbroomtxt.Text + "'; Select ID_Client From Client where LastName_Client = '" + clientcombo.Text + "'", con);
                     cmd1.CommandType = CommandType.Text;
                     SqlDataAdapter adapter1 = new SqlDataAdapter();
                     adapter1.SelectCommand = cmd1;
@@ -317,7 +336,8 @@ namespace HotelCalifornia
                     if (dataSet1.Tables[0].Rows.Count > 0)
                     {
                         string stridroom = dataSet1.Tables[0].Rows[0]["ID_Room"].ToString();
-                        string sql = "DELETE FROM Rezervirovanie WHERE ID_Room = '" + stridroom.ToString() + "'; Update Room set Status_Room ='" + 1 + "' Where ID_Room = '" + stridroom.ToString() + "' ";
+                        string stridclient = dataSet1.Tables[1].Rows[0]["ID_Client"].ToString();
+                        string sql = "DELETE FROM Rezervirovanie WHERE ID_Room = '" + stridroom.ToString() + "'; Update Room set Status_Room ='" + 1 + "' Where ID_Room = '" + stridroom.ToString() + "'; DELETE FROM RoomClient WHERE ID_Client = '" + stridclient.ToString() + "';";
                         SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
                         dataAdapter.SelectCommand.ExecuteNonQuery();
                         con.Close();