From 4f1d7e3010c0b57ce2ace20cdab829e2915bed4b Mon Sep 17 00:00:00 2001 From: Dasha Date: Tue, 30 Apr 2024 11:39:55 +0400 Subject: [PATCH] fix --- .../BusinessLogics/ImplementerLogic.cs | 119 ++++++++ .../BusinessLogics/OrderLogic.cs | 38 ++- .../BusinessLogics/WorkModeling.cs | 144 ++++++++++ .../BindingModels/ImplementerBindingModel.cs | 20 ++ .../BindingModels/OrderBindingModel.cs | 4 +- .../IImplementerLogic.cs | 19 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 3 +- .../BusinessLogicsContracts/IWorkProcess.cs | 10 + .../SearchModels/ImplementerSearchModel.cs | 11 + .../SearchModels/OrderSearchModel.cs | 8 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 25 ++ .../ViewModels/OrderViewModel.cs | 7 +- .../Models/IImplementerModel.cs | 13 + .../FishFactoryDatabase.cs | 3 +- .../Implements/ImplementerStorage.cs | 98 +++++++ .../Implements/OrderStorage.cs | 93 ++++--- .../20240429171937_Implementors.Designer.cs | 257 ++++++++++++++++++ .../Migrations/20240429171937_Implementors.cs | 67 +++++ .../FishFactoryDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 57 ++++ .../Models/Order.cs | 19 +- .../DataFileSingleton.cs | 13 +- .../Implements/ImplementerStorage.cs | 84 ++++++ .../Implements/OrderStorage.cs | 50 +++- .../Models/Implementer.cs | 76 ++++++ .../FishFactoryFileImplement/Models/Order.cs | 19 +- .../DataListSingleton.cs | 6 +- .../Implements/ImplementerStorage.cs | 124 +++++++++ .../Implements/OrderStorage.cs | 22 +- .../Models/Implementer.cs | 54 ++++ .../FishFactoryListImplement/Models/Order.cs | 16 +- .../Controllers/ImplementerController.cs | 107 ++++++++ FishFactory/FishFactoryRestApi/Program.cs | 2 + .../FishFactoryView/FormCreateOrder.cs | 1 - .../FormImplementer.Designer.cs | 178 ++++++++++++ .../FishFactoryView/FormImplementer.cs | 99 +++++++ .../FishFactoryView/FormImplementer.resx | 120 ++++++++ .../FormImplementers.Designer.cs | 122 +++++++++ .../FishFactoryView/FormImplementers.cs | 103 +++++++ .../FishFactoryView/FormImplementers.resx | 120 ++++++++ .../FishFactoryView/FormMain.Designer.cs | 128 ++++----- FishFactory/FishFactoryView/FormMain.cs | 67 ++--- FishFactory/FishFactoryView/FormMain.resx | 3 + FishFactory/FishFactoryView/Program.cs | 11 +- 45 files changed, 2412 insertions(+), 192 deletions(-) create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs create mode 100644 FishFactory/FishFactoryDataModels/Models/IImplementerModel.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.Designer.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs create mode 100644 FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactory/FishFactoryFileImplement/Models/Implementer.cs create mode 100644 FishFactory/FishFactoryListImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactory/FishFactoryListImplement/Models/Implementer.cs create mode 100644 FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs create mode 100644 FishFactory/FishFactoryView/FormImplementer.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormImplementer.cs create mode 100644 FishFactory/FishFactoryView/FormImplementer.resx create mode 100644 FishFactory/FishFactoryView/FormImplementers.Designer.cs create mode 100644 FishFactory/FishFactoryView/FormImplementers.cs create mode 100644 FishFactory/FishFactoryView/FormImplementers.resx diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..e2b686f --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Id:{Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}.Id:{Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("У исполнителя должно быть ФИО", nameof(model.ImplementerFIO)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("У исполнителя квалификация должна быть больше 0", nameof(model.Qualification)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("У исполнителя стаж должен быть больше 0", nameof(model.WorkExperience)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("У исполнителя должен быть пароль", nameof(model.Password)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}.Qualification:{Qualification}.WorkExperience:{WorkExperience} Id: {Id}", model.ImplementerFIO, model.Qualification, model.WorkExperience, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs index 211f4db..c67efe2 100644 --- a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -39,15 +39,24 @@ namespace FishFactoryBusinessLogic.BusinessLogics public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model, false); - if (model.Status + 1 != newStatus) - { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) { model.Status--; _logger.LogWarning("Update operation failed"); @@ -84,7 +93,24 @@ namespace FishFactoryBusinessLogic.BusinessLogics return list; } - private void CheckModel(OrderBindingModel model, bool withParams = true) + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) { diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..84d120a --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,144 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; + +namespace FishFactoryBusinessLogic.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 { OrderStatus = OrderStatus.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + /// + /// Имитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + + 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, + OrderStatus = 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; + } + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..8bf8c1e --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,20 @@ +using FishFactoryDataModels.Models; + +namespace FishFactoryContracts.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; } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs index 3815edd..4bd15cb 100644 --- a/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -7,8 +7,8 @@ namespace FishFactoryContracts.BindingModels { public int CannedId { get; set; } public int ClientId { get; set; } - public string CannedName { get; set; } = string.Empty; - public int Count { get; set; } + public int? ImplementerId { get; set; } + public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..5a3e293 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index 0602638..f861fbb 100644 --- a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,7 +7,8 @@ namespace FishFactoryContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - bool CreateOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..423db53 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,10 @@ +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..542bc90 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace FishFactoryContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs index aea6adc..3279522 100644 --- a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs +++ b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs @@ -1,10 +1,14 @@ -namespace FishFactoryContracts.SearchModels +using FishFactoryDataModels.Enums; + +namespace FishFactoryContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } public int? ClientId { get; set; } - public DateTime? DateFrom { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? OrderStatus { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } } diff --git a/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs b/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..33ccb07 --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..60ecf8a --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,25 @@ +using FishFactoryDataModels.Models; +using System.ComponentModel; + +namespace FishFactoryContracts.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; } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs index 59d039c..3d6a6ea 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -10,11 +10,14 @@ namespace FishFactoryContracts.ViewModels public int Id { get; set; } public int CannedId { get; set; } public int ClientId { get; set; } - [DisplayName("Консерва")] + public int? ImplementerId { get; set; } + [DisplayName("Консерва")] public string CannedName { get; set; } = string.Empty; [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("Количество")] + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] public double Sum { get; set; } diff --git a/FishFactory/FishFactoryDataModels/Models/IImplementerModel.cs b/FishFactory/FishFactoryDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..d97daec --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IImplementerModel.cs @@ -0,0 +1,13 @@ +namespace FishFactoryDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs index 5eece9d..63d3d64 100644 --- a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs +++ b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs @@ -23,5 +23,6 @@ namespace FishFactoryDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } - } + public virtual DbSet Implementers { set; get; } + } } diff --git a/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..6cdd246 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,98 @@ +using Microsoft.EntityFrameworkCore; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDatabaseImplement.Models; + +namespace FishFactoryDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var element = context.Implementers.Include(x => x.Orders).FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new FishFactoryDatabase(); + if (model.Id.HasValue) + { + return context.Implementers + .Include(x => x.Orders) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + return context.Implementers.Include(x => x.Orders) + .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + return context.Implementers.Include(x => x.Orders) + .FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO)?.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new FishFactoryDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new FishFactoryDatabase(); + return context.Implementers + .Include(x => x.Orders) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new FishFactoryDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return context.Implementers + .Include(x => x.Orders) + .FirstOrDefault(x => x.Id == newImplementer.Id)?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var implementer = context.Implementers.Include(x => x.Orders).FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs index 98d7a27..4425ef6 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -15,7 +15,8 @@ namespace FishFactoryDatabaseImplement.Implements var element = context.Orders .Include(x => x.Canned) .Include(x => x.Client) - .FirstOrDefault(rec => rec.Id == model.Id); + .Include(x => x.Implementer) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); @@ -27,55 +28,79 @@ namespace FishFactoryDatabaseImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } - using var context = new FishFactoryDatabase(); - return context.Orders - .Include(x => x.Canned) - .Include(x => x.Client) - .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; - } + using var context = new FishFactoryDatabase(); + if (model.Id.HasValue) + { + return context.Orders + .Include(x => x.Canned) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) + { + return context.Orders + .Include(x => x.Canned) + .Include(x => x.Client).Include(x => x.Implementer) + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) + ?.GetViewModel; + } + else if (model.ImplementerId.HasValue) + { + return context.Orders + .Include(x => x.Canned) + .Include(x => x.Client).Include(x => x.Implementer) + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } + return null; + } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue) - { - return new(); - } - using var context = new FishFactoryDatabase(); - if (model.DateFrom.HasValue) - { + if (model == null) return new(); + using var context = new FishFactoryDatabase(); + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { return context.Orders .Include(x => x.Canned) - .Include(x => x.Client) - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); } else if (model.ClientId.HasValue) return context.Orders .Include(x => x.Canned) - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) + .Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); - return context.Orders - .Include(x => x.Canned) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } + else if (model.OrderStatus.HasValue) + return context.Orders + .Include(x => x.Canned) + .Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.Status == model.OrderStatus) + .Select(x => x.GetViewModel) + .ToList(); + else if (model.Id.HasValue) + return context.Orders + .Include(x => x.Canned) + .Include(x => x.Client).Include(x => x.Implementer) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + return new(); + } public List GetFullList() { using var context = new FishFactoryDatabase(); return context.Orders .Include(x => x.Canned) .Include(x => x.Client) - .Select(x => x.GetViewModel) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) .ToList(); } @@ -92,7 +117,8 @@ namespace FishFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Canned) .Include(x => x.Client) - .FirstOrDefault(x => x.Id == newOrder.Id) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id) ?.GetViewModel; } @@ -102,7 +128,8 @@ namespace FishFactoryDatabaseImplement.Implements var order = context.Orders .Include(x => x.Canned) .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id); + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; diff --git a/FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.Designer.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.Designer.cs new file mode 100644 index 0000000..de7efc6 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240429171937_Implementors")] + partial class Implementors + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("CannedList"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("int"); + + 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("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.cs new file mode 100644 index 0000000..0d6dcfa --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240429171937_Implementors.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class Implementors : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + 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_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + 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"); + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs index 9de5842..fb857c0 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs @@ -113,6 +113,33 @@ namespace FishFactoryDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace FishFactoryDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -148,6 +178,8 @@ namespace FishFactoryDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -184,9 +216,15 @@ namespace FishFactoryDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.Navigation("Canned"); b.Navigation("Client"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => @@ -205,6 +243,11 @@ namespace FishFactoryDatabaseImplement.Migrations { b.Navigation("CannedComponents"); }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..29e11bd --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,57 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; + +namespace FishFactoryDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public int Qualification { get; private 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 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, + }; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs index 4704605..3400210 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs @@ -12,7 +12,8 @@ namespace FishFactoryDatabaseImplement.Models public int CannedId { get; set; } [Required] public int ClientId { get; set; } - [Required] + public int? ImplementerId { get; private set; } + [Required] public int Count { get; set; } [Required] public double Sum { get; set; } @@ -24,7 +25,8 @@ namespace FishFactoryDatabaseImplement.Models public int Id { get; set; } public Canned Canned { get; set; } public Client Client { get; set; } - public static Order? Create(OrderBindingModel? model) + public Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { @@ -35,7 +37,8 @@ namespace FishFactoryDatabaseImplement.Models Id = model.Id, CannedId = model.CannedId, ClientId = model.ClientId, - Count = model.Count, + ImplementerId = model.ImplementerId, + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -50,15 +53,19 @@ namespace FishFactoryDatabaseImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; - } + DateImplement = model.DateImplement; + if (model.ImplementerId.HasValue) + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel => new() { CannedId = CannedId, ClientId = ClientId, ClientFIO = Client.ClientFIO, - Count = Count, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, + ImplementerId = ImplementerId, + Count = Count, Sum = Sum, DateCreate = DateCreate, DateImplement = DateImplement, diff --git a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs index 9cf4468..a491b6f 100644 --- a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs +++ b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs @@ -1,5 +1,4 @@ using FishFactoryFileImplement.Models; -using System.Threading.Channels; using System.Xml.Linq; namespace FishFactoryFileImplement @@ -11,11 +10,13 @@ namespace FishFactoryFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string CannedFileName = "Canned.xml"; private readonly string ClientFileName = "Client.xml"; - public List Components { get; private set; } + private readonly string ImplementerFileName = "Implementer.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Clients { get; private set; } public List ListCanned { get; private set; } - public static DataFileSingleton GetInstance() + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -31,13 +32,15 @@ namespace FishFactoryFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); - private DataFileSingleton() + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; ListCanned = LoadData(CannedFileName, "Canned", x => Canned.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/FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..603b98e --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryFileImplement.Models; + +namespace FishFactoryFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!string.IsNullOrEmpty(model.ImplementerFIO) || model.Id.HasValue) + { + return source.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + return source.Implementers.FirstOrDefault(x => + x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs index ee068f2..d411f00 100644 --- a/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs +++ b/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs @@ -21,18 +21,23 @@ namespace FishFactoryFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (model.DateFrom.HasValue) - return source.Orders + if (model.DateFrom.HasValue && model.DateTo.HasValue) + return source.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Select(x => GetViewModel(x)) .ToList(); - if (model.ClientId.HasValue && !model.Id.HasValue) - return source.Orders + else if (model.ClientId.HasValue && !model.Id.HasValue) + return source.Orders .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); - if (model.Id.HasValue) - return source.Orders + else if (model.OrderStatus.HasValue) + return source.Orders + .Where(x => x.Status == model.OrderStatus) + .Select(x => x.GetViewModel) + .ToList(); + else if (model.Id.HasValue) + return source.Orders .Where(x => x.Id.Equals(model.Id)) .Select(x => GetViewModel(x)) .ToList(); @@ -41,14 +46,25 @@ namespace FishFactoryFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } + if (model.Id.HasValue) + { + return source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } - return source.Orders.FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } + else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) + ?.GetViewModel; + } + else if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } + return null; + } private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; @@ -56,12 +72,16 @@ namespace FishFactoryFileImplement.Implements .ListCanned.FirstOrDefault(x => x.Id == order.CannedId); var client = source .Clients.FirstOrDefault(x => x.Id == order.ClientId); + var implementer = source + .Implementers.FirstOrDefault(x => x.Id == order.ImplementerId); - if (canned != null) + if (canned != null) viewModel.CannedName = canned.CannedName; if (client != null) viewModel.ClientFIO = client.ClientFIO; - return viewModel; + if (implementer != null) + viewModel.ImplementerFIO = implementer.ImplementerFIO; + return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) { diff --git a/FishFactory/FishFactoryFileImplement/Models/Implementer.cs b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..cb5a843 --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs @@ -0,0 +1,76 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System.Xml.Linq; + +namespace FishFactoryFileImplement.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 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)); + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs index d91ac6b..0474512 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs @@ -11,7 +11,8 @@ namespace FishFactoryFileImplement.Models public int Id { get; private set; } public int CannedId { get; private set; } public int ClientId { get; private set; } - public int Count { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; @@ -28,7 +29,8 @@ namespace FishFactoryFileImplement.Models Id = model.Id, CannedId = model.CannedId, ClientId = model.ClientId, - Count = model.Count, + ImplementerId = model.ImplementerId, + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -47,7 +49,8 @@ namespace FishFactoryFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), CannedId = Convert.ToInt32(element.Element("CannedId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - Sum = Convert.ToDouble(element.Element("Sum")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), @@ -63,13 +66,16 @@ namespace FishFactoryFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - } + if (model.ImplementerId.HasValue) + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel => new() { CannedId = CannedId, ClientId = ClientId, - Count = Count, + ImplementerId = ImplementerId, + Count = Count, Sum = Sum, DateCreate = DateCreate, DateImplement = DateImplement, @@ -81,7 +87,8 @@ namespace FishFactoryFileImplement.Models new XAttribute("Id", Id), new XElement("CannedId", CannedId), new XElement("ClientId", ClientId), - new XElement("Count", Count.ToString()), + new XElement("ImplementerId", ImplementerId), + new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs index 79ed297..2e73fbb 100644 --- a/FishFactory/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -9,14 +9,16 @@ namespace FishFactoryListImplement public List Orders { get; set; } public List ListCanned { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } - private DataListSingleton() + private DataListSingleton() { Components = new List(); Orders = new List(); ListCanned = new List(); Clients = new List(); - } + Implementers = new List(); + } public static DataListSingleton GetInstance() { diff --git a/FishFactory/FishFactoryListImplement/Implements/ImplementerStorage.cs b/FishFactory/FishFactoryListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..f88f0a1 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,124 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; + +namespace FishFactoryListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + return implementer.GetViewModel; + } + } + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO) && implementer.Password.Equals(model.Password)) + { + return implementer.GetViewModel; + } + } + } + else if (!string.IsNullOrEmpty(model.ImplementerFIO)) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO == model.ImplementerFIO) + { + return implementer.GetViewModel; + } + } + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs index 8128dc0..032be34 100644 --- a/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs +++ b/FishFactory/FishFactoryListImplement/Implements/OrderStorage.cs @@ -47,7 +47,17 @@ namespace FishFactoryListImplement.Implements } } } - else if (model.Id.HasValue) + else if (model.OrderStatus.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Status == model.OrderStatus) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) { foreach (var order in _source.Orders) { @@ -95,7 +105,15 @@ namespace FishFactoryListImplement.Implements break; } } - return viewModel; + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == order.ImplementerId) + { + viewModel.ImplementerFIO = implementer.ImplementerFIO; + break; + } + } + return viewModel; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/FishFactory/FishFactoryListImplement/Models/Implementer.cs b/FishFactory/FishFactoryListImplement/Models/Implementer.cs new file mode 100644 index 0000000..0c72203 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Implementer.cs @@ -0,0 +1,54 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; + +namespace FishFactoryListImplement.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 + }; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryListImplement/Models/Order.cs b/FishFactory/FishFactoryListImplement/Models/Order.cs index 132c8de..087e963 100644 --- a/FishFactory/FishFactoryListImplement/Models/Order.cs +++ b/FishFactory/FishFactoryListImplement/Models/Order.cs @@ -12,9 +12,9 @@ namespace FishFactoryListImplement.Models public int ClientId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } - public string CannedName { get; private set; } = string.Empty; + public int? ImplementerId { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } @@ -32,7 +32,8 @@ namespace FishFactoryListImplement.Models Sum = model.Sum, Status = model.Status, ClientId = model.ClientId, - DateCreate = model.DateCreate, + ImplementerId = model.ImplementerId, + DateCreate = model.DateCreate, DateImplement = model.DateImplement, Id = model.Id, }; @@ -45,8 +46,10 @@ namespace FishFactoryListImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; - } + ImplementerId = model.ImplementerId; + if (model.ImplementerId.HasValue) + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel => new() { @@ -54,7 +57,8 @@ namespace FishFactoryListImplement.Models Count = Count, Sum = Sum, ClientId = ClientId, - DateCreate = DateCreate, + ImplementerId = ImplementerId, + DateCreate = DateCreate, DateImplement = DateImplement, Id = Id, Status = Status, diff --git a/FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs b/FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..48d8cbf --- /dev/null +++ b/FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using Microsoft.AspNetCore.Mvc; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; + +namespace FishFactoryRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + OrderStatus = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryRestApi/Program.cs b/FishFactory/FishFactoryRestApi/Program.cs index bf6f66a..74ff857 100644 --- a/FishFactory/FishFactoryRestApi/Program.cs +++ b/FishFactory/FishFactoryRestApi/Program.cs @@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config"); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/FishFactory/FishFactoryView/FormCreateOrder.cs b/FishFactory/FishFactoryView/FormCreateOrder.cs index ce2cfc0..21be8ef 100644 --- a/FishFactory/FishFactoryView/FormCreateOrder.cs +++ b/FishFactory/FishFactoryView/FormCreateOrder.cs @@ -108,7 +108,6 @@ namespace FishFactoryView { CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue), ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), - CannedName = comboBoxCanned.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/FishFactory/FishFactoryView/FormImplementer.Designer.cs b/FishFactory/FishFactoryView/FormImplementer.Designer.cs new file mode 100644 index 0000000..03a9a3f --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementer.Designer.cs @@ -0,0 +1,178 @@ +namespace FishFactoryView +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxFio = new System.Windows.Forms.TextBox(); + this.labelQualification = new System.Windows.Forms.Label(); + this.labelWorkExperience = new System.Windows.Forms.Label(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelFIO = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(190, 135); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(89, 33); + this.buttonSave.TabIndex = 19; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(285, 135); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(89, 33); + this.buttonCancel.TabIndex = 18; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // numericUpDownQualification + // + this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownQualification.Location = new System.Drawing.Point(112, 98); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(262, 23); + this.numericUpDownQualification.TabIndex = 17; + // + // numericUpDownWorkExperience + // + this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownWorkExperience.Location = new System.Drawing.Point(112, 69); + this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + this.numericUpDownWorkExperience.Size = new System.Drawing.Size(262, 23); + this.numericUpDownWorkExperience.TabIndex = 16; + // + // textBoxPassword + // + this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxPassword.Location = new System.Drawing.Point(112, 41); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.PasswordChar = '*'; + this.textBoxPassword.Size = new System.Drawing.Size(262, 23); + this.textBoxPassword.TabIndex = 15; + // + // textBoxFio + // + this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxFio.Location = new System.Drawing.Point(112, 12); + this.textBoxFio.Name = "textBoxFio"; + this.textBoxFio.Size = new System.Drawing.Size(262, 23); + this.textBoxFio.TabIndex = 14; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(12, 98); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(88, 15); + this.labelQualification.TabIndex = 13; + this.labelQualification.Text = "Квалификация"; + // + // labelWorkExperience + // + this.labelWorkExperience.AutoSize = true; + this.labelWorkExperience.Location = new System.Drawing.Point(12, 71); + this.labelWorkExperience.Name = "labelWorkExperience"; + this.labelWorkExperience.Size = new System.Drawing.Size(35, 15); + this.labelWorkExperience.TabIndex = 12; + this.labelWorkExperience.Text = "Стаж"; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(12, 41); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(49, 15); + this.labelPassword.TabIndex = 11; + this.labelPassword.Text = "Пароль"; + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(12, 15); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(34, 15); + this.labelFIO.TabIndex = 10; + this.labelFIO.Text = "ФИО"; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(386, 180); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFio); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelWorkExperience); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExperience; + private TextBox textBoxPassword; + private TextBox textBoxFio; + private Label labelQualification; + private Label labelWorkExperience; + private Label labelPassword; + private Label labelFIO; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormImplementer.cs b/FishFactory/FishFactoryView/FormImplementer.cs new file mode 100644 index 0000000..1373d95 --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementer.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; + +namespace FishFactoryView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExperience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExperience.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormImplementer.resx b/FishFactory/FishFactoryView/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FishFactory/FishFactoryView/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/FishFactory/FishFactoryView/FormImplementers.Designer.cs b/FishFactory/FishFactoryView/FormImplementers.Designer.cs new file mode 100644 index 0000000..cc4bc7a --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementers.Designer.cs @@ -0,0 +1,122 @@ +namespace FishFactoryView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(426, 291); + this.dataGridView.TabIndex = 10; + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(446, 163); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(130, 22); + this.buttonUpdate.TabIndex = 14; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(446, 137); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(130, 22); + this.buttonDelete.TabIndex = 13; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(446, 111); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(130, 22); + this.buttonEdit.TabIndex = 12; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(446, 85); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(130, 22); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(590, 291); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormImplementers.cs b/FishFactory/FishFactoryView/FormImplementers.cs new file mode 100644 index 0000000..16c5b4e --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementers.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using System.Windows.Forms; + +namespace FishFactoryView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormImplementers.resx b/FishFactory/FishFactoryView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FishFactory/FishFactoryView/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/FishFactory/FishFactoryView/FormMain.Designer.cs b/FishFactory/FishFactoryView/FormMain.Designer.cs index 9a8a900..b1b89ca 100644 --- a/FishFactory/FishFactoryView/FormMain.Designer.cs +++ b/FishFactory/FishFactoryView/FormMain.Designer.cs @@ -33,14 +33,14 @@ this.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.cannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.performersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listCannedsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ComponentsByCannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.buttonUpdate = new System.Windows.Forms.Button(); + this.startOfWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button(); - this.buttonSetToDone = new System.Windows.Forms.Button(); - this.buttonSetToWork = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.menuStrip.SuspendLayout(); @@ -51,8 +51,9 @@ // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.reference_booksToolStripMenuItem, - this.reportsToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.reportsToolStripMenuItem, + this.startOfWorkToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(1086, 24); this.menuStrip.TabIndex = 0; @@ -63,35 +64,43 @@ this.reference_booksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ComponentsToolStripMenuItem, this.cannedToolStripMenuItem, - this.clientsToolStripMenuItem}); - this.reference_booksToolStripMenuItem.Name = "reference_booksToolStripMenuItem"; + this.clientsToolStripMenuItem, + this.performersToolStripMenuItem}); + this.reference_booksToolStripMenuItem.Name = "reference_booksToolStripMenuItem"; this.reference_booksToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.reference_booksToolStripMenuItem.Text = "Справочники"; // // ComponentsToolStripMenuItem // this.ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.ComponentsToolStripMenuItem.Text = "Ингредиенты"; + this.ComponentsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.ComponentsToolStripMenuItem.Text = "Компоненты"; this.ComponentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // // cannedToolStripMenuItem // this.cannedToolStripMenuItem.Name = "cannedToolStripMenuItem"; - this.cannedToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.cannedToolStripMenuItem.Text = "Консервы"; + this.cannedToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.cannedToolStripMenuItem.Text = "Консервы"; this.cannedToolStripMenuItem.Click += new System.EventHandler(this.CannedToolStripMenuItem_Click); // // clientsToolStripMenuItem // this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - this.clientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); - this.clientsToolStripMenuItem.Text = "Клиенты"; + this.clientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.clientsToolStripMenuItem.Text = "Клиенты"; this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); - // - // reportsToolStripMenuItem - // - this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + // + // performersToolStripMenuItem + // + this.performersToolStripMenuItem.Name = "performersToolStripMenuItem"; + this.performersToolStripMenuItem.Size = new System.Drawing.Size(149, 22); + this.performersToolStripMenuItem.Text = "Исполнители"; + this.performersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click); + // + // reportsToolStripMenuItem + // + this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.listCannedsToolStripMenuItem, this.ComponentsByCannedToolStripMenuItem, this.ordersListToolStripMenuItem}); @@ -119,58 +128,43 @@ this.ordersListToolStripMenuItem.Size = new System.Drawing.Size(226, 22); this.ordersListToolStripMenuItem.Text = "Список заказов"; this.ordersListToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); - // - // buttonUpdate - // - this.buttonUpdate.Location = new System.Drawing.Point(875, 318); - this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + // + // startOfWorkToolStripMenuItem + // + this.startOfWorkToolStripMenuItem.Name = "startOfWorkToolStripMenuItem"; + this.startOfWorkToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.startOfWorkToolStripMenuItem.Text = "Запуск работ"; + this.startOfWorkToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(905, 253); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(199, 58); - this.buttonUpdate.TabIndex = 12; + this.buttonUpdate.Size = new System.Drawing.Size(169, 58); + this.buttonUpdate.TabIndex = 12; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonSetToFinish - // - this.buttonSetToFinish.Location = new System.Drawing.Point(875, 256); - this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + // + // buttonSetToFinish + // + this.buttonSetToFinish.Location = new System.Drawing.Point(905, 182); + this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Name = "buttonSetToFinish"; - this.buttonSetToFinish.Size = new System.Drawing.Size(199, 58); - this.buttonSetToFinish.TabIndex = 11; + this.buttonSetToFinish.Size = new System.Drawing.Size(169, 58); + this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.UseVisualStyleBackColor = true; this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // buttonSetToDone - // - this.buttonSetToDone.Location = new System.Drawing.Point(875, 194); - this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonSetToDone.Name = "buttonSetToDone"; - this.buttonSetToDone.Size = new System.Drawing.Size(199, 58); - this.buttonSetToDone.TabIndex = 10; - this.buttonSetToDone.Text = "Заказ готов"; - this.buttonSetToDone.UseVisualStyleBackColor = true; - this.buttonSetToDone.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonSetToWork - // - this.buttonSetToWork.Location = new System.Drawing.Point(875, 132); - this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonSetToWork.Name = "buttonSetToWork"; - this.buttonSetToWork.Size = new System.Drawing.Size(199, 58); - this.buttonSetToWork.TabIndex = 9; - this.buttonSetToWork.Text = "Отдать на выполнение"; - this.buttonSetToWork.UseVisualStyleBackColor = true; - this.buttonSetToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonCreateOrder - // - this.buttonCreateOrder.Location = new System.Drawing.Point(875, 70); - this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(905, 111); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(199, 58); - this.buttonCreateOrder.TabIndex = 8; + this.buttonCreateOrder.Size = new System.Drawing.Size(169, 58); + this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); @@ -184,8 +178,8 @@ this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(854, 426); - this.dataGridView.TabIndex = 7; + this.dataGridView.Size = new System.Drawing.Size(899, 426); + this.dataGridView.TabIndex = 7; // // FormMain // @@ -194,8 +188,6 @@ this.ClientSize = new System.Drawing.Size(1086, 450); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); - this.Controls.Add(this.buttonSetToDone); - this.Controls.Add(this.buttonSetToWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip); @@ -219,8 +211,6 @@ private ToolStripMenuItem cannedToolStripMenuItem; private Button buttonUpdate; private Button buttonSetToFinish; - private Button buttonSetToDone; - private Button buttonSetToWork; private Button buttonCreateOrder; private DataGridView dataGridView; private ToolStripMenuItem reportsToolStripMenuItem; @@ -228,5 +218,7 @@ private ToolStripMenuItem ComponentsByCannedToolStripMenuItem; private ToolStripMenuItem ordersListToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; - } + private ToolStripMenuItem performersToolStripMenuItem; + private ToolStripMenuItem startOfWorkToolStripMenuItem; + } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormMain.cs b/FishFactory/FishFactoryView/FormMain.cs index 98ac062..0fb437c 100644 --- a/FishFactory/FishFactoryView/FormMain.cs +++ b/FishFactory/FishFactoryView/FormMain.cs @@ -1,8 +1,6 @@ using Microsoft.Extensions.Logging; using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; -using FishFactoryDataModels.Enums; -using FishFactoryBusinessLogic.BusinessLogics; namespace FishFactoryView { @@ -11,13 +9,15 @@ namespace FishFactoryView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) - { + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; - } + _workProcess = workProcess; + } private void FormMain_Load(object sender, EventArgs e) { LoadData(); @@ -33,7 +33,11 @@ namespace FishFactoryView dataGridView.DataSource = list; dataGridView.Columns["CannedId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; - } + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) @@ -58,7 +62,26 @@ namespace FishFactoryView form.ShowDialog(); } } - private void ButtonCreateOrder_Click(object sender, EventArgs e) + + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork(( + Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, + _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) @@ -77,14 +100,8 @@ namespace FishFactoryView { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), - CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + Id = id + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -108,14 +125,8 @@ namespace FishFactoryView { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), - CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + Id = id + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -139,14 +150,8 @@ namespace FishFactoryView { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value), - CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); + Id = id + }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); diff --git a/FishFactory/FishFactoryView/FormMain.resx b/FishFactory/FishFactoryView/FormMain.resx index af32865..6c82d08 100644 --- a/FishFactory/FishFactoryView/FormMain.resx +++ b/FishFactory/FishFactoryView/FormMain.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 1bc9bdb..258ff74 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -43,13 +43,16 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -63,6 +66,8 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + } } }