Complete hard lab 3

This commit is contained in:
Viltskaa 2023-03-28 10:06:56 +04:00
parent c46aebdc08
commit d8422b1ef1
10 changed files with 283 additions and 56 deletions

View File

@ -34,8 +34,6 @@
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.storeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sushiToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonSubmit = new System.Windows.Forms.Button();
this.buttonReady = new System.Windows.Forms.Button();
@ -43,6 +41,8 @@
this.buttonReload = new System.Windows.Forms.Button();
this.buttonReplenishment = new System.Windows.Forms.Button();
this.ButtonSell = new System.Windows.Forms.Button();
this.buttonReplenisment = new System.Windows.Forms.Button();
this.buttonSelll = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -62,7 +62,7 @@
this.directoryToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(940, 24);
this.menuStrip1.Size = new System.Drawing.Size(937, 24);
this.menuStrip1.TabIndex = 1;
this.menuStrip1.Text = "menuStrip1";
//
@ -97,20 +97,6 @@
this.storeToolStripMenuItem.Text = "Store";
this.storeToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
//
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.componentsToolStripMenuItem.Text = "Components";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// sushiToolStripMenuItem
//
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(143, 22);
this.sushiToolStripMenuItem.Text = "Sushi";
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(814, 27);
@ -161,25 +147,47 @@
this.buttonReload.UseVisualStyleBackColor = true;
this.buttonReload.Click += new System.EventHandler(this.ButtonReload_Click);
//
// componentsToolStripMenuItem
// buttonReplenishment
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.componentsToolStripMenuItem.Text = "Components";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
this.buttonReplenishment.Location = new System.Drawing.Point(0, 0);
this.buttonReplenishment.Name = "buttonReplenishment";
this.buttonReplenishment.Size = new System.Drawing.Size(75, 23);
this.buttonReplenishment.TabIndex = 0;
//
// sushiToolStripMenuItem
// ButtonSell
//
this.sushiToolStripMenuItem.Name = "sushiToolStripMenuItem";
this.sushiToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.sushiToolStripMenuItem.Text = "Sushi";
this.sushiToolStripMenuItem.Click += new System.EventHandler(this.SushiToolStripMenuItem_Click);
this.ButtonSell.Location = new System.Drawing.Point(0, 0);
this.ButtonSell.Name = "ButtonSell";
this.ButtonSell.Size = new System.Drawing.Size(75, 23);
this.ButtonSell.TabIndex = 0;
//
// buttonReplenisment
//
this.buttonReplenisment.Location = new System.Drawing.Point(814, 415);
this.buttonReplenisment.Name = "buttonReplenisment";
this.buttonReplenisment.Size = new System.Drawing.Size(111, 23);
this.buttonReplenisment.TabIndex = 7;
this.buttonReplenisment.Text = "Replenishment";
this.buttonReplenisment.UseVisualStyleBackColor = true;
this.buttonReplenisment.Click += new System.EventHandler(this.ButtonReplenishment_Click);
//
// buttonSelll
//
this.buttonSelll.Location = new System.Drawing.Point(814, 386);
this.buttonSelll.Name = "buttonSelll";
this.buttonSelll.Size = new System.Drawing.Size(111, 23);
this.buttonSelll.TabIndex = 8;
this.buttonSelll.Text = "Sell";
this.buttonSelll.UseVisualStyleBackColor = true;
this.buttonSelll.Click += new System.EventHandler(this.ButtonSell_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.ClientSize = new System.Drawing.Size(937, 450);
this.Controls.Add(this.buttonSelll);
this.Controls.Add(this.buttonReplenisment);
this.Controls.Add(this.buttonReload);
this.Controls.Add(this.buttonIssue);
this.Controls.Add(this.buttonReady);
@ -214,5 +222,7 @@
private ToolStripMenuItem storeToolStripMenuItem;
private Button buttonReplenishment;
private Button ButtonSell;
private Button buttonReplenisment;
private Button buttonSelll;
}
}

View File

