diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..4b39348 --- /dev/null +++ b/AutoWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,135 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopBusinessLogic.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}. Password: {Password}. Id: {Id}", + Model?.ImplementerFIO, Model?.Password?.Length, Model?.Id); + + var List = Model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(Model); + + if (List == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count: {Count}", List.Count); + return List; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel Model) + { + if (Model is null) + { + throw new ArgumentNullException(nameof(Model)); + } + + _logger.LogInformation("ReadElement. ImplementerFIO: {ImplementerFIO}. Password: {Password}. Id: {Id}", + Model?.ImplementerFIO, Model?.Password?.Length, Model?.Id); + + var Element = _implementerStorage.GetElement(Model); + + if (Element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id: {Id}", Element.Id); + return Element; + } + + public bool Create(ImplementerBindingModel Model) + { + CheckModel(Model); + + if (_implementerStorage.Insert(Model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + + return true; + } + + public bool Update(ImplementerBindingModel Model) + { + CheckModel(Model); + + if (_implementerStorage.Update(Model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + + return true; + } + + public bool Delete(ImplementerBindingModel Model) + { + CheckModel(Model, false); + + _logger.LogInformation("Delete. Id:{Id}", Model.Id); + + if (_implementerStorage.Delete(Model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + + return true; + } + + private void CheckModel(ImplementerBindingModel Model, bool WithParams = true) + { + if (Model == null) + throw new ArgumentNullException(nameof(Model)); + + if (!WithParams) + return; + + if (string.IsNullOrEmpty(Model.ImplementerFIO)) + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(Model.ImplementerFIO)); + + if (string.IsNullOrEmpty(Model.Password)) + throw new ArgumentNullException("Нет пароля исполнителя", nameof(Model.Password)); + + if (Model.WorkExperience < 0) + throw new ArgumentNullException("Стаж должен быть неотрицательным целым числом", nameof(Model.WorkExperience)); + + if (Model.Qualification < 0) + throw new ArgumentNullException("Квалификация должна быть неотрицательным целым числом", nameof(Model.Qualification)); + + _logger.LogInformation("Implementer. ImplementerFIO: {ImplementerFIO}. Password: {Password}. WorkExperience: {WorkExperience}. Qualification: {Qualification}. Id: {Id}", + Model.ImplementerFIO, Model.Password, Model.WorkExperience, Model.Qualification, Model.Id); + + var Implementer = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = Model.ImplementerFIO + }); + + if (Implementer != null && Implementer.Id != Model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 246c491..4bb3da8 100644 --- a/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutoWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -14,6 +14,8 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics private readonly IOrderStorage _orderStorage; + static readonly object _locker = new object(); + public OrderLogic(ILogger Logger, IOrderStorage OrderStorage) { _logger = Logger; @@ -22,19 +24,18 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public List? ReadList(OrderSearchModel? Model) { - _logger.LogInformation("ReadList. Id:{Id}", Model?.Id); + _logger.LogInformation("ReadList. ClientId: {ClientId}. Status: {Status}. ImplementerId: {ImplementerId}. DateFrom: {DateFrom}. DateTo: {DateTo}. OrderId: {Id}", + Model?.ClientId, Model?.Status, Model?.ImplementerId, Model?.DateFrom, Model?.DateTo, Model?.Id); + var List = Model is null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(Model); - if (List is null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count: {Count}", List.Count); return List; } - public bool CreateOrder(OrderBindingModel Model) { CheckModel(Model); @@ -76,6 +77,8 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics } Model.RepairId = Order.RepairId; + Model.ClientId = Order.ClientId; + if (!Model.ImplementerId.HasValue) Model.ImplementerId = Order.ImplementerId; Model.Count = Order.Count; Model.Sum = Order.Sum; Model.DateCreate = Order.DateCreate; @@ -97,7 +100,10 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel Model) { - return ChangeOrderStatus(Model, OrderStatus.BeingProcessed); + lock (_locker) + { + return ChangeOrderStatus(Model, OrderStatus.BeingProcessed); + } } public bool FinishOrder(OrderBindingModel Model) @@ -129,5 +135,27 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics Model.RepairId, Model.Count, Model.Sum, Model.Status, Model.DateCreate, Model.DateImplement, Model.Id); } + + public OrderViewModel? ReadElement(OrderSearchModel Model) + { + if (Model == null) + { + throw new ArgumentNullException(nameof(Model)); + } + + _logger.LogInformation("ReadElement. ClientId: {ClientId}. Status: {Status}. ImplementerId: {ImplementerId}. DateFrom: {DateFrom}. DateTo: {DateTo}. OrderId: {Id}", + Model.ClientId, Model.Status, Model.ImplementerId, Model.DateFrom, Model.DateTo, Model.Id); + + var Order = _orderStorage.GetElement(Model); + + if (Order == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id: {Id}", Order.Id); + return Order; + } } } diff --git a/AutoWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/AutoWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..3402718 --- /dev/null +++ b/AutoWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,153 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopBusinessLogic.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.Accepted }); + var BeingProcessedOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.BeingProcessed }); + // in case there are BeingProcessed orders but no Accepted orders + + if (Orders == null || BeingProcessedOrders == null || (Orders.Count == 0 && BeingProcessedOrders.Count == 0)) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + + _logger.LogDebug("DoWork for {Count} orders", Orders.Count); + + foreach (var Implementer in Implementers) + { + Task.Run(() => WorkerWorkAsync(Implementer, Orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel Implementer, List Orders) + { + if (_orderLogic == null || Implementer == null) + { + return; + } + + await RunOrderInWork(Implementer); + + await Task.Run(() => + { + foreach (var Order in Orders) + { + try + { + _logger.LogDebug("WorkerWorkAsync. Worker {Id} try get order {Order}", Implementer.Id, Order.Id); + + // TakeOrderInWork will fail when the worker tries to change status to BeingProcessed when the order is already BeingProcessed + // which would happen when other worker already acquired that order + bool AcquireResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = Order.Id, + ImplementerId = Implementer.Id + }); + + if (!AcquireResult) + { + _logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", Implementer.Id, Order.Id); + continue; + } + + Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 1000) * Order.Count); + + _logger.LogDebug("WorkerWorkAsync. Worker {Id} finish order {Order}", Implementer.Id, Order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = Order.Id + }); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + + Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel Implementer) + { + if (_orderLogic == null || Implementer == null) + return; + + try + { + var RunOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = Implementer.Id, + Status = OrderStatus.BeingProcessed + })); + + if (RunOrder == null) + { + return; + } + + _logger.LogDebug("RunOrderInWork. Worker {Id} back to order {Order}", Implementer.Id, RunOrder.Id); + Thread.Sleep(Implementer.WorkExperience * _rnd.Next(100, 300) * RunOrder.Count); + + _logger.LogDebug("RunOrderInWork. Worker {Id} finish order {Order}", Implementer.Id, RunOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = RunOrder.Id + }); + + Thread.Sleep(Implementer.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/AutoWorkshopContracts/BindingModels/ImplementerBindingModel.cs b/AutoWorkshopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..a9fe78d --- /dev/null +++ b/AutoWorkshopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,17 @@ +using AutoWorkshopDataModels.Models; + +namespace AutoWorkshopContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs b/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs index cad16c1..199b492 100644 --- a/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs +++ b/AutoWorkshopContracts/BindingModels/OrderBindingModel.cs @@ -8,6 +8,7 @@ namespace AutoWorkshopContracts.BindingModels public int Id { get; set; } public int RepairId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Undefined; diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IImplementerLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IImplementerLogic.cs new file mode 100644 index 0000000..5a186fd --- /dev/null +++ b/AutoWorkshopContracts/BusinessLogicContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? Model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel Model); + + bool Create(ImplementerBindingModel Model); + + bool Update(ImplementerBindingModel Model); + + bool Delete(ImplementerBindingModel Model); + } +} diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IOrderLogic.cs b/AutoWorkshopContracts/BusinessLogicContracts/IOrderLogic.cs index 6c298b7..a69ceae 100644 --- a/AutoWorkshopContracts/BusinessLogicContracts/IOrderLogic.cs +++ b/AutoWorkshopContracts/BusinessLogicContracts/IOrderLogic.cs @@ -11,5 +11,6 @@ namespace AutoWorkshopContracts.BusinessLogicContracts bool TakeOrderInWork(OrderBindingModel Model); bool FinishOrder(OrderBindingModel Model); bool DeliveryOrder(OrderBindingModel Model); + OrderViewModel? ReadElement(OrderSearchModel Model); } } diff --git a/AutoWorkshopContracts/BusinessLogicContracts/IWorkProcess.cs b/AutoWorkshopContracts/BusinessLogicContracts/IWorkProcess.cs new file mode 100644 index 0000000..24c8ef5 --- /dev/null +++ b/AutoWorkshopContracts/BusinessLogicContracts/IWorkProcess.cs @@ -0,0 +1,9 @@ +using AutoWorkshopContracts.BusinessLogicsContracts; + +namespace AutoWorkshopContracts.BusinessLogicContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic ImplementerLogic, IOrderLogic OrderLogic); + } +} diff --git a/AutoWorkshopContracts/SearchModels/ImplementerSearchModel.cs b/AutoWorkshopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..258a1b8 --- /dev/null +++ b/AutoWorkshopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,11 @@ +namespace AutoWorkshopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs b/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs index e040df1..5f18f78 100644 --- a/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/AutoWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,6 @@ -namespace AutoWorkshopContracts.SearchModels +using AutoWorkshopDataModels.Enums; + +namespace AutoWorkshopContracts.SearchModels { public class OrderSearchModel { @@ -6,6 +8,10 @@ public int? ClientId { get; set; } + public OrderStatus? Status { get; set; } + + public int? ImplementerId { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } diff --git a/AutoWorkshopContracts/StoragesContracts/IImplementerStorage.cs b/AutoWorkshopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..822b70a --- /dev/null +++ b/AutoWorkshopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; + +namespace AutoWorkshopContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel Model); + + ImplementerViewModel? GetElement(ImplementerSearchModel Model); + + ImplementerViewModel? Insert(ImplementerBindingModel Model); + + ImplementerViewModel? Update(ImplementerBindingModel Model); + + ImplementerViewModel? Delete(ImplementerBindingModel Model); + } +} diff --git a/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs b/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..cf93e02 --- /dev/null +++ b/AutoWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,22 @@ +using AutoWorkshopDataModels.Models; +using System.ComponentModel; + +namespace AutoWorkshopContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/AutoWorkshopContracts/ViewModels/OrderViewModel.cs b/AutoWorkshopContracts/ViewModels/OrderViewModel.cs index df0608e..2a423b0 100644 --- a/AutoWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/AutoWorkshopContracts/ViewModels/OrderViewModel.cs @@ -19,6 +19,11 @@ namespace AutoWorkshopContracts.ViewModels [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + + [DisplayName("Исполнитель")] + public string? ImplementerFIO { get; set; } + [DisplayName("Количество")] public int Count { get; set; } diff --git a/AutoWorkshopDataModels/Models/IImplementerModel.cs b/AutoWorkshopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..0a925e0 --- /dev/null +++ b/AutoWorkshopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,13 @@ +namespace AutoWorkshopDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + + string Password { get; } + + int WorkExperience { get; } + + int Qualification { get; } + } +} diff --git a/AutoWorkshopDataModels/Models/IOrderModel.cs b/AutoWorkshopDataModels/Models/IOrderModel.cs index 7df19c4..190a54f 100644 --- a/AutoWorkshopDataModels/Models/IOrderModel.cs +++ b/AutoWorkshopDataModels/Models/IOrderModel.cs @@ -6,6 +6,7 @@ namespace AutoWorkshopDataModels.Models { int RepairId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs index 31fe0d0..6ded373 100644 --- a/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs +++ b/AutoWorkshopDatabaseImplement/AutoWorkshopDatabase.cs @@ -27,5 +27,7 @@ namespace AutoWorkshopDatabaseImplement public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + + public virtual DbSet Implementers { set; get; } } } diff --git a/AutoWorkshopDatabaseImplement/Implements/ImplementerStorage.cs b/AutoWorkshopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..a01c1d8 --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,90 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDatabaseImplement.Models; + +namespace AutoWorkshopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var Context = new AutoWorkshopDatabase(); + + return Context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ImplementerSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ImplementerFIO)) + { + return new(); + } + using var Context = new AutoWorkshopDatabase(); + 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 AutoWorkshopDatabase(); + + return Context.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO == Model.ImplementerFIO && (!string.IsNullOrEmpty(Model.Password) ? x.Password == Model.Password : true)) || + (Model.Id.HasValue && x.Id == Model.Id)) + ?.GetViewModel; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel Model) + { + var NewImplementer = Implementer.Create(Model); + if (NewImplementer == null) + { + return null; + } + using var Context = new AutoWorkshopDatabase(); + + Context.Implementers.Add(NewImplementer); + Context.SaveChanges(); + + return NewImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + + var Implementer = Context.Implementers.FirstOrDefault(x => x.Id == Model.Id); + if (Implementer == null) + { + return null; + } + + Implementer.Update(Model); + Context.SaveChanges(); + + return Implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel Model) + { + using var Context = new AutoWorkshopDatabase(); + + var Implementer = Context.Implementers.FirstOrDefault(rec => rec.Id == Model.Id); + if (Implementer == null) + { + return null; + } + + Context.Implementers.Remove(Implementer); + Context.SaveChanges(); + + return Implementer.GetViewModel; + } + } +} diff --git a/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs b/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs index 66fe8f7..a2f116a 100644 --- a/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -16,6 +16,7 @@ namespace AutoWorkshopDatabaseImplement.Implements return Context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -29,6 +30,7 @@ namespace AutoWorkshopDatabaseImplement.Implements return Context.Orders .Include(x => x.Repair) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId)) .Select(x => x.GetViewModel) .ToList(); @@ -37,14 +39,18 @@ namespace AutoWorkshopDatabaseImplement.Implements return Context.Orders .Include(x => x.Repair) .Include(x => x.Client) - .Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)) + .Include (x => x.Implementer) + .Where(x => (Model.Id.HasValue && x.Id == Model.Id) + || (Model.ClientId.HasValue && x.ClientId == Model.ClientId) + || (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId) + || (Model.Status.HasValue && x.Status == Model.Status)) .Select(x => x.GetViewModel) .ToList(); } public OrderViewModel? GetElement(OrderSearchModel Model) { - if (!Model.Id.HasValue) + if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue) return null; using var Context = new AutoWorkshopDatabase(); @@ -52,7 +58,9 @@ namespace AutoWorkshopDatabaseImplement.Implements return Context.Orders .Include(x => x.Repair) .Include(x => x.Client) - .FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)? + .Include(x => x.Implementer) + .FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id) + || (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status) )? .GetViewModel; } @@ -70,7 +78,7 @@ namespace AutoWorkshopDatabaseImplement.Implements Context.Orders.Add(NewOrder); Context.SaveChanges(); - return Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel; + return Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel Model) @@ -84,13 +92,13 @@ namespace AutoWorkshopDatabaseImplement.Implements Order.Update(Model); Context.SaveChanges(); - return Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel; + return Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel Model) { using var Context = new AutoWorkshopDatabase(); - var Order = Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(rec => rec.Id == Model.Id); + var Order = Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == Model.Id); if (Order == null) return null; diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240411091839_Clients.Designer.cs b/AutoWorkshopDatabaseImplement/Migrations/20240416160914_Implementers.Designer.cs similarity index 82% rename from AutoWorkshopDatabaseImplement/Migrations/20240411091839_Clients.Designer.cs rename to AutoWorkshopDatabaseImplement/Migrations/20240416160914_Implementers.Designer.cs index 61a3eaf..5e9800b 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/20240411091839_Clients.Designer.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/20240416160914_Implementers.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AutoWorkshopDatabaseImplement.Migrations { [DbContext(typeof(AutoWorkshopDatabase))] - [Migration("20240411091839_Clients")] - partial class Clients + [Migration("20240416160914_Implementers")] + partial class Implementers { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -70,6 +70,33 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -90,6 +117,9 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp without time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("RepairId") .HasColumnType("integer"); @@ -103,6 +133,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("RepairId"); b.ToTable("Orders"); @@ -162,6 +194,10 @@ namespace AutoWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("AutoWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") .WithMany("Orders") .HasForeignKey("RepairId") @@ -170,6 +206,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Repair"); }); @@ -202,6 +240,11 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("RepairComponents"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b => { b.Navigation("Components"); diff --git a/AutoWorkshopDatabaseImplement/Migrations/20240411091839_Clients.cs b/AutoWorkshopDatabaseImplement/Migrations/20240416160914_Implementers.cs similarity index 81% rename from AutoWorkshopDatabaseImplement/Migrations/20240411091839_Clients.cs rename to AutoWorkshopDatabaseImplement/Migrations/20240416160914_Implementers.cs index c1ef402..5968997 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/20240411091839_Clients.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/20240416160914_Implementers.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AutoWorkshopDatabaseImplement.Migrations { /// - public partial class Clients : Migration + public partial class Implementers : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -41,6 +41,22 @@ namespace AutoWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ImplementerFIO = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + WorkExperience = table.Column(type: "integer", nullable: false), + Qualification = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Repairs", columns: table => new @@ -63,6 +79,7 @@ namespace AutoWorkshopDatabaseImplement.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RepairId = table.Column(type: "integer", nullable: false), ClientId = table.Column(type: "integer", nullable: false), + ImplementerId = table.Column(type: "integer", nullable: true), Count = table.Column(type: "integer", nullable: false), Sum = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), @@ -78,6 +95,11 @@ namespace AutoWorkshopDatabaseImplement.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_Repairs_RepairId", column: x => x.RepairId, @@ -118,6 +140,11 @@ namespace AutoWorkshopDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_RepairId", table: "Orders", @@ -146,6 +173,9 @@ namespace AutoWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); diff --git a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs index c4adfe7..8d079d4 100644 --- a/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs +++ b/AutoWorkshopDatabaseImplement/Migrations/AutoWorkshopDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp without time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("RepairId") .HasColumnType("integer"); @@ -100,6 +130,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("RepairId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace AutoWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("AutoWorkshopDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.HasOne("AutoWorkshopDatabaseImplement.Models.Repair", "Repair") .WithMany("Orders") .HasForeignKey("RepairId") @@ -167,6 +203,8 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Repair"); }); @@ -199,6 +237,11 @@ namespace AutoWorkshopDatabaseImplement.Migrations b.Navigation("RepairComponents"); }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); + modelBuilder.Entity("AutoWorkshopDatabaseImplement.Models.Repair", b => { b.Navigation("Components"); diff --git a/AutoWorkshopDatabaseImplement/Models/Implementer.cs b/AutoWorkshopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..1c274e9 --- /dev/null +++ b/AutoWorkshopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AutoWorkshopDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; set; } + + [Required] + public string ImplementerFIO { get; set; } = string.Empty; + + [Required] + public string Password { get; set; } = string.Empty; + + [Required] + public int WorkExperience { get; set; } + + [Required] + public int Qualification { get; set; } + + [ForeignKey("ImplementerId")] + public virtual List Order { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel? Model) + { + if (Model == null) + return null; + + return new Implementer() + { + Id = Model.Id, + ImplementerFIO = Model.ImplementerFIO, + Password = Model.Password, + WorkExperience = Model.WorkExperience, + Qualification = Model.Qualification + }; + } + + public void Update(ImplementerBindingModel Model) + { + if (Model == null) + { + return; + } + ImplementerFIO = Model.ImplementerFIO; + Password = Model.Password; + WorkExperience = Model.WorkExperience; + Qualification = Model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/AutoWorkshopDatabaseImplement/Models/Order.cs b/AutoWorkshopDatabaseImplement/Models/Order.cs index cb77571..2bc3c9b 100644 --- a/AutoWorkshopDatabaseImplement/Models/Order.cs +++ b/AutoWorkshopDatabaseImplement/Models/Order.cs @@ -20,6 +20,10 @@ namespace AutoWorkshopDatabaseImplement.Models public virtual Client Client { get; set; } + public int? ImplementerId { get; private set; } + + public virtual Implementer? Implementer { get; set; } + [Required] public int Count { get; private set; } @@ -44,6 +48,7 @@ namespace AutoWorkshopDatabaseImplement.Models Id = Model.Id, RepairId = Model.RepairId, ClientId = Model.ClientId, + ImplementerId = Model.ImplementerId, Count = Model.Count, Sum = Model.Sum, Status = Model.Status, @@ -57,6 +62,7 @@ namespace AutoWorkshopDatabaseImplement.Models if (Model is null) return; + ImplementerId = Model.ImplementerId; Status = Model.Status; DateImplement = Model.DateImplement; } @@ -66,8 +72,10 @@ namespace AutoWorkshopDatabaseImplement.Models Id = Id, RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, RepairName = Repair.RepairName, ClientFIO = Client.ClientFIO, + ImplementerFIO = Implementer?.ImplementerFIO, Count = Count, Sum = Sum, Status = Status, diff --git a/AutoWorkshopFileImplement/DataFileSingleton.cs b/AutoWorkshopFileImplement/DataFileSingleton.cs index f638cc5..42fb3f1 100644 --- a/AutoWorkshopFileImplement/DataFileSingleton.cs +++ b/AutoWorkshopFileImplement/DataFileSingleton.cs @@ -11,6 +11,7 @@ namespace AutoWorkshopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string RepairFileName = "Repair.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } @@ -20,12 +21,15 @@ namespace AutoWorkshopFileImplement public List Clients { get; private set; } + public List Implementers { get; private set; } + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } public static DataFileSingleton GetInstance() @@ -42,6 +46,7 @@ namespace AutoWorkshopFileImplement public void SaveRepairs() => SaveData(Repairs, RepairFileName, "Repairs", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); private static List? LoadData(string FileName, string XmlNodeName, Func SelectFunction) { diff --git a/AutoWorkshopFileImplement/Implements/ImplementerStorage.cs b/AutoWorkshopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..f8ad293 --- /dev/null +++ b/AutoWorkshopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,97 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopFileImplement.Models; + +namespace AutoWorkshopFileImplement.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 (Model == null) + return new(); + + if (Model.Id.HasValue) + { + var Res = GetElement(Model); + return Res != null ? new() { Res } : new(); + } + + if (Model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Equals(Model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel Model) + { + if (Model.Id.HasValue) + return _source.Implementers.FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel; + + if (Model.ImplementerFIO != null && Model.Password != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(Model.ImplementerFIO) && x.Password.Equals(Model.Password))?.GetViewModel; + + if (Model.ImplementerFIO != null) + return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(Model.ImplementerFIO))?.GetViewModel; + + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel Model) + { + Model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + + var Res = Implementer.Create(Model); + if (Res != null) + { + _source.Implementers.Add(Res); + _source.SaveImplementers(); + } + + return Res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel Model) + { + var Res = _source.Implementers.FirstOrDefault(x => x.Id == Model.Id); + if (Res != null) + { + Res.Update(Model); + _source.SaveImplementers(); + } + + return Res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel Model) + { + var Res = _source.Implementers.FirstOrDefault(x => x.Id == Model.Id); + if (Res != null) + { + _source.Implementers.Remove(Res); + _source.SaveImplementers(); + } + + return Res?.GetViewModel; + } + } +} diff --git a/AutoWorkshopFileImplement/Implements/OrderStorage.cs b/AutoWorkshopFileImplement/Implements/OrderStorage.cs index 63fb8fc..efcc9d2 100644 --- a/AutoWorkshopFileImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopFileImplement/Implements/OrderStorage.cs @@ -26,14 +26,16 @@ namespace AutoWorkshopFileImplement.Implements if (Model.DateFrom.HasValue) { return _source.Orders - .Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId)) - .Select(x => AddClientFIO(AddRepairName(x.GetViewModel))) + .Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId) + && (!Model.ImplementerId.HasValue || x.ImplementerId == Model.ImplementerId)) + .Select(x => AddImplementerFIO(AddClientFIO(AddRepairName(x.GetViewModel)))) .ToList(); } return _source.Orders - .Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)) - .Select(x => AddClientFIO(AddRepairName(x.GetViewModel))) + .Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId) + || (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId)) + .Select(x => AddImplementerFIO(AddClientFIO(AddRepairName(x.GetViewModel)))) .ToList(); } @@ -54,15 +56,17 @@ namespace AutoWorkshopFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel Model) { - if (!Model.Id.HasValue) + if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue) return null; - - var Order = _source.Orders.FirstOrDefault(x => (Model.Id.HasValue && x.Id == Model.Id)); + + var Order = _source.Orders.FirstOrDefault(x => + (Model.Id.HasValue && x.Id == Model.Id) + || (Model.ImplementerId.HasValue && Model.Status.HasValue && x.ImplementerId == Model.ImplementerId && x.Status == Model.Status) ); if (Order == null) return null; - return AddRepairName(Order.GetViewModel); + return AddImplementerFIO(AddClientFIO(AddRepairName(Order.GetViewModel))); } public OrderViewModel? Insert(OrderBindingModel Model) @@ -108,5 +112,16 @@ namespace AutoWorkshopFileImplement.Implements Model.ClientFIO = SelectedClient?.ClientFIO ?? string.Empty; return Model; } + + public OrderViewModel AddImplementerFIO(OrderViewModel Model) + { + var SelectedImplementer = _source.Implementers.FirstOrDefault(x => x.Id == Model.ImplementerId); + + if (SelectedImplementer != null) + { + Model.ImplementerFIO = SelectedImplementer.ImplementerFIO; + } + return Model; + } } } diff --git a/AutoWorkshopFileImplement/Models/Implementer.cs b/AutoWorkshopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..1118fe7 --- /dev/null +++ b/AutoWorkshopFileImplement/Models/Implementer.cs @@ -0,0 +1,79 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; +using System.Xml.Linq; + +namespace AutoWorkshopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel Model) + { + if (Model == null) + return null; + + return new() + { + Id = Model.Id, + ImplementerFIO = Model.ImplementerFIO, + Password = Model.Password, + WorkExperience = Model.WorkExperience, + Qualification = Model.Qualification, + }; + } + + public static Implementer? Create(XElement Element) + { + if (Element == null) + return null; + + return new() + { + Id = Convert.ToInt32(Element.Attribute("Id")!.Value), + ImplementerFIO = Element.Element("ImplementerFIO")!.Value, + Password = Element.Element("Password")!.Value, + WorkExperience = Convert.ToInt32(Element.Element("WorkExperience")!.Value), + Qualification = Convert.ToInt32(Element.Element("Qualification")!.Value), + }; + } + + public void Update(ImplementerBindingModel Model) + { + if (Model == null) + return; + + ImplementerFIO = Model.ImplementerFIO; + Password = Model.Password; + WorkExperience = Model.WorkExperience; + Qualification = Model.Qualification; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification, + }; + + public XElement GetXElement => new( + "Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("WorkExperience", WorkExperience), + new XElement("Qualification", Qualification) + ); + } +} diff --git a/AutoWorkshopFileImplement/Models/Order.cs b/AutoWorkshopFileImplement/Models/Order.cs index 808823d..4f90bea 100644 --- a/AutoWorkshopFileImplement/Models/Order.cs +++ b/AutoWorkshopFileImplement/Models/Order.cs @@ -14,6 +14,8 @@ namespace AutoWorkshopFileImplement.Models public int ClientId { get; private set; } + public int? ImplementerId { get; set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -34,6 +36,7 @@ namespace AutoWorkshopFileImplement.Models Id = Model.Id, RepairId = Model.RepairId, ClientId = Model.ClientId, + ImplementerId = Model.ImplementerId, Count = Model.Count, Sum = Model.Sum, Status = Model.Status, @@ -52,6 +55,7 @@ namespace AutoWorkshopFileImplement.Models Id = Convert.ToInt32(Element.Attribute("Id")!.Value), RepairId = Convert.ToInt32(Element.Element("RepairId")!.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), @@ -65,6 +69,7 @@ namespace AutoWorkshopFileImplement.Models if (Model is null) return; + ImplementerId = Model.ImplementerId; Status = Model.Status; DateImplement = Model.DateImplement; } @@ -74,6 +79,7 @@ namespace AutoWorkshopFileImplement.Models Id = Id, RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -86,6 +92,7 @@ namespace AutoWorkshopFileImplement.Models new XAttribute("Id", Id), new XElement("RepairId", RepairId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/AutoWorkshopImplement/DataListSingleton.cs b/AutoWorkshopImplement/DataListSingleton.cs index 211e51a..0ddc659 100644 --- a/AutoWorkshopImplement/DataListSingleton.cs +++ b/AutoWorkshopImplement/DataListSingleton.cs @@ -14,12 +14,15 @@ namespace AutoWorkshopListImplement public List Clients { get; set; } + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Repairs = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() diff --git a/AutoWorkshopImplement/Implements/ImplementerStorage.cs b/AutoWorkshopImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..f31ea5c --- /dev/null +++ b/AutoWorkshopImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,104 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.StoragesContracts; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopListImplement.Models; + +namespace AutoWorkshopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var Result = new List(); + + foreach (var Implementer in _source.Implementers) + { + Result.Add(Implementer.GetViewModel); + } + + return Result; + } + + public List GetFilteredList(ImplementerSearchModel Model) + { + if (string.IsNullOrEmpty(Model.ImplementerFIO)) + return new(); + + return _source.Implementers + .Where(x => (!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO.Contains(Model.ImplementerFIO))) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel Model) + { + foreach (var Implementer in _source.Implementers) + { + if ((Model.Id.HasValue && Implementer.Id == Model.Id) || + (!string.IsNullOrEmpty(Model.ImplementerFIO) && Implementer.ImplementerFIO == Model.ImplementerFIO)) + { + return Implementer.GetViewModel; + } + } + + return null; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel Model) + { + Model.Id = 1; + foreach (var Implementer in _source.Implementers) + { + if (Model.Id <= Implementer.Id) + { + Model.Id = Implementer.Id + 1; + } + } + + var NewImplementer = Implementer.Create(Model); + if (NewImplementer == null) + return null; + + _source.Implementers.Add(NewImplementer); + return NewImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel Model) + { + foreach (var Implementer in _source.Implementers) + { + if (Implementer.Id == Model.Id) + { + Implementer.Update(Model); + return Implementer.GetViewModel; + } + } + + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel Model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == Model.Id) + { + var Implementer = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return Implementer.GetViewModel; + } + } + + return null; + } + } +} diff --git a/AutoWorkshopImplement/Implements/OrderStorage.cs b/AutoWorkshopImplement/Implements/OrderStorage.cs index 738fdbf..e83b110 100644 --- a/AutoWorkshopImplement/Implements/OrderStorage.cs +++ b/AutoWorkshopImplement/Implements/OrderStorage.cs @@ -32,27 +32,30 @@ namespace AutoWorkshopListImplement.Implements if (Model.DateFrom.HasValue) { return _source.Orders - .Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId)) - .Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel))) + .Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId) + && (!Model.ImplementerId.HasValue || x.ImplementerId == Model.ImplementerId)) + .Select(x => JoinImplementerFIO(JoinClientFIO(JoinRepairName(x.GetViewModel)))) .ToList(); } return _source.Orders - .Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)) - .Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel))) + .Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId) + || (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId)) + .Select(x => JoinImplementerFIO(JoinClientFIO(JoinRepairName(x.GetViewModel)))) .ToList(); } public OrderViewModel? GetElement(OrderSearchModel Model) { - if (!Model.Id.HasValue) + if (!Model.Id.HasValue && !Model.ImplementerId.HasValue && !Model.Status.HasValue) return null; foreach (var Order in _source.Orders) { - if (Order.Id == Model.Id) + if ((Model.Id.HasValue && Order.Id == Model.Id) + || (Model.ImplementerId.HasValue && Model.Status.HasValue && Order.ImplementerId == Model.ImplementerId && Order.Status == Model.Status)) { - return JoinRepairName(Order.GetViewModel); + return JoinImplementerFIO(JoinClientFIO(JoinRepairName(Order.GetViewModel))); } } @@ -130,5 +133,16 @@ namespace AutoWorkshopListImplement.Implements } return Model; } + + public OrderViewModel JoinImplementerFIO(OrderViewModel Model) + { + var SelectedImplementer = _source.Implementers.FirstOrDefault(x => x.Id == Model.ImplementerId); + + if (SelectedImplementer != null) + { + Model.ImplementerFIO = SelectedImplementer.ImplementerFIO; + } + return Model; + } } } diff --git a/AutoWorkshopImplement/Models/Implementer.cs b/AutoWorkshopImplement/Models/Implementer.cs new file mode 100644 index 0000000..3f9adb6 --- /dev/null +++ b/AutoWorkshopImplement/Models/Implementer.cs @@ -0,0 +1,54 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Models; + +namespace AutoWorkshopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel Model) + { + if (Model == null) + { + return null; + } + return new() + { + Id = Model.Id, + Password = Model.Password, + Qualification = Model.Qualification, + ImplementerFIO = Model.ImplementerFIO, + WorkExperience = Model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel Model) + { + if (Model == null) + return; + + Password = Model.Password; + Qualification = Model.Qualification; + ImplementerFIO = Model.ImplementerFIO; + WorkExperience = Model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/AutoWorkshopImplement/Models/Order.cs b/AutoWorkshopImplement/Models/Order.cs index 45ff7ff..dd719b3 100644 --- a/AutoWorkshopImplement/Models/Order.cs +++ b/AutoWorkshopImplement/Models/Order.cs @@ -13,6 +13,8 @@ namespace AutoWorkshopListImplement.Models public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -33,6 +35,7 @@ namespace AutoWorkshopListImplement.Models Id = Model.Id, RepairId = Model.RepairId, ClientId = Model.ClientId, + ImplementerId = Model.ImplementerId, Count = Model.Count, Sum = Model.Sum, Status = Model.Status, @@ -46,11 +49,7 @@ namespace AutoWorkshopListImplement.Models if (Model == null) return; - RepairId = Model.RepairId; - Count = Model.Count; - Sum = Model.Sum; Status = Model.Status; - DateCreate = Model.DateCreate; DateImplement = Model.DateImplement; } @@ -59,6 +58,7 @@ namespace AutoWorkshopListImplement.Models Id = Id, RepairId = RepairId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/AutoWorkshopRestApi/Controllers/ImplementerController.cs b/AutoWorkshopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..1881909 --- /dev/null +++ b/AutoWorkshopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,108 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using AutoWorkshopContracts.ViewModels; +using AutoWorkshopDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace AutoWorkshopRestApi.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.Accepted + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel Model) + { + try + { + _order.TakeOrderInWork(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", Model.Id); + throw; + } + } + + [HttpPost] + public void FinishOrder(OrderBindingModel Model) + { + try + { + _order.FinishOrder(Model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", Model.Id); + throw; + } + } + } +} diff --git a/AutoWorkshopRestApi/Program.cs b/AutoWorkshopRestApi/Program.cs index c494172..a84505b 100644 --- a/AutoWorkshopRestApi/Program.cs +++ b/AutoWorkshopRestApi/Program.cs @@ -1,5 +1,6 @@ using AutoWorkshopBusinessLogic.BusinessLogics; using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopContracts.StoragesContracts; using AutoWorkshopDatabaseImplement.Implements; using Microsoft.OpenApi.Models; @@ -12,9 +13,13 @@ Builder.Logging.AddLog4Net("log4net.config"); Builder.Services.AddTransient(); Builder.Services.AddTransient(); Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + Builder.Services.AddTransient(); Builder.Services.AddTransient(); Builder.Services.AddTransient(); +Builder.Services.AddTransient(); + Builder.Services.AddControllers(); Builder.Services.AddEndpointsApiExplorer(); diff --git a/AutoWorkshopView/AutoWorkshopView.csproj b/AutoWorkshopView/AutoWorkshopView.csproj index 8628399..a2417ee 100644 --- a/AutoWorkshopView/AutoWorkshopView.csproj +++ b/AutoWorkshopView/AutoWorkshopView.csproj @@ -28,4 +28,10 @@ + + + Always + + + \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormCreateOrder.Designer.cs b/AutoWorkshopView/Forms/FormCreateOrder.Designer.cs index 308a3ad..91f816c 100644 --- a/AutoWorkshopView/Forms/FormCreateOrder.Designer.cs +++ b/AutoWorkshopView/Forms/FormCreateOrder.Designer.cs @@ -28,6 +28,8 @@ /// private void InitializeComponent() { + ClientLabel = new Label(); + ClientComboBox = new ComboBox(); RepairComboBox = new ComboBox(); CountTextBox = new TextBox(); SumTextBox = new TextBox(); @@ -38,6 +40,24 @@ SumLabel = new Label(); SuspendLayout(); // + // ClientLabel + // + ClientLabel.AutoSize = true; + ClientLabel.Location = new Point(12, 102); + ClientLabel.Name = "ClientLabel"; + ClientLabel.Size = new Size(49, 15); + ClientLabel.TabIndex = 8; + ClientLabel.Text = "Клиент:"; + // + // ClientComboBox + // + ClientComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ClientComboBox.FormattingEnabled = true; + ClientComboBox.Location = new Point(103, 99); + ClientComboBox.Name = "ClientComboBox"; + ClientComboBox.Size = new Size(232, 23); + ClientComboBox.TabIndex = 9; + // // RepairComboBox // RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList; @@ -66,7 +86,7 @@ // // SaveButton // - SaveButton.Location = new Point(173, 107); + SaveButton.Location = new Point(173, 139); SaveButton.Name = "SaveButton"; SaveButton.Size = new Size(81, 23); SaveButton.TabIndex = 3; @@ -76,7 +96,7 @@ // // CancelButton // - CancelButton.Location = new Point(260, 107); + CancelButton.Location = new Point(260, 139); CancelButton.Name = "CancelButton"; CancelButton.Size = new Size(75, 23); CancelButton.TabIndex = 4; @@ -110,33 +130,15 @@ SumLabel.Size = new Size(48, 15); SumLabel.TabIndex = 7; SumLabel.Text = "Сумма:"; - // - // labelClient - // - labelClient.AutoSize = true; - labelClient.Location = new Point(26, 131); - labelClient.Name = "labelClient"; - labelClient.Size = new Size(58, 20); - labelClient.TabIndex = 8; - labelClient.Text = "Клиент"; - // - // comboBoxClient - // - comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxClient.FormattingEnabled = true; - comboBoxClient.Location = new Point(131, 131); - comboBoxClient.Name = "comboBoxClient"; - comboBoxClient.Size = new Size(260, 28); - comboBoxClient.TabIndex = 9; - // - // FormCreateOrder - // - AutoScaleDimensions = new SizeF(7F, 15F); + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(348, 142); - Controls.Add(comboBoxClient); - Controls.Add(labelClient); - Controls.Add(SumLabel); + ClientSize = new Size(348, 183); + Controls.Add(ClientComboBox); + Controls.Add(ClientLabel); + Controls.Add(SumLabel); Controls.Add(CountLabel); Controls.Add(RepairLabel); Controls.Add(CancelButton); @@ -161,7 +163,7 @@ private Label RepairLabel; private Label CountLabel; private Label SumLabel; - private Label labelClient; - private ComboBox comboBoxClient; + private Label ClientLabel; + private ComboBox ClientComboBox; } } \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormCreateOrder.cs b/AutoWorkshopView/Forms/FormCreateOrder.cs index c8a0816..48d91de 100644 --- a/AutoWorkshopView/Forms/FormCreateOrder.cs +++ b/AutoWorkshopView/Forms/FormCreateOrder.cs @@ -51,10 +51,10 @@ namespace AutoWorkshopView.Forms var list = _clientLogic.ReadList(null); if (list != null) { - comboBoxClient.DisplayMember = "ClientFIO"; - comboBoxClient.ValueMember = "Id"; - comboBoxClient.DataSource = list; - comboBoxClient.SelectedItem = null; + ClientComboBox.DisplayMember = "ClientFIO"; + ClientComboBox.ValueMember = "Id"; + ClientComboBox.DataSource = list; + ClientComboBox.SelectedItem = null; } _logger.LogInformation("Клиенты загружены"); } @@ -110,6 +110,12 @@ namespace AutoWorkshopView.Forms return; } + if (ClientComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); try @@ -117,6 +123,7 @@ namespace AutoWorkshopView.Forms var OperationResult = _orderLogic.CreateOrder(new OrderBindingModel { RepairId = Convert.ToInt32(RepairComboBox.SelectedValue), + ClientId = Convert.ToInt32(ClientComboBox.SelectedValue), Count = Convert.ToInt32(CountTextBox.Text), Sum = Convert.ToDouble(SumTextBox.Text) }); diff --git a/AutoWorkshopView/Forms/FormImplementer.Designer.cs b/AutoWorkshopView/Forms/FormImplementer.Designer.cs new file mode 100644 index 0000000..160101a --- /dev/null +++ b/AutoWorkshopView/Forms/FormImplementer.Designer.cs @@ -0,0 +1,173 @@ +namespace AutoWorkshopView.Forms +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + FioTextBox = new TextBox(); + FioLabel = new Label(); + PasswordTextBox = new TextBox(); + PasswordLabel = new Label(); + WorkExperienceLabel = new Label(); + WorkExperienceNumericUpDown = new NumericUpDown(); + QualificationNumericUpDown = new NumericUpDown(); + QualificationLabel = new Label(); + CancelButton = new Button(); + SaveButton = new Button(); + ((System.ComponentModel.ISupportInitialize)WorkExperienceNumericUpDown).BeginInit(); + ((System.ComponentModel.ISupportInitialize)QualificationNumericUpDown).BeginInit(); + SuspendLayout(); + // + // FioTextBox + // + FioTextBox.Location = new Point(137, 9); + FioTextBox.Margin = new Padding(3, 2, 3, 2); + FioTextBox.Name = "FioTextBox"; + FioTextBox.Size = new Size(335, 23); + FioTextBox.TabIndex = 3; + // + // FioLabel + // + FioLabel.AutoSize = true; + FioLabel.Location = new Point(10, 12); + FioLabel.Name = "FioLabel"; + FioLabel.Size = new Size(112, 15); + FioLabel.TabIndex = 2; + FioLabel.Text = "ФИО исполнителя:"; + // + // PasswordTextBox + // + PasswordTextBox.Location = new Point(137, 40); + PasswordTextBox.Margin = new Padding(3, 2, 3, 2); + PasswordTextBox.Name = "PasswordTextBox"; + PasswordTextBox.Size = new Size(335, 23); + PasswordTextBox.TabIndex = 5; + // + // PasswordLabel + // + PasswordLabel.AutoSize = true; + PasswordLabel.Location = new Point(10, 43); + PasswordLabel.Name = "PasswordLabel"; + PasswordLabel.Size = new Size(52, 15); + PasswordLabel.TabIndex = 4; + PasswordLabel.Text = "Пароль:"; + // + // WorkExperienceLabel + // + WorkExperienceLabel.AutoSize = true; + WorkExperienceLabel.Location = new Point(10, 75); + WorkExperienceLabel.Name = "WorkExperienceLabel"; + WorkExperienceLabel.Size = new Size(84, 15); + WorkExperienceLabel.TabIndex = 6; + WorkExperienceLabel.Text = "Опыт работы:"; + // + // WorkExperienceNumericUpDown + // + WorkExperienceNumericUpDown.Location = new Point(137, 73); + WorkExperienceNumericUpDown.Margin = new Padding(3, 2, 3, 2); + WorkExperienceNumericUpDown.Name = "WorkExperienceNumericUpDown"; + WorkExperienceNumericUpDown.Size = new Size(108, 23); + WorkExperienceNumericUpDown.TabIndex = 8; + // + // QualificationNumericUpDown + // + QualificationNumericUpDown.Location = new Point(137, 106); + QualificationNumericUpDown.Margin = new Padding(3, 2, 3, 2); + QualificationNumericUpDown.Name = "QualificationNumericUpDown"; + QualificationNumericUpDown.Size = new Size(108, 23); + QualificationNumericUpDown.TabIndex = 10; + // + // QualificationLabel + // + QualificationLabel.AutoSize = true; + QualificationLabel.Location = new Point(10, 108); + QualificationLabel.Name = "QualificationLabel"; + QualificationLabel.Size = new Size(91, 15); + QualificationLabel.TabIndex = 9; + QualificationLabel.Text = "Квалификация:"; + // + // CancelButton + // + CancelButton.Location = new Point(353, 142); + CancelButton.Margin = new Padding(3, 2, 3, 2); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(119, 30); + CancelButton.TabIndex = 12; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // SaveButton + // + SaveButton.Location = new Point(233, 142); + SaveButton.Margin = new Padding(3, 2, 3, 2); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(114, 30); + SaveButton.TabIndex = 11; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(482, 183); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(QualificationNumericUpDown); + Controls.Add(QualificationLabel); + Controls.Add(WorkExperienceNumericUpDown); + Controls.Add(WorkExperienceLabel); + Controls.Add(PasswordTextBox); + Controls.Add(PasswordLabel); + Controls.Add(FioTextBox); + Controls.Add(FioLabel); + Margin = new Padding(3, 2, 3, 2); + Name = "FormImplementer"; + Text = "Исполнитель"; + Load += FormImplementer_Load; + ((System.ComponentModel.ISupportInitialize)WorkExperienceNumericUpDown).EndInit(); + ((System.ComponentModel.ISupportInitialize)QualificationNumericUpDown).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox FioTextBox; + private Label FioLabel; + private TextBox PasswordTextBox; + private Label PasswordLabel; + private Label WorkExperienceLabel; + private NumericUpDown WorkExperienceNumericUpDown; + private NumericUpDown QualificationNumericUpDown; + private Label QualificationLabel; + private Button CancelButton; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormImplementer.cs b/AutoWorkshopView/Forms/FormImplementer.cs new file mode 100644 index 0000000..362b759 --- /dev/null +++ b/AutoWorkshopView/Forms/FormImplementer.cs @@ -0,0 +1,105 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using AutoWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormImplementer(ILogger Logger, IImplementerLogic Logic) + { + InitializeComponent(); + + _logger = Logger; + _logic = Logic; + } + + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + + var View = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + FioTextBox.Text = View.ImplementerFIO; + PasswordTextBox.Text = View.Password; + WorkExperienceNumericUpDown.Value = View.WorkExperience; + QualificationNumericUpDown.Value = View.Qualification; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FioTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Сохранение исполнителя"); + + try + { + var Model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FioTextBox.Text, + Password = PasswordTextBox.Text, + WorkExperience = (int)WorkExperienceNumericUpDown.Value, + Qualification = (int)QualificationNumericUpDown.Value + }; + + var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); + if (!OperationResult) + { + throw new Exception("Ошибка при создании или обновлении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutoWorkshopView/Forms/FormImplementer.resx b/AutoWorkshopView/Forms/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormImplementers.Designer.cs b/AutoWorkshopView/Forms/FormImplementers.Designer.cs new file mode 100644 index 0000000..2cfeed7 --- /dev/null +++ b/AutoWorkshopView/Forms/FormImplementers.Designer.cs @@ -0,0 +1,136 @@ +namespace AutoWorkshopView.Forms +{ + 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() + { + ToolsPanel = new Panel(); + RefreshButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + AddButton = new Button(); + DataGridView = new DataGridView(); + ToolsPanel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // ToolsPanel + // + ToolsPanel.Controls.Add(RefreshButton); + ToolsPanel.Controls.Add(DeleteButton); + ToolsPanel.Controls.Add(UpdateButton); + ToolsPanel.Controls.Add(AddButton); + ToolsPanel.Location = new Point(532, 9); + ToolsPanel.Margin = new Padding(3, 2, 3, 2); + ToolsPanel.Name = "ToolsPanel"; + ToolsPanel.Size = new Size(116, 320); + ToolsPanel.TabIndex = 3; + // + // RefreshButton + // + RefreshButton.Location = new Point(3, 126); + RefreshButton.Margin = new Padding(3, 2, 3, 2); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(110, 27); + RefreshButton.TabIndex = 3; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(3, 84); + DeleteButton.Margin = new Padding(3, 2, 3, 2); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(110, 27); + DeleteButton.TabIndex = 2; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(3, 42); + UpdateButton.Margin = new Padding(3, 2, 3, 2); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(110, 27); + UpdateButton.TabIndex = 1; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // AddButton + // + AddButton.Location = new Point(3, 2); + AddButton.Margin = new Padding(3, 2, 3, 2); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(110, 27); + AddButton.TabIndex = 0; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // DataGridView + // + DataGridView.AllowUserToAddRows = false; + DataGridView.AllowUserToDeleteRows = false; + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(10, 9); + DataGridView.Margin = new Padding(3, 2, 3, 2); + DataGridView.Name = "DataGridView"; + DataGridView.ReadOnly = true; + DataGridView.RowHeadersWidth = 51; + DataGridView.RowTemplate.Height = 29; + DataGridView.Size = new Size(516, 320); + DataGridView.TabIndex = 2; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(653, 338); + Controls.Add(ToolsPanel); + Controls.Add(DataGridView); + Margin = new Padding(3, 2, 3, 2); + Name = "FormImplementers"; + Text = "Исполнители"; + Load += FormImplementers_Load; + ToolsPanel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel ToolsPanel; + private Button RefreshButton; + private Button DeleteButton; + private Button UpdateButton; + private Button AddButton; + private DataGridView DataGridView; + } +} \ No newline at end of file diff --git a/AutoWorkshopView/Forms/FormImplementers.cs b/AutoWorkshopView/Forms/FormImplementers.cs new file mode 100644 index 0000000..47cae33 --- /dev/null +++ b/AutoWorkshopView/Forms/FormImplementers.cs @@ -0,0 +1,111 @@ +using AutoWorkshopContracts.BindingModels; +using AutoWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AutoWorkshopView.Forms +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _implementerLogic; + + public FormImplementers(ILogger Logger, IImplementerLogic ImplementerLogic) + { + InitializeComponent(); + + _logger = Logger; + _implementerLogic = ImplementerLogic; + } + + private void LoadData() + { + try + { + var List = _implementerLogic.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 FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void AddButton_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 UpdateButton_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 DeleteButton_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 (!_implementerLogic.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 RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutoWorkshopView/Forms/FormImplementers.resx b/AutoWorkshopView/Forms/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutoWorkshopView/Forms/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutoWorkshopView/MainForm.Designer.cs b/AutoWorkshopView/MainForm.Designer.cs index 17b5abc..773454d 100644 --- a/AutoWorkshopView/MainForm.Designer.cs +++ b/AutoWorkshopView/MainForm.Designer.cs @@ -32,15 +32,15 @@ ToolStripMenu = new ToolStripMenuItem(); ComponentsStripMenuItem = new ToolStripMenuItem(); RepairStripMenuItem = new ToolStripMenuItem(); - ClientsToolStripMenuItem = new ToolStripMenuItem(); - ReportsToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + ReportsToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem1 = new ToolStripMenuItem(); ComponentRepairToolStripMenuItem1 = new ToolStripMenuItem(); OrdersToolStripMenuItem = new ToolStripMenuItem(); + WorkStartToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); - TakeInWorkButton = new Button(); - ReadyButton = new Button(); IssuedButton = new Button(); RefreshButton = new Button(); MenuStrip.SuspendLayout(); @@ -50,17 +50,17 @@ // MenuStrip // MenuStrip.ImageScalingSize = new Size(20, 20); - MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, ReportsToolStripMenuItem }); + MenuStrip.Items.AddRange(new ToolStripItem[] { ToolStripMenu, ReportsToolStripMenuItem, WorkStartToolStripMenuItem }); MenuStrip.Location = new Point(0, 0); MenuStrip.Name = "MenuStrip"; MenuStrip.Padding = new Padding(5, 2, 0, 2); - MenuStrip.Size = new Size(1134, 24); + MenuStrip.Size = new Size(1356, 24); MenuStrip.TabIndex = 0; MenuStrip.Text = "TopMenuStrip"; // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { ComponentsStripMenuItem, RepairStripMenuItem, ClientsToolStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { ComponentsStripMenuItem, RepairStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(94, 20); ToolStripMenu.Text = "Справочники"; @@ -68,30 +68,34 @@ // ComponentsStripMenuItem // ComponentsStripMenuItem.Name = "ComponentsStripMenuItem"; - ComponentsStripMenuItem.Size = new Size(145, 22); + ComponentsStripMenuItem.Size = new Size(149, 22); ComponentsStripMenuItem.Text = "Компоненты"; ComponentsStripMenuItem.Click += ComponentsStripMenuItem_Click; // // RepairStripMenuItem // RepairStripMenuItem.Name = "RepairStripMenuItem"; - RepairStripMenuItem.Size = new Size(145, 22); + RepairStripMenuItem.Size = new Size(149, 22); RepairStripMenuItem.Text = "Ремонты"; RepairStripMenuItem.Click += RepairsStripMenuItem_Click; - // - // ClientsToolStripMenuItem - // - ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(182, 26); - ClientsToolStripMenuItem.Text = "Клиенты"; - ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // - // ReportsToolStripMenuItem - // - ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { - ComponentsToolStripMenuItem1, - ComponentRepairToolStripMenuItem1, - OrdersToolStripMenuItem}); + // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(149, 22); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(149, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += EmployersToolStripMenuItem_Click; + // + // ReportsToolStripMenuItem + // + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem1, ComponentRepairToolStripMenuItem1, OrdersToolStripMenuItem }); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; ReportsToolStripMenuItem.Size = new Size(60, 20); ReportsToolStripMenuItem.Text = "Отчёты"; @@ -99,23 +103,30 @@ // ComponentsToolStripMenuItem1 // ComponentsToolStripMenuItem1.Name = "ComponentsToolStripMenuItem1"; - ComponentsToolStripMenuItem1.Size = new Size(205, 22); + ComponentsToolStripMenuItem1.Size = new Size(210, 22); ComponentsToolStripMenuItem1.Text = "Ремонты"; - ComponentsToolStripMenuItem1.Click += new EventHandler(ComponentsToolStripMenuItem_Click); + ComponentsToolStripMenuItem1.Click += ComponentsToolStripMenuItem_Click; // // ComponentRepairToolStripMenuItem1 // ComponentRepairToolStripMenuItem1.Name = "ComponentRepairToolStripMenuItem1"; - ComponentRepairToolStripMenuItem1.Size = new Size(205, 22); + ComponentRepairToolStripMenuItem1.Size = new Size(210, 22); ComponentRepairToolStripMenuItem1.Text = "Ремонт с компонентами"; - ComponentRepairToolStripMenuItem1.Click += new EventHandler(ComponentRepairToolStripMenuItem_Click); + ComponentRepairToolStripMenuItem1.Click += ComponentRepairToolStripMenuItem_Click; // // OrdersToolStripMenuItem // OrdersToolStripMenuItem.Name = "OrdersToolStripMenuItem"; - OrdersToolStripMenuItem.Size = new Size(205, 22); + OrdersToolStripMenuItem.Size = new Size(210, 22); OrdersToolStripMenuItem.Text = "Заказы"; - OrdersToolStripMenuItem.Click += new EventHandler(OrdersToolStripMenuItem_Click); + OrdersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // WorkStartToolStripMenuItem + // + WorkStartToolStripMenuItem.Name = "WorkStartToolStripMenuItem"; + WorkStartToolStripMenuItem.Size = new Size(92, 20); + WorkStartToolStripMenuItem.Text = "Запуск работ"; + WorkStartToolStripMenuItem.Click += StartWorkToolStripMenuItem_Click; // // DataGridView // @@ -124,12 +135,12 @@ DataGridView.Margin = new Padding(3, 2, 3, 2); DataGridView.Name = "DataGridView"; DataGridView.RowHeadersWidth = 51; - DataGridView.Size = new Size(881, 305); + DataGridView.Size = new Size(1101, 358); DataGridView.TabIndex = 1; // // CreateOrderButton // - CreateOrderButton.Location = new Point(897, 23); + CreateOrderButton.Location = new Point(1117, 26); CreateOrderButton.Margin = new Padding(3, 2, 3, 2); CreateOrderButton.Name = "CreateOrderButton"; CreateOrderButton.Size = new Size(227, 30); @@ -138,31 +149,9 @@ CreateOrderButton.UseVisualStyleBackColor = true; CreateOrderButton.Click += CreateOrderButton_Click; // - // TakeInWorkButton - // - TakeInWorkButton.Location = new Point(897, 57); - TakeInWorkButton.Margin = new Padding(3, 2, 3, 2); - TakeInWorkButton.Name = "TakeInWorkButton"; - TakeInWorkButton.Size = new Size(227, 30); - TakeInWorkButton.TabIndex = 3; - TakeInWorkButton.Text = "Отдать заказ в работу"; - TakeInWorkButton.UseVisualStyleBackColor = true; - TakeInWorkButton.Click += TakeOrderInWorkButton_Click; - // - // ReadyButton - // - ReadyButton.Location = new Point(897, 91); - ReadyButton.Margin = new Padding(3, 2, 3, 2); - ReadyButton.Name = "ReadyButton"; - ReadyButton.Size = new Size(227, 30); - ReadyButton.TabIndex = 4; - ReadyButton.Text = "Заказ готов"; - ReadyButton.UseVisualStyleBackColor = true; - ReadyButton.Click += OrderReadyButton_Click; - // // IssuedButton // - IssuedButton.Location = new Point(897, 125); + IssuedButton.Location = new Point(1117, 70); IssuedButton.Margin = new Padding(3, 2, 3, 2); IssuedButton.Name = "IssuedButton"; IssuedButton.Size = new Size(227, 30); @@ -173,7 +162,7 @@ // // RefreshButton // - RefreshButton.Location = new Point(897, 159); + RefreshButton.Location = new Point(1117, 114); RefreshButton.Margin = new Padding(3, 2, 3, 2); RefreshButton.Name = "RefreshButton"; RefreshButton.Size = new Size(227, 30); @@ -186,11 +175,9 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1134, 338); + ClientSize = new Size(1356, 392); Controls.Add(RefreshButton); Controls.Add(IssuedButton); - Controls.Add(ReadyButton); - Controls.Add(TakeInWorkButton); Controls.Add(CreateOrderButton); Controls.Add(DataGridView); Controls.Add(MenuStrip); @@ -214,8 +201,6 @@ private ToolStripMenuItem RepairStripMenuItem; private DataGridView DataGridView; private Button CreateOrderButton; - private Button TakeInWorkButton; - private Button ReadyButton; private Button IssuedButton; private Button RefreshButton; private ToolStripMenuItem ReportsToolStripMenuItem; @@ -223,5 +208,7 @@ private ToolStripMenuItem ComponentRepairToolStripMenuItem1; private ToolStripMenuItem OrdersToolStripMenuItem; private ToolStripMenuItem ClientsToolStripMenuItem; - } + private ToolStripMenuItem ImplementersToolStripMenuItem; + private ToolStripMenuItem WorkStartToolStripMenuItem; + } } \ No newline at end of file diff --git a/AutoWorkshopView/MainForm.cs b/AutoWorkshopView/MainForm.cs index 7fcc9a8..f4808c4 100644 --- a/AutoWorkshopView/MainForm.cs +++ b/AutoWorkshopView/MainForm.cs @@ -1,7 +1,9 @@ using AutoWorkshopContracts.BindingModels; using AutoWorkshopContracts.BusinessLogicContracts; +using AutoWorkshopContracts.BusinessLogicsContracts; using AutoWorkshopView.Forms; using Microsoft.Extensions.Logging; +using System.Windows.Forms; namespace AutoWorkshopView { @@ -10,14 +12,16 @@ namespace AutoWorkshopView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - - public MainForm(ILogger Logger, IOrderLogic OrderLogic, IReportLogic ReportLogic) + private readonly IWorkProcess _workProcess; + + public MainForm(ILogger Logger, IOrderLogic OrderLogic, IReportLogic ReportLogic, IWorkProcess WorkProcess) { InitializeComponent(); _logger = Logger; _orderLogic = OrderLogic; _reportLogic = ReportLogic; + _workProcess = WorkProcess; } private void MainForm_Load(object sender, EventArgs e) @@ -38,7 +42,8 @@ namespace AutoWorkshopView DataGridView.DataSource = List; DataGridView.Columns["RepairId"].Visible = false; DataGridView.Columns["ClientId"].Visible = false; - DataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["ImplementerId"].Visible = false; + DataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); @@ -209,5 +214,23 @@ namespace AutoWorkshopView Form.ShowDialog(); } } - } + + private void EmployersToolStripMenuItem_Click(object sender, EventArgs e) + { + var Service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + + if (Service is FormImplementers Form) + { + Form.ShowDialog(); + } + } + + private void StartWorkToolStripMenuItem_Click(object sender, EventArgs e) + { + var ImplementerLogic = Program.ServiceProvider?.GetService(typeof(IImplementerLogic)); + _workProcess.DoWork((ImplementerLogic as IImplementerLogic)!, _orderLogic); + + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } } diff --git a/AutoWorkshopView/Program.cs b/AutoWorkshopView/Program.cs index d5624c6..131a87c 100644 --- a/AutoWorkshopView/Program.cs +++ b/AutoWorkshopView/Program.cs @@ -8,6 +8,7 @@ using AutoWorkshopView.Forms; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using AutoWorkshopContracts.BusinessLogicsContracts; namespace AutoWorkshopView { @@ -39,13 +40,16 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); - + Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); - Services.AddTransient(); + Services.AddTransient(); + Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); @@ -61,6 +65,8 @@ namespace AutoWorkshopView Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); - } + Services.AddTransient(); + Services.AddTransient(); + } } }