From 21d4d9350b2d1c4ecbb0235835da8885b066a36f Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sat, 27 Apr 2024 22:33:15 +0400 Subject: [PATCH 1/5] not done --- .../BusinessLogics/ImplementerLogic.cs | 128 +++++++++++++ .../BusinessLogics/WorkModeling.cs | 138 ++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 22 +++ .../BindingModels/OrderBindingModel .cs | 1 + .../IImplementerLogic.cs | 24 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 10 + .../SearchModels/ImplementerSearchModel.cs | 17 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 26 +++ .../ViewModels/ImplementerViewModel.cs | 26 +++ .../ViewModels/OrderViewModel.cs | 5 + .../ViewModels/ReportOrdersViewModel.cs | 2 +- .../Models/IImplementerModel.cs | 13 ++ .../Models/IOrderModel.cs | 2 +- .../CarpentryWorkshopDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 84 ++++++++ .../Implements/OrderStorage.cs | 179 +++++++++++------- .../Models/Implementer.cs | 70 +++++++ .../Models/Order.cs | 83 ++++---- .../Controllers/ImplementerController.cs | 107 +++++++++++ .../FormImplementer.Designer.cs | 169 +++++++++++++++++ .../CarpentryWorkshopView/FormImplementer.cs | 101 ++++++++++ .../FormImplementer.resx | 60 ++++++ .../FormImplementers.Designer.cs | 117 ++++++++++++ .../CarpentryWorkshopView/FormImplementers.cs | 112 +++++++++++ .../FormImplementers.resx | 120 ++++++++++++ .../FormMain.Designer.cs | 20 +- .../CarpentryWorkshopView/FormMain.cs | 17 +- 29 files changed, 1554 insertions(+), 106 deletions(-) create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IImplementerModel.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.resx create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.Designer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.resx diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..e858ec0 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,128 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Id:{ Id}", model?.ImplementerFIO, model?.Password?.Length, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж должен быть больше 0", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentNullException("Квалификация должна быть положительной", 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/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..5861f64 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,138 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace CarpentryWorkshopBusinessLogic.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 { Statuses = new() { OrderStatus.Принят } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = order.Id, ImplementerId = implementer.Id }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ImplementerBindingModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..cba7740 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel .cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel .cs index 6422938..ea6b70f 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel .cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BindingModels/OrderBindingModel .cs @@ -13,6 +13,7 @@ namespace CarpentryWorkshopContracts.BindingModels public int Id { get; set; } public int WoodId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public string WoodName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..6bc3a5a --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.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/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs index 99635fc..2a94536 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace CarpentryWorkshopContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..fd5c1dc --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,10 @@ +namespace CarpentryWorkshopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ImplementerSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..a4d12a7 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs index b800bf9..fc8b449 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using CarpentryWorkshopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace CarpentryWorkshopContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IImplementerStorage.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..b3ae156 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.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/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..5b0073d --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopContracts.ViewModels +{ + public class ImplementerViewModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs index c8999a1..11f6d68 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs @@ -15,8 +15,13 @@ namespace CarpentryWorkshopContracts.ViewModels public int Id { get; set; } public int WoodId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Фамилия клиента")] public string ClientFIO { get; set; } = string.Empty; + + [DisplayName("Фамилия исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Изделие")] public string WoodName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ReportOrdersViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ReportOrdersViewModel.cs index 06c2ff1..f3f17e4 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ReportOrdersViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/ReportOrdersViewModel.cs @@ -11,6 +11,6 @@ namespace CarpentryWorkshopContracts.ViewModels public string WoodName { get; set; } = string.Empty; public double Sum { get; set; } - public string Status { get; set; } + public string Status { get; set; } = string.Empty ; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IImplementerModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..dfad816 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,13 @@ +namespace CarpentryWorkshopDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs index 1a270d5..3bb7dbb 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDataModels/Models/IOrderModel.cs @@ -11,7 +11,7 @@ namespace CarpentryWorkshopDataModels.Models { int WoodId { get; } int ClientId { get; } - string WoodName{ get;} + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs index c8d5883..0537949 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs @@ -23,5 +23,6 @@ namespace CarpentryWorkshopDatabaseImplement public virtual DbSet WoodComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/ImplementerStorage.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..54677d6 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new CarpentryWorkshopDatabase(); + var implementer = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (implementer != null) + { + context.Implementers.Remove(implementer); + context.SaveChanges(); + return implementer.GetViewModel; + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + using var context = new CarpentryWorkshopDatabase(); + return context.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new CarpentryWorkshopDatabase(); + return context.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new CarpentryWorkshopDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new CarpentryWorkshopDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new CarpentryWorkshopDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/OrderStorage.cs index 212b758..a6ead0e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -9,97 +9,138 @@ namespace CarpentryWorkshopDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - public List GetFullList() - { - using var context = new CarpentryWorkshopDatabase(); - return context.Orders - .Include(x => x.Wood) - .Include(x => x.Client) - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue) - { - return new(); - } - using var context = new CarpentryWorkshopDatabase(); - if (model.ClientId.HasValue) - { - return context.Orders - .Include(x => x.Wood) - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); - } - if (model.DateFrom.HasValue) - { - return context.Orders.Include(x => x.Wood) - .Include(x => x.Client) - .Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)) - .Select(x => x.GetViewModel) - .ToList(); - } - return context.Orders.Include(x => x.Wood) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (model.Id == null && !model.Id.HasValue) - { - return null; - } - using var context = new CarpentryWorkshopDatabase(); - return context.Orders.Include(x => x.Wood).Include(x => x.Client) - .FirstOrDefault(x => (model.Id != null && x.Id == model.Id) || (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - using var context = new CarpentryWorkshopDatabase(); - context.Orders.Add(newOrder); - context.SaveChanges(); - return context.Orders - .Include(x => x.Wood) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == newOrder.Id) - ?.GetViewModel; - } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new CarpentryWorkshopDatabase(); - var element = context.Orders.Include(x => x.Wood).Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id); + + var element = context.Orders + .Include(x => x.Wood) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) { context.Orders.Remove(element); context.SaveChanges(); + return element.GetViewModel; } + return null; } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new CarpentryWorkshopDatabase(); + + return context.Orders + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || + model.Id.HasValue && x.Id == model.Id + ) + ?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (model.Id.HasValue) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + using var context = new CarpentryWorkshopDatabase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { + queryWhere = context.Orders + .Where(x => model.DateFrom <= x.DateCreate.Date && + x.DateCreate.Date <= model.DateTo); + } + + else if (model.Statuses != null) + { + queryWhere = context.Orders.Where(x => model.Statuses.Contains(x.Status)); + } + + else if (model.ClientId.HasValue) + { + queryWhere = context.Orders.Where(x => x.ClientId == model.ClientId); + } + + else + { + return new(); + } + + return queryWhere + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new CarpentryWorkshopDatabase(); + + return context.Orders + .Include(x => x.Wood) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + using var context = new CarpentryWorkshopDatabase(); + + context.Orders.Add(newOrder); + context.SaveChanges(); + + return context.Orders + .Include(x => x.Wood) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id) + ?.GetViewModel; + } - // public OrderViewModel? Update(OrderBindingModel model) { using var context = new CarpentryWorkshopDatabase(); - var order = context.Orders.Include(x => x.Wood).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id); + + var order = context.Orders + .Include(x => x.Wood) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id); + if (order == null) { return null; } + order.Update(model); context.SaveChanges(); + return order.GetViewModel; } } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..b3d362b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,70 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.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 CarpentryWorkshopDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List Order { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs index 4f850e7..1e01930 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs @@ -2,33 +2,43 @@ using CarpentryWorkshopContracts.ViewModels; using CarpentryWorkshopDataModels.Enums; using CarpentryWorkshopDataModels.Models; -using CarpentryWorkshopDatabaseImplement.Models; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Reflection.Metadata; namespace CarpentryWorkshopDatabaseImplement.Models { public class Order : IOrderModel { - public int Id { get; set; } + public int Id { get; private set; } + [ForeignKey("WoodId")] + public int WoodId { get; private set; } + [ForeignKey("ImplementerId")] + public int? ImplementerId { get; private set; } + [ForeignKey("ClientId")] [Required] - public int WoodId { get; set; } - [Required] - public int ClientId { get; private set; } - [Required] - public string WoodName { get; set; } = string.Empty; - [Required] - public int Count { get; set; } - [Required] - public double Sum { get; set; } - [Required] - public OrderStatus Status { get; set; } - [Required] - public DateTime DateCreate { get; set; } + public int ClientId { get; set; } + + [Required] + public int Count { get; private set; } + + [Required] + public double Sum { get; private set; } + + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } - public DateTime? DateImplement { get; set; } public virtual Wood Wood { get; set; } - public virtual Client Client { get; set; } + public Client Client { get; set; } + + public Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -36,12 +46,13 @@ namespace CarpentryWorkshopDatabaseImplement.Models { return null; } + return new Order() { Id = model.Id, WoodId = model.WoodId, ClientId = model.ClientId, - WoodName = model.WoodName, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -56,24 +67,32 @@ namespace CarpentryWorkshopDatabaseImplement.Models { return; } - Status = model.Status; - DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } - public OrderViewModel GetViewModel => new() + public OrderViewModel GetViewModel { - Id = Id, - WoodId = WoodId, - ClientId = ClientId, - ClientFIO = Client.ClientFIO, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - WoodName = Wood.WoodName - }; + get + { + using var context = new CarpentryWorkshopDatabase(); + return new OrderViewModel + { + Id = Id, + WoodId = WoodId, + ClientId = ClientId, + ImplementerId = ImplementerId, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + WoodName = context.Woods.FirstOrDefault(x => x.Id == WoodId)?.WoodName ?? string.Empty, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty + }; + } + } } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..61675ab --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.ViewModels; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace CarpentryWorkshopRestApi.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/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.Designer.cs new file mode 100644 index 0000000..4bea7c9 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.Designer.cs @@ -0,0 +1,169 @@ +namespace CarpentryWorkshopView +{ + 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() + { + labelFIO = new Label(); + labelPassword = new Label(); + labelWorkExperience = new Label(); + labelQualification = new Label(); + textBoxPassword = new TextBox(); + textBoxFIO = new TextBox(); + textBoxWorkExperience = new TextBox(); + textBoxQualification = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(10, 11); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(34, 15); + labelFIO.TabIndex = 0; + labelFIO.Text = "ФИО"; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(10, 36); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(49, 15); + labelPassword.TabIndex = 1; + labelPassword.Text = "Пароль"; + // + // labelWorkExperience + // + labelWorkExperience.AutoSize = true; + labelWorkExperience.Location = new Point(10, 61); + labelWorkExperience.Name = "labelWorkExperience"; + labelWorkExperience.Size = new Size(79, 15); + labelWorkExperience.TabIndex = 2; + labelWorkExperience.Text = "Стаж работы"; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(10, 86); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(88, 15); + labelQualification.TabIndex = 3; + labelQualification.Text = "Квалификация"; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(113, 34); + textBoxPassword.Margin = new Padding(3, 2, 3, 2); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(211, 23); + textBoxPassword.TabIndex = 4; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(113, 9); + textBoxFIO.Margin = new Padding(3, 2, 3, 2); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(211, 23); + textBoxFIO.TabIndex = 5; + // + // textBoxWorkExperience + // + textBoxWorkExperience.Location = new Point(113, 58); + textBoxWorkExperience.Margin = new Padding(3, 2, 3, 2); + textBoxWorkExperience.Name = "textBoxWorkExperience"; + textBoxWorkExperience.Size = new Size(211, 23); + textBoxWorkExperience.TabIndex = 6; + // + // textBoxQualification + // + textBoxQualification.Location = new Point(113, 83); + textBoxQualification.Margin = new Padding(3, 2, 3, 2); + textBoxQualification.Name = "textBoxQualification"; + textBoxQualification.Size = new Size(209, 23); + textBoxQualification.TabIndex = 7; + // + // buttonSave + // + buttonSave.Location = new Point(147, 110); + buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(89, 22); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(242, 110); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(82, 22); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(334, 140); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxQualification); + Controls.Add(textBoxWorkExperience); + Controls.Add(textBoxFIO); + Controls.Add(textBoxPassword); + Controls.Add(labelQualification); + Controls.Add(labelWorkExperience); + Controls.Add(labelPassword); + Controls.Add(labelFIO); + Margin = new Padding(3, 2, 3, 2); + Name = "FormImplementer"; + StartPosition = FormStartPosition.CenterParent; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelFIO; + private Label labelPassword; + private Label labelWorkExperience; + private Label labelQualification; + private TextBox textBoxPassword; + private TextBox textBoxFIO; + private TextBox textBoxWorkExperience; + private TextBox textBoxQualification; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.cs new file mode 100644 index 0000000..7bd8fe3 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.cs @@ -0,0 +1,101 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + textBoxQualification.Text = view.Qualification.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.Designer.cs new file mode 100644 index 0000000..5a336c7 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.Designer.cs @@ -0,0 +1,117 @@ +namespace CarpentryWorkshopView +{ + 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() + { + dataGridViewImplementers = new DataGridView(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewImplementers).BeginInit(); + SuspendLayout(); + // + // dataGridViewImplementers + // + dataGridViewImplementers.BackgroundColor = SystemColors.ControlLightLight; + dataGridViewImplementers.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewImplementers.Location = new Point(1, 1); + dataGridViewImplementers.Name = "dataGridViewImplementers"; + dataGridViewImplementers.RowHeadersVisible = false; + dataGridViewImplementers.RowHeadersWidth = 51; + dataGridViewImplementers.RowTemplate.Height = 29; + dataGridViewImplementers.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewImplementers.Size = new Size(650, 402); + dataGridViewImplementers.TabIndex = 0; + // + // buttonRef + // + buttonRef.Location = new Point(668, 117); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(102, 29); + buttonRef.TabIndex = 1; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(668, 82); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(102, 29); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(668, 47); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(102, 29); + buttonUpd.TabIndex = 3; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(668, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(102, 29); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(782, 403); + Controls.Add(buttonAdd); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonRef); + Controls.Add(dataGridViewImplementers); + Name = "FormImplementers"; + StartPosition = FormStartPosition.CenterParent; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewImplementers).EndInit(); + ResumeLayout(false); + } + + #endregion + private DataGridView dataGridViewImplementers; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs new file mode 100644 index 0000000..f2c9230 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.cs @@ -0,0 +1,112 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.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 CarpentryWorkshopView +{ + 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) + { + dataGridViewImplementers.DataSource = list; + dataGridViewImplementers.Columns["Id"].Visible = false; + dataGridViewImplementers.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewImplementers.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridViewImplementers.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == + DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewImplementers.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.resx b/CarpentryWorkshop/CarpentryWorkshopView/FormImplementers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopView/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/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs index f427b7c..4005e1e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.Designer.cs @@ -37,6 +37,8 @@ списокИзделийToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); ButtonCreateOrder = new Button(); ButtonTakeOrderInWork = new Button(); @@ -49,7 +51,7 @@ // // menuStrip1 // - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem, исполнителиToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1174, 24); @@ -112,6 +114,20 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(92, 20); + запускРаботToolStripMenuItem.Text = "Запуск Работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(94, 20); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // // dataGridView // dataGridView.BackgroundColor = SystemColors.ButtonHighlight; @@ -212,5 +228,7 @@ private ToolStripMenuItem списокКомпонентовПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs index 920eee9..7cde27c 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs @@ -19,12 +19,14 @@ namespace CarpentryWorkshopView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) { @@ -182,5 +184,18 @@ namespace CarpentryWorkshopView form.ShowDialog(); } } + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } } } -- 2.25.1 From 0e4d318a5f1c4f9747bea6aabbf7224e27c80bac Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sat, 27 Apr 2024 22:47:04 +0400 Subject: [PATCH 2/5] Ordlogic --- .../BusinessLogics/OrderLogic.cs | 203 ++++++++++-------- 1 file changed, 116 insertions(+), 87 deletions(-) diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 9cc613c..665e281 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,121 +17,150 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var vmodel = _orderStorage.GetElement(new() { Id = model.Id }); + + if (vmodel == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if ((int)vmodel.Status + 1 != (int)newStatus) + { + throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " + + $"Текущий статус: {vmodel.Status} \n" + + $"Планируемый статус: {newStatus} \n" + + $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}"); + } + + model.Status = newStatus; + model.DateCreate = vmodel.DateCreate; + + if (model.DateImplement == null) + model.DateImplement = vmodel.DateImplement; + + if (vmodel.ImplementerId.HasValue) + model.ImplementerId = vmodel.ImplementerId; + + model.WoodId = vmodel.WoodId; + model.Sum = vmodel.Sum; + model.Count = vmodel.Count; + + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + model.DateImplement = DateTime.Now; + return StatusUpdate(model, OrderStatus.Готов); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + _logger.LogInformation("Order. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool CreateOrder(OrderBindingModel model) + + private bool CheckModel(OrderBindingModel model) { - _orderStorage.Insert(new OrderBindingModel + if (model == null) { - WoodId = model.WoodId, - ClientId = model.ClientId, - WoodName = model.WoodName, - Count = model.Count, - Sum = model.Sum, - Status = OrderStatus.Принят, - DateCreate = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc) - }); ; + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentException("Суммарная стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateCreate > model.DateImplement) + { + throw new ArgumentException("Время создания заказа не может быть больше времени его выполнения", nameof(model.DateImplement)); + } + return true; } - public bool TakeOrderInWork(OrderBindingModel model) + + public OrderViewModel? ReadElement(OrderSearchModel model) { - var order = _orderStorage.GetElement(new OrderSearchModel + if (model == null) { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Элемент не найден"); - } - if (order.Status.ToString() != "Принят") - { - throw new Exception("Заказ не в статусе \"Принят\""); - } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - - Status = OrderStatus.Выполняется - }); - return true; - } - public bool FinishOrder(OrderBindingModel model) - { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Не найден заказ"); - } - if (order.Status.ToString() != "Выполняется") - { - throw new Exception("Заказ не в статусе \"Выполняется\""); - } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), - Status = OrderStatus.Готов - }); - return true; - } - public bool DeliveryOrder(OrderBindingModel model) - { - var order = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (order == null) - { - throw new Exception("Не найден заказ"); + throw new ArgumentNullException(nameof(model)); } - if (order.Status.ToString() != "Готов") + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + + var element = _orderStorage.GetElement(model); + + if (element == null) { - throw new Exception("Заказ не в статусе \"Готов\""); + _logger.LogWarning("ReadElement element not found"); + + return null; } - _orderStorage.Update(new OrderBindingModel - { - Id = order.Id, - WoodId = order.WoodId, - WoodName = order.WoodName, - Count = order.Count, - Sum = order.Sum, - DateCreate = order.DateCreate, - DateImplement = order.DateImplement, - Status = OrderStatus.Выдан - }); - return true; + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; } } } - -- 2.25.1 From 0c0ee234cf71df5e354610f6c0f98606b6685079 Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sat, 27 Apr 2024 23:21:07 +0400 Subject: [PATCH 3/5] need some fixes --- .../BusinessLogics/OrderLogic.cs | 2 +- ... 20240427190111_InitialCreate.Designer.cs} | 49 +++- ...ate.cs => 20240427190111_InitialCreate.cs} | 31 ++- .../CarpentryWorkshopDatabaseModelSnapshot.cs | 47 +++- .../DataFileSingleton.cs | 8 +- .../Implements/ImplementerStorage.cs | 92 ++++++++ .../Implements/OrderStorage.cs | 177 +++++++++------ .../Models/Implementer.cs | 85 +++++++ .../Models/Order.cs | 61 +++-- .../DataListSingleton.cs | 3 + .../Implements/ImplementerStorage.cs | 126 +++++++++++ .../Implements/OrderStorage.cs | 211 +++++++++++------- .../Models/Implementer.cs | 56 +++++ .../Models/Order.cs | 26 ++- .../CarpentryWorkshopView/Program.cs | 5 + 15 files changed, 787 insertions(+), 192 deletions(-) rename CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/{20240416072714_InitialCreate.Designer.cs => 20240427190111_InitialCreate.Designer.cs} (83%) rename CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/{20240416072714_InitialCreate.cs => 20240427190111_InitialCreate.cs} (82%) create mode 100644 CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs create mode 100644 CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs diff --git a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 665e281..f0f1b72 100644 --- a/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/CarpentryWorkshop/CarpentryWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -93,7 +93,7 @@ namespace CarpentryWorkshopBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { - model.DateImplement = DateTime.Now; + model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); return StatusUpdate(model, OrderStatus.Готов); } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs similarity index 83% rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.Designer.cs rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs index 7f314d6..1024bdf 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace CarpentryWorkshopDatabaseImplement.Migrations { [DbContext(typeof(CarpentryWorkshopDatabase))] - [Migration("20240416072714_InitialCreate")] + [Migration("20240427190111_InitialCreate")] partial class InitialCreate { /// @@ -70,6 +70,33 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -90,6 +117,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp with time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -99,14 +129,12 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Property("WoodId") .HasColumnType("integer"); - b.Property("WoodName") - .IsRequired() - .HasColumnType("text"); - b.HasKey("Id"); b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("WoodId"); b.ToTable("Orders"); @@ -166,6 +194,10 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood") .WithMany("Orders") .HasForeignKey("WoodId") @@ -174,6 +206,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Wood"); }); @@ -206,6 +240,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Navigation("WoodComponents"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b => { b.Navigation("Components"); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs similarity index 82% rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.cs rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs index 4feb6c9..9c8122e 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240416072714_InitialCreate.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs @@ -41,6 +41,22 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ImplementerFIO = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + WorkExperience = table.Column(type: "integer", nullable: false), + Qualification = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Woods", columns: table => new @@ -62,8 +78,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), WoodId = table.Column(type: "integer", nullable: false), + ImplementerId = table.Column(type: "integer", nullable: true), ClientId = table.Column(type: "integer", nullable: false), - WoodName = table.Column(type: "text", nullable: false), Count = table.Column(type: "integer", nullable: false), Sum = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), @@ -79,6 +95,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Woods_WoodId", column: x => x.WoodId, @@ -119,6 +140,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_WoodId", table: "Orders", @@ -147,6 +173,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs index 6e88e54..6300d49 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/CarpentryWorkshopDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp with time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -96,14 +126,12 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Property("WoodId") .HasColumnType("integer"); - b.Property("WoodName") - .IsRequired() - .HasColumnType("text"); - b.HasKey("Id"); b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("WoodId"); b.ToTable("Orders"); @@ -163,6 +191,10 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.HasOne("CarpentryWorkshopDatabaseImplement.Models.Wood", "Wood") .WithMany("Orders") .HasForeignKey("WoodId") @@ -171,6 +203,8 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Wood"); }); @@ -203,6 +237,11 @@ namespace CarpentryWorkshopDatabaseImplement.Migrations b.Navigation("WoodComponents"); }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("CarpentryWorkshopDatabaseImplement.Models.Wood", b => { b.Navigation("Components"); diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs index 09b1a3b..26101b1 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/DataFileSingleton.cs @@ -10,10 +10,12 @@ namespace CarpentryWorkshopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string WoodFileName = "Wood.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 Woods { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -25,12 +27,16 @@ namespace CarpentryWorkshopFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveWoods() => SaveData(Woods, WoodFileName, "Woods", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); + public void 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)!)!; Woods = LoadData(WoodFileName, "Wood", x => Wood.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..22eeb7e --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,92 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarpentryWorkshopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && + !string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs index f27f914..edc59b8 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Implements/OrderStorage.cs @@ -14,99 +14,128 @@ namespace CarpentryWorkshopFileImplement.Implements public class OrderStorage : IOrderStorage { private readonly DataFileSingleton source; + public OrderStorage() { source = DataFileSingleton.GetInstance(); } - public List GetFullList() - { - return source.Orders.Select(x => GetViewModel(x)).ToList(); - } - public List GetFilteredList(OrderSearchModel model) - { - if (!model.Id.HasValue && !model.DateFrom.HasValue) - { - return source.Orders - .Where(x => model.DateFrom <= x.DateCreate.Date && x.DateCreate <= model.DateTo) - .Select(x => GetViewModel(x)) - .ToList(); - } - if (model.DateFrom.HasValue) - { - return source.Orders - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); - } - return source.Orders - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (model.Id == null && !model.Id.HasValue) - { - return null; - } - return source.Orders - .FirstOrDefault(x => (model.Id != null && x.Id == model.Id) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); if (newOrder == null) - { - return null; - } - source.Orders.Add(newOrder); - source.SaveOrders(); - return newOrder.GetViewModel; - } - public OrderViewModel? Update(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - source.SaveOrders(); - return order.GetViewModel; - } + public OrderViewModel? Delete(OrderBindingModel model) { var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) { source.Orders.Remove(element); source.SaveOrders(); + return element.GetViewModel; } + return null; } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statuses.Contains(x.Status)) + ?.GetViewModel; + } + + if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) + ?.GetViewModel; + } + + if (!model.Id.HasValue) + { + return null; + } + + return source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var comp in source.Woods) - { - if (comp.Id == order.WoodId) - { - viewModel.WoodName = comp.WoodName; - break; - } - } - foreach (var client in source.Clients) - { - if (client.Id == order.ClientId) - { - viewModel.ClientFIO = client.ClientFIO; - break; - } - } + + var wood = source + .Woods.FirstOrDefault(x => x.Id == order.WoodId); + + var client = source + .Clients.FirstOrDefault(x => x.Id == order.ClientId); + + if (wood != null) + viewModel.WoodName = wood.WoodName; + + if (client != null) + viewModel.ClientFIO = client.ClientFIO; + return viewModel; } + public List GetFilteredList(OrderSearchModel model) + { + if (model.DateFrom.HasValue) + return source.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)) + .ToList(); + + if (model.ClientId.HasValue && !model.Id.HasValue) + return source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + + if (model.Id.HasValue) + return source.Orders + .Where(x => x.Id.Equals(model.Id)) + .Select(x => GetViewModel(x)) + .ToList(); + + return new(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + source.Orders.Add(newOrder); + source.SaveOrders(); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (order == null) + { + return null; + } + + order.Update(model); + source.SaveOrders(); + + return order.GetViewModel; + } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..f72f531 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Implementer.cs @@ -0,0 +1,85 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace CarpentryWorkshopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(element.Element("Cost")!.Value), + Qualification = Convert.ToInt32(element.Element("Cost")!.Value) + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification)); + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs index 510d85e..b572582 100644 --- a/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopFileImplement/Models/Order.cs @@ -4,6 +4,8 @@ using CarpentryWorkshopDataModels.Enums; using CarpentryWorkshopDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using System.Text; @@ -14,15 +16,24 @@ namespace CarpentryWorkshopFileImplement.Models { public class Order : IOrderModel { - public int Id { get; private set; } public int WoodId { get; private set; } - public int ClientId { get; set; } - public string WoodName { get; private set; } = string.Empty; + + public int? ImplementerId { get; set; } + + public int ClientId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + public static Order? Create(OrderBindingModel model) { if (model == null) @@ -32,9 +43,9 @@ namespace CarpentryWorkshopFileImplement.Models return new Order() { Id = model.Id, + ImplementerId = model.ImplementerId, WoodId = model.WoodId, ClientId = model.ClientId, - WoodName = model.WoodName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -42,26 +53,32 @@ namespace CarpentryWorkshopFileImplement.Models DateImplement = model.DateImplement }; } + public static Order? Create(XElement element) { if (element == null) { return null; } - return new Order() + + var order = new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), WoodId = Convert.ToInt32(element.Element("WoodId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - WoodName = element.Element("WoodName")!.Value, Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), - Status = (OrderStatus)Convert.ToInt32(element.Element("Status").Value), - DateCreate = Convert.ToDateTime(element.Element("DateCreate").Value), - DateImplement = String.IsNullOrEmpty(element.Element("DateImplement").Value) ? DateTime.MinValue : Convert.ToDateTime(element.Element("DateImplement").Value) - + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) }; + + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + order.DateImplement = dateImpl; + + return order; } + public void Update(OrderBindingModel model) { if (model == null) @@ -71,27 +88,29 @@ namespace CarpentryWorkshopFileImplement.Models Status = model.Status; DateImplement = model.DateImplement; } + public OrderViewModel GetViewModel => new() { Id = Id, + ImplementerId = ImplementerId, WoodId = WoodId, ClientId = ClientId, - WoodName = WoodName, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement, + DateImplement = DateImplement }; + public XElement GetXElement => new("Order", - new XAttribute("Id", Id), - new XElement("WoodId", WoodId), - new XElement("ClientId", ClientId), - new XElement("WoodName", WoodName), - new XElement("Count", Count), - new XElement("Sum", Sum.ToString()), - new XElement("Status", (int)Status), - new XElement("DateCreate", DateCreate), - new XElement("DateImplement", DateImplement)); + new XAttribute("Id", Id), + new XElement("WoodId", WoodId.ToString()), + new XElement("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); } } diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs index 3d6e086..0958ead 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/DataListSingleton.cs @@ -9,11 +9,14 @@ namespace CarpentryWorkshopListImplement public List Orders { get; set; } public List Woods { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Woods = new List(); + Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..088a269 --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,126 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; +using CarpentryWorkshopContracts.StoragesContracts; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopListImplement.Models; + +namespace CarpentryWorkshopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && + x.Password.Equals(model.Password)) + return x.GetViewModel; + + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + + var res = Implementer.Create(model); + + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + + return implementer.GetViewModel; + } + } + return null; + } + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs index 16db565..bfed4aa 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Implements/OrderStorage.cs @@ -18,80 +18,6 @@ namespace CarpentryWorkshopListImplement.Implements { _source = DataListSingleton.GetInstance(); } - public List GetFullList() - { - var result = new List(); - foreach (var Order in _source.Orders) - { - result.Add(GetViewModel(Order)); - } - return result; - } - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - return new() { GetViewModel(order) }; - } - else if (model.DateFrom.HasValue && model.DateTo.HasValue && model.DateFrom <= order.DateCreate.Date && order.DateCreate.Date <= model.DateTo) - { - result.Add(GetViewModel(order)); - } - else if (model.ClientId.HasValue && order.ClientId == model.ClientId) - { - result.Add(GetViewModel(order)); - } - } - return result; - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - foreach (var Order in _source.Orders) - { - if (model.Id.HasValue && Order.Id == model.Id) - { - return GetViewModel(Order); - } - } - return null; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - foreach (var Order in _source.Orders) - { - if (model.Id <= Order.Id) - { - model.Id = Order.Id + 1; - } - } - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - _source.Orders.Add(newOrder); - return GetViewModel(newOrder); - } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var Order in _source.Orders) - { - if (Order.Id == model.Id) - { - Order.Update(model); - return GetViewModel(Order); - } - } - return null; - } public OrderViewModel? Delete(OrderBindingModel model) { for (int i = 0; i < _source.Orders.Count; ++i) @@ -100,20 +26,100 @@ namespace CarpentryWorkshopListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return GetViewModel(element); + return element.GetViewModel; } } + return null; } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return order.GetViewModel; + } + + else if (model.ImplementerId.HasValue && model.Statuses != null && + order.ImplementerId == model.ImplementerId && + model.Statuses.Contains(order.Status)) + { + return GetViewModel(order); + } + + else if (model.ImplementerId.HasValue && + model.ImplementerId == order.ImplementerId) + { + return GetViewModel(order); + } + } + + return null; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + + if (model.DateFrom.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.ClientId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } + + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + + else if (model.Statuses != null && model.Statuses.Contains(order.Status)) + { + result.Add(GetViewModel(order)); + } + } + } + + + return result; + } private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var comp in _source.Woods) + foreach (var wood in _source.Woods) { - if (comp.Id == order.WoodId) + if (wood.Id == order.WoodId) { - viewModel.WoodName = comp.WoodName; + viewModel.WoodName = wood.WoodName; break; } } @@ -127,5 +133,54 @@ namespace CarpentryWorkshopListImplement.Implements } return viewModel; } + public List GetFullList() + { + var result = new List(); + + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + + return result; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + _source.Orders.Add(newOrder); + + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + + return null; + } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..9326f3a --- /dev/null +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Implementer.cs @@ -0,0 +1,56 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.ViewModels; +using CarpentryWorkshopDataModels.Models; + +namespace CarpentryWorkshopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs index 64f3b5f..7502dd0 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs @@ -1,4 +1,5 @@ using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.SearchModels; using CarpentryWorkshopContracts.ViewModels; using CarpentryWorkshopDataModels.Enums; using CarpentryWorkshopDataModels.Models; @@ -13,15 +14,22 @@ namespace CarpentryWorkshopListImplement.Models { public class Order : IOrderModel { - public int Id { get; private set; } public int WoodId { get; private set; } + public int ClientId { get; private set; } - public string WoodName { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } - public OrderStatus Status { get; private set; } - public DateTime DateCreate { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -32,8 +40,8 @@ namespace CarpentryWorkshopListImplement.Models { Id = model.Id, WoodId = model.WoodId, + ImplementerId = model.ImplementerId, ClientId = model.ClientId, - WoodName = model.WoodName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -41,6 +49,7 @@ namespace CarpentryWorkshopListImplement.Models DateImplement = model.DateImplement }; } + public void Update(OrderBindingModel? model) { if (model == null) @@ -50,17 +59,20 @@ namespace CarpentryWorkshopListImplement.Models Status = model.Status; DateImplement = model.DateImplement; } + public OrderViewModel GetViewModel => new() { Id = Id, WoodId = WoodId, ClientId = ClientId, - WoodName = WoodName, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ImplementerId = ImplementerId }; + + public int? ImplementerId { get; private set; } } } diff --git a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs index 575c4e4..058d34d 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/Program.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/Program.cs @@ -40,12 +40,15 @@ namespace CarpentryWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -61,6 +64,8 @@ namespace CarpentryWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file -- 2.25.1 From 9e67911affa04fa7cc9252e6a10671ac1711f6b3 Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sat, 27 Apr 2024 23:27:52 +0400 Subject: [PATCH 4/5] done --- .../CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs | 3 ++- .../CarpentryWorkshopDatabaseImplement/Models/Order.cs | 2 +- .../CarpentryWorkshopListImplement/Models/Order.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs index 11f6d68..4b19e26 100644 --- a/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/CarpentryWorkshop/CarpentryWorkshopContracts/ViewModels/OrderViewModel.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -31,7 +32,7 @@ namespace CarpentryWorkshopContracts.ViewModels [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs index 1e01930..4344258 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Models/Order.cs @@ -30,7 +30,7 @@ namespace CarpentryWorkshopDatabaseImplement.Models public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; [Required] - public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } diff --git a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs index 7502dd0..ebb01b8 100644 --- a/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs +++ b/CarpentryWorkshop/CarpentryWorkshopListImplement/Models/Order.cs @@ -24,7 +24,7 @@ namespace CarpentryWorkshopListImplement.Models public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime DateCreate { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public DateTime? DateImplement { get; private set; } -- 2.25.1 From 05501e2170ce884b749ff1c58aba8f76d0ae653f Mon Sep 17 00:00:00 2001 From: Vladislav_396ntk Date: Tue, 30 Apr 2024 12:56:27 +0400 Subject: [PATCH 5/5] fix --- .../CarpentryWorkshopDatabase.cs | 2 +- ...te.Designer.cs => 20240430082941_InitialCreate.Designer.cs} | 2 +- ...190111_InitialCreate.cs => 20240430082941_InitialCreate.cs} | 0 CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs | 3 ++- 4 files changed, 4 insertions(+), 3 deletions(-) rename CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/{20240427190111_InitialCreate.Designer.cs => 20240430082941_InitialCreate.Designer.cs} (99%) rename CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/{20240427190111_InitialCreate.cs => 20240430082941_InitialCreate.cs} (100%) diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs index 0537949..6e13c81 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/CarpentryWorkshopDatabase.cs @@ -14,7 +14,7 @@ namespace CarpentryWorkshopDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=CarpentryWorkshopDatabaseLab51;Username=postgres;Password=postgres"); + optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=CarpentryWorkshopDatabaseLab6;Username=postgres;Password=postgres"); } base.OnConfiguring(optionsBuilder); } diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240430082941_InitialCreate.Designer.cs similarity index 99% rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240430082941_InitialCreate.Designer.cs index 1024bdf..355fdc0 100644 --- a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.Designer.cs +++ b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240430082941_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace CarpentryWorkshopDatabaseImplement.Migrations { [DbContext(typeof(CarpentryWorkshopDatabase))] - [Migration("20240427190111_InitialCreate")] + [Migration("20240430082941_InitialCreate")] partial class InitialCreate { /// diff --git a/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs b/CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240430082941_InitialCreate.cs similarity index 100% rename from CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240427190111_InitialCreate.cs rename to CarpentryWorkshop/CarpentryWorkshopDatabaseImplement/Migrations/20240430082941_InitialCreate.cs diff --git a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs index 7cde27c..6372a79 100644 --- a/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs +++ b/CarpentryWorkshop/CarpentryWorkshopView/FormMain.cs @@ -43,7 +43,8 @@ namespace CarpentryWorkshopView { dataGridView.DataSource = list; dataGridView.Columns[1].Visible = false; - + dataGridView.Columns[2].Visible = false; + dataGridView.Columns[3].Visible = false; } _logger.LogInformation("Загрузка продуктов"); } -- 2.25.1