diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..c4de57b --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,126 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic +{ + 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 Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + 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; + } + + 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/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs index dde69a3..da06f53 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs @@ -37,7 +37,7 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic } if (model.Count <= 0) { - throw new ArgumentNullException("Количество суши в заказе должно быть больше 0", nameof(model.Count)); + throw new ArgumentNullException("Количество пакетов в заказе должно быть больше 0", nameof(model.Count)); } if (model.Sum <= 0) { @@ -104,6 +104,22 @@ namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic } return true; } + 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; + } public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); diff --git a/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/WorkModeling.cs b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..f918e91 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,137 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationBusinessLogic.BusinessLogic +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Statuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(ImplementerViewModel implementer, List allOrders) + { + if (_orderLogic == null || implementer == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + // Выбираем из всех заказов тот, который выполняется данным исполнителем + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.ImplementerId == implementer.Id && x.Status == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id); + // доделываем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + // заказа может не быть, просто игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..478511c --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,22 @@ +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/OrderBindingModel.cs index 428705a..b1d3ba4 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/OrderBindingModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..05c33b6 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs index 909382f..c6dbc32 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..e2cebeb --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..ebc2c74 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + + public string? ImplementerFIO { get; set; } + + public string? Password { get; set; } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/OrderSearchModel.cs index 6aa2495..9e055b3 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/OrderSearchModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using AbstractSoftwareInstallationDataModels; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace AbstractSoftwareInstallationContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public List? Statuses { get; set; } } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..e20fa2d --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/ViewModels/ClientViewModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/ClientViewModel.cs index 3b5b750..df8c8a1 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/ClientViewModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/ClientViewModel.cs @@ -12,11 +12,11 @@ namespace AbstractSoftwareInstallationContracts.ViewModels { public int Id { get; set; } [DisplayName("ФИО клиента")] - public string ClientFIO { get; set; }= String.Empty; + public string ClientFIO { get; set; }= string.Empty; [DisplayName("Логин (эл. почта)")] - public string Email { get; set; }= String.Empty; + public string Email { get; set; }= string.Empty; [DisplayName("Пароль")] - public string Password { get; set; }= String.Empty; + public string Password { get; set; }= string.Empty; } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..2415654 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,27 @@ +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationContracts.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/AbstractSoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/OrderViewModel.cs index a56c1b7..b1d0d07 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -16,11 +16,14 @@ namespace AbstractSoftwareInstallationContracts.ViewModels public int Id { get; set; } public int PackageId { get; set; } public int ClientId { get; set; } + public int ImplementerId { get; set; } [DisplayName("Пакет")] public string PackageName { get; set; } = string.Empty; [DisplayName("Логин клиента")] public string Email { get; set; } = string.Empty; + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IImplementerModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..7121d40 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IOrderModel.cs b/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IOrderModel.cs index dab03b6..9726c36 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IOrderModel.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDataModels/Models/IOrderModel.cs @@ -10,6 +10,7 @@ namespace AbstractSoftwareInstallationDataModels.Models { int PackageId { get; } int ClientId { get; } + int ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs index d69cb94..b9e561b 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/AbstractSoftwareInstallationDatabase.cs @@ -25,5 +25,6 @@ optionsBuilder) public virtual DbSet PackageSoftwares { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..e010416 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + 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.ImplementerFIO != null) + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new AbstractSoftwareInstallationDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + 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 AbstractSoftwareInstallationDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new AbstractSoftwareInstallationDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs index 78e1658..8203f74 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs @@ -34,7 +34,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements return null; } using var context = new AbstractSoftwareInstallationDatabase(); - return context.Orders.Include(x => x.Package).Include(x => x.Client).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) @@ -46,6 +46,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements return context.Orders .Include(x => x.Package) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) .ToList(); @@ -53,7 +54,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements return context.Orders .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) - .Include(x => x.Package).Include(x => x.Client) + .Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); @@ -63,7 +64,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements { using var context = new AbstractSoftwareInstallationDatabase(); return context.Orders - .Include(x => x.Package).Include(x => x.Client) + .Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -79,7 +80,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements using var context = new AbstractSoftwareInstallationDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Package).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders.Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } @@ -93,7 +94,7 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Package).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; + return context.Orders.Include(x => x.Package).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel; } } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs new file mode 100644 index 0000000..f5b9aae --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.Designer.cs @@ -0,0 +1,255 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230423193329_Implementer")] + partial class Implementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.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("AbstractSoftwareInstallationDatabaseImplement.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("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.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("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", null) + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs new file mode 100644 index 0000000..9c24aaf --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423193329_Implementer.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class Implementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + 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"), + Qualification = table.Column(type: "int", nullable: false), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Password = table.Column(type: "nvarchar(max)", 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_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + 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"); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs new file mode 100644 index 0000000..3e8fb73 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.Designer.cs @@ -0,0 +1,259 @@ +// +using System; +using AbstractSoftwareInstallationDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractSoftwareInstallationDatabase))] + [Migration("20230423205115_OrderUPDATE")] + partial class OrderUPDATE + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.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("AbstractSoftwareInstallationDatabaseImplement.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("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.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("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PackageId") + .HasColumnType("int"); + + b.Property("SoftwareId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("SoftwareId"); + + b.ToTable("PackageSoftwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("SoftwareName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Softwares"); + }); + + modelBuilder.Entity("AbstractPackageInstallationDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Orders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Package"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.PackageSoftware", b => + { + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") + .WithMany("Softwares") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Software", "Software") + .WithMany("PackageSoftwares") + .HasForeignKey("SoftwareId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("Software"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => + { + b.Navigation("Orders"); + + b.Navigation("Softwares"); + }); + + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Software", b => + { + b.Navigation("PackageSoftwares"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs new file mode 100644 index 0000000..cb79582 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/20230423205115_OrderUPDATE.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractSoftwareInstallationDatabaseImplement.Migrations +{ + /// + public partial class OrderUPDATE : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs index b768fcb..51e1636 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Migrations/AbstractSoftwareInstallationDatabaseModelSnapshot.cs @@ -42,6 +42,9 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PackageId") .HasColumnType("int"); @@ -55,6 +58,8 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PackageId"); b.ToTable("Orders"); @@ -85,6 +90,33 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.ToTable("Clients"); }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => { b.Property("Id") @@ -159,6 +191,12 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("AbstractSoftwareInstallationDatabaseImplement.Models.Package", "Package") .WithMany("Orders") .HasForeignKey("PackageId") @@ -167,6 +205,8 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Package"); }); @@ -194,6 +234,11 @@ namespace AbstractSoftwareInstallationDatabaseImplement.Migrations b.Navigation("Orders"); }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("AbstractSoftwareInstallationDatabaseImplement.Models.Package", b => { b.Navigation("Orders"); diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..a8ef5b3 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +using AbstractPackageInstallationDatabaseImplement.Models; +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public int Qualification { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public string Password { get; private set; } = string.Empty; + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + Password = model.Password + }; + } + public void Update(ImplementerBindingModel? model) + { + if (model == null) + { + return; + } + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + Password = model.Password; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + Password = Password + }; + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs index 5ebaad2..9d27cb2 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationDatabaseImplement/Models/Order.cs @@ -21,6 +21,8 @@ namespace AbstractPackageInstallationDatabaseImplement.Models [Required] public int ClientId { get; private set; } [Required] + public int ImplementerId { get; private set; } + [Required] public int Count { get; private set; } [Required] public double Sum { get; private set; } @@ -32,7 +34,7 @@ namespace AbstractPackageInstallationDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Package Package { get; set; } public virtual Client Client { get; set; } - + public virtual Implementer Implementer { get; set; } public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -43,6 +45,7 @@ namespace AbstractPackageInstallationDatabaseImplement.Models { PackageId = model.PackageId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -67,13 +70,15 @@ namespace AbstractPackageInstallationDatabaseImplement.Models Id = Id, PackageId = PackageId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, PackageName = Package.PackageName, - Email = Client.Email + Email = Client.Email, + ImplementerFIO = Implementer.ImplementerFIO }; } } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs index 5734751..47b0ed3 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/DataFileSingleton.cs @@ -11,10 +11,13 @@ namespace AbstractSoftwareInstallationFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string PackageFileName = "Package.xml"; private readonly string ClientFileName = "Package.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Softwares { 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) @@ -27,13 +30,16 @@ namespace AbstractSoftwareInstallationFileImplement 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() { Softwares = LoadData(SoftwareFileName, "Software", x => Software.Create(x)!)!; Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - Clients = LoadData(OrderFileName, "Client", x => Client.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/AbstractSoftwareInstallationFileImplement/Implements/ImplementerStorage.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..c41067f --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,84 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.StoragesContracts; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationFileImplement.Implements +{ + partial class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + if (model.ImplementerFIO != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Implementer.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..bd6cbb6 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Implementer.cs @@ -0,0 +1,88 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractSoftwareInstallationFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("FIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs index a619370..208a4b8 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationFileImplement/Models/Order.cs @@ -11,11 +11,11 @@ using System.Xml.Linq; namespace AbstractSoftwareInstallationFileImplement.Models { - internal class Order : IOrderModel + public class Order : IOrderModel { public int PackageId { get; private set; } public int ClientId { get; private set; } - + public int ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } diff --git a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs index f2a9bc3..672d974 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/DataListSingleton.cs @@ -15,12 +15,14 @@ namespace AbstractSoftwareInstallationListImplement public List Orders { get; set; } public List Packages { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Softwares = new List(); Orders = new List(); Packages = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Implementer.cs b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Implementer.cs new file mode 100644 index 0000000..e0f0c92 --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractSoftwareInstallationListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Order.cs b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Order.cs index 89ea1d1..385a13c 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Order.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationListImplement/Models/Order.cs @@ -9,7 +9,7 @@ namespace AbstractSoftwareInstallationListImplement.Models { public int PackageId { get; private set; } public int ClientId { get; private set; } - + public int ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -29,6 +29,7 @@ namespace AbstractSoftwareInstallationListImplement.Models { PackageId = model.PackageId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,6 +53,7 @@ namespace AbstractSoftwareInstallationListImplement.Models Id = Id, PackageId = PackageId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Controllers/ImplementerController.cs b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..9a9ee0d --- /dev/null +++ b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,106 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using AbstractSoftwareInstallationContracts.SearchModels; +using AbstractSoftwareInstallationContracts.ViewModels; +using AbstractSoftwareInstallationDataModels; +using Microsoft.AspNetCore.Mvc; + +namespace AbstractSoftwareInstallationRestApi.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/AbstractSoftwareInstallationRestApi/Program.cs b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Program.cs index 6de915e..406048d 100644 --- a/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Program.cs +++ b/SoftwareInstallation/AbstractSoftwareInstallationRestApi/Program.cs @@ -10,10 +10,12 @@ builder.Logging.SetMinimumLevel(LogLevel.Trace); builder.Logging.AddLog4Net("log4net.config"); // Add services to the container. +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementer.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementer.Designer.cs new file mode 100644 index 0000000..b90656e --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementer.Designer.cs @@ -0,0 +1,172 @@ +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() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownWorkExp = new System.Windows.Forms.NumericUpDown(); + this.textBoxPassword = new System.Windows.Forms.TextBox(); + this.textBoxFIO = new System.Windows.Forms.TextBox(); + this.labelQualification = new System.Windows.Forms.Label(); + this.labelWorkExp = new System.Windows.Forms.Label(); + this.labelPassword = new System.Windows.Forms.Label(); + this.labelFIO = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExp)).BeginInit(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(397, 160); + this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(93, 22); + this.buttonCancel.TabIndex = 19; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(302, 160); + this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(90, 22); + this.buttonSave.TabIndex = 18; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // numericUpDownQualification + // + this.numericUpDownQualification.Location = new System.Drawing.Point(154, 116); + this.numericUpDownQualification.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.numericUpDownQualification.Name = "numericUpDownQualification"; + this.numericUpDownQualification.Size = new System.Drawing.Size(159, 23); + this.numericUpDownQualification.TabIndex = 17; + // + // numericUpDownWorkExp + // + this.numericUpDownWorkExp.Location = new System.Drawing.Point(154, 84); + this.numericUpDownWorkExp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.numericUpDownWorkExp.Name = "numericUpDownWorkExp"; + this.numericUpDownWorkExp.Size = new System.Drawing.Size(159, 23); + this.numericUpDownWorkExp.TabIndex = 16; + // + // textBoxPassword + // + this.textBoxPassword.Location = new System.Drawing.Point(154, 49); + this.textBoxPassword.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxPassword.Name = "textBoxPassword"; + this.textBoxPassword.Size = new System.Drawing.Size(160, 23); + this.textBoxPassword.TabIndex = 15; + // + // textBoxFIO + // + this.textBoxFIO.Location = new System.Drawing.Point(154, 20); + this.textBoxFIO.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxFIO.Name = "textBoxFIO"; + this.textBoxFIO.Size = new System.Drawing.Size(325, 23); + this.textBoxFIO.TabIndex = 14; + // + // labelQualification + // + this.labelQualification.AutoSize = true; + this.labelQualification.Location = new System.Drawing.Point(39, 118); + this.labelQualification.Name = "labelQualification"; + this.labelQualification.Size = new System.Drawing.Size(91, 15); + this.labelQualification.TabIndex = 13; + this.labelQualification.Text = "Квалификация:"; + // + // labelWorkExp + // + this.labelWorkExp.AutoSize = true; + this.labelWorkExp.Location = new System.Drawing.Point(39, 85); + this.labelWorkExp.Name = "labelWorkExp"; + this.labelWorkExp.Size = new System.Drawing.Size(82, 15); + this.labelWorkExp.TabIndex = 12; + this.labelWorkExp.Text = "Стаж работы:"; + // + // labelPassword + // + this.labelPassword.AutoSize = true; + this.labelPassword.Location = new System.Drawing.Point(39, 54); + this.labelPassword.Name = "labelPassword"; + this.labelPassword.Size = new System.Drawing.Size(52, 15); + this.labelPassword.TabIndex = 11; + this.labelPassword.Text = "Пароль:"; + // + // labelFIO + // + this.labelFIO.AutoSize = true; + this.labelFIO.Location = new System.Drawing.Point(39, 20); + this.labelFIO.Name = "labelFIO"; + this.labelFIO.Size = new System.Drawing.Size(40, 15); + this.labelFIO.TabIndex = 10; + this.labelFIO.Text = "ФИО: "; + // + // FormImplementer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(528, 202); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.numericUpDownQualification); + this.Controls.Add(this.numericUpDownWorkExp); + this.Controls.Add(this.textBoxPassword); + this.Controls.Add(this.textBoxFIO); + this.Controls.Add(this.labelQualification); + this.Controls.Add(this.labelWorkExp); + this.Controls.Add(this.labelPassword); + this.Controls.Add(this.labelFIO); + this.Name = "FormImplementer"; + this.Text = "Исполнитель"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExp)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + this.Load += new EventHandler(this.FormImplementer_Load); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExp; + private TextBox textBoxPassword; + private TextBox textBoxFIO; + private Label labelQualification; + private Label labelWorkExp; + private Label labelPassword; + private Label labelFIO; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementer.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementer.cs new file mode 100644 index 0000000..153fd09 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementer.cs @@ -0,0 +1,101 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using AbstractSoftwareInstallationContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 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 FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение информации исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExp.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExp.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementer.resx b/SoftwareInstallation/SoftwareInstallation/FormImplementer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementers.Designer.cs new file mode 100644 index 0000000..e409bf7 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.Designer.cs @@ -0,0 +1,119 @@ +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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonRefresh = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonCreate = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 20); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(568, 320); + this.dataGridView.TabIndex = 9; + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(586, 99); + this.buttonRefresh.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(106, 22); + this.buttonRefresh.TabIndex = 8; + this.buttonRefresh.Text = "Обновить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(586, 73); + this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(106, 22); + this.buttonDelete.TabIndex = 7; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(586, 46); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(106, 22); + this.buttonEdit.TabIndex = 6; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click); + // + // buttonCreate + // + this.buttonCreate.Location = new System.Drawing.Point(586, 20); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(106, 22); + this.buttonCreate.TabIndex = 5; + this.buttonCreate.Text = "Добавить"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); + // + // FormImplementers + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(699, 358); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonCreate); + this.Name = "FormImplementers"; + this.Text = "Исполнители"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.Load += new EventHandler(this.FormImplementers_Load); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs new file mode 100644 index 0000000..e79217d --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.cs @@ -0,0 +1,115 @@ +using AbstractSoftwareInstallationContracts.BindingModels; +using AbstractSoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using SoftwareInstallation; +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 FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCreate_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 buttonEdit_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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SoftwareInstallation/SoftwareInstallation/FormImplementers.resx b/SoftwareInstallation/SoftwareInstallation/FormImplementers.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormImplementers.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index c93deac..e5efee0 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -41,10 +41,12 @@ namespace SoftwareInstallationView this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.packageToolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); this.clientToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.implementerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.storageToolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.packagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.packageSoftwaresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.startWorksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); @@ -70,26 +72,6 @@ namespace SoftwareInstallationView this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.Click += new System.EventHandler(this.buttonCreateOrder_Click); // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(628, 75); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(153, 23); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.buttonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(628, 123); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(153, 23); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.buttonOrderReady_Click); - // // buttonIssuedOrder // this.buttonIssuedOrder.Location = new System.Drawing.Point(628, 171); @@ -113,7 +95,8 @@ namespace SoftwareInstallationView // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.guideToolStripMenuItem, this.reportsToolStripMenuItem}); + this.guideToolStripMenuItem, this.reportsToolStripMenuItem, + this.startWorksToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; @@ -125,7 +108,7 @@ namespace SoftwareInstallationView // this.guideToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.packageToolStripMenuItem2, - this.storageToolStripMenuItem3, this.clientToolStripMenuItem}); + this.storageToolStripMenuItem3, this.clientToolStripMenuItem, this.implementerToolStripMenuItem}); this.guideToolStripMenuItem.Name = "guideToolStripMenuItem"; this.guideToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.guideToolStripMenuItem.Text = "Справочники"; @@ -140,6 +123,13 @@ namespace SoftwareInstallationView this.reportsToolStripMenuItem.Size = new System.Drawing.Size(73, 24); this.reportsToolStripMenuItem.Text = "Отчеты"; // + // startWorksToolStripMenuItem + // + this.startWorksToolStripMenuItem.Name = "startWorksToolStripMenuItem"; + this.startWorksToolStripMenuItem.Size = new System.Drawing.Size(114, 24); + this.startWorksToolStripMenuItem.Text = "Запуск работ"; + this.startWorksToolStripMenuItem.Click += new System.EventHandler(this.startWorksToolStripMenuItem_Click); + // // packagesToolStripMenuItem // this.packagesToolStripMenuItem.Name = "packagesToolStripMenuItem"; @@ -175,6 +165,13 @@ namespace SoftwareInstallationView this.clientToolStripMenuItem.Text = "Клиенты"; this.clientToolStripMenuItem.Click += new System.EventHandler(this.clientToolStripMenuItem_Click); // + // implementerToolStripMenuItem + // + this.implementerToolStripMenuItem.Name = "implementerToolStripMenuItem"; + this.implementerToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.implementerToolStripMenuItem.Text = "Исполнитель"; + this.implementerToolStripMenuItem.Click += new System.EventHandler(this.implementerToolStripMenuItem_Click); + // // storageToolStripMenuItem3 // this.storageToolStripMenuItem3.Name = "storageToolStripMenuItem3"; @@ -222,5 +219,7 @@ namespace SoftwareInstallationView private ToolStripMenuItem packagesToolStripMenuItem; private ToolStripMenuItem packageSoftwaresToolStripMenuItem; private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem implementerToolStripMenuItem; + private ToolStripMenuItem startWorksToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index 7f9ada6..e1eb46c 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -42,6 +42,7 @@ namespace SoftwareInstallationView dataGridView.DataSource = list; dataGridView.Columns["PackageId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } } catch (Exception ex) @@ -61,56 +62,7 @@ namespace SoftwareInstallationView LoadData(); } } - private void buttonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{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) { if (dataGridView.SelectedRows.Count == 1) @@ -198,5 +150,18 @@ namespace SoftwareInstallationView form.ShowDialog(); } } + private void implementerToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + private void startWorksToolStripMenuItem_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/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index 1ac1217..24c771b 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -35,21 +35,26 @@ namespace SoftwareInstallation option.SetMinimumLevel(LogLevel.Information); option.AddNLog("nlog.config"); }); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();