Browse Source

Сделана оплата через паттерн стратегия

максим карбышев 2 years ago
parent
commit
33c097b19c

+ 1 - 4
Kinomaks/App.config

@@ -7,9 +7,6 @@
   <startup>
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
   </startup>
-  <connectionStrings>
-    <add name="KinomaksEntities" connectionString="metadata=res://*/KinomaksDB.csdl|res://*/KinomaksDB.ssdl|res://*/KinomaksDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-5285QDG;initial catalog=Kinomaks;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
-  </connectionStrings>
   <entityFramework>
     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
       <parameters>
@@ -20,4 +17,4 @@
       <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
     </providers>
   </entityFramework>
-</configuration>
+<connectionStrings><add name="KinomaksEntities" connectionString="metadata=res://*/KinomaksDB.csdl|res://*/KinomaksDB.ssdl|res://*/KinomaksDB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-5285QDG;initial catalog=Kinomaks;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings></configuration>

+ 1 - 1
Kinomaks/App.xaml

@@ -2,7 +2,7 @@
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:local="clr-namespace:Kinomaks"
-             StartupUri="AddWindows/AddHallWindow.xaml">
+             StartupUri="AuthorizationWindow.xaml">
     <Application.Resources>
         <ResourceDictionary Source="Style.xaml"/>
     </Application.Resources>

+ 39 - 0
Kinomaks/BuyCash.cs

@@ -0,0 +1,39 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Kinomaks
+{
+    internal class BuyCash : IBuy
+    {
+        int IDFilm;
+        decimal Price;
+        int idTimetable;
+        int IDHall;
+        List<int> numberOfSeats;
+
+        public BuyCash(int idFilm, List<int> numberOfSeats, int idTimetable, int idHall)
+        {
+            this.IDFilm = idFilm;
+            this.numberOfSeats = numberOfSeats;
+            this.idTimetable = idTimetable;
+            this.IDHall = idHall;
+            this.Price = Connection.db.Films.Where(item => item.ID == IDFilm).Select(item => item.Price).FirstOrDefault();
+        }
+
+        public void DoBuy()
+        {
+            foreach (int item in this.numberOfSeats)
+            {
+                HallTimetable hallTimetable = new HallTimetable()
+                {
+                    IDHall = this.IDHall,
+                    IDTimetable = this.idTimetable,
+                    IDUser = User.IDUser,
+                    IDPlace = item
+                };
+                Connection.db.HallTimetable.Add(hallTimetable);
+                Connection.db.SaveChanges();
+            }
+        }
+    }
+}

+ 11 - 0
Kinomaks/Buyer.cs

@@ -0,0 +1,11 @@
+namespace Kinomaks
+{
+    internal class Buyer
+    {
+        public void DoBuy(IBuy buy)
+        {
+            if (buy != null)
+                buy.DoBuy();
+        }
+    }
+}

+ 9 - 5
Kinomaks/ElementsWindows/BuyingATicket.xaml

@@ -144,9 +144,13 @@
         <Label Content="Название:" HorizontalAlignment="Left" Margin="36,176,0,0" VerticalAlignment="Top" Height="60" Width="180" Foreground="White" FontSize="36"/>
         <Label x:Name="Title" HorizontalAlignment="Left" Margin="218,176,0,0" VerticalAlignment="Top" Height="60" Width="700" FontSize="36" Foreground="#FF54E4FF"/>
         <Image x:Name="Logo" HorizontalAlignment="Left" Margin="34,246,0,0" Width="307" Height="372" VerticalAlignment="Top"/>
