From f50188c620f7d1caeea90104a5001d841234a626 Mon Sep 17 00:00:00 2001 From: "A.Novopoltsev" Date: Sun, 14 May 2023 15:53:24 +0300 Subject: [PATCH] Implementers --- .../BusinessLogic/ImplementerLogic.cs | 129 +++++++++ .../BusinessLogic/OrderLogic.cs | 75 +++-- .../BusinessLogic/WorkModeling.cs | 137 +++++++++ .../BindingModels/ImplementerBindingModel.cs | 22 ++ .../BindingModels/OrderBindingModel.cs | 3 +- .../IImplementerLogic.cs | 24 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 13 + .../SearchModels/ImplementerSearchModel.cs | 17 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 26 ++ .../ViewModels/ImplementerViewModel.cs | 27 ++ .../ViewModels/OrderViewModel.cs | 5 +- .../Models/IImplementerModel.cs | 17 ++ .../Models/IOrderModel.cs | 1 + .../Implements/ImplementerStorage.cs | 122 ++++++++ .../Implements/OrderStorage.cs | 76 ++++- .../20230514113609_ThirdMig.Designer.cs | 261 ++++++++++++++++++ .../Migrations/20230514113609_ThirdMig.cs | 108 ++++++++ .../RenovationWorkDataBaseModelSnapshot.cs | 53 +++- .../Models/Implementer.cs | 70 +++++ .../Models/Order.cs | 9 +- .../RenovationWorkDatabaseImplement.cs | 1 + .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 108 ++++++++ .../Implements/OrderStorage.cs | 60 +++- .../Models/Implementer.cs | 86 ++++++ .../Models/Order.cs | 6 + .../Implements/ImplementerStorage.cs | 131 +++++++++ .../Implements/OrderStorage.cs | 78 +++++- .../Models/DataListSingleton.cs | 2 + .../Models/Implementer.cs | 61 ++++ .../Models/Order.cs | 11 +- .../Controllers/ImplementerController.cs | 103 +++++++ .../RenovationWorkRestApi/Program.cs | 2 + .../FormImplementer.Designer.cs | 165 +++++++++++ .../RenovationWorkView/FormImplementer.cs | 106 +++++++ .../RenovationWorkView/FormImplementer.resx | 120 ++++++++ .../FormImplementers.Designer.cs | 112 ++++++++ .../RenovationWorkView/FormImplementers.cs | 120 ++++++++ .../RenovationWorkView/FormImplementers.resx | 120 ++++++++ .../RenovationWorkView/FormMain.Designer.cs | 36 ++- RenovationWork/RenovationWorkView/FormMain.cs | 50 ++-- RenovationWork/RenovationWorkView/Program.cs | 5 + 44 files changed, 2595 insertions(+), 93 deletions(-) create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/WorkModeling.cs create mode 100644 RenovationWork/RenovationWorkContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 RenovationWork/RenovationWorkContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 RenovationWork/RenovationWorkContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs create mode 100644 RenovationWork/RenovationWorkDataModels/Models/IImplementerModel.cs create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.Designer.cs create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.cs create mode 100644 RenovationWork/RenovationWorkDatabaseImplement/Models/Implementer.cs create mode 100644 RenovationWork/RenovationWorkFileImplement/Implements/ImplementerStorage.cs create mode 100644 RenovationWork/RenovationWorkFileImplement/Models/Implementer.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Implements/ImplementerStorage.cs create mode 100644 RenovationWork/RenovationWorkListImplement/Models/Implementer.cs create mode 100644 RenovationWork/RenovationWorkRestApi/Controllers/ImplementerController.cs create mode 100644 RenovationWork/RenovationWorkView/FormImplementer.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormImplementer.cs create mode 100644 RenovationWork/RenovationWorkView/FormImplementer.resx create mode 100644 RenovationWork/RenovationWorkView/FormImplementers.Designer.cs create mode 100644 RenovationWork/RenovationWorkView/FormImplementers.cs create mode 100644 RenovationWork/RenovationWorkView/FormImplementers.resx diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ImplementerLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..6421d3d --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,129 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.BusinessLogic +{ + 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 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; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update 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 (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/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/OrderLogic.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/OrderLogic.cs index 36402f5..caf29f2 100644 --- a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/OrderLogic.cs @@ -48,22 +48,37 @@ namespace RenovationWorkBusinessLogic.BusinessLogic public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model); + var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); - if (model.Status + 1 != newStatus) + if (vmodel == null) { - _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); - return false; + throw new ArgumentNullException(nameof(model)); + } + + if ((int)vmodel.Status + 1 != (int)newStatus) + { + throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " + + $"Текущий статус: {vmodel.Status} \n" + + $"Планируемый статус: {newStatus} \n" + + $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}"); } model.Status = newStatus; + model.DateCreate = vmodel.DateCreate; - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; + if (model.DateImplement == null) + model.DateImplement = vmodel.DateImplement; + + if (vmodel.ImplementerId.HasValue) + model.ImplementerId = vmodel.ImplementerId; + + model.PackageId = vmodel.PackageId; + model.Sum = vmodel.Sum; + model.Count = vmodel.Count; if (_orderStorage.Update(model) == null) { - model.Status--; + _logger.LogWarning("Update operation failed"); return false; } @@ -78,6 +93,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogic public bool DeliveryOrder(OrderBindingModel model) { + model.DateImplement = DateTime.Now; return StatusUpdate(model, OrderStatus.Готов); } @@ -102,34 +118,51 @@ namespace RenovationWorkBusinessLogic.BusinessLogic return list; } - private void CheckModel(OrderBindingModel model, bool withParams = true) + private bool CheckModel(OrderBindingModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } - if (!withParams) - { - return; - } - - if (model.PackageId < 0) - { - throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.PackageId)); - } - if (model.Count <= 0) { - throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); } if (model.Sum <= 0) { - throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateCreate > model.DateImplement) + { + throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); } - _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. PackageId: { PackageId}", model.Id, model.Sum, model.PackageId); + return true; + } + + 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; } } } diff --git a/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/WorkModeling.cs b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..1fb9e05 --- /dev/null +++ b/RenovationWork/RenovationWorkBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,137 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkBusinessLogic.BusinessLogic +{ + 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 { Statuses = new() { OrderStatus.Принят, 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, orders); + + 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.DeliveryOrder(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, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.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.DeliveryOrder(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/RenovationWork/RenovationWorkContracts/BindingModels/ImplementerBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..2c8d697 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs b/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs index 90eb57c..a8428e3 100644 --- a/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs +++ b/RenovationWork/RenovationWorkContracts/BindingModels/OrderBindingModel.cs @@ -10,9 +10,10 @@ namespace RenovationWorkContracts.BindingModels { public class OrderBindingModel : IOrderModel { - public string PackageName { get; set; } + public string PackageName { get; set; } = string.Empty; public int PackageId { get; set; } public int Id { get; set; } + public int? ImplementerId { get; set; } public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } diff --git a/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IImplementerLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..072c1bc --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs index 2c9d044..06a259b 100644 --- a/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IWorkProcess.cs b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..be8733a --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/ImplementerSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..a6e4090 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs b/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs index 6520241..fb55ca9 100644 --- a/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs +++ b/RenovationWork/RenovationWorkContracts/SearchModels/OrderSearchModel.cs @@ -3,14 +3,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using RenovationWorkDataModels.Enums; namespace RenovationWorkContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } - public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? ImplementerId { get; set; } + public int? ClientId { get; set; } + public List? Statuses { get; set; } } } diff --git a/RenovationWork/RenovationWorkContracts/StoragesContracts/IImplementerStorage.cs b/RenovationWork/RenovationWorkContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..3be6017 --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..c4d850f --- /dev/null +++ b/RenovationWork/RenovationWorkContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkContracts.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/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs index d2675df..6d22e2b 100644 --- a/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs +++ b/RenovationWork/RenovationWorkContracts/ViewModels/OrderViewModel.cs @@ -13,10 +13,13 @@ namespace RenovationWorkContracts.ViewModels { public int PackageId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Номер")] public int Id { get; set; } - + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Изделие")] public string PackageName { get; set; } = string.Empty; [DisplayName("Клиент")] diff --git a/RenovationWork/RenovationWorkDataModels/Models/IImplementerModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..4bf8c15 --- /dev/null +++ b/RenovationWork/RenovationWorkDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs b/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs index a32ece3..2b1b37b 100644 --- a/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs +++ b/RenovationWork/RenovationWorkDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace RenovationWorkDataModels.Models public interface IOrderModel : IId { string PackageName { get; } + int? ImplementerId { get; } int PackageId { get; } int Count { get; } double Sum { get; } diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Implements/ImplementerStorage.cs b/RenovationWork/RenovationWorkDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..9c69202 --- /dev/null +++ b/RenovationWork/RenovationWorkDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,122 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new RenovationWorkDataBase(); + + 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) + { + using var context = new RenovationWorkDataBase(); + + 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.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + using var context = new RenovationWorkDataBase(); + + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new RenovationWorkDataBase(); + + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new RenovationWorkDataBase(); + + 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 RenovationWorkDataBase(); + + var res = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + } +} diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Implements/OrderStorage.cs b/RenovationWork/RenovationWorkDatabaseImplement/Implements/OrderStorage.cs index ccbdf2c..a271672 100644 --- a/RenovationWork/RenovationWorkDatabaseImplement/Implements/OrderStorage.cs +++ b/RenovationWork/RenovationWorkDatabaseImplement/Implements/OrderStorage.cs @@ -18,7 +18,11 @@ namespace RenovationWorkDatabaseImplement.Implements { using var context = new RenovationWorkDataBase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders + .Include(x => x.Package) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { @@ -40,27 +44,66 @@ namespace RenovationWorkDatabaseImplement.Implements using var context = new RenovationWorkDataBase(); - return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id + ) + ?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue) + if (model.Id.HasValue) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + using var context = new RenovationWorkDataBase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + queryWhere = context.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && + x.DateCreate.Date <= model.DateTo); + } + + else if (model.Statuses != null) + { + queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status)); + } + + else if (model.ClientId.HasValue) + { + queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId); + } + + else { return new(); } - using var context = new RenovationWorkDataBase(); - return context.Orders.Include(x => x.Package) - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + + return queryWhere + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } + public List GetFullList() { using var context = new RenovationWorkDataBase(); - - return context.Orders.Select(x => x.GetViewModel).ToList(); + return context.Orders + .Include(x => x.Package) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -77,14 +120,23 @@ namespace RenovationWorkDatabaseImplement.Implements context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders + .Include(x => x.Package) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id) + ?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new RenovationWorkDataBase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + var order = context.Orders + .Include(x => x.Package) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.Designer.cs b/RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.Designer.cs new file mode 100644 index 0000000..af9ccb1 --- /dev/null +++ b/RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.Designer.cs @@ -0,0 +1,261 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using RenovationWorkDatabaseImplement; + +#nullable disable + +namespace RenovationWorkDatabaseImplement.Migrations +{ + [DbContext(typeof(RenovationWorkDataBase))] + [Migration("20230514113609_ThirdMig")] + partial class ThirdMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.PackageComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PackageId"); + + b.ToTable("PackageComponents"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b => + { + b.HasOne("RenovationWorkDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RenovationWorkDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("RenovationWorkDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.PackageComponent", b => + { + b.HasOne("RenovationWorkDatabaseImplement.Models.Component", "Component") + .WithMany("PackageComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RenovationWorkDatabaseImplement.Models.Package", "Package") + .WithMany("Components") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Component", b => + { + b.Navigation("PackageComponents"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Package", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.cs b/RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.cs new file mode 100644 index 0000000..af54b48 --- /dev/null +++ b/RenovationWork/RenovationWorkDatabaseImplement/Migrations/20230514113609_ThirdMig.cs @@ -0,0 +1,108 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace RenovationWorkDatabaseImplement.Migrations +{ + /// + public partial class ThirdMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + } +} diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Migrations/RenovationWorkDataBaseModelSnapshot.cs b/RenovationWork/RenovationWorkDatabaseImplement/Migrations/RenovationWorkDataBaseModelSnapshot.cs index 76c21c5..5a8d60f 100644 --- a/RenovationWork/RenovationWorkDatabaseImplement/Migrations/RenovationWorkDataBaseModelSnapshot.cs +++ b/RenovationWork/RenovationWorkDatabaseImplement/Migrations/RenovationWorkDataBaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace RenovationWorkDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -75,7 +102,7 @@ namespace RenovationWorkDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -87,6 +114,9 @@ namespace RenovationWorkDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PackageId") .HasColumnType("int"); @@ -104,6 +134,8 @@ namespace RenovationWorkDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PackageId"); b.ToTable("Orders"); @@ -157,9 +189,15 @@ namespace RenovationWorkDatabaseImplement.Migrations modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Order", b => { - b.HasOne("RenovationWorkDatabaseImplement.Models.Client", null) + b.HasOne("RenovationWorkDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RenovationWorkDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); b.HasOne("RenovationWorkDatabaseImplement.Models.Package", "Package") .WithMany("Orders") @@ -167,6 +205,10 @@ namespace RenovationWorkDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + + b.Navigation("Implementer"); + b.Navigation("Package"); }); @@ -199,6 +241,11 @@ namespace RenovationWorkDatabaseImplement.Migrations b.Navigation("PackageComponents"); }); + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("RenovationWorkDatabaseImplement.Models.Package", b => { b.Navigation("Components"); diff --git a/RenovationWork/RenovationWorkDatabaseImplement/Models/Implementer.cs b/RenovationWork/RenovationWorkDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..99d0d99 --- /dev/null +++ b/RenovationWork/RenovationWorkDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,70 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.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 RenovationWorkDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + public int Id { 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, + 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/RenovationWork/RenovationWorkDatabaseImplement/Models/Order.cs b/RenovationWork/RenovationWorkDatabaseImplement/Models/Order.cs index 9e971c7..e6706c5 100644 --- a/RenovationWork/RenovationWorkDatabaseImplement/Models/Order.cs +++ b/RenovationWork/RenovationWorkDatabaseImplement/Models/Order.cs @@ -16,7 +16,9 @@ namespace RenovationWorkDatabaseImplement.Models public int Id { get; private set; } public int PackageId { get; private set; } + public int? ImplementerId { get; private set; } public int ClientId { get; set; } + public Client Client { get; set; } public string PackageName { get; private set; } = string.Empty; @@ -35,6 +37,7 @@ namespace RenovationWorkDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Package Package { get; set; } + public Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -47,6 +50,8 @@ namespace RenovationWorkDatabaseImplement.Models { Id = model.Id, PackageId = model.PackageId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, PackageName = model.PackageName, Count = model.Count, Sum = model.Sum, @@ -82,13 +87,15 @@ namespace RenovationWorkDatabaseImplement.Models Id = Id, PackageId = PackageId, ClientId = ClientId, + ImplementerId = ImplementerId, ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, PackageName = context.Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } diff --git a/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.cs b/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.cs index 79fac4f..1dfc72a 100644 --- a/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.cs +++ b/RenovationWork/RenovationWorkDatabaseImplement/RenovationWorkDatabaseImplement.cs @@ -24,5 +24,6 @@ namespace RenovationWorkDatabaseImplement public virtual DbSet PackageComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/RenovationWork/RenovationWorkFileImplement/DataFileSingleton.cs b/RenovationWork/RenovationWorkFileImplement/DataFileSingleton.cs index 9c4cd67..7f955fe 100644 --- a/RenovationWork/RenovationWorkFileImplement/DataFileSingleton.cs +++ b/RenovationWork/RenovationWorkFileImplement/DataFileSingleton.cs @@ -16,11 +16,13 @@ namespace RenovationWorkFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PackageFileName = "Package.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 Packages { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -35,6 +37,7 @@ namespace RenovationWorkFileImplement public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { @@ -42,6 +45,7 @@ namespace RenovationWorkFileImplement Packages = LoadData(PackageFileName, "Package", x => Package.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/RenovationWork/RenovationWorkFileImplement/Implements/ImplementerStorage.cs b/RenovationWork/RenovationWorkFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..b5e8e3e --- /dev/null +++ b/RenovationWork/RenovationWorkFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,108 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + 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; + } + + 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.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .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; + } + } +} diff --git a/RenovationWork/RenovationWorkFileImplement/Implements/OrderStorage.cs b/RenovationWork/RenovationWorkFileImplement/Implements/OrderStorage.cs index 7c209ff..613d764 100644 --- a/RenovationWork/RenovationWorkFileImplement/Implements/OrderStorage.cs +++ b/RenovationWork/RenovationWorkFileImplement/Implements/OrderStorage.cs @@ -37,21 +37,69 @@ namespace RenovationWorkFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statuses.Contains(x.Status)) + ?.GetViewModel; + } + + if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } + if (!model.Id.HasValue) { return null; } - return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + var package = source + .Packages.FirstOrDefault(x => x.Id == order.PackageId); + + var client = source + .Clients.FirstOrDefault(x => x.Id == order.ClientId); + + if (package != null) + viewModel.PackageName = package.PackageName; + + if (client != null) + viewModel.ClientFIO = client.ClientFIO; + + return viewModel; + } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) - { - return new(); - } - return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => x.GetViewModel).ToList(); + if (model.DateFrom.HasValue) + return source.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)) + .ToList(); + + if (model.ClientId.HasValue && !model.Id.HasValue) + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + + if (model.Id.HasValue) + return source.Orders + .Where(x => x.Id.Equals(model.Id)) + .Select(x => GetViewModel(x)) + .ToList(); + + return new(); } public List GetFullList() diff --git a/RenovationWork/RenovationWorkFileImplement/Models/Implementer.cs b/RenovationWork/RenovationWorkFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..4d99269 --- /dev/null +++ b/RenovationWork/RenovationWorkFileImplement/Models/Implementer.cs @@ -0,0 +1,86 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace RenovationWorkFileImplement.Models +{ + public class Implementer : IImplementerModel + { + 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 int Id { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.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, + 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 + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/RenovationWork/RenovationWorkFileImplement/Models/Order.cs b/RenovationWork/RenovationWorkFileImplement/Models/Order.cs index 635025d..918a6ac 100644 --- a/RenovationWork/RenovationWorkFileImplement/Models/Order.cs +++ b/RenovationWork/RenovationWorkFileImplement/Models/Order.cs @@ -18,6 +18,8 @@ namespace RenovationWorkFileImplement.Models public string PackageName { get; private set; } = string.Empty; public int Count { get; private set; } + public int? ImplementerId { get; set; } + public int ClientId { get; private set; } public double Sum { get; private set; } @@ -40,6 +42,7 @@ namespace RenovationWorkFileImplement.Models Id = model.Id, PackageId = model.PackageId, PackageName = model.PackageName, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -60,6 +63,7 @@ namespace RenovationWorkFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), PackageName = element.Element("PackageName")!.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), @@ -93,6 +97,7 @@ namespace RenovationWorkFileImplement.Models PackageId = PackageId, PackageName = PackageName, Count = Count, + ImplementerId = ImplementerId, Sum = Sum, Status = Status, DateCreate = DateCreate, @@ -105,6 +110,7 @@ namespace RenovationWorkFileImplement.Models new XElement("PackageId", PackageId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())); diff --git a/RenovationWork/RenovationWorkListImplement/Implements/ImplementerStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..f4fca6f --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,131 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.StoragesContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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; + } + + 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(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + 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; + } + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs index 3bcc30b..d3f760b 100644 --- a/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs +++ b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs @@ -45,6 +45,19 @@ namespace RenovationWorkListImplement.Implements { return order.GetViewModel; } + + else if (model.ImplementerId.HasValue && model.Statuses != null && + order.ImplementerId == model.ImplementerId && + model.Statuses.Contains(order.Status)) + { + return GetViewModel(order); + } + + else if (model.ImplementerId.HasValue && + model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } } return null; @@ -54,21 +67,70 @@ namespace RenovationWorkListImplement.Implements { var result = new List(); - if (!model.Id.HasValue) + if (model.DateFrom.HasValue) { - return result; - } - - foreach (var order in _source.Orders) - { - 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.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.ClientId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } + + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + + else if (model.Statuses != null && model.Statuses.Contains(order.Status)) + { + result.Add(GetViewModel(order)); + } } } return result; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var package in _source.Packages) + { + if (package.Id == order.PackageId) + { + viewModel.PackageName = package.PackageName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; + } public List GetFullList() { diff --git a/RenovationWork/RenovationWorkListImplement/Models/DataListSingleton.cs b/RenovationWork/RenovationWorkListImplement/Models/DataListSingleton.cs index 1d00fef..aeb9fdc 100644 --- a/RenovationWork/RenovationWorkListImplement/Models/DataListSingleton.cs +++ b/RenovationWork/RenovationWorkListImplement/Models/DataListSingleton.cs @@ -14,11 +14,13 @@ namespace RenovationWorkListImplement.Models public List Orders { get; set; } public List Packages { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Packages = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/RenovationWork/RenovationWorkListImplement/Models/Implementer.cs b/RenovationWork/RenovationWorkListImplement/Models/Implementer.cs new file mode 100644 index 0000000..08edbe1 --- /dev/null +++ b/RenovationWork/RenovationWorkListImplement/Models/Implementer.cs @@ -0,0 +1,61 @@ +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RenovationWorkListImplement.Models +{ + public class Implementer : IImplementerModel + { + 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 int Id { 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, + WorkExperience = WorkExperience + }; + } +} diff --git a/RenovationWork/RenovationWorkListImplement/Models/Order.cs b/RenovationWork/RenovationWorkListImplement/Models/Order.cs index f6cdbce..a8123a6 100644 --- a/RenovationWork/RenovationWorkListImplement/Models/Order.cs +++ b/RenovationWork/RenovationWorkListImplement/Models/Order.cs @@ -20,6 +20,7 @@ namespace RenovationWorkListImplement.Models public int Count { get; private set; } public double Sum { get; private set; } + public int ClientId { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -42,6 +43,7 @@ namespace RenovationWorkListImplement.Models PackageName = model.PackageName, Count = model.Count, Sum = model.Sum, + ImplementerId = model.ImplementerId, Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement @@ -54,12 +56,7 @@ namespace RenovationWorkListImplement.Models { return; } - PackageId = model.PackageId; - PackageName = model.PackageName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } @@ -72,7 +69,9 @@ namespace RenovationWorkListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerId = ImplementerId }; + public int? ImplementerId { get; private set; } } } diff --git a/RenovationWork/RenovationWorkRestApi/Controllers/ImplementerController.cs b/RenovationWork/RenovationWorkRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..c1e8414 --- /dev/null +++ b/RenovationWork/RenovationWorkRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using Microsoft.AspNetCore.Mvc; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Enums; + +namespace RenovationWorkRestApi.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 + { + Statuses = new() { 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/RenovationWork/RenovationWorkRestApi/Program.cs b/RenovationWork/RenovationWorkRestApi/Program.cs index b436ebd..8de248e 100644 --- a/RenovationWork/RenovationWorkRestApi/Program.cs +++ b/RenovationWork/RenovationWorkRestApi/Program.cs @@ -13,8 +13,10 @@ 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/RenovationWork/RenovationWorkView/FormImplementer.Designer.cs b/RenovationWork/RenovationWorkView/FormImplementer.Designer.cs new file mode 100644 index 0000000..913eec4 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormImplementer.Designer.cs @@ -0,0 +1,165 @@ +namespace RenovationWorkView +{ + 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() + { + this.FIOTextBox = new System.Windows.Forms.TextBox(); + this.PasswordTextBox = new System.Windows.Forms.TextBox(); + this.LabelFIO = new System.Windows.Forms.Label(); + this.LabelPassword = new System.Windows.Forms.Label(); + this.QualificationNumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.WorkExpNumericUpDown = new System.Windows.Forms.NumericUpDown(); + this.LabelWorkExperience = new System.Windows.Forms.Label(); + this.LabelQualification = new System.Windows.Forms.Label(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).BeginInit(); + this.SuspendLayout(); + // + // FIOTextBox + // + this.FIOTextBox.Location = new System.Drawing.Point(112, 12); + this.FIOTextBox.Name = "FIOTextBox"; + this.FIOTextBox.Size = new System.Drawing.Size(170, 23); + this.FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + this.PasswordTextBox.Location = new System.Drawing.Point(112, 49); + this.PasswordTextBox.Name = "PasswordTextBox"; + this.PasswordTextBox.Size = new System.Drawing.Size(170, 23); + this.PasswordTextBox.TabIndex = 1; + // + // LabelFIO + // + this.LabelFIO.AutoSize = true; + this.LabelFIO.Location = new System.Drawing.Point(12, 15); + this.LabelFIO.Name = "LabelFIO"; + this.LabelFIO.Size = new System.Drawing.Size(40, 15); + this.LabelFIO.TabIndex = 2; + this.LabelFIO.Text = "ФИО: "; + // + // LabelPassword + // + this.LabelPassword.AutoSize = true; + this.LabelPassword.Location = new System.Drawing.Point(12, 52); + this.LabelPassword.Name = "LabelPassword"; + this.LabelPassword.Size = new System.Drawing.Size(55, 15); + this.LabelPassword.TabIndex = 3; + this.LabelPassword.Text = "Пароль: "; + // + // QualificationNumericUpDown + // + this.QualificationNumericUpDown.Location = new System.Drawing.Point(112, 131); + this.QualificationNumericUpDown.Name = "QualificationNumericUpDown"; + this.QualificationNumericUpDown.Size = new System.Drawing.Size(170, 23); + this.QualificationNumericUpDown.TabIndex = 4; + // + // WorkExpNumericUpDown + // + this.WorkExpNumericUpDown.Location = new System.Drawing.Point(112, 90); + this.WorkExpNumericUpDown.Name = "WorkExpNumericUpDown"; + this.WorkExpNumericUpDown.Size = new System.Drawing.Size(170, 23); + this.WorkExpNumericUpDown.TabIndex = 5; + // + // LabelWorkExperience + // + this.LabelWorkExperience.AutoSize = true; + this.LabelWorkExperience.Location = new System.Drawing.Point(12, 92); + this.LabelWorkExperience.Name = "LabelWorkExperience"; + this.LabelWorkExperience.Size = new System.Drawing.Size(87, 15); + this.LabelWorkExperience.TabIndex = 6; + this.LabelWorkExperience.Text = "Опыт работы: "; + // + // LabelQualification + // + this.LabelQualification.AutoSize = true; + this.LabelQualification.Location = new System.Drawing.Point(12, 133); + this.LabelQualification.Name = "LabelQualification"; + this.LabelQualification.Size = new System.Drawing.Size(94, 15); + this.LabelQualification.TabIndex = 7; + this.LabelQualification.Text = "Квалификация: "; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(185, 169); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(97, 29); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(82, 169); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(97, 29); + this.ButtonSave.TabIndex = 9; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(306, 214); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.LabelQualification); + this.Controls.Add(this.LabelWorkExperience); + this.Controls.Add(this.WorkExpNumericUpDown); + this.Controls.Add(this.QualificationNumericUpDown); + this.Controls.Add(this.LabelPassword); + this.Controls.Add(this.LabelFIO); + this.Controls.Add(this.PasswordTextBox); + this.Controls.Add(this.FIOTextBox); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.QualificationNumericUpDown)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.WorkExpNumericUpDown)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private Label LabelFIO; + private Label LabelPassword; + private NumericUpDown QualificationNumericUpDown; + private NumericUpDown WorkExpNumericUpDown; + private Label LabelWorkExperience; + private Label LabelQualification; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormImplementer.cs b/RenovationWork/RenovationWorkView/FormImplementer.cs new file mode 100644 index 0000000..9436c82 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormImplementer.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +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 RenovationWorkView +{ + 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 ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(FIOTextBox.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 = (int)QualificationNumericUpDown.Value, + WorkExperience = (int)WorkExpNumericUpDown.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(); + } + + 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) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationNumericUpDown.Value = view.Qualification; + WorkExpNumericUpDown.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/RenovationWork/RenovationWorkView/FormImplementer.resx b/RenovationWork/RenovationWorkView/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/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/RenovationWork/RenovationWorkView/FormImplementers.Designer.cs b/RenovationWork/RenovationWorkView/FormImplementers.Designer.cs new file mode 100644 index 0000000..318d438 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormImplementers.Designer.cs @@ -0,0 +1,112 @@ +namespace RenovationWorkView +{ + 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() + { + this.DataGridView = new System.Windows.Forms.DataGridView(); + this.AddButton = new System.Windows.Forms.Button(); + this.ChangeButton = new System.Windows.Forms.Button(); + this.DeleteButton = new System.Windows.Forms.Button(); + this.UpdateButton = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); + this.SuspendLayout(); + // + // DataGridView + // + this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.DataGridView.Location = new System.Drawing.Point(1, 1); + this.DataGridView.Name = "DataGridView"; + this.DataGridView.RowTemplate.Height = 25; + this.DataGridView.Size = new System.Drawing.Size(632, 448); + this.DataGridView.TabIndex = 0; + // + // AddButton + // + this.AddButton.Location = new System.Drawing.Point(639, 12); + this.AddButton.Name = "AddButton"; + this.AddButton.Size = new System.Drawing.Size(98, 45); + this.AddButton.TabIndex = 1; + this.AddButton.Text = "Добавить"; + this.AddButton.UseVisualStyleBackColor = true; + this.AddButton.Click += new System.EventHandler(this.AddButton_Click); + // + // ChangeButton + // + this.ChangeButton.Location = new System.Drawing.Point(639, 63); + this.ChangeButton.Name = "ChangeButton"; + this.ChangeButton.Size = new System.Drawing.Size(98, 45); + this.ChangeButton.TabIndex = 2; + this.ChangeButton.Text = "Изменить"; + this.ChangeButton.UseVisualStyleBackColor = true; + this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); + // + // DeleteButton + // + this.DeleteButton.Location = new System.Drawing.Point(639, 114); + this.DeleteButton.Name = "DeleteButton"; + this.DeleteButton.Size = new System.Drawing.Size(98, 45); + this.DeleteButton.TabIndex = 3; + this.DeleteButton.Text = "Удалить"; + this.DeleteButton.UseVisualStyleBackColor = true; + this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); + // + // UpdateButton + // + this.UpdateButton.Location = new System.Drawing.Point(639, 165); + this.UpdateButton.Name = "UpdateButton"; + this.UpdateButton.Size = new System.Drawing.Size(98, 45); + this.UpdateButton.TabIndex = 4; + this.UpdateButton.Text = "Обновить"; + this.UpdateButton.UseVisualStyleBackColor = true; + this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(749, 450); + this.Controls.Add(this.UpdateButton); + this.Controls.Add(this.DeleteButton); + this.Controls.Add(this.ChangeButton); + this.Controls.Add(this.AddButton); + this.Controls.Add(this.DataGridView); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); + this.ResumeLayout(false); + } + + #endregion + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWorkView/FormImplementers.cs b/RenovationWork/RenovationWorkView/FormImplementers.cs new file mode 100644 index 0000000..fcc97a5 --- /dev/null +++ b/RenovationWork/RenovationWorkView/FormImplementers.cs @@ -0,0 +1,120 @@ +using Microsoft.Extensions.Logging; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +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 RenovationWorkView +{ + 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 AddButton_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 ChangeButton_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 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 UpdateButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + 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); + } + } + } +} diff --git a/RenovationWork/RenovationWorkView/FormImplementers.resx b/RenovationWork/RenovationWorkView/FormImplementers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/RenovationWork/RenovationWorkView/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/RenovationWork/RenovationWorkView/FormMain.Designer.cs b/RenovationWork/RenovationWorkView/FormMain.Designer.cs index bb6edd4..5f9e5ea 100644 --- a/RenovationWork/RenovationWorkView/FormMain.Designer.cs +++ b/RenovationWork/RenovationWorkView/FormMain.Designer.cs @@ -32,17 +32,19 @@ this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыПоИзделиямToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); - this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -51,7 +53,8 @@ // this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.СправочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.Size = new System.Drawing.Size(865, 24); @@ -63,7 +66,8 @@ this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ИзделияToolStripMenuItem, this.КомпонентыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.СправочникиToolStripMenuItem.Text = "Cправочники"; @@ -82,6 +86,13 @@ this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -113,6 +124,13 @@ this.списокЗаказовToolStripMenuItem.Text = "Список Заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -172,12 +190,12 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // - // клиентыToolStripMenuItem + // исполнителиToolStripMenuItem // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); // // FormMain // @@ -220,5 +238,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/RenovationWork/RenovationWorkView/FormMain.cs b/RenovationWork/RenovationWorkView/FormMain.cs index 57f6dee..c033a0a 100644 --- a/RenovationWork/RenovationWorkView/FormMain.cs +++ b/RenovationWork/RenovationWorkView/FormMain.cs @@ -20,13 +20,15 @@ namespace RenovationWorkView 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, IWorkProcess workProcess, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; LoadData(); } @@ -47,6 +49,8 @@ namespace RenovationWorkView { DataGridView.DataSource = list; DataGridView.Columns["PackageId"].Visible = false; + DataGridView.Columns["ClientId"].Visible = false; + DataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -100,14 +104,7 @@ namespace RenovationWorkView { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - ClientId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ClientId"].Value), - PackageId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["PackageId"].Value), - PackageName = DataGridView.SelectedRows[0].Cells["PackageName"].Value.ToString(), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) @@ -136,14 +133,7 @@ namespace RenovationWorkView { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - ClientId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ClientId"].Value), - PackageId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["PackageId"].Value), - PackageName = DataGridView.SelectedRows[0].Cells["PackageName"].Value.ToString(), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) @@ -172,14 +162,7 @@ namespace RenovationWorkView { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - ClientId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["ClientId"].Value), - PackageId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["PackageId"].Value), - PackageName = DataGridView.SelectedRows[0].Cells["PackageName"].Value.ToString(), - Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Id = id }); if (!operationResult) @@ -235,6 +218,7 @@ namespace RenovationWorkView form.ShowDialog(); } } + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormClients)); @@ -243,5 +227,21 @@ namespace RenovationWorkView form.ShowDialog(); } } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } diff --git a/RenovationWork/RenovationWorkView/Program.cs b/RenovationWork/RenovationWorkView/Program.cs index bf4e0df..14f84a5 100644 --- a/RenovationWork/RenovationWorkView/Program.cs +++ b/RenovationWork/RenovationWorkView/Program.cs @@ -37,16 +37,21 @@ namespace RenovationWorkView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); -- 2.25.1