Фикс: старая миграция не видела clients, обновил её, также не было имён, фиксанул

This commit is contained in:
Леонид Малафеев 2024-04-05 14:16:27 +04:00
parent b7d380e81f
commit ecdc534a24
9 changed files with 577 additions and 539 deletions

View File

@ -22,6 +22,6 @@ namespace JewelryStoreDatabaseImplement
public virtual DbSet<Jewel> Jewels { set; get; }
public virtual DbSet<JewelComponent> JewelComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { get; set; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -1,122 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace JewelryStoreDatabaseImplement.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Jewels",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
JewelName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Jewels", x => x.Id);
});
migrationBuilder.CreateTable(
name: "JewelComponents",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
JewelId = table.Column<int>(type: "int", nullable: false),
ComponentId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_JewelComponents", x => x.Id);
table.ForeignKey(
name: "FK_JewelComponents_Components_ComponentId",
column: x => x.ComponentId,
principalTable: "Components",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_JewelComponents_Jewels_JewelId",
column: x => x.JewelId,
principalTable: "Jewels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
JewelId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Jewels_JewelId",
column: x => x.JewelId,
principalTable: "Jewels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_JewelComponents_ComponentId",
table: "JewelComponents",
column: "ComponentId");
migrationBuilder.CreateIndex(
name: "IX_JewelComponents_JewelId",
table: "JewelComponents",
column: "JewelId");
migrationBuilder.CreateIndex(
name: "IX_Orders_JewelId",
table: "Orders",
column: "JewelId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "JewelComponents");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "Jewels");
}
}
}

View File

@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace JewelryStoreDatabaseImplement.Migrations
{
[DbContext(typeof(JewelryStoreDatabase))]
[Migration("20240310110723_InitialCreate")]
partial class InitialCreate
[Migration("20240405100149_InitialCreateFix")]
partial class InitialCreateFix
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -24,6 +24,31 @@ namespace JewelryStoreDatabaseImplement.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
@ -98,6 +123,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
@ -118,6 +146,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("JewelId");
b.ToTable("Orders");
@ -144,15 +174,28 @@ namespace JewelryStoreDatabaseImplement.Migrations
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
{
b.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany("Orders")
.HasForeignKey("JewelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Jewel");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
{
b.Navigation("JewelComponents");

View File

@ -0,0 +1,65 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace JewelryStoreDatabaseImplement.Migrations
{
public partial class InitialCreateFix : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ClientId",
table: "Orders",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.AddForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders",
column: "ClientId",
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Orders_Clients_ClientId",
table: "Orders");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropIndex(
name: "IX_Orders_ClientId",
table: "Orders");
migrationBuilder.DropColumn(
name: "ClientId",
table: "Orders");
}
}
}

View File

@ -22,6 +22,31 @@ namespace JewelryStoreDatabaseImplement.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
@ -39,7 +64,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Components", (string)null);
b.ToTable("Components");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
@ -59,7 +84,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Jewels", (string)null);
b.ToTable("Jewels");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
@ -85,7 +110,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasIndex("JewelId");
b.ToTable("JewelComponents", (string)null);
b.ToTable("JewelComponents");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
@ -96,6 +121,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
@ -116,9 +144,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("JewelId");
b.ToTable("Orders", (string)null);
b.ToTable("Orders");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
@ -142,15 +172,28 @@ namespace JewelryStoreDatabaseImplement.Migrations
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
{
b.HasOne("JewelryStoreDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany("Orders")
.HasForeignKey("JewelId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
b.Navigation("Jewel");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Component", b =>
{
b.Navigation("JewelComponents");

View File

@ -57,17 +57,26 @@ namespace JewelryStoreDatabaseImplement.Models
Status = model.Status;
if (model.DateImplement.HasValue) DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
public OrderViewModel GetViewModel
{
get
{
using var context = new JewelryStoreDatabase();
return new OrderViewModel
{
Id = Id,
ClientId = ClientId,
JewelId = JewelId,
ClientId = ClientId,
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty,
JewelName = context.Jewels.FirstOrDefault(x => x.Id == JewelId)?.JewelName ?? string.Empty,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
}
}
}
}

View File

@ -33,8 +33,8 @@
справочникиToolStripMenuItem = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
изделияToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
клиентыToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem();
списокКомпонентовToolStripMenuItem = new ToolStripMenuItem();
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
@ -54,7 +54,7 @@
dataGridView.Location = new Point(12, 31);
dataGridView.Name = "dataGridView";
dataGridView.RowTemplate.Height = 25;
dataGridView.Size = new Size(762, 407);
dataGridView.Size = new Size(970, 407);
dataGridView.TabIndex = 0;
//
// menuStripMain
@ -62,7 +62,7 @@
menuStripMain.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem });
menuStripMain.Location = new Point(0, 0);
menuStripMain.Name = "menuStripMain";
menuStripMain.Size = new Size(1039, 24);
menuStripMain.Size = new Size(1223, 24);
menuStripMain.TabIndex = 2;
menuStripMain.Text = "menuStripMain";
//
@ -90,7 +90,7 @@
// клиентыToolStripMenuItem
//
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
клиентыToolStripMenuItem.Size = new Size(180, 22);
клиентыToolStripMenuItem.Size = new Size(145, 22);
клиентыToolStripMenuItem.Text = "Клиенты";
клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click;
//
@ -124,7 +124,7 @@
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(836, 31);
buttonCreateOrder.Location = new Point(1012, 31);
buttonCreateOrder.Margin = new Padding(2);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(147, 34);
@ -135,7 +135,7 @@
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(836, 81);
buttonTakeOrderInWork.Location = new Point(1012, 81);
buttonTakeOrderInWork.Margin = new Padding(2);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(147, 36);
@ -146,7 +146,7 @@
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(836, 132);
buttonOrderReady.Location = new Point(1012, 132);
buttonOrderReady.Margin = new Padding(2);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(147, 34);
@ -157,7 +157,7 @@
//
// buttonIssuedOrder
//
buttonIssuedOrder.Location = new Point(836, 183);
buttonIssuedOrder.Location = new Point(1012, 183);
buttonIssuedOrder.Margin = new Padding(2);
buttonIssuedOrder.Name = "buttonIssuedOrder";
buttonIssuedOrder.Size = new Size(147, 35);
@ -168,7 +168,7 @@
//
// buttonRefresh
//
buttonRefresh.Location = new Point(836, 234);
buttonRefresh.Location = new Point(1012, 234);
buttonRefresh.Margin = new Padding(2);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(147, 39);
@ -181,7 +181,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1039, 450);
ClientSize = new Size(1223, 450);
Controls.Add(buttonRefresh);
Controls.Add(buttonIssuedOrder);
Controls.Add(buttonOrderReady);