diff --git a/FlowerShopBusinessLogic/OrderLogic.cs b/FlowerShopBusinessLogic/OrderLogic.cs index b2a706c..a0afe27 100644 --- a/FlowerShopBusinessLogic/OrderLogic.cs +++ b/FlowerShopBusinessLogic/OrderLogic.cs @@ -24,7 +24,6 @@ namespace FlowerShopBusinessLogic.BusinessLogic static readonly object locker = new object(); public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IFlowerStorage flowerStorage, ILogger logger) - public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _orderStorage = orderStorage; _shopStorage = shopStorage; @@ -84,23 +83,23 @@ namespace FlowerShopBusinessLogic.BusinessLogic _logger.LogWarning("Read operation failed"); return false; } - if (element.Status != status - 1) + if (!(element.Status == status - 1 || (element.Status == OrderStatus.Готов ))) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - if (element.Status == OrderStatus.Готов) + if (element.Status == OrderStatus.Готов || element.Status == OrderStatus.Ожидает) { - var flower = _flowerStorage.GetElement(new FlowerSearchModel() { Id = model.FlowerId }); + var flower = _flowerStorage.GetElement(new FlowerSearchModel() { Id = element.FlowerId }); if (flower == null) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found."); return false; } - if (CheckSupply(flower, model.Count) == false) + if (CheckSupply(flower, element.Count) == false) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error."); - return false; + status = OrderStatus.Ожидает; } } model.Status = status; @@ -127,7 +126,7 @@ namespace FlowerShopBusinessLogic.BusinessLogic public bool DeliveryOrder(OrderBindingModel model) { return ChangeStatus(model, OrderStatus.Выдан); - } + } private void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/FlowerShopBusinessLogic/WorkProcess.cs b/FlowerShopBusinessLogic/WorkProcess.cs index 6dd304a..131c6ca 100644 --- a/FlowerShopBusinessLogic/WorkProcess.cs +++ b/FlowerShopBusinessLogic/WorkProcess.cs @@ -31,19 +31,21 @@ namespace FlowerShopBusinessLogic _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel + var deliveredOrders = _orderLogic.ReadList(new OrderSearchModel { - Status = OrderStatus.Принят + Status = OrderStatus.Выдан }); - if (orders == null || orders.Count == 0) + var allOrders = _orderLogic.ReadList(null); + if (allOrders == null || deliveredOrders == null || allOrders.Count == deliveredOrders.Count ) { _logger.LogWarning("DoWork. Orders is null or empty"); return; } - _logger.LogDebug("DoWork for {Count} orders", orders.Count); + deliveredOrders.ForEach(x=> allOrders.Remove(x)); + _logger.LogDebug("DoWork for {Count} orders", allOrders.Count); foreach (var implementer in implementers) { - Task.Run(() => WorkerWorkAsync(implementer, orders)); + Task.Run(() => WorkerWorkAsync(implementer, allOrders)); } } /// Иммитация работы исполнителя @@ -53,6 +55,7 @@ namespace FlowerShopBusinessLogic { return; } + await DeliverWaitingOrder(implementer); await RunOrderInWork(implementer); await Task.Run(() => { @@ -75,6 +78,7 @@ namespace FlowerShopBusinessLogic { Id = order.Id }); + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = order.Id }); // отдыхаем Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } @@ -119,6 +123,7 @@ namespace FlowerShopBusinessLogic { Id = runOrder.Id }); + _orderLogic.DeliveryOrder(new OrderBindingModel { Id = runOrder.Id }); // отдыхаем Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } @@ -134,5 +139,46 @@ namespace FlowerShopBusinessLogic throw; } } + private async Task DeliverWaitingOrder(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Ожидает + })); + if (waitingOrders == null || waitingOrders.Count == 0) + { + return; + } + _logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count); + foreach (var waitingOrder in waitingOrders) + { + try + { + _logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id); + var res = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = waitingOrder.Id + }); + } + catch (ArgumentException ex) + { + _logger.LogWarning(ex, "DeliverWaitingOrder. Fault"); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try deliver order"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } } } diff --git a/FlowerShopDataModels/OrderStatus.cs b/FlowerShopDataModels/OrderStatus.cs index 2095810..4660a67 100644 --- a/FlowerShopDataModels/OrderStatus.cs +++ b/FlowerShopDataModels/OrderStatus.cs @@ -6,6 +6,7 @@ Принят = 0, Выполняется = 1, Готов = 2, - Выдан = 3 - } + Ожидает = 3, + Выдан = 4 + } } \ No newline at end of file diff --git a/FlowerShopDatabaseImplement/Migrations/20240507180802_InitialCreate.Designer.cs b/FlowerShopDatabaseImplement/Migrations/20240507180802_InitialCreate.Designer.cs new file mode 100644 index 0000000..9083245 --- /dev/null +++ b/FlowerShopDatabaseImplement/Migrations/20240507180802_InitialCreate.Designer.cs @@ -0,0 +1,335 @@ +// +using System; +using FlowerShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FlowerShopDatabaseImplement.Migrations +{ + [DbContext(typeof(FlowerShopDataBase))] + [Migration("20240507180802_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Flower", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("FlowerName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Flowers"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.FlowerComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FlowerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("FlowerId"); + + b.ToTable("FlowerComponents"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("FlowerId") + .HasColumnType("int"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("FlowerId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateOpen") + .HasColumnType("datetime2"); + + b.Property("MaxCapacity") + .HasColumnType("int"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("FlowerId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("FlowerId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopFlowers"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.FlowerComponent", b => + { + b.HasOne("FlowerShopDatabaseImplement.Models.Component", "Component") + .WithMany("FlowerComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower") + .WithMany("Components") + .HasForeignKey("FlowerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Flower"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower") + .WithMany("Orders") + .HasForeignKey("FlowerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Client"); + + b.Navigation("Flower"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b => + { + b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower") + .WithMany("ShopFlowers") + .HasForeignKey("FlowerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FlowerShopDatabaseImplement.Models.Shop", "Shop") + .WithMany("Flowers") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Flower"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b => + { + b.Navigation("FlowerComponents"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Flower", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("ShopFlowers"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Flowers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FlowerShopDatabaseImplement/Migrations/20240507180802_InitialCreate.cs b/FlowerShopDatabaseImplement/Migrations/20240507180802_InitialCreate.cs new file mode 100644 index 0000000..23c24ad --- /dev/null +++ b/FlowerShopDatabaseImplement/Migrations/20240507180802_InitialCreate.cs @@ -0,0 +1,241 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FlowerShopDatabaseImplement.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Flowers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FlowerName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Flowers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", 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), + DateOpen = table.Column(type: "datetime2", nullable: false), + MaxCapacity = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "FlowerComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FlowerId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FlowerComponents", x => x.Id); + table.ForeignKey( + name: "FK_FlowerComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FlowerComponents_Flowers_FlowerId", + column: x => x.FlowerId, + principalTable: "Flowers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + FlowerId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Flowers_FlowerId", + column: x => x.FlowerId, + principalTable: "Flowers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "ShopFlowers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FlowerId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopFlowers", x => x.Id); + table.ForeignKey( + name: "FK_ShopFlowers_Flowers_FlowerId", + column: x => x.FlowerId, + principalTable: "Flowers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopFlowers_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_FlowerComponents_ComponentId", + table: "FlowerComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_FlowerComponents_FlowerId", + table: "FlowerComponents", + column: "FlowerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_FlowerId", + table: "Orders", + column: "FlowerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopFlowers_FlowerId", + table: "ShopFlowers", + column: "FlowerId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopFlowers_ShopId", + table: "ShopFlowers", + column: "ShopId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "FlowerComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "ShopFlowers"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropTable( + name: "Flowers"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/FlowerShopDatabaseImplement/Migrations/FlowerShopDataBaseModelSnapshot.cs b/FlowerShopDatabaseImplement/Migrations/FlowerShopDataBaseModelSnapshot.cs index 386e995..fab4283 100644 --- a/FlowerShopDatabaseImplement/Migrations/FlowerShopDataBaseModelSnapshot.cs +++ b/FlowerShopDatabaseImplement/Migrations/FlowerShopDataBaseModelSnapshot.cs @@ -280,11 +280,6 @@ namespace FlowerShopDatabaseImplement.Migrations b.Navigation("Implementer"); }); - modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b => - { - b.Navigation("Orders"); - }); - modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b => { b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower") @@ -304,6 +299,11 @@ namespace FlowerShopDatabaseImplement.Migrations b.Navigation("Shop"); }); + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b => { b.Navigation("FlowerComponents"); @@ -318,15 +318,15 @@ namespace FlowerShopDatabaseImplement.Migrations b.Navigation("ShopFlowers"); }); - modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b => - { - b.Navigation("Flowers"); - }); - modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Implementer", b => { b.Navigation("Orders"); }); + + modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b => + { + b.Navigation("Flowers"); + }); #pragma warning restore 612, 618 } } diff --git a/FlowerShopFileImplement/DataFileSingleton.cs b/FlowerShopFileImplement/DataFileSingleton.cs index ff6bea3..711c18a 100644 --- a/FlowerShopFileImplement/DataFileSingleton.cs +++ b/FlowerShopFileImplement/DataFileSingleton.cs @@ -14,14 +14,12 @@ internal class DataFileSingleton private readonly string ShopFileName = "Shops.xml"; public List Components { get; private set; } private readonly string ImplementerFileName = "Implementer.xml"; - public List Components { get; private set; } public List Orders { get; private set; } public List Flowers { get; private set; } public List Clients { get; private set; } public List Implementers { get; private set; } public List Shops { get; private set; } - public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance() { if (instance == null) @@ -47,9 +45,7 @@ internal class DataFileSingleton Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; - Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; - } Implementers = LoadData(ImplementerFileName, "Implementer", x =>Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/FlowerShopListImplement/OrderStorage.cs b/FlowerShopListImplement/OrderStorage.cs index c1ac8b0..bc23731 100644 --- a/FlowerShopListImplement/OrderStorage.cs +++ b/FlowerShopListImplement/OrderStorage.cs @@ -127,7 +127,7 @@ namespace FlowerShopListImplement.Implements model.ClientFIO = client.ClientFIO; return model; } - } + public OrderViewModel AccessStorage(OrderViewModel model) { if (model == null) diff --git a/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs index 221679f..0482b48 100644 --- a/ProjectFlowerShop/MainForm.Designer.cs +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -30,21 +30,21 @@ { menuStrip1 = new MenuStrip(); ToolStripMenu = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); КомпонентыStripMenuItem = new ToolStripMenuItem(); ЦветыStripMenuItem = 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(); - стартРабот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(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -61,97 +61,76 @@ menuStrip1.Items.AddRange(new ToolStripItem[] { ToolStripMenu, отчетыToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; - menuStrip1.Size = new Size(1422, 28); + menuStrip1.Size = new Size(1296, 28); menuStrip1.TabIndex = 0; menuStrip1.Text = "menuStrip1"; // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem, стартРаботToolStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { клиентыToolStripMenuItem, КомпонентыStripMenuItem, ЦветыStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem, продажиToolStripMenuItem, исполнителиToolStripMenuItem, начатьРаботуToolStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(117, 24); ToolStripMenu.Text = "Справочники"; // - // списокМагазиновToolStripMenuItem + // клиентыToolStripMenuItem // - списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; - списокМагазиновToolStripMenuItem.Size = new Size(280, 26); - списокМагазиновToolStripMenuItem.Text = "Список магазинов"; - списокМагазиновToolStripMenuItem.Click += списокМагазиновToolStripMenuItem_Click; - // - // цветыПоМагазинамToolStripMenuItem - // - цветыПоМагазинамToolStripMenuItem.Name = "цветыПоМагазинамToolStripMenuItem"; - цветыПоМагазинамToolStripMenuItem.Size = new Size(280, 26); - цветыПоМагазинамToolStripMenuItem.Text = "Цветы по магазинам"; - цветыПоМагазинамToolStripMenuItem.Click += цветыПоМагазинамToolStripMenuItem_Click; - // - // заказыПоДатамToolStripMenuItem - // - заказыПоДатамToolStripMenuItem.Name = "заказыПоДатамToolStripMenuItem"; - заказыПоДатамToolStripMenuItem.Size = new Size(280, 26); - заказыПоДатамToolStripMenuItem.Text = "Заказы по датам"; - заказыПоДатамToolStripMenuItem.Click += заказыПоДатамToolStripMenuItem_Click; - // - // магазиныToolStripMenuItem - // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(182, 26); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; - // - // поставкиToolStripMenuItem - // - поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; - поставкиToolStripMenuItem.Size = new Size(182, 26); - поставкиToolStripMenuItem.Text = "Поставки"; - поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click; - // - // продажиToolStripMenuItem - // - продажиToolStripMenuItem.Name = "продажиToolStripMenuItem"; - продажиToolStripMenuItem.Size = new Size(182, 26); - продажиToolStripMenuItem.Text = "Продажи"; - продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click; + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(224, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; // // КомпонентыStripMenuItem // КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; - КомпонентыStripMenuItem.Size = new Size(185, 26); + КомпонентыStripMenuItem.Size = new Size(224, 26); КомпонентыStripMenuItem.Text = "Компоненты"; КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; // // ЦветыStripMenuItem // ЦветыStripMenuItem.Name = "ЦветыStripMenuItem"; - ЦветыStripMenuItem.Size = new Size(185, 26); + ЦветыStripMenuItem.Size = new Size(224, 26); ЦветыStripMenuItem.Text = "Цветы"; ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click; // - // клиентыToolStripMenuItem + // магазиныToolStripMenuItem // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(185, 26); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // поставкиToolStripMenuItem + // + поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + поставкиToolStripMenuItem.Size = new Size(224, 26); + поставкиToolStripMenuItem.Text = "Поставки"; + поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click; + // + // продажиToolStripMenuItem + // + продажиToolStripMenuItem.Name = "продажиToolStripMenuItem"; + продажиToolStripMenuItem.Size = new Size(224, 26); + продажиToolStripMenuItem.Text = "Продажи"; + продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click; // // исполнителиToolStripMenuItem // исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; - исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Size = new Size(224, 26); исполнителиToolStripMenuItem.Text = "Исполнители"; исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; // - // стартРаботToolStripMenuItem + // начатьРаботуToolStripMenuItem // - стартРаботToolStripMenuItem.Name = "стартРаботToolStripMenuItem"; - стартРаботToolStripMenuItem.Size = new Size(185, 26); - стартРаботToolStripMenuItem.Text = "Старт работ"; - стартРаботToolStripMenuItem.Click += стартРаботToolStripMenuItem_Click; + начатьРаботуToolStripMenuItem.Name = "начатьРаботуToolStripMenuItem"; + начатьРаботуToolStripMenuItem.Size = new Size(224, 26); + начатьРаботуToolStripMenuItem.Text = "Начать работу"; + начатьРаботуToolStripMenuItem.Click += начатьРаботуToolStripMenuItem_Click; // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыToolStripMenuItem, списокЗаказовToolStripMenuItem, списокМагазиновToolStripMenuItem, цветыПоМагазинамToolStripMenuItem, заказыПоДатамToolStripMenuItem }); отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; @@ -177,18 +156,39 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // + // списокМагазиновToolStripMenuItem + // + списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + списокМагазиновToolStripMenuItem.Size = new Size(280, 26); + списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + списокМагазиновToolStripMenuItem.Click += списокМагазиновToolStripMenuItem_Click; + // + // цветыПоМагазинамToolStripMenuItem + // + цветыПоМагазинамToolStripMenuItem.Name = "цветыПоМагазинамToolStripMenuItem"; + цветыПоМагазинамToolStripMenuItem.Size = new Size(280, 26); + цветыПоМагазинамToolStripMenuItem.Text = "Цветы по магазинам"; + цветыПоМагазинамToolStripMenuItem.Click += цветыПоМагазинамToolStripMenuItem_Click; + // + // заказыПоДатамToolStripMenuItem + // + заказыПоДатамToolStripMenuItem.Name = "заказыПоДатамToolStripMenuItem"; + заказыПоДатамToolStripMenuItem.Size = new Size(280, 26); + заказыПоДатамToolStripMenuItem.Text = "Заказы по датам"; + заказыПоДатамToolStripMenuItem.Click += заказыПоДатамToolStripMenuItem_Click; + // // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.Location = new Point(12, 31); DataGridView.Name = "DataGridView"; DataGridView.RowHeadersWidth = 51; - DataGridView.Size = new Size(1133, 407); + DataGridView.Size = new Size(1007, 407); DataGridView.TabIndex = 1; // // CreateOrderButton // - CreateOrderButton.Location = new Point(1151, 31); + CreateOrderButton.Location = new Point(1025, 31); CreateOrderButton.Name = "CreateOrderButton"; CreateOrderButton.Size = new Size(259, 29); CreateOrderButton.TabIndex = 2; @@ -198,7 +198,7 @@ // // TakeInWorkButton // - TakeInWorkButton.Location = new Point(1151, 66); + TakeInWorkButton.Location = new Point(1025, 66); TakeInWorkButton.Name = "TakeInWorkButton"; TakeInWorkButton.Size = new Size(259, 29); TakeInWorkButton.TabIndex = 3; @@ -208,7 +208,7 @@ // // ReadyButton // - ReadyButton.Location = new Point(1151, 101); + ReadyButton.Location = new Point(1025, 101); ReadyButton.Name = "ReadyButton"; ReadyButton.Size = new Size(259, 29); ReadyButton.TabIndex = 4; @@ -218,7 +218,7 @@ // // IssuedButton // - IssuedButton.Location = new Point(1151, 136); + IssuedButton.Location = new Point(1025, 136); IssuedButton.Name = "IssuedButton"; IssuedButton.Size = new Size(259, 29); IssuedButton.TabIndex = 5; @@ -228,7 +228,7 @@ // // RefreshButton // - RefreshButton.Location = new Point(1151, 171); + RefreshButton.Location = new Point(1025, 171); RefreshButton.Name = "RefreshButton"; RefreshButton.Size = new Size(259, 29); RefreshButton.TabIndex = 6; @@ -240,7 +240,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1422, 450); + ClientSize = new Size(1296, 450); Controls.Add(RefreshButton); Controls.Add(IssuedButton); Controls.Add(ReadyButton); @@ -261,20 +261,28 @@ #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem ToolStripMenu; - private ToolStripMenuItem КомпонентыStripMenuItem; - private ToolStripMenuItem ЦветыStripMenuItem; - private DataGridView DataGridView; - private Button CreateOrderButton; - private Button TakeInWorkButton; - private Button ReadyButton; - private Button IssuedButton; - private Button RefreshButton; - private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem списокКомпонентовToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem списокЗаказовToolStripMenuItem; - private ToolStripMenuItem клиентыToolStripMenuItem; - } + private MenuStrip menuStrip1; + private ToolStripMenuItem ToolStripMenu; + private ToolStripMenuItem КомпонентыStripMenuItem; + private ToolStripMenuItem ЦветыStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button TakeInWorkButton; + private Button ReadyButton; + private Button IssuedButton; + private Button RefreshButton; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem продажиToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem списокКомпонентовToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem цветыПоМагазинамToolStripMenuItem; + private ToolStripMenuItem заказыПоДатамToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem начатьРаботуToolStripMenuItem; + } } \ No newline at end of file diff --git a/ProjectFlowerShop/MainForm.cs b/ProjectFlowerShop/MainForm.cs index 74e86fe..1b6cdd3 100644 --- a/ProjectFlowerShop/MainForm.cs +++ b/ProjectFlowerShop/MainForm.cs @@ -23,6 +23,7 @@ namespace ProjectFlowerShop private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; private readonly IWorkProcess _workProcess; + public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); @@ -32,20 +33,18 @@ namespace ProjectFlowerShop _workProcess = workProcess; } - private void КомпонентыStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - - } - - private void MainForm_Load(object sender, EventArgs e) - { - LoadData(); - } + private void КомпонентыStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void MainForm_Load(object sender, EventArgs e) + { + LoadData(); + } private void LoadData() { @@ -58,7 +57,6 @@ namespace ProjectFlowerShop DataGridView.DataSource = list; DataGridView.Columns["FlowerId"].Visible = false; DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["ImplementerId"].Visible = false; DataGridView.Columns["FlowerName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); @@ -188,46 +186,46 @@ namespace ProjectFlowerShop LoadData(); } - private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); - if (service is ShopsForm form) - { - form.ShowDialog(); - } - } + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); + if (service is ShopsForm form) + { + form.ShowDialog(); + } + } - private void поставкиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(SupplyForm)); - if (service is SupplyForm form) - { - form.ShowDialog(); - } - } + private void поставкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(SupplyForm)); + if (service is SupplyForm form) + { + form.ShowDialog(); + } + } - private void продажиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(SellForm)); - if (service is SellForm form) - { - form.ShowDialog(); - } - } + private void продажиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(SellForm)); + if (service is SellForm form) + { + form.ShowDialog(); + } + } - private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveComponentsToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); - } - } + private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { @@ -248,13 +246,61 @@ namespace ProjectFlowerShop } } - private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } - } + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + + private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + + private void цветыПоМагазинамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopsFlowers)); + if (service is FormReportShopsFlowers form) + { + form.ShowDialog(); + } + } + + private void заказыПоДатамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders)); + if (service is FormReportDateOrders form) + { + form.ShowDialog(); + } + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm)); + if (service is ImplementersForm form) + { + form.ShowDialog(); + } + } + + private void начатьРаботуToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } } diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index 298c38a..2af9ef5 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -51,7 +51,6 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -70,7 +69,6 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();