Browse Source

Доработано приложение

ы ы 2 years ago
parent
commit
e2e947f9f4
10 changed files with 202 additions and 62 deletions
  1. 5 1
      App.xaml
  2. 5 5
      Book.cs
  3. 2 1
      Model1.Context.cs
  4. 103 42
      Model1.edmx
  5. 6 4
      Model1.edmx.diagram
  6. 9 3
      Order.cs
  7. 25 0
      OrderBook.cs
  8. 42 4
      Pages/CartPage.xaml.cs
  9. 2 2
      Pages/ListPage.xaml
  10. 3 0
      WpfApp2.csproj

+ 5 - 1
App.xaml

@@ -4,6 +4,10 @@
              xmlns:local="clr-namespace:WpfApp2"
              StartupUri="MainWindow.xaml">
     <Application.Resources>
-         
+        <Style TargetType="Button">
+            <Setter Property="Height" Value="50"/>
+            <Setter Property="Width" Value="128"/>
+            <Setter Property="Background" Value="Pink"/>
+        </Style>
     </Application.Resources>
 </Application>

+ 5 - 5
Book.cs

@@ -17,20 +17,20 @@ namespace WpfApp2
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
         public Book()
         {
-            this.Orders = new HashSet<Order>();
+            this.OrderBooks = new HashSet<OrderBook>();
         }
     
         public int id { get; set; }
         public string title { get; set; }
-        public string cover { get; set; }
         public string genre { get; set; }
         public string author { get; set; }
-        public string description { get; set; }
-        public Nullable<double> price { get; set; }
         public Nullable<int> countStrore { get; set; }
         public Nullable<int> countStock { get; set; }
+        public string description { get; set; }
+        public string cover { get; set; }
+        public Nullable<double> price { get; set; }
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
-        public virtual ICollection<Order> Orders { get; set; }
+        public virtual ICollection<OrderBook> OrderBooks { get; set; }
     }
 }

+ 2 - 1
Model1.Context.cs

@@ -25,8 +25,9 @@ namespace WpfApp2
             throw new UnintentionalCodeFirstException();
         }
     
-        public virtual DbSet<Book> Books { get; set; }
         public virtual DbSet<sysdiagram> sysdiagrams { get; set; }
+        public virtual DbSet<Book> Books { get; set; }
         public virtual DbSet<Order> Orders { get; set; }
+        public virtual DbSet<OrderBook> OrderBooks { get; set; }
     }
 }

+ 103 - 42
Model1.edmx

@@ -20,12 +20,20 @@
           <Property Name="price" Type="float" />
         </EntityType>
         <EntityType Name="Order">
+          <Key>
+            <PropertyRef Name="id" />
+          </Key>
+          <Property Name="id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
+          <Property Name="reserved" Type="datetime" />
+        </EntityType>
+        <EntityType Name="OrderBooks">
           <Key>
             <PropertyRef Name="id" />
           </Key>
           <Property Name="id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
           <Property Name="bookId" Type="int" />
           <Property Name="count" Type="int" />
+          <Property Name="orderId" Type="int" Nullable="false" />
         </EntityType>
         <EntityType Name="sysdiagrams">
           <Key>
@@ -37,46 +45,48 @@
           <Property Name="version" Type="int" />
           <Property Name="definition" Type="varbinary(max)" />
         </EntityType>
-        <Association Name="FK_Order_Book">
+        <Association Name="FK_OrderBooks_Book">
           <End Role="Book" Type="Self.Book" Multiplicity="0..1" />
-          <End Role="Order" Type="Self.Order" Multiplicity="*" />
+          <End Role="OrderBooks" Type="Self.OrderBooks" Multiplicity="*" />
           <ReferentialConstraint>
             <Principal Role="Book">
               <PropertyRef Name="id" />
             </Principal>