-        <Label Content="Дата и время:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="363,359,0,0" VerticalAlignment="Top" Height="60" Width="252" Foreground="White" FontSize="36"/>
-        <Label x:Name="Time" Content="" HorizontalAlignment="Center" Margin="0,359,0,0" VerticalAlignment="Top" Height="60" Width="365" Foreground="White" FontSize="36"/>
-        <Label Content="Зал №:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="363,440,0,0" VerticalAlignment="Top" Height="60" Width="252" Foreground="White" FontSize="36"/>
-        <Label x:Name="Hall" Content="" HorizontalAlignment="Center" VerticalAlignment="Top" Height="60" Width="365" Foreground="White" FontSize="36" Margin="0,440,0,0"/>
+        <Label Content="Дата и время:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="363,285,0,0" VerticalAlignment="Top" Height="60" Width="252" Foreground="White" FontSize="36"/>
+        <Label x:Name="Time" Content="" HorizontalAlignment="Center" Margin="0,285,0,0" VerticalAlignment="Top" Height="60" Width="364" Foreground="White" FontSize="36"/>
+        <Label Content="Зал №:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="363,366,0,0" VerticalAlignment="Top" Height="60" Width="252" Foreground="White" FontSize="36"/>
+        <Label x:Name="Hall" Content="" HorizontalAlignment="Center" VerticalAlignment="Top" Height="60" Width="364" Foreground="White" FontSize="36" Margin="0,366,0,0"/>
+        <Label Content="Цена:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="363,447,0,0" VerticalAlignment="Top" Height="60" Width="252" Foreground="White" FontSize="36"/>
+        <Label x:Name="Price" Content="" HorizontalAlignment="Center" VerticalAlignment="Top" Height="60" Width="364" Foreground="White" FontSize="36" Margin="0,447,0,0"/>
+        <Label Content="Мест:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="363,528,0,0" VerticalAlignment="Top" Height="60" Width="252" Foreground="White" FontSize="36"/>
+        <Label x:Name="CountOfSeats" Content="0" HorizontalAlignment="Center" VerticalAlignment="Top" Height="60" Width="364" Foreground="White" FontSize="36" Margin="0,528,0,0"/>
     </Grid>
-</Window>
+</Window>

+ 40 - 5
Kinomaks/ElementsWindows/BuyingATicket.xaml.cs

@@ -1,4 +1,5 @@
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -12,10 +13,16 @@ namespace Kinomaks.ElementsWindows
     public partial class BuyingATicket : Window
     {
         Brush color;
+        Films film;
+        Hall hall;
+        List<int> numberOfSeats = new List<int>();
+        int idTimetable;
 
         public BuyingATicket(int idTimetable)
         {
             InitializeComponent();
+            
+            this.idTimetable = idTimetable;
 
             foreach (UIElement item in Seats.Children)
             {
@@ -23,13 +30,13 @@ namespace Kinomaks.ElementsWindows
                 break;
             }
 
-            Films film = Connection.db.FilmTimetable.Where(item => item.IDTimeTable == idTimetable).Select(item => item.Films).FirstOrDefault();
+            film = Connection.db.FilmTimetable.Where(item => item.IDTimeTable == idTimetable).Select(item => item.Films).FirstOrDefault();
             Title.Content = film.Title;
             Logo.Source = ImagesManip.NewImage(film);
 
             Time.Content = Connection.db.Timetable.Where(item => item.ID == idTimetable).Select(item => item.Time).FirstOrDefault();
 
-            Hall hall = Connection.db.HallTimetable.Where(item => item.IDTimetable == idTimetable).Select(item => item.Hall).FirstOrDefault();
+            hall = Connection.db.HallTimetable.Where(item => item.IDTimetable == idTimetable).Select(item => item.Hall).FirstOrDefault();
             Hall.Content = hall.Number;
 
             int tempNumberOfSeat = 0;
@@ -51,10 +58,29 @@ namespace Kinomaks.ElementsWindows
 
         private void ClickOnCell(object sender, MouseButtonEventArgs e)
         {
+            if (((Button)sender).Background == Brushes.Red)
+            {
+                ErrorWindow errorWindow = new ErrorWindow("место уже занято");
+                errorWindow.Show();
+                return;
+            }
+
             if (((Button)sender).Background == color)
-                ((Button)sender).Background = Brushes.Red;
-            else if (((Button)sender).Background == Brushes.Red)
+            {
+                ((Button)sender).Background = Brushes.Blue;
+
+                numberOfSeats.Add((Grid.GetRow((Button)sender) * 10) + 1 + Grid.GetColumn((Button)sender) + 1);
+
+                CountOfSeats.Content = numberOfSeats.Count;
+            }    
+            else if (((Button)sender).Background == Brushes.Blue)
+            {
                 ((Button)sender).Background = color;
+
+                numberOfSeats.Remove((Grid.GetRow((Button)sender) * 10) + 1 + Grid.GetColumn((Button)sender) + 1);
+
+                CountOfSeats.Content = numberOfSeats.Count;
+            }
         }
 
         private void BackButtonClick(object sender, RoutedEventArgs e)
@@ -66,7 +92,16 @@ namespace Kinomaks.ElementsWindows
 
         private void BuyButtonClick(object sender, RoutedEventArgs e)
         {
+            if (numberOfSeats.Count == 0)
+            {
+                ErrorWindow errorWindow = new ErrorWindow("место не выбрано");
+                errorWindow.Show();
+                return;
+            }
 
+            PaymentMethod paymentMethod = new PaymentMethod(film.ID, numberOfSeats, idTimetable, hall.ID);
+            paymentMethod.Show();
+            this.Close();
         }
     }
 }

+ 13 - 0
Kinomaks/ElementsWindows/PaymentMethod.xaml

@@ -0,0 +1,13 @@
+<Window x:Class="Kinomaks.ElementsWindows.PaymentMethod"
+        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:local="clr-namespace:Kinomaks.ElementsWindows"
+        mc:Ignorable="d"
+        Title="Способ оплаты" Height="900" Width="1600" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize">
+    <Grid>
+        <Button Name="BackButton" Content="Назад" HorizontalAlignment="Left" Margin="20,17,0,0" VerticalAlignment="Top" Height="39" Width="140" FontSize="25" Click="BackButtonClick"/>
+        <Button x:Name="Cash" Content="Наличными" HorizontalAlignment="Center" Margin="0,0,0,0" VerticalAlignment="Center" Height="70" Width="223" FontSize="36" Click="CashButtonClick"/>
+    </Grid>
+</Window>

+ 40 - 0
Kinomaks/ElementsWindows/PaymentMethod.xaml.cs

@@ -0,0 +1,40 @@
+using System.Collections.Generic;
+using System.Windows;
+
+namespace Kinomaks.ElementsWindows
+{
+    /// <summary>
+    /// Логика взаимодействия для PaymentMethod.xaml
+    /// </summary>
+    public partial class PaymentMethod : Window
+    {
+        int idFilm;
+        List<int> numberOfSeats;
+        int idTimetable;
+        int idHall;
+
+        public PaymentMethod(int idFilm, List<int> numberOfSeats, int idTimetable, int idHall)
+        {
+            InitializeComponent();
+
+            this.idFilm = idFilm;
+            this.numberOfSeats = numberOfSeats;
+            this.idTimetable = idTimetable;
+            this.idHall = idHall;
+        }
+
+        private void CashButtonClick(object sender, RoutedEventArgs e)
+        {
+            PaymentWindow paymentWindow = new PaymentWindow(idFilm, numberOfSeats, idTimetable, idHall);
+            paymentWindow.Show();
+            this.Close();
+        }
+
+        private void BackButtonClick(object sender, RoutedEventArgs e)
+        {
+            BuyingATicket buyingATicket = new BuyingATicket(idTimetable);
+            buyingATicket.Show();
+            this.Close();
+        }
+    }
+}

+ 15 - 0
Kinomaks/ElementsWindows/PaymentWindow.xaml

