ivan matveev 1 năm trước cách đây
mục cha
commit
039d7e4a7f

+ 2 - 2
practica12/Pages/HotelPage.xaml

@@ -23,7 +23,7 @@
                 <DataGridTemplateColumn Width="*">
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>
-                                <Button Name="btnUpdate" Uid="{Binding Id}" HorizontalAlignment="Center" FontSize="14" Style="{StaticResource btnstyle1}" Content="Редактировать"/>
+                                <Button Name="btnUpdate" Uid="{Binding Id}" Click="btnUpdate_Click" HorizontalAlignment="Center" FontSize="14" Style="{StaticResource btnstyle1}" Content="Редактировать"/>
                         </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>
                 </DataGridTemplateColumn>
@@ -32,7 +32,7 @@
         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
             <Button Name="btn_Tours" Content="Туры" Click="btn_Tours_Click"  Style="{StaticResource btnstyle1}" />
             <Button Name="btn_Add" Content="Добавить" Click="btn_Add_Click"  Style="{StaticResource btnstyle1}" />
-            <Button Name="btn_Dell" Content="Туры" Click="btn_Dell_Click"  Style="{StaticResource btnstyle1}" />
+            <Button Name="btn_Dell" Content="Удалить" Click="btn_Dell_Click"  Style="{StaticResource btnstyle1}" />
             </StackPanel>
         </StackPanel>
         <StackPanel>

+ 34 - 3
practica12/Pages/HotelPage.xaml.cs

