Drenbb 2 rokov pred
rodič
commit
10fa72e19f

+ 13 - 0
Sect1/Class1.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Sect1
+{
+    public class Class1
+    {
+        int a = 1;
+    }
+}

+ 36 - 0
Sect1/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Общие сведения об этой сборке предоставляются следующим набором
+// набора атрибутов. Измените значения этих атрибутов для изменения сведений,
+// связанные со сборкой.
+[assembly: AssemblyTitle("Sect1")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Sect1")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
+// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
+// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
+[assembly: ComVisible(false)]
+
+// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
+[assembly: Guid("917c8d27-74b2-47d5-a91d-201e97ac0a38")]
+
+// Сведения о версии сборки состоят из указанных ниже четырех значений:
+//
+//      Основной номер версии
+//      Дополнительный номер версии
+//      Номер сборки
+//      Редакция
+//
+// Можно задать все значения или принять номера сборки и редакции по умолчанию 
+// используя "*", как показано ниже:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 54 - 0
Sect1/Sect1.csproj

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>917c8d27-74b2-47d5-a91d-201e97ac0a38</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Sect1</RootNamespace>
+    <AssemblyName>Sect1</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System"/>
+    
+    <Reference Include="System.Core"/>
+    <Reference Include="System.Xml.Linq"/>
+    <Reference Include="System.Data.DataSetExtensions"/>
+    
+    
+    <Reference Include="Microsoft.CSharp"/>
+    
+    <Reference Include="System.Data"/>
+    
+    <Reference Include="System.Net.Http"/>
+    
+    <Reference Include="System.Xml"/>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Class1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ </Project>

+ 1 - 1
WpfApp1/MainWindow.xaml

@@ -7,6 +7,6 @@
         mc:Ignorable="d"
         Title="MainWindow" Height="450" Width="800">
     <Grid>
-        <Frame Name="frm"></Frame>
+        <Frame Name="frm" NavigationUIVisibility="Hidden"></Frame>
     </Grid>
 </Window>

+ 14 - 0
WpfApp1/WpfApp1.csproj

@@ -83,12 +83,18 @@
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
     <Compile Include="partTour.cs" />
+    <Compile Include="pgAddHotel.xaml.cs">
+      <DependentUpon>pgAddHotel.xaml</DependentUpon>
+    </Compile>
     <Compile Include="pgHotels.xaml.cs">
       <DependentUpon>pgHotels.xaml</DependentUpon>
     </Compile>
     <Compile Include="pgTours.xaml.cs">
       <DependentUpon>pgTours.xaml</DependentUpon>
     </Compile>
+    <Compile Include="pgUpdateHotel.xaml.cs">
+      <DependentUpon>pgUpdateHotel.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Tour.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
@@ -108,6 +114,10 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="pgAddHotel.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="pgHotels.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -116,6 +126,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="pgUpdateHotel.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Model1.Context.cs">

+ 20 - 0
WpfApp1/pgAddHotel.xaml

@@ -0,0 +1,20 @@
+<Page x:Class="WpfApp1.pgAddHotel"
+      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:WpfApp1"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="pgAddHotel">
+
+    <Grid>
+        <StackPanel>
+            <TextBox Text="{Binding Name}"></TextBox>
+            <TextBox Text="{Binding CountOfStars}" Name="tbStars"></TextBox>
+            <ComboBox Name="cbCountry" SelectionChanged="cbCountry_SelectionChanged"></ComboBox>
+            <TextBox Text="{Binding Description}" AcceptsReturn="True"></TextBox>
+            <Button Name="btnSave" Click="btnSave_Click" Content="Сохранить"></Button>
+        </StackPanel>
+    </Grid>
+</Page>

+ 45 - 0
WpfApp1/pgAddHotel.xaml.cs

@@ -0,0 +1,45 @@
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace WpfApp1
+{
+    /// <summary>
+    /// Логика взаимодействия для pgAddHotel.xaml
+    /// </summary>
+    public partial class pgAddHotel : Page
+    {
+        Hotel hotel;
+        public pgAddHotel()
+        {
+            InitializeComponent();
+            hotel = new Hotel();
+            DataContext = hotel;
+            cbCountry.ItemsSource = BaseConnect.BaseModel.Country.ToList();
+            cbCountry.SelectedValuePath = "Code";
+            cbCountry.DisplayMemberPath = "Name";
+        }
+
+        private void cbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            hotel.CountryCode = (string)cbCountry.SelectedValue;
+        }
+
+        private void btnSave_Click(object sender, RoutedEventArgs e)
+        {
+            BaseConnect.BaseModel.Hotel.Add(hotel);
+            BaseConnect.BaseModel.SaveChanges();
+        }
+    }
+}

+ 20 - 4
WpfApp1/pgHotels.xaml

@@ -9,18 +9,34 @@
       Title="pgHotels">
 
     <Grid>