@@ -0,0 +1,15 @@
+<Window x:Class="Kinomaks.ElementsWindows.PaymentWindow"
+        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:local="clr-namespace:Kinomaks.ElementsWindows"
+        mc:Ignorable="d"
+        Title="Окно оплаты" Height="900" Width="1600" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize">
+    <Grid>
+        <Button x:Name="BackButton" Content="Назад" HorizontalAlignment="Left" Margin="20,17,0,0" VerticalAlignment="Top" Height="39" Width="140" FontSize="25" Click="BackButtonClick"/>
+        <Button x:Name="Paid" Content="Оплачено" HorizontalAlignment="Center" Margin="0,746,0,0" VerticalAlignment="Top" Height="60" Width="180" FontSize="36" Click="PaidButtonClick"/>
+        <Label Content="К оплате:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="507,0,0,0" VerticalAlignment="Center" Height="60" Width="252" Foreground="White" FontSize="36"/>
+        <Label x:Name="ToPay" Content="" HorizontalAlignment="Left" Margin="762,0,0,0" VerticalAlignment="Center" Height="60" Width="364" Foreground="White" FontSize="36"/>
+    </Grid>
+</Window>

+ 50 - 0
Kinomaks/ElementsWindows/PaymentWindow.xaml.cs

@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows;
+
+namespace Kinomaks.ElementsWindows
+{
+    /// <summary>
+    /// Логика взаимодействия для PaymentWindow.xaml
+    /// </summary>
+    public partial class PaymentWindow : Window
+    {
+        int idFilm;
+        List<int> numberOfSeats;
+        int idTimetable;
+        int idHall;
+
+        public PaymentWindow(int idFilm, List<int> numberOfSeats, int idTimetable, int idHall)
+        {
+            InitializeComponent();
+
+            this.idFilm = idFilm;
+            this.numberOfSeats = numberOfSeats;
+            this.idTimetable = idTimetable;
+            this.idHall = idHall;
+
+            ToPay.Content = Connection.db.Films.Where(item => item.ID == this.idFilm).Select(item => item.Price).FirstOrDefault() * this.numberOfSeats.Count();
+            Payment();
+        }
+
+        void Payment()
+        {
+            Buyer buyer = new Buyer();
+            buyer.DoBuy(new BuyCash(idFilm, numberOfSeats, idTimetable, idHall));
+        }
+
+        private void PaidButtonClick(object sender, RoutedEventArgs e)
+        {
+            MainWindow mainWindow = new MainWindow();
+            mainWindow.Show();
+            this.Close();
+        }
+
+        private void BackButtonClick(object sender, RoutedEventArgs e)
+        {
+            PaymentMethod paymentMethod = new PaymentMethod(idFilm, numberOfSeats, idTimetable, idHall);
+            paymentMethod.Show();
+            this.Close();
+        }
+    }
+}

+ 1 - 0
Kinomaks/Films.cs

@@ -24,6 +24,7 @@ namespace Kinomaks
         public string Title { get; set; }
         public string Descripton { get; set; }
         public byte[] Logo { get; set; }