@@ -21,6 +21,7 @@ namespace practica12.Pages
     /// </summary>
     public partial class HotelPage : Page
     {
+       
         Pagin pc = new Pagin();
         List<Hotel> listHotel = Base.ep.Hotel.ToList();
         public HotelPage()
@@ -51,7 +52,7 @@ namespace practica12.Pages
         {
             TextBlock tb = (TextBlock)sender;
 
-            switch (tb.Uid)  // определяем, куда конкретно было сделано нажатие
+            switch (tb.Uid)  
             {
                 case "prev":
                     pc.CurrentPage--;
@@ -78,13 +79,43 @@ namespace practica12.Pages
 
         private void btn_Add_Click(object sender, RoutedEventArgs e)
         {
-
+            
+            FrameClass.MainFrame.Navigate(new PageUpdADD());
         }
 
         private void btn_Dell_Click(object sender, RoutedEventArgs e)
         {
+            if (dgHotels.SelectedItems.Count != 0)
+            {
+                foreach (Hotel hotel in dgHotels.SelectedItems)
+                {
+                    List<Hotel> hot = Base.ep.Hotel.Where(z => z.Id == hotel.Id).ToList();
+                    foreach (Hotel h in hot)
+                    {
+                          if (MessageBox.Show("Вы хотите удалить {0}", Name, MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+                            {
+                                Base.ep.Hotel.Remove(hotel);
+                                Base.ep.SaveChanges();
+                                MessageBox.Show("Успешное удаление!!!");
+                                FrameClass.MainFrame.Navigate(new HotelPage());
+                            }
+                        
+                        
+                    }
+                }
+            }
+            else
+            {
+                MessageBox.Show("Выберите отель для удаления!!!");
+            }
+        }
 
+        private void btnUpdate_Click(object sender, RoutedEventArgs e)
+        {
+            Button btn = (Button)sender;
+            int index = Convert.ToInt32(btn.Uid);
+            Hotel hotel = Base.ep.Hotel.FirstOrDefault(x => x.Id == index);
+            FrameClass.MainFrame.Navigate(new PageUpdADD(hotel));
         }
-       
     }
 }

+ 37 - 0
practica12/Pages/PageUpdADD.xaml

@@ -0,0 +1,37 @@
+<Page x:Class="practica12.Pages.PageUpdADD"
+      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+      xmlns:local="clr-namespace:practica12.Pages"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="PageUpdADD">
+
+    <Grid>
+        <StackPanel>
+            <StackPanel HorizontalAlignment="Center" Margin="10">
+               
+                    <StackPanel>
+                    <TextBlock Text="Наименование" Style="{StaticResource TBStyle}" />
+                    <TextBox Name="tbName"  MaxLength="100"/>
+                    <TextBlock Text="Количество звезд" Style="{StaticResource TBStyle}" />
+                    <TextBox Name="tbCountOfStars"  TextAlignment="Center" MaxLength="1" ToolTip="Отель может принимать следующее значение количества звёзд: целое значение от 0 до 5"/>
+                    <TextBlock Text="Страна" Style="{StaticResource TBStyle}" />
+                    <StackPanel >
+                        <ComboBox Name="cbCountry" Width="300" HorizontalAlignment="Left"/>
+                    </StackPanel>
+                    <TextBlock Text="Описание:" Style="{StaticResource TBStyle}"/>
+                </StackPanel>
+                
+            
+            <TextBox Name="tbDescription" TextWrapping="Wrap" AcceptsReturn="True" Height="217" Width="422"/>
+        </StackPanel>
+        
+            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="50,0,50,0">
+                <Button Name="btnBack" Content="Назад"  Style="{StaticResource btnstyle1}"  Margin="5" Click="btnBack_Click"/>
+                <Button Name="btnAddUpd" Style="{StaticResource btnstyle1}" Content="Добавить/Изменить"  Margin="5" Click="btnAddUpd_Click" Cursor="Hand"/>
+            </StackPanel>
+        </StackPanel>
+    </Grid>
+</Page>

+ 100 - 0
practica12/Pages/PageUpdADD.xaml.cs

@@ -0,0 +1,100 @@
+using practica12.Classs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace practica12.Pages
+{
+    /// <summary>
+    /// Логика взаимодействия для PageUpdADD.xaml
+    /// </summary>
+    public partial class PageUpdADD : Page
+    {
+        Hotel hotel;
+        bool a;
+        public PageUpdADD()
+        {
+            InitializeComponent();
+            a = true;
+            cbCountry.ItemsSource = Base.ep.Country.ToList();
+            cbCountry.SelectedValuePath = "Code";
+            cbCountry.DisplayMemberPath = "Name";
+            cbCountry.SelectedIndex = 0;
+        }
+
+        public PageUpdADD(Hotel hotel)
+        {
+            InitializeComponent();
+            this.hotel = hotel;
+            tbName.Text = hotel.Name;
+            cbCountry.ItemsSource = Base.ep.Country.ToList();
+            cbCountry.SelectedValuePath = "Code";
+            cbCountry.DisplayMemberPath = "Name";
+            cbCountry.SelectedIndex = 0;
+            tbCountOfStars.Text = Convert.ToString(hotel.CountOfStars);
+            cbCountry.SelectedValue = hotel.CountryCode;
+            tbDescription.Text = hotel.Description;
+            a = false;
+        }
+       
+        private void btnAddUpd_Click(object sender, RoutedEventArgs e)
+        {
+            if (tbName.Text != "" && tbCountOfStars.Text != "" && tbDescription.Text != "" && cbCountry.SelectedIndex != -1)
+            {
+                if (a == true)
+                {
+                    hotel = new Hotel();
+                }
+                hotel.Name = tbName.Text;
+                Regex r1 = new Regex("^[0-5]{1}$");
+                if (r1.IsMatch(tbCountOfStars.Text) == true)
+                {
+                    hotel.CountOfStars = Convert.ToInt32(tbCountOfStars.Text);
+                    hotel.CountryCode = Convert.ToString(cbCountry.SelectedValue);
+                    hotel.Description = tbDescription.Text;
+                    if (a == true)
+                    {
+                        Base.ep.Hotel.Add(hotel);
+                    }
+                    Base.ep.SaveChanges();
+                    if (a == true)
+                    {
+                        MessageBox.Show("Запись добавлена");
+                    }
+                    else
+                    {
+                        MessageBox.Show("Запись изменена");
+                    }
+                    FrameClass.MainFrame.Navigate(new HotelPage());
+                }
+                else
+                {
+                    MessageBox.Show("Звезды должны находится в диапазоне от 0 до 5");
+                }
+            }
+            else
+            {
+                MessageBox.Show("Все поля должны быть заполнены  ");
+            }
+
+        }
+
+        private void btnBack_Click(object sender, RoutedEventArgs e)
+        {
+            FrameClass.MainFrame.Navigate(new HotelPage());
+        }
+        
+    }
+}

+ 7 - 0
practica12/practica12.csproj

@@ -83,6 +83,9 @@
       <DesignTime>True</DesignTime>
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
+    <Compile Include="Pages\PageUpdADD.xaml.cs">
+      <DependentUpon>PageUpdADD.xaml</DependentUpon>
+    </Compile>
     <Compile Include="sp_helpdiagramdefinition_Result.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
@@ -122,6 +125,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Pages\PageUpdADD.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Model1.Context.cs">