From 7b6b82d2f9aaf4619fa04f005dd28f489176676f Mon Sep 17 00:00:00 2001 From: Extrimal <extrimedved@bk.ru> Date: Fri, 3 May 2024 14:58:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=85=D0=B8=D0=BC=D0=B8=D1=87=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ImplementerLogic.cs | 129 +++++++++++++ .../BusinessLogics/OrderLogic.cs | 27 ++- .../BusinessLogics/WorkModeling.cs | 139 ++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 22 +++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 24 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 13 ++ .../SearchModels/ImplementerSearchModel.cs | 17 ++ .../SearchModels/OrderSearchModel.cs | 6 +- .../StoragesContracts/IImplementerStorage.cs | 26 +++ .../ViewModels/ImplementerViewModel.cs | 27 +++ .../ViewModels/OrderViewModel.cs | 4 + .../Models/IImplementerModel.cs | 19 ++ .../Models/IOrderModel.cs | 1 + .../GarmentFactoryDatabase.cs | 3 +- .../Implements/ImplementerStorage.cs | 91 +++++++++ .../Implements/OrderStorage.cs | 35 +++- .../20240319190105_InitialCreate.Designer.cs | 171 ----------------- .../20240407190354_ClientAddition.cs | 68 ------- ... 20240501154750_InitialCreate.Designer.cs} | 47 ++++- ...ate.cs => 20240501154750_InitialCreate.cs} | 62 ++++++- .../GarmentFactoryDatabaseModelSnapshot.cs | 43 +++++ .../Models/Implementer.cs | 82 +++++++++ .../Models/Order.cs | 11 +- .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 88 +++++++++ .../Implements/OrderStorage.cs | 27 ++- .../Models/Implementer.cs | 86 +++++++++ .../Models/Order.cs | 7 +- .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 114 ++++++++++++ .../Implements/OrderStorage.cs | 30 ++- .../Models/Implementer.cs | 61 ++++++ .../Models/Order.cs | 6 +- .../Controllers/ImplementerController.cs | 104 +++++++++++ .../FormImplementer.Designer.cs | 173 ++++++++++++++++++ .../GarmentFactoryView/FormImplementer.cs | 104 +++++++++++ .../GarmentFactoryView/FormImplementer.resx | 120 ++++++++++++ .../GarmentFactoryView/FormImplementers.cs | 106 +++++++++++ .../FormImplementers.designer.cs | 127 +++++++++++++ .../GarmentFactoryView/FormImplementers.resx | 120 ++++++++++++ .../GarmentFactoryView/FormMain.Designer.cs | 80 ++++---- GarmentFactory/GarmentFactoryView/FormMain.cs | 71 ++----- GarmentFactory/GarmentFactoryView/Program.cs | 5 + 45 files changed, 2146 insertions(+), 358 deletions(-) create mode 100644 GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 GarmentFactory/GarmentFactoryContracts/ViewModels/ImplementerViewModel.cs create mode 100644 GarmentFactory/GarmentFactoryDataModels/Models/IImplementerModel.cs create mode 100644 GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ImplementerStorage.cs delete mode 100644 GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs delete mode 100644 GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs rename GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/{20240407190354_ClientAddition.Designer.cs => 20240501154750_InitialCreate.Designer.cs} (82%) rename GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/{20240319190105_InitialCreate.cs => 20240501154750_InitialCreate.cs} (65%) create mode 100644 GarmentFactory/GarmentFactoryDatabaseImplement/Models/Implementer.cs create mode 100644 GarmentFactory/GarmentFactoryFileImplement/Implements/ImplementerStorage.cs create mode 100644 GarmentFactory/GarmentFactoryFileImplement/Models/Implementer.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Implements/ImplementerStorage.cs create mode 100644 GarmentFactory/GarmentFactoryListImplement/Models/Implementer.cs create mode 100644 GarmentFactory/GarmentFactoryRestApi/Controllers/ImplementerController.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormImplementer.Designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormImplementer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormImplementer.resx create mode 100644 GarmentFactory/GarmentFactoryView/FormImplementers.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormImplementers.designer.cs create mode 100644 GarmentFactory/GarmentFactoryView/FormImplementers.resx diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..d9ddd97 --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,129 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("Стаж работы исполнителя должен быть больше 0", nameof(model.WorkExperience)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация исполнителя должен быть больше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. Id: {Id}. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Qualification: {Qualification}. " + + "WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже существует"); + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs index d85bc13..e652c9f 100644 --- a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -18,6 +18,7 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object locker = new(); public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) { @@ -54,10 +55,28 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } - + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id: {Id}", 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; + } public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) @@ -116,6 +135,10 @@ namespace GarmentFactoryBusinessLogic.BusinessLogics return false; } model.Status = newStatus; + if (order.ImplementerId.HasValue) + { + model.ImplementerId = order.ImplementerId; + } if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; diff --git a/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/WorkModeling.cs b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..30b033c --- /dev/null +++ b/GarmentFactory/GarmentFactoryBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,139 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger<WorkModeling> logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/BindingModels/ImplementerBindingModel.cs b/GarmentFactory/GarmentFactoryContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..0353756 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs b/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs index def73bc..f22e473 100644 --- a/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/GarmentFactory/GarmentFactoryContracts/BindingModels/OrderBindingModel.cs @@ -16,6 +16,7 @@ namespace GarmentFactoryContracts.BindingModels public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } + public int? ImplementerId { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } diff --git a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..c30df2f --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index f735303..ebf58af 100644 --- a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace GarmentFactoryContracts.BusinessLogicsContracts public interface IOrderLogic { List<OrderViewModel>? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..d5497ab --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/SearchModels/ImplementerSearchModel.cs b/GarmentFactory/GarmentFactoryContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..a80d3f8 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs b/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs index 433efdd..7ee3e5c 100644 --- a/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs +++ b/GarmentFactory/GarmentFactoryContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using GarmentFactoryDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,8 +11,9 @@ namespace GarmentFactoryContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } } } diff --git a/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IImplementerStorage.cs b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..876021b --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List<ImplementerViewModel> GetFullList(); + + List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/ViewModels/ImplementerViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..ba8f3d7 --- /dev/null +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs b/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs index 123f9ea..f24c2f9 100644 --- a/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs +++ b/GarmentFactory/GarmentFactoryContracts/ViewModels/OrderViewModel.cs @@ -13,6 +13,10 @@ namespace GarmentFactoryContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int? ImplementerId { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; public int TextileId { get; set; } [DisplayName("Изделие")] public string TextileName { get; set; } = string.Empty; diff --git a/GarmentFactory/GarmentFactoryDataModels/Models/IImplementerModel.cs b/GarmentFactory/GarmentFactoryDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..fe0fbba --- /dev/null +++ b/GarmentFactory/GarmentFactoryDataModels/Models/IImplementerModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} diff --git a/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs b/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs index b3ef9c5..74014fb 100644 --- a/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs +++ b/GarmentFactory/GarmentFactoryDataModels/Models/IOrderModel.cs @@ -13,6 +13,7 @@ namespace GarmentFactoryDataModels.Models int Count { get; } double Sum { get; } int ClientId { get; } + int? ImplementerId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs index 6e95244..56dadb1 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/GarmentFactoryDatabase.cs @@ -14,7 +14,7 @@ namespace GarmentFactoryDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=GarmentFactoryDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=GarmentFactoryDatabaseNew;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -23,5 +23,6 @@ namespace GarmentFactoryDatabaseImplement public virtual DbSet<TextileComponent> TextileComponents { set; get; } public virtual DbSet<Order> Orders { set; get; } public virtual DbSet<Client> Clients { set; get; } + public virtual DbSet<Implementer> Implementers { set; get; } } } diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..d7d83c3 --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,91 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List<ImplementerViewModel> GetFullList() + { + using var context = new GarmentFactoryDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new GarmentFactoryDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new GarmentFactoryDatabase(); + return context.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) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new GarmentFactoryDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new GarmentFactoryDatabase(); + var element = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/OrderStorage.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/OrderStorage.cs index 943de97..a025841 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -15,6 +15,7 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -27,6 +28,7 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -36,6 +38,7 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -45,16 +48,37 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Textile) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return context.Orders + .Include(x => x.Textile) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -62,7 +86,11 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) + .Include(x => x.Implementer) + .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) ?.GetViewModel; } @@ -79,6 +107,7 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -96,6 +125,7 @@ namespace GarmentFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } @@ -109,6 +139,7 @@ namespace GarmentFactoryDatabaseImplement.Implements var deletedElement = context.Orders .Include(x => x.Textile) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; context.Orders.Remove(element); diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs deleted file mode 100644 index 84c4a19..0000000 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.Designer.cs +++ /dev/null @@ -1,171 +0,0 @@ -// <auto-generated /> -using System; -using GarmentFactoryDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace GarmentFactoryDatabaseImplement.Migrations -{ - [DbContext(typeof(GarmentFactoryDatabase))] - [Migration("20240319190105_InitialCreate")] - partial class InitialCreate - { - /// <inheritdoc /> - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => - { - b.Property<int>("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); - - b.Property<string>("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property<double>("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => - { - b.Property<int>("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); - - b.Property<int>("Count") - .HasColumnType("int"); - - b.Property<DateTime>("DateCreate") - .HasColumnType("datetime2"); - - b.Property<DateTime?>("DateImplement") - .HasColumnType("datetime2"); - - b.Property<int>("Status") - .HasColumnType("int"); - - b.Property<double>("Sum") - .HasColumnType("float"); - - b.Property<int>("TextileId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("TextileId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => - { - b.Property<int>("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); - - b.Property<double>("Price") - .HasColumnType("float"); - - b.Property<string>("TextileName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Textiles"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => - { - b.Property<int>("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); - - b.Property<int>("ComponentId") - .HasColumnType("int"); - - b.Property<int>("Count") - .HasColumnType("int"); - - b.Property<int>("TextileId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("TextileId"); - - b.ToTable("TextileComponents"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => - { - b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") - .WithMany("Orders") - .HasForeignKey("TextileId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Textile"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.TextileComponent", b => - { - b.HasOne("GarmentFactoryDatabaseImplement.Models.Component", "Component") - .WithMany("TextileComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") - .WithMany("Components") - .HasForeignKey("TextileId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Textile"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Component", b => - { - b.Navigation("TextileComponents"); - }); - - modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs deleted file mode 100644 index 9931a8a..0000000 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace GarmentFactoryDatabaseImplement.Migrations -{ - /// <inheritdoc /> - public partial class ClientAddition : Migration - { - /// <inheritdoc /> - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn<int>( - name: "ClientId", - table: "Orders", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column<int>(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false), - Email = table.Column<string>(type: "nvarchar(max)", nullable: false), - Password = table.Column<string>(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientId", - table: "Orders", - column: "ClientId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders", - column: "ClientId", - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// <inheritdoc /> - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ClientId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ClientId", - table: "Orders"); - } - } -} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.Designer.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240501154750_InitialCreate.Designer.cs similarity index 82% rename from GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.Designer.cs rename to GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240501154750_InitialCreate.Designer.cs index 817baf3..9ffa2f4 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240407190354_ClientAddition.Designer.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240501154750_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace GarmentFactoryDatabaseImplement.Migrations { [DbContext(typeof(GarmentFactoryDatabase))] - [Migration("20240407190354_ClientAddition")] - partial class ClientAddition + [Migration("20240501154750_InitialCreate")] + partial class InitialCreate { /// <inheritdoc /> protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -70,6 +70,33 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<string>("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<int>("Qualification") + .HasColumnType("int"); + + b.Property<int>("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => { b.Property<int>("Id") @@ -90,6 +117,9 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Property<DateTime?>("DateImplement") .HasColumnType("datetime2"); + b.Property<int?>("ImplementerId") + .HasColumnType("int"); + b.Property<int>("Status") .HasColumnType("int"); @@ -103,6 +133,8 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("TextileId"); b.ToTable("Orders"); @@ -162,6 +194,10 @@ namespace GarmentFactoryDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("GarmentFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") .WithMany("Orders") .HasForeignKey("TextileId") @@ -170,6 +206,8 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Textile"); }); @@ -202,6 +240,11 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240501154750_InitialCreate.cs similarity index 65% rename from GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs rename to GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240501154750_InitialCreate.cs index 251274b..1f2228b 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240319190105_InitialCreate.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/20240501154750_InitialCreate.cs @@ -11,7 +11,21 @@ namespace GarmentFactoryDatabaseImplement.Migrations /// <inheritdoc /> protected override void Up(MigrationBuilder migrationBuilder) { - + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false), + Email = table.Column<string>(type: "nvarchar(max)", nullable: false), + Password = table.Column<string>(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Components", columns: table => new @@ -26,6 +40,22 @@ namespace GarmentFactoryDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column<int>(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false), + Password = table.Column<string>(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column<int>(type: "int", nullable: false), + Qualification = table.Column<int>(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Textiles", columns: table => new @@ -47,6 +77,8 @@ namespace GarmentFactoryDatabaseImplement.Migrations Id = table.Column<int>(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), TextileId = table.Column<int>(type: "int", nullable: false), + ImplementerId = table.Column<int>(type: "int", nullable: true), + ClientId = table.Column<int>(type: "int", nullable: false), Count = table.Column<int>(type: "int", nullable: false), Sum = table.Column<double>(type: "float", nullable: false), Status = table.Column<int>(type: "int", nullable: false), @@ -56,6 +88,17 @@ namespace GarmentFactoryDatabaseImplement.Migrations 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_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Textiles_TextileId", column: x => x.TextileId, @@ -91,6 +134,16 @@ namespace GarmentFactoryDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_TextileId", table: "Orders", @@ -110,13 +163,18 @@ namespace GarmentFactoryDatabaseImplement.Migrations /// <inheritdoc /> protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "TextileComponents"); + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs index 5e471ac..fedfaf9 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Migrations/GarmentFactoryDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property<int>("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); + + b.Property<string>("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<string>("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property<int>("Qualification") + .HasColumnType("int"); + + b.Property<int>("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Order", b => { b.Property<int>("Id") @@ -87,6 +114,9 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Property<DateTime?>("DateImplement") .HasColumnType("datetime2"); + b.Property<int?>("ImplementerId") + .HasColumnType("int"); + b.Property<int>("Status") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("TextileId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace GarmentFactoryDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("GarmentFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("GarmentFactoryDatabaseImplement.Models.Textile", "Textile") .WithMany("Orders") .HasForeignKey("TextileId") @@ -167,6 +203,8 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Textile"); }); @@ -199,6 +237,11 @@ namespace GarmentFactoryDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("GarmentFactoryDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Implementer.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..1cd6e8a --- /dev/null +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,82 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +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; + +namespace GarmentFactoryDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List<Order> Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer Create(ImplementerViewModel model) + { + return new Implementer + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Order.cs b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Order.cs index a81d63a..3a3f8a5 100644 --- a/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Order.cs +++ b/GarmentFactory/GarmentFactoryDatabaseImplement/Models/Order.cs @@ -17,7 +17,7 @@ namespace GarmentFactoryDatabaseImplement.Models [Required] public int TextileId { get; set; } - + public int? ImplementerId { get; private set; } [Required] public int ClientId { get; set; } @@ -38,6 +38,7 @@ namespace GarmentFactoryDatabaseImplement.Models public virtual Textile Textile { get; set; } public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -50,6 +51,7 @@ namespace GarmentFactoryDatabaseImplement.Models Id = model.Id, TextileId = model.TextileId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -66,6 +68,7 @@ namespace GarmentFactoryDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -73,13 +76,15 @@ namespace GarmentFactoryDatabaseImplement.Models Id = Id, TextileId = TextileId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - TextileName = Textile.TextileName, - ClientFIO = Client.ClientFIO + TextileName = Textile.TextileName ?? string.Empty, + ClientFIO = Client.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } diff --git a/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs b/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs index b01f348..02ec3ba 100644 --- a/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs +++ b/GarmentFactory/GarmentFactoryFileImplement/DataFileSingleton.cs @@ -15,10 +15,12 @@ namespace GarmentFactoryFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string TextileFileName = "Textile.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List<Component> Components { get; private set; } public List<Order> Orders { get; private set; } public List<Textile> Textils { get; private set; } public List<Client> Clients { get; private set; } + public List<Implementer> Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -30,6 +32,7 @@ namespace GarmentFactoryFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveTextils() => SaveData(Textils, TextileFileName, "Textils", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); private DataFileSingleton() { @@ -37,6 +40,7 @@ namespace GarmentFactoryFileImplement Textils = LoadData(TextileFileName, "Textile", x => Textile.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction) diff --git a/GarmentFactory/GarmentFactoryFileImplement/Implements/ImplementerStorage.cs b/GarmentFactory/GarmentFactoryFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..59ea6f5 --- /dev/null +++ b/GarmentFactory/GarmentFactoryFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,88 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryFileImplement.Models; + +namespace GarmentFactoryFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List<ImplementerViewModel> GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + 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 newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/GarmentFactory/GarmentFactoryFileImplement/Implements/OrderStorage.cs b/GarmentFactory/GarmentFactoryFileImplement/Implements/OrderStorage.cs index 59bfb9a..aea247f 100644 --- a/GarmentFactory/GarmentFactoryFileImplement/Implements/OrderStorage.cs +++ b/GarmentFactory/GarmentFactoryFileImplement/Implements/OrderStorage.cs @@ -50,20 +50,33 @@ namespace GarmentFactoryFileImplement.Implements .Select(x => AddIntelligence(x.GetViewModel)) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AddIntelligence(x.GetViewModel)) + .ToList(); + } + else if (model.Status != null) + { + return source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => AddIntelligence(x.GetViewModel)) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - return AddIntelligence(order.GetViewModel); + 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 ? AddIntelligence(order.GetViewModel) : null; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/GarmentFactory/GarmentFactoryFileImplement/Models/Implementer.cs b/GarmentFactory/GarmentFactoryFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..907897e --- /dev/null +++ b/GarmentFactory/GarmentFactoryFileImplement/Models/Implementer.cs @@ -0,0 +1,86 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace GarmentFactoryFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification) + ); + } +} diff --git a/GarmentFactory/GarmentFactoryFileImplement/Models/Order.cs b/GarmentFactory/GarmentFactoryFileImplement/Models/Order.cs index 7342288..2ae801d 100644 --- a/GarmentFactory/GarmentFactoryFileImplement/Models/Order.cs +++ b/GarmentFactory/GarmentFactoryFileImplement/Models/Order.cs @@ -17,7 +17,7 @@ namespace GarmentFactoryFileImplement.Models public int TextileId { 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; } @@ -39,6 +39,7 @@ namespace GarmentFactoryFileImplement.Models Id = model.Id, TextileId = model.TextileId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -58,6 +59,7 @@ namespace GarmentFactoryFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), TextileId = Convert.ToInt32(element.Element("TextileId")!.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), @@ -75,6 +77,7 @@ namespace GarmentFactoryFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -82,6 +85,7 @@ namespace GarmentFactoryFileImplement.Models Id = Id, TextileId = TextileId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -93,6 +97,7 @@ namespace GarmentFactoryFileImplement.Models new XAttribute("Id", Id), new XElement("TextileId", TextileId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs b/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs index 0ad6ea9..9a8163f 100644 --- a/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs +++ b/GarmentFactory/GarmentFactoryListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace GarmentFactoryListImplement public List<Order> Orders { get; set; } public List<Textile> Textiles { get; set; } public List<Client> Clients { get; set; } + public List<Implementer> Implementers { get; set; } private DataListSingleton() { Components = new List<Component>(); Orders = new List<Order>(); Textiles = new List<Textile>(); Clients = new List<Client>(); + Implementers = new List<Implementer>(); } public static DataListSingleton GetInstance() { diff --git a/GarmentFactory/GarmentFactoryListImplement/Implements/ImplementerStorage.cs b/GarmentFactory/GarmentFactoryListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..3ead16e --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,114 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.StoragesContracts; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List<ImplementerViewModel> GetFullList() + { + var result = new List<ImplementerViewModel>(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model) + { + var result = new List<ImplementerViewModel>(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + foreach (var implementer in _source.Implementers) + { + if ((!string.IsNullOrEmpty(model.ImplementerFIO) && implementer.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + || (model.Id.HasValue && implementer.Id == model.Id)) + { + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs b/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs index 444493a..27bd1b8 100644 --- a/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs +++ b/GarmentFactory/GarmentFactoryListImplement/Implements/OrderStorage.cs @@ -63,12 +63,32 @@ namespace GarmentFactoryListImplement.Implements } } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(AddIntelligence(order.GetViewModel)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(AddIntelligence(order.GetViewModel)); + } + } + } return result; } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -78,6 +98,14 @@ namespace GarmentFactoryListImplement.Implements { return AddIntelligence(order.GetViewModel); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return AddIntelligence(order.GetViewModel); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return AddIntelligence(order.GetViewModel); + } } return null; } diff --git a/GarmentFactory/GarmentFactoryListImplement/Models/Implementer.cs b/GarmentFactory/GarmentFactoryListImplement/Models/Implementer.cs new file mode 100644 index 0000000..5700437 --- /dev/null +++ b/GarmentFactory/GarmentFactoryListImplement/Models/Implementer.cs @@ -0,0 +1,61 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GarmentFactoryListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs b/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs index 9cc993e..f4eb520 100644 --- a/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs +++ b/GarmentFactory/GarmentFactoryListImplement/Models/Order.cs @@ -21,6 +21,7 @@ namespace GarmentFactoryListImplement.Models public int Count { get; private set; } public double Sum { get; private set; } + public int? ImplementerId { get; private set; } public OrderStatus Status { get; private set; } @@ -43,7 +44,8 @@ namespace GarmentFactoryListImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId, }; } @@ -55,6 +57,7 @@ namespace GarmentFactoryListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -62,6 +65,7 @@ namespace GarmentFactoryListImplement.Models Id = Id, TextileId = TextileId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/GarmentFactory/GarmentFactoryRestApi/Controllers/ImplementerController.cs b/GarmentFactory/GarmentFactoryRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..a673dea --- /dev/null +++ b/GarmentFactory/GarmentFactoryRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,104 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; +using GarmentFactoryContracts.ViewModels; +using GarmentFactoryDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace GarmentFactoryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, + ILogger<ImplementerController> logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + [HttpGet] + public List<OrderViewModel>? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id); + throw; + } + } + + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormImplementer.Designer.cs b/GarmentFactory/GarmentFactoryView/FormImplementer.Designer.cs new file mode 100644 index 0000000..fc64b01 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormImplementer.Designer.cs @@ -0,0 +1,173 @@ +namespace GarmentFactoryView +{ + partial class FormImplementer + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + textBoxPassword = new TextBox(); + labelPassword = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxFIO = new TextBox(); + labelFIO = new Label(); + textBoxWorkExperience = new TextBox(); + labelWorkExperience = new Label(); + textBoxQualification = new TextBox(); + labelQualification = new Label(); + SuspendLayout(); + // + // textBoxPassword + // + textBoxPassword.Location = new Point(102, 44); + textBoxPassword.Margin = new Padding(4, 3, 4, 3); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(235, 23); + textBoxPassword.TabIndex = 15; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(3, 48); + labelPassword.Margin = new Padding(4, 0, 4, 0); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(55, 15); + labelPassword.TabIndex = 14; + labelPassword.Text = "Пароль :"; + // + // buttonCancel + // + buttonCancel.Location = new Point(242, 140); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(147, 140); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 16; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(102, 16); + textBoxFIO.Margin = new Padding(4, 3, 4, 3); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(235, 23); + textBoxFIO.TabIndex = 13; + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(3, 19); + labelFIO.Margin = new Padding(4, 0, 4, 0); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(40, 15); + labelFIO.TabIndex = 12; + labelFIO.Text = "ФИО :"; + // + // textBoxWorkExperience + // + textBoxWorkExperience.Location = new Point(102, 74); + textBoxWorkExperience.Margin = new Padding(4, 3, 4, 3); + textBoxWorkExperience.Name = "textBoxWorkExperience"; + textBoxWorkExperience.Size = new Size(235, 23); + textBoxWorkExperience.TabIndex = 19; + // + // labelWorkExperience + // + labelWorkExperience.AutoSize = true; + labelWorkExperience.Location = new Point(3, 78); + labelWorkExperience.Margin = new Padding(4, 0, 4, 0); + labelWorkExperience.Name = "labelWorkExperience"; + labelWorkExperience.Size = new Size(85, 15); + labelWorkExperience.TabIndex = 18; + labelWorkExperience.Text = "Стаж работы :"; + // + // textBoxQualification + // + textBoxQualification.Location = new Point(102, 103); + textBoxQualification.Margin = new Padding(4, 3, 4, 3); + textBoxQualification.Name = "textBoxQualification"; + textBoxQualification.Size = new Size(235, 23); + textBoxQualification.TabIndex = 21; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(3, 106); + labelQualification.Margin = new Padding(4, 0, 4, 0); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(94, 15); + labelQualification.TabIndex = 20; + labelQualification.Text = "Квалификация :"; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(350, 178); + Controls.Add(textBoxQualification); + Controls.Add(labelQualification); + Controls.Add(textBoxWorkExperience); + Controls.Add(labelWorkExperience); + Controls.Add(textBoxPassword); + Controls.Add(labelPassword); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFIO); + Controls.Add(labelFIO); + Margin = new Padding(2, 2, 2, 2); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxPassword; + private Label labelPassword; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxFIO; + private Label labelFIO; + private TextBox textBoxWorkExperience; + private Label labelWorkExperience; + private TextBox textBoxQualification; + private Label labelQualification; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormImplementer.cs b/GarmentFactory/GarmentFactoryView/FormImplementer.cs new file mode 100644 index 0000000..ad2beb2 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormImplementer.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using GarmentFactoryContracts.SearchModels; + +namespace GarmentFactoryView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + + private readonly IImplementerLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Receiving implementer"); + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxQualification.Text = view.Qualification.ToString(); + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Receiving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxWorkExperience.Text)) + { + MessageBox.Show("Заполните стаж работы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + MessageBox.Show("Заполните квалификацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving implementer"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/GarmentFactory/GarmentFactoryView/FormImplementer.resx b/GarmentFactory/GarmentFactoryView/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormImplementer.resx @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormImplementers.cs b/GarmentFactory/GarmentFactoryView/FormImplementers.cs new file mode 100644 index 0000000..db532da --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormImplementers.cs @@ -0,0 +1,106 @@ +using GarmentFactoryContracts.BindingModels; +using GarmentFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace GarmentFactoryView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + + private readonly IImplementerLogic _logic; + + public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + 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; + dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Implementers loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementers loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + 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 ButtonEdit_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("Deletion of implementer"); + try + { + if (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementer deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormImplementers.designer.cs b/GarmentFactory/GarmentFactoryView/FormImplementers.designer.cs new file mode 100644 index 0000000..1038c2c --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormImplementers.designer.cs @@ -0,0 +1,127 @@ +namespace GarmentFactoryView +{ + partial class FormImplementers + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 0; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormImplementers"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormImplementers.resx b/GarmentFactory/GarmentFactoryView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/GarmentFactory/GarmentFactoryView/FormImplementers.resx @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs b/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs index 95cf9a2..aa35f44 100644 --- a/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs +++ b/GarmentFactory/GarmentFactoryView/FormMain.Designer.cs @@ -32,17 +32,17 @@ справочники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(); buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonUpd = new Button(); - клиентыToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -50,16 +50,16 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1178, 28); + menuStrip.Size = new Size(1447, 28); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -67,17 +67,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(185, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // изделиеToolStripMenuItem // изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem"; - изделиеToolStripMenuItem.Size = new Size(224, 26); + изделиеToolStripMenuItem.Size = new Size(185, 26); изделиеToolStripMenuItem.Text = "Изделие"; изделиеToolStripMenuItem.Click += ИзделиеToolStripMenuItem_Click; // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(185, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += ИсполнителиToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокПродуктаToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -106,6 +120,13 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += СписокЗаказовToolStripMenuItem_Click; // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += ЗапускРаботToolStripMenuItem_Click; + // // dataGridView // dataGridView.AllowUserToAddRows = false; @@ -120,12 +141,12 @@ dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(944, 427); + dataGridView.Size = new Size(1213, 427); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(965, 77); + buttonCreateOrder.Location = new Point(1236, 127); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(199, 36); buttonCreateOrder.TabIndex = 2; @@ -133,29 +154,9 @@ buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += ButtonCreateOrder_Click; // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(965, 149); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(199, 36); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(963, 222); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(199, 36); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(965, 305); + buttonIssuedOrder.Location = new Point(1236, 211); buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Size = new Size(199, 36); buttonIssuedOrder.TabIndex = 5; @@ -165,7 +166,7 @@ // // buttonUpd // - buttonUpd.Location = new Point(965, 384); + buttonUpd.Location = new Point(1236, 291); buttonUpd.Name = "buttonUpd"; buttonUpd.Size = new Size(197, 36); buttonUpd.TabIndex = 6; @@ -173,22 +174,13 @@ buttonUpd.UseVisualStyleBackColor = true; buttonUpd.Click += ButtonUpd_Click; // - // клиентыToolStripMenuItem - // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(224, 26); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1178, 463); + ClientSize = new Size(1447, 463); Controls.Add(buttonUpd); Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(dataGridView); Controls.Add(menuStrip); @@ -212,8 +204,6 @@ private ToolStripMenuItem изделиеToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonUpd; private ToolStripMenuItem отчетыToolStripMenuItem; @@ -221,5 +211,7 @@ private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/GarmentFactory/GarmentFactoryView/FormMain.cs b/GarmentFactory/GarmentFactoryView/FormMain.cs index fcaa4e1..737600d 100644 --- a/GarmentFactory/GarmentFactoryView/FormMain.cs +++ b/GarmentFactory/GarmentFactoryView/FormMain.cs @@ -18,13 +18,14 @@ namespace GarmentFactoryView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - - public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -43,6 +44,8 @@ namespace GarmentFactoryView dataGridView.Columns["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -81,55 +84,6 @@ namespace GarmentFactoryView } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new - OrderBindingModel - { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -196,5 +150,20 @@ namespace GarmentFactoryView 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); + } + + private void ИсполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/GarmentFactory/GarmentFactoryView/Program.cs b/GarmentFactory/GarmentFactoryView/Program.cs index 8d30f4c..f073195 100644 --- a/GarmentFactory/GarmentFactoryView/Program.cs +++ b/GarmentFactory/GarmentFactoryView/Program.cs @@ -35,12 +35,15 @@ namespace GarmentFactoryView services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<ITextileStorage, TextileStorage>(); services.AddTransient<IClientStorage, ClientStorage>(); + services.AddTransient<IImplementerStorage, ImplementerStorage>(); services.AddTransient<IComponentLogic, ComponentLogic>(); services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<ITextileLogic, TextileLogic>(); services.AddTransient<IReportLogic, ReportLogic>(); services.AddTransient<IClientLogic, ClientLogic>(); + services.AddTransient<IImplementerLogic, ImplementerLogic>(); + services.AddTransient<IWorkProcess, WorkModeling>(); services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); @@ -55,6 +58,8 @@ namespace GarmentFactoryView services.AddTransient<FormReportTextileComponents>(); services.AddTransient<FormReportOrders>(); services.AddTransient<FormClients>(); + services.AddTransient<FormImplementer>(); + services.AddTransient<FormImplementers>(); } } -- 2.25.1