-            <Dependent Role="Order">
+            <Dependent Role="OrderBooks">
               <PropertyRef Name="bookId" />
             </Dependent>
           </ReferentialConstraint>
         </Association>
+        <Association Name="FK_OrderBooks_Order1">
+          <End Role="Order" Type="Self.Order" Multiplicity="1" />
+          <End Role="OrderBooks" Type="Self.OrderBooks" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Order">
+              <PropertyRef Name="id" />
+            </Principal>
+            <Dependent Role="OrderBooks">
+              <PropertyRef Name="orderId" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
         <EntityContainer Name="Хранилище ModelContainer">
           <EntitySet Name="Book" EntityType="Self.Book" Schema="dbo" store:Type="Tables" />
           <EntitySet Name="Order" EntityType="Self.Order" Schema="dbo" store:Type="Tables" />
+          <EntitySet Name="OrderBooks" EntityType="Self.OrderBooks" Schema="dbo" store:Type="Tables" />
           <EntitySet Name="sysdiagrams" EntityType="Self.sysdiagrams" Schema="dbo" store:Type="Tables" />
-          <AssociationSet Name="FK_Order_Book" Association="Self.FK_Order_Book">
+          <AssociationSet Name="FK_OrderBooks_Book" Association="Self.FK_OrderBooks_Book">
             <End Role="Book" EntitySet="Book" />
+            <End Role="OrderBooks" EntitySet="OrderBooks" />
+          </AssociationSet>
+          <AssociationSet Name="FK_OrderBooks_Order1" Association="Self.FK_OrderBooks_Order1">
             <End Role="Order" EntitySet="Order" />
+            <End Role="OrderBooks" EntitySet="OrderBooks" />
           </AssociationSet>
         </EntityContainer>
       </Schema></edmx:StorageModels>
     <!-- CSDL content -->
     <edmx:ConceptualModels>
       <Schema Namespace="Model" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
-        <EntityType Name="Book">
-          <Key>
-            <PropertyRef Name="id" />
-          </Key>
-          <Property Name="id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
-          <Property Name="title" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
-          <Property Name="cover" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
-          <Property Name="genre" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
-          <Property Name="author" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
-          <Property Name="description" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
-          <Property Name="price" Type="Double" />
-          <Property Name="countStrore" Type="Int32" />
-          <Property Name="countStock" Type="Int32" />
-          <NavigationProperty Name="Orders" Relationship="Model.FK_Order_Book" FromRole="Book" ToRole="Order" />
-        </EntityType>
         <EntityType Name="sysdiagram">
           <Key>
             <PropertyRef Name="diagram_id" />
@@ -88,56 +98,83 @@
           <Property Name="definition" Type="Binary" MaxLength="Max" FixedLength="false" />
         </EntityType>
         <EntityContainer Name="Entities" annotation:LazyLoadingEnabled="true">
-          <EntitySet Name="Books" EntityType="Self.Book" />
           <EntitySet Name="sysdiagrams" EntityType="Self.sysdiagram" />
+          <EntitySet Name="Books" EntityType="Model.Book" />
           <EntitySet Name="Orders" EntityType="Model.Order" />
-          <AssociationSet Name="FK_Order_Book" Association="Model.FK_Order_Book">
+          <EntitySet Name="OrderBooks" EntityType="Model.OrderBook" />
+          <AssociationSet Name="FK_OrderBooks_Book" Association="Model.FK_OrderBooks_Book">
             <End Role="Book" EntitySet="Books" />
+            <End Role="OrderBook" EntitySet="OrderBooks" />
+          </AssociationSet>
+          <AssociationSet Name="FK_OrderBooks_Order1" Association="Model.FK_OrderBooks_Order1">
             <End Role="Order" EntitySet="Orders" />
+            <End Role="OrderBook" EntitySet="OrderBooks" />
           </AssociationSet>
