From 1aa2b64b3bad2b65eb3a6119aba777c6f68ab4e0 Mon Sep 17 00:00:00 2001 From: russell Date: Thu, 2 May 2024 22:47:27 +0400 Subject: [PATCH 1/2] lab6 --- .../BusinessLogics/ImplementerLogic.cs | 124 +++++++++ .../BusinessLogics/OrderLogic.cs | 32 ++- .../BusinessLogics/WorkModeling.cs | 144 ++++++++++ .../BindingModels/ImplementerBindingModel.cs | 17 ++ .../BindingModels/OrderBindingModel.cs | 2 + .../IImplementerLogic.cs | 19 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 2 + .../BusinessLogicsContracts/IWorkProcess.cs | 10 + .../SearchModels/ImplementerSearchModel.cs | 11 + .../SearchModels/OrderSearchModel.cs | 7 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 27 ++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 13 + .../Models/IOrderModel.cs | 1 + .../CarRepairShopDatabase.cs | 2 + .../Implements/ImplementerStorage.cs | 91 +++++++ .../Implements/OrderStorage.cs | 35 ++- .../20240502171359_AddImplementer.Designer.cs | 256 ++++++++++++++++++ .../20240502171359_AddImplementer.cs | 105 +++++++ .../CarRepairShopDatabaseModelSnapshot.cs | 53 +++- .../Models/Implementer.cs | 82 ++++++ .../Models/Order.cs | 12 +- .../DataFileSingleton.cs | 7 + .../Implements/ImplementerStorage.cs | 88 ++++++ .../Implements/OrderStorage.cs | 27 +- .../Models/Implementer.cs | 81 ++++++ .../Models/Order.cs | 7 + .../DataListSingleton.cs | 3 + .../Implements/ImplementerStorage.cs | 109 ++++++++ .../Implements/OrderStorage.cs | 30 +- .../Models/Implementer.cs | 61 +++++ .../Models/Order.cs | 5 + .../Controllers/ImplementerController.cs | 107 ++++++++ CarRepairShop/CarRepairShopRestApi/Program.cs | 2 + .../FormImplementer.Designer.cs | 173 ++++++++++++ .../CarRepairShopView/FormImplementer.cs | 104 +++++++ .../CarRepairShopView/FormImplementer.resx | 120 ++++++++ .../CarRepairShopView/FormImplementers.cs | 106 ++++++++ .../FormImplementers.designer.cs | 127 +++++++++ .../CarRepairShopView/FormImplementers.resx | 120 ++++++++ CarRepairShop/CarRepairShopView/FormMain.cs | 69 ++--- .../CarRepairShopView/FormMain.designer.cs | 122 ++++----- CarRepairShop/CarRepairShopView/Program.cs | 5 + 44 files changed, 2408 insertions(+), 134 deletions(-) create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 CarRepairShop/CarRepairShopContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 CarRepairShop/CarRepairShopContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs create mode 100644 CarRepairShop/CarRepairShopDataModels/Models/IImplementerModel.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.Designer.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.cs create mode 100644 CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs create mode 100644 CarRepairShop/CarRepairShopFileImplement/Implements/ImplementerStorage.cs create mode 100644 CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Implements/ImplementerStorage.cs create mode 100644 CarRepairShop/CarRepairShopListImplement/Models/Implementer.cs create mode 100644 CarRepairShop/CarRepairShopRestApi/Controllers/ImplementerController.cs create mode 100644 CarRepairShop/CarRepairShopView/FormImplementer.Designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormImplementer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormImplementer.resx create mode 100644 CarRepairShop/CarRepairShopView/FormImplementers.cs create mode 100644 CarRepairShop/CarRepairShopView/FormImplementers.designer.cs create mode 100644 CarRepairShop/CarRepairShopView/FormImplementers.resx diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..feb095e --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,124 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Id: {Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("Стаж работы исполнителя должен быть больше 0", nameof(model.WorkExperience)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация исполнителя должен быть больше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. Id: {Id}. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Qualification: {Qualification}. " + + "WorkExperience: {WorkExperience}", model.Id, model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже существует"); + } + } + } +} diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs index 73f85d7..0204723 100644 --- a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -14,6 +14,8 @@ namespace CarRepairShopBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; + static readonly object locker = new(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; @@ -50,9 +52,29 @@ namespace CarRepairShopBusinessLogic.BusinessLogics return list; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id: {Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) @@ -110,11 +132,11 @@ namespace CarRepairShopBusinessLogic.BusinessLogics newStatus, order.Status); return false; } - model.RepairId = order.RepairId; - model.Count = order.Count; - model.Sum = order.Sum; - model.DateCreate = order.DateCreate; model.Status = newStatus; + if (order.ImplementerId.HasValue) + { + model.ImplementerId = order.ImplementerId; + } if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; diff --git a/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/WorkModeling.cs b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..99495f1 --- /dev/null +++ b/CarRepairShop/CarRepairShopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,144 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/BindingModels/ImplementerBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..eeac813 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,17 @@ +using CarRepairShopDataModels.Models; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs index be3d586..72c41e2 100644 --- a/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs +++ b/CarRepairShop/CarRepairShopContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,8 @@ namespace CarRepairShopContracts.BindingModels public int Id { get; set; } public int RepairId { 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/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..b32e829 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs index 0129f06..7eb9819 100644 --- a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -8,6 +8,8 @@ namespace CarRepairShopContracts.BusinessLogicsContracts { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); diff --git a/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IWorkProcess.cs b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..be7a7ee --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,10 @@ +namespace CarRepairShopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/ImplementerSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..be0b491 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace CarRepairShopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs index d4940b2..359ca6d 100644 --- a/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs +++ b/CarRepairShop/CarRepairShopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using CarRepairShopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,8 +13,12 @@ namespace CarRepairShopContracts.SearchModels public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + + public OrderStatus? Status { get; set; } } } diff --git a/CarRepairShop/CarRepairShopContracts/StoragesContracts/IImplementerStorage.cs b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..f90b9e4 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..f99ac26 --- /dev/null +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopContracts.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/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs index 87045db..b99bdbc 100644 --- a/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs +++ b/CarRepairShop/CarRepairShopContracts/ViewModels/OrderViewModel.cs @@ -20,6 +20,9 @@ namespace CarRepairShopContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; [DisplayName("Количество")] + public int? ImplementerId { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; public int Count { get; set; } [DisplayName("Сумма")] public double Sum { get; set; } diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IImplementerModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..27ba628 --- /dev/null +++ b/CarRepairShop/CarRepairShopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,13 @@ +namespace CarRepairShopDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} diff --git a/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs b/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs index b117530..51ca2e3 100644 --- a/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs +++ b/CarRepairShop/CarRepairShopDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace CarRepairShopDataModels.Models { int RepairId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs b/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs index f58cb39..3066b76 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/CarRepairShopDatabase.cs @@ -23,5 +23,7 @@ namespace CarRepairShopDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + + public virtual DbSet Implementers { set; get; } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ImplementerStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..888db56 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,91 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new CarRepairShopDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new CarRepairShopDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new CarRepairShopDatabase(); + return context.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new CarRepairShopDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new CarRepairShopDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new CarRepairShopDatabase(); + var element = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs index 7e03054..8c59e8d 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Implements/OrderStorage.cs @@ -15,6 +15,7 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -27,6 +28,7 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -36,6 +38,7 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -45,16 +48,37 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Repair) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.Status != null) + { + return context.Orders + .Include(x => x.Repair) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -62,7 +86,11 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) + .Include(x => x.Implementer) + .FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -79,6 +107,7 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -96,6 +125,7 @@ namespace CarRepairShopDatabaseImplement.Implements return context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } @@ -109,6 +139,7 @@ namespace CarRepairShopDatabaseImplement.Implements var deletedElement = context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; context.Orders.Remove(element); diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.Designer.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.Designer.cs new file mode 100644 index 0000000..3291ab1 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.Designer.cs @@ -0,0 +1,256 @@ +// +using System; +using CarRepairShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CarRepairShopDatabaseImplement.Migrations +{ + [DbContext(typeof(CarRepairShopDatabase))] + [Migration("20240502171359_AddImplementer")] + partial class AddImplementer + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.27") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("RepairId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("RepairId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Repair", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("RepairName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Repairs"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.RepairComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("RepairId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("RepairId"); + + b.ToTable("RepairComponents"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => + { + b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarRepairShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair") + .WithMany("Orders") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Repair"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.RepairComponent", b => + { + b.HasOne("CarRepairShopDatabaseImplement.Models.Component", "Component") + .WithMany("RepairComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair") + .WithMany("Components") + .HasForeignKey("RepairId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Repair"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Component", b => + { + b.Navigation("RepairComponents"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Repair", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.cs new file mode 100644 index 0000000..d81746f --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/20240502171359_AddImplementer.cs @@ -0,0 +1,105 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CarRepairShopDatabaseImplement.Migrations +{ + public partial class AddImplementer : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + } +} diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs index d491008..bfa0e1f 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Migrations/CarRepairShopDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace CarRepairShopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -75,7 +102,7 @@ namespace CarRepairShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); - b.Property("ClientId") + b.Property("ClientId") .HasColumnType("int"); b.Property("Count") @@ -87,6 +114,9 @@ namespace CarRepairShopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("RepairId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace CarRepairShopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("RepairId"); b.ToTable("Orders"); @@ -153,9 +185,15 @@ namespace CarRepairShopDatabaseImplement.Migrations modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Order", b => { - b.HasOne("CarRepairShopDatabaseImplement.Models.Client", null) + b.HasOne("CarRepairShopDatabaseImplement.Models.Client", "Client") .WithMany("Orders") - .HasForeignKey("ClientId"); + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CarRepairShopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); b.HasOne("CarRepairShopDatabaseImplement.Models.Repair", "Repair") .WithMany("Orders") @@ -163,6 +201,10 @@ namespace CarRepairShopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + + b.Navigation("Implementer"); + b.Navigation("Repair"); }); @@ -195,6 +237,11 @@ namespace CarRepairShopDatabaseImplement.Migrations b.Navigation("RepairComponents"); }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("CarRepairShopDatabaseImplement.Models.Repair", b => { b.Navigation("Components"); diff --git a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..4f172e4 --- /dev/null +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,82 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopDatabaseImplement.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/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs index 2458ca1..c623454 100644 --- a/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopDatabaseImplement/Models/Order.cs @@ -17,6 +17,8 @@ namespace CarRepairShopDatabaseImplement.Models [Required] public int ClientId { get; set; } + public int? ImplementerId { get; private set; } + [Required] public int Count { get; set; } @@ -35,6 +37,8 @@ namespace CarRepairShopDatabaseImplement.Models public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -46,6 +50,7 @@ namespace CarRepairShopDatabaseImplement.Models Id = model.Id, RepairId = model.RepairId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -62,6 +67,7 @@ namespace CarRepairShopDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -69,13 +75,15 @@ namespace CarRepairShopDatabaseImplement.Models Id = Id, RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - RepairName = Repair.RepairName, - ClientFIO = Client.ClientFIO + RepairName = Repair.RepairName ?? string.Empty, + ClientFIO = Client.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs b/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs index a5e4f69..5bd7b9b 100644 --- a/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs +++ b/CarRepairShop/CarRepairShopFileImplement/DataFileSingleton.cs @@ -15,6 +15,8 @@ namespace CarRepairShopFileImplement private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; + public List Components { get; private set; } public List Orders { get; private set; } @@ -23,6 +25,8 @@ namespace CarRepairShopFileImplement public List Clients { get; private set; } + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -40,12 +44,15 @@ namespace CarRepairShopFileImplement public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Repairs = LoadData(RepairFileName, "Repair", x => Repair.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/CarRepairShop/CarRepairShopFileImplement/Implements/ImplementerStorage.cs b/CarRepairShop/CarRepairShopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..254aaf6 --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,88 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopFileImplement.Models; + +namespace CarRepairShopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs index 949fba2..81b7381 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Implements/OrderStorage.cs @@ -46,21 +46,34 @@ namespace CarRepairShopFileImplement.Implements .Select(x => AddInfo(x.GetViewModel)) .ToList(); } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .Where(x => x.ImplementerId == model.ImplementerId) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } + else if (model.Status != null) + { + return source.Orders + .Where(x => x.Status.Equals(model.Status)) + .Select(x => AddInfo(x.GetViewModel)) + .ToList(); + } return new(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - return AddInfo(order.GetViewModel); + var order = source.Orders.FirstOrDefault(x => + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId && model.Status != null && x.Status.Equals(model.Status) + || model.Status == null && model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId + || model.Id.HasValue && x.Id == model.Id); + return order?.GetViewModel != null ? AddInfo(order.GetViewModel) : null; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..8933a8d --- /dev/null +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Implementer.cs @@ -0,0 +1,81 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System.Xml.Linq; + +namespace CarRepairShopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value) + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification) + ); + } +} diff --git a/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs b/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs index 0b0fa43..969652d 100644 --- a/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopFileImplement/Models/Order.cs @@ -15,6 +15,8 @@ namespace CarRepairShopFileImplement.Models public int ClientId { get; set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -36,6 +38,7 @@ namespace CarRepairShopFileImplement.Models Id = model.Id, RepairId = model.RepairId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -55,6 +58,7 @@ namespace CarRepairShopFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), RepairId = Convert.ToInt32(element.Element("RepairId")!.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), @@ -72,6 +76,7 @@ namespace CarRepairShopFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -79,6 +84,7 @@ namespace CarRepairShopFileImplement.Models Id = Id, RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -90,6 +96,7 @@ namespace CarRepairShopFileImplement.Models new XAttribute("Id", Id), new XElement("RepairId", RepairId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs index c4dd483..5bc7f27 100644 --- a/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs +++ b/CarRepairShop/CarRepairShopListImplement/DataListSingleton.cs @@ -14,12 +14,15 @@ namespace CarRepairShopListImplement public List Clients { get; set; } + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Repairs = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/ImplementerStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..9709b90 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,109 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.StoragesContracts; +using CarRepairShopContracts.ViewModels; +using CarRepairShopListImplement.Models; + +namespace CarRepairShopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + foreach (var implementer in _source.Implementers) + { + if ((!string.IsNullOrEmpty(model.ImplementerFIO) && implementer.ImplementerFIO == model.ImplementerFIO + && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + || (model.Id.HasValue && implementer.Id == model.Id)) + { + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs index eb51f5b..fc8f224 100644 --- a/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs +++ b/CarRepairShop/CarRepairShopListImplement/Implements/OrderStorage.cs @@ -58,12 +58,32 @@ namespace CarRepairShopListImplement.Implements } } } + else if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } + else if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (order.Status.Equals(model.Status)) + { + result.Add(AddInfo(order.GetViewModel)); + } + } + } return result; } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.ImplementerId.HasValue) { return null; } @@ -73,6 +93,14 @@ namespace CarRepairShopListImplement.Implements { return AddInfo(order.GetViewModel); } + if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && order.Status.Equals(model.Status)) + { + return AddInfo(order.GetViewModel); + } + if (model.ImplementerId.HasValue && model.Status == null && order.ImplementerId == model.ImplementerId) + { + return AddInfo(order.GetViewModel); + } } return null; } diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Implementer.cs b/CarRepairShop/CarRepairShopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..1491455 --- /dev/null +++ b/CarRepairShop/CarRepairShopListImplement/Models/Implementer.cs @@ -0,0 +1,61 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarRepairShopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/CarRepairShop/CarRepairShopListImplement/Models/Order.cs b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs index 7e94607..3f58e22 100644 --- a/CarRepairShop/CarRepairShopListImplement/Models/Order.cs +++ b/CarRepairShop/CarRepairShopListImplement/Models/Order.cs @@ -13,6 +13,8 @@ namespace CarRepairShopListImplement.Models public int ClientId { get; set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -34,6 +36,7 @@ namespace CarRepairShopListImplement.Models Id = model.Id, RepairId = model.RepairId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -50,6 +53,7 @@ namespace CarRepairShopListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -57,6 +61,7 @@ namespace CarRepairShopListImplement.Models Id = Id, RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/CarRepairShop/CarRepairShopRestApi/Controllers/ImplementerController.cs b/CarRepairShop/CarRepairShopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..c1f95dd --- /dev/null +++ b/CarRepairShop/CarRepairShopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; +using CarRepairShopContracts.ViewModels; +using CarRepairShopDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace CarRepairShopRestApi.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, "Employee authorization error"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error receiving new orders"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error of receiving the current order of an implementer"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Taking order №{Id} in work error", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Finishing order №{Id} error", model.Id); + throw; + } + } + } +} diff --git a/CarRepairShop/CarRepairShopRestApi/Program.cs b/CarRepairShop/CarRepairShopRestApi/Program.cs index 5fb81db..c11ce79 100644 --- a/CarRepairShop/CarRepairShopRestApi/Program.cs +++ b/CarRepairShop/CarRepairShopRestApi/Program.cs @@ -11,10 +11,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(); diff --git a/CarRepairShop/CarRepairShopView/FormImplementer.Designer.cs b/CarRepairShop/CarRepairShopView/FormImplementer.Designer.cs new file mode 100644 index 0000000..c2f8fae --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormImplementer.Designer.cs @@ -0,0 +1,173 @@ +namespace CarRepairShopView +{ + 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() + { + textBoxPassword = new TextBox(); + labelPassword = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxFIO = new TextBox(); + labelFIO = new Label(); + textBoxWorkExperience = new TextBox(); + labelWorkExperience = new Label(); + textBoxQualification = new TextBox(); + labelQualification = new Label(); + SuspendLayout(); + // + // textBoxPassword + // + textBoxPassword.Location = new Point(102, 44); + textBoxPassword.Margin = new Padding(4, 3, 4, 3); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(235, 23); + textBoxPassword.TabIndex = 15; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(3, 48); + labelPassword.Margin = new Padding(4, 0, 4, 0); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(55, 15); + labelPassword.TabIndex = 14; + labelPassword.Text = "Пароль :"; + // + // buttonCancel + // + buttonCancel.Location = new Point(242, 140); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(147, 140); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 16; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(102, 16); + textBoxFIO.Margin = new Padding(4, 3, 4, 3); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(235, 23); + textBoxFIO.TabIndex = 13; + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(3, 19); + labelFIO.Margin = new Padding(4, 0, 4, 0); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(40, 15); + labelFIO.TabIndex = 12; + labelFIO.Text = "ФИО :"; + // + // textBoxWorkExperience + // + textBoxWorkExperience.Location = new Point(102, 74); + textBoxWorkExperience.Margin = new Padding(4, 3, 4, 3); + textBoxWorkExperience.Name = "textBoxWorkExperience"; + textBoxWorkExperience.Size = new Size(235, 23); + textBoxWorkExperience.TabIndex = 19; + // + // labelWorkExperience + // + labelWorkExperience.AutoSize = true; + labelWorkExperience.Location = new Point(3, 78); + labelWorkExperience.Margin = new Padding(4, 0, 4, 0); + labelWorkExperience.Name = "labelWorkExperience"; + labelWorkExperience.Size = new Size(85, 15); + labelWorkExperience.TabIndex = 18; + labelWorkExperience.Text = "Стаж работы :"; + // + // textBoxQualification + // + textBoxQualification.Location = new Point(102, 103); + textBoxQualification.Margin = new Padding(4, 3, 4, 3); + textBoxQualification.Name = "textBoxQualification"; + textBoxQualification.Size = new Size(235, 23); + textBoxQualification.TabIndex = 21; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(3, 106); + labelQualification.Margin = new Padding(4, 0, 4, 0); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(94, 15); + labelQualification.TabIndex = 20; + labelQualification.Text = "Квалификация :"; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(350, 178); + Controls.Add(textBoxQualification); + Controls.Add(labelQualification); + Controls.Add(textBoxWorkExperience); + Controls.Add(labelWorkExperience); + Controls.Add(textBoxPassword); + Controls.Add(labelPassword); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFIO); + Controls.Add(labelFIO); + Margin = new Padding(2, 2, 2, 2); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxPassword; + private Label labelPassword; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxFIO; + private Label labelFIO; + private TextBox textBoxWorkExperience; + private Label labelWorkExperience; + private TextBox textBoxQualification; + private Label labelQualification; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormImplementer.cs b/CarRepairShop/CarRepairShopView/FormImplementer.cs new file mode 100644 index 0000000..c506c7d --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormImplementer.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using CarRepairShopContracts.SearchModels; + +namespace CarRepairShopView +{ + 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("Receiving implementer"); + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxQualification.Text = view.Qualification.ToString(); + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Receiving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxWorkExperience.Text)) + { + MessageBox.Show("Заполните стаж работы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + MessageBox.Show("Заполните квалификацию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving implementer"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Saving implementer error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarRepairShop/CarRepairShopView/FormImplementer.resx b/CarRepairShop/CarRepairShopView/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/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/CarRepairShop/CarRepairShopView/FormImplementers.cs b/CarRepairShop/CarRepairShopView/FormImplementers.cs new file mode 100644 index 0000000..a6b68f2 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormImplementers.cs @@ -0,0 +1,106 @@ +using CarRepairShopContracts.BindingModels; +using CarRepairShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace CarRepairShopView +{ + 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("Implementers loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementers loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of implementer"); + try + { + if (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Implementer deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormImplementers.designer.cs b/CarRepairShop/CarRepairShopView/FormImplementers.designer.cs new file mode 100644 index 0000000..6f064c2 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/FormImplementers.designer.cs @@ -0,0 +1,127 @@ +namespace CarRepairShopView +{ + 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() + { + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 0; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Margin = new Padding(4, 3, 4, 3); + Name = "FormImplementers"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormImplementers.resx b/CarRepairShop/CarRepairShopView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/CarRepairShop/CarRepairShopView/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/CarRepairShop/CarRepairShopView/FormMain.cs b/CarRepairShop/CarRepairShopView/FormMain.cs index cd7f7aa..d4f653b 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.cs @@ -12,12 +12,16 @@ namespace CarRepairShopView private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + + private readonly IWorkProcess _workProcess; + + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) @@ -37,6 +41,8 @@ namespace CarRepairShopView dataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -75,52 +81,6 @@ namespace CarRepairShopView } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -186,5 +146,20 @@ namespace CarRepairShopView form.ShowDialog(); } } + + private void ИсполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void ЗапускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } \ No newline at end of file diff --git a/CarRepairShop/CarRepairShopView/FormMain.designer.cs b/CarRepairShop/CarRepairShopView/FormMain.designer.cs index 1170a2e..b0e878d 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.designer.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.designer.cs @@ -32,14 +32,14 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ремонтыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.клиентыToolStripMenuItem = new ToolStripMenuItem(); - this.отчетыToolStripMenuItem = new ToolStripMenuItem(); - this.ComponentsToolStripMenuItem = new ToolStripMenuItem(); - this.ComponentRepairsToolStripMenuItem = new ToolStripMenuItem(); - this.OrdersToolStripMenuItem = new ToolStripMenuItem(); + this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ComponentRepairsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.OrdersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonRef = new System.Windows.Forms.Button(); @@ -51,11 +51,12 @@ // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2); - this.menuStrip1.Size = new System.Drawing.Size(1031, 24); + this.menuStrip1.Size = new System.Drawing.Size(1144, 24); this.menuStrip1.TabIndex = 0; this.menuStrip1.Text = "menuStrip1"; // @@ -64,7 +65,8 @@ this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.ремонтыToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -72,56 +74,70 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // ремонтыToolStripMenuItem // this.ремонтыToolStripMenuItem.Name = "ремонтыToolStripMenuItem"; - this.ремонтыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ремонтыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); this.ремонтыToolStripMenuItem.Text = "Ремонты"; this.ремонтыToolStripMenuItem.Click += new System.EventHandler(this.РемонтыToolStripMenuItem_Click); // // клиентыToolStripMenuItem // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(180, 22); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; - // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += ИсполнителиToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentRepairsToolStripMenuItem, OrdersToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); - отчетыToolStripMenuItem.Text = "Отчеты"; + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ComponentsToolStripMenuItem, + this.ComponentRepairsToolStripMenuItem, + this.OrdersToolStripMenuItem}); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); + this.отчетыToolStripMenuItem.Text = "Отчеты"; // // ComponentsToolStripMenuItem // - ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(221, 22); - ComponentsToolStripMenuItem.Text = "Список ремонтов"; - ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(221, 22); + this.ComponentsToolStripMenuItem.Text = "Список ремонтов"; // // ComponentRepairsToolStripMenuItem // - ComponentRepairsToolStripMenuItem.Name = "ComponentRepairsToolStripMenuItem"; - ComponentRepairsToolStripMenuItem.Size = new Size(221, 22); - ComponentRepairsToolStripMenuItem.Text = "Компоненты по ремонтам"; - ComponentRepairsToolStripMenuItem.Click += ComponentRepairsToolStripMenuItem_Click; + this.ComponentRepairsToolStripMenuItem.Name = "ComponentRepairsToolStripMenuItem"; + this.ComponentRepairsToolStripMenuItem.Size = new System.Drawing.Size(221, 22); + this.ComponentRepairsToolStripMenuItem.Text = "Компоненты по ремонтам"; // // OrdersToolStripMenuItem // - OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; - OrdersToolStripMenuItem.Size = new Size(221, 22); - OrdersToolStripMenuItem.Text = "Список заказов"; - OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + this.OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; + this.OrdersToolStripMenuItem.Size = new System.Drawing.Size(221, 22); + this.OrdersToolStripMenuItem.Text = "Список заказов"; + // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += ЗапускРаботToolStripMenuItem_Click; // // buttonIssuedOrder // this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonIssuedOrder.Location = new System.Drawing.Point(844, 231); + this.buttonIssuedOrder.Location = new System.Drawing.Point(957, 117); this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(174, 27); @@ -130,34 +146,10 @@ this.buttonIssuedOrder.UseVisualStyleBackColor = true; this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); // - // buttonOrderReady - // - this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOrderReady.Location = new System.Drawing.Point(844, 171); - this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(174, 27); - this.buttonOrderReady.TabIndex = 3; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(844, 117); - this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(174, 27); - this.buttonTakeOrderInWork.TabIndex = 2; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // // buttonCreateOrder // this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCreateOrder.Location = new System.Drawing.Point(844, 58); + this.buttonCreateOrder.Location = new System.Drawing.Point(957, 58); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(174, 27); @@ -182,13 +174,13 @@ this.dataGridView.ReadOnly = true; this.dataGridView.RowHeadersVisible = false; this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(826, 320); + this.dataGridView.Size = new System.Drawing.Size(939, 320); this.dataGridView.TabIndex = 0; // // buttonRef // this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRef.Location = new System.Drawing.Point(844, 290); + this.buttonRef.Location = new System.Drawing.Point(957, 176); this.buttonRef.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(174, 27); @@ -201,11 +193,9 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1031, 347); + this.ClientSize = new System.Drawing.Size(1144, 347); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -230,8 +220,6 @@ private System.Windows.Forms.ToolStripMenuItem компонентыToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem ремонтыToolStripMenuItem; private System.Windows.Forms.Button buttonIssuedOrder; - private System.Windows.Forms.Button buttonOrderReady; - private System.Windows.Forms.Button buttonTakeOrderInWork; private System.Windows.Forms.Button buttonCreateOrder; private System.Windows.Forms.DataGridView dataGridView; private System.Windows.Forms.Button buttonRef; @@ -240,6 +228,8 @@ private ToolStripMenuItem ComponentRepairsToolStripMenuItem; private ToolStripMenuItem OrdersToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; } } diff --git a/CarRepairShop/CarRepairShopView/Program.cs b/CarRepairShop/CarRepairShopView/Program.cs index 866f7e4..b606716 100644 --- a/CarRepairShop/CarRepairShopView/Program.cs +++ b/CarRepairShop/CarRepairShopView/Program.cs @@ -40,12 +40,15 @@ namespace CarRepairShopView 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(); @@ -59,6 +62,8 @@ namespace CarRepairShopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); } -- 2.25.1 From 0ec57c54aececf85058b85f7bf7bd4fb396ce841 Mon Sep 17 00:00:00 2001 From: russell Date: Thu, 16 May 2024 21:27:30 +0400 Subject: [PATCH 2/2] formmain fix --- CarRepairShop/CarRepairShopView/FormMain.designer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CarRepairShop/CarRepairShopView/FormMain.designer.cs b/CarRepairShop/CarRepairShopView/FormMain.designer.cs index b0e878d..c6c2eab 100644 --- a/CarRepairShop/CarRepairShopView/FormMain.designer.cs +++ b/CarRepairShop/CarRepairShopView/FormMain.designer.cs @@ -114,18 +114,21 @@ this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(221, 22); this.ComponentsToolStripMenuItem.Text = "Список ремонтов"; + this.ComponentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // ComponentRepairsToolStripMenuItem // this.ComponentRepairsToolStripMenuItem.Name = "ComponentRepairsToolStripMenuItem"; this.ComponentRepairsToolStripMenuItem.Size = new System.Drawing.Size(221, 22); this.ComponentRepairsToolStripMenuItem.Text = "Компоненты по ремонтам"; + this.ComponentRepairsToolStripMenuItem.Click += ComponentRepairsToolStripMenuItem_Click; // // OrdersToolStripMenuItem // this.OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; this.OrdersToolStripMenuItem.Size = new System.Drawing.Size(221, 22); this.OrdersToolStripMenuItem.Text = "Список заказов"; + this.OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // // запускРаботToolStripMenuItem // -- 2.25.1