diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ImplementerLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..285ea69 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,123 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}. Id:{Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); + } + if (model.Qualification <= 0) + { + throw new ArgumentNullException("Квалификация должна быть больше 0", nameof(model.Qualification)); + } + if (model.WorkExperience <= 0) + { + throw new ArgumentNullException("Стаж работы должен быть больше 0", nameof(model.WorkExperience)); + } + _logger.LogInformation("Component. ImplementerFIO:{ImplementerFIO}.Password:{Password}.Qualification:{Qualification}.WorkExperience:{WorkExperience}.", model.ImplementerFIO, model.Password, model.Qualification, model.WorkExperience); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с таким ФИО уже есть"); + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs index c5cdfa8..f3d64c7 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs @@ -5,6 +5,7 @@ using PlumbingRepairContracts.ViewModels; using PlumbingRepairContracts.StoragesContracts; using PlumbingRepairDataModels.Enums; using Microsoft.Extensions.Logging; +using System.Xml.Linq; namespace PlumbingRepairBusinessLogic.BusinessLogics @@ -17,7 +18,8 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics private readonly IShopStorage _shopStorage; private readonly IWorkStorage _workStorage; private readonly IShopLogic _shopLogic; - public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage, IWorkStorage workStorage, IShopLogic shopLogic) + static readonly object _locker = new object(); + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage, IWorkStorage workStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; @@ -25,6 +27,23 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics _workStorage = workStorage; _shopLogic = shopLogic; } + + 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 bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -67,49 +86,52 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (_locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) { + CheckModel(model, false); 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"); + _logger.LogWarning("Find order failed"); return false; } - if (newStatus == OrderStatus.Выдан) + if (viewModel.Status != newStatus - 1 && viewModel.Status != OrderStatus.Ожидание) { - var work = _workStorage.GetElement(new WorkSearchModel() { Id = viewModel.WorkId}); - if (work == null) - { - _logger.LogWarning("Change status operation failed.Work not found"); - return false; - } - if (!_shopLogic.CheckAndSupply(work, viewModel.Count)) - { - _logger.LogWarning("Change status operation failed. Works delivery operation failed"); - return false; - } - } - model.Status = newStatus; - if (model.Status == OrderStatus.Готов) - { - model.DateImplement = DateTime.Now; - } - else - { - model.DateImplement = viewModel.DateImplement; - } - CheckModel(model, false); - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Change status operation failed"); - return false; + _logger.LogWarning("Status change failed"); + throw new InvalidOperationException("Невозможно перевести состояние заказа"); } + if (viewModel.ImplementerId != null) + viewModel.ImplementerId = model.ImplementerId; + model.Status = newStatus; + if (model.WorkId == 0) + model.WorkId = viewModel.WorkId; + if (model.Count == 0) + model.Count = viewModel.Count; + if (newStatus == OrderStatus.Готов) + { + var work = _workStorage.GetElement(new WorkSearchModel { Id = model.WorkId }); + if (work == null) + { + _logger.LogWarning("Status change operation failed. Work not found."); + return false; + } + + if (!_shopLogic.CheckAndSupply(work, model.Count)) + { + _logger.LogWarning("Status change operation failed. Shop supply error."); + model.Status = OrderStatus.Ожидание; + if (_orderStorage.Update(model) == null) + _logger.LogWarning("Update operation failed"); + return false; + } + + } + _orderStorage.Update(model); return true; } private void CheckModel(OrderBindingModel model, bool withParams = true) diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkModeling.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..334ca78 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,191 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +using Microsoft.Extensions.Logging; +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepairBusinessLogic.BusinessLogics +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); + if (orders == null) + { + _logger.LogWarning("DoWork. Orders is null"); + return; + } + orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Выполняется }) ?? new()); + orders.AddRange(_orderLogic.ReadList(new() { Status = OrderStatus.Ожидание }) ?? new()); + if (orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is 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 RunWaitingOrder(implementer); + await RunOrderInWork(implementer); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + + } + }); + } + + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + _logger.LogDebug("DoWork. Worker {Id} delivery order {Order}", implementer.Id, runOrder.Id); + _orderLogic.DeliveryOrder(new() { 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; + } + } + private async Task RunWaitingOrder(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var order = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Ожидание + })); + if (order == null) + { + return; + } + _logger.LogDebug("DoWork. Worker {Id} delivery order {Order}", implementer.Id, order.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id + }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/ImplementerBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..d65d926 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,16 @@ +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs index eeed65d..8ee10bd 100644 --- a/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/BindingModels/OrderBindingModel.cs @@ -10,6 +10,7 @@ namespace PlumbingRepairContracts.BindingModels public int WorkId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IImplementerLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..91b9efb --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; + +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs index 3588a21..8aba92b 100644 --- a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,7 @@ namespace PlumbingRepairContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); diff --git a/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..7ab6246 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,10 @@ +namespace PlumbingRepairContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + /// + /// Запуск работ + /// + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/ImplementerSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..5fdb263 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace PlumbingRepairContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs index ae2ee14..2b4ffc9 100644 --- a/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/SearchModels/OrderSearchModel.cs @@ -1,10 +1,14 @@ -namespace PlumbingRepairContracts.SearchModels +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepairContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } + public DateTime? DateTo { get; set;} + public OrderStatus? Status { get; set; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IImplementerStorage.cs b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..d71ec16 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; + +namespace PlumbingRepairContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..dc637e1 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,20 @@ +using PlumbingRepairDataModels.Models; +using System.ComponentModel; + +namespace PlumbingRepairContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs index b4de89b..a1747a2 100644 --- a/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs +++ b/PlumbingRepair/PlumbingRepairContracts/ViewModels/OrderViewModel.cs @@ -18,6 +18,11 @@ namespace PlumbingRepairContracts.ViewModels [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Исполнитель")] + public int? ImplementerId { get; set; } + [DisplayName("ФИО исполнителя")] + public string? ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } diff --git a/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs b/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs index 8b72a9c..df0aceb 100644 --- a/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs +++ b/PlumbingRepair/PlumbingRepairDataModels/Enums/OrderStatus.cs @@ -10,6 +10,8 @@ Готов = 2, - Выдан = 3 + Выдан = 3, + + Ожидание = 4 } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDataModels/Models/IImplementerModel.cs b/PlumbingRepair/PlumbingRepairDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..d86c2a6 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDataModels/Models/IImplementerModel.cs @@ -0,0 +1,11 @@ + +namespace PlumbingRepairDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..8129314 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDatabaseImplement.Models; + +namespace PlumbingRepairDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new PlumbingRepairDatabase(); + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new PlumbingRepairDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + using var context = new PlumbingRepairDatabase(); + return context.Implementers + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + using var context = new PlumbingRepairDatabase(); + context.Implementers.Add(newImplementer); + context.SaveChanges(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new PlumbingRepairDatabase(); + var component = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new PlumbingRepairDatabase(); + var element = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Implementers.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs index e68a231..48d857a 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs @@ -29,19 +29,21 @@ namespace PlumbingRepairDatabaseImplement.Implements return null; } using var context = new PlumbingRepairDatabase(); - return AttachNames(context.Orders + if (model.Id.HasValue) + return AttachNames(context.Orders .Include(x => x.Work) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel); + else if (model.ImplementerId.HasValue && model.Status.HasValue) + return AttachNames(context.Orders + .Include(x => x.Implementer) + .FirstOrDefault(x => model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) + ?.GetViewModel); + return null; } public List GetFilteredList(OrderSearchModel model) { - - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) - { - return new(); - } using var context = new PlumbingRepairDatabase(); @@ -51,18 +53,31 @@ namespace PlumbingRepairDatabaseImplement.Implements .Where(x => x.Id == model.Id) .Select(x => AttachNames(x.GetViewModel)).ToList(); } - if (model.ClientId.HasValue) + if (model.Status.HasValue) + { + return context.Orders. + Include(x => x.Work) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Where(x => x.Status.Equals(model.Status)) + .Select(x => x.GetViewModel) + .ToList(); + } + if (model.ClientId.HasValue) { return context.Orders .Include(x => x.Client). Where(x => x.ClientId == model.ClientId) .Select(x =>AttachNames(x.GetViewModel)).ToList(); } - - return context.Orders. + if (model.DateFrom != null && model.DateTo != null) + { + return context.Orders. Include(x => x.Work) .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) - .Select(x =>AttachNames(x.GetViewModel)).ToList(); + .Select(x => AttachNames(x.GetViewModel)).ToList(); + } + return new(); } @@ -71,6 +86,7 @@ namespace PlumbingRepairDatabaseImplement.Implements using var context = new PlumbingRepairDatabase(); return context.Orders .Include(x => x.Work) + .Include(x => x.Implementer) .Select(x =>AttachNames(x.GetViewModel)) .ToList(); } @@ -124,6 +140,14 @@ namespace PlumbingRepairDatabaseImplement.Implements return model; } } + foreach (var implementer in context.Implementers) + { + if (implementer.Id == model.ImplementerId) + { + model.ImplementerFIO = implementer.ImplementerFIO; + return model; + } + } return model; } } diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240501122640_InitCreate.Designer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503121400_initCreate.Designer.cs similarity index 86% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240501122640_InitCreate.Designer.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503121400_initCreate.Designer.cs index 3634563..3867f4a 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240501122640_InitCreate.Designer.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503121400_initCreate.Designer.cs @@ -12,8 +12,8 @@ using PlumbingRepairDatabaseImplement; namespace PlumbingRepairDatabaseImplement.Migrations { [DbContext(typeof(PlumbingRepairDatabase))] - [Migration("20240501122640_InitCreate")] - partial class InitCreate + [Migration("20240503121400_initCreate")] + partial class initCreate { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -69,6 +69,33 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -89,6 +116,9 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -102,6 +132,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("WorkId"); b.ToTable("Orders"); @@ -214,6 +246,10 @@ namespace PlumbingRepairDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PlumbingRepairDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work") .WithMany("Orders") .HasForeignKey("WorkId") @@ -222,6 +258,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Work"); }); @@ -273,6 +311,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Shop", b => { b.Navigation("Works"); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240501122640_InitCreate.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503121400_initCreate.cs similarity index 85% rename from PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240501122640_InitCreate.cs rename to PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503121400_initCreate.cs index 4f55d71..3283641 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240501122640_InitCreate.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20240503121400_initCreate.cs @@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace PlumbingRepairDatabaseImplement.Migrations { - public partial class InitCreate : Migration + public partial class initCreate : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -38,6 +38,22 @@ namespace PlumbingRepairDatabaseImplement.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: "Shops", columns: table => new @@ -76,6 +92,7 @@ namespace PlumbingRepairDatabaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), WorkId = table.Column(type: "int", nullable: false), ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), Status = table.Column(type: "int", nullable: false), @@ -91,6 +108,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Works_WorkId", column: x => x.WorkId, @@ -158,6 +180,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_WorkId", table: "Orders", @@ -198,6 +225,9 @@ namespace PlumbingRepairDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Shops"); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs index efdde03..726c524 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/PlumbingRepairDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("WorkId"); b.ToTable("Orders"); @@ -212,6 +244,10 @@ namespace PlumbingRepairDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("PlumbingRepairDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work") .WithMany("Orders") .HasForeignKey("WorkId") @@ -220,6 +256,8 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Work"); }); @@ -271,6 +309,11 @@ namespace PlumbingRepairDatabaseImplement.Migrations b.Navigation("WorkComponents"); }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Shop", b => { b.Navigation("Works"); diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..ea0fb22 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,76 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace PlumbingRepairDatabaseImplement.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 static Implementer Create(ImplementerViewModel model) + { + return new Implementer + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification= Qualification, + }; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs index e699921..b3396dd 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Order.cs @@ -12,6 +12,7 @@ namespace PlumbingRepairDatabaseImplement.Models public int WorkId { get; set; } [Required] public int ClientId { get; set; } + public int? ImplementerId { get; set; } [Required] public int Count { get; set; } @@ -28,6 +29,7 @@ namespace PlumbingRepairDatabaseImplement.Models public virtual Work Work { get; set; } public virtual Client Client { get; set; } + public virtual Implementer? Implementer { get; set; } public static Order? Create( OrderBindingModel? model) { @@ -38,6 +40,7 @@ namespace PlumbingRepairDatabaseImplement.Models Id = model.Id, WorkId = model.WorkId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,12 +55,18 @@ namespace PlumbingRepairDatabaseImplement.Models return; Status = model.Status; DateImplement = model.DateImplement; + if (model.ImplementerId.HasValue) + { + ImplementerId = model.ImplementerId; + } } public OrderViewModel GetViewModel => new() { WorkId = WorkId, ClientId = ClientId, + ImplementerId= ImplementerId, + ImplementerFIO = Implementer == null ? null : Implementer.ImplementerFIO, Count = Count, Sum = Sum, DateCreate = DateCreate, diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs index ecf78b7..9f8f624 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/PlumbingRepairDatabase.cs @@ -26,5 +26,6 @@ namespace PlumbingRepairDatabaseImplement public virtual DbSet ShopWorks { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs b/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs index 5ad05d3..2922dc0 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/DataFileSingleton.cs @@ -16,6 +16,7 @@ namespace PlumbingRepairFileImplement private readonly string ShopFileName = "Shop.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; } @@ -24,6 +25,7 @@ namespace PlumbingRepairFileImplement public List Shops { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -41,6 +43,7 @@ namespace PlumbingRepairFileImplement public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; @@ -48,6 +51,8 @@ namespace PlumbingRepairFileImplement Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Shops = LoadData(ShopFileName, "Shop", x => Shop.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/PlumbingRepair/PlumbingRepairFileImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..d3c8601 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,87 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairFileImplement.Models; +using System.Net; + +namespace PlumbingRepairFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + return source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + return source.Implementers + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var client = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + source.SaveImplementers(); + return client.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs index d437bc7..1c0bbf6 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Implements/OrderStorage.cs @@ -31,7 +31,11 @@ namespace PlumbingRepairFileImplement.Implements { return null; } - return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + if (model.ImplementerId.HasValue && model.Status.HasValue) + return GetViewModel(source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status)); + if (model.Id.HasValue) + return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + return null; } @@ -47,8 +51,11 @@ namespace PlumbingRepairFileImplement.Implements .ToList(); if (model.ClientId.HasValue) return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList(); + if (model.ImplementerId.HasValue && model.Status.HasValue) + return source.Orders.Where(x => x.ImplementerId == model.ImplementerId && x.Status == model.Status).Select(x => GetViewModel(x)).ToList(); return source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo). Select(x => GetViewModel(x)).ToList(); + } public List GetFullList() @@ -92,6 +99,7 @@ namespace PlumbingRepairFileImplement.Implements { viewModel.WorkName = work.WorkName; } + return viewModel; } } diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..6bff04e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Implementer.cs @@ -0,0 +1,79 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; +using System.Xml.Linq; + +namespace PlumbingRepairFileImplement.Models +{ + internal 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 Qualification { get; private set; } + public int WorkExperience { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = Convert.ToString(element.Element("Password")!.Value), + Qualification = Convert.ToInt32(element.Attribute("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Attribute("WorkExperience")!.Value), + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + WorkExperience = WorkExperience + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + + ); + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs index 7e68eb8..c0c5d63 100644 --- a/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairFileImplement/Models/Order.cs @@ -11,6 +11,7 @@ namespace PlumbingRepairFileImplement.Models { public int WorkId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } @@ -33,6 +34,8 @@ namespace PlumbingRepairFileImplement.Models return new Order() { WorkId = model.WorkId, + ClientId= model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,6 +55,8 @@ namespace PlumbingRepairFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), WorkId = Convert.ToInt32(element.Element("WorkId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -85,6 +90,8 @@ namespace PlumbingRepairFileImplement.Models "Order", new XAttribute("Id", Id), new XElement("WorkId", WorkId.ToString()), + new XElement("ClientId", ClientId.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs index 216ce60..e731128 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/DataListSingleton.cs @@ -12,6 +12,8 @@ namespace PlumbingRepairListImplement public List Works { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } + public List Shops { get; set; } @@ -22,6 +24,7 @@ namespace PlumbingRepairListImplement Works = new List(); Shops = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..df9f020 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,108 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.StoragesContracts; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairListImplement.Models; + +namespace PlumbingRepairListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var client in _source.Implementers) + { + result.Add(client.GetViewModel); + } + return result; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + foreach (var client in _source.Implementers) + { + if (client.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(client.GetViewModel); + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + foreach (var client in _source.Implementers) + { + if ((!string.IsNullOrEmpty(model.ImplementerFIO) && client.ImplementerFIO == model.ImplementerFIO) || + (model.Id.HasValue && client.Id == model.Id)) + { + return client.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var client in _source.Implementers) + { + if (model.Id <= client.Id) + { + model.Id = client.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var Implementer in _source.Implementers) + { + if (Implementer.Id == model.Id) + { + Implementer.Update(model); + return Implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs index e96335a..ca61c94 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Implements/OrderStorage.cs @@ -41,6 +41,26 @@ namespace PlumbingRepairListImplement.Implements return AttachInfo(order.GetViewModel); } } + if (model.Id.HasValue) + { + foreach (var Order in _source.Orders) + { + if (Order.Id == model.Id) + { + return Order.GetViewModel; + } + } + } + else if (model.ImplementerId.HasValue && model.Status.HasValue) + { + foreach (var Order in _source.Orders) + { + if (Order.ImplementerId == model.ImplementerId && Order.Status == model.Status) + { + return Order.GetViewModel; + } + } + } return null; } diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs new file mode 100644 index 0000000..1c3dd9e --- /dev/null +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Implementer.cs @@ -0,0 +1,52 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Models; + +namespace PlumbingRepairListImplement.Models +{ + internal 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 Qualification { get; private set; } + public int WorkExperience { get; private set; } + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + WorkExperience = WorkExperience, + }; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs index 68ce6f6..a4d3af6 100644 --- a/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs +++ b/PlumbingRepair/PlumbingRepairListImplement/Models/Order.cs @@ -9,6 +9,7 @@ namespace PlumbingRepairListImplement.Models { public int WorkId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } @@ -33,6 +34,7 @@ namespace PlumbingRepairListImplement.Models Id = model.Id, WorkId = model.WorkId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -50,6 +52,7 @@ namespace PlumbingRepairListImplement.Models } Status = model.Status; DateImplement= model.DateImplement; + ImplementerId= model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -58,6 +61,7 @@ namespace PlumbingRepairListImplement.Models WorkId = WorkId, Count = Count, ClientId= ClientId, + ImplementerId = ImplementerId, Sum = Sum, Status = Status, DateCreate = DateCreate, diff --git a/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs b/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..07a222b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,107 @@ +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; +using PlumbingRepairContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; +using PlumbingRepairDataModels.Enums; + +namespace PlumbingRepairRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementerLogic _logic; + + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id); + throw; + } + } + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairRestApi/Program.cs b/PlumbingRepair/PlumbingRepairRestApi/Program.cs index bf4e7ee..cc8f2d7 100644 --- a/PlumbingRepair/PlumbingRepairRestApi/Program.cs +++ b/PlumbingRepair/PlumbingRepairRestApi/Program.cs @@ -14,11 +14,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/PlumbingRepair/PlumbingRepairView/FormImplementer.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormImplementer.Designer.cs new file mode 100644 index 0000000..54dedf9 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormImplementer.Designer.cs @@ -0,0 +1,173 @@ +namespace PlumbingRepairView +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.labelPassword = new System.Windows.Forms.Label(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.labelImplementerFIO = new System.Windows.Forms.Label(); + this.textBoxWorkExperience = new System.Windows.Forms.TextBox(); + this.labelWorkExperience = new System.Windows.Forms.Label(); + this.textBoxQualification = new System.Windows.Forms.TextBox(); + this.labelQualification = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(138, 74); + this.textBoxPassword.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(334, 31); + this.textBoxPassword.TabIndex = 15; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(4, 80); + this.labelPassword.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(78, 25); + this.labelPassword.TabIndex = 14; + this.labelPassword.Text = "Пароль:"; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(346, 221); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 45); + this.buttonCancel.TabIndex = 17; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(210, 221); + this.buttonSave.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 45); + this.buttonSave.TabIndex = 16; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(138, 26); + this.textBoxName.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(334, 31); + this.textBoxName.TabIndex = 13; + // + // labelImplementerFIO + // + this.labelImplementerFIO.AutoSize = true; + this.labelImplementerFIO.Location = new System.Drawing.Point(4, 32); + this.labelImplementerFIO.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelImplementerFIO.Name = "labelImplementerFIO"; + this.labelImplementerFIO.Size = new System.Drawing.Size(56, 25); + this.labelImplementerFIO.TabIndex = 12; + this.labelImplementerFIO.Text = "ФИО:"; + // + // textBoxWorkExperience + // + this.textBoxWorkExperience.Location = new System.Drawing.Point(138, 124); + this.textBoxWorkExperience.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxWorkExperience.Name = "textBoxWorkExperience"; + this.textBoxWorkExperience.Size = new System.Drawing.Size(183, 31); + this.textBoxWorkExperience.TabIndex = 19; + // + // labelWorkExperience + // + this.labelWorkExperience.AutoSize = true; + this.labelWorkExperience.Location = new System.Drawing.Point(4, 130); + this.labelWorkExperience.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelWorkExperience.Name = "labelWorkExperience"; + this.labelWorkExperience.Size = new System.Drawing.Size(122, 25); + this.labelWorkExperience.TabIndex = 18; + this.labelWorkExperience.Text = "Стаж работы:"; + // + // textBoxQualification + // + this.textBoxQualification.Location = new System.Drawing.Point(138, 171); + this.textBoxQualification.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.textBoxQualification.Name = "textBoxQualification"; + this.textBoxQualification.Size = new System.Drawing.Size(183, 31); + this.textBoxQualification.TabIndex = 21; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(4, 171); + this.labelQualification.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(134, 25); + this.labelQualification.TabIndex = 20; + this.labelQualification.Text = "Квалификация:"; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(485, 281); + this.Controls.Add(this.textBoxQualification); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.textBoxWorkExperience); + this.Controls.Add(this.labelWorkExperience); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelImplementerFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + this.Load += new System.EventHandler(this.FormImplementer_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxPassword; + private Label labelPassword; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxName; + private Label labelImplementerFIO; + private TextBox textBoxWorkExperience; + private Label labelWorkExperience; + private TextBox textBoxQualification; + private Label labelQualification; + } +} \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormImplementer.cs b/PlumbingRepair/PlumbingRepairView/FormImplementer.cs new file mode 100644 index 0000000..292685a --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormImplementer.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; +using PlumbingRepairContracts.SearchModels; + +namespace PlumbingRepairView +{ + 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) + { + textBoxName.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + textBoxQualification.Text = view.Qualification.ToString(); + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQualification.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxWorkExperience.Text)) + { + MessageBox.Show("Заполните ФИО исполнителя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxName.Text, + Password= textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepairView/FormImplementer.resx b/PlumbingRepair/PlumbingRepairView/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormImplementer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormImplementers.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormImplementers.Designer.cs new file mode 100644 index 0000000..7cf7c30 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormImplementers.Designer.cs @@ -0,0 +1,127 @@ +namespace PlumbingRepairView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(661, 254); + this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(125, 44); + this.buttonRef.TabIndex = 14; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(661, 175); + this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(125, 44); + this.buttonDel.TabIndex = 13; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(661, 96); + this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(125, 44); + this.buttonUpd.TabIndex = 12; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(661, 23); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(125, 44); + this.buttonAdd.TabIndex = 11; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(583, 450); + this.dataGridView.TabIndex = 10; + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + this.Load += new System.EventHandler(this.FormImplementers_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.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/PlumbingRepair/PlumbingRepairView/FormImplementers.cs b/PlumbingRepair/PlumbingRepairView/FormImplementers.cs new file mode 100644 index 0000000..2d1e250 --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormImplementers.cs @@ -0,0 +1,102 @@ +using Microsoft.Extensions.Logging; +using PlumbingRepairContracts.BindingModels; +using PlumbingRepairContracts.BusinessLogicsContracts; + +namespace PlumbingRepairView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/PlumbingRepair/PlumbingRepairView/FormImplementers.resx b/PlumbingRepair/PlumbingRepairView/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PlumbingRepair/PlumbingRepairView/FormImplementers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs b/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs index c1e25f9..5401a6b 100644 --- a/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs +++ b/PlumbingRepair/PlumbingRepairView/FormMain.Designer.cs @@ -28,252 +28,242 @@ /// private void InitializeComponent() { - this.buttonRef = new System.Windows.Forms.Button(); - this.buttonIssuedOrder = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - 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.списокЗаказов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(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.menuStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // buttonRef - // - this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRef.Location = new System.Drawing.Point(1113, 373); - this.buttonRef.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(249, 45); - this.buttonRef.TabIndex = 11; - this.buttonRef.Text = "Обновить список"; - this.buttonRef.UseVisualStyleBackColor = true; - this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonIssuedOrder - // - this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonIssuedOrder.Location = new System.Drawing.Point(1113, 297); - this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(249, 45); - this.buttonIssuedOrder.TabIndex = 10; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOrderReady.Location = new System.Drawing.Point(1113, 225); - this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(249, 45); - this.buttonOrderReady.TabIndex = 9; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1113, 158); - this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(249, 45); - this.buttonTakeOrderInWork.TabIndex = 8; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonCreateOrder - // - this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCreateOrder.Location = new System.Drawing.Point(1113, 83); - this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(249, 45); - this.buttonCreateOrder.TabIndex = 7; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // dataGridView - // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + 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.компонентыПоРаботам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(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // buttonRef + // + this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRef.Location = new System.Drawing.Point(1113, 227); + this.buttonRef.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(249, 45); + this.buttonRef.TabIndex = 11; + this.buttonRef.Text = "Обновить список"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonIssuedOrder.Location = new System.Drawing.Point(1113, 151); + this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(249, 45); + this.buttonIssuedOrder.TabIndex = 10; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonCreateOrder + // + this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCreateOrder.Location = new System.Drawing.Point(1113, 83); + this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(249, 45); + this.buttonCreateOrder.TabIndex = 7; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(2, 44); - this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); - this.dataGridView.MultiSelect = false; - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowHeadersVisible = false; - this.dataGridView.RowHeadersWidth = 62; - this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.dataGridView.Size = new System.Drawing.Size(1055, 533); - this.dataGridView.TabIndex = 6; - // - // menuStrip1 - // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(2, 44); + this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 62; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(1055, 533); + this.dataGridView.TabIndex = 6; + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem, - this.отчетыToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1377, 33); - this.menuStrip1.TabIndex = 12; - this.menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.отчетыToolStripMenuItem, + this.выполнениеРаботToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1377, 33); + this.menuStrip1.TabIndex = 12; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, this.РаботыToolStripMenuItem, this.магазиныToolStripMenuItem, this.пToolStripMenuItem, this.продажаРаботToolStripMenuItem, - this.клиентыToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(296, 34); - this.компонентыToolStripMenuItem.Text = "Компоненты"; - this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); - // - // РаботыToolStripMenuItem - // - this.РаботыToolStripMenuItem.Name = "РаботыToolStripMenuItem"; - this.РаботыToolStripMenuItem.Size = new System.Drawing.Size(296, 34); - this.РаботыToolStripMenuItem.Text = "Работы"; - this.РаботыToolStripMenuItem.Click += new System.EventHandler(this.РаботыToolStripMenuItem_Click); - // - // магазиныToolStripMenuItem - // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(296, 34); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); - // - // пToolStripMenuItem - // - this.пToolStripMenuItem.Name = "пToolStripMenuItem"; - this.пToolStripMenuItem.Size = new System.Drawing.Size(296, 34); - this.пToolStripMenuItem.Text = "Пополнение магазина"; - this.пToolStripMenuItem.Click += new System.EventHandler(this.пополнениеToolStripMenuItem_Click); - // - // продажаРаботToolStripMenuItem - // - this.продажаРаботToolStripMenuItem.Name = "продажаРаботToolStripMenuItem"; - this.продажаРаботToolStripMenuItem.Size = new System.Drawing.Size(296, 34); - this.продажаРаботToolStripMenuItem.Text = "Продажа работ"; - this.продажаРаботToolStripMenuItem.Click += new System.EventHandler(this.продажаРаботToolStripMenuItem_Click); - // - // отчетыToolStripMenuItem - // - this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.клиентыToolStripMenuItem, + this.исполнителиToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // РаботыToolStripMenuItem + // + this.РаботыToolStripMenuItem.Name = "РаботыToolStripMenuItem"; + this.РаботыToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.РаботыToolStripMenuItem.Text = "Работы"; + this.РаботыToolStripMenuItem.Click += new System.EventHandler(this.РаботыToolStripMenuItem_Click); + // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // + // пToolStripMenuItem + // + this.пToolStripMenuItem.Name = "пToolStripMenuItem"; + this.пToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.пToolStripMenuItem.Text = "Пополнение магазина"; + this.пToolStripMenuItem.Click += new System.EventHandler(this.пополнениеToolStripMenuItem_Click); + // + // продажаРаботToolStripMenuItem + // + this.продажаРаботToolStripMenuItem.Name = "продажаРаботToolStripMenuItem"; + this.продажаРаботToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.продажаРаботToolStripMenuItem.Text = "Продажа работ"; + this.продажаРаботToolStripMenuItem.Click += new System.EventHandler(this.продажаРаботToolStripMenuItem_Click); + // + // клиентыToolStripMenuItem + // + this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.клиентыToolStripMenuItem.Text = "Клиенты"; + this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); + // + // отчетыToolStripMenuItem + // + this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокКомпонентовToolStripMenuItem, this.компонентыПоРаботамToolStripMenuItem, this.списокЗаказовToolStripMenuItem, this.списокМагазиновToolStripMenuItem, this.работыПоМагазинамToolStripMenuItem, this.списокВсехЗаказовToolStripMenuItem}); - this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); - this.отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокКомпонентовToolStripMenuItem - // - this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; - this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(319, 34); - this.списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; - this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click); - // - // компонентыПоРаботамToolStripMenuItem - // - this.компонентыПоРаботамToolStripMenuItem.Name = "компонентыПоРаботамToolStripMenuItem"; - this.компонентыПоРаботамToolStripMenuItem.Size = new System.Drawing.Size(319, 34); - this.компонентыПоРаботамToolStripMenuItem.Text = "Компоненты по работам"; - // - // списокЗаказовToolStripMenuItem - // - this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(319, 34); - this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; - // - // списокМагазиновToolStripMenuItem - // - this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; - this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(319, 34); - this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; - this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); - // - // работыПоМагазинамToolStripMenuItem - // - this.работыПоМагазинамToolStripMenuItem.Name = "работыПоМагазинамToolStripMenuItem"; - this.работыПоМагазинамToolStripMenuItem.Size = new System.Drawing.Size(319, 34); - this.работыПоМагазинамToolStripMenuItem.Text = "Работы по магазинам"; - this.работыПоМагазинамToolStripMenuItem.Click += new System.EventHandler(this.ShopWorksToolStripMenuItem_Click); - // - // списокВсехЗаказовToolStripMenuItem - // - this.списокВсехЗаказовToolStripMenuItem.Name = "списокВсехЗаказовToolStripMenuItem"; - this.списокВсехЗаказовToolStripMenuItem.Size = new System.Drawing.Size(319, 34); - this.списокВсехЗаказовToolStripMenuItem.Text = "Список всех заказов"; - this.списокВсехЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersByDateToolStripMenuItem_Click); - // - // клиентыToolStripMenuItem - // - this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(296, 34); - this.клиентыToolStripMenuItem.Text = "Клиенты"; - this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1377, 602); - 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); - this.MainMenuStrip = this.menuStrip1; - this.Name = "FormMain"; - this.Text = "Ремонт труб"; - this.Load += new System.EventHandler(this.FormMain_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); + this.отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + this.отчетыToolStripMenuItem.Size = new System.Drawing.Size(88, 29); + this.отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокКомпонентовToolStripMenuItem + // + this.списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; + this.списокКомпонентовToolStripMenuItem.Size = new System.Drawing.Size(319, 34); + this.списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; + this.списокКомпонентовToolStripMenuItem.Click += new System.EventHandler(this.списокКомпонентовToolStripMenuItem_Click); + // + // компонентыПоРаботамToolStripMenuItem + // + this.компонентыПоРаботамToolStripMenuItem.Name = "компонентыПоРаботамToolStripMenuItem"; + this.компонентыПоРаботамToolStripMenuItem.Size = new System.Drawing.Size(319, 34); + this.компонентыПоРаботамToolStripMenuItem.Text = "Компоненты по работам"; + // + // списокЗаказовToolStripMenuItem + // + this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(319, 34); + this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; + // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(319, 34); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // + // работыПоМагазинамToolStripMenuItem + // + this.работыПоМагазинамToolStripMenuItem.Name = "работыПоМагазинамToolStripMenuItem"; + this.работыПоМагазинамToolStripMenuItem.Size = new System.Drawing.Size(319, 34); + this.работыПоМагазинамToolStripMenuItem.Text = "Работы по магазинам"; + this.работыПоМагазинамToolStripMenuItem.Click += new System.EventHandler(this.ShopWorksToolStripMenuItem_Click); + // + // списокВсехЗаказовToolStripMenuItem + // + this.списокВсехЗаказовToolStripMenuItem.Name = "списокВсехЗаказовToolStripMenuItem"; + this.списокВсехЗаказовToolStripMenuItem.Size = new System.Drawing.Size(319, 34); + this.списокВсехЗаказовToolStripMenuItem.Text = "Список всех заказов"; + this.списокВсехЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersByDateToolStripMenuItem_Click); + // + // выполнениеРаботToolStripMenuItem + // + this.выполнениеРаботToolStripMenuItem.Name = "выполнениеРаботToolStripMenuItem"; + this.выполнениеРаботToolStripMenuItem.Size = new System.Drawing.Size(136, 29); + this.выполнениеРаботToolStripMenuItem.Text = "Запуск работ"; + this.выполнениеРаботToolStripMenuItem.Click += new System.EventHandler(this.выполнениеРаботToolStripMenuItem_Click); + // + // исполнителиToolStripMenuItem + // + this.исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + this.исполнителиToolStripMenuItem.Size = new System.Drawing.Size(296, 34); + this.исполнителиToolStripMenuItem.Text = "Исполнители"; + this.исполнителиToolStripMenuItem.Click += new System.EventHandler(this.исполнителиToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1377, 602); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Ремонт труб"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -281,8 +271,6 @@ private Button buttonRef; private Button buttonIssuedOrder; - private Button buttonOrderReady; - private Button buttonTakeOrderInWork; private Button buttonCreateOrder; private DataGridView dataGridView; private MenuStrip menuStrip1; @@ -300,5 +288,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/PlumbingRepair/PlumbingRepairView/FormMain.cs b/PlumbingRepair/PlumbingRepairView/FormMain.cs index 0ca5eb3..0e97bf3 100644 --- a/PlumbingRepair/PlumbingRepairView/FormMain.cs +++ b/PlumbingRepair/PlumbingRepairView/FormMain.cs @@ -11,13 +11,14 @@ namespace PlumbingRepairView 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) @@ -34,7 +35,7 @@ namespace PlumbingRepairView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -90,51 +91,6 @@ namespace PlumbingRepairView } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } private void ButtonIssuedOrder_Click(object sender, EventArgs e) { @@ -252,5 +208,22 @@ namespace PlumbingRepairView form.ShowDialog(); } } - } + + private void выполнениеРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + } } \ No newline at end of file diff --git a/PlumbingRepair/PlumbingRepairView/Program.cs b/PlumbingRepair/PlumbingRepairView/Program.cs index bdc8e8a..831a407 100644 --- a/PlumbingRepair/PlumbingRepairView/Program.cs +++ b/PlumbingRepair/PlumbingRepairView/Program.cs @@ -43,7 +43,8 @@ namespace PlumbingRepairView services.AddTransient(); services.AddTransient(); - + services.AddTransient(); + services.AddTransient(); services.AddTransient(); @@ -51,6 +52,8 @@ namespace PlumbingRepairView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -74,6 +77,8 @@ namespace PlumbingRepairView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file