-        </EntityContainer>
+          </EntityContainer>
+        <EntityType Name="Book">
+          <Key>
+            <PropertyRef Name="id" />
+          </Key>
+          <Property Name="id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
+          <Property Name="title" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <Property Name="genre" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <Property Name="author" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <Property Name="countStrore" Type="Int32" />
+          <Property Name="countStock" Type="Int32" />
+          <Property Name="description" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <Property Name="cover" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
+          <Property Name="price" Type="Double" />
+          <NavigationProperty Name="OrderBooks" Relationship="Model.FK_OrderBooks_Book" FromRole="Book" ToRole="OrderBook" />
+        </EntityType>
         <EntityType Name="Order">
+          <Key>
+            <PropertyRef Name="id" />
+          </Key>
+          <Property Name="id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
+          <NavigationProperty Name="OrderBooks" Relationship="Model.FK_OrderBooks_Order1" FromRole="Order" ToRole="OrderBook" />
+          <Property Name="reserved" Type="DateTime" Precision="3" />
+        </EntityType>
+        <EntityType Name="OrderBook">
           <Key>
             <PropertyRef Name="id" />
           </Key>
           <Property Name="id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
           <Property Name="bookId" Type="Int32" />
-          <NavigationProperty Name="Book" Relationship="Model.FK_Order_Book" FromRole="Order" ToRole="Book" />
           <Property Name="count" Type="Int32" />
+          <NavigationProperty Name="Book" Relationship="Model.FK_OrderBooks_Book" FromRole="OrderBook" ToRole="Book" />
+          <Property Name="orderId" Type="Int32" Nullable="false" />
+          <NavigationProperty Name="Order1" Relationship="Model.FK_OrderBooks_Order1" FromRole="OrderBook" ToRole="Order" />
         </EntityType>
-        <Association Name="FK_Order_Book">
+        <Association Name="FK_OrderBooks_Book">
           <End Type="Model.Book" Role="Book" Multiplicity="0..1" />
-          <End Type="Model.Order" Role="Order" Multiplicity="*" />
+          <End Type="Model.OrderBook" Role="OrderBook" Multiplicity="*" />
           <ReferentialConstraint>
             <Principal Role="Book">
               <PropertyRef Name="id" />
             </Principal>
-            <Dependent Role="Order">
+            <Dependent Role="OrderBook">
               <PropertyRef Name="bookId" />
             </Dependent>
           </ReferentialConstraint>
         </Association>
-      </Schema>
+        <Association Name="FK_OrderBooks_Order1">
+          <End Type="Model.Order" Role="Order" Multiplicity="1" />
+          <End Type="Model.OrderBook" Role="OrderBook" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Order">
+              <PropertyRef Name="id" />
+            </Principal>
+            <Dependent Role="OrderBook">
+              <PropertyRef Name="orderId" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
+        </Schema>
     </edmx:ConceptualModels>
     <!-- C-S mapping content -->
     <edmx:Mappings>
       <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
         <EntityContainerMapping StorageEntityContainer="Хранилище ModelContainer" CdmEntityContainer="Entities">
-          <EntitySetMapping Name="Books">
-            <EntityTypeMapping TypeName="Model.Book">
-              <MappingFragment StoreEntitySet="Book">
-                <ScalarProperty Name="id" ColumnName="id" />
-                <ScalarProperty Name="title" ColumnName="title" />
-                <ScalarProperty Name="cover" ColumnName="cover" />
-                <ScalarProperty Name="genre" ColumnName="genre" />
-                <ScalarProperty Name="author" ColumnName="author" />
-                <ScalarProperty Name="description" ColumnName="description" />
-                <ScalarProperty Name="price" ColumnName="price" />
-                <ScalarProperty Name="countStrore" ColumnName="countStrore" />
-                <ScalarProperty Name="countStock" ColumnName="countStock" />
-              </MappingFragment>
-            </EntityTypeMapping>
-          </EntitySetMapping>
           <EntitySetMapping Name="sysdiagrams">
             <EntityTypeMapping TypeName="Model.sysdiagram">
               <MappingFragment StoreEntitySet="sysdiagrams">
