diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ImplementLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ImplementLogic.cs new file mode 100644 index 0000000..f5a3e6b --- /dev/null +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ImplementLogic.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesBusinessLogic.BusinessLogic +{ + public class ImplementLogic : IImplementLogic + { + private readonly ILogger _logger; + private readonly IImplementStorage _storage; + public ImplementLogic(ILogger logger, IImplementStorage storage) + { + _logger = logger; + _storage = storage; + } + public ImplementViewModel? ReadElement(ImplementSearchModel? model) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + _logger.LogInformation("ReadElement. FIO:{ImplementFIO}. Id:{Id}", model.ImplementFIO, model.Id); + var element = _storage.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(ImplementSearchModel? model) + { + var list = model == null ? _storage.GetFullList() : _storage.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(ImplementBindingModel? model, bool withParams = true) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (!withParams) + return; + if (string.IsNullOrEmpty(model.ImplementFIO)) + throw new ArgumentException("Нет ФИО исполнителя", nameof(model.ImplementFIO)); + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж меньше 0", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}. Password:{Password}. WorkExperience:{WorkExperience}. Qualification:{Qualification}. Id: {Id} ", model.ImplementFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _storage.GetElement(new ImplementSearchModel { ImplementFIO = model.ImplementFIO }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с этим именем уже существует"); + } + } + public bool Create(ImplementBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Insert Imlement"); + if (_storage.Insert(model) == null) + { + _logger.LogWarning("Insert Error"); + return false; + } + return true; + } + public bool Delete(ImplementBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete Implement Id:{Id}", model.Id); + if (_storage.Delete(model) == null) + { + _logger.LogWarning("Delete Error"); + return false; + } + return true; + } + public bool Update(ImplementBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Update Implement Id:{Id}", model.Id); + if (_storage.Update(model) == null) + { + _logger.LogWarning("Update Error"); + return false; + } + return true; + } + } +} diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs index a99f4f3..561595a 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs @@ -12,6 +12,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { @@ -19,6 +20,22 @@ namespace SewingDressesBusinessLogic.BusinessLogic _orderStorage = orderStorage; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var elem = _orderStorage.GetElement(model); + if (elem == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement found. Id:{Id}", elem.Id); + return elem; + } public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); @@ -32,12 +49,16 @@ namespace SewingDressesBusinessLogic.BusinessLogic return list; } - private void CheckModel(OrderBindingModel model) + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } + if (!withParams) + { + return; + } if (model.Count <= 0) { throw new ArgumentNullException("Количество заказов должно быть больше нуля"); @@ -68,6 +89,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic private bool ChangeStatus(OrderBindingModel model, OrderStatus status) { + CheckModel (model, false); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (element == null) { @@ -79,6 +101,8 @@ namespace SewingDressesBusinessLogic.BusinessLogic _logger.LogWarning("Status change failed"); throw new InvalidOperationException("Невозможно перевести состояние заказа"); } + if (element.ImplementId != null) + element.ImplementId = model.ImplementId; model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); @@ -87,7 +111,10 @@ namespace SewingDressesBusinessLogic.BusinessLogic public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } public bool FinishOrder(OrderBindingModel model) diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/WorkModeling.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..32e2fa3 --- /dev/null +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,110 @@ +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Enums; + +namespace SewingDressesBusinessLogic.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(IImplementLogic implementLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel { Status = 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(ImplementViewModel implement, List orders) + { + if (_orderLogic == null || implement == null) + return; + await RunOrderInWork(implement); + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implement.Id, order.Id); + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementId = implement.Id + }); + Thread.Sleep(implement.WorkExperience * _rnd.Next(100, 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implement.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id, + ImplementId = implement.Id + }); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + Thread.Sleep(implement.Qualification * _rnd.Next(10, 100)); + } + }); + } + + private async Task RunOrderInWork(ImplementViewModel implement) + { + if (_orderLogic == null || implement == null) + return; + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + { + ImplementId = implement.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + return; + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implement.Id, runOrder.Id); + Thread.Sleep(implement.WorkExperience * _rnd.Next(100, 300) * runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implement.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel { Id = runOrder.Id }); + Thread.Sleep(implement.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning("Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/SewingDresses/SewingDressesContracts/BindingModels/ImplementBindingModel.cs b/SewingDresses/SewingDressesContracts/BindingModels/ImplementBindingModel.cs new file mode 100644 index 0000000..ab6bf70 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BindingModels/ImplementBindingModel.cs @@ -0,0 +1,18 @@ +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.BindingModels +{ + public class ImplementBindingModel : IImplementModel + { + public int Id { get; set; } + public string ImplementFIO { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } + public int Qualification { get; set; } + } +} diff --git a/SewingDresses/SewingDressesContracts/BindingModels/OrderBindingModel.cs b/SewingDresses/SewingDressesContracts/BindingModels/OrderBindingModel.cs index 0462f9a..53a27e2 100644 --- a/SewingDresses/SewingDressesContracts/BindingModels/OrderBindingModel.cs +++ b/SewingDresses/SewingDressesContracts/BindingModels/OrderBindingModel.cs @@ -8,6 +8,8 @@ namespace SewingDressesContracts.BindingModels public int Id { get; set; } public int DressId { get; set; } public int ClientId { get; set; } + public int? ImplementId { get; set; } + public string? ImplementFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } diff --git a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IImplementLogic.cs b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IImplementLogic.cs new file mode 100644 index 0000000..70ab012 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IImplementLogic.cs @@ -0,0 +1,20 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.BusinessLogicsContracts +{ + public interface IImplementLogic + { + List? ReadList(ImplementSearchModel? model); + ImplementViewModel? ReadElement(ImplementSearchModel? model); + bool Create(ImplementBindingModel? model); + bool Update(ImplementBindingModel? model); + bool Delete(ImplementBindingModel? model); + } +} diff --git a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IOrderLogic.cs b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IOrderLogic.cs index 8486c9a..7d014d0 100644 --- a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -7,6 +7,7 @@ namespace SewingDressesContracts.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/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IWorkProcess.cs b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..6251d67 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementLogic implementLogic, IOrderLogic orderLogic); + } +} diff --git a/SewingDresses/SewingDressesContracts/SearchModels/ImplementSearchModel.cs b/SewingDresses/SewingDressesContracts/SearchModels/ImplementSearchModel.cs new file mode 100644 index 0000000..1c07910 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/SearchModels/ImplementSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.SearchModels +{ + public class ImplementSearchModel + { + public int? Id { get; set; } + public string? ImplementFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/SewingDresses/SewingDressesContracts/SearchModels/OrderSearchModel.cs b/SewingDresses/SewingDressesContracts/SearchModels/OrderSearchModel.cs index cd22d81..782678f 100644 --- a/SewingDresses/SewingDressesContracts/SearchModels/OrderSearchModel.cs +++ b/SewingDresses/SewingDressesContracts/SearchModels/OrderSearchModel.cs @@ -1,10 +1,14 @@ -namespace SewingDressesContracts.SearchModels +using SewingDressesDataModels.Enums; + +namespace SewingDressesContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/SewingDresses/SewingDressesContracts/StoragesContracts/IImplementStorage.cs b/SewingDresses/SewingDressesContracts/StoragesContracts/IImplementStorage.cs new file mode 100644 index 0000000..f4487c1 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/StoragesContracts/IImplementStorage.cs @@ -0,0 +1,22 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.StoragesContracts +{ + public interface IImplementStorage + { + List GetFullList(); + List GetFilteredList(ImplementSearchModel model); + ImplementViewModel? GetElement(ImplementSearchModel model); + ImplementViewModel? Insert(ImplementBindingModel? model); + ImplementViewModel? Update(ImplementBindingModel? model); + ImplementViewModel? Delete(ImplementBindingModel? model); + + } +} diff --git a/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs new file mode 100644 index 0000000..41acdec --- /dev/null +++ b/SewingDresses/SewingDressesContracts/ViewModels/ImplementViewModel.cs @@ -0,0 +1,23 @@ +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.ViewModels +{ + public class ImplementViewModel : IImplementModel + { + public int Id { get; set; } + [DisplayName("Имя исполнителя")] + public string ImplementFIO { 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/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs index ca74cf3..7429814 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/OrderViewModel.cs @@ -9,9 +9,12 @@ namespace SewingDressesContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int DressId { get; set; } + public int? ImplementId { get; set; } public int ClientId { get; set; } [DisplayName("Имя клиента")] public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Имя исполнителя")] + public string? ImplementFIO { get; set; } = string.Empty; [DisplayName("Платье")] public string DressName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/SewingDresses/SewingDressesDataModels/Models/IImplementModel.cs b/SewingDresses/SewingDressesDataModels/Models/IImplementModel.cs new file mode 100644 index 0000000..7267eb7 --- /dev/null +++ b/SewingDresses/SewingDressesDataModels/Models/IImplementModel.cs @@ -0,0 +1,10 @@ +namespace SewingDressesDataModels.Models +{ + public interface IImplementModel : IId + { + string ImplementFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/SewingDresses/SewingDressesDataModels/Models/IOrderModel.cs b/SewingDresses/SewingDressesDataModels/Models/IOrderModel.cs index 377aa05..82e6c8b 100644 --- a/SewingDresses/SewingDressesDataModels/Models/IOrderModel.cs +++ b/SewingDresses/SewingDressesDataModels/Models/IOrderModel.cs @@ -7,6 +7,8 @@ namespace SewingDressesDataModels.Models int DressId { get; } int Count { get; } double Sum { get; } + int ClientId { get; } + int? ImplementId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/SewingDresses/SewingDressesDatabaseImplement/Implements/ImplementStorage.cs b/SewingDresses/SewingDressesDatabaseImplement/Implements/ImplementStorage.cs new file mode 100644 index 0000000..d2b1a37 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Implements/ImplementStorage.cs @@ -0,0 +1,65 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesDatabaseImplement.Implements +{ + public class ImplementStorage : IImplementStorage + { + public ImplementViewModel? Insert(ImplementBindingModel? model) + { + using var context = new SewingDressesDatabase(); + var newImplement = Implement.Create(model); + if (newImplement == null) + return null; + context.Implements.Add(newImplement); + context.SaveChanges(); + return newImplement.GetViewModel; + } + public ImplementViewModel? Update(ImplementBindingModel? model) + { + using var context = new SewingDressesDatabase(); + if (model == null) + return null; + var implement = context.Implements.FirstOrDefault(x => x.Id == model.Id); + if (implement == null) return null; + implement.Update(model); + context.SaveChanges(); + return implement.GetViewModel; + } + public ImplementViewModel? Delete(ImplementBindingModel? model) + { + using var context = new SewingDressesDatabase(); + var implement = context.Implements.FirstOrDefault(x => x.Id == model.Id); + if (implement == null) return null; + context.Implements.Remove(implement); + context.SaveChanges(); + return implement.GetViewModel; + } + public ImplementViewModel? GetElement(ImplementSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementFIO) && !model.Id.HasValue) + return null; + using var context = new SewingDressesDatabase(); + return context.Implements.FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO.Equals(model.ImplementFIO)) && (!model.Id.HasValue || model.Id == x.Id))?.GetViewModel; + } + public List GetFullList() + { + using var context = new SewingDressesDatabase(); + return context.Implements.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ImplementSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementFIO)) return new(); + using var context = new SewingDressesDatabase(); + return context.Implements.Where(x => x.ImplementFIO.Equals(model.ImplementFIO)).Select(x => x.GetViewModel).ToList(); + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Implements/OrderStorage.cs b/SewingDresses/SewingDressesDatabaseImplement/Implements/OrderStorage.cs index 6734e10..bc62179 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Implements/OrderStorage.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Implements/OrderStorage.cs @@ -1,4 +1,5 @@ -using SewingDressesContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using SewingDressesContracts.BindingModels; using SewingDressesContracts.SearchModels; using SewingDressesContracts.StoragesContracts; using SewingDressesContracts.ViewModels; @@ -8,87 +9,76 @@ namespace SewingDressesDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - public List GetFullList() + public List GetFullList() { using var context = new SewingDressesDatabase(); - return context.Orders.Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Select(x => x.GetViewModel).ToList(); } - public List GetFilteredList(OrderSearchModel model) + public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue && !model.Status.HasValue) { return new(); } using var context = new SewingDressesDatabase(); if (model.Id.HasValue) - return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); else if (model.ClientId.HasValue) - return context.Orders.Where(x => x.ClientId == model.ClientId).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + else if (model.DateFrom != null) + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); else - return context.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList(); + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).Where(x => x.Status.Equals(model.Status)).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (!model.ImplementId.HasValue || !model.Status.HasValue)) { return null; } using var context = new SewingDressesDatabase(); - return AcessDressesStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context); + if (model.Id.HasValue) + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.ImplementId == model.ImplementId && x.Status == model.Status)?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { - var order = Order.Create(model); + using var context = new SewingDressesDatabase(); + var order = Order.Create(model, context); if (order == null) { return null; } - using var context = new SewingDressesDatabase(); context.Orders.Add(order); context.SaveChanges(); - return AcessDressesStorage(order.GetViewModel, context); + return order.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new SewingDressesDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + var order = context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; } order.Update(model); context.SaveChanges(); - return AcessDressesStorage(order.GetViewModel, context); + return order.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new SewingDressesDatabase(); - var element = context.Orders.FirstOrDefault(x => x.Id == model.Id); + var element = context.Orders.Include(x => x.Dress).Include(x => x.Client).Include(x => x.Implement).FirstOrDefault(x => x.Id == model.Id); if (element == null) { return null; } context.Orders.Remove(element); context.SaveChanges(); - return AcessDressesStorage(element.GetViewModel, context); - } - public static OrderViewModel? AcessDressesStorage(OrderViewModel? model, SewingDressesDatabase context) - { - if (model == null) - { - return null; - } - var dress = context.Dresses.FirstOrDefault(x => x.Id == model.DressId); - var client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId); - if (client == null || dress == null) - return null; - model.DressName = dress.DressName; - model.ClientFIO = client.ClientFIO; - model.ClientId = client.Id; - return model; + return element.GetViewModel; } } diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.Designer.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.Designer.cs new file mode 100644 index 0000000..11b427c --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.Designer.cs @@ -0,0 +1,260 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SewingDressesDatabaseImplement; + +#nullable disable + +namespace SewingDressesDatabaseImplement.Migrations +{ + [DbContext(typeof(SewingDressesDatabase))] + [Migration("20240418162241_init")] + partial class init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SewingDressesDatabaseImplement.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("SewingDressesDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DressName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Dresses"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DressId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DressId"); + + b.ToTable("DressComponents"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementFIO") + .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("Implements"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.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("DressId") + .HasColumnType("int"); + + b.Property("ImplementId") + .IsRequired() + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("DressId"); + + b.HasIndex("ImplementId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component") + .WithMany("DressComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") + .WithMany("Components") + .HasForeignKey("DressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Dress"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") + .WithMany("Orders") + .HasForeignKey("DressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement") + .WithMany("Orders") + .HasForeignKey("ImplementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Dress"); + + b.Navigation("Implement"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b => + { + b.Navigation("DressComponents"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.cs new file mode 100644 index 0000000..0375ce3 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418162241_init.cs @@ -0,0 +1,186 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SewingDressesDatabaseImplement.Migrations +{ + /// + public partial class init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Dresses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DressName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Dresses", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Implements", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementFIO = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implements", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "DressComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DressId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DressComponents", x => x.Id); + table.ForeignKey( + name: "FK_DressComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_DressComponents_Dresses_DressId", + column: x => x.DressId, + principalTable: "Dresses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DressId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + ImplementId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Dresses_DressId", + column: x => x.DressId, + principalTable: "Dresses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implements_ImplementId", + column: x => x.ImplementId, + principalTable: "Implements", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_DressComponents_ComponentId", + table: "DressComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_DressComponents_DressId", + table: "DressComponents", + column: "DressId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_DressId", + table: "Orders", + column: "DressId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementId", + table: "Orders", + column: "ImplementId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "DressComponents"); + + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Dresses"); + + migrationBuilder.DropTable( + name: "Implements"); + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.Designer.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.Designer.cs new file mode 100644 index 0000000..7d583ee --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SewingDressesDatabaseImplement; + +#nullable disable + +namespace SewingDressesDatabaseImplement.Migrations +{ + [DbContext(typeof(SewingDressesDatabase))] + [Migration("20240418182438_nullab")] + partial class nullab + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SewingDressesDatabaseImplement.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("SewingDressesDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DressName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Dresses"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DressId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DressId"); + + b.ToTable("DressComponents"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementFIO") + .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("Implements"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.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("DressId") + .HasColumnType("int"); + + b.Property("ImplementId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("DressId"); + + b.HasIndex("ImplementId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.DressComponent", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Component", "Component") + .WithMany("DressComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") + .WithMany("Components") + .HasForeignKey("DressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Dress"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b => + { + b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") + .WithMany("Orders") + .HasForeignKey("DressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement") + .WithMany("Orders") + .HasForeignKey("ImplementId"); + + b.Navigation("Client"); + + b.Navigation("Dress"); + + b.Navigation("Implement"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Component", b => + { + b.Navigation("DressComponents"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Dress", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.cs new file mode 100644 index 0000000..7b643d3 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/20240418182438_nullab.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SewingDressesDatabaseImplement.Migrations +{ + /// + public partial class nullab : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implements_ImplementId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementId", + table: "Orders", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implements_ImplementId", + table: "Orders", + column: "ImplementId", + principalTable: "Implements", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implements_ImplementId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implements_ImplementId", + table: "Orders", + column: "ImplementId", + principalTable: "Implements", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs b/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs index c8ce769..b8d2e94 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Migrations/SewingDressesDatabaseModelSnapshot.cs @@ -113,6 +113,33 @@ namespace SewingDressesDatabaseImplement.Migrations b.ToTable("DressComponents"); }); + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementFIO") + .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("Implements"); + }); + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace SewingDressesDatabaseImplement.Migrations b.Property("DressId") .HasColumnType("int"); + b.Property("ImplementId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -148,6 +178,8 @@ namespace SewingDressesDatabaseImplement.Migrations b.HasIndex("DressId"); + b.HasIndex("ImplementId"); + b.ToTable("Orders"); }); @@ -172,17 +204,27 @@ namespace SewingDressesDatabaseImplement.Migrations modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Order", b => { - b.HasOne("SewingDressesDatabaseImplement.Models.Client", null) + b.HasOne("SewingDressesDatabaseImplement.Models.Client", "Client") .WithMany("Orders") .HasForeignKey("ClientId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("SewingDressesDatabaseImplement.Models.Dress", null) + b.HasOne("SewingDressesDatabaseImplement.Models.Dress", "Dress") .WithMany("Orders") .HasForeignKey("DressId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.HasOne("SewingDressesDatabaseImplement.Models.Implement", "Implement") + .WithMany("Orders") + .HasForeignKey("ImplementId"); + + b.Navigation("Client"); + + b.Navigation("Dress"); + + b.Navigation("Implement"); }); modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Client", b => @@ -201,6 +243,11 @@ namespace SewingDressesDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("SewingDressesDatabaseImplement.Models.Implement", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs new file mode 100644 index 0000000..275bcb3 --- /dev/null +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Implement.cs @@ -0,0 +1,59 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.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 SewingDressesDatabaseImplement.Models +{ + public class Implement : IImplementModel + { + public int Id { get; private set; } + [Required] + public string ImplementFIO { get; private set; } = string.Empty; + [Required] + public int WorkExperience { get; private set; } + [Required] + public string Password { get; private set; } = string.Empty; + [Required] + public int Qualification { get; private set; } + [ForeignKey("ImplementId")] + public virtual List? Orders { get; set; } = new(); + public static Implement? Create(ImplementBindingModel? model) + { + if (model == null) + return null; + return new Implement + { + Id = model.Id, + ImplementFIO = model.ImplementFIO, + WorkExperience = model.WorkExperience, + Password = model.Password, + Qualification = model.Qualification, + }; + } + public ImplementViewModel GetViewModel => new() + { + Id = Id, + ImplementFIO = ImplementFIO, + WorkExperience = WorkExperience, + Password = Password, + Qualification = Qualification + }; + public void Update(ImplementBindingModel? model) + { + if (model == null) return; + ImplementFIO = model.ImplementFIO; + WorkExperience = model.WorkExperience; + Password = model.Password; + Qualification = model.Qualification; + } + + + } +} diff --git a/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs b/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs index 40cfa60..f29665e 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace SewingDressesDatabaseImplement.Models public int DressId { get; private set; } [Required] public int ClientId { get; private set; } + public int? ImplementId { get; private set; } [Required] public int Count { get; private set; } [Required] @@ -23,8 +24,11 @@ namespace SewingDressesDatabaseImplement.Models [Required] public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } + public virtual Dress Dress { get; set; } + public virtual Client Client { get; set; } + public virtual Implement? Implement { get; set; } - public static Order? Create(OrderBindingModel model) + public static Order? Create(OrderBindingModel model, SewingDressesDatabase context) { if (model == null) { @@ -35,6 +39,10 @@ namespace SewingDressesDatabaseImplement.Models Id = model.Id, DressId = model.DressId, ClientId = model.ClientId, + ImplementId = model.ImplementId, + Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId)!, + Dress = context.Dresses.FirstOrDefault(x => x.Id == model.DressId)!, + Implement = model.ImplementId.HasValue ? context.Implements.FirstOrDefault(x => x.Id == model.ImplementId) : null, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -48,13 +56,18 @@ namespace SewingDressesDatabaseImplement.Models return; } Status = model.Status; + ImplementId = model.ImplementId; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() { Id = Id, DressId = DressId, + DressName = Dress.DressName, ClientId = ClientId, + ClientFIO = Client.ClientFIO, + ImplementId = ImplementId, + ImplementFIO = Implement?.ImplementFIO, Count = Count, Sum = Sum, Status = Status, diff --git a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs index b0cc144..fdde74f 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs +++ b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabase.cs @@ -17,5 +17,6 @@ namespace SewingDressesDatabaseImplement public virtual DbSet DressComponents { get; set; } public virtual DbSet Orders { get; set; } public virtual DbSet Clients { get; set; } + public virtual DbSet Implements { get; set; } } } diff --git a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj index 020576c..2574adc 100644 --- a/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj +++ b/SewingDresses/SewingDressesDatabaseImplement/SewingDressesDatabaseImplement.csproj @@ -20,8 +20,4 @@ - - - - diff --git a/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs b/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs index b09ca99..6923819 100644 --- a/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs +++ b/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs @@ -10,10 +10,12 @@ namespace SewingDressesFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string DressFileName = "Dress.xml"; private readonly string ClientFileName = "Client.xml"; - public List Components { get; private set; } + private readonly string ImplementFileName = "Implement.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Dresses { get; private set;} public List Clients { get; private set; } + public List Implements { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -42,12 +44,14 @@ namespace SewingDressesFileImplement public void SaveDresses() => SaveData(Dresses, DressFileName, "Dresses", 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 SaveImplements() => SaveData(Implements, ImplementFileName, "Implements", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implements = LoadData(ImplementFileName, "Implement", x => Implement.Create(x)!)!; } } } diff --git a/SewingDresses/SewingDressesFileImplement/Implements/ImplementStorage.cs b/SewingDresses/SewingDressesFileImplement/Implements/ImplementStorage.cs new file mode 100644 index 0000000..b8f084f --- /dev/null +++ b/SewingDresses/SewingDressesFileImplement/Implements/ImplementStorage.cs @@ -0,0 +1,77 @@ +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesFileImplement.Models; + +namespace SewingDressesFileImplement.Implements +{ + public class ImplementStorage : IImplementStorage + { + private readonly DataFileSingleton source; + public ImplementStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implements + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implements + .Where(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO.Contains(model.ImplementFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementViewModel? GetElement(ImplementSearchModel model) + { + return source.Implements + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO == model.ImplementFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + public ImplementViewModel? Insert(ImplementBindingModel model) + { + model.Id = source.Implements.Count > 0 ? source.Implements.Max(x => + x.Id) + 1 : 1; + var newImplement = Implement.Create(model); + if (newImplement == null) + { + return null; + } + source.Implements.Add(newImplement); + source.SaveImplements(); + return newImplement.GetViewModel; + } + public ImplementViewModel? Update(ImplementBindingModel model) + { + var Implement = source.Implements.FirstOrDefault(x => x.Id == model.Id); + if (Implement == null) + { + return null; + } + Implement.Update(model); + source.SaveImplements(); + return Implement.GetViewModel; + } + public ImplementViewModel? Delete(ImplementBindingModel model) + { + var element = source.Implements.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Implements.Remove(element); + source.SaveImplements(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SewingDresses/SewingDressesFileImplement/Models/Implement.cs b/SewingDresses/SewingDressesFileImplement/Models/Implement.cs new file mode 100644 index 0000000..3401290 --- /dev/null +++ b/SewingDresses/SewingDressesFileImplement/Models/Implement.cs @@ -0,0 +1,76 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SewingDressesFileImplement.Models +{ + public class Implement : IImplementModel + { + public int Id { get; set; } + public string ImplementFIO { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } + public int Qualification { get; set; } + public static Implement? Create(ImplementBindingModel? model) + { + if (model == null) return null; + return new Implement + { + Id = model.Id, + ImplementFIO = model.ImplementFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification, + }; + } + public static Implement? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implement() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementFIO = element.Element("ImplementFIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + public XElement GetXElement => new("Implement", + new XAttribute("Id", Id), + new XElement("ImplementFIO", ImplementFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString()) + ); + public ImplementViewModel GetViewModel => new() + { + Id = Id, + ImplementFIO = ImplementFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public void Update(ImplementBindingModel model) + { + if (model == null) + { + return; + } + ImplementFIO = model.ImplementFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + + } +} diff --git a/SewingDresses/SewingDressesFileImplement/Models/Order.cs b/SewingDresses/SewingDressesFileImplement/Models/Order.cs index 08d0a00..1fc4cfd 100644 --- a/SewingDresses/SewingDressesFileImplement/Models/Order.cs +++ b/SewingDresses/SewingDressesFileImplement/Models/Order.cs @@ -11,6 +11,8 @@ namespace SewingDressesFileImplement.Models { public int Id { get; private set; } public int DressId { get; private set; } + public int ClientId { get; private set; } + public int? ImplementId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -27,6 +29,8 @@ namespace SewingDressesFileImplement.Models { Id = model.Id, DressId = model.DressId, + ClientId = model.ClientId, + ImplementId = model.ImplementId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -44,7 +48,9 @@ namespace SewingDressesFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), DressId = Convert.ToInt32(element.Element("DressId")!.Value), - Count = Convert.ToInt32(element.Element("Count")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementId = Convert.ToInt32(element.Element("ImplementId")?.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value, new System.Globalization.CultureInfo("en-US")), Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")?.Value), @@ -64,6 +70,8 @@ namespace SewingDressesFileImplement.Models { Id = Id, DressId = DressId, + ClientId = ClientId, + ImplementId = ImplementId, Count = Count, Sum = Sum, Status = Status, @@ -73,7 +81,9 @@ namespace SewingDressesFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("DressId", DressId), - new XElement("Count", Count), + new XElement("ClientId", ClientId), + new XElement("ImplementId", ImplementId), + new XElement("Count", Count), new XElement("Sum", Sum), new XElement("Status", Status - OrderStatus.Принят), new XElement("DateCreate", DateCreate), diff --git a/SewingDresses/SewingDressesListImplement/DataListSingleton.cs b/SewingDresses/SewingDressesListImplement/DataListSingleton.cs index 5202502..0cec0a4 100644 --- a/SewingDresses/SewingDressesListImplement/DataListSingleton.cs +++ b/SewingDresses/SewingDressesListImplement/DataListSingleton.cs @@ -9,12 +9,14 @@ namespace SewingDressesListImplement public List Orders { get; set; } public List Dresses { get; set; } public List Clients { get; set; } + public List Implements { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Dresses = new List(); Clients = new List(); + Implements = new List(); } public static DataListSingleton GetInstance() { diff --git a/SewingDresses/SewingDressesListImplement/Implements/ImplementStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/ImplementStorage.cs new file mode 100644 index 0000000..c9f7f17 --- /dev/null +++ b/SewingDresses/SewingDressesListImplement/Implements/ImplementStorage.cs @@ -0,0 +1,103 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.ViewModels; +using SewingDressesListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesListImplement.Implements +{ + public class ImplementStorage : IImplementStorage + { + private readonly DataListSingleton _source; + public ImplementStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var Implement in _source.Implements) + { + result.Add(Implement.GetViewModel); + } + return result; + } + public List GetFilteredList(ImplementSearchModel + model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementFIO) && string.IsNullOrEmpty(model.Password)) + { + return result; + } + foreach (var Implement in _source.Implements) + { + if (Implement.ImplementFIO.Contains(model.ImplementFIO)) + { + result.Add(Implement.GetViewModel); + } + } + return result; + } + public ImplementViewModel? GetElement(ImplementSearchModel model) + { + foreach (var Implement in _source.Implements) + { + if ((string.IsNullOrEmpty(model.ImplementFIO) || Implement.ImplementFIO == model.ImplementFIO) && + (!model.Id.HasValue || Implement.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || Implement.Password == model.Password)) + { + return Implement.GetViewModel; + } + } + return null; + } + public ImplementViewModel? Insert(ImplementBindingModel model) + { + model.Id = 1; + foreach (var Implement in _source.Implements) + { + if (model.Id <= Implement.Id) + { + model.Id = Implement.Id + 1; + } + } + var newImplement = Implement.Create(model); + if (newImplement == null) + { + return null; + } + _source.Implements.Add(newImplement); + return newImplement.GetViewModel; + } + public ImplementViewModel? Update(ImplementBindingModel model) + { + foreach (var Implement in _source.Implements) + { + if (model.Id == Implement.Id) + { + Implement.Update(model); + return Implement.GetViewModel; + } + } + return null; + } + public ImplementViewModel? Delete(ImplementBindingModel model) + { + for (int i = 0; i < _source.Implements.Count; ++i) + { + if (_source.Implements[i].Id == model.Id) + { + var element = _source.Implements[i]; + _source.Implements.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/SewingDresses/SewingDressesListImplement/Models/Implement.cs b/SewingDresses/SewingDressesListImplement/Models/Implement.cs new file mode 100644 index 0000000..c5108f2 --- /dev/null +++ b/SewingDresses/SewingDressesListImplement/Models/Implement.cs @@ -0,0 +1,54 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesListImplement.Models +{ + public class Implement : IImplementModel + { + public int Id { get; private set; } + public string ImplementFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public static Implement? Create(ImplementBindingModel model) + { + if (model == null) + { + return null; + } + return new Implement() + { + Id = model.Id, + ImplementFIO = model.ImplementFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementBindingModel model) + { + if (model == null) + { + return; + } + ImplementFIO = model.ImplementFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementViewModel GetViewModel => new() + { + Id = Id, + ImplementFIO = ImplementFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/SewingDresses/SewingDressesListImplement/Models/Order.cs b/SewingDresses/SewingDressesListImplement/Models/Order.cs index 9dc5697..2e468d4 100644 --- a/SewingDresses/SewingDressesListImplement/Models/Order.cs +++ b/SewingDresses/SewingDressesListImplement/Models/Order.cs @@ -9,6 +9,8 @@ namespace SewingDressesListImplement.Models { public int Id { get; private set; } public int DressId { get; private set; } + public int ClientId { get; private set; } + public int? ImplementId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -25,6 +27,8 @@ namespace SewingDressesListImplement.Models { Id = model.Id, DressId = model.DressId, + ClientId = model.ClientId, + ImplementId = model.ImplementId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -46,6 +50,8 @@ namespace SewingDressesListImplement.Models { Id = Id, DressId = DressId, + ClientId = ClientId, + ImplementId = ImplementId, Count = Count, Sum = Sum, Status = Status, diff --git a/SewingDresses/SewingDressesRestApi/Controllers/ImplementController.cs b/SewingDresses/SewingDressesRestApi/Controllers/ImplementController.cs new file mode 100644 index 0000000..4c56153 --- /dev/null +++ b/SewingDresses/SewingDressesRestApi/Controllers/ImplementController.cs @@ -0,0 +1,108 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Enums; + +namespace SewingDressesRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementController : Controller + { + private readonly ILogger _logger; + + private readonly IOrderLogic _order; + + private readonly IImplementLogic _logic; + + public ImplementController(IOrderLogic order, IImplementLogic logic, ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + + [HttpGet] + public ImplementViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementSearchModel + { + ImplementFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + + [HttpGet] + public OrderViewModel? GetImplementOrder(int ImplementId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementId = ImplementId + }); + } + 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/SewingDresses/SewingDressesRestApi/Program.cs b/SewingDresses/SewingDressesRestApi/Program.cs index cd23cd7..f079db5 100644 --- a/SewingDresses/SewingDressesRestApi/Program.cs +++ b/SewingDresses/SewingDressesRestApi/Program.cs @@ -16,6 +16,8 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); builder.Services.AddSwaggerGen(c => diff --git a/SewingDresses/SewingDressesRestApi/SewingDressesRestApi.csproj b/SewingDresses/SewingDressesRestApi/SewingDressesRestApi.csproj index 72e0d8d..dc7127d 100644 --- a/SewingDresses/SewingDressesRestApi/SewingDressesRestApi.csproj +++ b/SewingDresses/SewingDressesRestApi/SewingDressesRestApi.csproj @@ -7,6 +7,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/SewingDresses/SewingDressesView/ImplementForm.Designer.cs b/SewingDresses/SewingDressesView/ImplementForm.Designer.cs new file mode 100644 index 0000000..fcb096e --- /dev/null +++ b/SewingDresses/SewingDressesView/ImplementForm.Designer.cs @@ -0,0 +1,162 @@ +namespace SewingDressesView +{ + partial class ImplementForm + { + /// + /// 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() + { + textBoxFIO = new TextBox(); + label1 = new Label(); + label2 = new Label(); + textBoxPassword = new TextBox(); + label3 = new Label(); + textBoxQual = new TextBox(); + label4 = new Label(); + textBoxExp = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxFIO + // + textBoxFIO.Location = new Point(153, 34); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(125, 27); + textBoxFIO.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(32, 37); + label1.Name = "label1"; + label1.Size = new Size(39, 20); + label1.TabIndex = 1; + label1.Text = "Имя"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(32, 89); + label2.Name = "label2"; + label2.Size = new Size(62, 20); + label2.TabIndex = 3; + label2.Text = "Пароль"; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(153, 86); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(125, 27); + textBoxPassword.TabIndex = 2; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(32, 144); + label3.Name = "label3"; + label3.Size = new Size(111, 20); + label3.TabIndex = 5; + label3.Text = "Квалификация"; + // + // textBoxQual + // + textBoxQual.Location = new Point(153, 141); + textBoxQual.Name = "textBoxQual"; + textBoxQual.Size = new Size(125, 27); + textBoxQual.TabIndex = 4; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(32, 197); + label4.Name = "label4"; + label4.Size = new Size(46, 20); + label4.TabIndex = 7; + label4.Text = "Опыт"; + // + // textBoxExp + // + textBoxExp.Location = new Point(153, 194); + textBoxExp.Name = "textBoxExp"; + textBoxExp.Size = new Size(125, 27); + textBoxExp.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(334, 32); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(334, 84); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // ImplementForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(451, 237); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label4); + Controls.Add(textBoxExp); + Controls.Add(label3); + Controls.Add(textBoxQual); + Controls.Add(label2); + Controls.Add(textBoxPassword); + Controls.Add(label1); + Controls.Add(textBoxFIO); + Name = "ImplementForm"; + Text = "Исполнитель форма"; + Load += ImplementForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxFIO; + private Label label1; + private Label label2; + private TextBox textBoxPassword; + private Label label3; + private TextBox textBoxQual; + private Label label4; + private TextBox textBoxExp; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ImplementForm.cs b/SewingDresses/SewingDressesView/ImplementForm.cs new file mode 100644 index 0000000..6e8e2cd --- /dev/null +++ b/SewingDresses/SewingDressesView/ImplementForm.cs @@ -0,0 +1,111 @@ +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SewingDressesView +{ + public partial class ImplementForm : Form + { + private readonly ILogger _logger; + private readonly IImplementLogic _logic; + private int? _id; + public int ID { set { _id = value; } } + public ImplementForm(ILogger logger, IImplementLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Empty Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Empty Password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxExp.Text)) + { + MessageBox.Show("Empty Experience", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxQual.Text)) + { + MessageBox.Show("Empty Qualification", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Saving Imlement"); + try + { + var model = new ImplementBindingModel + { + Id = _id ?? 0, + Password = textBoxPassword.Text, + ImplementFIO = textBoxFIO.Text, + WorkExperience = Convert.ToInt32(textBoxExp.Text), + Qualification = Convert.ToInt32(textBoxQual.Text) + }; + var result = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!result) + throw new Exception("Error on saving implement"); + MessageBox.Show("Saving success", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error saving implement"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void ImplementForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Init implement"); + var view = _logic.ReadElement(new ImplementSearchModel + { + Id = _id.Value, + }); + if (view != null) + { + textBoxPassword.Text = view.Password; + textBoxFIO.Text = view.ImplementFIO; + textBoxExp.Text = view.WorkExperience.ToString(); + textBoxQual.Text = view.Qualification.ToString(); + } + } + catch(Exception ex) + { + _logger.LogError(ex, "Init implement error"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } + } +} diff --git a/SewingDresses/SewingDressesView/ImplementForm.resx b/SewingDresses/SewingDressesView/ImplementForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SewingDresses/SewingDressesView/ImplementForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ImplementsForm.Designer.cs b/SewingDresses/SewingDressesView/ImplementsForm.Designer.cs new file mode 100644 index 0000000..1ca9b14 --- /dev/null +++ b/SewingDresses/SewingDressesView/ImplementsForm.Designer.cs @@ -0,0 +1,114 @@ +namespace SewingDressesView +{ + partial class ImplementsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonCreate = new Button(); + buttonChange = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(17, 18); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(524, 355); + dataGridView.TabIndex = 0; + // + // buttonCreate + // + buttonCreate.Location = new Point(572, 18); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 1; + buttonCreate.Text = "Создать"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // buttonChange + // + buttonChange.Location = new Point(572, 64); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(94, 29); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(572, 111); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(572, 161); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(94, 29); + buttonUpdate.TabIndex = 4; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // ImplementsForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(678, 383); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "ImplementsForm"; + Text = "Исполнители"; + Load += ImplementsForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonCreate; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + } +} \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ImplementsForm.cs b/SewingDresses/SewingDressesView/ImplementsForm.cs new file mode 100644 index 0000000..2070d6c --- /dev/null +++ b/SewingDresses/SewingDressesView/ImplementsForm.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.BindingModels; +using SewingDressesDatabaseImplement.Models; +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 SewingDressesView +{ + public partial class ImplementsForm : Form + { + private readonly ILogger _logger; + private readonly IImplementLogic _logic; + public ImplementsForm(ILogger logger, IImplementLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + } + _logger.LogInformation("Loading employees"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error loading employees"); + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementForm)); + if (service is ImplementForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ImplementsForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementForm)); + if (service is ImplementForm 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) + { + try + { + _logger.LogInformation("Delete component: {ComponentName}- {Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _logic?.Delete(new ImplementBindingModel{ Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)}); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SewingDresses/SewingDressesView/ImplementsForm.resx b/SewingDresses/SewingDressesView/ImplementsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SewingDresses/SewingDressesView/ImplementsForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/MainForm.Designer.cs b/SewingDresses/SewingDressesView/MainForm.Designer.cs index d2a4e01..692c56a 100644 --- a/SewingDresses/SewingDressesView/MainForm.Designer.cs +++ b/SewingDresses/SewingDressesView/MainForm.Designer.cs @@ -30,19 +30,19 @@ { dataGridView = new DataGridView(); buttonCreate = new Button(); - buttonDoOrder = new Button(); - buttonOrderReady = new Button(); buttonOrderGive = new Button(); buttonOrderUpdate = new Button(); menuStrip1 = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); платьяToolStripMenuItem = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); DressesReportToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); - clientsToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -67,29 +67,9 @@ buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += buttonCreate_Click; // - // buttonDoOrder - // - buttonDoOrder.Location = new Point(854, 130); - buttonDoOrder.Name = "buttonDoOrder"; - buttonDoOrder.Size = new Size(194, 37); - buttonDoOrder.TabIndex = 2; - buttonDoOrder.Text = "Отдать на выполнение"; - buttonDoOrder.UseVisualStyleBackColor = true; - buttonDoOrder.Click += buttonDoOrder_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(854, 205); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(194, 37); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += buttonOrderReady_Click; - // // buttonOrderGive // - buttonOrderGive.Location = new Point(854, 280); + buttonOrderGive.Location = new Point(854, 142); buttonOrderGive.Name = "buttonOrderGive"; buttonOrderGive.Size = new Size(194, 37); buttonOrderGive.TabIndex = 4; @@ -99,7 +79,7 @@ // // buttonOrderUpdate // - buttonOrderUpdate.Location = new Point(854, 357); + buttonOrderUpdate.Location = new Point(854, 219); buttonOrderUpdate.Name = "buttonOrderUpdate"; buttonOrderUpdate.Size = new Size(194, 37); buttonOrderUpdate.TabIndex = 5; @@ -110,7 +90,7 @@ // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); menuStrip1.Location = new Point(0, 0); menuStrip1.Name = "menuStrip1"; menuStrip1.Size = new Size(1096, 28); @@ -119,7 +99,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, clientsToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, clientsToolStripMenuItem, исполнителиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -127,17 +107,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(185, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // платьяToolStripMenuItem // платьяToolStripMenuItem.Name = "платьяToolStripMenuItem"; - платьяToolStripMenuItem.Size = new Size(224, 26); + платьяToolStripMenuItem.Size = new Size(185, 26); платьяToolStripMenuItem.Text = "Платья"; платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click; // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(185, 26); + clientsToolStripMenuItem.Text = "Клиенты"; + clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(185, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += ImplementToolStripMenuItem_Click; + // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { DressesReportToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -166,12 +160,12 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItemReport_Click; // - // clientsToolStripMenuItem + // запускРаботToolStripMenuItem // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(224, 26); - clientsToolStripMenuItem.Text = "Клиенты"; - clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(114, 24); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; // // MainForm // @@ -180,8 +174,6 @@ ClientSize = new Size(1096, 493); Controls.Add(buttonOrderUpdate); Controls.Add(buttonOrderGive); - Controls.Add(buttonOrderReady); - Controls.Add(buttonDoOrder); Controls.Add(buttonCreate); Controls.Add(dataGridView); Controls.Add(menuStrip1); @@ -200,8 +192,6 @@ private DataGridView dataGridView; private Button buttonCreate; - private Button buttonDoOrder; - private Button buttonOrderReady; private Button buttonOrderGive; private Button buttonOrderUpdate; private MenuStrip menuStrip1; @@ -213,5 +203,7 @@ private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 600ab9b..ad966dd 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -11,12 +11,14 @@ namespace SewingDressesView private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public MainForm(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void LoadData() { @@ -28,6 +30,7 @@ namespace SewingDressesView dataGridView.DataSource = list; dataGridView.Columns["DressId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementId"].Visible = false; } _logger.LogInformation("Load orders"); } @@ -65,57 +68,6 @@ namespace SewingDressesView } } - private void buttonDoOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Order №{id}. Change Status on 'In work'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Change Status on 'In work' error"); - 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("Order №{id}. Change status on 'Ready'", - id); - try - { - var operationResult = _orderLogic.FinishOrder(new - OrderBindingModel - { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Change status on 'Ready' error"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - } private void buttonOrderGive_Click(object sender, EventArgs e) { @@ -188,5 +140,21 @@ namespace SewingDressesView form.ShowDialog(); } } + + private void ImplementToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementsForm)); + if (service is ImplementsForm form) + { + form.ShowDialog(); + } + } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementLogic)) as IImplementLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/SewingDresses/SewingDressesView/Program.cs b/SewingDresses/SewingDressesView/Program.cs index 681720c..4352870 100644 --- a/SewingDresses/SewingDressesView/Program.cs +++ b/SewingDresses/SewingDressesView/Program.cs @@ -40,6 +40,9 @@ namespace SewingDressesView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -53,6 +56,8 @@ namespace SewingDressesView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/SewingDressesView.csproj b/SewingDresses/SewingDressesView/SewingDressesView.csproj index b630ad1..18a5a43 100644 --- a/SewingDresses/SewingDressesView/SewingDressesView.csproj +++ b/SewingDresses/SewingDressesView/SewingDressesView.csproj @@ -22,4 +22,10 @@ + + + Always + + + \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/nlog.config b/SewingDresses/SewingDressesView/nlog.config new file mode 100644 index 0000000..0c764ed --- /dev/null +++ b/SewingDresses/SewingDressesView/nlog.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file