From 946c7cf0480cd7b27dc489a771916c9c9de64397 Mon Sep 17 00:00:00 2001 From: malimova Date: Mon, 3 Jun 2024 23:32:39 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ImplementerLogic.cs | 5 + .../ConfectioneryBusinessLogic/OrderLogic.cs | 239 +++++++++------- .../BindingModels/ImplementerBindingModel.cs | 2 +- .../BindingModels/OrderBindingModel.cs | 23 +- .../IImplementerLogic.cs | 2 + .../StoragesContracts/IImplementerStorage.cs | 1 + .../ViewModels/ImplementerViewModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 45 +-- .../ConfectioneryDataModels/IOrderModel.cs | 21 +- .../ConfectioneryDatabase.cs | 2 +- .../Implementer.cs | 14 +- .../ImplementerStorage.cs | 2 +- .../20240603191022_Implementers.Designer.cs | 257 +++++++++++++++++ .../Migrations/20240603191022_Implementers.cs | 108 ++++++++ .../ConfectioneryDatabaseModelSnapshot.cs | 53 +++- .../ConfectioneryDatabaseImplement/Order.cs | 122 ++++---- .../OrderStorage.cs | 139 +++++----- .../ImplementerStorage.cs | 78 +++--- .../ConfectioneryFileImplement/Order.cs | 155 ++++++----- .../OrderStorage.cs | 193 +++++++------ .../DataListSingleton.cs | 48 ++-- .../ImplementerStorage.cs | 3 +- .../ConfectioneryListImplement/Order.cs | 99 +++---- .../OrderStorage.cs | 260 +++++++++++------- Confectionery/ConfectioneryRestApi/Program.cs | 2 + .../FormImplementers.Designer.cs | 113 ++++++++ .../ConfectioneryView/FormImplementers.cs | 118 ++++++++ .../ConfectioneryView/FormImplementers.resx | 120 ++++++++ .../ConfectioneryView/FormMain.Designer.cs | 23 +- Confectionery/ConfectioneryView/FormMain.cs | 10 + Confectionery/ConfectioneryView/Program.cs | 92 ++++--- 31 files changed, 1648 insertions(+), 703 deletions(-) create mode 100644 Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.Designer.cs create mode 100644 Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.cs create mode 100644 Confectionery/ConfectioneryView/FormImplementers.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormImplementers.cs create mode 100644 Confectionery/ConfectioneryView/FormImplementers.resx diff --git a/Confectionery/ConfectioneryBusinessLogic/ImplementerLogic.cs b/Confectionery/ConfectioneryBusinessLogic/ImplementerLogic.cs index e4daea6..2670a0d 100644 --- a/Confectionery/ConfectioneryBusinessLogic/ImplementerLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/ImplementerLogic.cs @@ -1,4 +1,9 @@ using Microsoft.Extensions.Logging; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs index 4146e4e..65049ef 100644 --- a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs +++ b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs @@ -13,113 +13,144 @@ using System.Threading.Tasks; namespace ConfectioneryBusinessLogic { - public class OrderLogic : IOrderLogic - { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) - return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + static readonly object _locker = new object(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - public bool TakeOrderInWork(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выполняется); - } + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (_locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + } - public bool FinishOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Готов); - } + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); - } + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Count <= 0) - { - throw new ArgumentException("Колличество кондитерских изделий в заказе не может быть меньше 1", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); - } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) - { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); - } - _logger.LogInformation("Pastry. PastryId:{PastryId}.Count:{Count}.Sum:{Sum}Id:{Id}", - model.PastryId, model.Count, model.Sum, model.Id); - } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentException("Колличество суши в заказе не может быть меньше 1", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Sushi. SushiId:{SushiId}.Count:{Count}.Sum:{Sum}Id:{Id}", + model.PastryId, model.Count, model.Sum, model.Id); + } - private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() - { - Id = model.Id - }); - if (element == null) - { - throw new ArgumentNullException(nameof(element)); - } - model.DateCreate = element.DateCreate; - model.PastryId = element.PastryId; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - if (requiredStatus - model.Status == 1) - { - model.Status = requiredStatus; - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); - throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); - } - } + private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new InvalidOperationException(nameof(element)); + } + model.DateCreate = element.DateCreate; + model.PastryId = element.PastryId; + model.DateImplement = element.DateImplement; + model.ClientId = element.ClientId; + if (!model.ImplementerId.HasValue) + { + model.ImplementerId = element.ImplementerId; + } + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (requiredStatus - model.Status == 1) + { + model.Status = requiredStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); + throw new InvalidOperationException($"Невозможно приствоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); + + } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + } } diff --git a/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs index 497558f..cb176e6 100644 --- a/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs +++ b/Confectionery/ConfectioneryContracts/BindingModels/ImplementerBindingModel.cs @@ -1,4 +1,4 @@ -using ConfectioneryDataModels; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.Linq; diff --git a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs index d51f207..d5d6fcf 100644 --- a/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs +++ b/Confectionery/ConfectioneryContracts/BindingModels/OrderBindingModel.cs @@ -8,15 +8,16 @@ using System.Threading.Tasks; namespace ConfectioneryContracts.BindingModels { - public class OrderBindingModel : IOrderModel - { - public int Id { get; set; } - public int PastryId { get; set; } - public int ClientId { get; set; } - public int Count { get; set; } - public double Sum { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; set; } = DateTime.Now; - public DateTime? DateImplement { get; set; } - } + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int PastryId { get; set; } + public int ClientId { get; set; } + public int? ImplementerId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } } diff --git a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs index b06b6dc..a868533 100644 --- a/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs +++ b/Confectionery/ConfectioneryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -1,4 +1,6 @@ using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs b/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs index e9b3c81..967d0d6 100644 --- a/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs +++ b/Confectionery/ConfectioneryContracts/StoragesContracts/IImplementerStorage.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs index 559f526..7427339 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/ImplementerViewModel.cs @@ -1,4 +1,4 @@ -using ConfectioneryDataModels; +using ConfectioneryDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel; diff --git a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs index f09bcf1..ebdcf7d 100644 --- a/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs +++ b/Confectionery/ConfectioneryContracts/ViewModels/OrderViewModel.cs @@ -9,26 +9,29 @@ using System.Threading.Tasks; namespace ConfectioneryContracts.ViewModels { - public class OrderViewModel : IOrderModel - { - [DisplayName("Номер")] - public int Id { get; set; } - public int ClientId { get; set; } + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int ClientId { get; set; } - [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; } = string.Empty; - public int PastryId { get; set; } - [DisplayName("Изделие")] - public string PastryName { get; set; } = string.Empty; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Сумма")] - public double Sum { get; set; } - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] - public DateTime? DateImplement { get; set; } - } + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string? ImplementerFIO { get; set; } = null; + public int PastryId { get; set; } + [DisplayName("Изделие")] + public string PastryName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } } diff --git a/Confectionery/ConfectioneryDataModels/IOrderModel.cs b/Confectionery/ConfectioneryDataModels/IOrderModel.cs index 97508bb..a2170fb 100644 --- a/Confectionery/ConfectioneryDataModels/IOrderModel.cs +++ b/Confectionery/ConfectioneryDataModels/IOrderModel.cs @@ -7,14 +7,15 @@ using System.Threading.Tasks; namespace ConfectioneryDataModels.Models { - public interface IOrderModel : IId - { - int PastryId { get; } - int ClientId { get; } - int Count { get; } - double Sum { get; } - OrderStatus Status { get; } - DateTime DateCreate { get; } - DateTime? DateImplement { get; } - } + public interface IOrderModel : IId + { + int PastryId { get; } + int ClientId { get; } + int? ImplementerId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } } diff --git a/Confectionery/ConfectioneryDatabaseImplement/ConfectioneryDatabase.cs b/Confectionery/ConfectioneryDatabaseImplement/ConfectioneryDatabase.cs index 5746540..80437d2 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/ConfectioneryDatabase.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/ConfectioneryDatabase.cs @@ -15,7 +15,7 @@ namespace ConfectioneryDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=ConfectioneryDatabaseNew;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=ConfectioneryDatabase11;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs b/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs index 438be9f..7282a3e 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Implementer.cs @@ -1,15 +1,15 @@ -using ConfectioneryContracts.BindingModels; -using ConfectioneryContracts.ViewModels; -using ConfectioneryDataModels.Models; -using System; +using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; -namespace ConfectioneryDatabaseImplement +namespace ConfectioneryDatabaseImplement.Models { public class Implementer : IImplementerModel { diff --git a/Confectionery/ConfectioneryDatabaseImplement/ImplementerStorage.cs b/Confectionery/ConfectioneryDatabaseImplement/ImplementerStorage.cs index 08bbe59..07aee90 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/ImplementerStorage.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/ImplementerStorage.cs @@ -9,7 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryDatabaseImplement +namespace ConfectioneryDatabaseImplement.Implements { public class ImplementerStorage : IImplementerStorage { diff --git a/Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.Designer.cs b/Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.Designer.cs new file mode 100644 index 0000000..84fa486 --- /dev/null +++ b/Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using ConfectioneryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ConfectioneryDatabaseImplement.Migrations +{ + [DbContext(typeof(ConfectioneryDatabase))] + [Migration("20240603191022_Implementers")] + partial class Implementers + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + 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("ConfectioneryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + 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("ConfectioneryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PastryId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PastryName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Pastrys"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PastryId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PastryId"); + + b.ToTable("PastryComponents"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => + { + b.HasOne("ConfectioneryDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + + b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") + .WithMany("Orders") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Pastry"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.PastryComponent", b => + { + b.HasOne("ConfectioneryDatabaseImplement.Models.Component", "Component") + .WithMany("PastryComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") + .WithMany("Components") + .HasForeignKey("PastryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Pastry"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Component", b => + { + b.Navigation("PastryComponents"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.cs b/Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.cs new file mode 100644 index 0000000..f07b52d --- /dev/null +++ b/Confectionery/ConfectioneryDatabaseImplement/Migrations/20240603191022_Implementers.cs @@ -0,0 +1,108 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ConfectioneryDatabaseImplement.Migrations +{ + /// + public partial class Implementers : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + 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), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + } +} diff --git a/Confectionery/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs b/Confectionery/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs index 912d903..605726a 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Migrations/ConfectioneryDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace ConfectioneryDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + 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("ConfectioneryDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -75,7 +102,7 @@ namespace ConfectioneryDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -87,6 +114,9 @@ namespace ConfectioneryDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PastryId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace ConfectioneryDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PastryId"); b.ToTable("Orders"); @@ -153,9 +185,15 @@ namespace ConfectioneryDatabaseImplement.Migrations modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Order", b => { - b.HasOne("ConfectioneryDatabaseImplement.Models.Client", null) + b.HasOne("ConfectioneryDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ConfectioneryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); b.HasOne("ConfectioneryDatabaseImplement.Models.Pastry", "Pastry") .WithMany("Orders") @@ -163,6 +201,10 @@ namespace ConfectioneryDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + + b.Navigation("Implementer"); + b.Navigation("Pastry"); }); @@ -195,6 +237,11 @@ namespace ConfectioneryDatabaseImplement.Migrations b.Navigation("PastryComponents"); }); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("ConfectioneryDatabaseImplement.Models.Pastry", b => { b.Navigation("Components"); diff --git a/Confectionery/ConfectioneryDatabaseImplement/Order.cs b/Confectionery/ConfectioneryDatabaseImplement/Order.cs index d5f3e6c..50544dd 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/Order.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/Order.cs @@ -11,72 +11,80 @@ using System.Threading.Tasks; namespace ConfectioneryDatabaseImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - [Required] - public int ClientId { get; private set; } + public class Order : IOrderModel + { + public int Id { get; private set; } + [Required] + public int ClientId { get; private set; } - public virtual Client Client { get; private set; } = new(); + public virtual Client Client { get; private set; } = new(); - [Required] - public int PastryId { get; private set; } + [Required] + public int PastryId { get; private set; } - public virtual Pastry Pastry { get; set; } = new(); + public virtual Pastry Pastry { get; set; } = new(); + public int? ImplementerId { get; private set; } + public virtual Implementer? Implementer { get; set; } = new(); - [Required] - public int Count { get; private set; } + [Required] + public int Count { get; private set; } - [Required] - public double Sum { get; private set; } + [Required] + public double Sum { get; private set; } - [Required] - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + public DateTime? DateImplement { get; private set; } - public static Order Create(ConfectioneryDatabase context, OrderBindingModel model) - { - return new Order() - { - Id = model.Id, - ClientId = model.ClientId, - Client = context.Clients.First(x => x.Id == model.ClientId), - PastryId = model.PastryId, - Pastry = context.Pastrys.First(x => x.Id == model.PastryId), - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } + public static Order Create(ConfectioneryDatabase context, OrderBindingModel model) + { + return new Order() + { + Id = model.Id, + ClientId = model.ClientId, + Client = context.Clients.First(x => x.Id == model.ClientId), + PastryId = model.PastryId, + Pastry = context.Pastrys.First(x => x.Id == model.PastryId), + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - DateImplement = model.DateImplement; - } + public void Update(ConfectioneryDatabase context, OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; + } - public OrderViewModel GetViewModel => new() - { - Id = Id, - ClientId = ClientId, - ClientFIO = Client.ClientFIO, - PastryId = PastryId, - PastryName = Pastry.PastryName, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; - } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ClientId = ClientId, + ClientFIO = Client.ClientFIO, + PastryId = PastryId, + PastryName = Pastry.PastryName, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : null, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } } diff --git a/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs b/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs index 2372bb9..8fdaf2f 100644 --- a/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs +++ b/Confectionery/ConfectioneryDatabaseImplement/OrderStorage.cs @@ -12,77 +12,80 @@ using Microsoft.EntityFrameworkCore; namespace ConfectioneryDatabaseImplement.Implements { - public class OrderStorage : IOrderStorage - { - public List GetFullList() - { - using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); - } + public class OrderStorage : IOrderStorage + { + public List GetFullList() + { + using var context = new ConfectioneryDatabase(); + return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Include(y => y.Implementer).Select(x => x.GetViewModel).ToList(); + } - public List GetFilteredList(OrderSearchModel model) - { - using var context = new ConfectioneryDatabase(); - if (model.DateFrom.HasValue) - { - return context.Orders.Include(x => x.Pastry).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); - } - if (model.ClientId.HasValue) - { - return context.Orders.Include(x => x.Pastry).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); - } - return context.Orders.Include(x => x.Pastry).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); - } + public List GetFilteredList(OrderSearchModel model) + { + using var context = new ConfectioneryDatabase(); + if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue && !model.Status.HasValue) + { + return new(); + } + return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Include(x => x.Implementer).Where(x => + (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) || + (model.ClientId.HasValue && x.ClientId == model.ClientId) || + (model.Status.HasValue && x.Status == model.Status)) + .Select(x => x.GetViewModel).ToList(); + } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - using var context = new ConfectioneryDatabase(); - return context.Orders.Include(x => x.Pastry).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; - } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) + { + return new(); + } + using var context = new ConfectioneryDatabase(); + return context.Orders.Include(x => x.Pastry).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && x.Status == model.Status)) + ?.GetViewModel; + } - public OrderViewModel? Insert(OrderBindingModel model) - { - using var context = new ConfectioneryDatabase(); - if (model == null) - return null; - var newOrder = Order.Create(context, model); - if (newOrder == null) - { - return null; - } - context.Orders.Add(newOrder); - context.SaveChanges(); - return newOrder.GetViewModel; - } + public OrderViewModel? Insert(OrderBindingModel model) + { + using var context = new ConfectioneryDatabase(); + if (model == null) + return null; + var newOrder = Order.Create(context, model); + if (newOrder == null) + { + return null; + } + context.Orders.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; + } - public OrderViewModel? Update(OrderBindingModel model) - { - using var context = new ConfectioneryDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - return order.GetViewModel; - } + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new ConfectioneryDatabase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(context, model); + context.SaveChanges(); + return order.GetViewModel; + } - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new ConfectioneryDatabase(); - var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); - if (order != null) - { - context.Orders.Remove(order); - context.SaveChanges(); - return order.GetViewModel; - } - return null; - } - } + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new ConfectioneryDatabase(); + var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + if (order != null) + { + context.Orders.Remove(order); + context.SaveChanges(); + return order.GetViewModel; + } + return null; + } + } } diff --git a/Confectionery/ConfectioneryFileImplement/ImplementerStorage.cs b/Confectionery/ConfectioneryFileImplement/ImplementerStorage.cs index fdf3b61..413ba55 100644 --- a/Confectionery/ConfectioneryFileImplement/ImplementerStorage.cs +++ b/Confectionery/ConfectioneryFileImplement/ImplementerStorage.cs @@ -13,87 +13,81 @@ namespace ConfectioneryFileImplement.Implements { public class ImplementerStorage : IImplementerStorage { - private readonly DataFileSingleton _source; + private readonly DataFileSingleton source; + public ImplementerStorage() { - _source = DataFileSingleton.GetInstance(); + source = DataFileSingleton.GetInstance(); } public List GetFullList() { - return _source.Implementers.Select(x => x.GetViewModel).ToList(); + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(ImplementerSearchModel model) { - if (model == null) + if (string.IsNullOrEmpty(model.ImplementerFIO)) { return new(); } - if (model.Id.HasValue) - { - var res = GetElement(model); - return res != null ? new() { res } : new(); - } - if (model.ImplementerFIO != null) - { - return _source.Implementers - .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) .Select(x => x.GetViewModel) .ToList(); - } - return new(); } public ImplementerViewModel? GetElement(ImplementerSearchModel model) { - if (model.Id.HasValue) + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) { - return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return null; } - if (model.ImplementerFIO != null && model.Password != null) - { - return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; - } - if (model.ImplementerFIO != null) - { - return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; - } - return null; + return source.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public ImplementerViewModel? Insert(ImplementerBindingModel model) { - model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; - var res = Implementer.Create(model); - if (res != null) + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) { - _source.Implementers.Add(res); - _source.SaveImplementers(); + return null; } - return res?.GetViewModel; + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; } public ImplementerViewModel? Update(ImplementerBindingModel model) { - var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); - if (res != null) + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) { - res.Update(model); - _source.SaveImplementers(); + return null; } - return res?.GetViewModel; + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; } public ImplementerViewModel? Delete(ImplementerBindingModel model) { - var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); - if (res != null) + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) { - _source.Implementers.Remove(res); - _source.SaveImplementers(); + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; } - return res?.GetViewModel; + return null; } } } diff --git a/Confectionery/ConfectioneryFileImplement/Order.cs b/Confectionery/ConfectioneryFileImplement/Order.cs index 37c036e..e7e242f 100644 --- a/Confectionery/ConfectioneryFileImplement/Order.cs +++ b/Confectionery/ConfectioneryFileImplement/Order.cs @@ -6,82 +6,91 @@ using System.Xml.Linq; namespace ConfectioneryFileImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - public int ClientId { get; private set; } - public int PastryId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ClientId { get; private set; } + public int? ImplementerId { get; set; } + public int PastryId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - PastryId = model.PastryId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PastryId = model.PastryId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } - public static Order? Create(XElement element) - { - if (element == null) - { - return null; - } - string dateImplement = element.Element("DateImplement")!.Value; - return new Order() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - PastryId = Convert.ToInt32(element.Element("PastryId")!.Value), - Count = Convert.ToInt32(element.Element("Count")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), - Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), - DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) - }; - } + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + string dateImplement = element.Element("DateImplement")!.Value; + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PastryId = Convert.ToInt32(element.Element("PastryId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) + }; + } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; - } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } - public OrderViewModel GetViewModel => new() - { - Id = Id, - PastryId = PastryId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; + public OrderViewModel GetViewModel => new() + { + Id = Id, + PastryId = PastryId, + ClientId = ClientId, + ImplementerId = ImplementerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; - public XElement GetXElement => new("Order", - new XAttribute("Id", Id), - new XElement("PastryId", PastryId.ToString()), - new XElement("Count", Count.ToString()), - new XElement("Sum", Sum.ToString()), - new XElement("Status", Status.ToString()), - new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString())); - } + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("PastryId", PastryId.ToString()), + new XElement("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } } diff --git a/Confectionery/ConfectioneryFileImplement/OrderStorage.cs b/Confectionery/ConfectioneryFileImplement/OrderStorage.cs index 0ca29d8..ea65eb1 100644 --- a/Confectionery/ConfectioneryFileImplement/OrderStorage.cs +++ b/Confectionery/ConfectioneryFileImplement/OrderStorage.cs @@ -1,94 +1,129 @@ -using ConfectioneryContracts.BindingModels; -using ConfectioneryContracts.SearchModels; -using ConfectioneryContracts.StoragesContracts; -using ConfectioneryContracts.ViewModels; -using ConfectioneryFileImplement.Models; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContracts; +using ConfectioneryContracts.ViewModels; +using ConfectioneryFileImplement.Models; namespace ConfectioneryFileImplement.Implements { - public class OrderStorage : IOrderStorage - { - private readonly DataFileSingleton source; + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; - public OrderStorage() - { - source = DataFileSingleton.GetInstance(); - } + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } - public List GetFullList() => source.Orders.Select(x => AttachPastryName(x.GetViewModel)).ToList(); + public List GetFullList() + { + return source.Orders + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachPastryName(x.GetViewModel)).ToList(); - } + public List GetFilteredList(OrderSearchModel model) + { + if (model.Id.HasValue) + { + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + return source.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + else if (model.ClientId.HasValue) + { + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + else if (model.Status != null) + { + return source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + return new(); + } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return new(); - } - return AttachPastryName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); - } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue && !model.ImplementerId.HasValue) + { + return null; + } + var order = source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? AddInfo(order.GetViewModel) : null; + } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - source.Orders.Add(newOrder); - source.SaveOrders(); - return AttachPastryName(newOrder.GetViewModel); - } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return AddInfo(newOrder.GetViewModel); + } - public OrderViewModel? Update(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - source.SaveOrders(); - return AttachPastryName(order.GetViewModel); - } + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return AddInfo(order.GetViewModel); + } - public OrderViewModel? Delete(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order != null) - { - source.Orders.Remove(order); - source.SaveOrders(); - return AttachPastryName(order.GetViewModel); - } - return null; - } + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return AddInfo(element.GetViewModel); + } + return null; + } - private OrderViewModel? AttachPastryName(OrderViewModel? model) - { - if (model == null) - { - return null; - } - var pastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId); - if (pastry != null) - { - model.PastryName = pastry.PastryName; - } - return model; - } - } -} + private OrderViewModel AddInfo(OrderViewModel model) + { + var selectedPastry = source.Pastrys.FirstOrDefault(x => x.Id == model.PastryId); + model.PastryName = selectedPastry?.PastryName ?? string.Empty; + var selectedClient = source.Clients.FirstOrDefault(x => x.Id == model.ClientId); + model.ClientFIO = selectedClient?.ClientFIO ?? string.Empty; + return model; + } + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs index 4229679..daa9f84 100644 --- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs +++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs @@ -7,27 +7,29 @@ using ConfectioneryListImplement.Models; namespace ConfectioneryListImplement { - public class DataListSingleton - { - private static DataListSingleton? _instance; - public List Components { get; set; } - public List Orders { get; set; } - public List Pastrys { get; set; } - public List Clients { get; set; } - private DataListSingleton() - { - Components = new List(); - Orders = new List(); - Pastrys = new List(); - Clients = new List(); - } - public static DataListSingleton GetInstance() - { - if (_instance == null) - { - _instance = new DataListSingleton(); - } - return _instance; - } - } + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Pastrys { get; set; } + public List Clients { get; set; } + public List Implementers { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Pastrys = new List(); + Clients = new List(); + Implementers = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } } diff --git a/Confectionery/ConfectioneryListImplement/ImplementerStorage.cs b/Confectionery/ConfectioneryListImplement/ImplementerStorage.cs index f7afdea..f4896e5 100644 --- a/Confectionery/ConfectioneryListImplement/ImplementerStorage.cs +++ b/Confectionery/ConfectioneryListImplement/ImplementerStorage.cs @@ -2,6 +2,7 @@ using ConfectioneryContracts.SearchModels; using ConfectioneryContracts.StoragesContracts; using ConfectioneryContracts.ViewModels; +using ConfectioneryListImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -119,4 +120,4 @@ namespace ConfectioneryListImplement.Implements return null; } } -} \ No newline at end of file +} diff --git a/Confectionery/ConfectioneryListImplement/Order.cs b/Confectionery/ConfectioneryListImplement/Order.cs index 0fe5af5..8e4a4f9 100644 --- a/Confectionery/ConfectioneryListImplement/Order.cs +++ b/Confectionery/ConfectioneryListImplement/Order.cs @@ -10,54 +10,59 @@ using System.Threading.Tasks; namespace ConfectioneryListImplement.Models { - public class Order : IOrderModel - { - public int Id { get; private set; } - public int PastryId { get; private set; } - public int ClientId { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } + public class Order : IOrderModel + { + public int Id { get; private set; } + public int PastryId { get; private set; } + public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - PastryId = model.PastryId, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - }; - } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PastryId = model.PastryId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - Status = model.Status; - if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; - } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + } - public OrderViewModel GetViewModel => new() - { - Id = Id, - PastryId = PastryId, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - }; - } + public OrderViewModel GetViewModel => new() + { + Id = Id, + PastryId = PastryId, + ClientId = ClientId, + ImplementerId = ImplementerId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } } diff --git a/Confectionery/ConfectioneryListImplement/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/OrderStorage.cs index 0cc40fd..220c201 100644 --- a/Confectionery/ConfectioneryListImplement/OrderStorage.cs +++ b/Confectionery/ConfectioneryListImplement/OrderStorage.cs @@ -9,117 +9,169 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ConfectioneryListImplement +namespace ConfectioneryListImplement.Implements { - public class OrderStorage : IOrderStorage - { - private readonly DataListSingleton _source; + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; - public OrderStorage() - { - _source = DataListSingleton.GetInstance(); - } + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } - public List GetFullList() - { - var result = new List(); - foreach (var order in _source.Orders) - { - result.Add(AttachPastryName(order.GetViewModel)); - } - return result; - } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AddInfo(order.GetViewModel)); + } + return result; + } - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - if (model == null || !model.Id.HasValue) - { - return result; - } - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - result.Add(AttachPastryName(order.GetViewModel)); - } - } - return result; - } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + else if (model.ClientId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + return result; + } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - foreach (var order in _source.Orders) - { - if (model.Id.HasValue && order.Id == model.Id) - { - return AttachPastryName(order.GetViewModel); - } - } - return null; - } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue && !model.ImplementerId.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + return AddInfo(order.GetViewModel); + } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return AddInfo(order.GetViewModel); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return AddInfo(order.GetViewModel); + } + } + return null; + } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - foreach (var order in _source.Orders) - { - if (model.Id <= order.Id) - { - model.Id = order.Id + 1; - } - } - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - _source.Orders.Add(newOrder); - return AttachPastryName(newOrder.GetViewModel); - } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AddInfo(newOrder.GetViewModel); + } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.Update(model); - return AttachPastryName(order.GetViewModel); - } - } - return null; - } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AddInfo(order.GetViewModel); + } + } + return null; + } - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; ++i) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - return AttachPastryName(element.GetViewModel); - } - } - return null; - } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AddInfo(element.GetViewModel); + } + } + return null; + } - private OrderViewModel AttachPastryName(OrderViewModel model) - { - foreach (var Pastry in _source.Pastrys) - { - if (Pastry.Id == model.PastryId) - { - model.PastryName = Pastry.PastryName; - return model; - } - } - return model; - } - } + private OrderViewModel AddInfo(OrderViewModel model) + { + var selectedPastry = _source.Pastrys.Find(pastry => pastry.Id == model.PastryId); + if (selectedPastry != null) + { + model.PastryName = selectedPastry.PastryName; + } + foreach (var client in _source.Clients) + { + if (client.Id == model.ClientId) + { + model.ClientFIO = client.ClientFIO; + break; + } + } + return model; + } + } } diff --git a/Confectionery/ConfectioneryRestApi/Program.cs b/Confectionery/ConfectioneryRestApi/Program.cs index 8e21fc4..d785dee 100644 --- a/Confectionery/ConfectioneryRestApi/Program.cs +++ b/Confectionery/ConfectioneryRestApi/Program.cs @@ -15,6 +15,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at diff --git a/Confectionery/ConfectioneryView/FormImplementers.Designer.cs b/Confectionery/ConfectioneryView/FormImplementers.Designer.cs new file mode 100644 index 0000000..05ed065 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementers.Designer.cs @@ -0,0 +1,113 @@ +namespace ConfectioneryView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.Size = new Size(768, 492); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(849, 59); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(112, 34); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(849, 137); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(112, 34); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(849, 218); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(112, 34); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(849, 296); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(112, 34); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1028, 516); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormImplementers"; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormImplementers.cs b/Confectionery/ConfectioneryView/FormImplementers.cs new file mode 100644 index 0000000..be8dafb --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementers.cs @@ -0,0 +1,118 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConfectioneryView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + + public FormImplementers(ILogger logger, IImplementerLogic implementerLogic) + { + InitializeComponent(); + _logger = logger; + _logic = implementerLogic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormImplementers.resx b/Confectionery/ConfectioneryView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs index b781ed0..d049394 100644 --- a/Confectionery/ConfectioneryView/FormMain.Designer.cs +++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs @@ -38,12 +38,13 @@ pastrysListToolStripMenuItem = new ToolStripMenuItem(); componentPastryToolStripMenuItem = new ToolStripMenuItem(); ordersListToolStripMenuItem = new ToolStripMenuItem(); + startWorkToolStripMenuItem = new ToolStripMenuItem(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - startWorkToolStripMenuItem = new ToolStripMenuItem(); + implementersToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -70,7 +71,7 @@ // // toolStripMenuItem // - toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastryToolStripMenuItem, clientsToolStripMenuItem }); + toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, pastryToolStripMenuItem, clientsToolStripMenuItem, implementersToolStripMenuItem }); toolStripMenuItem.Name = "toolStripMenuItem"; toolStripMenuItem.Size = new Size(139, 29); toolStripMenuItem.Text = "Справочники"; @@ -124,6 +125,13 @@ ordersListToolStripMenuItem.Text = "Список заказов"; ordersListToolStripMenuItem.Click += ordersListToolStripMenuItem_Click; // + // startWorkToolStripMenuItem + // + startWorkToolStripMenuItem.Name = "startWorkToolStripMenuItem"; + startWorkToolStripMenuItem.Size = new Size(136, 29); + startWorkToolStripMenuItem.Text = "Запуск работ"; + startWorkToolStripMenuItem.Click += startWorkToolStripMenuItem_Click; + // // buttonCreateOrder // buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -179,12 +187,12 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // - // startWorkToolStripMenuItem + // implementersToolStripMenuItem // - startWorkToolStripMenuItem.Name = "startWorkToolStripMenuItem"; - startWorkToolStripMenuItem.Size = new Size(136, 29); - startWorkToolStripMenuItem.Text = "Запуск работ"; - startWorkToolStripMenuItem.Click += startWorkToolStripMenuItem_Click; + implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + implementersToolStripMenuItem.Size = new Size(298, 34); + implementersToolStripMenuItem.Text = "Исполнители"; + implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click_1; // // FormMain // @@ -227,5 +235,6 @@ private ToolStripMenuItem ordersListToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; private ToolStripMenuItem startWorkToolStripMenuItem; + private ToolStripMenuItem implementersToolStripMenuItem; } } \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs index f1b3cc3..37bc800 100644 --- a/Confectionery/ConfectioneryView/FormMain.cs +++ b/Confectionery/ConfectioneryView/FormMain.cs @@ -43,6 +43,7 @@ namespace ConfectioneryView dataGridView.DataSource = list; dataGridView.Columns["PastryId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } @@ -211,5 +212,14 @@ namespace ConfectioneryView _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } + + private void implementersToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs index 84c333b..ac928bb 100644 --- a/Confectionery/ConfectioneryView/Program.cs +++ b/Confectionery/ConfectioneryView/Program.cs @@ -7,55 +7,63 @@ using ConfectioneryDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using ConfectioneryBusinessLogic.BusinessLogics; +using Microsoft.EntityFrameworkCore.Design; namespace ConfectioneryView { - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - services.AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddNLog("nlog.config"); - }); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } - } + } } \ No newline at end of file