+        public decimal Price { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<FilmTimetable> FilmTimetable { get; set; }

+ 7 - 0
Kinomaks/IBuy.cs

@@ -0,0 +1,7 @@
+namespace Kinomaks
+{
+    internal interface IBuy
+    {
+        void DoBuy();
+    }
+}

+ 21 - 5
Kinomaks/Kinomaks.csproj

@@ -70,6 +70,8 @@
     <Compile Include="AddWindows\AddHallWindow.xaml.cs">
       <DependentUpon>AddHallWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="BuyCash.cs" />
+    <Compile Include="Buyer.cs" />
     <Compile Include="Connection.cs" />
     <Compile Include="ElementsWindows\BuyingATicket.xaml.cs">
       <DependentUpon>BuyingATicket.xaml</DependentUpon>
@@ -77,6 +79,12 @@
     <Compile Include="ElementsWindows\FilmWindow.xaml.cs">
       <DependentUpon>FilmWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="ElementsWindows\PaymentMethod.xaml.cs">
+      <DependentUpon>PaymentMethod.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="ElementsWindows\PaymentWindow.xaml.cs">
+      <DependentUpon>PaymentWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Films.cs">
       <DependentUpon>KinomaksDB.tt</DependentUpon>
     </Compile>
@@ -89,6 +97,7 @@
     <Compile Include="HallTimetable.cs">
       <DependentUpon>KinomaksDB.tt</DependentUpon>
     </Compile>
+    <Compile Include="IBuy.cs" />
     <Compile Include="KinomaksDB.Context.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
@@ -149,6 +158,14 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="ElementsWindows\PaymentMethod.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="ElementsWindows\PaymentWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="ErrorWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -225,10 +242,13 @@
     <None Include="App.config" />
   </ItemGroup>
   <ItemGroup>
+    <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
+  </ItemGroup>
+  <ItemGroup>
     <Content Include="KinomaksDB.Context.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
-      <LastGenOutput>KinomaksDB.Context.cs</LastGenOutput>
       <DependentUpon>KinomaksDB.edmx</DependentUpon>
+      <LastGenOutput>KinomaksDB.Context.cs</LastGenOutput>
     </Content>
     <Content Include="KinomaksDB.tt">
       <Generator>TextTemplatingFileGenerator</Generator>
@@ -236,9 +256,5 @@
       <LastGenOutput>KinomaksDB.cs</LastGenOutput>
     </Content>
   </ItemGroup>
-  <ItemGroup>
-    <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
-  </ItemGroup>
-  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 3 - 0
Kinomaks/KinomaksDB.edmx

@@ -13,6 +13,7 @@
           <Property Name="Title" Type="nvarchar" MaxLength="150" Nullable="false" />
           <Property Name="Descripton" Type="nvarchar(max)" />
           <Property Name="Logo" Type="image" />
+          <Property Name="Price" Type="money" Nullable="false" />
         </EntityType>
         <EntityType Name="FilmTimetable">
           <Key>
@@ -221,6 +222,7 @@
           <Property Name="Title" Type="String" MaxLength="150" FixedLength="false" Unicode="true" Nullable="false" />
           <Property Name="Descripton" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
           <Property Name="Logo" Type="Binary" MaxLength="Max" FixedLength="false" />
+          <Property Name="Price" Type="Decimal" Precision="19" Scale="4" Nullable="false" />
           <NavigationProperty Name="FilmTimetable" Relationship="Self.FK_FilmTimetable_Films" FromRole="Films" ToRole="FilmTimetable" />
         </EntityType>
         <EntityType Name="FilmTimetable">
@@ -443,6 +445,7 @@
                 <ScalarProperty Name="Title" ColumnName="Title" />
                 <ScalarProperty Name="Descripton" ColumnName="Descripton" />
                 <ScalarProperty Name="Logo" ColumnName="Logo" />
+                <ScalarProperty Name="Price" ColumnName="Price" />
               </MappingFragment>
             </EntityTypeMapping>
           </EntitySetMapping>

+ 2 - 2
Kinomaks/KinomaksDB.edmx.diagram

@@ -4,8 +4,8 @@
   <edmx:Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
-      <Diagram DiagramId="8b0d1d93d7db4145821f30ef1bcb7518" Name="Diagram1">
-        <EntityTypeShape EntityType="KinomaksModel.Films" Width="1.5" PointX="0.75" PointY="16" IsExpanded="true" />
+      <Diagram DiagramId="94c4894b896e40b88b092d51e142a2f1" Name="Diagram1">
+        <EntityTypeShape EntityType="KinomaksModel.Films" Width="1.5" PointX="0.75" PointY="15.125" IsExpanded="true" />
         <EntityTypeShape EntityType="KinomaksModel.FilmTimetable" Width="1.5" PointX="3" PointY="0.75" IsExpanded="true" />
         <EntityTypeShape EntityType="KinomaksModel.Hall" Width="1.5" PointX="0.75" PointY="4.625" IsExpanded="true" />
         <EntityTypeShape EntityType="KinomaksModel.HallTimetable" Width="1.5" PointX="3" PointY="4.25" IsExpanded="true" />