diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..e89977a --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,129 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}", + model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id); + var list = (model == null) ? _implementerStorage.GetFullList() : + _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.WorkExperience < 0) + { + throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs index d2b185c..922c166 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,6 +17,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { @@ -62,9 +63,12 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics model.Status = newStatus; - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (viewModel.ImplementerId.HasValue) + model.ImplementerId = viewModel.ImplementerId; + model.Sum = viewModel.Sum; model.Count = viewModel.Count; model.PackageId = viewModel.PackageId; @@ -82,7 +86,10 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics public bool TakeOrderInWork(OrderBindingModel model) { - return StatusUpdate(model, OrderStatus.Выполняется); + lock (locker) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) @@ -140,6 +147,27 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogics _logger.LogInformation("Order. OrderId:{Id}.Sum:{Sum}. PackageId: {PackageId}", model.Id, model.Sum, model.PackageId); } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + + var element = _orderStorage.GetElement(model); + + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + + return element; + } } } diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..24de305 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,144 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.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. Исполнитель равен null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel + { + Statuses = new() { OrderStatus.Принят } + }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + /// + /// Иммитация работы исполнителя + /// + /// + /// + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order} ", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 10000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order} ", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 50)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + /// + /// Ищем заказ, которые уже в работе (вдруг исполнителя прервали) + /// + /// + /// + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementerId = implementer.Id, + Statuses = new() { OrderStatus.Выполняется } + })); + if (runOrder == null) + { + return; + } + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..7672ab6 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs index 19154ba..fd76759 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace SoftwareInstallationContracts.BindingModels public int Id { get; set; } public int PackageId { 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.Неизвестен; diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..1102a55 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,24 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs index 41bc7f7..0242473 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace SoftwareInstallationContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..ae46f05 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..8a42b72 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs index 59474fb..21c63b8 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using SoftwareInstallationDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace SoftwareInstallationContracts.SearchModels public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } } } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..b48a403 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,26 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..accc4e9 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.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/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs index e18d593..24f3284 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -13,17 +13,28 @@ namespace SoftwareInstallationContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } - public int PackageId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Изделие")] - public int ClientId { get; set; } + public int PackageId { get; set; } + [DisplayName("Клиент")] + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; - [DisplayName("ФИО клиента")] + + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Изделия")] public string PackageName { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } + [DisplayName("Сумма")] public double Sum { get; set; } + [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; [DisplayName("Дата создания")] diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs new file mode 100644 index 0000000..bc28cab --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IImplementerModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDataModels +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs index e1d1e02..7c0e90e 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IOrderModel.cs @@ -11,6 +11,7 @@ namespace SoftwareInstallationDataModels.Models { int PackageId { get; } int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs new file mode 100644 index 0000000..a084649 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Implementer.cs @@ -0,0 +1,70 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDatabaseImplement +{ + public class Implementer : IImplementerModel + { + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [Required] + public int WorkExperience { get; private set; } + + [Required] + public int Qualification { get; private set; } + + public int Id { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs new file mode 100644 index 0000000..1dc03c5 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/ImplementerStorage.cs @@ -0,0 +1,121 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDatabaseImplement +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + + var res = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new SoftwareInstallationDatabase(); + + if (model.Id.HasValue) + return context.Implementers + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) + && x.Password.Equals(model.Password)) + ?.GetViewModel; + + if (model.ImplementerFIO != null) + return context.Implementers + .FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + ?.GetViewModel; + + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + if (model.ImplementerFIO != null) + { + using var context = new SoftwareInstallationDatabase(); + + return context.Implementers + .Where(x => x.ImplementerFIO.Equals(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + + return new(); + } + + public List GetFullList() + { + using var context = new SoftwareInstallationDatabase(); + + return context.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + + var res = Implementer.Create(model); + + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDatabase(); + + var res = context.Implementers + .FirstOrDefault(x => x.Id == model.Id); + + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240505115211_AddImplementer.Designer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240505115211_AddImplementer.Designer.cs new file mode 100644 index 0000000..6cf7cc9 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240505115211_AddImplementer.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SoftwareInstallationDatabaseImplement; + +#nullable disable + +namespace SoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(SoftwareInstallationDatabase))] + [Migration("20240505115211_AddImplementer")] + partial class AddImplementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PackageName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.PackageComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("PackageId"); + + b.ToTable("PackageComponents"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.PackageComponent", b => + { + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Component", "Component") + .WithMany("PackageComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Components") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Order", b => + { + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDatabaseImplement.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Component", b => + { + b.Navigation("PackageComponents"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240505115211_AddImplementer.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240505115211_AddImplementer.cs new file mode 100644 index 0000000..e0f8d2c --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/20240505115211_AddImplementer.cs @@ -0,0 +1,108 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class AddImplementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders"); + + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Clients_ClientId", + table: "Orders", + column: "ClientId", + principalTable: "Clients", + principalColumn: "Id"); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs index 1b002a0..5626ef8 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDatabaseModelSnapshot.cs @@ -22,7 +22,34 @@ namespace SoftwareInstallationDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Client", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -47,7 +74,7 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Clients"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Component", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Component", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -67,45 +94,7 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Components"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("PackageId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("PackageId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Package", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -125,7 +114,7 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Packages"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.PackageComponent", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.PackageComponent", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -153,28 +142,56 @@ namespace SoftwareInstallationDatabaseImplement.Migrations modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Order", b => { - b.HasOne("SoftwareInstallationDatabaseImplement.Client", null) - .WithMany("Orders") - .HasForeignKey("ClientId"); + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); - b.HasOne("SoftwareInstallationDatabaseImplement.Package", "Package") - .WithMany("Orders") - .HasForeignKey("PackageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Navigation("Package"); + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("PackageId"); + + b.ToTable("Orders"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.PackageComponent", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.PackageComponent", b => { - b.HasOne("SoftwareInstallationDatabaseImplement.Component", "Component") + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Component", "Component") .WithMany("PackageComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("SoftwareInstallationDatabaseImplement.Package", "Package") + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package") .WithMany("Components") .HasForeignKey("PackageId") .OnDelete(DeleteBehavior.Cascade) @@ -185,17 +202,47 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Navigation("Package"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Client", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Order", b => + { + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SoftwareInstallationDatabaseImplement.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Implementer", b => { b.Navigation("Orders"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Component", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Component", b => { b.Navigation("PackageComponents"); }); - modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Package", b => + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Package", b => { b.Navigation("Components"); diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs index 79c7bd7..6c3fe13 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/Order.cs @@ -20,6 +20,7 @@ namespace SoftwareInstallationDatabaseImplement [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } [Required] public int Count { get; private set; } @@ -37,6 +38,7 @@ namespace SoftwareInstallationDatabaseImplement public virtual Package Package { get; set; } public virtual Client Client { get; private set; } + public virtual Implementer? Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -49,6 +51,7 @@ namespace SoftwareInstallationDatabaseImplement { Id = model.Id, PackageId = model.PackageId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -66,12 +69,14 @@ namespace SoftwareInstallationDatabaseImplement } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { Id = Id, PackageId = PackageId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, @@ -79,7 +84,8 @@ namespace SoftwareInstallationDatabaseImplement DateImplement = DateImplement, PackageName = Package?.PackageName, ClientId = ClientId, - ClientFIO = Client?.ClientFIO + ClientFIO = Client?.ClientFIO, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty }; } } diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs index 67f77dc..26383a9 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/OrderStorage.cs @@ -39,16 +39,21 @@ namespace SoftwareInstallationDatabaseImplement.Implements using var context = new SoftwareInstallationDatabase(); - return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Package) + .Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { using var context = new SoftwareInstallationDatabase(); - return context.Orders.Include(x => x.Package) - .Include(x => x.Client).Where(x => ((!model.Id.HasValue || x.Id == model.Id) && + return context.Orders.Include(x => x.Package).Include(x => x.Implementer) + .Include(x => x.Client).Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) + && + (model.Statuses == null || model.Statuses != null && model.Statuses.Contains(x.Status)) && + (!model.ImplementerId.HasValue || x.ImplementerId == model.ImplementerId) && (!model.ClientId.HasValue || x.ClientId == model.ClientId))) .Select(x => x.GetViewModel).ToList(); } @@ -57,7 +62,7 @@ namespace SoftwareInstallationDatabaseImplement.Implements { using var context = new SoftwareInstallationDatabase(); - return context.Orders.Include(x => x.Client).Include(x => x.Package).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Client).Include(x => x.Package).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs index 6991420..539e92e 100644 --- a/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs +++ b/SoftwareInstallation/SoftwareInstallationDatabaseImplement/SoftwareInstallationDatabase.cs @@ -24,5 +24,6 @@ namespace SoftwareInstallationDatabaseImplement public virtual DbSet PackageComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs index e159bcb..7dbeecb 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/DataFileSingleton.cs @@ -16,10 +16,12 @@ namespace SoftwareInstallationFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PackageFileName = "Package.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Packages { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -32,12 +34,15 @@ namespace SoftwareInstallationFileImplement public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Implementer.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Implementer.cs new file mode 100644 index 0000000..a1d2dda --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Implementer.cs @@ -0,0 +1,78 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int Qualification { get; set; } = 0; + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString()) + ); + } +} diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/ImplementerStorage.cs new file mode 100644 index 0000000..5d4e11e --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/ImplementerStorage.cs @@ -0,0 +1,82 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel + model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implementers + .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO.Contains(model.ImplementerFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + return source.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => + x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/Order.cs index 968c80f..86ac055 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/Order.cs @@ -15,6 +15,7 @@ namespace SoftwareInstallationFileImplement { public int ClientId { get; private set; } public int PackageId { get; private set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -35,6 +36,7 @@ namespace SoftwareInstallationFileImplement Count = model.Count, Sum = model.Sum, Status = model.Status, + ImplementerId = model.ImplementerId, DateCreate = model.DateCreate, DateImplement = model.DateImplement }; @@ -53,6 +55,7 @@ namespace SoftwareInstallationFileImplement ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) }; @@ -69,6 +72,7 @@ namespace SoftwareInstallationFileImplement return; } PackageId = model.PackageId; + ImplementerId = ImplementerId; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -82,6 +86,7 @@ namespace SoftwareInstallationFileImplement ClientId = ClientId, Count = Count, Sum = Sum, + ImplementerId = ImplementerId, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement @@ -92,6 +97,7 @@ namespace SoftwareInstallationFileImplement new XElement("ClientId", ClientId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Status", Status.ToString()), new XElement("DateCreate", DateCreate.ToString()), new XElement("DateImplement", DateImplement.ToString())); diff --git a/SoftwareInstallation/SoftwareInstallationFileImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationFileImplement/OrderStorage.cs index f4c2ab1..df0033c 100644 --- a/SoftwareInstallation/SoftwareInstallationFileImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationFileImplement/OrderStorage.cs @@ -37,6 +37,19 @@ namespace SoftwareInstallationFileImplement.Implements public OrderViewModel? GetElement(OrderSearchModel model) { + if (model.ImplementerId.HasValue && model.Statuses != null) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && + model.Statuses.Contains(x.Status)) ?.GetViewModel; + } + + if (model.ImplementerId.HasValue) + { + return source.Orders + .FirstOrDefault(x => x.ImplementerId == model.ImplementerId) ?.GetViewModel; + } + if (!model.Id.HasValue) { return null; @@ -47,14 +60,12 @@ namespace SoftwareInstallationFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - return source.Orders.Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) && - (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) - ) - ) - .Select(x => GetPackageName(x.GetViewModel)) - .ToList(); + if (!model.Id.HasValue) + { + return new(); + } + + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetPackageName(x.GetViewModel)).ToList(); } public List GetFullList() diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs index fd99be3..f7b0cc2 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace SoftwareInstallationListImplement public List Orders { get; set; } public List Packages { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Packages = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs new file mode 100644 index 0000000..56aef30 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Implementer.cs @@ -0,0 +1,61 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement +{ + public class Implementer : IImplementerModel + { + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public int Id { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience + }; + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs new file mode 100644 index 0000000..25c6138 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationListImplement/ImplementerStorage.cs @@ -0,0 +1,131 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationListImplement +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + + return element.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && + x.Password.Equals(model.Password)) + return x.GetViewModel; + + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + + if (model.Id.HasValue) + { + var res = GetElement(model); + + return res != null ? new() { res } : new(); + } + + List result = new(); + + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + + var 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; + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs index d5ebc31..3e9d1c7 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Order.cs @@ -13,6 +13,7 @@ namespace SoftwareInstallationListImplement public class Order : IOrderModel { public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int PackageId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -29,6 +30,7 @@ namespace SoftwareInstallationListImplement ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, + ImplementerId = model.ImplementerId, Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, @@ -43,6 +45,7 @@ namespace SoftwareInstallationListImplement } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -51,6 +54,7 @@ namespace SoftwareInstallationListImplement ClientId = ClientId, Count = Count, Sum = Sum, + ImplementerId = ImplementerId, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs index ec54b37..36d5590 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/OrderStorage.cs @@ -55,26 +55,31 @@ namespace SoftwareInstallationListImplement.Implements { var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) { - if ((!model.Id.HasValue || order.Id == model.Id) && - (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) - && (!model.DateTo.HasValue || order.DateCreate <= model.DateTo)) - + if (model.Id.HasValue && order.Id == model.Id) { - result.Add(GetViewModelName(order.GetViewModel)); + result.Add(GetViewModelName(order)); } } + return result; } public List GetFullList() { var result = new List(); + foreach (var order in _source.Orders) { - result.Add(GetViewModelName(order.GetViewModel)); + result.Add(GetViewModelName(order)); } + return result; } @@ -115,30 +120,18 @@ namespace SoftwareInstallationListImplement.Implements return null; } - private OrderViewModel GetViewModelName(OrderViewModel model) + private OrderViewModel GetViewModelName(Order model) { + var res = model.GetViewModel; foreach (var package in _source.Packages) { if (package.Id == model.PackageId) { - model.PackageName = package.PackageName; + res.PackageName = package.PackageName; break; } } - return model; - } - - private OrderViewModel GetClientName(OrderViewModel viewModel) - { - foreach (var client in _source.Clients) - { - if (client.Id == viewModel.ClientId) - { - viewModel.ClientFIO = client.ClientFIO; - break; - } - } - return viewModel; + return res; } } } diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..9084c71 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,103 @@ +using Microsoft.AspNetCore.Mvc; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; + +namespace SoftwareInstallationRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : Controller + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Statuses = new() { OrderStatus.Принят } + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id); + throw; + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs index 22b2006..ef4106a 100644 --- a/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationRestApi/Program.cs @@ -12,9 +12,11 @@ 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(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/SoftwareInstallation/SoftwareInstallationView/FormImplementer.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormImplementer.Designer.cs new file mode 100644 index 0000000..f4a03e2 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormImplementer.Designer.cs @@ -0,0 +1,165 @@ +namespace SoftwareInstallationView +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelFIO = new Label(); + textBoxFio = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelQualification = new Label(); + labelWorkExperience = new Label(); + workExpNumericUpDown = new NumericUpDown(); + qualificationNumericUpDown = new NumericUpDown(); + labelPassword = new Label(); + textBoxPassword = new TextBox(); + ((System.ComponentModel.ISupportInitialize)workExpNumericUpDown).BeginInit(); + ((System.ComponentModel.ISupportInitialize)qualificationNumericUpDown).BeginInit(); + SuspendLayout(); + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(22, 28); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(40, 15); + labelFIO.TabIndex = 3; + labelFIO.Text = "ФИО: "; + // + // textBoxFio + // + textBoxFio.Location = new Point(105, 20); + textBoxFio.Name = "textBoxFio"; + textBoxFio.Size = new Size(200, 23); + textBoxFio.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(117, 194); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(97, 29); + buttonSave.TabIndex = 17; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(234, 194); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(97, 29); + buttonCancel.TabIndex = 16; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(22, 142); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(94, 15); + labelQualification.TabIndex = 15; + labelQualification.Text = "Квалификация: "; + // + // labelWorkExperience + // + labelWorkExperience.AutoSize = true; + labelWorkExperience.Location = new Point(22, 101); + labelWorkExperience.Name = "labelWorkExperience"; + labelWorkExperience.Size = new Size(87, 15); + labelWorkExperience.TabIndex = 14; + labelWorkExperience.Text = "Опыт работы: "; + // + // workExpNumericUpDown + // + workExpNumericUpDown.Location = new Point(126, 99); + workExpNumericUpDown.Name = "workExpNumericUpDown"; + workExpNumericUpDown.Size = new Size(170, 23); + workExpNumericUpDown.TabIndex = 13; + // + // qualificationNumericUpDown + // + qualificationNumericUpDown.Location = new Point(126, 140); + qualificationNumericUpDown.Name = "qualificationNumericUpDown"; + qualificationNumericUpDown.Size = new Size(170, 23); + qualificationNumericUpDown.TabIndex = 12; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(22, 61); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(55, 15); + labelPassword.TabIndex = 11; + labelPassword.Text = "Пароль: "; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(105, 58); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(200, 23); + textBoxPassword.TabIndex = 10; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(343, 244); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(labelQualification); + Controls.Add(labelWorkExperience); + Controls.Add(workExpNumericUpDown); + Controls.Add(qualificationNumericUpDown); + Controls.Add(labelPassword); + Controls.Add(textBoxPassword); + Controls.Add(textBoxFio); + Controls.Add(labelFIO); + Name = "FormImplementer"; + Text = "Исполнитель"; + ((System.ComponentModel.ISupportInitialize)workExpNumericUpDown).EndInit(); + ((System.ComponentModel.ISupportInitialize)qualificationNumericUpDown).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFIO; + private TextBox textBoxFio; + private Button buttonSave; + private Button buttonCancel; + private Label labelQualification; + private Label labelWorkExperience; + private NumericUpDown workExpNumericUpDown; + private NumericUpDown qualificationNumericUpDown; + private Label labelPassword; + private TextBox textBoxPassword; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormImplementer.cs b/SoftwareInstallation/SoftwareInstallationView/FormImplementer.cs new file mode 100644 index 0000000..3ad4f13 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormImplementer.cs @@ -0,0 +1,105 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + 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 buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFio.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFio.Text, + Password = textBoxPassword.Text, + Qualification = (int)qualificationNumericUpDown.Value, + WorkExperience = (int)workExpNumericUpDown.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFio.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + qualificationNumericUpDown.Value = view.Qualification; + workExpNumericUpDown.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormImplementer.resx b/SoftwareInstallation/SoftwareInstallationView/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/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/SoftwareInstallation/SoftwareInstallationView/FormImplementers.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.Designer.cs new file mode 100644 index 0000000..0281b39 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.Designer.cs @@ -0,0 +1,112 @@ +namespace SoftwareInstallationView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonChange = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(612, 451); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(641, 48); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(128, 40); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonChange + // + buttonChange.Location = new Point(641, 94); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(128, 40); + buttonChange.TabIndex = 3; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(641, 186); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(128, 40); + buttonUpdate.TabIndex = 6; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(641, 140); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(128, 40); + buttonDelete.TabIndex = 5; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormImplementers"; + Text = "Исполнители"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonUpdate; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs new file mode 100644 index 0000000..24567dd --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.cs @@ -0,0 +1,119 @@ +using Microsoft.Extensions.Logging; +using SoftwareInstallation; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + + _logger.LogInformation("Удаление исполнителя"); + + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка исполнителей"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallationView/FormImplementers.resx b/SoftwareInstallation/SoftwareInstallationView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallationView/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/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs index 636e882..1d2717b 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -32,15 +32,16 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); изделияToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); buttonIssuedOrder = new Button(); - buttonOrderReady = new Button(); buttonRefresh = new Button(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); @@ -48,16 +49,16 @@ // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(958, 24); + menuStrip.Size = new Size(1180, 24); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; @@ -65,17 +66,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(145, 22); + компонентыToolStripMenuItem.Size = new Size(149, 22); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // изделияToolStripMenuItem // изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(145, 22); + изделияToolStripMenuItem.Size = new Size(149, 22); изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(149, 22); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click_1; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(149, 22); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -104,59 +119,46 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(92, 20); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(12, 27); dataGridView.Name = "dataGridView"; - dataGridView.Size = new Size(751, 395); + dataGridView.Size = new Size(976, 395); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(785, 110); + buttonCreateOrder.Location = new Point(1010, 113); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(144, 39); + buttonCreateOrder.Size = new Size(144, 35); buttonCreateOrder.TabIndex = 2; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += buttonCreateOrder_Click; // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(785, 155); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(144, 39); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; - // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(785, 245); + buttonIssuedOrder.Location = new Point(1010, 197); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(144, 39); + buttonIssuedOrder.Size = new Size(144, 35); buttonIssuedOrder.TabIndex = 4; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; buttonIssuedOrder.Click += buttonIssuedOrder_Click; // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(785, 200); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(144, 39); - buttonOrderReady.TabIndex = 5; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += buttonOrderReady_Click; - // // buttonRefresh // - buttonRefresh.Location = new Point(785, 290); + buttonRefresh.Location = new Point(1010, 304); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(144, 39); + buttonRefresh.Size = new Size(144, 35); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить список"; buttonRefresh.UseVisualStyleBackColor = true; @@ -166,17 +168,15 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(958, 439); + ClientSize = new Size(1180, 439); Controls.Add(buttonRefresh); - Controls.Add(buttonOrderReady); Controls.Add(buttonIssuedOrder); - Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(dataGridView); Controls.Add(menuStrip); MainMenuStrip = menuStrip; Name = "FormMain"; - Text = "FormMain"; + Text = "Установка ПО"; Load += FormMain_Load; menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); @@ -193,13 +193,14 @@ private ToolStripMenuItem изделияToolStripMenuItem; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; private Button buttonIssuedOrder; - private Button buttonOrderReady; private Button buttonRefresh; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem списокКомпонентовToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs index 4390803..faae35d 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs @@ -20,12 +20,14 @@ namespace SoftwareInstallationView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void FormMain_Load(object sender, EventArgs e) { @@ -45,6 +47,10 @@ namespace SoftwareInstallationView dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["PackageId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } _logger.LogInformation("Загрузка заказов"); @@ -92,54 +98,6 @@ namespace SoftwareInstallationView } } - private void buttonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - - private void buttonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } private void buttonIssuedOrder_Click(object sender, EventArgs e) { @@ -200,5 +158,29 @@ namespace SoftwareInstallationView form.ShowDialog(); } } + + private void клиентыToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.resx b/SoftwareInstallation/SoftwareInstallationView/FormMain.resx index 6c82d08..57d8785 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.resx +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.resx @@ -120,4 +120,7 @@ 17, 17 + + 75 + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/Program.cs b/SoftwareInstallation/SoftwareInstallationView/Program.cs index f1c2777..3adf413 100644 --- a/SoftwareInstallation/SoftwareInstallationView/Program.cs +++ b/SoftwareInstallation/SoftwareInstallationView/Program.cs @@ -41,12 +41,15 @@ namespace SoftwareInstallation 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(); @@ -59,6 +62,8 @@ namespace SoftwareInstallation services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); }