@@ -149,9 +186,33 @@
               </MappingFragment>
             </EntityTypeMapping>
           </EntitySetMapping>
+          <EntitySetMapping Name="Books">
+            <EntityTypeMapping TypeName="Model.Book">
+              <MappingFragment StoreEntitySet="Book">
+                <ScalarProperty Name="price" ColumnName="price" />
+                <ScalarProperty Name="cover" ColumnName="cover" />
+                <ScalarProperty Name="description" ColumnName="description" />
+                <ScalarProperty Name="countStock" ColumnName="countStock" />
+                <ScalarProperty Name="countStrore" ColumnName="countStrore" />
+                <ScalarProperty Name="author" ColumnName="author" />
+                <ScalarProperty Name="genre" ColumnName="genre" />
+                <ScalarProperty Name="title" ColumnName="title" />
+                <ScalarProperty Name="id" ColumnName="id" />
+              </MappingFragment>
+            </EntityTypeMapping>
+          </EntitySetMapping>
           <EntitySetMapping Name="Orders">
             <EntityTypeMapping TypeName="Model.Order">
               <MappingFragment StoreEntitySet="Order">
+                <ScalarProperty Name="reserved" ColumnName="reserved" />
+                <ScalarProperty Name="id" ColumnName="id" />
+              </MappingFragment>
+            </EntityTypeMapping>
+          </EntitySetMapping>
+          <EntitySetMapping Name="OrderBooks">
+            <EntityTypeMapping TypeName="Model.OrderBook">
+              <MappingFragment StoreEntitySet="OrderBooks">
+                <ScalarProperty Name="orderId" ColumnName="orderId" />
                 <ScalarProperty Name="count" ColumnName="count" />
                 <ScalarProperty Name="bookId" ColumnName="bookId" />
                 <ScalarProperty Name="id" ColumnName="id" />

+ 6 - 4
Model1.edmx.diagram

@@ -5,11 +5,13 @@
     <!-- Diagram content (shape and connector positions) -->
     <edmx:Diagrams>
       <Diagram DiagramId="0a1c161441e64862850fc11b4f297ccd" Name="Diagram1">
-        <EntityTypeShape EntityType="Model.Book" Width="1.5" PointX="6.75" PointY="2" IsExpanded="true" />
         <EntityTypeShape EntityType="Model.sysdiagram" Width="1.5" PointX="2.75" PointY="0.75" IsExpanded="true" />
-        <EntityTypeShape EntityType="Model.Order" Width="1.5" PointX="10.5" PointY="2" />
-        <AssociationConnector Association="Model.FK_Order_Book" />
-      </Diagram>
+        <EntityTypeShape EntityType="Model.Book" Width="1.5" PointX="0.75" PointY="4" />
+        <EntityTypeShape EntityType="Model.Order" Width="1.5" PointX="0.75" PointY="0.75" />
+        <EntityTypeShape EntityType="Model.OrderBook" Width="1.5" PointX="3" PointY="4.5" />
+        <AssociationConnector Association="Model.FK_OrderBooks_Book" />
+        <AssociationConnector Association="Model.FK_OrderBooks_Order1" />
+        </Diagram>
     </edmx:Diagrams>
   </edmx:Designer>
 </edmx:Edmx>

+ 9 - 3
Order.cs

@@ -14,10 +14,16 @@ namespace WpfApp2
     
     public partial class Order
     {
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
+        public Order()
+        {
+            this.OrderBooks = new HashSet<OrderBook>();
+        }
+    
         public int id { get; set; }
-        public Nullable<int> bookId { get; set; }
-        public Nullable<int> count { get; set; }
+        public Nullable<System.DateTime> reserved { get; set; }
     
-        public virtual Book Book { get; set; }
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
+        public virtual ICollection<OrderBook> OrderBooks { get; set; }
     }
 }

