From 1c5f17c0496ff3351832d1188db52b713da54b82 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Thu, 2 May 2024 18:22:55 +0400 Subject: [PATCH] lab6 --- .../BusinessLogics/ImplementerLogic.cs | 125 +++++++++ .../BusinessLogics/OrderLogic.cs | 33 ++- .../BusinessLogics/WorkModeling.cs | 116 ++++++++ .../BindingModels/ImplementerBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 3 +- .../BusinessLogicsContracts/IWorkProcess.cs | 13 + .../SearchModels/ImplementerSearchModel.cs | 15 + .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 23 ++ .../ViewModels/OrderViewModel.cs | 5 +- .../Models/IImplementerModel.cs | 17 ++ .../Models/IOrderModel.cs | 1 + .../FishFactoryDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 87 ++++++ .../Implements/OrderStorage.cs | 55 ++-- .../20240419090853_implementer.Designer.cs | 260 ++++++++++++++++++ .../Migrations/20240419090853_implementer.cs | 69 +++++ .../20240419092837_chevl.Designer.cs | 257 +++++++++++++++++ .../Migrations/20240419092837_chevl.cs | 59 ++++ .../FishFactoryDatabaseModelSnapshot.cs | 51 +++- .../Models/Implementer.cs | 65 +++++ .../Models/Order.cs | 25 +- .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 83 ++++++ .../Implements/OrderStorage.cs | 3 + .../Models/Implementer.cs | 78 ++++++ .../FishFactoryFileImplement/Models/Order.cs | 9 + .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 103 +++++++ .../Models/Implementer.cs | 54 ++++ .../FishFactoryListImplement/Models/Order.cs | 5 + .../Controllers/ImplementerController.cs | 104 +++++++ .../FormImplementer.Designer.cs | 162 +++++++++++ .../FishFactoryView/FormImplementer.cs | 109 ++++++++ .../FishFactoryView/FormImplementer.resx | 120 ++++++++ .../FormImplementers.Designer.cs | 114 ++++++++ .../FishFactoryView/FormImplementers.cs | 125 +++++++++ .../FishFactoryView/FormImplementers.resx | 120 ++++++++ .../FishFactoryView/MainForm.Designer.cs | 58 ++-- FishFactory/FishFactoryView/MainForm.cs | 71 ++--- FishFactory/FishFactoryView/Program.cs | 9 +- 44 files changed, 2546 insertions(+), 132 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/20240419090853_implementer.Designer.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Migrations/20240419090853_implementer.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Migrations/20240419092837_chevl.Designer.cs create mode 100644 FishFactory/FishFactoryDatabaseImplement/Migrations/20240419092837_chevl.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..501a718 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,125 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ClientFIO}. Id:{ Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : + _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Id:{ Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ImplementerBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж меньше 0", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}." + + "Password:{ Password}. WorkExperience:{ WorkExperience}. Qualification:{ Qualification}. Id: { Id} ", + model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs index 840b83e..bbb1cca 100644 --- a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,14 +17,30 @@ namespace FishFactoryBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } - - public List? ReadList(OrderSearchModel? model) + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); var list = model == null ? _orderStorage.GetFullList() : @@ -53,7 +69,7 @@ namespace FishFactoryBusinessLogic.BusinessLogics public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - CheckModel(model); + CheckModel(model, false); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (element == null) { @@ -67,14 +83,17 @@ namespace FishFactoryBusinessLogic.BusinessLogics } model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; - _orderStorage.Update(model); + _orderStorage.Update(model); return true; } public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); - } + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + } public bool FinishOrder(OrderBindingModel model) { diff --git a/FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..e7f3654 --- /dev/null +++ b/FishFactory/FishFactoryBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,116 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 { Status = OrderStatus.Принят }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + + } + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + return; + await RunOrderInWork(implementer); + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + return; + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + return; + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel { Id = runOrder.Id }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning("Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..327323a --- /dev/null +++ b/FishFactory/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public string Password { get; set; } = string.Empty; + } +} diff --git a/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs index 797335a..f1d01c2 100644 --- a/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/FishFactory/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace FishFactoryContracts.BindingModels { public int Id { get; set; } public int CannedId { get; set; } + public int? ImplementerId { get; set; } = null; public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..8ffc02f --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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); + } +} diff --git a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index 0bd427b..297fc5b 100644 --- a/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,7 +12,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..130c3e3 --- /dev/null +++ b/FishFactory/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..b1ea3a9 --- /dev/null +++ b/FishFactory/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } +} diff --git a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs index c8329cc..c69f94c 100644 --- a/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs +++ b/FishFactory/FishFactoryContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using FishFactoryDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,6 +11,8 @@ namespace FishFactoryContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { 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..915256c --- /dev/null +++ b/FishFactory/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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); + } +} diff --git a/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..e086a24 --- /dev/null +++ b/FishFactory/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } = 0; + [DisplayName("Квалификация")] + public int Qualification { get; set; } = 0; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs index 815d94b..d7fc040 100644 --- a/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactory/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -14,12 +14,15 @@ namespace FishFactoryContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; public int CannedId { get; set; } [DisplayName("Консерва")] public string CannedName { 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..3ae5dec --- /dev/null +++ b/FishFactory/FishFactoryDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } + +} diff --git a/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs b/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs index a94f66b..97e3740 100644 --- a/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs +++ b/FishFactory/FishFactoryDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace FishFactoryDataModels.Models { int CannedId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs index e158968..d037fba 100644 --- a/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs +++ b/FishFactory/FishFactoryDatabaseImplement/FishFactoryDatabase.cs @@ -23,5 +23,6 @@ namespace FishFactoryDatabaseImplement public virtual DbSet CannedComponents { set; get; } 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..5f30fc9 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,87 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } + using var context = new FishFactoryDatabase(); + return context.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + return new(); + } + + public List GetFullList() + { + using var context = new FishFactoryDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs index 3f96954..75b90b0 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -17,39 +17,43 @@ namespace FishFactoryDatabaseImplement.Implements public List GetFullList() { using var context = new FishFactoryDatabase(); - return context.Orders.Select(x => AccessCannedStorage(x.GetViewModel, context)).ToList(); - } + return context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); + } public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.Id.HasValue && !model.ClientId.HasValue) - { - return new(); - } - using var context = new FishFactoryDatabase(); - if (model.Id.HasValue) - return context.Orders.Where(x => x.Id == model.Id).Select(x => AccessCannedStorage(x.GetViewModel, context)).ToList(); - else if (model.ClientId.HasValue) - return context.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AccessCannedStorage(x.GetViewModel, context)).ToList(); - else - return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AccessCannedStorage(x.GetViewModel, context)).ToList(); - } + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Status.HasValue) + { + return new(); + } + using var context = new FishFactoryDatabase(); + 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(); + else if (model.ClientId.HasValue) + return context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + else if (model.DateFrom != null) + return context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); + else + return context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).Where(x => x.Status.Equals(model.Status)).Select(x => x.GetViewModel).ToList(); + } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return null; - } - using var context = new FishFactoryDatabase(); - return AccessCannedStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context); - } + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) + { + return null; + } + 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; + return context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)?.GetViewModel; + } public OrderViewModel? Insert(OrderBindingModel model) { - var newOrder = Order.Create(model); + using var context = new FishFactoryDatabase(); + var newOrder = Order.Create(model, context); if (newOrder == null) { return null; } - using var context = new FishFactoryDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); return AccessCannedStorage(newOrder.GetViewModel, context); @@ -57,8 +61,7 @@ namespace FishFactoryDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { using var context = new FishFactoryDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == - model.Id); + var order = context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -70,7 +73,7 @@ namespace FishFactoryDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new FishFactoryDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == + var element = context.Orders.Include(x => x.Canned).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419090853_implementer.Designer.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419090853_implementer.Designer.cs new file mode 100644 index 0000000..8bc4935 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419090853_implementer.Designer.cs @@ -0,0 +1,260 @@ +// +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("20240419090853_implementer")] + partial class implementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .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("Canneds"); + }); + + 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") + .IsRequired() + .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") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + 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/20240419090853_implementer.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419090853_implementer.cs new file mode 100644 index 0000000..158806b --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419090853_implementer.cs @@ -0,0 +1,69 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class implementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0); + + 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), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = 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", + onDelete: ReferentialAction.Cascade); + } + + /// + 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/20240419092837_chevl.Designer.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419092837_chevl.Designer.cs new file mode 100644 index 0000000..37adf21 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419092837_chevl.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("20240419092837_chevl")] + partial class chevl + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .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("Canneds"); + }); + + 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/20240419092837_chevl.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419092837_chevl.cs new file mode 100644 index 0000000..f4ad6be --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Migrations/20240419092837_chevl.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class chevl : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + 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.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs b/FishFactory/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs index e0f5971..59e1033 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"); }); @@ -172,17 +204,27 @@ namespace FishFactoryDatabaseImplement.Migrations modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => { - b.HasOne("FishFactoryDatabaseImplement.Models.Canned", null) + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") .WithMany("Orders") .HasForeignKey("CannedId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("FishFactoryDatabaseImplement.Models.Client", null) + 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 => @@ -201,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..c237337 --- /dev/null +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,65 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace 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; set; } = string.Empty; + [Required] + public int Qualification { get; set; } = 0; + [Required] + public int WorkExperience { get; set; } = 0; + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = + new(); + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + }; + } +} diff --git a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs index e20606e..92f1d21 100644 --- a/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactory/FishFactoryDatabaseImplement/Models/Order.cs @@ -16,19 +16,22 @@ namespace FishFactoryDatabaseImplement.Models public int Id { get; private set; } [Required] public int ClientId { get; private set; } - [Required] - public int Count { get; private set; } + public int? ImplementerId { get; private set; } + [Required] + public int Count { get; private set; } [Required] public double Sum { get; private set; } [Required] public OrderStatus Status { get; private set; } [Required] - public DateTime DateCreate { get; private set; } + public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } [Required] public int CannedId { get; private set; } - - public static Order? Create(OrderBindingModel model) + public virtual Canned Canned { get; set; } + public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } + public static Order? Create(OrderBindingModel model, FishFactoryDatabase context) { if (model == null) { @@ -38,12 +41,15 @@ namespace FishFactoryDatabaseImplement.Models { Id = model.Id, ClientId = model.ClientId, + Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId)!, + ImplementerId = model.ImplementerId, + Implementer = model.ImplementerId.HasValue ? context.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId) : null, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, CannedId = model.CannedId, + Canned = context.Canneds.FirstOrDefault(x => x.Id == model.CannedId)!, }; } @@ -55,13 +61,18 @@ namespace FishFactoryDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { CannedId = CannedId, + CannedName = Canned.CannedName, ClientId = ClientId, - Count = Count, + ClientFIO = Client.ClientFIO, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO, + Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, diff --git a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs index bc9fa8b..c824b0e 100644 --- a/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs +++ b/FishFactory/FishFactoryFileImplement/DataFileSingleton.cs @@ -15,10 +15,12 @@ namespace FishFactoryFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string CannedFileName = "Canned.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Canneds { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -47,12 +49,14 @@ namespace FishFactoryFileImplement public void SaveCannedes() => SaveData(Canneds, CannedFileName, "Canneds", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Canneds = 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)!)!; } } } diff --git a/FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..fd0a975 --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,83 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel + model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implementers + .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO.Contains(model.ImplementerFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + return source.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => + x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs b/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs index 3d87644..d2858df 100644 --- a/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs +++ b/FishFactory/FishFactoryFileImplement/Implements/OrderStorage.cs @@ -24,6 +24,9 @@ namespace FishFactoryFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { + if (model.Id.HasValue) + return source.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel)).ToList(); + else return source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AcessDressesStorage(x.GetViewModel)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) diff --git a/FishFactory/FishFactoryFileImplement/Models/Implementer.cs b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..ca8fcbd --- /dev/null +++ b/FishFactory/FishFactoryFileImplement/Models/Implementer.cs @@ -0,0 +1,78 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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; set; } = string.Empty; + public int Qualification { get; set; } = 0; + public int WorkExperience { get; set; } = 0; + 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 + }; + 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, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString()) + ); + } +} diff --git a/FishFactory/FishFactoryFileImplement/Models/Order.cs b/FishFactory/FishFactoryFileImplement/Models/Order.cs index a30836c..8742d6e 100644 --- a/FishFactory/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactory/FishFactoryFileImplement/Models/Order.cs @@ -17,6 +17,7 @@ namespace FishFactoryFileImplement.Models public int Id { get; private set; } public int CannedId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -33,6 +34,8 @@ namespace FishFactoryFileImplement.Models { Id = model.Id, CannedId = model.CannedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -50,6 +53,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), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")?.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value, new System.Globalization.CultureInfo("en-US")), Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), @@ -70,6 +75,8 @@ namespace FishFactoryFileImplement.Models { Id = Id, CannedId = CannedId, + ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -79,6 +86,8 @@ namespace FishFactoryFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("CannedId", CannedId), + new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count), new XElement("Sum", Sum), new XElement("Status", Status - OrderStatus.Принят), diff --git a/FishFactory/FishFactoryListImplement/DataListSingleton.cs b/FishFactory/FishFactoryListImplement/DataListSingleton.cs index 8161db2..dcd496a 100644 --- a/FishFactory/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactory/FishFactoryListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace FishFactoryListImplement public List Orders { get; set; } public List Canneds { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Canneds = 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..e563ebd --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,103 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FishFactoryListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Implement in _source.Implementers) + { + result.Add(Implement.GetViewModel); + } + return result; + } + public List GetFilteredList(ImplementerSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return result; + } + foreach (var Implement in _source.Implementers) + { + if (Implement.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(Implement.GetViewModel); + } + } + return result; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var Implement in _source.Implementers) + { + if ((string.IsNullOrEmpty(model.ImplementerFIO) || Implement.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || Implement.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || Implement.Password == model.Password)) + { + return Implement.GetViewModel; + } + } + return null; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var Implement in _source.Implementers) + { + if (model.Id <= Implement.Id) + { + model.Id = Implement.Id + 1; + } + } + var newImplement = Implementer.Create(model); + if (newImplement == null) + { + return null; + } + _source.Implementers.Add(newImplement); + return newImplement.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var Implement in _source.Implementers) + { + if (model.Id == Implement.Id) + { + Implement.Update(model); + return Implement.GetViewModel; + } + } + return null; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Implementer.cs b/FishFactory/FishFactoryListImplement/Models/Implementer.cs new file mode 100644 index 0000000..e92b878 --- /dev/null +++ b/FishFactory/FishFactoryListImplement/Models/Implementer.cs @@ -0,0 +1,54 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/FishFactory/FishFactoryListImplement/Models/Order.cs b/FishFactory/FishFactoryListImplement/Models/Order.cs index d3d9f96..334c40b 100644 --- a/FishFactory/FishFactoryListImplement/Models/Order.cs +++ b/FishFactory/FishFactoryListImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace FishFactoryListImplement.Models public int Id { get; private set; } public int CannedId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -31,6 +32,8 @@ namespace FishFactoryListImplement.Models { Id = model.Id, CannedId = model.CannedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -54,6 +57,8 @@ namespace FishFactoryListImplement.Models { Id = Id, CannedId = CannedId, + ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs b/FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..1530d5f --- /dev/null +++ b/FishFactory/FishFactoryRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,104 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModels.Enums; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +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 + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int ImplementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = ImplementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id); + throw; + } + } + } +} diff --git a/FishFactory/FishFactoryView/FormImplementer.Designer.cs b/FishFactory/FishFactoryView/FormImplementer.Designer.cs new file mode 100644 index 0000000..dca6ffe --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementer.Designer.cs @@ -0,0 +1,162 @@ +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() + { + FIOTextBox = new TextBox(); + PasswordTextBox = new TextBox(); + QualificationTextBox = new TextBox(); + WorkExperienceTextBox = new TextBox(); + FIOlabel = new Label(); + PasswordLabel = new Label(); + QualificationLabel = new Label(); + WorkExperienceLabel = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // FIOTextBox + // + FIOTextBox.Location = new Point(241, 25); + FIOTextBox.Name = "FIOTextBox"; + FIOTextBox.Size = new Size(125, 27); + FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + PasswordTextBox.Location = new Point(241, 82); + PasswordTextBox.Name = "PasswordTextBox"; + PasswordTextBox.Size = new Size(125, 27); + PasswordTextBox.TabIndex = 1; + // + // QualificationTextBox + // + QualificationTextBox.Location = new Point(241, 142); + QualificationTextBox.Name = "QualificationTextBox"; + QualificationTextBox.Size = new Size(125, 27); + QualificationTextBox.TabIndex = 2; + // + // WorkExperienceTextBox + // + WorkExperienceTextBox.Location = new Point(241, 201); + WorkExperienceTextBox.Name = "WorkExperienceTextBox"; + WorkExperienceTextBox.Size = new Size(125, 27); + WorkExperienceTextBox.TabIndex = 3; + // + // FIOlabel + // + FIOlabel.AutoSize = true; + FIOlabel.Location = new Point(57, 28); + FIOlabel.Name = "FIOlabel"; + FIOlabel.Size = new Size(136, 20); + FIOlabel.TabIndex = 4; + FIOlabel.Text = "ФИО исполнителя"; + // + // PasswordLabel + // + PasswordLabel.AutoSize = true; + PasswordLabel.Location = new Point(57, 85); + PasswordLabel.Name = "PasswordLabel"; + PasswordLabel.Size = new Size(62, 20); + PasswordLabel.TabIndex = 5; + PasswordLabel.Text = "Пароль"; + // + // QualificationLabel + // + QualificationLabel.AutoSize = true; + QualificationLabel.Location = new Point(57, 145); + QualificationLabel.Name = "QualificationLabel"; + QualificationLabel.Size = new Size(111, 20); + QualificationLabel.TabIndex = 6; + QualificationLabel.Text = "Квалификация"; + // + // WorkExperienceLabel + // + WorkExperienceLabel.AutoSize = true; + WorkExperienceLabel.Location = new Point(57, 204); + WorkExperienceLabel.Name = "WorkExperienceLabel"; + WorkExperienceLabel.Size = new Size(99, 20); + WorkExperienceLabel.TabIndex = 7; + WorkExperienceLabel.Text = "Стаж работы"; + // + // buttonSave + // + buttonSave.Location = new Point(241, 283); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(359, 283); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(481, 324); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(WorkExperienceLabel); + Controls.Add(QualificationLabel); + Controls.Add(PasswordLabel); + Controls.Add(FIOlabel); + Controls.Add(WorkExperienceTextBox); + Controls.Add(QualificationTextBox); + Controls.Add(PasswordTextBox); + Controls.Add(FIOTextBox); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private TextBox QualificationTextBox; + private TextBox WorkExperienceTextBox; + private Label FIOlabel; + private Label PasswordLabel; + private Label QualificationLabel; + private Label WorkExperienceLabel; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormImplementer.cs b/FishFactory/FishFactoryView/FormImplementer.cs new file mode 100644 index 0000000..4033408 --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementer.cs @@ -0,0 +1,109 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 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) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationTextBox.Text = view.Qualification.ToString(); + WorkExperienceTextBox.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = Convert.ToInt32(QualificationTextBox.Text), + WorkExperience = Convert.ToInt32(WorkExperienceTextBox.Text), + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormImplementer.resx b/FishFactory/FishFactoryView/FormImplementer.resx new file mode 100644 index 0000000..a395bff --- /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..e963889 --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementers.Designer.cs @@ -0,0 +1,114 @@ +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() + { + dataGridView = new DataGridView(); + buttonCreate = new Button(); + buttonChange = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, -1); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(626, 452); + dataGridView.TabIndex = 0; + // + // buttonCreate + // + buttonCreate.Location = new Point(667, 51); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonChange + // + buttonChange.Location = new Point(667, 118); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(94, 29); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(667, 189); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(667, 269); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormImplementers"; + Text = "Список исполнителей"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreate; + private Button buttonChange; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/FishFactory/FishFactoryView/FormImplementers.cs b/FishFactory/FishFactoryView/FormImplementers.cs new file mode 100644 index 0000000..0ef3f47 --- /dev/null +++ b/FishFactory/FishFactoryView/FormImplementers.cs @@ -0,0 +1,125 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 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; + dataGridView.Columns["Password"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Qualification"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["WorkExperience"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/FishFactory/FishFactoryView/FormImplementers.resx b/FishFactory/FishFactoryView/FormImplementers.resx new file mode 100644 index 0000000..a395bff --- /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/MainForm.Designer.cs b/FishFactory/FishFactoryView/MainForm.Designer.cs index c4db1b3..ba77f05 100644 --- a/FishFactory/FishFactoryView/MainForm.Designer.cs +++ b/FishFactory/FishFactoryView/MainForm.Designer.cs @@ -30,8 +30,6 @@ { dataGridView = new DataGridView(); button1 = new Button(); - button2 = new Button(); - button3 = new Button(); button4 = new Button(); button5 = new Button(); menuStrip1 = new MenuStrip(); @@ -39,10 +37,12 @@ компонентыToolStripMenuItem = new ToolStripMenuItem(); консервыToolStripMenuItem = new ToolStripMenuItem(); ClientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementerToolStripMenuItem = new ToolStripMenuItem(); otchetToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ComponentCannedToolStripMenuItem = new ToolStripMenuItem(); OrdersToolStripMenuItem = new ToolStripMenuItem(); + StartingWorkToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -67,29 +67,9 @@ button1.UseVisualStyleBackColor = true; button1.Click += ButtonCreateOrder_Click; // - // button2 - // - button2.Location = new Point(885, 117); - button2.Name = "button2"; - button2.Size = new Size(179, 29); - button2.TabIndex = 3; - button2.Text = "Отдать на выполнение"; - button2.UseVisualStyleBackColor = true; - button2.Click += ButtonTakeOrderInWork_Click; - // - // button3 - // - button3.Location = new Point(885, 185); - button3.Name = "button3"; - button3.Size = new Size(179, 29); - button3.TabIndex = 4; - button3.Text = "Заказ готов"; - button3.UseVisualStyleBackColor = true; - button3.Click += ButtonOrderReady_Click; - // // button4 // - button4.Location = new Point(885, 254); + button4.Location = new Point(885, 133); button4.Name = "button4"; button4.Size = new Size(179, 29); button4.TabIndex = 5; @@ -99,7 +79,7 @@ // // button5 // - button5.Location = new Point(885, 321); + button5.Location = new Point(885, 206); button5.Name = "button5"; button5.Size = new Size(179, 29); button5.TabIndex = 6; @@ -110,7 +90,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { spravochnikToolStripMenuItem, otchetToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { spravochnikToolStripMenuItem, otchetToolStripMenuItem, StartingWorkToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1076, 28); @@ -119,7 +99,7 @@ // // spravochnikToolStripMenuItem // - spravochnikToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, ClientsToolStripMenuItem }); + spravochnikToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, ClientsToolStripMenuItem, ImplementerToolStripMenuItem }); spravochnikToolStripMenuItem.Name = "spravochnikToolStripMenuItem"; spravochnikToolStripMenuItem.Size = new Size(117, 24); spravochnikToolStripMenuItem.Text = "Справочники"; @@ -127,24 +107,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(185, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; // // консервыToolStripMenuItem // консервыToolStripMenuItem.Name = "консервыToolStripMenuItem"; - консервыToolStripMenuItem.Size = new Size(224, 26); + консервыToolStripMenuItem.Size = new Size(185, 26); консервыToolStripMenuItem.Text = "Консервы"; консервыToolStripMenuItem.Click += CannedToolStripMenuItem_Click; // // ClientsToolStripMenuItem // ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(224, 26); + ClientsToolStripMenuItem.Size = new Size(185, 26); ClientsToolStripMenuItem.Text = "Клиенты"; ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; // + // ImplementerToolStripMenuItem + // + ImplementerToolStripMenuItem.Name = "ImplementerToolStripMenuItem"; + ImplementerToolStripMenuItem.Size = new Size(185, 26); + ImplementerToolStripMenuItem.Text = "Исполнители"; + ImplementerToolStripMenuItem.Click += ImplementerToolStripMenuItem_Click; + // // otchetToolStripMenuItem // otchetToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ComponentCannedToolStripMenuItem, OrdersToolStripMenuItem }); @@ -173,6 +160,13 @@ OrdersToolStripMenuItem.Text = "Список заказов"; OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; // + // StartingWorkToolStripMenuItem + // + StartingWorkToolStripMenuItem.Name = "StartingWorkToolStripMenuItem"; + StartingWorkToolStripMenuItem.Size = new Size(114, 24); + StartingWorkToolStripMenuItem.Text = "Запуск работ"; + StartingWorkToolStripMenuItem.Click += StartingWorkToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -180,8 +174,6 @@ ClientSize = new Size(1076, 487); Controls.Add(button5); Controls.Add(button4); - Controls.Add(button3); - Controls.Add(button2); Controls.Add(button1); Controls.Add(dataGridView); Controls.Add(menuStrip1); @@ -199,8 +191,6 @@ #endregion private DataGridView dataGridView; private Button button1; - private Button button2; - private Button button3; private Button button4; private Button button5; private MenuStrip menuStrip1; @@ -212,5 +202,7 @@ private ToolStripMenuItem ComponentCannedToolStripMenuItem; private ToolStripMenuItem OrdersToolStripMenuItem; private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem StartingWorkToolStripMenuItem; + private ToolStripMenuItem ImplementerToolStripMenuItem; } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/MainForm.cs b/FishFactory/FishFactoryView/MainForm.cs index 267902e..9479486 100644 --- a/FishFactory/FishFactoryView/MainForm.cs +++ b/FishFactory/FishFactoryView/MainForm.cs @@ -11,12 +11,14 @@ namespace FishFactoryView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public MainForm(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) { @@ -32,9 +34,8 @@ namespace FishFactoryView { dataGridView.DataSource = list; dataGridView.Columns["CannedId"].Visible = false; - dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; - dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation(" "); } @@ -72,55 +73,6 @@ namespace FishFactoryView LoadData(); } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" {id}. ' '", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception(" . ."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation(" {id}. ''", - id); - try - { - var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception(" . ."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, -MessageBoxIcon.Error); - } - } - } private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -197,5 +149,20 @@ MessageBoxIcon.Error); form.ShowDialog(); } } + private void ImplementerToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + private void StartingWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic + )) as IImplementerLogic)!, _orderLogic); + MessageBox.Show(" ", "", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } \ No newline at end of file diff --git a/FishFactory/FishFactoryView/Program.cs b/FishFactory/FishFactoryView/Program.cs index 2e90769..824c20f 100644 --- a/FishFactory/FishFactoryView/Program.cs +++ b/FishFactory/FishFactoryView/Program.cs @@ -45,7 +45,10 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,6 +61,8 @@ namespace FishFactoryView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file