@ -4,7 +4,7 @@ using NLog.Extensions.Logging;
using SushiBarBusinessLogic.BusinessLogics;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
using SushiBarFileImplement.Implements;
using SushiBarDatabaseImplement.Implements;
namespace SushiBar
{

View File

@ -13,13 +13,13 @@ namespace SushiBarDatabaseImplement.Implements
{
using var context = new SushiBarDatabase();
var element = context.Sushi
var element = context.Sushis
.Include(x => x.Components)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Sushi.Remove(element);
context.Sushis.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
@ -36,7 +36,7 @@ namespace SushiBarDatabaseImplement.Implements
using var context = new SushiBarDatabase();
return context.Sushi
return context.Sushis
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.FirstOrDefault(x => (
@ -55,7 +55,7 @@ namespace SushiBarDatabaseImplement.Implements
using var context = new SushiBarDatabase();
return context.Sushi
return context.Sushis
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.Where(x => x.SushiName.Contains(model.SushiName))
@ -68,7 +68,7 @@ namespace SushiBarDatabaseImplement.Implements
{
using var context = new SushiBarDatabase();
return context.Sushi
return context.Sushis
.Include(x => x.Components)
.ThenInclude(x => x.Component)
.ToList().Select(x => x.GetViewModel)
@ -86,7 +86,7 @@ namespace SushiBarDatabaseImplement.Implements
return null;
}
context.Sushi.Add(newSushi);
context.Sushis.Add(newSushi);
context.SaveChanges();
return newSushi.GetViewModel;
@ -98,7 +98,7 @@ namespace SushiBarDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try {
var sushi = context.Sushi.FirstOrDefault(rec => rec.Id == model.Id);
var sushi = context.Sushis.FirstOrDefault(rec => rec.Id == model.Id);
if (sushi == null)
{

View File

@ -12,8 +12,8 @@ using SushiBarDatabaseImplement;
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
[Migration("20230227124505_InitialCreate")]
partial class InitialCreate
[Migration("20230328054704_init")]
partial class init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -82,6 +82,59 @@ namespace SushiBarDatabaseImplement.Migrations
b.ToTable("Orders");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Store", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.Property<string>("StoreAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("StoreName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("maxSushi")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Stores");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.StoreSushi", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("StoreId")
.HasColumnType("int");
b.Property<int>("SushiId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StoreId");
b.HasIndex("SushiId");
b.ToTable("StoreSushis");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Property<int>("Id")
@ -99,7 +152,7 @@ namespace SushiBarDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Sushi");
b.ToTable("Sushis");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
@ -139,6 +192,25 @@ namespace SushiBarDatabaseImplement.Migrations
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.StoreSushi", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Store", "Store")
.WithMany("StoreSushi")
.HasForeignKey("StoreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany()
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Store");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
@ -163,6 +235,11 @@ namespace SushiBarDatabaseImplement.Migrations
b.Navigation("SushiComponent");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Store", b =>
{
b.Navigation("StoreSushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Navigation("Components");

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace SushiBarDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
public partial class init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -26,7 +26,23 @@ namespace SushiBarDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "Sushi",
name: "Stores",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
StoreName = table.Column<string>(type: "nvarchar(max)", nullable: false),
StoreAddress = table.Column<string>(type: "nvarchar(max)", nullable: false),
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
maxSushi = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stores", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sushis",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
@ -36,7 +52,7 @@ namespace SushiBarDatabaseImplement.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Sushi", x => x.Id);
table.PrimaryKey("PK_Sushis", x => x.Id);
});
migrationBuilder.CreateTable(
@ -57,9 +73,36 @@ namespace SushiBarDatabaseImplement.Migrations
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Sushi_SushiId",
name: "FK_Orders_Sushis_SushiId",
column: x => x.SushiId,
principalTable: "Sushi",
principalTable: "Sushis",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "StoreSushis",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
SushiId = table.Column<int>(type: "int", nullable: false),
StoreId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StoreSushis", x => x.Id);
table.ForeignKey(
name: "FK_StoreSushis_Stores_StoreId",
column: x => x.StoreId,
principalTable: "Stores",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_StoreSushis_Sushis_SushiId",
column: x => x.SushiId,
principalTable: "Sushis",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -84,9 +127,9 @@ namespace SushiBarDatabaseImplement.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SushiComponents_Sushi_SushiId",
name: "FK_SushiComponents_Sushis_SushiId",
column: x => x.SushiId,
principalTable: "Sushi",
principalTable: "Sushis",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -96,6 +139,16 @@ namespace SushiBarDatabaseImplement.Migrations
table: "Orders",
column: "SushiId");
migrationBuilder.CreateIndex(
name: "IX_StoreSushis_StoreId",
table: "StoreSushis",
column: "StoreId");
migrationBuilder.CreateIndex(
name: "IX_StoreSushis_SushiId",
table: "StoreSushis",
column: "SushiId");
migrationBuilder.CreateIndex(
name: "IX_SushiComponents_ComponentId",
table: "SushiComponents",
@ -113,14 +166,20 @@ namespace SushiBarDatabaseImplement.Migrations
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "StoreSushis");
migrationBuilder.DropTable(
name: "SushiComponents");
migrationBuilder.DropTable(
name: "Stores");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Sushi");
name: "Sushis");
}
}
}

View File

@ -11,7 +11,7 @@ using SushiBarDatabaseImplement;
namespace SushiBarDatabaseImplement.Migrations
{
[DbContext(typeof(SushiBarDatabase))]
partial class SushiDatabaseModelSnapshot : ModelSnapshot
partial class SushiBarDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
@ -79,6 +79,59 @@ namespace SushiBarDatabaseImplement.Migrations
b.ToTable("Orders");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Store", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("OpeningDate")
.HasColumnType("datetime2");
b.Property<string>("StoreAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("StoreName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("maxSushi")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Stores");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.StoreSushi", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("StoreId")
.HasColumnType("int");
b.Property<int>("SushiId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("StoreId");
b.HasIndex("SushiId");
b.ToTable("StoreSushis");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Property<int>("Id")
@ -96,7 +149,7 @@ namespace SushiBarDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Sushi");
b.ToTable("Sushis");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
@ -136,6 +189,25 @@ namespace SushiBarDatabaseImplement.Migrations
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.StoreSushi", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Store", "Store")
.WithMany("StoreSushi")
.HasForeignKey("StoreId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
.WithMany()
.HasForeignKey("SushiId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Store");
b.Navigation("Sushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
{
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
@ -160,6 +232,11 @@ namespace SushiBarDatabaseImplement.Migrations
b.Navigation("SushiComponent");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Store", b =>
{
b.Navigation("StoreSushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
{
b.Navigation("Components");

View File

@ -27,7 +27,7 @@ public class Store : IStoreModel
{
using var context = new SushiBarDatabase();
_sushis = StoreSushi
.ToDictionary(x => x.SushiId, x => (context.Sushi
.ToDictionary(x => x.SushiId, x => (context.Sushis
.FirstOrDefault(y => y.Id == x.SushiId)! as ISushiModel, x.Count));
}
@ -54,7 +54,7 @@ public class Store : IStoreModel
maxSushi = model.maxSushi,
StoreSushi = model.Sushis.Select(x => new StoreSushi()
{
Sushi = context.Sushi.FirstOrDefault(y => y.Id == x.Key)!,
Sushi = context.Sushis.FirstOrDefault(y => y.Id == x.Key)!,
Count = x.Value.Item2
}).ToList()
};
@ -103,7 +103,7 @@ public class Store : IStoreModel
var shop = context.Stores.First(x => x.Id == model.Id);
shop.StoreSushi.AddRange(model.Sushis.Select(x => new StoreSushi()
{
Sushi = context.Sushi.First(y => y.Id == x.Key),
Sushi = context.Sushis.First(y => y.Id == x.Key),
Count = x.Value.Item2,
}).Except(StoreSushi));
context.SaveChanges();

View File

@ -58,7 +58,7 @@ namespace SushiBarDatabaseImplement.Models
public void UpdateComponents(SushiBarDatabase context, SushiBindingModel model)
{
var sushiComponents = context.SushiComponents.Where(rec => rec.SushiId == model.Id).ToList();
if (sushiComponents != null && sushiComponents.Count > 0)
if (sushiComponents is { Count: > 0 })
{
context.SushiComponents.RemoveRange(sushiComponents.Where(rec => !model.SushiComponents.ContainsKey(rec.ComponentId)));
context.SaveChanges();
@ -70,7 +70,7 @@ namespace SushiBarDatabaseImplement.Models
}
context.SaveChanges();
}
var sushi = context.Sushi.First(x => x.Id == Id);
var sushi = context.Sushis.First(x => x.Id == Id);
foreach (var pc in model.SushiComponents)
{
context.SushiComponents.Add(new SushiComponent

View File

@ -9,12 +9,12 @@ namespace SushiBarDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-QKSH4DCA\SQLEXPRESS;Initial Catalog=SushiBarDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-QKSH4DCA\SQLEXPRESS;Initial Catalog=SushiBarDataBaseHard;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Sushi> Sushi { set; get; }
public virtual DbSet<Sushi> Sushis { set; get; }
public virtual DbSet<SushiComponent> SushiComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Store> Stores { get; set; }

View File

@ -19,4 +19,8 @@
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations" />
</ItemGroup>
</Project>