gr682_bpv 4 年之前
父节点
当前提交
b84968185a

+ 10 - 10
HotelCalifornia/ClientRoom.xaml

@@ -14,7 +14,7 @@
                 <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="215,46,215,344.6"/>
         <Button
   Style="{StaticResource MaterialDesignIconButton}"
   ToolTip="Выход из приложения" Margin="742,10,10,391.6" Click="Close">
@@ -23,32 +23,32 @@
         </Button>
         <Button
   Style="{StaticResource MaterialDesignIconButton}"
-  ToolTip="Вернуться к окну авторизации" Margin="10,10,742,391.6" Click="Back">
+  ToolTip="Вернуться к окну выбора функции" Margin="10,10,742,391.6" Click="Back">
             <materialDesign:PackIcon
     Kind="Backburger"  Foreground="White"/>
         </Button>
-        <TextBlock Name="timetxt" HorizontalAlignment="Center" FontFamily="Century Gothic" Margin="561,110,10,0" TextWrapping="Wrap" Foreground="White" FontSize="22" VerticalAlignment="Top" Height="28" Width="229"/>
+        <TextBlock Name="timetxt" HorizontalAlignment="Center" FontFamily="Century Gothic" Margin="561,115,10,0" TextWrapping="Wrap" Foreground="White" FontSize="22" VerticalAlignment="Top" Height="28" Width="229"/>
         <Button Name="WindMin"
   Style="{StaticResource MaterialDesignIconButton}"
   ToolTip="Свернуть окно" Margin="694,10,58,391.6" Click="WindMin_Click">
             <materialDesign:PackIcon
     Kind="WindowMinimize" Foreground="White"/>
         </Button>
-        <DataGrid Name="dataclientroom" IsReadOnly="True" HorizontalAlignment="Left" Height="257" Margin="293,138,0,0" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Top" Width="497" SelectionChanged="dataClientRoom_SelectionChanged"/>
-        <ComboBox Name="roomcombo" Margin="10,138,534,263.6" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
+        <DataGrid Name="dataclientroom" IsReadOnly="True" HorizontalAlignment="Left" Height="257" Margin="293,158,0,0" BorderThickness="1" BorderBrush="Black" VerticalAlignment="Top" Width="497" SelectionChanged="dataClientRoom_SelectionChanged"/>
+        <ComboBox Name="roomcombo" Margin="10,158,534,243.6" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
              materialDesign:ColorZoneAssist.Mode="Inverted" materialDesign:HintAssist.Hint="Комната" Height="48"/>
-        <ComboBox Name="clientcombo" Margin="10,204,534,197.6" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
+        <ComboBox Name="clientcombo" Margin="10,224,534,177.6" FontSize="18" FontFamily="Century Gothic" Foreground="White" Style="{StaticResource MaterialDesignFloatingHintComboBox}"
              materialDesign:ColorZoneAssist.Mode="Inverted" materialDesign:HintAssist.Hint="Клиент" Height="48"/>
-        <StackPanel Margin="10,292,537,71.6" Orientation="Horizontal">
+        <StackPanel Margin="62,312,589,51.6" Orientation="Horizontal">
             <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Добавить" Margin="25,0,0,0" Click="Add_Click">
                 <materialDesign:PackIcon Kind="Add" />
             </Button>
-            <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Редактировать" Margin="25,0,0,0" Click="Update_Click">
-                <materialDesign:PackIcon Kind="Edit" />
-            </Button>
             <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Удалить" Margin="25,0,0,0" Click="Delete_Click">
                 <materialDesign:PackIcon Kind="Delete" />
             </Button>
         </StackPanel>
+        <Button Style="{StaticResource MaterialDesignIconButton}" Foreground="White" ToolTip="Обновить" Margin="508,103,244,298.6" Click="Refresh_Click">
+            <materialDesign:PackIcon Kind="Refresh" />
+        </Button>
     </Grid>
 </Window>

+ 188 - 9
HotelCalifornia/ClientRoom.xaml.cs

