diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs b/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs
index cbf540d..6a58b74 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/ComputerShopDatabase.cs
@@ -15,7 +15,7 @@ namespace ComputersShopDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
- optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-1DE5E8N\SQLEXPRESS;Initial Catalog=ComputersShopDatabaseFull;
+ optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-1DE5E8N\SQLEXPRESS;Initial Catalog=ComputersShopDatabaseHard3;
Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/ShopStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/ShopStorage.cs
index bf472ff..a37fa87 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Implements/ShopStorage.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Implements/ShopStorage.cs
@@ -2,7 +2,9 @@
using ComputersShopContracts.SearchModels;
using ComputersShopContracts.StoragesContracts;
using ComputersShopContracts.ViewModels;
+using ComputersShopDatabaseImplement.Models;
using ComputersShopDataModels.Models;
+using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -166,3 +168,4 @@ namespace ComputersShopDatabaseImplement.Implements
}
}
}
+
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240519063447_HardCreate.Designer.cs
similarity index 67%
rename from ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.Designer.cs
rename to ComputersShop/ComputersShopDatabaseImplement/Migrations/20240519063447_HardCreate.Designer.cs
index 1ac4371..83a2c51 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.Designer.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240519063447_HardCreate.Designer.cs
@@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace ComputersShopDatabaseImplement.Migrations
{
[DbContext(typeof(ComputersShopDatabase))]
- [Migration("20240326105531_InitialCreate")]
- partial class InitialCreate
+ [Migration("20240519063447_HardCreate")]
+ partial class HardCreate
{
///
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -124,6 +124,59 @@ namespace ComputersShopDatabaseImplement.Migrations
b.ToTable("Orders");
});
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Shop", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Address")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("DateOpening")
+ .HasColumnType("datetime2");
+
+ b.Property("MaxComputers")
+ .HasColumnType("int");
+
+ b.Property("ShopName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Shops");
+ });
+
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ShopComputer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComputerId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ShopId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComputerId");
+
+ b.HasIndex("ShopId");
+
+ b.ToTable("ShopComputers");
+ });
+
modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b =>
{
b.HasOne("ComputersShopDatabaseImplement.Models.Component", "Component")
@@ -154,6 +207,25 @@ namespace ComputersShopDatabaseImplement.Migrations
b.Navigation("Computer");
});
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ShopComputer", b =>
+ {
+ b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer")
+ .WithMany()
+ .HasForeignKey("ComputerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("ComputersShopDatabaseImplement.Models.Shop", "Shop")
+ .WithMany("Computers")
+ .HasForeignKey("ShopId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Computer");
+
+ b.Navigation("Shop");
+ });
+
modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("ComputerComponents");
@@ -165,6 +237,11 @@ namespace ComputersShopDatabaseImplement.Migrations
b.Navigation("Orders");
});
+
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Shop", b =>
+ {
+ b.Navigation("Computers");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240519063447_HardCreate.cs
similarity index 65%
rename from ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.cs
rename to ComputersShop/ComputersShopDatabaseImplement/Migrations/20240519063447_HardCreate.cs
index 77f25f2..404b041 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240326105531_InitialCreate.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240519063447_HardCreate.cs
@@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace ComputersShopDatabaseImplement.Migrations
{
///
- public partial class InitialCreate : Migration
+ public partial class HardCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
@@ -39,6 +39,22 @@ namespace ComputersShopDatabaseImplement.Migrations
table.PrimaryKey("PK_Computers", x => x.Id);
});
+ migrationBuilder.CreateTable(
+ name: "Shops",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ShopName = table.Column(type: "nvarchar(max)", nullable: false),
+ Address = table.Column(type: "nvarchar(max)", nullable: false),
+ DateOpening = table.Column(type: "datetime2", nullable: false),
+ MaxComputers = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Shops", x => x.Id);
+ });
+
migrationBuilder.CreateTable(
name: "ComputerComponents",
columns: table => new
@@ -90,6 +106,33 @@ namespace ComputersShopDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
+ migrationBuilder.CreateTable(
+ name: "ShopComputers",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ShopId = table.Column(type: "int", nullable: false),
+ ComputerId = table.Column(type: "int", nullable: false),
+ Count = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_ShopComputers", x => x.Id);
+ table.ForeignKey(
+ name: "FK_ShopComputers_Computers_ComputerId",
+ column: x => x.ComputerId,
+ principalTable: "Computers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_ShopComputers_Shops_ShopId",
+ column: x => x.ShopId,
+ principalTable: "Shops",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
migrationBuilder.CreateIndex(
name: "IX_ComputerComponents_ComponentId",
table: "ComputerComponents",
@@ -104,6 +147,16 @@ namespace ComputersShopDatabaseImplement.Migrations
name: "IX_Orders_ComputerId",
table: "Orders",
column: "ComputerId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ShopComputers_ComputerId",
+ table: "ShopComputers",
+ column: "ComputerId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_ShopComputers_ShopId",
+ table: "ShopComputers",
+ column: "ShopId");
}
///
@@ -115,11 +168,17 @@ namespace ComputersShopDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Orders");
+ migrationBuilder.DropTable(
+ name: "ShopComputers");
+
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Computers");
+
+ migrationBuilder.DropTable(
+ name: "Shops");
}
}
}
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs
index 00020d3..28117ea 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/ComputersShopDatabaseModelSnapshot.cs
@@ -121,6 +121,59 @@ namespace ComputersShopDatabaseImplement.Migrations
b.ToTable("Orders");
});
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Shop", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Address")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("DateOpening")
+ .HasColumnType("datetime2");
+
+ b.Property("MaxComputers")
+ .HasColumnType("int");
+
+ b.Property("ShopName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Shops");
+ });
+
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ShopComputer", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ComputerId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("ShopId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ComputerId");
+
+ b.HasIndex("ShopId");
+
+ b.ToTable("ShopComputers");
+ });
+
modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ComputerComponent", b =>
{
b.HasOne("ComputersShopDatabaseImplement.Models.Component", "Component")
@@ -151,6 +204,25 @@ namespace ComputersShopDatabaseImplement.Migrations
b.Navigation("Computer");
});
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.ShopComputer", b =>
+ {
+ b.HasOne("ComputersShopDatabaseImplement.Models.Computer", "Computer")
+ .WithMany()
+ .HasForeignKey("ComputerId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("ComputersShopDatabaseImplement.Models.Shop", "Shop")
+ .WithMany("Computers")
+ .HasForeignKey("ShopId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Computer");
+
+ b.Navigation("Shop");
+ });
+
modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Component", b =>
{
b.Navigation("ComputerComponents");
@@ -162,6 +234,11 @@ namespace ComputersShopDatabaseImplement.Migrations
b.Navigation("Orders");
});
+
+ modelBuilder.Entity("ComputersShopDatabaseImplement.Models.Shop", b =>
+ {
+ b.Navigation("Computers");
+ });
#pragma warning restore 612, 618
}
}
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs
index 3fe84c4..7a252be 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs
@@ -12,34 +12,34 @@ namespace ComputersShopDatabaseImplement.Models
{
public class Order
{
- public int Id { get; private set; }
+ public int Id { get; set; }
[Required]
- public int ComputerId { get; private set; }
+ public int ComputerId { get; set; }
[Required]
- public int Count { get; private set; }
+ public int Count { get; set; }
[Required]
- public double Sum { get; private set; }
+ public double Sum { get; set; }
[Required]
- public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+ public OrderStatus Status { get; set; }
[Required]
- public DateTime DateCreate { get; private set; } = DateTime.Now;
- public DateTime? DateImplement { get; private set; }
- public virtual Computer Computer { get; private set; }
+ public DateTime DateCreate { get; set; }
+ public DateTime? DateImplement { get; set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
+
return new Order
{
+ Id = model.Id,
ComputerId = model.ComputerId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
- DateImplement = model.DateImplement,
- Id = model.Id,
+ DateImplement = model.DateImplement
};
}
public void Update(OrderBindingModel? model)
@@ -48,19 +48,19 @@ namespace ComputersShopDatabaseImplement.Models
{
return;
}
+
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
+ Id = Id,
ComputerId = ComputerId,
Count = Count,
Sum = Sum,
- DateCreate = DateCreate,
- DateImplement = DateImplement,
- Id = Id,
Status = Status,
- ComputerName = Computer.ComputerName
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
};
}
}
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Shop.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Shop.cs
index 8719b35..6d2bb4f 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Models/Shop.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Shop.cs
@@ -102,3 +102,4 @@ namespace ComputersShopDatabaseImplement.Models
}
}
}
+
diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/ShopComputer.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/ShopComputer.cs
index c616c30..21db4bd 100644
--- a/ComputersShop/ComputersShopDatabaseImplement/Models/ShopComputer.cs
+++ b/ComputersShop/ComputersShopDatabaseImplement/Models/ShopComputer.cs
@@ -21,4 +21,3 @@ namespace ComputersShopDatabaseImplement.Models
public virtual Computer Computer { get; set; } = new();
}
}
-
diff --git a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs
index ca02429..a123381 100644
--- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs
+++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs
@@ -43,8 +43,7 @@ namespace ComputersShopFileImplement.Implements
return null;
}
- return GetViewModel(_source.Orders
- .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
+ return GetViewModel(_source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
}
public OrderViewModel? Insert(OrderBindingModel model)
{
diff --git a/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs
index 0c656bf..0b303ae 100644
--- a/ComputersShop/ComputersShopView/FormMain.Designer.cs
+++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs
@@ -71,35 +71,35 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(218, 26);
this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// изделияToolStripMenuItem
//
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
- this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.изделияToolStripMenuItem.Size = new System.Drawing.Size(218, 26);
this.изделияToolStripMenuItem.Text = "Изделия";
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
- this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(218, 26);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click);
//
// поставкиToolStripMenuItem
//
this.поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem";
- this.поставкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.поставкиToolStripMenuItem.Size = new System.Drawing.Size(218, 26);
this.поставкиToolStripMenuItem.Text = "Поставки";
this.поставкиToolStripMenuItem.Click += new System.EventHandler(this.ПоставкиToolStripMenuItem_Click);
//
// продажаИзделийToolStripMenuItem
//
this.продажаИзделийToolStripMenuItem.Name = "продажаИзделийToolStripMenuItem";
- this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.продажаИзделийToolStripMenuItem.Size = new System.Drawing.Size(218, 26);
this.продажаИзделийToolStripMenuItem.Text = "Продажа изделий";
this.продажаИзделийToolStripMenuItem.Click += new System.EventHandler(this.ПродажаизделийToolStripMenuItem_Click);
//
@@ -144,7 +144,7 @@
this.buttonOrderReady.TabIndex = 4;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
- this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
+ this.buttonOrderReady.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonIssuedOrder
//
@@ -154,7 +154,7 @@
this.buttonIssuedOrder.TabIndex = 5;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
- this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
+ this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonRef
//
diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs
index 8071061..ae94c9f 100644
--- a/ComputersShop/ComputersShopView/Program.cs
+++ b/ComputersShop/ComputersShopView/Program.cs
@@ -1,7 +1,7 @@
using ComputersShopBusinessLogic.BusinessLogics;
using ComputersShopContracts.BusinessLogicsContracts;
using ComputersShopContracts.StoragesContracts;
-using ComputersShopFileImplement.Implements;
+using ComputersShopDatabaseImplement.Implements;
using ComputersShopView;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;