-        <ScrollViewer HorizontalScrollBarVisibility="Auto">
+        <Grid.RowDefinitions>
+            <RowDefinition/>
+            <RowDefinition Height="4*"/>
+        </Grid.RowDefinitions>
+        <StackPanel Grid.Row="0" Orientation="Horizontal">
+            <Button  Name="btnDelHotel" Click="btnDelHotel_Click" Content="Удалить отель" Width="100px" Height="50px"></Button>
+            <Button  Name="btnAddHotel" Click="btnAddHotel_Click" Content="Добавить" Width="100px" Height="50px"></Button>
+        </StackPanel>
+        
+        <ScrollViewer HorizontalScrollBarVisibility="Auto" Grid.Row="1">
             <StackPanel>
-                <DataGrid Name="dgHotels" AutoGenerateColumns="False">
+                <DataGrid Name="dgHotels" AutoGenerateColumns="False" IsReadOnly="True">
                     <DataGrid.Columns>
                         <DataGridTextColumn Binding="{Binding Name}"></DataGridTextColumn>
                         <DataGridTextColumn Binding="{Binding CountOfStars}"></DataGridTextColumn>
                         <DataGridTextColumn Binding="{Binding Country.Name}"></DataGridTextColumn>
+                        <DataGridTextColumn Binding="{Binding Tour.Count}"></DataGridTextColumn>
+                        <DataGridTemplateColumn>
+                            <DataGridTemplateColumn.CellTemplate>
+                                <DataTemplate>
+                                    <Button Content="Изменить" Uid="{Binding Id}" Click="Button_Click"></Button>
+                                </DataTemplate>
+                            </DataGridTemplateColumn.CellTemplate>
+                        </DataGridTemplateColumn>
                     </DataGrid.Columns>
                 </DataGrid>
             </StackPanel>
         </ScrollViewer>
-        
-       
+
     </Grid>
 </Page>

+ 24 - 0
WpfApp1/pgHotels.xaml.cs

@@ -28,5 +28,29 @@ namespace WpfApp1
             hotels = BaseConnect.BaseModel.Hotel.ToList();
             dgHotels.ItemsSource = hotels;
         }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+            Button btn = (Button)sender;
+            int id = Convert.ToInt32(btn.Uid);
+            LoadPages.frmMain.Navigate(new pgUpdateHotel(id));
+        }
+
+        private void btnDelHotel_Click(object sender, RoutedEventArgs e)
+        {
+            foreach(Hotel hotel in dgHotels.SelectedItems)
+            {
+                BaseConnect.BaseModel.Hotel.Remove(hotel);
+                BaseConnect.BaseModel.SaveChanges();
+            }
+            BaseConnect.BaseModel = new ToursEntities();
+            hotels = BaseConnect.BaseModel.Hotel.ToList();
+            dgHotels.ItemsSource = hotels;
+        }
+
+        private void btnAddHotel_Click(object sender, RoutedEventArgs e)
+        {
+            LoadPages.frmMain.Navigate(new pgAddHotel());
+        }
     }
 }

+ 20 - 0
WpfApp1/pgUpdateHotel.xaml

@@ -0,0 +1,20 @@
+<Page x:Class="WpfApp1.pgUpdateHotel"
+      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:WpfApp1"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="pgUpdateHotel">
+
+    <Grid>
+        <StackPanel>
+            <TextBox Text="{Binding Name}"></TextBox>
+            <TextBox Text="{Binding CountOfStars}" Name="tbStars"></TextBox>
+            <ComboBox Name="cbCountry" SelectionChanged="cbCountry_SelectionChanged"></ComboBox>
+            <TextBox Text="{Binding Description}" AcceptsReturn="True"></TextBox>
+            <Button Name="btnSave" Click="btnSave_Click" Content="Сохранить"></Button>
+        </StackPanel>
+    </Grid>
+</Page>

+ 58 - 0
WpfApp1/pgUpdateHotel.xaml.cs

@@ -0,0 +1,58 @@
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace WpfApp1
+{
+    /// <summary>
+    /// Логика взаимодействия для pgUpdateHotel.xaml
+    /// </summary>
+    public partial class pgUpdateHotel : Page
+    {
+        Hotel hotel;
+        public pgUpdateHotel(int id)
+        {
+            InitializeComponent();
+            hotel = BaseConnect.BaseModel.Hotel.FirstOrDefault(x => x.Id == id);
+            DataContext = hotel;
+            Country country = BaseConnect.BaseModel.Country.FirstOrDefault(x => x.Code == hotel.CountryCode);
+            List<Country> countryList = BaseConnect.BaseModel.Country.Where(x => x.Code != hotel.CountryCode).ToList();
+            countryList.Insert(0, country);
+            cbCountry.ItemsSource = countryList;
+            cbCountry.SelectedValuePath = "Code";
+            cbCountry.DisplayMemberPath = "Name";
+            cbCountry.SelectedIndex = 0;
+        }
+
+        private void btnSave_Click(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                if (Convert.ToInt32(tbStars.Text) <= 5 && Convert.ToInt32(tbStars.Text) >= 0)
+                    BaseConnect.BaseModel.SaveChanges();
+                else
+                    MessageBox.Show("sasa");
+            }
+            catch
+            {
+                MessageBox.Show("sasa");
+            }
+        }
+
+        private void cbCountry_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            hotel.CountryCode = (string)cbCountry.SelectedValue;
+        }
+    }
+}