@@ -70,27 +70,174 @@ namespace HotelCalifornia
 
         private void dataClientRoom_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-
+            try
+            {
+                DataGrid gd = (DataGrid)sender;
+                DataRowView rowView = gd.SelectedItem as DataRowView;
+                if (rowView != null)
+                {
+                    roomcombo.Text = rowView["Number_Room"].ToString();
+                    clientcombo.Text = rowView["LastName_Client"].ToString();
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
         }
 
         private void Add_Click(object sender, RoutedEventArgs e)
         {
-
-        }
-
-        private void Update_Click(object sender, RoutedEventArgs e)
-        {
-
+            try
+            {
+                if (clientcombo.Text == "" || roomcombo.Text == "")
+                {
+                    MessageBox.Show("Заполните все поля!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
+                else
+                {
+                    con.Open();
+                    SqlCommand cmd = new SqlCommand("Select * from Room where Number_Room ='" + roomcombo.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)
+                    {                        
+                        string idroom = dataSet.Tables[0].Rows[0]["ID_Room"].ToString();
+                        SqlCommand cmd1 = new SqlCommand("Select * from Client where LastName_Client ='" + clientcombo.Text + "'", con);
+                        cmd1.CommandType = CommandType.Text;
+                        SqlDataAdapter adapter1 = new SqlDataAdapter();
+                        adapter1.SelectCommand = cmd1;
+                        DataSet dataSet1 = new DataSet();
+                        adapter1.Fill(dataSet1);
+                        if (dataSet1.Tables[0].Rows.Count > 0)
+                        {
+                            string idclient = dataSet1.Tables[0].Rows[0]["ID_Client"].ToString();
+                            SqlCommand cmd2 = new SqlCommand("Select * from RoomClient where ID_Client = '"+ idclient.ToString() +"'", con);
+                            cmd2.CommandType = CommandType.Text;
+                            SqlDataAdapter adapter2 = new SqlDataAdapter();
+                            adapter2.SelectCommand = cmd2;
+                            DataSet dataSet2 = new DataSet();
+                            adapter2.Fill(dataSet2);
+                            if (dataSet2.Tables[0].Rows.Count > 0)
+                            {
+                                con.Close();
+                                MessageBox.Show("У клиента уже есть комната!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                            }
+                            else
+                            {
+                                string reg = "INSERT INTO RoomClient (ID_Room,ID_Client) VALUES('" + idroom.ToString() + "','" + idclient.ToString() + "')";
+                                SqlDataAdapter dataAdapter = new SqlDataAdapter(reg, con);
+                                dataAdapter.SelectCommand.ExecuteNonQuery();
+                                con.Close();
+                                showgrid();
+                                roomcombo.Text = "";
+                                clientcombo.Text = "";
+                                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 (roomcombo.Text == "" || clientcombo.Text == "")
+            {
+                MessageBox.Show("Поле не выбрано! Выберите нужное поле!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+            else
+            {
+                try
+                {
+                    con.Open();
+                    SqlCommand cmd = new SqlCommand("Select * from Room where Number_Room ='" + roomcombo.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)
+                    {
+                        string idroom = dataSet.Tables[0].Rows[0]["ID_Room"].ToString();
+                        SqlCommand cmd1 = new SqlCommand("Select * from Client where LastName_Client ='" + clientcombo.Text + "'", con);
+                        cmd1.CommandType = CommandType.Text;
+                        SqlDataAdapter adapter1 = new SqlDataAdapter();
+                        adapter1.SelectCommand = cmd1;
+                        DataSet dataSet1 = new DataSet();
+                        adapter1.Fill(dataSet1);
+                        if (dataSet1.Tables[0].Rows.Count > 0)
+                        {
+                            string idclient = dataSet1.Tables[0].Rows[0]["ID_Client"].ToString();
+                            SqlCommand cmd2 = new SqlCommand("Select * from RoomClient where ID_Client = '" + idclient.ToString() + "' and ID_Room = '" + idroom.ToString() + "'", con);
+                            cmd2.CommandType = CommandType.Text;
+                            SqlDataAdapter adapter2 = new SqlDataAdapter();
+                            adapter2.SelectCommand = cmd2;
+                            DataSet dataSet2 = new DataSet();
+                            adapter2.Fill(dataSet2);
+                            if (dataSet2.Tables[0].Rows.Count > 0)
+                            {
+                                string sql = "DELETE FROM RoomClient WHERE ID_Room = '" + idroom.ToString() + "' and ID_Client = '"+idclient.ToString()+"'";
+                                SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
+                                dataAdapter.SelectCommand.ExecuteNonQuery();
+                                con.Close();
+                                showgrid();
+                                roomcombo.Text = "";
+                                clientcombo.Text = "";
+                                MessageBox.Show("Запись удалена!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);                   
+                            }
+                            else
+                            {
+                                con.Close();
+                                roomcombo.Text = "";
+                                clientcombo.Text = "";
+                                MessageBox.Show("Такой записи нет!", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Information);
+                            }
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    con.Close();
+                    MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+                }
+            }
         }
 
         private void Window_Loaded(object sender, RoutedEventArgs e)
         {
             fillroomcombo();
+            fillclientcombo();
+            showgrid();
+        }
+
+        void showgrid()
+        {
+            try
+            {
+                con.Open();
+                string sql = "SELECT Number_Room, Client.LastName_Client From Room inner join RoomClient on Room.ID_Room = RoomClient.ID_Room inner join Client on RoomClient.ID_Client = Client.ID_Client";
+                SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
+                DataTable data = new DataTable("RoomClient");
+                dataAdapter.Fill(data);
+                dataclientroom.ItemsSource = data.DefaultView;
+                dataAdapter.Update(data);
+                con.Close();
+                dataclientroom.Columns[0].Header = "Номер комнты";
+                dataclientroom.Columns[1].Header = "Фамилия клиента";
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
         }
 
         void fillroomcombo()
@@ -102,7 +249,7 @@ namespace HotelCalifornia
                 con.Open();
                 SqlCommand sql = con.CreateCommand();
                 sql.CommandType = CommandType.Text;
-                sql.CommandText = "Select Number_Room from Room";
+                sql.CommandText = "Select Number_Room from Room WHERE Status_Room = 1";
                 sql.ExecuteNonQuery();
                 DataTable dt = new DataTable();
                 SqlDataAdapter da = new SqlDataAdapter(sql);
@@ -119,5 +266,37 @@ namespace HotelCalifornia
                 MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
+        void fillclientcombo()
+        {
+            try
+            {
+                clientcombo.Items.Clear();
+                con.Open();
+                SqlCommand sql = con.CreateCommand();
+                sql.CommandType = CommandType.Text;
+                sql.CommandText = "Select LastName_Client from Client";
+                sql.ExecuteNonQuery();
+                DataTable dt = new DataTable();
+                SqlDataAdapter da = new SqlDataAdapter(sql);
+                da.Fill(dt);
+                foreach (DataRow dr in dt.Rows)
+                {
+                    clientcombo.Items.Add(dr["LastName_Client"].ToString());
+                }
+                con.Close();
+            }
+            catch (Exception ex)
+            {
+                con.Close();
+                MessageBox.Show("Возникла ошибка! " + ex.ToString(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+        }
+
+        private void Refresh_Click(object sender, RoutedEventArgs e)
+        {
+            showgrid();
+            roomcombo.Text = "";
+            clientcombo.Text = "";
+        }
     }
 }

+ 7 - 0
HotelCalifornia/HotelCalifornia.csproj

@@ -69,6 +69,9 @@
     <Compile Include="ClientRoom.xaml.cs">
       <DependentUpon>ClientRoom.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Rezerv.xaml.cs">
+      <DependentUpon>Rezerv.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Room.xaml.cs">
       <DependentUpon>Room.xaml</DependentUpon>
     </Compile>
@@ -98,6 +101,10 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="Rezerv.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Room.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 30 - 0
HotelCalifornia/Rezerv.xaml

@@ -0,0 +1,30 @@
+<Window x:Class="HotelCalifornia.Rezerv"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+        xmlns:local="clr-namespace:HotelCalifornia"
+        mc:Ignorable="d"
+        Title="Rezerv" Height="450" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None" Icon="image/h1.png">
+    <Grid MouseDown="Grid_MouseDown">
+        <Grid.Background>
+            <LinearGradientBrush StartPoint="0.1,0" EndPoint="0.9,1">
+                <GradientStop Color="#7E42F5" Offset="1" />
+                <GradientStop Color="#383E7A" Offset="0"/>
+            </LinearGradientBrush>
+        </Grid.Background>
+        <Button Style="{StaticResource MaterialDesignIconButton}" ToolTip="Вернуться к окну выбора функции" Margin="10,10,742,391.6" Click="Back">
+            <materialDesign:PackIcon Kind="Backburger"  Foreground="White"/>
+        </Button>
+        <Button Style="{StaticResource MaterialDesignIconButton}" ToolTip="Выход из приложения" Margin="742,10,10,391.6" Click="Close">
+            <materialDesign:PackIcon Kind="ExitToApp" Foreground="White"/>
+        </Button>
+        <Button Name="WindMin"
+  Style="{StaticResource MaterialDesignIconButton}"
+  ToolTip="Свернуть окно" Margin="694,10,58,391.6" Click="WindMin_Click">
+            <materialDesign:PackIcon
+    Kind="WindowMinimize" Foreground="White"/>
+        </Button>
+    </Grid>
+</Window>

+ 57 - 0
HotelCalifornia/Rezerv.xaml.cs

@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+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.Shapes;
+
+namespace HotelCalifornia
+{
+    /// <summary>
+    /// Логика взаимодействия для Rezerv.xaml
+    /// </summary>
+    public partial class Rezerv : Window
+    {
+        public Rezerv()
+        {
+            InitializeComponent();
+        }
+
+        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
+        {
+            DragMove();
+        }
+
+        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;
+            }
+        }
+
+        private void WindMin_Click(object sender, RoutedEventArgs e)
+        {
+            this.WindowState = WindowState.Minimized;
+        }
+
+        private void Close(object sender, RoutedEventArgs e)
+        {
+            Application.Current.Shutdown();
+        }
+    }
+}

+ 2 - 2
HotelCalifornia/Room.xaml.cs

@@ -255,8 +255,8 @@ namespace HotelCalifornia
             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);
+                string sql = "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(sql, con);
                 DataTable data = new DataTable("Room");
                 dataAdapter.Fill(data);
                 dataroom.ItemsSource = data.DefaultView;

+ 1 - 1
HotelCalifornia/Variant.xaml

@@ -50,7 +50,7 @@
     Width="35" />
             </Button>
             <Button
-  Style="{StaticResource MaterialDesignFloatingActionLightButton}" Margin="100,0,0,0">
+  Style="{StaticResource MaterialDesignFloatingActionLightButton}" Margin="100,0,0,0" Click="RezervirovanieGO_Click">
                 <materialDesign:PackIcon
     Kind="Ticket"
     Height="35"

+ 15 - 0
HotelCalifornia/Variant.xaml.cs

@@ -139,5 +139,20 @@ namespace HotelCalifornia
                     break;
             }
         }
+
+        private void RezervirovanieGO_Click(object sender, RoutedEventArgs e)
+        {
+            MessageBoxResult result = MessageBox.Show("Вы хотите перейти к окну резервирования?", "Предупреждение", MessageBoxButton.YesNo, MessageBoxImage.Question);
+            switch (result)
+            {
+                case MessageBoxResult.Yes:
+                    Rezerv rezerv = new Rezerv();
+                    this.Close();
+                    rezerv.Show();
+                    break;
+                case MessageBoxResult.No:
+                    break;
+            }
+        }
     }
 }