From 44825a7cdd010a6bd7b43a35e597a0d0df55cbc6 Mon Sep 17 00:00:00 2001 From: Kirill <117719052+KirillFirsof@users.noreply.github.com> Date: Sat, 25 May 2024 20:00:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=D0=BA=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ClientLogic.cs | 4 +- .../BusinessLogics/ImplementerLogic.cs | 123 ++++++ .../BusinessLogics/OrderLogic.cs | 165 +++++---- .../BusinessLogics/WorkModeling.cs | 139 +++++++ ClothShop/ClothShopClientApp/APIClient.cs | 5 +- .../ClothShopClientApp.csproj | 2 + .../Views/Home/Create.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 1 + .../BindingModels/ImplementerBindingModel.cs | 18 + .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 20 + .../BusinessLogicContracts/IOrderLogic.cs | 1 + .../BusinessLogicContracts/IWorkProcess.cs | 13 + .../SearchModels/ImplementerSearchModel.cs | 15 + .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 23 ++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 17 + .../ClothShopDataModels/Models/IOrderModel.cs | 1 + .../ClothShopDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 87 +++++ .../Implements/OrderStorage.cs | 13 +- ... 20240525142829_InitialCreate.Designer.cs} | 45 ++- ...ate.cs => 20240525142829_InitialCreate.cs} | 32 +- .../ClothShopDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 64 ++++ .../Models/Order.cs | 8 +- .../DataFileSingleton.cs | 6 +- .../Implements/ImplementerStorage.cs | 83 +++++ .../Implements/OrderStorage.cs | 50 ++- .../Models/Implementer.cs | 78 ++++ .../ClothShopFileImplement/Models/Order.cs | 10 +- .../DataListSingleton.cs | 3 + .../Implements/ImplementerStorage.cs | 103 ++++++ .../Implements/OrderStorage.cs | 44 +-- .../Models/Implementer.cs | 54 +++ .../ClothShopListImplement/Models/Order.cs | 4 + .../Controllers/ImplementerController.cs | 103 ++++++ ClothShop/ClothShopRestApi/Program.cs | 2 + .../ClothShopView/FormComponents.Designer.cs | 112 +++--- ClothShop/ClothShopView/FormComponents.resx | 62 +++- ClothShop/ClothShopView/FormMain.Designer.cs | 350 +++++++++--------- ClothShop/ClothShopView/FormMain.cs | 167 +++++---- .../ClothShopView/ImplementerForm.Designer.cs | 162 ++++++++ ClothShop/ClothShopView/ImplementerForm.cs | 109 ++++++ ClothShop/ClothShopView/ImplementerForm.resx | 120 ++++++ .../ImplementersForm.Designer.cs | 114 ++++++ ClothShop/ClothShopView/ImplementersForm.cs | 124 +++++++ ClothShop/ClothShopView/ImplementersForm.resx | 120 ++++++ ClothShop/ClothShopView/Program.cs | 5 + 51 files changed, 2420 insertions(+), 437 deletions(-) create mode 100644 ClothShop/ClothShopBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 ClothShop/ClothShopBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 ClothShop/ClothShopContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 ClothShop/ClothShopContracts/BusinessLogicContracts/IImplementerLogic.cs create mode 100644 ClothShop/ClothShopContracts/BusinessLogicContracts/IWorkProcess.cs create mode 100644 ClothShop/ClothShopContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 ClothShop/ClothShopContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 ClothShop/ClothShopContracts/ViewModels/ImplementerViewModel.cs create mode 100644 ClothShop/ClothShopDataModels/Models/IImplementerModel.cs create mode 100644 ClothShop/ClothShopDatabaseImplement/Implements/ImplementerStorage.cs rename ClothShop/ClothShopDatabaseImplement/Migrations/{20240518182542_InitialCreate.Designer.cs => 20240525142829_InitialCreate.Designer.cs} (82%) rename ClothShop/ClothShopDatabaseImplement/Migrations/{20240518182542_InitialCreate.cs => 20240525142829_InitialCreate.cs} (81%) create mode 100644 ClothShop/ClothShopDatabaseImplement/Models/Implementer.cs create mode 100644 ClothShop/ClothShopFileImplement/Implements/ImplementerStorage.cs create mode 100644 ClothShop/ClothShopFileImplement/Models/Implementer.cs create mode 100644 ClothShop/ClothShopListImplement/Implements/ImplementerStorage.cs create mode 100644 ClothShop/ClothShopListImplement/Models/Implementer.cs create mode 100644 ClothShop/ClothShopRestApi/Controllers/ImplementerController.cs create mode 100644 ClothShop/ClothShopView/ImplementerForm.Designer.cs create mode 100644 ClothShop/ClothShopView/ImplementerForm.cs create mode 100644 ClothShop/ClothShopView/ImplementerForm.resx create mode 100644 ClothShop/ClothShopView/ImplementersForm.Designer.cs create mode 100644 ClothShop/ClothShopView/ImplementersForm.cs create mode 100644 ClothShop/ClothShopView/ImplementersForm.resx diff --git a/ClothShop/ClothShopBusinessLogic/BusinessLogics/ClientLogic.cs b/ClothShop/ClothShopBusinessLogic/BusinessLogics/ClientLogic.cs index c798b3a..348badc 100644 --- a/ClothShop/ClothShopBusinessLogic/BusinessLogics/ClientLogic.cs +++ b/ClothShop/ClothShopBusinessLogic/BusinessLogics/ClientLogic.cs @@ -17,10 +17,10 @@ namespace ClothShopBusinessLogic.BusinessLogics private readonly ILogger _logger; private readonly IClientStorage _clientStorage; public ClientLogic(ILogger logger, IClientStorage - componentStorage) + clientStorage) { _logger = logger; - _clientStorage = componentStorage; + _clientStorage = clientStorage; } public List? ReadList(ClientSearchModel? model) { diff --git a/ClothShop/ClothShopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/ClothShop/ClothShopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..9c17ede --- /dev/null +++ b/ClothShop/ClothShopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,123 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.BusinessLogicContracts; +using ClothShopContracts.SearchModels; +using ClothShopContracts.StoragesContracts; +using ClothShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage + implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ClientFIO}. 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 ArgumentException("Квалификация меньше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}." + + "Password:{ Password}. WorkExperience:{ WorkExperience}. Qualification:{ Qualification}. Id: { Id} ", + model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/ClothShop/ClothShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ClothShop/ClothShopBusinessLogic/BusinessLogics/OrderLogic.cs index 3257d45..2fdff2e 100644 --- a/ClothShop/ClothShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/ClothShop/ClothShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -15,94 +15,119 @@ namespace ClothShopBusinessLogic.BusinessLogics { public class OrderLogic : IOrderLogic { - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } - - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { - _logger.LogWarning("ReadList return null list"); - return null; + _logger = logger; + _orderStorage = orderStorage; } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - private void CheckModel(OrderBindingModel model) - { - if (model == null) + public List? ReadList(OrderSearchModel? model) { - throw new ArgumentNullException(nameof(model)); + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : + _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество заказов должно быть больше нуля"); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Цена заказа должна быть больше нуля"); - } - _logger.LogInformation("Order. OrderId:{Id}. Sum:{Sum}", model.Id, model.Sum); - } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) + public OrderViewModel? ReadElement(OrderSearchModel model) { - return false; + 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; } - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) + + public bool CreateOrder(OrderBindingModel model) { - _logger.LogWarning("Insert operation failed"); - return false; + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; } - return true; - } - - private bool ChangeStatus(OrderBindingModel model, OrderStatus status) - { - var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (element == null) + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - _logger.LogWarning("Find order failed"); - return false; + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (element.ImplementerId.HasValue) model.ImplementerId = element.ImplementerId; + _orderStorage.Update(model); + return true; } - if (element.Status != status - 1) + + public bool TakeOrderInWork(OrderBindingModel model) { - _logger.LogWarning("Status change failed"); - throw new InvalidOperationException("Невозможно перевести состояние заказа"); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } - model.Status = status; - if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - _orderStorage.Update(model); - return true; - } - public bool TakeOrderInWork(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выполняется); - } + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } - public bool FinishOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Готов); - } + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); + } } } -} + diff --git a/ClothShop/ClothShopBusinessLogic/BusinessLogics/WorkModeling.cs b/ClothShop/ClothShopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..d104615 --- /dev/null +++ b/ClothShop/ClothShopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,139 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.BusinessLogicContracts; +using ClothShopContracts.SearchModels; +using ClothShopContracts.ViewModels; +using ClothShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + private readonly Random _rnd; + private IOrderLogic? _orderLogic; + public WorkModeling(ILogger 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 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/ClothShop/ClothShopClientApp/APIClient.cs b/ClothShop/ClothShopClientApp/APIClient.cs index 10a4e1d..dc39da3 100644 --- a/ClothShop/ClothShopClientApp/APIClient.cs +++ b/ClothShop/ClothShopClientApp/APIClient.cs @@ -9,6 +9,7 @@ namespace ClothShopClientApp { private static readonly HttpClient _client = new(); public static ClientViewModel? Client { get; set; } = null; + public static void Connect(IConfiguration configuration) { _client.BaseAddress = new Uri(configuration["IPAddress"]); @@ -16,6 +17,7 @@ namespace ClothShopClientApp _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } + public static T? GetRequest(string requestUrl) { var response = _client.GetAsync(requestUrl); @@ -35,9 +37,6 @@ namespace ClothShopClientApp var data = new StringContent(json, Encoding.UTF8, "application/json"); var response = _client.PostAsync(requestUrl, data); - var a = response.Result; - var b = response.Result.Content; - var c = response.Result.Content.ReadAsStringAsync(); var result = response.Result.Content.ReadAsStringAsync().Result; if (!response.Result.IsSuccessStatusCode) { diff --git a/ClothShop/ClothShopClientApp/ClothShopClientApp.csproj b/ClothShop/ClothShopClientApp/ClothShopClientApp.csproj index 44db962..e2f0ca1 100644 --- a/ClothShop/ClothShopClientApp/ClothShopClientApp.csproj +++ b/ClothShop/ClothShopClientApp/ClothShopClientApp.csproj @@ -7,6 +7,8 @@ + + diff --git a/ClothShop/ClothShopClientApp/Views/Home/Create.cshtml b/ClothShop/ClothShopClientApp/Views/Home/Create.cshtml index e945899..1c943ec 100644 --- a/ClothShop/ClothShopClientApp/Views/Home/Create.cshtml +++ b/ClothShop/ClothShopClientApp/Views/Home/Create.cshtml @@ -17,7 +17,7 @@
Сумма:
-
+
diff --git a/ClothShop/ClothShopClientApp/Views/Shared/_Layout.cshtml b/ClothShop/ClothShopClientApp/Views/Shared/_Layout.cshtml index 27d3a06..ab6960a 100644 --- a/ClothShop/ClothShopClientApp/Views/Shared/_Layout.cshtml +++ b/ClothShop/ClothShopClientApp/Views/Shared/_Layout.cshtml @@ -4,6 +4,7 @@ @ViewData["Title"] - ClothShopClientApp + diff --git a/ClothShop/ClothShopContracts/BindingModels/ImplementerBindingModel.cs b/ClothShop/ClothShopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..7bdf8a4 --- /dev/null +++ b/ClothShop/ClothShopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using ClothShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public string Password { get; set; } = string.Empty; + } +} diff --git a/ClothShop/ClothShopContracts/BindingModels/OrderBindingModel.cs b/ClothShop/ClothShopContracts/BindingModels/OrderBindingModel.cs index 11c14d3..3e628d8 100644 --- a/ClothShop/ClothShopContracts/BindingModels/OrderBindingModel.cs +++ b/ClothShop/ClothShopContracts/BindingModels/OrderBindingModel.cs @@ -15,6 +15,7 @@ namespace ClothShopContracts.BindingModels public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } + public int? ImplementerId { get; set; } = null; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } diff --git a/ClothShop/ClothShopContracts/BusinessLogicContracts/IImplementerLogic.cs b/ClothShop/ClothShopContracts/BusinessLogicContracts/IImplementerLogic.cs new file mode 100644 index 0000000..243e179 --- /dev/null +++ b/ClothShop/ClothShopContracts/BusinessLogicContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.SearchModels; +using ClothShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopContracts.BusinessLogicContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerBindingModel model); + bool Update(ImplementerBindingModel model); + bool Delete(ImplementerBindingModel model); + } +} diff --git a/ClothShop/ClothShopContracts/BusinessLogicContracts/IOrderLogic.cs b/ClothShop/ClothShopContracts/BusinessLogicContracts/IOrderLogic.cs index 9b79f26..0c12813 100644 --- a/ClothShop/ClothShopContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/ClothShop/ClothShopContracts/BusinessLogicContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace ClothShopContracts.BusinessLogicContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/ClothShop/ClothShopContracts/BusinessLogicContracts/IWorkProcess.cs b/ClothShop/ClothShopContracts/BusinessLogicContracts/IWorkProcess.cs new file mode 100644 index 0000000..b638c7a --- /dev/null +++ b/ClothShop/ClothShopContracts/BusinessLogicContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopContracts.BusinessLogicContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/ClothShop/ClothShopContracts/SearchModels/ImplementerSearchModel.cs b/ClothShop/ClothShopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..3c98613 --- /dev/null +++ b/ClothShop/ClothShopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } +} diff --git a/ClothShop/ClothShopContracts/SearchModels/OrderSearchModel.cs b/ClothShop/ClothShopContracts/SearchModels/OrderSearchModel.cs index 3cc0322..4e6d7e4 100644 --- a/ClothShop/ClothShopContracts/SearchModels/OrderSearchModel.cs +++ b/ClothShop/ClothShopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using ClothShopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,6 +11,8 @@ namespace ClothShopContracts.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/ClothShop/ClothShopContracts/StoragesContracts/IImplementerStorage.cs b/ClothShop/ClothShopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..5a7c2d9 --- /dev/null +++ b/ClothShop/ClothShopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.SearchModels; +using ClothShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + List GetFilteredList(ImplementerSearchModel model); + ImplementerViewModel? GetElement(ImplementerSearchModel model); + ImplementerViewModel? Insert(ImplementerBindingModel model); + ImplementerViewModel? Update(ImplementerBindingModel model); + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/ClothShop/ClothShopContracts/ViewModels/ImplementerViewModel.cs b/ClothShop/ClothShopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..6447955 --- /dev/null +++ b/ClothShop/ClothShopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using ClothShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } = 0; + [DisplayName("Квалификация")] + public int Qualification { get; set; } = 0; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/ClothShop/ClothShopContracts/ViewModels/OrderViewModel.cs b/ClothShop/ClothShopContracts/ViewModels/OrderViewModel.cs index f623cfe..62b2b19 100644 --- a/ClothShop/ClothShopContracts/ViewModels/OrderViewModel.cs +++ b/ClothShop/ClothShopContracts/ViewModels/OrderViewModel.cs @@ -18,6 +18,9 @@ namespace ClothShopContracts.ViewModels public string TextileName { get; set; } = string.Empty; public int ClientId { get; set; } [DisplayName("Клиент")] + public int? ImplementerId { get; set; } = null; + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/ClothShop/ClothShopDataModels/Models/IImplementerModel.cs b/ClothShop/ClothShopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..ec7485e --- /dev/null +++ b/ClothShop/ClothShopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopDataModels.Models +{ + public interface IImplementerModel + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/ClothShop/ClothShopDataModels/Models/IOrderModel.cs b/ClothShop/ClothShopDataModels/Models/IOrderModel.cs index 6f3995d..8a959c1 100644 --- a/ClothShop/ClothShopDataModels/Models/IOrderModel.cs +++ b/ClothShop/ClothShopDataModels/Models/IOrderModel.cs @@ -13,6 +13,7 @@ namespace ClothShopDataModels.Models int ClientId { get; } int Count { get; } double Sum { get; } + int? ImplementerId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/ClothShop/ClothShopDatabaseImplement/ClothShopDatabase.cs b/ClothShop/ClothShopDatabaseImplement/ClothShopDatabase.cs index c7fa78f..b4a40ef 100644 --- a/ClothShop/ClothShopDatabaseImplement/ClothShopDatabase.cs +++ b/ClothShop/ClothShopDatabaseImplement/ClothShopDatabase.cs @@ -19,5 +19,6 @@ namespace ClothShopDatabaseImplement public virtual DbSet TextileComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } \ No newline at end of file diff --git a/ClothShop/ClothShopDatabaseImplement/Implements/ImplementerStorage.cs b/ClothShop/ClothShopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..a986fb9 --- /dev/null +++ b/ClothShop/ClothShopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,87 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.SearchModels; +using ClothShopContracts.StoragesContracts; +using ClothShopContracts.ViewModels; +using ClothShopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new ClothShopDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } + using var context = new ClothShopDatabase(); + return context.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + return new(); + } + + public List GetFullList() + { + using var context = new ClothShopDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new ClothShopDatabase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new ClothShopDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/ClothShop/ClothShopDatabaseImplement/Implements/OrderStorage.cs b/ClothShop/ClothShopDatabaseImplement/Implements/OrderStorage.cs index 055d927..bb59d9b 100644 --- a/ClothShop/ClothShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ClothShop/ClothShopDatabaseImplement/Implements/OrderStorage.cs @@ -17,14 +17,14 @@ namespace ClothShopDatabaseImplement.Implements public List GetFullList() { using var context = new ClothShopDatabase(); - return context.Orders.Include(x => x.Textiles).Include(x => x.Client) + return context.Orders.Include(x => x.Textiles).Include(x => x.Client).Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(OrderSearchModel model) { using var context = new ClothShopDatabase(); - return context.Orders.Include(x => x.Textiles).Include(x => x.Client) + return context.Orders.Include(x => x.Textiles).Include(x => x.Client).Include(x => x.Implementer) .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && @@ -42,7 +42,10 @@ namespace ClothShopDatabaseImplement.Implements return null; } using var context = new ClothShopDatabase(); - return context.Orders.Include(x => x.Textiles).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Textiles).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault( + x => ((model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -59,7 +62,7 @@ namespace ClothShopDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new ClothShopDatabase(); - var order = context.Orders.Include(x => x.Textiles).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); + var order = context.Orders.Include(x => x.Textiles).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -71,7 +74,7 @@ namespace ClothShopDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new ClothShopDatabase(); - var element = context.Orders.Include(x => x.Textiles).Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders.Include(x => x.Textiles).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/ClothShop/ClothShopDatabaseImplement/Migrations/20240518182542_InitialCreate.Designer.cs b/ClothShop/ClothShopDatabaseImplement/Migrations/20240525142829_InitialCreate.Designer.cs similarity index 82% rename from ClothShop/ClothShopDatabaseImplement/Migrations/20240518182542_InitialCreate.Designer.cs rename to ClothShop/ClothShopDatabaseImplement/Migrations/20240525142829_InitialCreate.Designer.cs index 1e6b9d4..cf4c870 100644 --- a/ClothShop/ClothShopDatabaseImplement/Migrations/20240518182542_InitialCreate.Designer.cs +++ b/ClothShop/ClothShopDatabaseImplement/Migrations/20240525142829_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ClothShopDatabaseImplement.Migrations { [DbContext(typeof(ClothShopDatabase))] - [Migration("20240518182542_InitialCreate")] + [Migration("20240525142829_InitialCreate")] partial class InitialCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -69,6 +69,33 @@ namespace ClothShopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -89,6 +116,9 @@ namespace ClothShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -102,6 +132,8 @@ namespace ClothShopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("TextileId"); b.ToTable("Orders"); @@ -161,6 +193,10 @@ namespace ClothShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ClothShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("ClothShopDatabaseImplement.Models.Textile", "Textiles") .WithMany("Orders") .HasForeignKey("TextileId") @@ -169,6 +205,8 @@ namespace ClothShopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Textiles"); }); @@ -201,6 +239,11 @@ namespace ClothShopDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); diff --git a/ClothShop/ClothShopDatabaseImplement/Migrations/20240518182542_InitialCreate.cs b/ClothShop/ClothShopDatabaseImplement/Migrations/20240525142829_InitialCreate.cs similarity index 81% rename from ClothShop/ClothShopDatabaseImplement/Migrations/20240518182542_InitialCreate.cs rename to ClothShop/ClothShopDatabaseImplement/Migrations/20240525142829_InitialCreate.cs index 4d5880d..43fdf1e 100644 --- a/ClothShop/ClothShopDatabaseImplement/Migrations/20240518182542_InitialCreate.cs +++ b/ClothShop/ClothShopDatabaseImplement/Migrations/20240525142829_InitialCreate.cs @@ -38,6 +38,22 @@ namespace ClothShopDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Textiles", columns: table => new @@ -64,7 +80,8 @@ namespace ClothShopDatabaseImplement.Migrations DateCreate = table.Column(type: "datetime2", nullable: false), DateImplement = table.Column(type: "datetime2", nullable: true), TextileId = table.Column(type: "int", nullable: false), - ClientId = table.Column(type: "int", nullable: false) + ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true) }, constraints: table => { @@ -75,6 +92,11 @@ namespace ClothShopDatabaseImplement.Migrations 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, @@ -115,6 +137,11 @@ namespace ClothShopDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_TextileId", table: "Orders", @@ -142,6 +169,9 @@ namespace ClothShopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); diff --git a/ClothShop/ClothShopDatabaseImplement/Migrations/ClothShopDatabaseModelSnapshot.cs b/ClothShop/ClothShopDatabaseImplement/Migrations/ClothShopDatabaseModelSnapshot.cs index c395b97..276fd5f 100644 --- a/ClothShop/ClothShopDatabaseImplement/Migrations/ClothShopDatabaseModelSnapshot.cs +++ b/ClothShop/ClothShopDatabaseImplement/Migrations/ClothShopDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace ClothShopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace ClothShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace ClothShopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("TextileId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace ClothShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ClothShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("ClothShopDatabaseImplement.Models.Textile", "Textiles") .WithMany("Orders") .HasForeignKey("TextileId") @@ -167,6 +203,8 @@ namespace ClothShopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Textiles"); }); @@ -199,6 +237,11 @@ namespace ClothShopDatabaseImplement.Migrations b.Navigation("TextileComponents"); }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("ClothShopDatabaseImplement.Models.Textile", b => { b.Navigation("Components"); diff --git a/ClothShop/ClothShopDatabaseImplement/Models/Implementer.cs b/ClothShop/ClothShopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..a7b5efe --- /dev/null +++ b/ClothShop/ClothShopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.ViewModels; +using ClothShopDataModels.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 ClothShopDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public int Qualification { get; set; } = 0; + [Required] + public int WorkExperience { get; set; } = 0; + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + }; + } +} diff --git a/ClothShop/ClothShopDatabaseImplement/Models/Order.cs b/ClothShop/ClothShopDatabaseImplement/Models/Order.cs index c306f83..0c89b10 100644 --- a/ClothShop/ClothShopDatabaseImplement/Models/Order.cs +++ b/ClothShop/ClothShopDatabaseImplement/Models/Order.cs @@ -24,6 +24,8 @@ namespace ClothShopDatabaseImplement.Models [Required] public int ClientId { get; private set; } public virtual Client? Client { get; private set; } + public int? ImplementerId { get; private set; } = null; + public virtual Implementer? Implementer { get; private set; } public static Order? Create(OrderBindingModel model) { @@ -41,6 +43,7 @@ namespace ClothShopDatabaseImplement.Models DateImplement = model.DateImplement, TextileId = model.TextileId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, }; } @@ -52,12 +55,14 @@ namespace ClothShopDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { TextileId = TextileId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -65,7 +70,8 @@ namespace ClothShopDatabaseImplement.Models DateImplement = DateImplement, Id = Id, TextileName = Textiles?.TextileName ?? string.Empty, - ClientFIO = Client?.ClientFIO ?? string.Empty + ClientFIO = Client?.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, }; } } diff --git a/ClothShop/ClothShopFileImplement/DataFileSingleton.cs b/ClothShop/ClothShopFileImplement/DataFileSingleton.cs index 903ab5b..7eeaef4 100644 --- a/ClothShop/ClothShopFileImplement/DataFileSingleton.cs +++ b/ClothShop/ClothShopFileImplement/DataFileSingleton.cs @@ -2,18 +2,20 @@ using System.Xml.Linq; namespace ClothShopFileImplement { - public class DataFileSingleton + internal class DataFileSingleton { private static DataFileSingleton? instance; private readonly string ComponentFileName = "Component.xml"; 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 Components { get; private set; } public List Orders { get; private set; } public List Textiles { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -26,12 +28,14 @@ namespace ClothShopFileImplement public void SaveTextiles() => SaveData(Textiles, TextileFileName, "Textiles", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Textiles = 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? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/ClothShop/ClothShopFileImplement/Implements/ImplementerStorage.cs b/ClothShop/ClothShopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..3990552 --- /dev/null +++ b/ClothShop/ClothShopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,83 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.SearchModels; +using ClothShopContracts.StoragesContracts; +using ClothShopContracts.ViewModels; +using ClothShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel + model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implementers + .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO.Contains(model.ImplementerFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + return source.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.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(rec => rec.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/ClothShop/ClothShopFileImplement/Implements/OrderStorage.cs b/ClothShop/ClothShopFileImplement/Implements/OrderStorage.cs index eb3ebbc..eb9f518 100644 --- a/ClothShop/ClothShopFileImplement/Implements/OrderStorage.cs +++ b/ClothShop/ClothShopFileImplement/Implements/OrderStorage.cs @@ -16,19 +16,24 @@ namespace ClothShopFileImplement.Implements public List GetFullList() { return source.Orders - .Select(x => AccessTextileStorage(x.GetViewModel)) + .Select(x => AccessStorage(x.GetViewModel)) .ToList(); } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return new(); - } return source.Orders - .Where(x => x.Id == model.Id) - .Select(x => AccessTextileStorage(x.GetViewModel)) + .Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) && + (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) + && + (!model.ClientId.HasValue || x.ClientId == model.ClientId) + && + (!model.Status.HasValue || x.Status == model.Status) + ) + ) + .Select(x => AccessStorage(x.GetViewModel)) .ToList(); } @@ -38,7 +43,11 @@ namespace ClothShopFileImplement.Implements { return null; } - return AccessTextileStorage(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel); + return AccessStorage(source.Orders + .FirstOrDefault( + x => (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status))?.GetViewModel ?? new()); } public OrderViewModel? Insert(OrderBindingModel model) @@ -51,7 +60,7 @@ namespace ClothShopFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return AccessTextileStorage(newOrder.GetViewModel); + return AccessStorage(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -63,7 +72,7 @@ namespace ClothShopFileImplement.Implements } order.Update(model); source.SaveOrders(); - return AccessTextileStorage(order.GetViewModel); + return AccessStorage(order.GetViewModel); } public OrderViewModel? Delete(OrderBindingModel model) { @@ -73,23 +82,24 @@ namespace ClothShopFileImplement.Implements { source.Orders.Remove(element); source.SaveOrders(); - return AccessTextileStorage(element.GetViewModel); + return AccessStorage(element.GetViewModel); } return null; } - public OrderViewModel AccessTextileStorage(OrderViewModel model) + public OrderViewModel AccessStorage(OrderViewModel model) { if (model == null) return null; - foreach (var Textile in source.Textiles) - { - if (Textile.Id == model.TextileId) - { - model.TextileName = Textile.TextileName; - break; - } - } + var textile = source.Textiles.FirstOrDefault(x => x.Id == model.Id); + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (textile != null) + model.TextileName = textile.TextileName; + if (client != null) + model.ClientFIO = client.ClientFIO; + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } } diff --git a/ClothShop/ClothShopFileImplement/Models/Implementer.cs b/ClothShop/ClothShopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..fb58b19 --- /dev/null +++ b/ClothShop/ClothShopFileImplement/Models/Implementer.cs @@ -0,0 +1,78 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.ViewModels; +using ClothShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ClothShopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int Qualification { get; set; } = 0; + public int WorkExperience { get; set; } = 0; + 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 + }; + 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, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString()) + ); + } +} diff --git a/ClothShop/ClothShopFileImplement/Models/Order.cs b/ClothShop/ClothShopFileImplement/Models/Order.cs index b4d7107..c1cad03 100644 --- a/ClothShop/ClothShopFileImplement/Models/Order.cs +++ b/ClothShop/ClothShopFileImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace ClothShopFileImplement.Models public OrderStatus Status { get; private set; } public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } + public int? ImplementerId { get; private set; } = null; public static Order? Create(OrderBindingModel model) { @@ -32,6 +33,7 @@ namespace ClothShopFileImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId, }; } public static Order? Create(XElement element) @@ -49,7 +51,8 @@ namespace ClothShopFileImplement.Models Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value.ToString()), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), }; } public void Update(OrderBindingModel model) @@ -60,6 +63,7 @@ namespace ClothShopFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -71,6 +75,7 @@ namespace ClothShopFileImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, + ImplementerId = ImplementerId }; public XElement GetXElement => new("Order", new XAttribute("Id", Id), @@ -80,7 +85,8 @@ namespace ClothShopFileImplement.Models new XElement("Count", Count), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString()) + new XElement("DateImplement", DateImplement.ToString()), + new XElement("ImplementerId", ImplementerId) ); } } diff --git a/ClothShop/ClothShopListImplement/DataListSingleton.cs b/ClothShop/ClothShopListImplement/DataListSingleton.cs index 11d980f..0fa7dd8 100644 --- a/ClothShop/ClothShopListImplement/DataListSingleton.cs +++ b/ClothShop/ClothShopListImplement/DataListSingleton.cs @@ -1,5 +1,6 @@ using ClothShopListImplement.Models; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; @@ -15,6 +16,7 @@ namespace ClothShopListImplement public List Orders { get; set; } public List Textiles { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { @@ -22,6 +24,7 @@ namespace ClothShopListImplement Orders = new List(); Textiles = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/ClothShop/ClothShopListImplement/Implements/ImplementerStorage.cs b/ClothShop/ClothShopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..30fbe21 --- /dev/null +++ b/ClothShop/ClothShopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,103 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.SearchModels; +using ClothShopContracts.StoragesContracts; +using ClothShopContracts.ViewModels; +using ClothShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + public List GetFilteredList(ImplementerSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + 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) + { + foreach (var implementer in _source.Implementers) + { + if ((string.IsNullOrEmpty(model.ImplementerFIO) || implementer.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || implementer.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + { + 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 (model.Id == implementer.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/ClothShop/ClothShopListImplement/Implements/OrderStorage.cs b/ClothShop/ClothShopListImplement/Implements/OrderStorage.cs index 9b8c138..5df9b79 100644 --- a/ClothShop/ClothShopListImplement/Implements/OrderStorage.cs +++ b/ClothShop/ClothShopListImplement/Implements/OrderStorage.cs @@ -23,7 +23,7 @@ namespace ClothShopListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(AccessTextileStorage(order.GetViewModel)); + result.Add(AccessStorage(order.GetViewModel)); } return result; } @@ -33,11 +33,14 @@ namespace ClothShopListImplement.Implements foreach (var order in _source.Orders) { if ((!model.Id.HasValue || order.Id == model.Id) && - (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || order.DateCreate <= model.DateTo) && - (!model.ClientId.HasValue || order.ClientId == model.ClientId)) + (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || order.DateCreate <= model.DateTo) + && + (!model.ClientId.HasValue || order.ClientId == model.ClientId) + && + (!model.Status.HasValue || order.Status == model.Status)) { - result.Add(AccessTextileStorage(order.GetViewModel)); + result.Add(AccessStorage(order.GetViewModel)); } } return result; @@ -50,9 +53,11 @@ namespace ClothShopListImplement.Implements } foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) + if ((model.Id.HasValue && order.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + order.ImplementerId == model.ImplementerId && order.Status == model.Status)) { - return order.GetViewModel; + return AccessStorage(order.GetViewModel); } } return null; @@ -101,24 +106,19 @@ namespace ClothShopListImplement.Implements return null; } - public OrderViewModel AccessTextileStorage(OrderViewModel model) + public OrderViewModel AccessStorage(OrderViewModel model) { - foreach (var Textile in _source.Textiles) - { - if (Textile.Id == model.TextileId) - { - model.TextileName = Textile.TextileName; - break; - } - } - return model; - } - - public OrderViewModel AccessClientStorage(OrderViewModel model) - { - var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId); + if (model == null) + return null; + var textile = _source.Textiles.FirstOrDefault(x => x.Id == model.Id); + var client = _source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = _source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (textile != null) + model.TextileName = textile.TextileName; if (client != null) model.ClientFIO = client.ClientFIO; + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } } diff --git a/ClothShop/ClothShopListImplement/Models/Implementer.cs b/ClothShop/ClothShopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..a335bbf --- /dev/null +++ b/ClothShop/ClothShopListImplement/Models/Implementer.cs @@ -0,0 +1,54 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.ViewModels; +using ClothShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClothShopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + 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/ClothShop/ClothShopListImplement/Models/Order.cs b/ClothShop/ClothShopListImplement/Models/Order.cs index a6c3bc0..9005136 100644 --- a/ClothShop/ClothShopListImplement/Models/Order.cs +++ b/ClothShop/ClothShopListImplement/Models/Order.cs @@ -20,6 +20,7 @@ namespace ClothShopListImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } public int Id { get; private set; } + public int? ImplementerId { get; private set; } public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -36,6 +37,7 @@ namespace ClothShopListImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, Id = model.Id, + ImplementerId = model.ImplementerId, }; } public void Update(OrderBindingModel? model) @@ -46,6 +48,7 @@ namespace ClothShopListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -57,6 +60,7 @@ namespace ClothShopListImplement.Models DateImplement = DateImplement, Id = Id, Status = Status, + ImplementerId = ImplementerId, }; } } diff --git a/ClothShop/ClothShopRestApi/Controllers/ImplementerController.cs b/ClothShop/ClothShopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..4494740 --- /dev/null +++ b/ClothShop/ClothShopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.BusinessLogicContracts; +using ClothShopContracts.SearchModels; +using ClothShopContracts.ViewModels; +using ClothShopDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace ClothShopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : ControllerBase + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, + ILogger 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? 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/ClothShop/ClothShopRestApi/Program.cs b/ClothShop/ClothShopRestApi/Program.cs index e99cefa..ceb27c1 100644 --- a/ClothShop/ClothShopRestApi/Program.cs +++ b/ClothShop/ClothShopRestApi/Program.cs @@ -17,6 +17,8 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/ClothShop/ClothShopView/FormComponents.Designer.cs b/ClothShop/ClothShopView/FormComponents.Designer.cs index 1b80bc7..9abade4 100644 --- a/ClothShop/ClothShopView/FormComponents.Designer.cs +++ b/ClothShop/ClothShopView/FormComponents.Designer.cs @@ -28,81 +28,79 @@ /// private void InitializeComponent() { - this.buttonRefresh = new System.Windows.Forms.Button(); - this.buttonDelete = new System.Windows.Forms.Button(); - this.buttonUpdate = new System.Windows.Forms.Button(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // buttonRefresh // - this.buttonRefresh.Location = new System.Drawing.Point(642, 209); - this.buttonRefresh.Name = "buttonRefresh"; - this.buttonRefresh.Size = new System.Drawing.Size(120, 39); - this.buttonRefresh.TabIndex = 9; - this.buttonRefresh.Text = "Обновить"; - this.buttonRefresh.UseVisualStyleBackColor = true; - this.buttonRefresh.Click += new System.EventHandler(this.ButtonRef_Click); + buttonRefresh.Location = new Point(642, 209); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(120, 39); + buttonRefresh.TabIndex = 9; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; // // buttonDelete // - this.buttonDelete.Location = new System.Drawing.Point(642, 149); - this.buttonDelete.Name = "buttonDelete"; - this.buttonDelete.Size = new System.Drawing.Size(120, 39); - this.buttonDelete.TabIndex = 8; - this.buttonDelete.Text = "Удалить"; - this.buttonDelete.UseVisualStyleBackColor = true; - this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + buttonDelete.Location = new Point(642, 149); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(120, 39); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(642, 86); - this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(120, 39); - this.buttonUpdate.TabIndex = 7; - this.buttonUpdate.Text = "Изменить"; - this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.ButtonUpd_Click); + buttonUpdate.Location = new Point(642, 86); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(120, 39); + buttonUpdate.TabIndex = 7; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(642, 26); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(120, 39); - this.buttonAdd.TabIndex = 6; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + buttonAdd.Location = new Point(642, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(120, 39); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; // // dataGridView // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(1, -1); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(593, 450); - this.dataGridView.TabIndex = 5; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, -1); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(593, 450); + dataGridView.TabIndex = 5; // // FormComponents // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonRefresh); - this.Controls.Add(this.buttonDelete); - this.Controls.Add(this.buttonUpdate); - this.Controls.Add(this.buttonAdd); - this.Controls.Add(this.dataGridView); - this.Name = "FormComponents"; - this.Text = "Компоненты"; - this.Load += new System.EventHandler(this.FormComponents_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Компоненты"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion diff --git a/ClothShop/ClothShopView/FormComponents.resx b/ClothShop/ClothShopView/FormComponents.resx index f298a7b..af32865 100644 --- a/ClothShop/ClothShopView/FormComponents.resx +++ b/ClothShop/ClothShopView/FormComponents.resx @@ -1,4 +1,64 @@ - + + + diff --git a/ClothShop/ClothShopView/FormMain.Designer.cs b/ClothShop/ClothShopView/FormMain.Designer.cs index c14a48f..c06783e 100644 --- a/ClothShop/ClothShopView/FormMain.Designer.cs +++ b/ClothShop/ClothShopView/FormMain.Designer.cs @@ -20,199 +20,191 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - menuStrip = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - изделиеToolStripMenuItem = new ToolStripMenuItem(); - клиентыToolStripMenuItem = new ToolStripMenuItem(); - ReportToolStripMenuItem = new ToolStripMenuItem(); - ReportTextilesToolStripMenuItem = new ToolStripMenuItem(); - ReportTextileComponentsToolStripMenuItem = new ToolStripMenuItem(); - ReportOrdeersToolStripMenuItem = new ToolStripMenuItem(); - buttonRefresh = new Button(); - buttonIssuedOrder = new Button(); - buttonOrderReady = new Button(); - buttonTakeOrderInWork = new Button(); - buttonCreateOrder = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - menuStrip.SuspendLayout(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; - dataGridView.BackgroundColor = Color.White; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 31); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 51; - dataGridView.Size = new Size(1073, 377); - dataGridView.TabIndex = 8; - // - // menuStrip - // - menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, ReportToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1331, 28); - menuStrip.TabIndex = 7; - menuStrip.Text = "Меню справочников"; - // - // справочникиToolStripMenuItem - // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(117, 24); - справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; - // - // изделиеToolStripMenuItem - // - изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem"; - изделиеToolStripMenuItem.Size = new Size(182, 26); - изделиеToolStripMenuItem.Text = "Изделие"; - изделиеToolStripMenuItem.Click += TextileToolStripMenuItem_Click; - // - // клиентыToolStripMenuItem - // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(182, 26); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += clientsToolStripMenuItem_Click; - // - // ReportToolStripMenuItem - // - ReportToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ReportTextilesToolStripMenuItem, ReportTextileComponentsToolStripMenuItem, ReportOrdeersToolStripMenuItem }); - ReportToolStripMenuItem.Name = "ReportToolStripMenuItem"; - ReportToolStripMenuItem.Size = new Size(73, 24); - ReportToolStripMenuItem.Text = "Отчеты"; - // - // ReportTextilesToolStripMenuItem - // - ReportTextilesToolStripMenuItem.Name = "ReportTextilesToolStripMenuItem"; - ReportTextilesToolStripMenuItem.Size = new Size(276, 26); - ReportTextilesToolStripMenuItem.Text = "Список изделий"; - ReportTextilesToolStripMenuItem.Click += ReportComponentsToolStripMenuItem_Click; - // - // ReportTextileComponentsToolStripMenuItem - // - ReportTextileComponentsToolStripMenuItem.Name = "ReportTextileComponentsToolStripMenuItem"; - ReportTextileComponentsToolStripMenuItem.Size = new Size(276, 26); - ReportTextileComponentsToolStripMenuItem.Text = "Компоненты по изделиям"; - ReportTextileComponentsToolStripMenuItem.Click += ReportTextileComponentsToolStripMenuItem_Click; - // - // ReportOrdeersToolStripMenuItem - // - ReportOrdeersToolStripMenuItem.Name = "ReportOrdeersToolStripMenuItem"; - ReportOrdeersToolStripMenuItem.Size = new Size(276, 26); - ReportOrdeersToolStripMenuItem.Text = "Список заказов"; - ReportOrdeersToolStripMenuItem.Click += ReportOrdersToolStripMenuItem_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(1107, 318); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(212, 38); - buttonRefresh.TabIndex = 13; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRef_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(1107, 237); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(212, 38); - buttonIssuedOrder.TabIndex = 12; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(1107, 163); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(212, 38); - buttonOrderReady.TabIndex = 11; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(1107, 109); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(212, 38); - buttonTakeOrderInWork.TabIndex = 10; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(1107, 48); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(212, 38); - buttonCreateOrder.TabIndex = 9; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1331, 417); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - Controls.Add(buttonRefresh); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Name = "FormMain"; - Text = "Заказы"; - Load += FormMain_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделиеToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + ReportToolStripMenuItem = new ToolStripMenuItem(); + ReportTextilesToolStripMenuItem = new ToolStripMenuItem(); + ReportTextileComponentsToolStripMenuItem = new ToolStripMenuItem(); + ReportOrdeersToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); + buttonRefresh = new Button(); + buttonIssuedOrder = new Button(); + buttonCreateOrder = new Button(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(1073, 377); + dataGridView.TabIndex = 8; + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, ReportToolStripMenuItem, запускРаботToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1331, 28); + menuStrip.TabIndex = 7; + menuStrip.Text = "Меню справочников"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += ComponentsStripMenuItem_Click; + // + // изделиеToolStripMenuItem + // + изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem"; + изделиеToolStripMenuItem.Size = new Size(224, 26); + изделиеToolStripMenuItem.Text = "Изделие"; + изделиеToolStripMenuItem.Click += TextilesStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(224, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // ReportToolStripMenuItem + // + ReportToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ReportTextilesToolStripMenuItem, ReportTextileComponentsToolStripMenuItem, ReportOrdeersToolStripMenuItem }); + ReportToolStripMenuItem.Name = "ReportToolStripMenuItem"; + ReportToolStripMenuItem.Size = new Size(73, 24); + ReportToolStripMenuItem.Text = "Отчеты"; + // + // ReportTextilesToolStripMenuItem + // + ReportTextilesToolStripMenuItem.Name = "ReportTextilesToolStripMenuItem"; + ReportTextilesToolStripMenuItem.Size = new Size(276, 26); + ReportTextilesToolStripMenuItem.Text = "Список изделий"; + ReportTextilesToolStripMenuItem.Click += списокКомпонентовToolStripMenuItem_Click; + // + // ReportTextileComponentsToolStripMenuItem + // + ReportTextileComponentsToolStripMenuItem.Name = "ReportTextileComponentsToolStripMenuItem"; + ReportTextileComponentsToolStripMenuItem.Size = new Size(276, 26); + ReportTextileComponentsToolStripMenuItem.Text = "Компоненты по изделиям"; + ReportTextileComponentsToolStripMenuItem.Click += компонентыПоКомпьютерамToolStripMenuItem_Click; + // + // ReportOrdeersToolStripMenuItem + // + ReportOrdeersToolStripMenuItem.Name = "ReportOrdeersToolStripMenuItem"; + ReportOrdeersToolStripMenuItem.Size = new Size(276, 26); + ReportOrdeersToolStripMenuItem.Text = "Список заказов"; + ReportOrdeersToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(1107, 318); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(212, 38); + buttonRefresh.TabIndex = 13; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(1107, 237); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(212, 38); + buttonIssuedOrder.TabIndex = 12; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += IssuedButton_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(1107, 48); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(212, 38); + buttonCreateOrder.TabIndex = 9; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += CreateOrderButton_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(1331, 417); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonCreateOrder); + Name = "FormMain"; + Text = "Заказы"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private DataGridView dataGridView; + private DataGridView dataGridView; private MenuStrip menuStrip; private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделиеToolStripMenuItem; private Button buttonRefresh; private Button buttonIssuedOrder; - private Button buttonOrderReady; - private Button buttonTakeOrderInWork; private Button buttonCreateOrder; private ToolStripMenuItem ReportToolStripMenuItem; private ToolStripMenuItem ReportTextilesToolStripMenuItem; private ToolStripMenuItem ReportTextileComponentsToolStripMenuItem; private ToolStripMenuItem ReportOrdeersToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/ClothShop/ClothShopView/FormMain.cs b/ClothShop/ClothShopView/FormMain.cs index 36e023d..061348a 100644 --- a/ClothShop/ClothShopView/FormMain.cs +++ b/ClothShop/ClothShopView/FormMain.cs @@ -19,18 +19,31 @@ namespace ClothShopView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } + + private void ComponentsStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void FormMain_Load(object sender, EventArgs e) { LoadData(); } + private void LoadData() { _logger.LogInformation("Загрузка заказов"); @@ -42,8 +55,8 @@ namespace ClothShopView dataGridView.DataSource = list; dataGridView.Columns["TextileId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["TextileName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["TextileName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -53,15 +66,8 @@ namespace ClothShopView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void TextileToolStripMenuItem_Click(object sender, EventArgs e) + + private void TextilesStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormTextiles)); if (service is FormTextiles form) @@ -70,7 +76,52 @@ namespace ClothShopView } } - private void clientsToolStripMenuItem_Click(object sender, EventArgs e) + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveTextilesToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + + } + + private void компонентыПоКомпьютерамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportTextileComponents)); + if (service is FormReportTextileComponents form) + { + form.ShowDialog(); + } + + } + + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + + } + + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormClients)); if (service is FormClients form) @@ -78,17 +129,27 @@ namespace ClothShopView form.ShowDialog(); } } - private void ButtonCreateOrder_Click(object sender, EventArgs e) + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) { - var service = - Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) + var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm)); + if (service is ImplementersForm form) { form.ShowDialog(); - LoadData(); } } - private OrderBindingModel CreateBindingModel(int id) + + 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 OrderBindingModel CreateBindingModel(int id, bool isDone = false) { return new OrderBindingModel { @@ -101,12 +162,12 @@ namespace ClothShopView DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }; } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + + private void TakeInWorkButton_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { @@ -120,19 +181,18 @@ namespace ClothShopView catch (Exception ex) { _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + } - private void ButtonOrderReady_Click(object sender, EventArgs e) + + private void ReadyButton_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); @@ -149,14 +209,13 @@ namespace ClothShopView } } } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) + + private void IssuedButton_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", - id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); @@ -170,47 +229,15 @@ namespace ClothShopView catch (Exception ex) { _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + } - private void ButtonRef_Click(object sender, EventArgs e) + + private void RefreshButton_Click(object sender, EventArgs e) { LoadData(); } - - private void ReportComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveTextilesToWordFile(new ReportBindingModel - { - FileName = dialog.FileName - }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, - MessageBoxIcon.Information); - } - } - private void ReportTextileComponentsToolStripMenuItem_Click(object sender, - EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportTextileComponents)); - if (service is FormReportTextileComponents form) - { - form.ShowDialog(); - } - } - private void ReportOrdersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } } } diff --git a/ClothShop/ClothShopView/ImplementerForm.Designer.cs b/ClothShop/ClothShopView/ImplementerForm.Designer.cs new file mode 100644 index 0000000..a31db7e --- /dev/null +++ b/ClothShop/ClothShopView/ImplementerForm.Designer.cs @@ -0,0 +1,162 @@ +namespace ClothShopView +{ + partial class ImplementerForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCancel = new Button(); + buttonSave = new Button(); + PasswordTextBox = new TextBox(); + FIOTextBox = new TextBox(); + labelPassword = new Label(); + labelName = new Label(); + WorkExperienceTextBox = new TextBox(); + QualificationTextBox = new TextBox(); + label1 = new Label(); + label2 = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(395, 161); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += CancelButton_Click; + // + // buttonSave + // + buttonSave.Location = new Point(286, 161); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 16; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // PasswordTextBox + // + PasswordTextBox.Location = new Point(123, 63); + PasswordTextBox.Name = "PasswordTextBox"; + PasswordTextBox.Size = new Size(366, 27); + PasswordTextBox.TabIndex = 15; + // + // FIOTextBox + // + FIOTextBox.Location = new Point(123, 11); + FIOTextBox.Name = "FIOTextBox"; + FIOTextBox.Size = new Size(366, 27); + FIOTextBox.TabIndex = 14; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(16, 64); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(62, 20); + labelPassword.TabIndex = 13; + labelPassword.Text = "Пароль"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 12); + labelName.Name = "labelName"; + labelName.Size = new Size(45, 20); + labelName.TabIndex = 12; + labelName.Text = "ФИО:"; + // + // WorkExperienceTextBox + // + WorkExperienceTextBox.Location = new Point(123, 107); + WorkExperienceTextBox.Name = "WorkExperienceTextBox"; + WorkExperienceTextBox.Size = new Size(115, 27); + WorkExperienceTextBox.TabIndex = 18; + // + // QualificationTextBox + // + QualificationTextBox.Location = new Point(364, 107); + QualificationTextBox.Name = "QualificationTextBox"; + QualificationTextBox.Size = new Size(125, 27); + QualificationTextBox.TabIndex = 19; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(16, 111); + label1.Name = "label1"; + label1.Size = new Size(102, 20); + label1.TabIndex = 20; + label1.Text = "Стаж работы:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(244, 110); + label2.Name = "label2"; + label2.Size = new Size(114, 20); + label2.TabIndex = 21; + label2.Text = "Квалификация:"; + // + // ImplementerForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(522, 220); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(QualificationTextBox); + Controls.Add(WorkExperienceTextBox); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(PasswordTextBox); + Controls.Add(FIOTextBox); + Controls.Add(labelPassword); + Controls.Add(labelName); + Name = "ImplementerForm"; + Text = "ImplementerForm"; + Load += ImplementerForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox PasswordTextBox; + private TextBox FIOTextBox; + private Label labelPassword; + private Label labelName; + private TextBox WorkExperienceTextBox; + private TextBox QualificationTextBox; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/ClothShop/ClothShopView/ImplementerForm.cs b/ClothShop/ClothShopView/ImplementerForm.cs new file mode 100644 index 0000000..42ebeba --- /dev/null +++ b/ClothShop/ClothShopView/ImplementerForm.cs @@ -0,0 +1,109 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.BusinessLogicContracts; +using ClothShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ClothShopView +{ + public partial class ImplementerForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public ImplementerForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementerForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationTextBox.Text = view.Qualification.ToString(); + WorkExperienceTextBox.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = Convert.ToInt32(QualificationTextBox.Text), + WorkExperience = Convert.ToInt32(WorkExperienceTextBox.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, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ClothShop/ClothShopView/ImplementerForm.resx b/ClothShop/ClothShopView/ImplementerForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ClothShop/ClothShopView/ImplementerForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ClothShop/ClothShopView/ImplementersForm.Designer.cs b/ClothShop/ClothShopView/ImplementersForm.Designer.cs new file mode 100644 index 0000000..d483234 --- /dev/null +++ b/ClothShop/ClothShopView/ImplementersForm.Designer.cs @@ -0,0 +1,114 @@ +namespace ClothShopView +{ + partial class ImplementersForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(642, 211); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(120, 39); + buttonRefresh.TabIndex = 14; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(642, 151); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(120, 39); + buttonDelete.TabIndex = 13; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += DeleteButton_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(642, 88); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(120, 39); + buttonUpdate.TabIndex = 12; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ChangeButton_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(642, 28); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(120, 39); + buttonAdd.TabIndex = 11; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += CreateButton_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 1); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(593, 450); + dataGridView.TabIndex = 10; + // + // ImplementersForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "ImplementersForm"; + Text = "ImplementersForm"; + Load += ImplementersForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ClothShop/ClothShopView/ImplementersForm.cs b/ClothShop/ClothShopView/ImplementersForm.cs new file mode 100644 index 0000000..eb613ce --- /dev/null +++ b/ClothShop/ClothShopView/ImplementersForm.cs @@ -0,0 +1,124 @@ +using ClothShopContracts.BindingModels; +using ClothShopContracts.BusinessLogicContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ClothShopView +{ + public partial class ImplementersForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public ImplementersForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementersForm_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["Qualification"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkExperience"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CreateButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ClothShop/ClothShopView/ImplementersForm.resx b/ClothShop/ClothShopView/ImplementersForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ClothShop/ClothShopView/ImplementersForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ClothShop/ClothShopView/Program.cs b/ClothShop/ClothShopView/Program.cs index 760fb94..7631410 100644 --- a/ClothShop/ClothShopView/Program.cs +++ b/ClothShop/ClothShopView/Program.cs @@ -48,6 +48,9 @@ namespace ClothShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -59,6 +62,8 @@ namespace ClothShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();