+ 25 - 0
OrderBook.cs

@@ -0,0 +1,25 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Этот код создан по шаблону.
+//
+//     Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+//     Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace WpfApp2
+{
+    using System;
+    using System.Collections.Generic;
+    
+    public partial class OrderBook
+    {
+        public int id { get; set; }
+        public Nullable<int> bookId { get; set; }
+        public Nullable<int> count { get; set; }
+        public int orderId { get; set; }
+    
+        public virtual Book Book { get; set; }
+        public virtual Order Order1 { get; set; }
+    }
+}

+ 42 - 4
Pages/CartPage.xaml.cs

@@ -35,17 +35,55 @@ namespace WpfApp2.Pages
 
         private void Button_Click_1(object sender, RoutedEventArgs e)
         {
-            list.Items.Clear();
-            cart.Clear();
+            list.ItemsSource = null;
+            
+            var ord = new Order();
+            bool storeStock = false;
+            bool stock = true;
             foreach (var book in cart)
             {
-                var o = new Order();
+                var o = new OrderBook();
                 o.bookId = book.id;
                 o.count = book.Count;
+                o.orderId = ord.id;
+                if (book.countStrore <= 0)
+                {
+                    storeStock = true;
+                }
+                else
+                {
+                    stock = false;
+                }
+                DB.data.OrderBooks.Add(o);
+            }
+            ord.reserved = DateTime.Now.AddDays(7);
+            DB.data.Orders.Add(ord);
 
 
+            DB.data.SaveChanges();
+            string msg = $"Номер заказа {ord.id}\nМожно забрать - ";
+            if (!storeStock)
+            {
+                msg += $"{DateTime.Now}\n";
             }
-            string msg = $"";
+            else
+            {
+                if (stock)
+                {
+                    msg += $"{DateTime.Now.AddHours(72)}\n";
+                }
+                else
+                {
+                    msg += $"{DateTime.Now} и {DateTime.Now.AddHours(72)}\n";
+                }
+            }
+            msg += $"Общее количество - {cart.Sum(a => a.Count)} шт.\n";
+            msg += $"Общая сумма - {cart.Sum(a => a.price * a.Count)} руб.\n";
+            msg += $"Зарезервированно до - {DateTime.Now.AddDays(7)}\n";
+
+            MessageBox.Show(msg);
+            cart.Clear();
+            FrameClass.frame.Navigate(new ListPage());
         }
     }
 }

+ 2 - 2
Pages/ListPage.xaml

@@ -14,7 +14,7 @@
             <RowDefinition Height="*"/>
         </Grid.RowDefinitions>
         <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
-            <Button Content="Посмотреть корзину" Height="30" Margin="0 0 20 0" Click="Button_Click_1"/>
+            <Button Content="Посмотреть корзину" Margin="0 0 20 0" Click="Button_Click_1"/>
             <Border BorderBrush="Black" Padding="7" BorderThickness="1" Width="300" HorizontalAlignment="Right">
                 <StackPanel Grid.Row="0">
                     <TextBlock>
@@ -70,7 +70,7 @@
                                     <Run Text="{Binding description}"/>
                             </TextBlock>
                         </StackPanel>
-                        <Button Click="Button_Click" Height="50" Content="Добавить в корзину"/>
+                        <Button Click="Button_Click" Content="Добавить в корзину"/>
                     </StackPanel>
                 </DataTemplate>
             </ListView.ItemTemplate>

+ 3 - 0
WpfApp2.csproj

@@ -77,6 +77,9 @@
     <Compile Include="Order.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>
+    <Compile Include="OrderBook.cs">
+      <DependentUpon>Model1.tt</DependentUpon>
+    </Compile>
     <Compile Include="Pages\CartPage.xaml.cs">
       <DependentUpon>CartPage.xaml</DependentUpon>
     </Compile>