From 6264822cab58c33ec72c35a05c33cf455a96a210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=9A=D1=80?= =?UTF-8?q?=D1=8E=D0=BA=D0=BE=D0=B2?= Date: Mon, 22 Apr 2024 06:54:28 +0400 Subject: [PATCH] =?UTF-8?q?=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D1=82=D0=BE=20(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ImplementerLogic.cs | 126 +++++++++++++ .../BusinessLogics/OrderLogic.cs | 24 ++- .../BusinessLogics/WorkModeling.cs | 149 +++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 22 +++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 24 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 16 ++ .../SearchModels/ImplementerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 3 + .../StoragesContracts/IImplementerStorage.cs | 27 +++ .../ViewModels/ImplementerViewModel.cs | 28 +++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 16 ++ TypographyDataModels/Models/IOrderModel.cs | 2 + TypographyFileImplement/DataFileSingleton.cs | 8 + .../Implements/ClientStorage.cs | 82 ++++++++ .../Implements/ImplementerStorage.cs | 85 +++++++++ .../Implements/OrderStorage.cs | 23 ++- TypographyFileImplement/Models/Client.cs | 74 ++++++++ TypographyFileImplement/Models/Implementer.cs | 85 +++++++++ TypographyFileImplement/Models/Order.cs | 12 ++ TypographyListImplement/DataListSingleton.cs | 4 + .../Implements/ClientStorage.cs | 99 ++++++++++ .../{ => Implements}/ComponentStorage.cs | 0 .../Implements/ImplementerStorage.cs | 111 +++++++++++ .../{ => Implements}/OrderStorage.cs | 65 ++++++- .../{ => Implements}/PrintedStorage.cs | 0 TypographyListImplement/Models/Client.cs | 51 +++++ .../{ => Models}/Component.cs | 0 TypographyListImplement/Models/Implementer.cs | 60 ++++++ TypographyListImplement/{ => Models}/Order.cs | 9 +- .../{ => Models}/Printed.cs | 0 .../Controllers/ImplementerController.cs | 107 +++++++++++ TypographyRestApi/Program.cs | 3 + .../Implements/ImplementerStorage.cs | 85 +++++++++ .../Implements/OrderStorage.cs | 39 +++- .../Models/Implementer.cs | 66 +++++++ .../Models/Order.cs | 10 +- .../TypographyDatabase.cs | 1 + TypographyView/FormClients.Designer.cs | 2 +- TypographyView/FormClients.cs | 2 +- TypographyView/FormImplementer.Designer.cs | 176 ++++++++++++++++++ TypographyView/FormImplementer.cs | 101 ++++++++++ TypographyView/FormImplementer.resx | 120 ++++++++++++ TypographyView/FormImplementers.Designer.cs | 120 ++++++++++++ TypographyView/FormImplementers.cs | 114 ++++++++++++ TypographyView/FormImplementers.resx | 120 ++++++++++++ TypographyView/FormMain.Designer.cs | 22 ++- TypographyView/FormMain.cs | 20 +- TypographyView/Program.cs | 8 +- 51 files changed, 2305 insertions(+), 36 deletions(-) create mode 100644 TypographyBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 TypographyBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 TypographyContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 TypographyContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 TypographyContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 TypographyContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 TypographyContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 TypographyContracts/ViewModels/ImplementerViewModel.cs create mode 100644 TypographyDataModels/Models/IImplementerModel.cs create mode 100644 TypographyFileImplement/Implements/ClientStorage.cs create mode 100644 TypographyFileImplement/Implements/ImplementerStorage.cs create mode 100644 TypographyFileImplement/Models/Client.cs create mode 100644 TypographyFileImplement/Models/Implementer.cs create mode 100644 TypographyListImplement/Implements/ClientStorage.cs rename TypographyListImplement/{ => Implements}/ComponentStorage.cs (100%) create mode 100644 TypographyListImplement/Implements/ImplementerStorage.cs rename TypographyListImplement/{ => Implements}/OrderStorage.cs (58%) rename TypographyListImplement/{ => Implements}/PrintedStorage.cs (100%) create mode 100644 TypographyListImplement/Models/Client.cs rename TypographyListImplement/{ => Models}/Component.cs (100%) create mode 100644 TypographyListImplement/Models/Implementer.cs rename TypographyListImplement/{ => Models}/Order.cs (80%) rename TypographyListImplement/{ => Models}/Printed.cs (100%) create mode 100644 TypographyRestApi/Controllers/ImplementerController.cs create mode 100644 TypographyShopDatabaseImplements/Implements/ImplementerStorage.cs create mode 100644 TypographyShopDatabaseImplements/Models/Implementer.cs create mode 100644 TypographyView/FormImplementer.Designer.cs create mode 100644 TypographyView/FormImplementer.cs create mode 100644 TypographyView/FormImplementer.resx create mode 100644 TypographyView/FormImplementers.Designer.cs create mode 100644 TypographyView/FormImplementers.cs create mode 100644 TypographyView/FormImplementers.resx diff --git a/TypographyBusinessLogic/BusinessLogics/ImplementerLogic.cs b/TypographyBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..175ce8c --- /dev/null +++ b/TypographyBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,126 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + 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; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FIO:{FIO}.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 List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.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; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.WorkExperience < 0) + { + throw new ArgumentException("Стаж работы не может быть меньше нуля", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть меньше нуля", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs b/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs index bcf03a7..e977771 100644 --- a/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/TypographyBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,6 +17,7 @@ namespace TypographyBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { @@ -36,6 +37,22 @@ namespace TypographyBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } public bool CreateOrder(OrderBindingModel model) { @@ -64,6 +81,8 @@ namespace TypographyBusinessLogic.BusinessLogics _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } + if (element.ImplementerId.HasValue) + model.ImplementerId = element.ImplementerId; OrderStatus oldStatus = model.Status; model.Status = status; if (model.Status == OrderStatus.Выдан) @@ -79,7 +98,10 @@ namespace TypographyBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) diff --git a/TypographyBusinessLogic/BusinessLogics/WorkModeling.cs b/TypographyBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..f5f8969 --- /dev/null +++ b/TypographyBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,149 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Enums; + +namespace TypographyBusinessLogic.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 + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + 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/TypographyContracts/BindingModels/ImplementerBindingModel.cs b/TypographyContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..f9ba2ad --- /dev/null +++ b/TypographyContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/TypographyContracts/BindingModels/OrderBindingModel.cs b/TypographyContracts/BindingModels/OrderBindingModel.cs index 7f8e468..96dce44 100644 --- a/TypographyContracts/BindingModels/OrderBindingModel.cs +++ b/TypographyContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace TypographyContracts.BindingModels public int Id { get; set; } public int PrintedId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/TypographyContracts/BusinessLogicsContracts/IImplementerLogic.cs b/TypographyContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..c15ed80 --- /dev/null +++ b/TypographyContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + 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/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs b/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs index 6105b9a..bf323bd 100644 --- a/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/TypographyContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -13,6 +13,7 @@ namespace TypographyContracts.BusinessLogicsContracts 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/TypographyContracts/BusinessLogicsContracts/IWorkProcess.cs b/TypographyContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..bc9b3dc --- /dev/null +++ b/TypographyContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/TypographyContracts/SearchModels/ImplementerSearchModel.cs b/TypographyContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..67f445e --- /dev/null +++ b/TypographyContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/TypographyContracts/SearchModels/OrderSearchModel.cs b/TypographyContracts/SearchModels/OrderSearchModel.cs index f050363..c7bdf6e 100644 --- a/TypographyContracts/SearchModels/OrderSearchModel.cs +++ b/TypographyContracts/SearchModels/OrderSearchModel.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TypographyDataModels.Enums; namespace TypographyContracts.SearchModels { @@ -12,5 +13,7 @@ namespace TypographyContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/TypographyContracts/StoragesContracts/IImplementerStorage.cs b/TypographyContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..c0b907a --- /dev/null +++ b/TypographyContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; + + +namespace TypographyContracts.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/TypographyContracts/ViewModels/ImplementerViewModel.cs b/TypographyContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..737f44e --- /dev/null +++ b/TypographyContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФМО")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} + diff --git a/TypographyContracts/ViewModels/OrderViewModel.cs b/TypographyContracts/ViewModels/OrderViewModel.cs index 53436fe..ee2e88b 100644 --- a/TypographyContracts/ViewModels/OrderViewModel.cs +++ b/TypographyContracts/ViewModels/OrderViewModel.cs @@ -20,6 +20,9 @@ namespace TypographyContracts.ViewModels public int ClientId { get; set; } [DisplayName("ФИО Клиента")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Implementer's FIO")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/TypographyDataModels/Models/IImplementerModel.cs b/TypographyDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..07126d5 --- /dev/null +++ b/TypographyDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/TypographyDataModels/Models/IOrderModel.cs b/TypographyDataModels/Models/IOrderModel.cs index 5a282aa..096af8f 100644 --- a/TypographyDataModels/Models/IOrderModel.cs +++ b/TypographyDataModels/Models/IOrderModel.cs @@ -10,6 +10,8 @@ namespace TypographyDataModels.Models public interface IOrderModel : IId { int PrintedId { get; } + int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/TypographyFileImplement/DataFileSingleton.cs b/TypographyFileImplement/DataFileSingleton.cs index 53cb395..7e8dc72 100644 --- a/TypographyFileImplement/DataFileSingleton.cs +++ b/TypographyFileImplement/DataFileSingleton.cs @@ -18,10 +18,14 @@ namespace TypographyFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PrintedFileName = "Printed.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 Printeds { get; private set; } + public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -35,12 +39,16 @@ namespace TypographyFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SavePrinteds() => SaveData(Printeds, PrintedFileName, "Printeds", 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(Orders, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Printeds = LoadData(PrintedFileName, "Printed", x => Printed.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Impleneter", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/TypographyFileImplement/Implements/ClientStorage.cs b/TypographyFileImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..b67ba64 --- /dev/null +++ b/TypographyFileImplement/Implements/ClientStorage.cs @@ -0,0 +1,82 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyFileImplement.Models; + + +namespace TypographyFileImplement.Implements +{ + public class ClientStorage : IClientStorage + { + private readonly DataFileSingleton source; + public ClientStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + return source.Clients + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email)) + { + return new(); + } + return source.Clients + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Clients.Select(x => x.GetViewModel).ToList(); + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1; + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + source.Clients.Add(newClient); + source.SaveClients(); + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + source.SaveClients(); + return client?.GetViewModel; + } + + public ClientViewModel? Delete(ClientBindingModel model) + { + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + source.Clients.Remove(client); + source.SaveClients(); + return client?.GetViewModel; + } + } +} \ No newline at end of file diff --git a/TypographyFileImplement/Implements/ImplementerStorage.cs b/TypographyFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..bc6169c --- /dev/null +++ b/TypographyFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyFileImplement.Models; + +namespace TypographyFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + if (model.ImplementerFIO != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} + diff --git a/TypographyFileImplement/Implements/OrderStorage.cs b/TypographyFileImplement/Implements/OrderStorage.cs index 01b69bb..ade42b2 100644 --- a/TypographyFileImplement/Implements/OrderStorage.cs +++ b/TypographyFileImplement/Implements/OrderStorage.cs @@ -21,19 +21,25 @@ namespace TypographyFileImplement.Implements { return null; } + if (model.ImplementerId.HasValue && model.Status != null) + return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Status.Equals(x.Status))?.GetViewModel; + return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null) { return new(); } return source.Orders - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + .Where(x => x.Id == model.Id || + model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || + x.ClientId == model.ClientId || + model.Status.Equals(x.Status)) .Select(x => GetViewModel(x)) - .ToList(); + .ToList(); ; } public List GetFullList() @@ -81,10 +87,15 @@ namespace TypographyFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - var car = source.Printeds.FirstOrDefault(x => x.Id == order.PrintedId); - if (car != null) + var printed = source.Printeds.FirstOrDefault(x => x.Id == order.PrintedId); + if (printed != null) { - viewModel.PrintedName = car.PrintedName; + viewModel.PrintedName = printed.PrintedName; + } + var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); + if (client != null) + { + viewModel.ClientFIO = client.ClientFIO; } return viewModel; } diff --git a/TypographyFileImplement/Models/Client.cs b/TypographyFileImplement/Models/Client.cs new file mode 100644 index 0000000..96ebcec --- /dev/null +++ b/TypographyFileImplement/Models/Client.cs @@ -0,0 +1,74 @@ +using System.Xml.Linq; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyFileImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + + public string ClientFIO { get; private set; } = string.Empty; + + public string Email { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + public static Client? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ClientFIO = element.Element("FIO")!.Value, + Email = element.Element("Email")!.Value, + Password = element.Element("Password")!.Value, + }; + } + + + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("FIO", ClientFIO), + new XElement("Email", Email), + new XElement("Password", Password) + ); + } +} \ No newline at end of file diff --git a/TypographyFileImplement/Models/Implementer.cs b/TypographyFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..f03e591 --- /dev/null +++ b/TypographyFileImplement/Models/Implementer.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("FIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/TypographyFileImplement/Models/Order.cs b/TypographyFileImplement/Models/Order.cs index 437beda..ff43ad8 100644 --- a/TypographyFileImplement/Models/Order.cs +++ b/TypographyFileImplement/Models/Order.cs @@ -15,6 +15,8 @@ namespace TypographyFileImplement.Models { public int Id { get; private set; } public int PrintedId { get; private set; } + public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -30,6 +32,8 @@ namespace TypographyFileImplement.Models { Id = model.Id, PrintedId = model.PrintedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -47,6 +51,8 @@ namespace TypographyFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), PrintedId = Convert.ToInt32(element.Element("PrintedId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -63,11 +69,15 @@ namespace TypographyFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { Id = Id, PrintedId = PrintedId, + ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataFileSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, Status = Status, @@ -78,6 +88,8 @@ namespace TypographyFileImplement.Models new("Order", new XAttribute("Id", Id), new XElement("PrintedId", PrintedId.ToString()), + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", PrintedId.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/TypographyListImplement/DataListSingleton.cs b/TypographyListImplement/DataListSingleton.cs index dd973c4..12260f4 100644 --- a/TypographyListImplement/DataListSingleton.cs +++ b/TypographyListImplement/DataListSingleton.cs @@ -13,11 +13,15 @@ namespace TypographyListImplement public List Components { get; set; } public List Orders { get; set; } public List Printeds { get; set; } + public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Printeds = new List(); + Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/TypographyListImplement/Implements/ClientStorage.cs b/TypographyListImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..06ac947 --- /dev/null +++ b/TypographyListImplement/Implements/ClientStorage.cs @@ -0,0 +1,99 @@ +using TypographyListImplement.Models; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; + +namespace TypographyListImplement.Implements +{ + public class ClientStorage : IClientStorage + { + private readonly DataListSingleton _source; + public ClientStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + foreach (var client in _source.Clients) + { + if ((!string.IsNullOrEmpty(model.Email) && client.Email == model.Email) || (model.Id.HasValue && client.Id == model.Id)) + { + return client.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ClientSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Email)) + { + return result; + } + var client = GetElement(model); + if (client != null) result.Add(client); + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var client in _source.Clients) + { + result.Add(client.GetViewModel); + } + return result; + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + model.Id = 1; + foreach (var client in _source.Clients) + { + if (model.Id <= client.Id) + { + model.Id = client.Id + 1; + } + } + var res = Client.Create(model); + if (res != null) + { + _source.Clients.Add(res); + } + return res?.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + foreach (var client in _source.Clients) + { + if (client.Id == model.Id) + { + client.Update(model); + return client.GetViewModel; + } + } + return null; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + for (int i = 0; i < _source.Clients.Count; ++i) + { + if (_source.Clients[i].Id == model.Id) + { + var element = _source.Clients[i]; + _source.Clients.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/TypographyListImplement/ComponentStorage.cs b/TypographyListImplement/Implements/ComponentStorage.cs similarity index 100% rename from TypographyListImplement/ComponentStorage.cs rename to TypographyListImplement/Implements/ComponentStorage.cs diff --git a/TypographyListImplement/Implements/ImplementerStorage.cs b/TypographyListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..5e767c2 --- /dev/null +++ b/TypographyListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,111 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyListImplement.Models; + +namespace TypographyListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password)) + return x.GetViewModel; + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + List list = new(); + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + list.Add(implementer.GetViewModel); + } + } + } + return list; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + 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 res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/TypographyListImplement/OrderStorage.cs b/TypographyListImplement/Implements/OrderStorage.cs similarity index 58% rename from TypographyListImplement/OrderStorage.cs rename to TypographyListImplement/Implements/OrderStorage.cs index 76bbb6f..98c2bdd 100644 --- a/TypographyListImplement/OrderStorage.cs +++ b/TypographyListImplement/Implements/OrderStorage.cs @@ -34,11 +34,44 @@ namespace TypographyListImplement.Implements { return result; } - foreach (var order in _source.Orders) + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) + foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.ClientId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (model.Status.Equals(order.Status)) + { + result.Add(GetViewModel(order)); + } } } return result; @@ -51,9 +84,15 @@ namespace TypographyListImplement.Implements } foreach (var order in _source.Orders) { - if ( - (model.Id.HasValue && order.Id == model.Id) - ) + if (model.Id.HasValue && order.Id == model.Id) + { + return GetViewModel(order); + } + else if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && model.Status.Equals(order.Status)) + { + return GetViewModel(order); + } + else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId) { return order.GetViewModel; } @@ -106,11 +145,19 @@ namespace TypographyListImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var car in _source.Printeds) + foreach (var printed in _source.Printeds) { - if (car.Id == order.PrintedId) + if (printed.Id == order.PrintedId) { - viewModel.PrintedName = car.PrintedName; + viewModel.PrintedName = printed.PrintedName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; break; } } diff --git a/TypographyListImplement/PrintedStorage.cs b/TypographyListImplement/Implements/PrintedStorage.cs similarity index 100% rename from TypographyListImplement/PrintedStorage.cs rename to TypographyListImplement/Implements/PrintedStorage.cs diff --git a/TypographyListImplement/Models/Client.cs b/TypographyListImplement/Models/Client.cs new file mode 100644 index 0000000..8427214 --- /dev/null +++ b/TypographyListImplement/Models/Client.cs @@ -0,0 +1,51 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyListImplement.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + + public string ClientFIO { get; private set; } = string.Empty; + + public string Email { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password, + }; + } +} \ No newline at end of file diff --git a/TypographyListImplement/Component.cs b/TypographyListImplement/Models/Component.cs similarity index 100% rename from TypographyListImplement/Component.cs rename to TypographyListImplement/Models/Component.cs diff --git a/TypographyListImplement/Models/Implementer.cs b/TypographyListImplement/Models/Implementer.cs new file mode 100644 index 0000000..7bca867 --- /dev/null +++ b/TypographyListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; + +namespace TypographyListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + 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, + }; + } +} diff --git a/TypographyListImplement/Order.cs b/TypographyListImplement/Models/Order.cs similarity index 80% rename from TypographyListImplement/Order.cs rename to TypographyListImplement/Models/Order.cs index da05a97..703f7a5 100644 --- a/TypographyListImplement/Order.cs +++ b/TypographyListImplement/Models/Order.cs @@ -13,7 +13,8 @@ namespace TypographyListImplement.Models public class Order : IOrderModel { public int PrintedId { get; private set; } - + public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -36,6 +37,8 @@ namespace TypographyListImplement.Models { Id = model.Id, PrintedId = model.PrintedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,11 +60,15 @@ namespace TypographyListImplement.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { PrintedId = PrintedId, + ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, DateCreate = DateCreate, diff --git a/TypographyListImplement/Printed.cs b/TypographyListImplement/Models/Printed.cs similarity index 100% rename from TypographyListImplement/Printed.cs rename to TypographyListImplement/Models/Printed.cs diff --git a/TypographyRestApi/Controllers/ImplementerController.cs b/TypographyRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..f4e4b28 --- /dev/null +++ b/TypographyRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Enums; + +namespace TypographyRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger 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/TypographyRestApi/Program.cs b/TypographyRestApi/Program.cs index 75c4e2d..082b08a 100644 --- a/TypographyRestApi/Program.cs +++ b/TypographyRestApi/Program.cs @@ -15,9 +15,12 @@ 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(); + builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/TypographyShopDatabaseImplements/Implements/ImplementerStorage.cs b/TypographyShopDatabaseImplements/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..af22658 --- /dev/null +++ b/TypographyShopDatabaseImplements/Implements/ImplementerStorage.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDatabaseImplements.Models; +using TypographyContracts.ViewModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.BindingModels; + + +namespace TypographyDatabaseImplements.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new TypographyDatabase(); + if (model.Id.HasValue) return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + if (model.ImplementerFIO != null) return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + using var context = new TypographyDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new TypographyDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new TypographyDatabase(); + 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 TypographyDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new TypographyDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/TypographyShopDatabaseImplements/Implements/OrderStorage.cs b/TypographyShopDatabaseImplements/Implements/OrderStorage.cs index 0961d7c..2ef60e4 100644 --- a/TypographyShopDatabaseImplements/Implements/OrderStorage.cs +++ b/TypographyShopDatabaseImplements/Implements/OrderStorage.cs @@ -17,28 +17,45 @@ namespace TypographyDatabaseImplement.Implements return null; } using var context = new TypographyDatabase(); - return context.Orders.Include(x => x.Printed).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders + .Include(x => x.Printed) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Status == null || model.Status != null && model.Status.Equals(x.Status)) && + (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) || + (model.Id.HasValue && x.Id == model.Id))? + .GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null) { return new(); } using var context = new TypographyDatabase(); return context.Orders - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId) - .Include(x => x.Printed) - .Include(x => x.Client) - .Select(x => x.GetViewModel) - .ToList(); + .Where(x => + x.Id == model.Id || + model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || + x.ClientId == model.ClientId || + model.Status.Equals(x.Status)) + .Include(x => x.Printed) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { using var context = new TypographyDatabase(); - return context.Orders.Include(x => x.Printed).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + return context.Orders + .Include(x => x.Printed) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -51,7 +68,11 @@ namespace TypographyDatabaseImplement.Implements using var context = new TypographyDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Printed).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders + .Include(x => x.Printed) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) diff --git a/TypographyShopDatabaseImplements/Models/Implementer.cs b/TypographyShopDatabaseImplements/Models/Implementer.cs new file mode 100644 index 0000000..6f2a03c --- /dev/null +++ b/TypographyShopDatabaseImplements/Models/Implementer.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using TypographyDatabaseImplement.Models; + +namespace TypographyDatabaseImplements.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + WorkExperience = WorkExperience, + }; + } +} diff --git a/TypographyShopDatabaseImplements/Models/Order.cs b/TypographyShopDatabaseImplements/Models/Order.cs index 5daa1d8..b631eee 100644 --- a/TypographyShopDatabaseImplements/Models/Order.cs +++ b/TypographyShopDatabaseImplements/Models/Order.cs @@ -16,6 +16,7 @@ namespace TypographyDatabaseImplement.Models public int PrintedId { get; set; } [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } [Required] public int Count { get; set; } @@ -33,6 +34,7 @@ namespace TypographyDatabaseImplement.Models public virtual Printed Printed { get; set; } public virtual Client Client { get; set; } + public Implementer? Implementer { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -45,6 +47,7 @@ namespace TypographyDatabaseImplement.Models Id = model.Id, PrintedId = model.PrintedId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -61,6 +64,7 @@ namespace TypographyDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -68,13 +72,15 @@ namespace TypographyDatabaseImplement.Models Id = Id, PrintedId = PrintedId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - PrintedName = Printed.PrintedName, - ClientFIO = Client.ClientFIO + PrintedName = Printed.PrintedName ?? string.Empty, + ClientFIO = Client.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, }; } } \ No newline at end of file diff --git a/TypographyShopDatabaseImplements/TypographyDatabase.cs b/TypographyShopDatabaseImplements/TypographyDatabase.cs index bb96297..08ff139 100644 --- a/TypographyShopDatabaseImplements/TypographyDatabase.cs +++ b/TypographyShopDatabaseImplements/TypographyDatabase.cs @@ -27,5 +27,6 @@ namespace TypographyDatabaseImplements public virtual DbSet PrintedComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/TypographyView/FormClients.Designer.cs b/TypographyView/FormClients.Designer.cs index d4ccc18..4ad3e4d 100644 --- a/TypographyView/FormClients.Designer.cs +++ b/TypographyView/FormClients.Designer.cs @@ -1,4 +1,4 @@ -namespace AutomobilePlantView +namespace TypographyView { partial class FormClients { diff --git a/TypographyView/FormClients.cs b/TypographyView/FormClients.cs index 3152ffa..dc26e4b 100644 --- a/TypographyView/FormClients.cs +++ b/TypographyView/FormClients.cs @@ -2,7 +2,7 @@ using TypographyContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; -namespace AutomobilePlantView +namespace TypographyView { public partial class FormClients : Form { diff --git a/TypographyView/FormImplementer.Designer.cs b/TypographyView/FormImplementer.Designer.cs new file mode 100644 index 0000000..9a3b5ce --- /dev/null +++ b/TypographyView/FormImplementer.Designer.cs @@ -0,0 +1,176 @@ +namespace TypographyView +{ + partial class FormImplementer + { + /// + /// 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(); + textBoxFIO = new TextBox(); + labelFIO = new Label(); + textBoxPassword = new TextBox(); + numericUpDownQualification = new NumericUpDown(); + numericUpDownWorkExpirience = new NumericUpDown(); + labelPassword = new Label(); + labelQualification = new Label(); + labelExpirience = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExpirience).BeginInit(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(392, 167); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(86, 31); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(299, 167); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(86, 31); + buttonSave.TabIndex = 10; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(110, 12); + textBoxFIO.Margin = new Padding(3, 4, 3, 4); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(367, 27); + textBoxFIO.TabIndex = 8; + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(14, 16); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(45, 20); + labelFIO.TabIndex = 6; + labelFIO.Text = "ФИО:"; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(110, 51); + textBoxPassword.Margin = new Padding(3, 4, 3, 4); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(367, 27); + textBoxPassword.TabIndex = 12; + // + // numericUpDownQualification + // + numericUpDownQualification.Location = new Point(110, 89); + numericUpDownQualification.Margin = new Padding(3, 4, 3, 4); + numericUpDownQualification.Name = "numericUpDownQualification"; + numericUpDownQualification.Size = new Size(368, 27); + numericUpDownQualification.TabIndex = 13; + // + // numericUpDownWorkExpirience + // + numericUpDownWorkExpirience.Location = new Point(110, 128); + numericUpDownWorkExpirience.Margin = new Padding(3, 4, 3, 4); + numericUpDownWorkExpirience.Name = "numericUpDownWorkExpirience"; + numericUpDownWorkExpirience.Size = new Size(368, 27); + numericUpDownWorkExpirience.TabIndex = 14; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(14, 55); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(65, 20); + labelPassword.TabIndex = 15; + labelPassword.Text = "Пароль:"; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(14, 92); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(114, 20); + labelQualification.TabIndex = 16; + labelQualification.Text = "Квалификация:"; + labelQualification.TextAlign = ContentAlignment.TopRight; + // + // labelExpirience + // + labelExpirience.AutoSize = true; + labelExpirience.Location = new Point(14, 131); + labelExpirience.Name = "labelExpirience"; + labelExpirience.Size = new Size(46, 20); + labelExpirience.TabIndex = 17; + labelExpirience.Text = "Стаж:"; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(486, 208); + Controls.Add(labelExpirience); + Controls.Add(labelQualification); + Controls.Add(labelPassword); + Controls.Add(numericUpDownWorkExpirience); + Controls.Add(numericUpDownQualification); + Controls.Add(textBoxPassword); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFIO); + Controls.Add(labelFIO); + Margin = new Padding(3, 4, 3, 4); + Name = "FormImplementer"; + Text = "Implementer"; + Load += FormImplementer_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExpirience).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCost; + private TextBox textBoxFIO; + private Label labelCost; + private Label labelFIO; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExpirience; + private Label labelPassword; + private Label labelQualification; + private Label labelExpirience; + } +} \ No newline at end of file diff --git a/TypographyView/FormImplementer.cs b/TypographyView/FormImplementer.cs new file mode 100644 index 0000000..54d1d44 --- /dev/null +++ b/TypographyView/FormImplementer.cs @@ -0,0 +1,101 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.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 TypographyView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение информации исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExpirience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExpirience.Value, + }; + 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 buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TypographyView/FormImplementer.resx b/TypographyView/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TypographyView/FormImplementer.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/TypographyView/FormImplementers.Designer.cs b/TypographyView/FormImplementers.Designer.cs new file mode 100644 index 0000000..22fa93a --- /dev/null +++ b/TypographyView/FormImplementers.Designer.cs @@ -0,0 +1,120 @@ +namespace TypographyView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + 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(775, 140); + buttonRefresh.Margin = new Padding(3, 4, 3, 4); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(133, 31); + buttonRefresh.TabIndex = 9; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(775, 101); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(133, 31); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(775, 63); + buttonUpdate.Margin = new Padding(3, 4, 3, 4); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(133, 31); + buttonUpdate.TabIndex = 7; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(775, 24); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(133, 31); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonCreate_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(7, 8); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(761, 584); + dataGridView.TabIndex = 5; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(914, 600); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormImplementers"; + Text = "Сотрудники"; + Load += FormImplementers_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/TypographyView/FormImplementers.cs b/TypographyView/FormImplementers.cs new file mode 100644 index 0000000..6da5c48 --- /dev/null +++ b/TypographyView/FormImplementers.cs @@ -0,0 +1,114 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TypographyView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TypographyView/FormImplementers.resx b/TypographyView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TypographyView/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TypographyView/FormMain.Designer.cs b/TypographyView/FormMain.Designer.cs index cb9672f..1b96b74 100644 --- a/TypographyView/FormMain.Designer.cs +++ b/TypographyView/FormMain.Designer.cs @@ -33,10 +33,12 @@ компонентыToolStripMenuItem = new ToolStripMenuItem(); изделиеToolStripMenuItem = new ToolStripMenuItem(); клиентыToolStripMenuItem = new ToolStripMenuItem(); + сотрудникиToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + началоРаботыToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); @@ -50,7 +52,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, началоРаботыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1146, 28); @@ -59,7 +61,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem, сотрудникиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -85,6 +87,13 @@ клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; // + // сотрудникиToolStripMenuItem + // + сотрудникиToolStripMenuItem.Name = "сотрудникиToolStripMenuItem"; + сотрудникиToolStripMenuItem.Size = new Size(224, 26); + сотрудникиToolStripMenuItem.Text = "Сотрудники"; + сотрудникиToolStripMenuItem.Click += РаботникиToolStripMenuItem_Click; + // // отчётыToolStripMenuItem // отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -113,6 +122,13 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // + // началоРаботыToolStripMenuItem + // + началоРаботыToolStripMenuItem.Name = "началоРаботыToolStripMenuItem"; + началоРаботыToolStripMenuItem.Size = new Size(131, 24); + началоРаботыToolStripMenuItem.Text = "Начало работы"; + началоРаботыToolStripMenuItem.Click += НачалоРаботыToolStripMenuItem_Click; + // // dataGridView // dataGridView.BackgroundColor = SystemColors.ControlLightLight; @@ -215,5 +231,7 @@ private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem сотрудникиToolStripMenuItem; + private ToolStripMenuItem началоРаботыToolStripMenuItem; } } \ No newline at end of file diff --git a/TypographyView/FormMain.cs b/TypographyView/FormMain.cs index 9862bab..071742f 100644 --- a/TypographyView/FormMain.cs +++ b/TypographyView/FormMain.cs @@ -13,7 +13,6 @@ using Microsoft.Extensions.Logging; using TypographyDataModels.Enums; using AbstractShopView; using TypographyBusinessLogic.BusinessLogics; -using AutomobilePlantView; namespace TypographyView { @@ -22,13 +21,14 @@ namespace TypographyView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -46,6 +46,7 @@ namespace TypographyView dataGridView.DataSource = list; dataGridView.Columns["PrintedId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Orders loading"); @@ -56,6 +57,19 @@ namespace TypographyView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void РаботникиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + private void НачалоРаботыToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormClients)); diff --git a/TypographyView/Program.cs b/TypographyView/Program.cs index b93ee90..be5f358 100644 --- a/TypographyView/Program.cs +++ b/TypographyView/Program.cs @@ -8,7 +8,7 @@ using NLog.Extensions.Logging; using TypographyBusinessLogic.OfficePackage.Implements; using TypographyBusinessLogic.OfficePackage; using AbstractShopView; -using AutomobilePlantView; +using TypographyDatabaseImplements.Implements; namespace TypographyView @@ -42,16 +42,20 @@ namespace TypographyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -63,6 +67,8 @@ namespace TypographyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file