diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..0a80a9f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,129 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.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. FIO:{FIO}.Id:{ Id}", + model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id); + var list = (model == null) ? _implementerStorage.GetFullList() : + _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.WorkExperience < 0) + { + throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет фио исполнителя", nameof(model.ImplementerFIO)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким фио уже есть"); + } + } + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs index 4711f8b..1bc5fc4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -22,6 +22,22 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics _logger = logger; _orderStorage = orderStorage; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DateFrom:{DateFrom}. DateTo:{DateTo}. Id:{Id}", model.DateFrom, model.DateTo, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Id: {Id}", model?.Id); @@ -45,58 +61,58 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogics model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } return true; } + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + throw new InvalidOperationException(); + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = viewModel.DateImplement; + } + if (viewModel.ImplementerId.HasValue) + { + model.ImplementerId = viewModel.ImplementerId.Value; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model, false); - if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Принят) - { - _logger.LogWarning("Invalid order status"); - return false; - } - model.Status = OrderStatus.Выполняется; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - } - return true; + return StatusUpdate(model, OrderStatus.Выполняется); } public bool FinishOrder(OrderBindingModel model) { - CheckModel(model, false); - if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) - { - _logger.LogWarning("Invalid order status"); - return false; - } - model.Status = OrderStatus.Готов; model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - } - return true; + return StatusUpdate(model, OrderStatus.Готов); } public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model, false); - var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); - if (order?.Status != OrderStatus.Готов) - { - _logger.LogWarning("Invalid order status"); - return false; - } - model.Status = OrderStatus.Выдан; - model.DateImplement = order.DateImplement; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - } - return true; + + return StatusUpdate(model, OrderStatus.Выдан); } private void CheckModel(OrderBindingModel model, bool withParams = true) { diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/WorkModeling.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..7b04540 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,138 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantBusinessLogic.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.Принят, 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.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, 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.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index 7759681..2b4942d 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -303,7 +303,7 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements return; } _spreadsheetDocument.WorkbookPart!.Workbook.Save(); - _spreadsheetDocument.Close(); + _spreadsheetDocument.Dispose(); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 95d42d2..211ddf6 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -118,7 +118,7 @@ namespace PrecastConcretePlantBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); - _wordDocument.Close(); + _wordDocument.Dispose(); } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..e600bc9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs index 7b2701e..d903ac4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/OrderBindingModel.cs @@ -18,5 +18,6 @@ namespace PrecastConcretePlantContracts.BindingModels public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } + public int? ImplementerId { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..37fbec9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs index 5b3c94b..3895100 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..fe3ab5d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..8e9b321 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs index c25069e..baf6cfa 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using PrecastConcretePlantDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,6 +13,7 @@ namespace PrecastConcretePlantContracts.SearchModels public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } - + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..a0c0e80 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.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/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..b41daf9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs index 086d903..55481c7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/OrderViewModel.cs @@ -16,6 +16,9 @@ namespace PrecastConcretePlantContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("ФИО исполнителя")] + public string? ImplementerFIO { get; set; } = string.Empty; public int ReinforcedId { get; set; } [DisplayName("Изделие")] public string ReinforcedName { get; set; } = string.Empty; diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IImplementerModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..7386da8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs index d1aa7b0..0c0b46f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/Models/IOrderModel.cs @@ -11,6 +11,7 @@ namespace PrecastConcretePlantDataModels.Models { int ReinforcedId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..ddadfee --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,95 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new PrecastConcretePlantDataBase(); + if (model.Id.HasValue) + return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + if (model.ImplementerFIO != null) + return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.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(); + } + if (model.ImplementerFIO != null) + { + using var context = new PrecastConcretePlantDataBase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new PrecastConcretePlantDataBase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new PrecastConcretePlantDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs index f44ea77..4046bf9 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Implements/OrderStorage.cs @@ -18,42 +18,46 @@ namespace PrecastConcretePlantDatabaseImplement.Implements { using var context = new PrecastConcretePlantDataBase(); return context.Orders - .Include(x => x.Reinforced).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + .Include(x => x.Reinforced).Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) { - using var context = new PrecastConcretePlantDataBase(); if (model.Id.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + var result = GetElement(model); + return result != null ? new() { result } : new(); } - else if (model.DateFrom != null && model.DateTo != null) + + using var context = new PrecastConcretePlantDataBase(); + IQueryable? queryWhere = null; + + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Select(x => x.GetViewModel) - .ToList(); + 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) { - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .Where(x => x.ClientId == model.ClientId) - .Select(x => x.GetViewModel) - .ToList(); + 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 OrderViewModel? GetElement(OrderSearchModel model) { @@ -62,7 +66,11 @@ namespace PrecastConcretePlantDatabaseImplement.Implements return null; } using var context = new PrecastConcretePlantDataBase(); - return context.Orders.Include(x => x.Reinforced).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + 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 OrderViewModel? Insert(OrderBindingModel model) { @@ -74,41 +82,40 @@ namespace PrecastConcretePlantDatabaseImplement.Implements using var context = new PrecastConcretePlantDataBase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == newOrder.Id) - ?.GetViewModel; + return newOrder.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new PrecastConcretePlantDataBase(); - var order = context.Orders.FirstOrDefault(x => x.Id == - model.Id); + + var order = context.Orders + .Include(x => x.Reinforced) + .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 context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; + + return order.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new PrecastConcretePlantDataBase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == - model.Id); + + var element = context.Orders + .Include(x => x.Reinforced) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) { - var deletedElement = context.Orders - .Include(x => x.Reinforced) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id) - ?.GetViewModel; context.Orders.Remove(element); context.SaveChanges(); return element.GetViewModel; diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240321175433_InitialCreate.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240321175433_InitialCreate.Designer.cs deleted file mode 100644 index 23ee048..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240321175433_InitialCreate.Designer.cs +++ /dev/null @@ -1,171 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PrecastConcretePlantDatabaseImplement; - -#nullable disable - -namespace PrecastConcretePlantDatabaseImplement.Migrations -{ - [DbContext(typeof(PrecastConcretePlantDataBase))] - [Migration("20240321175433_InitialCreate")] - partial class InitialCreate - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ReinforcedName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Reinforceds"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ReinforcedId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ReinforcedId"); - - b.ToTable("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Orders") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b => - { - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component") - .WithMany("ReinforcedComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") - .WithMany("Components") - .HasForeignKey("ReinforcedId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Reinforced"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b => - { - b.Navigation("ReinforcedComponents"); - }); - - modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240412175454_Add_Clients.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240412175454_Add_Clients.cs deleted file mode 100644 index 3b21064..0000000 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240412175454_Add_Clients.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace PrecastConcretePlantDatabaseImplement.Migrations -{ - /// - public partial class Add_Clients : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ClientId", - table: "Orders", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "Clients", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), - Email = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Clients", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ClientId", - table: "Orders", - column: "ClientId"); - - migrationBuilder.AddForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders", - column: "ClientId", - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Orders_Clients_ClientId", - table: "Orders"); - - migrationBuilder.DropTable( - name: "Clients"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ClientId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ClientId", - table: "Orders"); - } - } -} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240412175454_Add_Clients.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240501153814_Full_Reatart.Designer.cs similarity index 82% rename from PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240412175454_Add_Clients.Designer.cs rename to PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240501153814_Full_Reatart.Designer.cs index 09daa93..6b0e7a1 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240412175454_Add_Clients.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240501153814_Full_Reatart.Designer.cs @@ -12,8 +12,8 @@ using PrecastConcretePlantDatabaseImplement; namespace PrecastConcretePlantDatabaseImplement.Migrations { [DbContext(typeof(PrecastConcretePlantDataBase))] - [Migration("20240412175454_Add_Clients")] - partial class Add_Clients + [Migration("20240501153814_Full_Reatart")] + partial class Full_Reatart { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -70,6 +70,33 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -90,6 +117,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ReinforcedId") .HasColumnType("int"); @@ -103,6 +133,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ReinforcedId"); b.ToTable("Orders"); @@ -162,6 +194,10 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") .HasForeignKey("ReinforcedId") @@ -170,6 +206,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Reinforced"); }); @@ -202,6 +240,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("ReinforcedComponents"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => { b.Navigation("Components"); diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240321175433_InitialCreate.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240501153814_Full_Reatart.cs similarity index 64% rename from PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240321175433_InitialCreate.cs rename to PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240501153814_Full_Reatart.cs index 3715aa6..eaefcd0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240321175433_InitialCreate.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/20240501153814_Full_Reatart.cs @@ -6,11 +6,26 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace PrecastConcretePlantDatabaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class Full_Reatart : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Components", columns: table => new @@ -25,6 +40,22 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Reinforceds", columns: table => new @@ -45,7 +76,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), Sum = table.Column(type: "float", nullable: false), Status = table.Column(type: "int", nullable: false), DateCreate = table.Column(type: "datetime2", nullable: false), @@ -55,6 +88,17 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + 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_Reinforceds_ReinforcedId", column: x => x.ReinforcedId, @@ -90,6 +134,16 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ReinforcedId", table: "Orders", @@ -115,6 +169,12 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations migrationBuilder.DropTable( name: "ReinforcedComponents"); + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); @@ -122,4 +182,4 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations name: "Reinforceds"); } } -} \ No newline at end of file +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs index f1c5cf4..14c5f03 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Migrations/PrecastConcretePlantDataBaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ReinforcedId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ReinforcedId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced") .WithMany("Orders") .HasForeignKey("ReinforcedId") @@ -167,6 +203,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Reinforced"); }); @@ -199,6 +237,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations b.Navigation("ReinforcedComponents"); }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b => { b.Navigation("Components"); diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..0db20f3 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,70 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.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 PrecastConcretePlantDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification, + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs index e6508c7..9764415 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/Models/Order.cs @@ -17,6 +17,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models [Required] public int ClientId { get; set; } public int Count { get; private set; } + public int? ImplementerId { get; set; } [Required] public double Sum { get; private set; } [Required] @@ -28,6 +29,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models public int ReinforcedId { get; private set; } public virtual Reinforced Reinforced { get; set; } public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel model) { @@ -45,6 +47,7 @@ namespace PrecastConcretePlantDatabaseImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, ReinforcedId = model.ReinforcedId, + ImplementerId = model.ImplementerId, }; } @@ -56,20 +59,30 @@ namespace PrecastConcretePlantDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } - public OrderViewModel GetViewModel => new() + public OrderViewModel GetViewModel { - ReinforcedId = ReinforcedId, - ReinforcedName = Reinforced.ReinforcedName, - ClientId = ClientId, - ClientFIO = Client.ClientFIO, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement, - Id = Id, - }; + get + { + using var context = new PrecastConcretePlantDataBase(); + return new OrderViewModel + { + ReinforcedId = ReinforcedId, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, + ReinforcedName = context.Reinforceds.FirstOrDefault(x => x.Id == ReinforcedId)?.ReinforcedName ?? string.Empty, + ClientId = ClientId, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + }; + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs index a681b82..b50363f 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDataBase.cs @@ -25,6 +25,7 @@ optionsBuilder) public virtual DbSet ReinforcedComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj index 9376618..b5f0979 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantDatabaseImplement/PrecastConcretePlantDatabaseImplement.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs index 15ff682..e9a5b11 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -15,10 +15,12 @@ namespace PrecastConcretePlantFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ReinforcedFileName = "Reinforced.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 Reinforceds { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -31,12 +33,14 @@ namespace PrecastConcretePlantFileImplement public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..2e1e48b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,96 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) + return _source.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + if (model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.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(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs index e148698..8790d70 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Implements/OrderStorage.cs @@ -38,6 +38,17 @@ namespace PrecastConcretePlantFileImplement.Implements 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; diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..3cf5a75 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Implementer.cs @@ -0,0 +1,86 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.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(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + 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 + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("FIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs index 34a3a4c..b1640f4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace PrecastConcretePlantFileImplement.Models { public int Id { get; private set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int ReinforcedId { get; private set; } @@ -22,7 +23,7 @@ namespace PrecastConcretePlantFileImplement.Models public double Sum { get; private set; } - public OrderStatus Status { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; private set; } @@ -36,6 +37,7 @@ namespace PrecastConcretePlantFileImplement.Models } return new Order() { + ImplementerId = model.ImplementerId, ReinforcedId = model.ReinforcedId, ClientId = model.ClientId, Count = model.Count, @@ -61,6 +63,7 @@ namespace PrecastConcretePlantFileImplement.Models Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement) }; @@ -78,6 +81,7 @@ namespace PrecastConcretePlantFileImplement.Models { Id = Id, ClientId = ClientId, + ImplementerId = ImplementerId, ReinforcedId = ReinforcedId, Count = Count, Sum = Sum, @@ -94,6 +98,7 @@ namespace PrecastConcretePlantFileImplement.Models new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), + new XElement("ImplementerId", ImplementerId), new XElement("DateImplement", DateImplement.ToString())); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs index bcdd47f..302afa7 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace PrecastConcretePlantListImplement public List Orders { get; set; } public List Reinforceds { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Reinforceds = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..2ff5412 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,131 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContracts; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.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/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs index 9616703..757db68 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Implements/OrderStorage.cs @@ -41,17 +41,36 @@ namespace PrecastConcretePlantListImplement.Implements result.Add(ViewAddReinforcedName(order.GetViewModel)); } } - if (!model.Id.HasValue) + if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + result.Add(order.GetViewModel); + } + + else if (model.Statuses != null && model.Statuses.Contains(order.Status)) + { + result.Add(order.GetViewModel); + } + } + } + else if (model.DateFrom != null && model.DateTo != null) { foreach (var order in _source.Orders) { if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) { - result.Add(ViewAddReinforcedName(order.GetViewModel)); + result.Add(order.GetViewModel); } } } - else if (!model.ClientId.HasValue) + else if (model.ClientId.HasValue) { foreach (var order in _source.Orders) { @@ -61,6 +80,7 @@ namespace PrecastConcretePlantListImplement.Implements } } } + return result; } public OrderViewModel? GetElement(OrderSearchModel model) @@ -73,9 +93,22 @@ namespace PrecastConcretePlantListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return ViewAddReinforcedName(order.GetViewModel); + 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 OrderViewModel? Insert(OrderBindingModel model) @@ -130,5 +163,26 @@ namespace PrecastConcretePlantListImplement.Implements } return model; } + private OrderViewModel GetViewModel(Order model) + { + var res = model.GetViewModel; + foreach (var reinforced in _source.Reinforceds) + { + if (reinforced.Id == model.ReinforcedId) + { + res.ReinforcedName = reinforced.ReinforcedName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == res.ClientId) + { + res.ClientFIO = client.ClientFIO; + break; + } + } + return res; + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Implementer.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Implementer.cs new file mode 100644 index 0000000..132554e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PrecastConcretePlantListImplement.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() + { + 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, + }; + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs index 7116255..3a3e265 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace PrecastConcretePlantListImplement.Models public int Id { get; private set; } public int ClientId { get; private set; } public int ReinforcedId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -36,6 +37,7 @@ namespace PrecastConcretePlantListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId, }; } public void Update(OrderBindingModel? model) @@ -57,6 +59,7 @@ namespace PrecastConcretePlantListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, + ImplementerId = ImplementerId, }; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs b/PrecastConcretePlant/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..5f76e29 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,104 @@ +using Microsoft.AspNetCore.Mvc; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; + +namespace PrecastConcretePlantRestApi.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 + { + Statuses = new() { 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/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.Designer.cs new file mode 100644 index 0000000..1d7cda3 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.Designer.cs @@ -0,0 +1,173 @@ +namespace PrecastConcretePlantView +{ + 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + textBoxFio = new TextBox(); + textBoxPassword = new TextBox(); + numericUpDownWorkExperience = new NumericUpDown(); + numericUpDownQualification = new NumericUpDown(); + buttonCancel = new Button(); + buttonSave = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(79, 12); + label1.Name = "label1"; + label1.Size = new Size(37, 15); + label1.TabIndex = 0; + label1.Text = "ФИО:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(69, 41); + label2.Name = "label2"; + label2.Size = new Size(52, 15); + label2.TabIndex = 1; + label2.Text = "Пароль:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(78, 68); + label3.Name = "label3"; + label3.Size = new Size(38, 15); + label3.TabIndex = 2; + label3.Text = "Стаж:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(25, 97); + label4.Name = "label4"; + label4.Size = new Size(91, 15); + label4.TabIndex = 3; + label4.Text = "Квалификация:"; + // + // textBoxFio + // + textBoxFio.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxFio.Location = new Point(127, 9); + textBoxFio.Name = "textBoxFio"; + textBoxFio.Size = new Size(271, 23); + textBoxFio.TabIndex = 4; + // + // textBoxPassword + // + textBoxPassword.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxPassword.Location = new Point(127, 38); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.PasswordChar = '*'; + textBoxPassword.Size = new Size(271, 23); + textBoxPassword.TabIndex = 5; + // + // numericUpDownWorkExperience + // + numericUpDownWorkExperience.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + numericUpDownWorkExperience.Location = new Point(127, 66); + numericUpDownWorkExperience.Name = "numericUpDownWorkExperience"; + numericUpDownWorkExperience.Size = new Size(271, 23); + numericUpDownWorkExperience.TabIndex = 6; + // + // numericUpDownQualification + // + numericUpDownQualification.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + numericUpDownQualification.Location = new Point(127, 95); + numericUpDownQualification.Name = "numericUpDownQualification"; + numericUpDownQualification.Size = new Size(271, 23); + numericUpDownQualification.TabIndex = 7; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(309, 138); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(89, 33); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(214, 138); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(89, 33); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(410, 183); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(numericUpDownQualification); + Controls.Add(numericUpDownWorkExperience); + Controls.Add(textBoxPassword); + Controls.Add(textBoxFio); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormImplementer"; + Text = "Добавление / Редактирование исполнителя"; + Load += FormImplementer_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExperience).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private TextBox textBoxFio; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownWorkExperience; + private NumericUpDown numericUpDownQualification; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.cs new file mode 100644 index 0000000..336c9ad --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.cs @@ -0,0 +1,109 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantContracts.SearchModels; +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 PrecastConcretePlantView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExperience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExperience.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs index ca55523..85af9b4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.Designer.cs @@ -33,14 +33,14 @@ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.исполнителиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокИзделийToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияПоКомпонентамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.списокЗаказовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.запускРаботToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); @@ -52,7 +52,8 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникToolStripMenuItem, - this.отчетыToolStripMenuItem}); + this.отчетыToolStripMenuItem, + this.запускРаботToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); @@ -65,7 +66,8 @@ this.справочникToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.изделияToolStripMenuItem, - this.клиентыToolStripMenuItem}); + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; this.справочникToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникToolStripMenuItem.Text = "Справочники"; @@ -73,24 +75,31 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.изделияToolStripMenuItem.Text = "Железные изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // клиентыToolStripMenuItem // this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(178, 22); this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(178, 22); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -122,6 +131,13 @@ this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовToolStripMenuItem_Click); // + // запускРаботToolStripMenuItem + // + this.запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + this.запускРаботToolStripMenuItem.Size = new System.Drawing.Size(92, 20); + this.запускРаботToolStripMenuItem.Text = "Запуск работ"; + this.запускРаботToolStripMenuItem.Click += new System.EventHandler(this.запускРаботToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.AllowUserToAddRows = false; @@ -139,7 +155,7 @@ // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(867, 40); + this.buttonCreateOrder.Location = new System.Drawing.Point(867, 109); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(216, 22); @@ -148,31 +164,9 @@ this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(867, 91); - this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(216, 22); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(867, 143); - this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(216, 22); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(867, 191); + this.buttonIssuedOrder.Location = new System.Drawing.Point(867, 152); this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; this.buttonIssuedOrder.Size = new System.Drawing.Size(216, 22); @@ -183,7 +177,7 @@ // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(867, 232); + this.buttonRef.Location = new System.Drawing.Point(867, 191); this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(216, 22); @@ -199,8 +193,6 @@ this.ClientSize = new System.Drawing.Size(1099, 320); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -225,8 +217,6 @@ private ToolStripMenuItem изделияToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; private ToolStripMenuItem отчетыToolStripMenuItem; @@ -234,5 +224,7 @@ private ToolStripMenuItem изделияПоКомпонентамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs index 87dc161..5a35854 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormMain.cs @@ -2,6 +2,7 @@ using PrecastConcretePlantBusinessLogic.BusinessLogics; using PrecastConcretePlantContracts.BindingModels; using PrecastConcretePlantContracts.BusinessLogicsContracts; +using PrecastConcretePlantBusinessLogic.BusinessLogics; using System; using System.Collections.Generic; using System.ComponentModel; @@ -19,12 +20,14 @@ namespace PrecastConcretePlantView 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) { @@ -40,6 +43,7 @@ namespace PrecastConcretePlantView dataGridView.DataSource = list; dataGridView.Columns["ReinforcedId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -74,56 +78,7 @@ namespace PrecastConcretePlantView LoadData(); } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -189,5 +144,25 @@ namespace PrecastConcretePlantView 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(FormViewImplementers)); + if (service is FormViewImplementers form) + { + form.ShowDialog(); + } + } } } + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.Designer.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.Designer.cs new file mode 100644 index 0000000..c240197 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.Designer.cs @@ -0,0 +1,118 @@ +namespace PrecastConcretePlantView +{ + partial class FormViewImplementers + { + /// + /// 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() + { + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(626, 202); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(90, 37); + buttonRef.TabIndex = 9; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDel.Location = new Point(626, 151); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(90, 33); + buttonDel.TabIndex = 8; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(626, 102); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(90, 34); + buttonUpd.TabIndex = 7; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(626, 57); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(90, 30); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 12); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(553, 302); + dataGridView.TabIndex = 5; + // + // FormViewImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(722, 319); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormViewImplementers"; + Text = "Просмотр списка исполнителей"; + Load += FormViewImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.cs b/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.cs new file mode 100644 index 0000000..3e37169 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.cs @@ -0,0 +1,112 @@ +using Microsoft.Extensions.Logging; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.BusinessLogicsContracts; +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 PrecastConcretePlantView +{ + public partial class FormViewImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormViewImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormViewImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.resx b/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantView/FormViewImplementers.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/PrecastConcretePlant/PrecastConcretePlantView/Program.cs b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs index d3535ef..52971d3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantView/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantView/Program.cs @@ -41,12 +41,15 @@ namespace PrecastConcretePlantView 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(); @@ -62,6 +65,8 @@ namespace PrecastConcretePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file