瀏覽代碼

Сделан возврат чека

максим карбышев 2 年之前
父節點
當前提交
e855963965

+ 1 - 1
Kinomaks/AddWindows/AddTimetable.xaml

@@ -1,4 +1,4 @@
-<Window x:Class="Kinomaks.AddWindows.AddTimetable"
+<Window x:Class="Kinomaks.AddWindows.AddTimetableWindow"
         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"

+ 2 - 2
Kinomaks/AddWindows/AddTimetable.xaml.cs

@@ -9,10 +9,10 @@ namespace Kinomaks.AddWindows
     /// <summary>
     /// Логика взаимодействия для AddTimetable.xaml
     /// </summary>
-    public partial class AddTimetable : Window
+    public partial class AddTimetableWindow : Window
     {
 
-        public AddTimetable()
+        public AddTimetableWindow()
         {
             InitializeComponent();
             Film.ItemsSource = Connection.db.Films.Select(items => items.Title).ToList();

+ 15 - 0
Kinomaks/ElementsWindows/ReturnWindow.xaml

@@ -0,0 +1,15 @@
+<Window x:Class="Kinomaks.ElementsWindows.ReturnWindow"
+        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>
+        <Label Content="Введите номер чека:" HorizontalAlignment="Left" Margin="293,0,0,0" VerticalAlignment="Center" Height="60" Width="368" Foreground="White" FontSize="36"/>
+        <TextBox x:Name="Cheque" HorizontalAlignment="Left" Margin="661,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Center" Height="60" Width="730" FontSize="36"/>
+        <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="ReturnButton" Content="Вернуть" HorizontalAlignment="Center" Margin="0,792,0,0" VerticalAlignment="Top" Height="60" Width="180" FontSize="36" Click="ReturnButtonClick" />
+    </Grid>
+</Window>

+ 71 - 0
Kinomaks/ElementsWindows/ReturnWindow.xaml.cs

@@ -0,0 +1,71 @@
+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 Kinomaks.ElementsWindows
+{
+    /// <summary>
+    /// Логика взаимодействия для ReturnWindow.xaml
+    /// </summary>
+    public partial class ReturnWindow : Window
+    {
+        public ReturnWindow()
+        {
+            InitializeComponent();
+        }
+
+        private void ReturnButtonClick(object sender, RoutedEventArgs e)
+        {
+            int cheque;
+            if (!int.TryParse(Cheque.Text, out cheque))
+            {
+                ErrorWindow errorWindow = new ErrorWindow("неверный формат чека");
+                errorWindow.Show();
+                return;
+            }
+
+            DateTime now = DateTime.Now;
+            DateTime date = Connection.db.UserTicket.Where(item => item.ID == cheque).Select(item => item.Timetable.Date).FirstOrDefault();
+            TimeSpan time = Connection.db.UserTicket.Where(item => item.ID == cheque).Select(item => item.Timetable.Time).FirstOrDefault();
+
+            if (now.Date >= date || (now.Date == date && now.TimeOfDay > time))
+            {
+                ErrorWindow errorWindow = new ErrorWindow("вы уже не можете вернуть этот билет");
+                errorWindow.Show();
+                return;
+            }    
+
+            UserTicket userTicket = Connection.db.UserTicket.Where(item => item.ID == cheque).Select(item => item).FirstOrDefault();
+
+            if (userTicket == null)
+            {
+                ErrorWindow errorWindow = new ErrorWindow("такого билета не существует");
+                errorWindow.Show();
+                return;
+            }
+
+            Connection.db.UserTicket.Remove(userTicket);
+
+            MainWindow mainWindow = new MainWindow();
+            mainWindow.Show();
+            this.Close();
+        }
+
+        private void BackButtonClick(object sender, RoutedEventArgs e)
+        {
+            MainWindow mainWindow = new MainWindow();
+            mainWindow.Show();
+            this.Close();
+        }
+    }
+}

+ 10 - 3
Kinomaks/Kinomaks.csproj

@@ -104,8 +104,8 @@
     <Compile Include="AddWindows\AddHallWindow.xaml.cs">
       <DependentUpon>AddHallWindow.xaml</DependentUpon>
     </Compile>
-    <Compile Include="AddWindows\AddTimetable.xaml.cs">
-      <DependentUpon>AddTimetable.xaml</DependentUpon>
+    <Compile Include="AddWindows\AddTimetableWindow.xaml.cs">
+      <DependentUpon>AddTimetableWindow.xaml</DependentUpon>
     </Compile>
     <Compile Include="BuyCash.cs" />
     <Compile Include="Buyer.cs" />
@@ -122,6 +122,9 @@
     <Compile Include="ElementsWindows\PaymentWindow.xaml.cs">
       <DependentUpon>PaymentWindow.xaml</DependentUpon>
     </Compile>
+    <Compile Include="ElementsWindows\ReturnWindow.xaml.cs">
+      <DependentUpon>ReturnWindow.xaml</DependentUpon>
+    </Compile>
     <Compile Include="ElementsWindows\TimetableWindow.xaml.cs">
       <DependentUpon>TimetableWindow.xaml</DependentUpon>
     </Compile>
@@ -186,7 +189,7 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
-    <Page Include="AddWindows\AddTimetable.xaml">
+    <Page Include="AddWindows\AddTimetableWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
@@ -210,6 +213,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="ElementsWindows\ReturnWindow.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="ElementsWindows\TimetableWindow.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 3 - 2
Kinomaks/MainWindow.xaml

@@ -10,8 +10,9 @@
         <TabControl BorderThickness="0">
             <TabItem Header="Главная" Height="20" Width="100" Background="#FF4F5856">
                 <Grid Margin="-3,-22,-3,-2">
-                    <Button Name="FilmsList" Content="Фильмы" HorizontalAlignment="Center" Margin="0,336,0,0" VerticalAlignment="Top" Height="70" Width="223" FontSize="36" Click="FilmsListClick"/>
-                    <Button Name="Tabletime" Content="Расписание" HorizontalAlignment="Center" Margin="0,428,0,0" VerticalAlignment="Top" Height="70" Width="223" FontSize="36" Click="TimetableListClick"/>
+                    <Button Name="FilmsList" Content="Фильмы" HorizontalAlignment="Center" Margin="0,314,0,0" VerticalAlignment="Top" Height="70" Width="222" FontSize="36" Click="FilmsListClick"/>
+                    <Button Name="Tabletime" Content="Расписание" HorizontalAlignment="Center" VerticalAlignment="Center" Height="70" Width="222" FontSize="36" Click="TimetableListClick"/>
+                    <Button x:Name="Return" Content="Возврат" HorizontalAlignment="Center" Margin="0,498,0,0" VerticalAlignment="Top" Height="70" Width="222" FontSize="36" Click="ReturnClick"/>
                 </Grid>
             </TabItem>
             <TabItem Name="AddItem" Header="Добавить" Height="20" Width="100" Background="#FF4F5856">

+ 9 - 2
Kinomaks/MainWindow.xaml.cs

@@ -30,8 +30,8 @@ namespace Kinomaks
 
         private void AddTimetableClick(object sender, RoutedEventArgs e)
         {
-            //AddTimetableWindow addTimetableWindow = new AddTimetableWindow();
-            //addTimetableWindow.Show();
+            AddTimetableWindow addTimetableWindow = new AddTimetableWindow();
+            addTimetableWindow.Show();
             this.Close();
         }
 
@@ -57,6 +57,13 @@ namespace Kinomaks
             timetableWindow.Show();
             this.Close();
         }
+
+        private void ReturnClick(object sender, RoutedEventArgs e)
+        {
+            ReturnWindow returnWindow = new ReturnWindow();
+            returnWindow.Show();
+            this.Close();
+        }
         #endregion
 
         #endregion