From db3e3d8d9343095a511ef17227022d838d0dc357 Mon Sep 17 00:00:00 2001 From: "kagbie3nn@mail.ru" Date: Sat, 11 May 2024 16:48:00 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=206=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ImplementerLogic.cs | 115 +++++++++ .../BusinessLogic/OrderLogic.cs | 9 + .../BusinessLogic/WorkModeling.cs | 160 +++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 21 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 24 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 16 ++ .../SearchModels/ImplementerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 26 +++ .../ViewModels/ImplementerViewModel.cs | 26 +++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 19 ++ .../Models/IOrderModel.cs | 1 + .../ComputersShopDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 106 +++++++++ .../Implements/OrderStorage.cs | 20 +- .../20240401150307_InitialCreate.Designer.cs | 43 ++++ .../20240401150307_InitialCreate.cs | 29 +++ .../Models/Implementer.cs | 79 +++++++ .../Models/Order.cs | 7 +- .../DataFileSingleton.cs | 5 + .../Implements/ImplementerStorage.cs | 88 +++++++ .../Implements/OrderStorage.cs | 113 +++++---- .../Models/Implementer.cs | 81 +++++++ .../Models/Order.cs | 59 +++-- .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 120 ++++++++++ .../Implements/OrderStorage.cs | 180 ++++++-------- .../Models/Implementer.cs | 59 +++++ .../Models/Order.cs | 4 + .../Controllers/ImplementerController.cs | 109 +++++++++ ComputersShop/ComputersShopRestApi/Program.cs | 2 + .../FormImplementer.Designer.cs | 163 +++++++++++++ .../ComputersShopView/FormImplementer.cs | 100 ++++++++ .../ComputersShopView/FormImplementer.resx | 120 ++++++++++ .../FormImplementers.Designer.cs | 117 ++++++++++ .../ComputersShopView/FormImplementers.cs | 116 +++++++++ .../ComputersShopView/FormImplementers.resx | 120 ++++++++++ .../ComputersShopView/FormMain.Designer.cs | 221 ++++++++---------- ComputersShop/ComputersShopView/FormMain.cs | 83 +++++-- ComputersShop/ComputersShopView/Program.cs | 5 + 43 files changed, 2265 insertions(+), 329 deletions(-) create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs create mode 100644 ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs create mode 100644 ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs create mode 100644 ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs create mode 100644 ComputersShop/ComputersShopFileImplement/Models/Implementer.cs create mode 100644 ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs create mode 100644 ComputersShop/ComputersShopListImplement/Models/Implementer.cs create mode 100644 ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs create mode 100644 ComputersShop/ComputersShopView/FormImplementer.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormImplementer.cs create mode 100644 ComputersShop/ComputersShopView/FormImplementer.resx create mode 100644 ComputersShop/ComputersShopView/FormImplementers.Designer.cs create mode 100644 ComputersShop/ComputersShopView/FormImplementers.cs create mode 100644 ComputersShop/ComputersShopView/FormImplementers.resx diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..936c396 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,115 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.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. ImplementerFIO:{ImplementerFIO}. Id:{ Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public 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 (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация не может быть меньше 0", nameof(model.Qualification)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("Стаж работы не модет былть меньше 0", nameof(model.WorkExperience)); + } + _logger.LogInformation("Implementer. ImplementerID:{Id}. ImplementerFIO: {ImplementerFIO}. Password: { Password}. Qualification: {Qualification}. WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Такой исполнитель уже существует"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs index 78ee495..c099a5d 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -63,6 +63,15 @@ namespace ComputersShopBusinessLogic.BusinessLogic throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } model.Status = status; + model.DateCreate = element.DateCreate; + model.Sum = element.Sum; + model.Count = element.Count; + model.DateImplement = element.DateImplement; + model.ComputerId = element.ComputerId; + if (element.ImplementerId.HasValue) + { + model.ImplementerId = element.ImplementerId; + } if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); return true; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..20f4172 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,160 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.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 + { + Status = OrderStatus.Принят + }); + + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + // Иммитация работы исполнителя + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + //Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..d4a76f0 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs index 2e9cdd0..b473973 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace ComputersShopContracts.BindingModels public int Id { get; set; } public int ComputerId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..a4a3027 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs index cd57b9f..f71aa0e 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -16,5 +16,6 @@ namespace ComputersShopContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); } } diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..657fcd7 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + // + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..e0e7149 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs index d5f3ec0..f85ef94 100644 --- a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using ComputersShopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace ComputersShopContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..ed5e3bc --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..1b7d5eb --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs index 1433620..c1b6216 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -18,6 +18,9 @@ namespace ComputersShopContracts.ViewModels public int ClientId { get; set; } [DisplayName("Фамилия клиента")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; public string ComputerName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs b/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..bb8c67d --- /dev/null +++ b/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs index d15fdfb..f1b755e 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs @@ -12,6 +12,7 @@ namespace ComputersShopDataModels.Models { int ComputerId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs index cd0a0a8..0b46b63 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs @@ -24,5 +24,6 @@ namespace ComputersShopDatabaseImplement public virtual DbSet ComputerComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..0a710b3 --- /dev/null +++ b/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,106 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new ComputersShopDatabase(); + var element = context.Implementers + .Include(x => x.Orders) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new ComputersShopDatabase(); + if (model.Id.HasValue) + { + return context.Implementers + .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + return context.Implementers + .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + return context.Implementers + .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO))?.GetViewModel; + } + return new(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + using var context = new ComputersShopDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new ComputersShopDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new ComputersShopDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new ComputersShopDatabase(); + var client = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + context.SaveChanges(); + return client.GetViewModel; + } + } +} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs index c00e178..feb62f1 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs @@ -17,7 +17,12 @@ namespace ComputersShopDatabaseImplement.Implements public List GetFullList() { using var context = new ComputersShopDatabase(); - return context.Orders.Include(x => x.Computer).Select(x => x.GetViewModel).ToList(); + return context.Orders + .Include(x => x.Computer) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -31,6 +36,8 @@ namespace ComputersShopDatabaseImplement.Implements { return context.Orders .Include(x => x.Computer) + .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -39,6 +46,8 @@ namespace ComputersShopDatabaseImplement.Implements { return context.Orders .Include(x => x.Computer) + .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -55,7 +64,10 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + .Include(x => x.Implementer) + .FirstOrDefault(x => (model.Status == null || model.Status != null && model.Status == x.Status) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -75,6 +87,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -92,6 +105,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } @@ -104,6 +118,8 @@ namespace ComputersShopDatabaseImplement.Implements { var deletedElement = context.Orders .Include(x => x.Computer) + .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; context.Orders.Remove(order); diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs index 4e4844a..8abfb16 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs @@ -116,6 +116,33 @@ namespace ComputersShopDataBaseImplement.Migrations b.ToTable("ComputerComponents"); }); + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -139,6 +166,9 @@ namespace ComputersShopDataBaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp with time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -151,6 +181,8 @@ namespace ComputersShopDataBaseImplement.Migrations b.HasIndex("ComputerId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -187,9 +219,15 @@ namespace ComputersShopDataBaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ComputersShopDataBaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.Navigation("Client"); b.Navigation("Computer"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => @@ -208,6 +246,11 @@ namespace ComputersShopDataBaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs index 7bd9b7c..32419f4 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs @@ -54,6 +54,21 @@ namespace ComputersShopDataBaseImplement.Migrations { table.PrimaryKey("PK_Computers", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ImplementerFIO = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + WorkExperience = table.Column(type: "integer", nullable: false), + Qualification = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); migrationBuilder.CreateTable( name: "ComputerComponents", @@ -90,6 +105,7 @@ namespace ComputersShopDataBaseImplement.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ComputerId = table.Column(type: "integer", nullable: false), ClientId = table.Column(type: "integer", nullable: false), + ImplementerId = table.Column(type: "integer", nullable: true), Count = table.Column(type: "integer", nullable: false), Sum = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), @@ -111,6 +127,11 @@ namespace ComputersShopDataBaseImplement.Migrations principalTable: "Computers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); }); migrationBuilder.CreateIndex( @@ -132,6 +153,11 @@ namespace ComputersShopDataBaseImplement.Migrations name: "IX_Orders_ComputerId", table: "Orders", column: "ComputerId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); } /// @@ -151,6 +177,9 @@ namespace ComputersShopDataBaseImplement.Migrations migrationBuilder.DropTable( name: "Computers"); + + migrationBuilder.DropTable( + name: "Implementers"); } } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..bbe95fd --- /dev/null +++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,79 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public static Implementer Create(ImplementerViewModel model) + { + return new Implementer + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs index 564238b..89c9d42 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs @@ -19,7 +19,7 @@ namespace ComputersShopDatabaseImplement.Models [Required] public int ComputerId { get; private set; } - + public int? ImplementerId { get; set; } public virtual Computer Computer { get; set; } = new(); @@ -40,6 +40,7 @@ namespace ComputersShopDatabaseImplement.Models [Required] public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } public static Order Create(OrderBindingModel model) { @@ -52,6 +53,7 @@ namespace ComputersShopDatabaseImplement.Models Id = model.Id, ComputerId = model.ComputerId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -68,6 +70,7 @@ namespace ComputersShopDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -76,6 +79,8 @@ namespace ComputersShopDatabaseImplement.Models ComputerId = ComputerId, ClientId = ClientId, ClientFIO = Client.ClientFIO, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ComputerName = Computer.ComputerName, Count = Count, Sum = Sum, diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index 633a59a..6d724d5 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -10,10 +10,12 @@ namespace ComputersShopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ComputerFileName = "Computer.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 Computers { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -28,6 +30,7 @@ namespace ComputersShopFileImplement public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", 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, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { @@ -35,6 +38,8 @@ namespace ComputersShopFileImplement Computers = LoadData(ComputerFileName, "Computer", x => Computer.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/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..abfe9ab --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,88 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + { + return source.Implementers + .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + return source.Implementers + .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel; + } + return new(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers.Where(x => + x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); + } + + public 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 newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs index 8b327b1..f2a66a1 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs @@ -20,50 +20,38 @@ namespace ComputersShopFileImplement.Implements source = DataFileSingleton.GetInstance(); } - public List GetFullList() => source.Orders.Select(x => AttachComputerName(x.GetViewModel)).ToList(); - - public List GetFilteredList(OrderSearchModel model) - { - 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(); - } - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - - var computer = source.Computers.FirstOrDefault(x => x.Id == order.ComputerId); - var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); - - if (computer != null) - { - viewModel.ComputerName = computer.ComputerName; - } - if (client != null) - { - viewModel.ClientFIO = client.ClientFIO; - } - return viewModel; - } public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) { - return new(); + return null; } - return AttachComputerName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); + return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) + { + return source.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)) + .ToList(); + } + if (!model.Id.HasValue && model.ClientId.HasValue) + { + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => GetViewModel(x)) + .ToList(); + } + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + public List GetFullList() + { + return source.Orders.Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -76,7 +64,7 @@ namespace ComputersShopFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return AttachComputerName(newOrder.GetViewModel); + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -88,33 +76,40 @@ namespace ComputersShopFileImplement.Implements } order.Update(model); source.SaveOrders(); - return AttachComputerName(order.GetViewModel); + return GetViewModel(order); } - public OrderViewModel? Delete(OrderBindingModel model) { var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order != null) - { - source.Orders.Remove(order); - source.SaveOrders(); - return AttachComputerName(order.GetViewModel); - } - return null; - } - - private OrderViewModel? AttachComputerName(OrderViewModel? model) - { - if (model == null) + if (order == null) { return null; } - var computer = source.Computers.FirstOrDefault(x => x.Id == model.ComputerId); - if (computer != null) + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var comp in source.Computers) { - model.ComputerName = computer.ComputerName; - } - return model; + if (comp.Id == order.ComputerId) + { + viewModel.ComputerName = comp.ComputerName; + break; + } + } + foreach (var client in source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; } } } diff --git a/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..a777a6f --- /dev/null +++ b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs @@ -0,0 +1,81 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace ComputersShopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public int Id { get; set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification)); + } +} diff --git a/ComputersShop/ComputersShopFileImplement/Models/Order.cs b/ComputersShop/ComputersShopFileImplement/Models/Order.cs index 410edab..c05d8bb 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Order.cs @@ -13,15 +13,24 @@ namespace ComputersShopFileImplement.Models { public class Order : IOrderModel { - public int Id { get; private set; } public int ComputerId { get; private set; } + public int ClientId { get; set; } + + public int? ImplementerId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -32,12 +41,13 @@ namespace ComputersShopFileImplement.Models { Id = model.Id, ComputerId = model.ComputerId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, - ClientId = model.ClientId, + DateImplement = model.DateImplement }; } @@ -47,18 +57,26 @@ namespace ComputersShopFileImplement.Models { return null; } - string dateImplement = element.Element("DateImplement")!.Value; - return new Order() + var order = new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), - Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), - DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + order.DateImplement = dateImpl; + + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; } public void Update(OrderBindingModel? model) @@ -68,29 +86,32 @@ namespace ComputersShopFileImplement.Models return; } Status = model.Status; - if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; + DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { Id = Id, ComputerId = ComputerId, + ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, - ClientId = ClientId, DateCreate = DateCreate, - DateImplement = DateImplement, + DateImplement = DateImplement }; public XElement GetXElement => new("Order", - new XAttribute("Id", Id), - new XElement("ComputerId", ComputerId.ToString()), - new XElement("ClientId", ClientId), - new XElement("Count", Count.ToString()), - new XElement("Sum", Sum.ToString()), - new XElement("Status", Status.ToString()), - new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString())); + new XAttribute("Id", Id), + new XElement("ComputerId", ComputerId), + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); } } diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index 5450b07..b7c65d7 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -9,12 +9,14 @@ namespace ComputersShopListImplement public List Orders { get; set; } public List Computers { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Computers = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..462114a --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,120 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.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) + { + if (model.Id.HasValue) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + return implementer.GetViewModel; + } + } + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO == model.ImplementerFIO && implementer.Password == model.Password) + { + return implementer.GetViewModel; + } + } + } + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public 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 newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs index 71cbf34..9b3e0c9 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -21,57 +21,99 @@ namespace ComputersShopListImplement.Implements public List GetFullList() { var result = new List(); - foreach (var order in _source.Orders) + foreach (var Order in _source.Orders) { - result.Add(AccessIceCreamStorage(order.GetViewModel)); + result.Add(GetViewModel(Order)); } return result; } - public List GetFilteredList(OrderSearchModel - model) + public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (model.DateFrom.HasValue) + foreach (var order in _source.Orders) { - foreach (var order in _source.Orders) + if (order.Id == model.Id) { - if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) - { - result.Add(GetViewModel(order)); - } + return new() { GetViewModel(order) }; + } + else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + else if (model.ClientId.HasValue && order.ClientId == model.ClientId) + { + 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)); - } - } - } return result; } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var Order in _source.Orders) + { + if (model.Id.HasValue && Order.Id == model.Id) + { + return GetViewModel(Order); + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var Order in _source.Orders) + { + if (model.Id <= Order.Id) + { + model.Id = Order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return GetViewModel(newOrder); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + Order.Update(model); + return GetViewModel(Order); + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return GetViewModel(element); + } + } + return null; + } private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var package in _source.Computers) + foreach (var comp in _source.Computers) { - if (package.Id == order.ComputerId) + if (comp.Id == order.ComputerId) { - viewModel.ComputerName = package.ComputerName; + viewModel.ComputerName = comp.ComputerName; break; } } @@ -85,77 +127,5 @@ namespace ComputersShopListImplement.Implements } return viewModel; } - - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - foreach (var order in _source.Orders) - { - if (model.Id.HasValue && order.Id == model.Id) - { - return order.GetViewModel; - } - } - return null; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - foreach (var order in _source.Orders) - { - if (model.Id <= order.Id) - { - model.Id = order.Id + 1; - } - } - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - _source.Orders.Add(newOrder); - return newOrder.GetViewModel; - } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.Update(model); - return order.GetViewModel; - } - } - return null; - } - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; ++i) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - - public OrderViewModel AccessIceCreamStorage(OrderViewModel model) - { - foreach (var iceCream in _source.Computers) - { - if (iceCream.Id == model.ComputerId) - { - model.ComputerName = iceCream.ComputerName; - break; - } - } - return model; - } } } diff --git a/ComputersShop/ComputersShopListImplement/Models/Implementer.cs b/ComputersShop/ComputersShopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..a03a7db --- /dev/null +++ b/ComputersShop/ComputersShopListImplement/Models/Implementer.cs @@ -0,0 +1,59 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public int Id { get; set; } + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/ComputersShop/ComputersShopListImplement/Models/Order.cs b/ComputersShop/ComputersShopListImplement/Models/Order.cs index 2592959..c644ceb 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Order.cs @@ -17,6 +17,7 @@ namespace ComputersShopListImplement.Models public int Count { get; private set; } public double Sum { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public OrderStatus Status { get; private set; } public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } @@ -33,6 +34,7 @@ namespace ComputersShopListImplement.Models ComputerId = model.ComputerId, Count = model.Count, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -52,6 +54,7 @@ namespace ComputersShopListImplement.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -59,6 +62,7 @@ namespace ComputersShopListImplement.Models ComputerId = ComputerId, Count = Count, ClientId = ClientId, + ImplementerId = ImplementerId, Sum = Sum, Status = Status, DateCreate = DateCreate, diff --git a/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs b/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..aac6907 --- /dev/null +++ b/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,109 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace ComputersShopRestApi.Controllers +{ + namespace ComputersShopRestApi.Controllers + { + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + //Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + //ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopRestApi/Program.cs b/ComputersShop/ComputersShopRestApi/Program.cs index 2c94cc2..bf456bc 100644 --- a/ComputersShop/ComputersShopRestApi/Program.cs +++ b/ComputersShop/ComputersShopRestApi/Program.cs @@ -12,10 +12,12 @@ builder.Logging.AddLog4Net("log4net.config"); // Add services to the container. builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddControllers(); diff --git a/ComputersShop/ComputersShopView/FormImplementer.Designer.cs b/ComputersShop/ComputersShopView/FormImplementer.Designer.cs new file mode 100644 index 0000000..64b119a --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementer.Designer.cs @@ -0,0 +1,163 @@ +namespace ComputersShopView +{ + 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.labelFIO = new System.Windows.Forms.Label(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelExperience = new System.Windows.Forms.Label(); + this.labelQualification = new System.Windows.Forms.Label(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxExperience = new System.Windows.Forms.TextBox(); + this.textBoxQualification = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(32, 9); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(45, 20); + this.labelFIO.TabIndex = 0; + this.labelFIO.Text = "ФИО:"; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(32, 50); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(65, 20); + this.labelPassword.TabIndex = 1; + this.labelPassword.Text = "Пароль:"; + // + // labelExperience + // + this.labelExperience.AutoSize = true; + this.labelExperience.Location = new System.Drawing.Point(32, 105); + this.labelExperience.Name = "labelExperience"; + this.labelExperience.Size = new System.Drawing.Size(102, 20); + this.labelExperience.TabIndex = 2; + this.labelExperience.Text = "Стаж работы:"; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(270, 105); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(114, 20); + this.labelQualification.TabIndex = 3; + this.labelQualification.Text = "Квалификация:"; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(102, 6); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(282, 27); + this.textBoxFIO.TabIndex = 4; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(103, 50); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(281, 27); + this.textBoxPassword.TabIndex = 5; + // + // textBoxExperience + // + this.textBoxExperience.Location = new System.Drawing.Point(140, 105); + this.textBoxExperience.Name = "textBoxExperience"; + this.textBoxExperience.Size = new System.Drawing.Size(124, 27); + this.textBoxExperience.TabIndex = 6; + // + // textBoxQualification + // + this.textBoxQualification.Location = new System.Drawing.Point(390, 105); + this.textBoxQualification.Name = "textBoxQualification"; + this.textBoxQualification.Size = new System.Drawing.Size(96, 27); + this.textBoxQualification.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(270, 157); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(392, 157); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(498, 202); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxQualification); + this.Controls.Add(this.textBoxExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelExperience); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelFIO; + private Label labelPassword; + private Label labelExperience; + private Label labelQualification; + private TextBox textBoxFIO; + private TextBox textBoxPassword; + private TextBox textBoxExperience; + private TextBox textBoxQualification; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormImplementer.cs b/ComputersShop/ComputersShopView/FormImplementer.cs new file mode 100644 index 0000000..75d5a66 --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementer.cs @@ -0,0 +1,100 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using ComputersShopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ComputersShopView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxExperience.Text = view.WorkExperience.ToString(); + textBoxPassword.Text = view.Password; + textBoxQualification.Text = view.Qualification.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text), + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormImplementer.resx b/ComputersShop/ComputersShopView/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormImplementers.Designer.cs b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs new file mode 100644 index 0000000..6f6153c --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs @@ -0,0 +1,117 @@ +namespace ComputersShopView +{ + 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.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(564, 450); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(637, 37); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(94, 29); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(637, 100); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(94, 29); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(637, 164); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(94, 29); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(637, 228); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(94, 29); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + 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 buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormImplementers.cs b/ComputersShop/ComputersShopView/FormImplementers.cs new file mode 100644 index 0000000..fa3a46f --- /dev/null +++ b/ComputersShop/ComputersShopView/FormImplementers.cs @@ -0,0 +1,116 @@ +using ComputersShop; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ComputersShopView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ComputersShop/ComputersShopView/FormImplementers.resx b/ComputersShop/ComputersShopView/FormImplementers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ComputersShop/ComputersShopView/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/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index 1c8f65f..b9d6d50 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -28,139 +28,128 @@ /// private void InitializeComponent() { - menuStrip1 = new MenuStrip(); - справочникToolStripMenuItem = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - изделияToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); - списокИзделийToolStripMenuItem = new ToolStripMenuItem(); - изделияПоКомпонентамToolStripMenuItem = new ToolStripMenuItem(); - списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + menuStrip = new MenuStrip(); + dictionaryToolStripMenuItem = new ToolStripMenuItem(); + computerToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + implementersToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + computerListToolStripMenuItem = new ToolStripMenuItem(); + componentsOfComputersToolStripMenuItem = new ToolStripMenuItem(); + listOrderToolStripMenuItem = new ToolStripMenuItem(); + doWorkToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - clientsToolStripMenuItem = new ToolStripMenuItem(); - menuStrip1.SuspendLayout(); + menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // menuStrip1 + // menuStrip // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, отчетыToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(5, 2, 0, 2); - menuStrip1.Size = new Size(1099, 24); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; + menuStrip.Items.AddRange(new ToolStripItem[] { dictionaryToolStripMenuItem, отчётыToolStripMenuItem, doWorkToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1047, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; // - // справочникToolStripMenuItem + // dictionaryToolStripMenuItem // - справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, clientsToolStripMenuItem }); - справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; - справочникToolStripMenuItem.Size = new Size(94, 20); - справочникToolStripMenuItem.Text = "Справочники"; + dictionaryToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, computerToolStripMenuItem, clientsToolStripMenuItem, implementersToolStripMenuItem }); + dictionaryToolStripMenuItem.Name = "dictionaryToolStripMenuItem"; + dictionaryToolStripMenuItem.Size = new Size(94, 20); + dictionaryToolStripMenuItem.Text = "Справочники"; // - // компонентыToolStripMenuItem + // computerToolStripMenuItem // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(180, 22); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + computerToolStripMenuItem.Name = "computerToolStripMenuItem"; + computerToolStripMenuItem.Size = new Size(180, 22); + computerToolStripMenuItem.Text = "Компьютеры"; + computerToolStripMenuItem.Click += ComputersToolStripMenuItem_Click; // - // изделияToolStripMenuItem + // componentsToolStripMenuItem // - изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(180, 22); - изделияToolStripMenuItem.Text = "Изделия"; - изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(180, 22); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // - // отчетыToolStripMenuItem + // clientsToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокИзделийToolStripMenuItem, изделияПоКомпонентамToolStripMenuItem, списокЗаказовToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(180, 22); + clientsToolStripMenuItem.Text = "Клиенты"; + clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // - // списокИзделийToolStripMenuItem + // implementersToolStripMenuItem // - списокИзделийToolStripMenuItem.Name = "списокИзделийToolStripMenuItem"; - списокИзделийToolStripMenuItem.Size = new Size(216, 22); - списокИзделийToolStripMenuItem.Text = "Список изделий"; - списокИзделийToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; + implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + implementersToolStripMenuItem.Size = new Size(180, 22); + implementersToolStripMenuItem.Text = "Исполнители"; + implementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; // - // изделияПоКомпонентамToolStripMenuItem + // отчётыToolStripMenuItem // - изделияПоКомпонентамToolStripMenuItem.Name = "изделияПоКомпонентамToolStripMenuItem"; - изделияПоКомпонентамToolStripMenuItem.Size = new Size(216, 22); - изделияПоКомпонентамToolStripMenuItem.Text = "Изделия по компонентам"; - изделияПоКомпонентамToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { computerListToolStripMenuItem, componentsOfComputersToolStripMenuItem, listOrderToolStripMenuItem }); + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(60, 20); + отчётыToolStripMenuItem.Text = "Отчёты"; // - // списокЗаказовToolStripMenuItem + // computerListToolStripMenuItem // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(216, 22); - списокЗаказовToolStripMenuItem.Text = "Список заказов"; - списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + computerListToolStripMenuItem.Name = "computerListToolStripMenuItem"; + computerListToolStripMenuItem.Size = new Size(243, 22); + computerListToolStripMenuItem.Text = "Список компьютеров"; + computerListToolStripMenuItem.Click += ComponentsDocxToolStripMenuItem_Click; + // + // componentsOfComputersToolStripMenuItem + // + componentsOfComputersToolStripMenuItem.Name = "componentsOfComputersToolStripMenuItem"; + componentsOfComputersToolStripMenuItem.Size = new Size(243, 22); + componentsOfComputersToolStripMenuItem.Text = "Компоненты по компьютерам"; + componentsOfComputersToolStripMenuItem.Click += ComputerComponentsToolStripMenuItem_Click; + // + // listOrderToolStripMenuItem + // + listOrderToolStripMenuItem.Name = "listOrderToolStripMenuItem"; + listOrderToolStripMenuItem.Size = new Size(243, 22); + listOrderToolStripMenuItem.Text = "Список заказов"; + listOrderToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // doWorkToolStripMenuItem + // + doWorkToolStripMenuItem.Name = "doWorkToolStripMenuItem"; + doWorkToolStripMenuItem.Size = new Size(92, 20); + doWorkToolStripMenuItem.Text = "Запуск работ"; + doWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; // // dataGridView // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.BackgroundColor = Color.White; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 23); - dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Location = new Point(12, 27); dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(861, 297); + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(817, 411); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(867, 40); - buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); + buttonCreateOrder.Location = new Point(835, 50); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(216, 22); + buttonCreateOrder.Size = new Size(200, 23); buttonCreateOrder.TabIndex = 2; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += ButtonCreateOrder_Click; // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(867, 91); - buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(216, 22); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(867, 143); - buttonOrderReady.Margin = new Padding(3, 2, 3, 2); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(216, 22); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(867, 191); - buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); + buttonIssuedOrder.Location = new Point(835, 113); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(216, 22); + buttonIssuedOrder.Size = new Size(200, 23); buttonIssuedOrder.TabIndex = 5; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; @@ -168,40 +157,30 @@ // // buttonRef // - buttonRef.Location = new Point(867, 232); - buttonRef.Margin = new Padding(3, 2, 3, 2); + buttonRef.Location = new Point(835, 170); buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(216, 22); + buttonRef.Size = new Size(200, 23); buttonRef.TabIndex = 6; buttonRef.Text = "Обновить список"; buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += ButtonRef_Click; // - // clientsToolStripMenuItem - // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(180, 22); - clientsToolStripMenuItem.Text = "Клиенты"; - // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1099, 320); + ClientSize = new Size(1047, 450); Controls.Add(buttonRef); Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Margin = new Padding(3, 2, 3, 2); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormMain"; - Text = "Компьютерный магазин"; + Text = "Магазин электроники"; Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); @@ -209,20 +188,20 @@ #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem изделияToolStripMenuItem; + private MenuStrip menuStrip; + private ToolStripMenuItem dictionaryToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; - private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem списокИзделийToolStripMenuItem; - private ToolStripMenuItem изделияПоКомпонентамToolStripMenuItem; - private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem computerToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem отчётыToolStripMenuItem; + private ToolStripMenuItem computerListToolStripMenuItem; + private ToolStripMenuItem componentsOfComputersToolStripMenuItem; + private ToolStripMenuItem listOrderToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem implementersToolStripMenuItem; + private ToolStripMenuItem doWorkToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index 26f5003..69e75dd 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -20,19 +20,24 @@ namespace ComputersShopView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportlogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; - _reportLogic = reportLogic; + _reportLogic = reportlogic; + _workProcess = workProcess; } + private void FormMain_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { + _logger.LogInformation("Загрузка заказов"); try { var list = _orderLogic.ReadList(null); @@ -41,8 +46,7 @@ namespace ComputersShopView dataGridView.DataSource = list; dataGridView.Columns["ComputerId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ComputerName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -52,7 +56,7 @@ namespace ComputersShopView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); if (service is FormComponents form) @@ -60,7 +64,7 @@ namespace ComputersShopView form.ShowDialog(); } } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + private void ComputersToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComputers)); if (service is FormComputers form) @@ -82,12 +86,17 @@ namespace ComputersShopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id + Id = id, + ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), + 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()) }); if (!operationResult) { @@ -107,12 +116,17 @@ namespace ComputersShopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id + Id = id, + ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), + 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()) }); if (!operationResult) { @@ -132,18 +146,24 @@ namespace ComputersShopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id + Id = id, + ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), + ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), + 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()) }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - _logger.LogInformation("Заказ No{id} выдан", id); + _logger.LogInformation("Заказ №{id} выдан", id); LoadData(); } catch (Exception ex) @@ -153,11 +173,8 @@ namespace ComputersShopView } } } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e) + + private void ComponentsDocxToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) @@ -167,7 +184,7 @@ namespace ComputersShopView } } - private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) + private void ComputerComponentsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportComputerComponents)); if (service is FormReportComputerComponents form) @@ -176,7 +193,7 @@ namespace ComputersShopView } } - private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); if (service is FormReportOrders form) @@ -184,7 +201,8 @@ namespace ComputersShopView form.ShowDialog(); } } - private void clientsToolStripMenuItem_Click(object sender, EventArgs e) + + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormClients)); if (service is FormClients form) @@ -192,5 +210,28 @@ namespace ComputersShopView form.ShowDialog(); } } + + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(( + Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index d6bf5de..2773da6 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -42,12 +42,15 @@ namespace ComputersShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient() services.AddTransient(); services.AddTransient(); @@ -63,6 +66,8 @@ namespace ComputersShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 116be686c178084615299b0c6efbed3332cded07 Mon Sep 17 00:00:00 2001 From: "kagbie3nn@mail.ru" Date: Sat, 15 Jun 2024 20:01:32 +0400 Subject: [PATCH 2/2] =?UTF-8?q?Revert=20"=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=206=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D0=BD=D0=B0=D1=8F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit db3e3d8d9343095a511ef17227022d838d0dc357. --- .../BusinessLogic/ImplementerLogic.cs | 115 --------- .../BusinessLogic/OrderLogic.cs | 9 - .../BusinessLogic/WorkModeling.cs | 160 ------------- .../BindingModels/ImplementerBindingModel.cs | 21 -- .../BindingModels/OrderBindingModel.cs | 1 - .../IImplementerLogic.cs | 24 -- .../BusinessLogicsContracts/IOrderLogic.cs | 1 - .../BusinessLogicsContracts/IWorkProcess.cs | 16 -- .../SearchModels/ImplementerSearchModel.cs | 15 -- .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 26 --- .../ViewModels/ImplementerViewModel.cs | 26 --- .../ViewModels/OrderViewModel.cs | 3 - .../Models/IImplementerModel.cs | 19 -- .../Models/IOrderModel.cs | 1 - .../ComputersShopDatabase.cs | 1 - .../Implements/ImplementerStorage.cs | 106 --------- .../Implements/OrderStorage.cs | 20 +- .../20240401150307_InitialCreate.Designer.cs | 43 ---- .../20240401150307_InitialCreate.cs | 29 --- .../Models/Implementer.cs | 79 ------- .../Models/Order.cs | 7 +- .../DataFileSingleton.cs | 5 - .../Implements/ImplementerStorage.cs | 88 ------- .../Implements/OrderStorage.cs | 113 ++++----- .../Models/Implementer.cs | 81 ------- .../Models/Order.cs | 71 ++---- .../DataListSingleton.cs | 2 - .../Implements/ImplementerStorage.cs | 120 ---------- .../Implements/OrderStorage.cs | 168 +++++++------ .../Models/Implementer.cs | 59 ----- .../Models/Order.cs | 4 - .../Controllers/ImplementerController.cs | 109 --------- ComputersShop/ComputersShopRestApi/Program.cs | 2 - .../FormImplementer.Designer.cs | 163 ------------- .../ComputersShopView/FormImplementer.cs | 100 -------- .../ComputersShopView/FormImplementer.resx | 120 ---------- .../FormImplementers.Designer.cs | 117 ---------- .../ComputersShopView/FormImplementers.cs | 116 --------- .../ComputersShopView/FormImplementers.resx | 120 ---------- .../ComputersShopView/FormMain.Designer.cs | 221 ++++++++++-------- ComputersShop/ComputersShopView/FormMain.cs | 83 ++----- ComputersShop/ComputersShopView/Program.cs | 5 - 43 files changed, 329 insertions(+), 2265 deletions(-) delete mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs delete mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs delete mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs delete mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs delete mode 100644 ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs delete mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs delete mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs delete mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs delete mode 100644 ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs delete mode 100644 ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs delete mode 100644 ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs delete mode 100644 ComputersShop/ComputersShopFileImplement/Models/Implementer.cs delete mode 100644 ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs delete mode 100644 ComputersShop/ComputersShopListImplement/Models/Implementer.cs delete mode 100644 ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs delete mode 100644 ComputersShop/ComputersShopView/FormImplementer.Designer.cs delete mode 100644 ComputersShop/ComputersShopView/FormImplementer.cs delete mode 100644 ComputersShop/ComputersShopView/FormImplementer.resx delete mode 100644 ComputersShop/ComputersShopView/FormImplementers.Designer.cs delete mode 100644 ComputersShop/ComputersShopView/FormImplementers.cs delete mode 100644 ComputersShop/ComputersShopView/FormImplementers.resx diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs deleted file mode 100644 index 936c396..0000000 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/ImplementerLogic.cs +++ /dev/null @@ -1,115 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopBusinessLogic.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. ImplementerFIO:{ImplementerFIO}. Id:{ Id}", model.ImplementerFIO, model.Id); - var element = _implementerStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - - public List? ReadList(ImplementerSearchModel? model) - { - _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model?.ImplementerFIO, model?.Id); - var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - public 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 (string.IsNullOrEmpty(model.ImplementerFIO)) - { - throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); - } - if (model.Qualification <= 0) - { - throw new ArgumentNullException("Квалификация не может быть меньше 0", nameof(model.Qualification)); - } - if (model.WorkExperience <= 0) - { - throw new ArgumentNullException("Стаж работы не модет былть меньше 0", nameof(model.WorkExperience)); - } - _logger.LogInformation("Implementer. ImplementerID:{Id}. ImplementerFIO: {ImplementerFIO}. Password: { Password}. Qualification: {Qualification}. WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); - var element = _implementerStorage.GetElement(new ImplementerSearchModel - { - ImplementerFIO = model.ImplementerFIO - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Такой исполнитель уже существует"); - } - } - } -} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs index c099a5d..78ee495 100644 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -63,15 +63,6 @@ namespace ComputersShopBusinessLogic.BusinessLogic throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } model.Status = status; - model.DateCreate = element.DateCreate; - model.Sum = element.Sum; - model.Count = element.Count; - model.DateImplement = element.DateImplement; - model.ComputerId = element.ComputerId; - if (element.ImplementerId.HasValue) - { - model.ImplementerId = element.ImplementerId; - } if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); return true; diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs deleted file mode 100644 index 20f4172..0000000 --- a/ComputersShop/ComputersShopBusinessLogic/BusinessLogic/WorkModeling.cs +++ /dev/null @@ -1,160 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BusinessLogicsContracts; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.ViewModels; -using ComputersShopDataModels.Enums; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace ComputersShopBusinessLogic.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 - { - Status = OrderStatus.Принят - }); - - if (orders == null || orders.Count == 0) - { - _logger.LogWarning("DoWork. Orders is null or empty"); - return; - } - - _logger.LogDebug("DoWork for {Count} orders", orders.Count); - foreach (var implementer in implementers) - { - Task.Run(() => WorkerWorkAsync(implementer, orders)); - } - } - - // Иммитация работы исполнителя - private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) - { - if (_orderLogic == null || implementer == null) - { - return; - } - - await RunOrderInWork(implementer); - - await Task.Run(() => - { - foreach (var order in orders) - { - try - { - _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); - - // пытаемся назначить заказ на исполнителя - _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = order.Id, - ImplementerId = implementer.Id - }); - - // делаем работу - Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); - - _orderLogic.FinishOrder(new OrderBindingModel - { - Id = order.Id, - }); - } - // кто-то мог уже перехватить заказ, игнорируем ошибку - catch (InvalidOperationException ex) - { - _logger.LogWarning(ex, "Error try get work"); - } - // заканчиваем выполнение имитации в случае иной ошибки - catch (Exception ex) - { - _logger.LogError(ex, "Error while do work"); - throw; - } - - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); - } - }); - } - - //Ищем заказ, которые уже в работе (вдруг исполнителя прервали) - private async Task RunOrderInWork(ImplementerViewModel implementer) - { - if (_orderLogic == null || implementer == null) - { - return; - } - - try - { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel - { - ImplementerId = implementer.Id, - Status = OrderStatus.Выполняется - })); - - if (runOrder == null) - { - return; - } - - _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); - - // доделываем работу - Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); - - _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); - - _orderLogic.FinishOrder(new OrderBindingModel - { - Id = runOrder.Id - }); - - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); - } - // заказа может не быть, просто игнорируем ошибку - catch (InvalidOperationException ex) - { - _logger.LogWarning(ex, "Error try get work"); - } - // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации - catch (Exception ex) - { - _logger.LogError(ex, "Error while do work"); - throw; - } - } - } -} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs deleted file mode 100644 index d4a76f0..0000000 --- a/ComputersShop/ComputersShopContracts/BindingModels/ImplementerBindingModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs index b473973..2e9cdd0 100644 --- a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -13,7 +13,6 @@ namespace ComputersShopContracts.BindingModels public int Id { get; set; } public int ComputerId { get; set; } public int ClientId { get; set; } - public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs deleted file mode 100644 index a4a3027..0000000 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IImplementerLogic.cs +++ /dev/null @@ -1,24 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs index f71aa0e..cd57b9f 100644 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -16,6 +16,5 @@ namespace ComputersShopContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); - OrderViewModel? ReadElement(OrderSearchModel model); } } diff --git a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs b/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs deleted file mode 100644 index 657fcd7..0000000 --- a/ComputersShop/ComputersShopContracts/BusinessLogicsContracts/IWorkProcess.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopContracts.BusinessLogicsContracts -{ - public interface IWorkProcess - { - // - /// Запуск работ - /// - void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); - } -} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs deleted file mode 100644 index e0e7149..0000000 --- a/ComputersShop/ComputersShopContracts/SearchModels/ImplementerSearchModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopContracts.SearchModels -{ - public class ImplementerSearchModel - { - public int? Id { get; set; } - public string? ImplementerFIO { get; set; } - public string? Password { get; set; } - } -} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs index f85ef94..d5f3ec0 100644 --- a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -1,5 +1,4 @@ -using ComputersShopDataModels.Enums; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,7 +12,5 @@ namespace ComputersShopContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } - public int? ImplementerId { get; set; } - public OrderStatus? Status { get; set; } } } diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs deleted file mode 100644 index ed5e3bc..0000000 --- a/ComputersShop/ComputersShopContracts/StoragesContracts/IImplementerStorage.cs +++ /dev/null @@ -1,26 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs deleted file mode 100644 index 1b7d5eb..0000000 --- a/ComputersShop/ComputersShopContracts/ViewModels/ImplementerViewModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopContracts.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/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs index c1b6216..1433620 100644 --- a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -18,9 +18,6 @@ namespace ComputersShopContracts.ViewModels public int ClientId { get; set; } [DisplayName("Фамилия клиента")] public string ClientFIO { get; set; } = string.Empty; - public int? ImplementerId { get; set; } - [DisplayName("Исполнитель")] - public string ImplementerFIO { get; set; } = string.Empty; public string ComputerName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs b/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs deleted file mode 100644 index bb8c67d..0000000 --- a/ComputersShop/ComputersShopDataModels/Models/IImplementerModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDataModels.Models -{ - public interface IImplementerModel : IId - { - string ImplementerFIO { get; } - - string Password { get; } - - int WorkExperience { get; } - - int Qualification { get; } - } -} diff --git a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs index f1b755e..d15fdfb 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs @@ -12,7 +12,6 @@ namespace ComputersShopDataModels.Models { int ComputerId { get; } int ClientId { get; } - int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs index 0b46b63..cd0a0a8 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/ComputersShopDatabase.cs @@ -24,6 +24,5 @@ namespace ComputersShopDatabaseImplement public virtual DbSet ComputerComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } - public virtual DbSet Implementers { set; get; } } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs deleted file mode 100644 index 0a710b3..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/ImplementerStorage.cs +++ /dev/null @@ -1,106 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; -using ComputersShopContracts.ViewModels; -using ComputersShopDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopDatabaseImplement.Implements -{ - public class ImplementerStorage : IImplementerStorage - { - public ImplementerViewModel? Delete(ImplementerBindingModel model) - { - using var context = new ComputersShopDatabase(); - var element = context.Implementers - .Include(x => x.Orders) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Implementers.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - public ImplementerViewModel? GetElement(ImplementerSearchModel model) - { - using var context = new ComputersShopDatabase(); - if (model.Id.HasValue) - { - return context.Implementers - .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; - } - else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) - { - return context.Implementers - .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel; - } - else if (!string.IsNullOrEmpty(model.ImplementerFIO)) - { - return context.Implementers - .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO))?.GetViewModel; - } - return new(); - } - - public List GetFilteredList(ImplementerSearchModel model) - { - if (model == null) - { - return new(); - } - if (!string.IsNullOrEmpty(model.ImplementerFIO)) - { - using var context = new ComputersShopDatabase(); - return context.Implementers - .Include(x => x.Orders) - .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) - .Select(x => x.GetViewModel) - .ToList(); - } - return new(); - } - - public List GetFullList() - { - using var context = new ComputersShopDatabase(); - return context.Implementers - .Include(x => x.Orders) - .Select(x => x.GetViewModel) - .ToList(); - } - - public ImplementerViewModel? Insert(ImplementerBindingModel model) - { - var newImplementer = Implementer.Create(model); - if (newImplementer == null) - { - return null; - } - using var context = new ComputersShopDatabase(); - context.Implementers.Add(newImplementer); - context.SaveChanges(); - return newImplementer.GetViewModel; - } - - public ImplementerViewModel? Update(ImplementerBindingModel model) - { - using var context = new ComputersShopDatabase(); - var client = context.Implementers.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - client.Update(model); - context.SaveChanges(); - return client.GetViewModel; - } - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs index feb62f1..c00e178 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Implements/OrderStorage.cs @@ -17,12 +17,7 @@ namespace ComputersShopDatabaseImplement.Implements public List GetFullList() { using var context = new ComputersShopDatabase(); - return context.Orders - .Include(x => x.Computer) - .Include(x => x.Client) - .Include(x => x.Implementer) - .Select(x => x.GetViewModel) - .ToList(); + return context.Orders.Include(x => x.Computer).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -36,8 +31,6 @@ namespace ComputersShopDatabaseImplement.Implements { return context.Orders .Include(x => x.Computer) - .Include(x => x.Client) - .Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -46,8 +39,6 @@ namespace ComputersShopDatabaseImplement.Implements { return context.Orders .Include(x => x.Computer) - .Include(x => x.Client) - .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -64,10 +55,7 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) - .Include(x => x.Implementer) - .FirstOrDefault(x => (model.Status == null || model.Status != null && model.Status == x.Status) && - model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || - model.Id.HasValue && x.Id == model.Id) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -87,7 +75,6 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) - .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -105,7 +92,6 @@ namespace ComputersShopDatabaseImplement.Implements return context.Orders .Include(x => x.Computer) .Include(x => x.Client) - .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } @@ -118,8 +104,6 @@ namespace ComputersShopDatabaseImplement.Implements { var deletedElement = context.Orders .Include(x => x.Computer) - .Include(x => x.Client) - .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; context.Orders.Remove(order); diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs index 8abfb16..4e4844a 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.Designer.cs @@ -116,33 +116,6 @@ namespace ComputersShopDataBaseImplement.Migrations b.ToTable("ComputerComponents"); }); - modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("ImplementerFIO") - .IsRequired() - .HasColumnType("text"); - - b.Property("Password") - .IsRequired() - .HasColumnType("text"); - - b.Property("Qualification") - .HasColumnType("integer"); - - b.Property("WorkExperience") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Implementers"); - }); - modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Order", b => { b.Property("Id") @@ -166,9 +139,6 @@ namespace ComputersShopDataBaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp with time zone"); - b.Property("ImplementerId") - .HasColumnType("integer"); - b.Property("Status") .HasColumnType("integer"); @@ -181,8 +151,6 @@ namespace ComputersShopDataBaseImplement.Migrations b.HasIndex("ComputerId"); - b.HasIndex("ImplementerId"); - b.ToTable("Orders"); }); @@ -219,15 +187,9 @@ namespace ComputersShopDataBaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("ComputersShopDataBaseImplement.Models.Implementer", "Implementer") - .WithMany("Orders") - .HasForeignKey("ImplementerId"); - b.Navigation("Client"); b.Navigation("Computer"); - - b.Navigation("Implementer"); }); modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Client", b => @@ -246,11 +208,6 @@ namespace ComputersShopDataBaseImplement.Migrations b.Navigation("Orders"); }); - - modelBuilder.Entity("ComputersShopDataBaseImplement.Models.Implementer", b => - { - b.Navigation("Orders"); - }); #pragma warning restore 612, 618 } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs index 32419f4..7bd9b7c 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Migrations/20240401150307_InitialCreate.cs @@ -54,21 +54,6 @@ namespace ComputersShopDataBaseImplement.Migrations { table.PrimaryKey("PK_Computers", x => x.Id); }); - migrationBuilder.CreateTable( - name: "Implementers", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - ImplementerFIO = table.Column(type: "text", nullable: false), - Password = table.Column(type: "text", nullable: false), - WorkExperience = table.Column(type: "integer", nullable: false), - Qualification = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Implementers", x => x.Id); - }); migrationBuilder.CreateTable( name: "ComputerComponents", @@ -105,7 +90,6 @@ namespace ComputersShopDataBaseImplement.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ComputerId = table.Column(type: "integer", nullable: false), ClientId = table.Column(type: "integer", nullable: false), - ImplementerId = table.Column(type: "integer", nullable: true), Count = table.Column(type: "integer", nullable: false), Sum = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), @@ -127,11 +111,6 @@ namespace ComputersShopDataBaseImplement.Migrations principalTable: "Computers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Orders_Implementers_ImplementerId", - column: x => x.ImplementerId, - principalTable: "Implementers", - principalColumn: "Id"); }); migrationBuilder.CreateIndex( @@ -153,11 +132,6 @@ namespace ComputersShopDataBaseImplement.Migrations name: "IX_Orders_ComputerId", table: "Orders", column: "ComputerId"); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ImplementerId", - table: "Orders", - column: "ImplementerId"); } /// @@ -177,9 +151,6 @@ namespace ComputersShopDataBaseImplement.Migrations migrationBuilder.DropTable( name: "Computers"); - - migrationBuilder.DropTable( - name: "Implementers"); } } } diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs deleted file mode 100644 index bbe95fd..0000000 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Implementer.cs +++ /dev/null @@ -1,79 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ComputersShopDataModels.Models; - -namespace ComputersShopDatabaseImplement.Models -{ - public class Implementer : IImplementerModel - { - public int Id { get; set; } - - [Required] - public string ImplementerFIO { get; set; } = string.Empty; - - [Required] - public string Password { get; set; } = string.Empty; - - [Required] - public int WorkExperience { get; set; } - - [Required] - public int Qualification { get; set; } - - [ForeignKey("ImplementerId")] - public virtual List Orders { get; set; } = new(); - - public static Implementer? Create(ImplementerBindingModel model) - { - if (model == null) - { - return null; - } - return new Implementer() - { - Id = model.Id, - ImplementerFIO = model.ImplementerFIO, - Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification - }; - } - public static Implementer Create(ImplementerViewModel model) - { - return new Implementer - { - Id = model.Id, - ImplementerFIO = model.ImplementerFIO, - Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification - }; - } - public void Update(ImplementerBindingModel model) - { - if (model == null) - { - return; - } - ImplementerFIO = model.ImplementerFIO; - Password = model.Password; - WorkExperience = model.WorkExperience; - Qualification = model.Qualification; - } - public ImplementerViewModel GetViewModel => new() - { - Id = Id, - ImplementerFIO = ImplementerFIO, - Password = Password, - WorkExperience = WorkExperience, - Qualification = Qualification - }; - } -} diff --git a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs index 89c9d42..564238b 100644 --- a/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopDatabaseImplement/Models/Order.cs @@ -19,7 +19,7 @@ namespace ComputersShopDatabaseImplement.Models [Required] public int ComputerId { get; private set; } - public int? ImplementerId { get; set; } + public virtual Computer Computer { get; set; } = new(); @@ -40,7 +40,6 @@ namespace ComputersShopDatabaseImplement.Models [Required] public virtual Client Client { get; set; } - public virtual Implementer? Implementer { get; set; } public static Order Create(OrderBindingModel model) { @@ -53,7 +52,6 @@ namespace ComputersShopDatabaseImplement.Models Id = model.Id, ComputerId = model.ComputerId, ClientId = model.ClientId, - ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -70,7 +68,6 @@ namespace ComputersShopDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -79,8 +76,6 @@ namespace ComputersShopDatabaseImplement.Models ComputerId = ComputerId, ClientId = ClientId, ClientFIO = Client.ClientFIO, - ImplementerId = ImplementerId, - ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, ComputerName = Computer.ComputerName, Count = Count, Sum = Sum, diff --git a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs index 6d724d5..633a59a 100644 --- a/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs +++ b/ComputersShop/ComputersShopFileImplement/DataFileSingleton.cs @@ -10,12 +10,10 @@ namespace ComputersShopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ComputerFileName = "Computer.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 Computers { get; private set; } public List Clients { get; private set; } - public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { @@ -30,7 +28,6 @@ namespace ComputersShopFileImplement public void SaveComputers() => SaveData(Computers, ComputerFileName, "Computers", 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, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { @@ -38,8 +35,6 @@ namespace ComputersShopFileImplement Computers = LoadData(ComputerFileName, "Computer", x => Computer.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/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs deleted file mode 100644 index abfe9ab..0000000 --- a/ComputersShop/ComputersShopFileImplement/Implements/ImplementerStorage.cs +++ /dev/null @@ -1,88 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; -using ComputersShopContracts.ViewModels; -using ComputersShopFileImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopFileImplement.Implements -{ - public class ImplementerStorage : IImplementerStorage - { - private readonly DataFileSingleton source; - public ImplementerStorage() - { - source = DataFileSingleton.GetInstance(); - } - public ImplementerViewModel? Delete(ImplementerBindingModel model) - { - var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); - if (element != null) - { - source.Implementers.Remove(element); - source.SaveImplementers(); - return element.GetViewModel; - } - return null; - } - - public ImplementerViewModel? GetElement(ImplementerSearchModel model) - { - if (model.Id.HasValue) - { - return source.Implementers - .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; - } - else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) - { - return source.Implementers - .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel; - } - return new(); - } - - public List GetFilteredList(ImplementerSearchModel model) - { - if (string.IsNullOrEmpty(model.ImplementerFIO)) - { - return new(); - } - return source.Implementers.Where(x => - x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); - } - - public 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 newImplementer = Implementer.Create(model); - if (newImplementer == null) - { - return null; - } - source.Implementers.Add(newImplementer); - source.SaveImplementers(); - return newImplementer.GetViewModel; - } - - public ImplementerViewModel? Update(ImplementerBindingModel model) - { - var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); - if (implementer == null) - { - return null; - } - implementer.Update(model); - source.SaveImplementers(); - return implementer.GetViewModel; - } - } -} diff --git a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs index f2a66a1..8b327b1 100644 --- a/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopFileImplement/Implements/OrderStorage.cs @@ -20,38 +20,50 @@ namespace ComputersShopFileImplement.Implements source = DataFileSingleton.GetInstance(); } + public List GetFullList() => source.Orders.Select(x => AttachComputerName(x.GetViewModel)).ToList(); + + public List GetFilteredList(OrderSearchModel model) + { + 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(); + } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + + var computer = source.Computers.FirstOrDefault(x => x.Id == order.ComputerId); + var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); + + if (computer != null) + { + viewModel.ComputerName = computer.ComputerName; + } + if (client != null) + { + viewModel.ClientFIO = client.ClientFIO; + } + return viewModel; + } public OrderViewModel? GetElement(OrderSearchModel model) { if (!model.Id.HasValue) { - return null; + return new(); } - return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); - } - - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) - { - return source.Orders - .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo) - .Select(x => GetViewModel(x)) - .ToList(); - } - if (!model.Id.HasValue && model.ClientId.HasValue) - { - return source.Orders - .Where(x => x.ClientId == model.ClientId) - .Select(x => GetViewModel(x)) - .ToList(); - } - var result = GetElement(model); - return result != null ? new() { result } : new(); - } - - public List GetFullList() - { - return source.Orders.Select(x => GetViewModel(x)).ToList(); + return AttachComputerName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); } public OrderViewModel? Insert(OrderBindingModel model) @@ -64,7 +76,7 @@ namespace ComputersShopFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return GetViewModel(newOrder); + return AttachComputerName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -76,40 +88,33 @@ namespace ComputersShopFileImplement.Implements } order.Update(model); source.SaveOrders(); - return GetViewModel(order); + return AttachComputerName(order.GetViewModel); } + public OrderViewModel? Delete(OrderBindingModel model) { var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) + if (order != null) + { + source.Orders.Remove(order); + source.SaveOrders(); + return AttachComputerName(order.GetViewModel); + } + return null; + } + + private OrderViewModel? AttachComputerName(OrderViewModel? model) + { + if (model == null) { return null; } - order.Update(model); - source.SaveOrders(); - return GetViewModel(order); - } - - private OrderViewModel GetViewModel(Order order) - { - var viewModel = order.GetViewModel; - foreach (var comp in source.Computers) + var computer = source.Computers.FirstOrDefault(x => x.Id == model.ComputerId); + if (computer != null) { - if (comp.Id == order.ComputerId) - { - viewModel.ComputerName = comp.ComputerName; - break; - } - } - foreach (var client in source.Clients) - { - if (client.Id == order.ClientId) - { - viewModel.ClientFIO = client.ClientFIO; - break; - } - } - return viewModel; + model.ComputerName = computer.ComputerName; + } + return model; } } } diff --git a/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs b/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs deleted file mode 100644 index a777a6f..0000000 --- a/ComputersShop/ComputersShopFileImplement/Models/Implementer.cs +++ /dev/null @@ -1,81 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.ViewModels; -using ComputersShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Xml.Linq; - -namespace ComputersShopFileImplement.Models -{ - public class Implementer : IImplementerModel - { - public string ImplementerFIO { get; set; } = string.Empty; - - public string Password { get; set; } = string.Empty; - - public int WorkExperience { get; set; } - - public int Qualification { get; set; } - - public int Id { get; set; } - - public static Implementer? Create(ImplementerBindingModel? model) - { - if (model == null) - { - return null; - } - return new Implementer() - { - Id = model.Id, - ImplementerFIO = model.ImplementerFIO, - Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification - }; - } - public static Implementer? Create(XElement element) - { - if (element == null) - { - return null; - } - return new Implementer() - { - Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ImplementerFIO = element.Element("ImplementerFIO")!.Value, - Password = element.Element("Password")!.Value, - WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), - Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) - }; - } - public void Update(ImplementerBindingModel? model) - { - if (model == null) - { - return; - } - ImplementerFIO = model.ImplementerFIO; - Password = model.Password; - WorkExperience = model.WorkExperience; - Qualification = model.Qualification; - } - public ImplementerViewModel GetViewModel => new() - { - Id = Id, - ImplementerFIO = ImplementerFIO, - Password = Password, - WorkExperience = WorkExperience, - Qualification = Qualification - }; - public XElement GetXElement => new("Implementer", - new XAttribute("Id", Id), - new XElement("ImplementerFIO", ImplementerFIO), - new XElement("Password", Password), - new XElement("WorkExperience", WorkExperience), - new XElement("Qualification", Qualification)); - } -} diff --git a/ComputersShop/ComputersShopFileImplement/Models/Order.cs b/ComputersShop/ComputersShopFileImplement/Models/Order.cs index c05d8bb..410edab 100644 --- a/ComputersShop/ComputersShopFileImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopFileImplement/Models/Order.cs @@ -13,23 +13,14 @@ namespace ComputersShopFileImplement.Models { public class Order : IOrderModel { - public int ComputerId { get; private set; } - - public int ClientId { get; set; } - - public int? ImplementerId { get; private set; } - - public int Count { get; private set; } - - public double Sum { get; private set; } - - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - - public DateTime DateCreate { get; private set; } = DateTime.Now; - - public DateTime? DateImplement { get; private set; } - public int Id { get; private set; } + public int ComputerId { get; private set; } + public int ClientId { get; set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -41,13 +32,12 @@ namespace ComputersShopFileImplement.Models { Id = model.Id, ComputerId = model.ComputerId, - ClientId = model.ClientId, - ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ClientId = model.ClientId, }; } @@ -57,26 +47,18 @@ namespace ComputersShopFileImplement.Models { return null; } - var order = new Order() + string dateImplement = element.Element("DateImplement")!.Value; + return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ComputerId = Convert.ToInt32(element.Element("ComputerId")!.Value), - ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), - DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) }; - DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); - order.DateImplement = dateImpl; - - if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) - { - return null; - } - order.Status = status; - return order; } public void Update(OrderBindingModel? model) @@ -86,32 +68,29 @@ namespace ComputersShopFileImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; + if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, ComputerId = ComputerId, - ClientId = ClientId, - ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, + ClientId = ClientId, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, }; public XElement GetXElement => new("Order", - new XAttribute("Id", Id), - new XElement("ComputerId", ComputerId), - new XElement("ClientId", ClientId), - new XElement("ImplementerId", ImplementerId), - new XElement("Count", Count.ToString()), - new XElement("Sum", Sum.ToString()), - new XElement("Status", Status.ToString()), - new XElement("DateCreate", DateCreate.ToString()), - new XElement("DateImplement", DateImplement.ToString())); + new XAttribute("Id", Id), + new XElement("ComputerId", ComputerId.ToString()), + new XElement("ClientId", ClientId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); } } diff --git a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs index b7c65d7..5450b07 100644 --- a/ComputersShop/ComputersShopListImplement/DataListSingleton.cs +++ b/ComputersShop/ComputersShopListImplement/DataListSingleton.cs @@ -9,14 +9,12 @@ namespace ComputersShopListImplement public List Orders { get; set; } public List Computers { get; set; } public List Clients { get; set; } - public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Computers = new List(); Clients = new List(); - Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs deleted file mode 100644 index 462114a..0000000 --- a/ComputersShop/ComputersShopListImplement/Implements/ImplementerStorage.cs +++ /dev/null @@ -1,120 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.StoragesContracts; -using ComputersShopContracts.ViewModels; -using ComputersShopListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopListImplement.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) - { - if (model.Id.HasValue) - { - foreach (var implementer in _source.Implementers) - { - if (implementer.Id == model.Id) - { - return implementer.GetViewModel; - } - } - } - else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) - { - foreach (var implementer in _source.Implementers) - { - if (implementer.ImplementerFIO == model.ImplementerFIO && implementer.Password == model.Password) - { - return implementer.GetViewModel; - } - } - } - - return null; - } - - public List GetFilteredList(ImplementerSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.ImplementerFIO)) - { - return result; - } - foreach (var implementer in _source.Implementers) - { - if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) - { - result.Add(implementer.GetViewModel); - } - } - return result; - } - - public 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 newImplementer = Implementer.Create(model); - if (newImplementer == null) - { - return null; - } - _source.Implementers.Add(newImplementer); - return newImplementer.GetViewModel; - } - - public ImplementerViewModel? Update(ImplementerBindingModel model) - { - foreach (var implementer in _source.Implementers) - { - if (implementer.Id == model.Id) - { - implementer.Update(model); - return implementer.GetViewModel; - } - } - return null; - } - } -} diff --git a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs index 9b3e0c9..71cbf34 100644 --- a/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs +++ b/ComputersShop/ComputersShopListImplement/Implements/OrderStorage.cs @@ -19,101 +19,59 @@ namespace ComputersShopListImplement.Implements _source = DataListSingleton.GetInstance(); } public List GetFullList() - { - var result = new List(); - foreach (var Order in _source.Orders) - { - result.Add(GetViewModel(Order)); - } - return result; - } - public List GetFilteredList(OrderSearchModel model) { var result = new List(); foreach (var order in _source.Orders) { - if (order.Id == model.Id) - { - return new() { GetViewModel(order) }; - } - else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo) - { - result.Add(GetViewModel(order)); - } - else if (model.ClientId.HasValue && order.ClientId == model.ClientId) - { - result.Add(GetViewModel(order)); - } + result.Add(AccessIceCreamStorage(order.GetViewModel)); } return result; } - public OrderViewModel? GetElement(OrderSearchModel model) + public List GetFilteredList(OrderSearchModel + model) { - if (!model.Id.HasValue) + var result = new List(); + if (model.DateFrom.HasValue) { - return null; - } - foreach (var Order in _source.Orders) - { - if (model.Id.HasValue && Order.Id == model.Id) + foreach (var order in _source.Orders) { - return GetViewModel(Order); + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } } } - return null; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - foreach (var Order in _source.Orders) + else if (model.ClientId.HasValue && !model.Id.HasValue) { - if (model.Id <= Order.Id) - { - model.Id = Order.Id + 1; + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } } } - var newOrder = Order.Create(model); - if (newOrder == null) + else if (model.Id.HasValue) { - return null; - } - _source.Orders.Add(newOrder); - return GetViewModel(newOrder); - } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var Order in _source.Orders) - { - if (Order.Id == model.Id) + foreach (var order in _source.Orders) { - Order.Update(model); - return GetViewModel(Order); + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } } - } - return null; - } - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; ++i) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - return GetViewModel(element); } - } - return null; + return result; } private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var comp in _source.Computers) + foreach (var package in _source.Computers) { - if (comp.Id == order.ComputerId) + if (package.Id == order.ComputerId) { - viewModel.ComputerName = comp.ComputerName; + viewModel.ComputerName = package.ComputerName; break; } } @@ -127,5 +85,77 @@ namespace ComputersShopListImplement.Implements } return viewModel; } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public OrderViewModel AccessIceCreamStorage(OrderViewModel model) + { + foreach (var iceCream in _source.Computers) + { + if (iceCream.Id == model.ComputerId) + { + model.ComputerName = iceCream.ComputerName; + break; + } + } + return model; + } } } diff --git a/ComputersShop/ComputersShopListImplement/Models/Implementer.cs b/ComputersShop/ComputersShopListImplement/Models/Implementer.cs deleted file mode 100644 index a03a7db..0000000 --- a/ComputersShop/ComputersShopListImplement/Models/Implementer.cs +++ /dev/null @@ -1,59 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.ViewModels; -using ComputersShopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ComputersShopListImplement.Models -{ - public class Implementer : IImplementerModel - { - public string ImplementerFIO { get; set; } = string.Empty; - - public string Password { get; set; } = string.Empty; - - public int WorkExperience { get; set; } - - public int Qualification { get; set; } - - public int Id { get; set; } - public static Implementer? Create(ImplementerBindingModel? model) - { - if (model == null) - { - return null; - } - return new Implementer() - { - Id = model.Id, - ImplementerFIO = model.ImplementerFIO, - Password = model.Password, - WorkExperience = model.WorkExperience, - Qualification = model.Qualification - }; - } - - public void Update(ImplementerBindingModel? model) - { - if (model == null) - { - return; - } - ImplementerFIO = model.ImplementerFIO; - Password = model.Password; - WorkExperience = model.WorkExperience; - Qualification = model.Qualification; - } - public ImplementerViewModel GetViewModel => new() - { - Id = Id, - ImplementerFIO = ImplementerFIO, - Password = Password, - WorkExperience = WorkExperience, - Qualification = Qualification - }; - } -} diff --git a/ComputersShop/ComputersShopListImplement/Models/Order.cs b/ComputersShop/ComputersShopListImplement/Models/Order.cs index c644ceb..2592959 100644 --- a/ComputersShop/ComputersShopListImplement/Models/Order.cs +++ b/ComputersShop/ComputersShopListImplement/Models/Order.cs @@ -17,7 +17,6 @@ namespace ComputersShopListImplement.Models public int Count { get; private set; } public double Sum { get; private set; } public int ClientId { get; private set; } - public int? ImplementerId { get; private set; } public OrderStatus Status { get; private set; } public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } @@ -34,7 +33,6 @@ namespace ComputersShopListImplement.Models ComputerId = model.ComputerId, Count = model.Count, ClientId = model.ClientId, - ImplementerId = model.ImplementerId, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -54,7 +52,6 @@ namespace ComputersShopListImplement.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; - ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -62,7 +59,6 @@ namespace ComputersShopListImplement.Models ComputerId = ComputerId, Count = Count, ClientId = ClientId, - ImplementerId = ImplementerId, Sum = Sum, Status = Status, DateCreate = DateCreate, diff --git a/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs b/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs deleted file mode 100644 index aac6907..0000000 --- a/ComputersShop/ComputersShopRestApi/Controllers/ImplementerController.cs +++ /dev/null @@ -1,109 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BusinessLogicsContracts; -using ComputersShopContracts.SearchModels; -using ComputersShopContracts.ViewModels; -using Microsoft.AspNetCore.Mvc; - -namespace ComputersShopRestApi.Controllers -{ - namespace ComputersShopRestApi.Controllers - { - [Route("api/[controller]/[action]")] - [ApiController] - public class ImplementerController : Controller - { - private readonly ILogger _logger; - - private readonly IOrderLogic _order; - - private readonly IImplementerLogic _logic; - - public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) - { - _logger = logger; - _order = order; - _logic = logic; - } - - [HttpGet] - public ImplementerViewModel? Login(string login, string password) - { - try - { - return _logic.ReadElement(new ImplementerSearchModel - { - ImplementerFIO = login, - Password = password - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка авторизации сотрудника"); - throw; - } - } - - [HttpGet] - public List? GetNewOrders() - { - try - { - return _order.ReadList(new OrderSearchModel - { - //Status = OrderStatus.Принят - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения новых заказов"); - throw; - } - } - - [HttpGet] - public OrderViewModel? GetImplementerOrder(int implementerId) - { - try - { - return _order.ReadElement(new OrderSearchModel - { - //ImplementerId = implementerId - }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); - throw; - } - } - - [HttpPost] - public void TakeOrderInWork(OrderBindingModel model) - { - try - { - _order.TakeOrderInWork(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); - throw; - } - } - - [HttpPost] - public void FinishOrder(OrderBindingModel model) - { - try - { - _order.FinishOrder(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); - throw; - } - } - } - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShopRestApi/Program.cs b/ComputersShop/ComputersShopRestApi/Program.cs index bf456bc..2c94cc2 100644 --- a/ComputersShop/ComputersShopRestApi/Program.cs +++ b/ComputersShop/ComputersShopRestApi/Program.cs @@ -12,12 +12,10 @@ builder.Logging.AddLog4Net("log4net.config"); // Add services to the container. builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddControllers(); diff --git a/ComputersShop/ComputersShopView/FormImplementer.Designer.cs b/ComputersShop/ComputersShopView/FormImplementer.Designer.cs deleted file mode 100644 index 64b119a..0000000 --- a/ComputersShop/ComputersShopView/FormImplementer.Designer.cs +++ /dev/null @@ -1,163 +0,0 @@ -namespace ComputersShopView -{ - 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.labelFIO = new System.Windows.Forms.Label(); - this.labelPassword = new System.Windows.Forms.Label(); - this.labelExperience = new System.Windows.Forms.Label(); - this.labelQualification = new System.Windows.Forms.Label(); - this.textBoxFIO = new System.Windows.Forms.TextBox(); - this.textBoxPassword = new System.Windows.Forms.TextBox(); - this.textBoxExperience = new System.Windows.Forms.TextBox(); - this.textBoxQualification = new System.Windows.Forms.TextBox(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // labelFIO - // - this.labelFIO.AutoSize = true; - this.labelFIO.Location = new System.Drawing.Point(32, 9); - this.labelFIO.Name = "labelFIO"; - this.labelFIO.Size = new System.Drawing.Size(45, 20); - this.labelFIO.TabIndex = 0; - this.labelFIO.Text = "ФИО:"; - // - // labelPassword - // - this.labelPassword.AutoSize = true; - this.labelPassword.Location = new System.Drawing.Point(32, 50); - this.labelPassword.Name = "labelPassword"; - this.labelPassword.Size = new System.Drawing.Size(65, 20); - this.labelPassword.TabIndex = 1; - this.labelPassword.Text = "Пароль:"; - // - // labelExperience - // - this.labelExperience.AutoSize = true; - this.labelExperience.Location = new System.Drawing.Point(32, 105); - this.labelExperience.Name = "labelExperience"; - this.labelExperience.Size = new System.Drawing.Size(102, 20); - this.labelExperience.TabIndex = 2; - this.labelExperience.Text = "Стаж работы:"; - // - // labelQualification - // - this.labelQualification.AutoSize = true; - this.labelQualification.Location = new System.Drawing.Point(270, 105); - this.labelQualification.Name = "labelQualification"; - this.labelQualification.Size = new System.Drawing.Size(114, 20); - this.labelQualification.TabIndex = 3; - this.labelQualification.Text = "Квалификация:"; - // - // textBoxFIO - // - this.textBoxFIO.Location = new System.Drawing.Point(102, 6); - this.textBoxFIO.Name = "textBoxFIO"; - this.textBoxFIO.Size = new System.Drawing.Size(282, 27); - this.textBoxFIO.TabIndex = 4; - // - // textBoxPassword - // - this.textBoxPassword.Location = new System.Drawing.Point(103, 50); - this.textBoxPassword.Name = "textBoxPassword"; - this.textBoxPassword.Size = new System.Drawing.Size(281, 27); - this.textBoxPassword.TabIndex = 5; - // - // textBoxExperience - // - this.textBoxExperience.Location = new System.Drawing.Point(140, 105); - this.textBoxExperience.Name = "textBoxExperience"; - this.textBoxExperience.Size = new System.Drawing.Size(124, 27); - this.textBoxExperience.TabIndex = 6; - // - // textBoxQualification - // - this.textBoxQualification.Location = new System.Drawing.Point(390, 105); - this.textBoxQualification.Name = "textBoxQualification"; - this.textBoxQualification.Size = new System.Drawing.Size(96, 27); - this.textBoxQualification.TabIndex = 7; - // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(270, 157); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(94, 29); - this.buttonSave.TabIndex = 8; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(392, 157); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(94, 29); - this.buttonCancel.TabIndex = 9; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // FormImplementer - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(498, 202); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.textBoxQualification); - this.Controls.Add(this.textBoxExperience); - this.Controls.Add(this.textBoxPassword); - this.Controls.Add(this.textBoxFIO); - this.Controls.Add(this.labelQualification); - this.Controls.Add(this.labelExperience); - this.Controls.Add(this.labelPassword); - this.Controls.Add(this.labelFIO); - this.Name = "FormImplementer"; - this.Text = "Исполнитель"; - this.Load += new System.EventHandler(this.FormImplementer_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private Label labelFIO; - private Label labelPassword; - private Label labelExperience; - private Label labelQualification; - private TextBox textBoxFIO; - private TextBox textBoxPassword; - private TextBox textBoxExperience; - private TextBox textBoxQualification; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormImplementer.cs b/ComputersShop/ComputersShopView/FormImplementer.cs deleted file mode 100644 index 75d5a66..0000000 --- a/ComputersShop/ComputersShopView/FormImplementer.cs +++ /dev/null @@ -1,100 +0,0 @@ -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BusinessLogicsContracts; -using ComputersShopContracts.SearchModels; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ComputersShopView -{ - public partial class FormImplementer : Form - { - private readonly ILogger _logger; - private readonly IImplementerLogic _logic; - private int? _id; - public int Id { set { _id = value; } } - public FormImplementer(ILogger logger, IImplementerLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - - private void FormImplementer_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - try - { - _logger.LogInformation("Получение исполнителя"); - var view = _logic.ReadElement(new ImplementerSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxFIO.Text = view.ImplementerFIO; - textBoxExperience.Text = view.WorkExperience.ToString(); - textBoxPassword.Text = view.Password; - textBoxQualification.Text = view.Qualification.ToString(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения исполнителя"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxFIO.Text)) - { - MessageBox.Show("Заполните ФИО", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение исполнителя"); - try - { - var model = new ImplementerBindingModel - { - Id = _id ?? 0, - ImplementerFIO = textBoxFIO.Text, - Password = textBoxPassword.Text, - WorkExperience = Convert.ToInt32(textBoxExperience.Text), - Qualification = Convert.ToInt32(textBoxQualification.Text), - }; - var operationResult = _id.HasValue ? _logic.Update(model) : - _logic.Create(model); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка сохранения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} diff --git a/ComputersShop/ComputersShopView/FormImplementer.resx b/ComputersShop/ComputersShopView/FormImplementer.resx deleted file mode 100644 index 1af7de1..0000000 --- a/ComputersShop/ComputersShopView/FormImplementer.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/ComputersShop/ComputersShopView/FormImplementers.Designer.cs b/ComputersShop/ComputersShopView/FormImplementers.Designer.cs deleted file mode 100644 index 6f6153c..0000000 --- a/ComputersShop/ComputersShopView/FormImplementers.Designer.cs +++ /dev/null @@ -1,117 +0,0 @@ -namespace ComputersShopView -{ - 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.buttonAdd = new System.Windows.Forms.Button(); - this.buttonUpd = new System.Windows.Forms.Button(); - this.buttonDel = new System.Windows.Forms.Button(); - this.buttonRef = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // dataGridView - // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; - this.dataGridView.Location = new System.Drawing.Point(0, 0); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(564, 450); - this.dataGridView.TabIndex = 0; - // - // buttonAdd - // - this.buttonAdd.Location = new System.Drawing.Point(637, 37); - this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(94, 29); - this.buttonAdd.TabIndex = 1; - this.buttonAdd.Text = "Добавить"; - this.buttonAdd.UseVisualStyleBackColor = true; - this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); - // - // buttonUpd - // - this.buttonUpd.Location = new System.Drawing.Point(637, 100); - this.buttonUpd.Name = "buttonUpd"; - this.buttonUpd.Size = new System.Drawing.Size(94, 29); - this.buttonUpd.TabIndex = 2; - this.buttonUpd.Text = "Изменить"; - this.buttonUpd.UseVisualStyleBackColor = true; - this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); - // - // buttonDel - // - this.buttonDel.Location = new System.Drawing.Point(637, 164); - this.buttonDel.Name = "buttonDel"; - this.buttonDel.Size = new System.Drawing.Size(94, 29); - this.buttonDel.TabIndex = 3; - this.buttonDel.Text = "Удалить"; - this.buttonDel.UseVisualStyleBackColor = true; - this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); - // - // buttonRef - // - this.buttonRef.Location = new System.Drawing.Point(637, 228); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(94, 29); - this.buttonRef.TabIndex = 4; - this.buttonRef.Text = "Обновить"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // FormImplementers - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonRef); - this.Controls.Add(this.buttonDel); - this.Controls.Add(this.buttonUpd); - this.Controls.Add(this.buttonAdd); - 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 buttonAdd; - private Button buttonUpd; - private Button buttonDel; - private Button buttonRef; - } -} \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormImplementers.cs b/ComputersShop/ComputersShopView/FormImplementers.cs deleted file mode 100644 index fa3a46f..0000000 --- a/ComputersShop/ComputersShopView/FormImplementers.cs +++ /dev/null @@ -1,116 +0,0 @@ -using ComputersShop; -using ComputersShopContracts.BindingModels; -using ComputersShopContracts.BusinessLogicsContracts; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace ComputersShopView -{ - public partial class FormImplementers : Form - { - private readonly ILogger _logger; - private readonly IImplementerLogic _logic; - public FormImplementers(ILogger logger, IImplementerLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - - private void FormImplementers_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка исполнителей"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки исполнителей"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonAdd_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - - private void ButtonUpd_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); - if (service is FormImplementer form) - { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } - - private void ButtonDel_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление исполнителя"); - try - { - if (!_logic.Delete(new ImplementerBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления исполнителя"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - } -} diff --git a/ComputersShop/ComputersShopView/FormImplementers.resx b/ComputersShop/ComputersShopView/FormImplementers.resx deleted file mode 100644 index 1af7de1..0000000 --- a/ComputersShop/ComputersShopView/FormImplementers.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/ComputersShop/ComputersShopView/FormMain.Designer.cs b/ComputersShop/ComputersShopView/FormMain.Designer.cs index b9d6d50..1c8f65f 100644 --- a/ComputersShop/ComputersShopView/FormMain.Designer.cs +++ b/ComputersShop/ComputersShopView/FormMain.Designer.cs @@ -28,128 +28,139 @@ /// private void InitializeComponent() { - menuStrip = new MenuStrip(); - dictionaryToolStripMenuItem = new ToolStripMenuItem(); - computerToolStripMenuItem = new ToolStripMenuItem(); - componentsToolStripMenuItem = new ToolStripMenuItem(); - clientsToolStripMenuItem = new ToolStripMenuItem(); - implementersToolStripMenuItem = new ToolStripMenuItem(); - отчётыToolStripMenuItem = new ToolStripMenuItem(); - computerListToolStripMenuItem = new ToolStripMenuItem(); - componentsOfComputersToolStripMenuItem = new ToolStripMenuItem(); - listOrderToolStripMenuItem = new ToolStripMenuItem(); - doWorkToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1 = new MenuStrip(); + справочникToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + списокИзделийToolStripMenuItem = new ToolStripMenuItem(); + изделияПоКомпонентамToolStripMenuItem = new ToolStripMenuItem(); + списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - menuStrip.SuspendLayout(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // menuStrip + // menuStrip1 // - menuStrip.Items.AddRange(new ToolStripItem[] { dictionaryToolStripMenuItem, отчётыToolStripMenuItem, doWorkToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1047, 24); - menuStrip.TabIndex = 0; - menuStrip.Text = "menuStrip1"; + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(5, 2, 0, 2); + menuStrip1.Size = new Size(1099, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; // - // dictionaryToolStripMenuItem + // справочникToolStripMenuItem // - dictionaryToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, computerToolStripMenuItem, clientsToolStripMenuItem, implementersToolStripMenuItem }); - dictionaryToolStripMenuItem.Name = "dictionaryToolStripMenuItem"; - dictionaryToolStripMenuItem.Size = new Size(94, 20); - dictionaryToolStripMenuItem.Text = "Справочники"; + справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, clientsToolStripMenuItem }); + справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; + справочникToolStripMenuItem.Size = new Size(94, 20); + справочникToolStripMenuItem.Text = "Справочники"; // - // computerToolStripMenuItem + // компонентыToolStripMenuItem // - computerToolStripMenuItem.Name = "computerToolStripMenuItem"; - computerToolStripMenuItem.Size = new Size(180, 22); - computerToolStripMenuItem.Text = "Компьютеры"; - computerToolStripMenuItem.Click += ComputersToolStripMenuItem_Click; + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // - // componentsToolStripMenuItem + // изделияToolStripMenuItem // - componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(180, 22); - componentsToolStripMenuItem.Text = "Компоненты"; - componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(180, 22); + изделияToolStripMenuItem.Text = "Изделия"; + изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; // - // clientsToolStripMenuItem + // отчетыToolStripMenuItem // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(180, 22); - clientsToolStripMenuItem.Text = "Клиенты"; - clientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокИзделийToolStripMenuItem, изделияПоКомпонентамToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; // - // implementersToolStripMenuItem + // списокИзделийToolStripMenuItem // - implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; - implementersToolStripMenuItem.Size = new Size(180, 22); - implementersToolStripMenuItem.Text = "Исполнители"; - implementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + списокИзделийToolStripMenuItem.Name = "списокИзделийToolStripMenuItem"; + списокИзделийToolStripMenuItem.Size = new Size(216, 22); + списокИзделийToolStripMenuItem.Text = "Список изделий"; + списокИзделийToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; // - // отчётыToolStripMenuItem + // изделияПоКомпонентамToolStripMenuItem // - отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { computerListToolStripMenuItem, componentsOfComputersToolStripMenuItem, listOrderToolStripMenuItem }); - отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - отчётыToolStripMenuItem.Size = new Size(60, 20); - отчётыToolStripMenuItem.Text = "Отчёты"; + изделияПоКомпонентамToolStripMenuItem.Name = "изделияПоКомпонентамToolStripMenuItem"; + изделияПоКомпонентамToolStripMenuItem.Size = new Size(216, 22); + изделияПоКомпонентамToolStripMenuItem.Text = "Изделия по компонентам"; + изделияПоКомпонентамToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; // - // computerListToolStripMenuItem + // списокЗаказовToolStripMenuItem // - computerListToolStripMenuItem.Name = "computerListToolStripMenuItem"; - computerListToolStripMenuItem.Size = new Size(243, 22); - computerListToolStripMenuItem.Text = "Список компьютеров"; - computerListToolStripMenuItem.Click += ComponentsDocxToolStripMenuItem_Click; - // - // componentsOfComputersToolStripMenuItem - // - componentsOfComputersToolStripMenuItem.Name = "componentsOfComputersToolStripMenuItem"; - componentsOfComputersToolStripMenuItem.Size = new Size(243, 22); - componentsOfComputersToolStripMenuItem.Text = "Компоненты по компьютерам"; - componentsOfComputersToolStripMenuItem.Click += ComputerComponentsToolStripMenuItem_Click; - // - // listOrderToolStripMenuItem - // - listOrderToolStripMenuItem.Name = "listOrderToolStripMenuItem"; - listOrderToolStripMenuItem.Size = new Size(243, 22); - listOrderToolStripMenuItem.Text = "Список заказов"; - listOrderToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; - // - // doWorkToolStripMenuItem - // - doWorkToolStripMenuItem.Name = "doWorkToolStripMenuItem"; - doWorkToolStripMenuItem.Size = new Size(92, 20); - doWorkToolStripMenuItem.Text = "Запуск работ"; - doWorkToolStripMenuItem.Click += DoWorkToolStripMenuItem_Click; + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(216, 22); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // // dataGridView // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = Color.White; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 27); + dataGridView.Location = new Point(0, 23); + dataGridView.Margin = new Padding(3, 2, 3, 2); dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(817, 411); + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(861, 297); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(835, 50); + buttonCreateOrder.Location = new Point(867, 40); + buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(200, 23); + buttonCreateOrder.Size = new Size(216, 22); buttonCreateOrder.TabIndex = 2; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += ButtonCreateOrder_Click; // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(867, 91); + buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(216, 22); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(867, 143); + buttonOrderReady.Margin = new Padding(3, 2, 3, 2); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(216, 22); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(835, 113); + buttonIssuedOrder.Location = new Point(867, 191); + buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(200, 23); + buttonIssuedOrder.Size = new Size(216, 22); buttonIssuedOrder.TabIndex = 5; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; @@ -157,30 +168,40 @@ // // buttonRef // - buttonRef.Location = new Point(835, 170); + buttonRef.Location = new Point(867, 232); + buttonRef.Margin = new Padding(3, 2, 3, 2); buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(200, 23); + buttonRef.Size = new Size(216, 22); buttonRef.TabIndex = 6; buttonRef.Text = "Обновить список"; buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += ButtonRef_Click; // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(180, 22); + clientsToolStripMenuItem.Text = "Клиенты"; + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1047, 450); + ClientSize = new Size(1099, 320); Controls.Add(buttonRef); Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 2, 3, 2); Name = "FormMain"; - Text = "Магазин электроники"; + Text = "Компьютерный магазин"; Load += FormMain_Load; - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); @@ -188,20 +209,20 @@ #endregion - private MenuStrip menuStrip; - private ToolStripMenuItem dictionaryToolStripMenuItem; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; - private ToolStripMenuItem computerToolStripMenuItem; - private ToolStripMenuItem componentsToolStripMenuItem; - private ToolStripMenuItem отчётыToolStripMenuItem; - private ToolStripMenuItem computerListToolStripMenuItem; - private ToolStripMenuItem componentsOfComputersToolStripMenuItem; - private ToolStripMenuItem listOrderToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem списокИзделийToolStripMenuItem; + private ToolStripMenuItem изделияПоКомпонентамToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; - private ToolStripMenuItem implementersToolStripMenuItem; - private ToolStripMenuItem doWorkToolStripMenuItem; } } \ No newline at end of file diff --git a/ComputersShop/ComputersShopView/FormMain.cs b/ComputersShop/ComputersShopView/FormMain.cs index 69e75dd..26f5003 100644 --- a/ComputersShop/ComputersShopView/FormMain.cs +++ b/ComputersShop/ComputersShopView/FormMain.cs @@ -20,24 +20,19 @@ namespace ComputersShopView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - private readonly IWorkProcess _workProcess; - - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportlogic, IWorkProcess workProcess) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; - _reportLogic = reportlogic; - _workProcess = workProcess; + _reportLogic = reportLogic; } - private void FormMain_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { - _logger.LogInformation("Загрузка заказов"); try { var list = _orderLogic.ReadList(null); @@ -46,7 +41,8 @@ namespace ComputersShopView dataGridView.DataSource = list; dataGridView.Columns["ComputerId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ComputerName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -56,7 +52,7 @@ namespace ComputersShopView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); if (service is FormComponents form) @@ -64,7 +60,7 @@ namespace ComputersShopView form.ShowDialog(); } } - private void ComputersToolStripMenuItem_Click(object sender, EventArgs e) + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComputers)); if (service is FormComputers form) @@ -86,17 +82,12 @@ namespace ComputersShopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), - 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) { @@ -116,17 +107,12 @@ namespace ComputersShopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), - 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) { @@ -146,24 +132,18 @@ namespace ComputersShopView if (dataGridView.SelectedRows.Count == 1) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - ComputerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ComputerId"].Value), - ImplementerId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ImplementerId"].Value), - 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) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - _logger.LogInformation("Заказ №{id} выдан", id); + _logger.LogInformation("Заказ No{id} выдан", id); LoadData(); } catch (Exception ex) @@ -173,8 +153,11 @@ namespace ComputersShopView } } } - - private void ComponentsDocxToolStripMenuItem_Click(object sender, EventArgs e) + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) @@ -184,7 +167,7 @@ namespace ComputersShopView } } - private void ComputerComponentsToolStripMenuItem_Click(object sender, EventArgs e) + private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportComputerComponents)); if (service is FormReportComputerComponents form) @@ -193,7 +176,7 @@ namespace ComputersShopView } } - private void OrdersToolStripMenuItem_Click(object sender, EventArgs e) + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); if (service is FormReportOrders form) @@ -201,8 +184,7 @@ namespace ComputersShopView form.ShowDialog(); } } - - private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + private void clientsToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormClients)); if (service is FormClients form) @@ -210,28 +192,5 @@ namespace ComputersShopView form.ShowDialog(); } } - - private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); - if (service is FormImplementers form) - { - form.ShowDialog(); - } - } - - private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) - { - _workProcess.DoWork(( - Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, - _orderLogic); - MessageBox.Show("Процесс обработки запущен", "Сообщение", - MessageBoxButtons.OK, MessageBoxIcon.Information); - } - - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } } } diff --git a/ComputersShop/ComputersShopView/Program.cs b/ComputersShop/ComputersShopView/Program.cs index 2773da6..d6bf5de 100644 --- a/ComputersShop/ComputersShopView/Program.cs +++ b/ComputersShop/ComputersShopView/Program.cs @@ -42,15 +42,12 @@ namespace ComputersShop 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(); @@ -66,8 +63,6 @@ namespace ComputersShop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); } } } \ No newline at end of file -- 2.25.1