From 9f6da595a4cd942b04b33f760262908951c2b0e0 Mon Sep 17 00:00:00 2001 From: Timourka Date: Fri, 19 Apr 2024 22:52:44 +0400 Subject: [PATCH] =?UTF-8?q?laba=206=20=D1=83=D1=80=D0=B0=20=D1=8F=20=D1=81?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=202=20=D0=B0=D0=B1=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B0=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B8=20=D0=BD=D0=B5=20=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=20=D1=87=D1=82=D0=BE=20=D0=BE=D0=BD=D0=B8=20=D0=B1=D1=83=D0=B4?= =?UTF-8?q?=D1=83=D1=82=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BC=20=D0=BD=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D1=82=D1=8C,=20=D0=BF=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=80=D0=B0=D1=81=D0=BD=D0=B0=D1=8F=20=D0=B1=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0,=2095%=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20"=D1=80=D0=B0=D0=B7=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D1=82=D1=8C=20=D1=81=D0=B0=D0=BC=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=8F=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ImplementerLogic.cs | 121 +++++++++ .../BusinessLogics/OrderLogic.cs | 17 ++ .../BindingModels/ImplementerBindingModel.cs | 17 ++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerLogic.cs | 19 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../SearchModels/ImplementerSearchModel.cs | 9 + .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 ++ .../ViewModels/ImplementerViewModel.cs | 22 ++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 10 + .../Models/IOrderModel.cs | 2 + .../AutomobilePlantDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 79 ++++++ .../Implements/OrderStorage.cs | 43 ++- .../20240419183903_MbINeedItLaba6.Designer.cs | 257 ++++++++++++++++++ .../20240419183903_MbINeedItLaba6.cs | 67 +++++ .../AutomobilePlantDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 60 ++++ .../Models/Order.cs | 10 +- .../DataFileSingleton.cs | 4 + .../Implements/ImplementerStorage.cs | 79 ++++++ .../Implements/OrderStorage.cs | 21 +- .../Models/Implementer.cs | 80 ++++++ .../Models/Order.cs | 7 + .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 106 ++++++++ .../Implements/OrderStorage.cs | 32 ++- .../Models/Implementer.cs | 55 ++++ .../Models/Order.cs | 5 + .../FormImplementer.Designer.cs | 169 ++++++++++++ .../AutomobilePlantView/FormImplementer.cs | 101 +++++++ .../AutomobilePlantView/FormImplementer.resx | 120 ++++++++ .../FormImplementers.Designer.cs | 113 ++++++++ .../AutomobilePlantView/FormImplementers.cs | 114 ++++++++ .../AutomobilePlantView/FormImplementers.resx | 120 ++++++++ .../AutomobilePlantView/FormMain.Designer.cs | 57 ++-- .../AutomobilePlantView/FormMain.cs | 22 +- .../AutomobilePlantView/Program.cs | 4 + 40 files changed, 1948 insertions(+), 71 deletions(-) create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/Models/IImplementerModel.cs create mode 100644 AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.cs create mode 100644 AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs create mode 100644 AutomobilePlant/AutomobilePlantFileImplement/Implements/ImplementerStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Implements/ImplementerStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Models/Implementer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormImplementer.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormImplementer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormImplementer.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormImplementers.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormImplementers.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormImplementers.resx diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..b013f78 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,121 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FIO:{FIO}.Id:{ Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.Id:{ Id} ", model?.ImplementerFIO, model?.Id); + var list = (model == null) ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + private void CheckModel(ImplementerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.WorkExperience < 0) + { + throw new ArgumentException("Стаж работы не может быть меньше нуля", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть меньше нуля", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", nameof(model.ImplementerFIO)); + } + _logger.LogInformation("Implementer. Id: {Id}, FIO: {FIO}", model.Id, model.ImplementerFIO); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs index 215cdf4..da22911 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -37,6 +37,23 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics return list; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/ImplementerBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..29fef82 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,17 @@ +using AutomobilePlantDataModels.Models; + +namespace AutomobilePlantContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + + public string ImplementerFIO { get; set; } = string.Empty; + + public string Password { get; set; } = string.Empty; + + public int WorkExperience { get; set; } + + public int Qualification { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs index 505eb51..2819d77 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs @@ -13,6 +13,7 @@ namespace AutomobilePlantContracts.BindingModels public int Id { get; set; } public int CarId { get; set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..f42e8bd --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,19 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + + bool Create(ImplementerBindingModel model); + + bool Update(ImplementerBindingModel model); + + bool Delete(ImplementerBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs index b2d87f2..1d4c459 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace AutomobilePlantContracts.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/AutomobilePlant/AutomobilePlantContracts/SearchModels/ImplementerSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..0756244 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,9 @@ +namespace AutomobilePlantContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs index 7852946..89beb5d 100644 --- a/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using AutomobilePlantDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace AutomobilePlantContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IImplementerStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..5e87694 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + + List GetFilteredList(ImplementerSearchModel model); + + ImplementerViewModel? GetElement(ImplementerSearchModel model); + + ImplementerViewModel? Insert(ImplementerBindingModel model); + + ImplementerViewModel? Update(ImplementerBindingModel model); + + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..238ea6b --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,22 @@ +using AutomobilePlantDataModels.Models; +using System.ComponentModel; + +namespace AutomobilePlantContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + + [DisplayName("FIO")] + public string ImplementerFIO { get; set; } = string.Empty; + + [DisplayName("Password")] + public string Password { get; set; } = string.Empty; + + [DisplayName("Work expirience")] + public int WorkExperience { get; set; } + + [DisplayName("Qualification")] + public int Qualification { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs index 96c7753..9f86e8c 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs @@ -19,6 +19,9 @@ namespace AutomobilePlantContracts.ViewModels public int ClientId { get; set; } [DisplayName("Client's FIO")] public string ClientFIO { get; set; } = string.Empty; + public int? ImplementerId { get; set; } + [DisplayName("Implementer's FIO")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Count")] public int Count { get; set; } [DisplayName("Sum")] diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IImplementerModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..ab1891a --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IImplementerModel.cs @@ -0,0 +1,10 @@ +namespace AutomobilePlantDataModels.Models +{ + public interface IImplementerModel : IId + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs index ee46a2c..191dbf4 100644 --- a/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs @@ -10,6 +10,8 @@ namespace AutomobilePlantDataModels.Models public interface IOrderModel : IId { int CarId { get; } + int ClientId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabase.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabase.cs index caa668a..0ee34d3 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabase.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/AutomobilePlantDatabase.cs @@ -18,5 +18,6 @@ namespace AutomobilePlantDatabaseImplement public virtual DbSet CarComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/ImplementerStorage.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..31aae12 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,79 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDatabaseImplement.Models; + +namespace AutomobilePlantDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + using var context = new AutomobilePlantDatabase(); + if (model.Id.HasValue) return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + if (model.ImplementerFIO != null) return context.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + using var context = new AutomobilePlantDatabase(); + return context.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new AutomobilePlantDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new AutomobilePlantDatabase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new AutomobilePlantDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new AutomobilePlantDatabase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs index 9a00333..5dab5fc 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Implements/OrderStorage.cs @@ -21,20 +21,33 @@ namespace AutomobilePlantDatabaseImplement.Implements return null; } using var context = new AutomobilePlantDatabase(); - return context.Orders.Include(x => x.Car).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders + .Include(x => x.Car) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => + (model.Status == null || model.Status != null && model.Status.Equals(x.Status)) && + (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId) || + (model.Id.HasValue && x.Id == model.Id))? + .GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null) { return new(); } using var context = new AutomobilePlantDatabase(); return context.Orders - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId) + .Where(x => + x.Id == model.Id || + model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || + x.ClientId == model.ClientId || + model.Status.Equals(x.Status)) .Include(x => x.Car) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -42,7 +55,11 @@ namespace AutomobilePlantDatabaseImplement.Implements public List GetFullList() { using var context = new AutomobilePlantDatabase(); - return context.Orders.Include(x => x.Car).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); + return context.Orders + .Include(x => x.Car) + .Include(x => x.Client) + .Include(x => x.Implementer) + .Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -55,7 +72,11 @@ namespace AutomobilePlantDatabaseImplement.Implements using var context = new AutomobilePlantDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Car).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders + .Include(x => x.Car) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -68,12 +89,20 @@ namespace AutomobilePlantDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Car).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders + .Include(x => x.Car) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { using var context = new AutomobilePlantDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders + .Include(x => x.Car) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.Designer.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.Designer.cs new file mode 100644 index 0000000..897546e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using AutomobilePlantDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AutomobilePlantDatabaseImplement.Migrations +{ + [DbContext(typeof(AutomobilePlantDatabase))] + [Migration("20240419183903_MbINeedItLaba6")] + partial class MbINeedItLaba6 + { + /// + 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("AutomobilePlantDatabaseImplement.Models.Car", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Cars"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.CarComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CarComponents"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.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("AutomobilePlantDatabaseImplement.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("AutomobilePlantDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CarId") + .HasColumnType("int"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("CarId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.CarComponent", b => + { + b.HasOne("AutomobilePlantDatabaseImplement.Models.Car", "Car") + .WithMany("Components") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutomobilePlantDatabaseImplement.Models.Component", "Component") + .WithMany("CarComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Car"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Order", b => + { + b.HasOne("AutomobilePlantDatabaseImplement.Models.Car", "Car") + .WithMany("Orders") + .HasForeignKey("CarId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutomobilePlantDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AutomobilePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.Navigation("Car"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Car", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Component", b => + { + b.Navigation("CarComponents"); + }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.cs new file mode 100644 index 0000000..64adadc --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/20240419183903_MbINeedItLaba6.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AutomobilePlantDatabaseImplement.Migrations +{ + /// + public partial class MbINeedItLaba6 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/AutomobilePlantDatabaseModelSnapshot.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/AutomobilePlantDatabaseModelSnapshot.cs index e251e82..234f032 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/AutomobilePlantDatabaseModelSnapshot.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Migrations/AutomobilePlantDatabaseModelSnapshot.cs @@ -113,6 +113,33 @@ namespace AutomobilePlantDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace AutomobilePlantDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("Status") .HasColumnType("int"); @@ -148,6 +178,8 @@ namespace AutomobilePlantDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -184,9 +216,15 @@ namespace AutomobilePlantDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("AutomobilePlantDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.Navigation("Car"); b.Navigation("Client"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Car", b => @@ -205,6 +243,11 @@ namespace AutomobilePlantDatabaseImplement.Migrations { b.Navigation("CarComponents"); }); + + modelBuilder.Entity("AutomobilePlantDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); #pragma warning restore 612, 618 } } diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..4094b75 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AutomobilePlantDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + [ForeignKey("ImplementerId")] + public virtual List Orders { get; private set; } = new(); + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + WorkExperience = WorkExperience, + }; + } +} diff --git a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs index 737d005..4ce3118 100644 --- a/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantDatabaseImplement/Models/Order.cs @@ -19,6 +19,7 @@ namespace AutomobilePlantDatabaseImplement.Models public int CarId { get; private set; } [Required] public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } [Required] public int Count { get; private set; } [Required] @@ -31,6 +32,7 @@ namespace AutomobilePlantDatabaseImplement.Models public DateTime? DateImplement { get; private set; } public virtual Car Car { get; private set; } public virtual Client Client { get; set; } + public Implementer? Implementer { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -42,6 +44,7 @@ namespace AutomobilePlantDatabaseImplement.Models { CarId = model.CarId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -59,6 +62,7 @@ namespace AutomobilePlantDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -66,13 +70,15 @@ namespace AutomobilePlantDatabaseImplement.Models Id = Id, CarId = CarId, ClientId = ClientId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, DateCreate = DateCreate, DateImplement = DateImplement, Status = Status, - CarName = Car.CarName, - ClientFIO = Client.ClientFIO + CarName = Car.CarName ?? string.Empty, + ClientFIO = Client.ClientFIO ?? string.Empty, + ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty, }; } } diff --git a/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs b/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs index 1738149..bdf8668 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/DataFileSingleton.cs @@ -15,10 +15,12 @@ namespace AutomobilePlantFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string CarFileName = "Car.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Cars { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -31,12 +33,14 @@ namespace AutomobilePlantFileImplement public void SaveCars() => SaveData(Cars, CarFileName, "Cars", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Orders, ImplementerFileName, "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Cars = LoadData(CarFileName, "Car", x => Car.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Impleneter", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Implements/ImplementerStorage.cs b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..adc066d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,79 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantFileImplement.Models; + +namespace AutomobilePlantFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton _source; + public ImplementerStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (model.Id.HasValue) return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel; + if (model.ImplementerFIO != null) return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel; + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.ImplementerFIO != null) + { + return _source.Implementers + .Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1; + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Implementers.Remove(res); + _source.SaveImplementers(); + } + return res?.GetViewModel; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantFileImplement/Implements/OrderStorage.cs index 6553f8b..e41d463 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Implements/OrderStorage.cs @@ -1,13 +1,8 @@ -using System; -using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.SearchModels; using AutomobilePlantContracts.StoragesContracts; using AutomobilePlantContracts.ViewModels; using AutomobilePlantFileImplement.Models; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace AutomobilePlantFileImplement.Implements { @@ -26,18 +21,24 @@ namespace AutomobilePlantFileImplement.Implements { return null; } - return GetViewModel(source.Orders - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); + + if (model.ImplementerId.HasValue && model.Status != null) + return source.Orders.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && model.Status.Equals(x.Status))?.GetViewModel; + + return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && model.Status == null) { return new(); } return source.Orders - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId) + .Where(x => x.Id == model.Id || + model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || + x.ClientId == model.ClientId || + model.Status.Equals(x.Status)) .Select(x => GetViewModel(x)) .ToList(); } diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..9170a3a --- /dev/null +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Implementer.cs @@ -0,0 +1,80 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System.Xml.Linq; + +namespace AutomobilePlantFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + Qualification = model.Qualification, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + Qualification = model.Qualification; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + }; + + public XElement GetXElement => new("Client", + new XAttribute("Id", Id), + new XElement("FIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs index 1afa8f1..c9f24c0 100644 --- a/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantFileImplement/Models/Order.cs @@ -16,6 +16,7 @@ namespace AutomobilePlantFileImplement.Models public int Id { get; private set; } public int CarId { get; private set; } public int ClientId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -33,6 +34,7 @@ namespace AutomobilePlantFileImplement.Models Id = model.Id, CarId = model.CarId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,6 +54,7 @@ namespace AutomobilePlantFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), CarId = Convert.ToInt32(element.Element("CarId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -68,6 +71,7 @@ namespace AutomobilePlantFileImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() @@ -75,6 +79,8 @@ namespace AutomobilePlantFileImplement.Models Id = Id, CarId = CarId, ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataFileSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, DateCreate = DateCreate, @@ -87,6 +93,7 @@ namespace AutomobilePlantFileImplement.Models new XAttribute("Id", Id), new XElement("CarId", CarId.ToString()), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs b/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs index 2e1bc2c..70e9927 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace AutomobilePlantListImplement public List Orders { get; set; } public List Cars { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Cars = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/ImplementerStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..3ddfc8b --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,106 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantListImplement.Models; + +namespace AutomobilePlantListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password)) + return x.GetViewModel; + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + List list = new(); + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + list.Add(implementer.GetViewModel); + } + } + } + return list; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs index 3318865..7e6354b 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs @@ -49,6 +49,26 @@ namespace AutomobilePlantListImplement.Implements } } } + if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (model.Status.Equals(order.Status)) + { + result.Add(GetViewModel(order)); + } + } + } return result; } public OrderViewModel? GetElement(OrderSearchModel model) @@ -59,9 +79,15 @@ namespace AutomobilePlantListImplement.Implements } foreach (var order in _source.Orders) { - if ( - (model.Id.HasValue && order.Id == model.Id) - ) + if (model.Id.HasValue && order.Id == model.Id) + { + return GetViewModel(order); + } + else if (model.ImplementerId.HasValue && model.Status != null && order.ImplementerId == model.ImplementerId && model.Status.Equals(order.Status)) + { + return GetViewModel(order); + } + else if (model.ImplementerId.HasValue && model.ImplementerId == order.ImplementerId) { return order.GetViewModel; } diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Implementer.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Implementer.cs new file mode 100644 index 0000000..1f7b5b3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Implementer.cs @@ -0,0 +1,55 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; + +namespace AutomobilePlantListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs index 396dba6..ff5b561 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace AutomobilePlantListImplement.Models { public int CarId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } @@ -38,6 +39,7 @@ namespace AutomobilePlantListImplement.Models Id = model.Id, CarId = model.CarId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -54,12 +56,15 @@ namespace AutomobilePlantListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { CarId = CarId, ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, DateCreate = DateCreate, diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementer.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormImplementer.Designer.cs new file mode 100644 index 0000000..11b6c26 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormImplementer.Designer.cs @@ -0,0 +1,169 @@ +namespace AutomobilePlantView +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxFIO = new TextBox(); + labelFIO = new Label(); + textBoxPassword = new TextBox(); + numericUpDownQualification = new NumericUpDown(); + numericUpDownWorkExpirience = new NumericUpDown(); + labelPassword = new Label(); + labelQualification = new Label(); + labelExpirience = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExpirience).BeginInit(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(343, 125); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(262, 125); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 10; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(96, 9); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(322, 23); + textBoxFIO.TabIndex = 8; + // + // labelFIO + // + labelFIO.AutoSize = true; + labelFIO.Location = new Point(12, 12); + labelFIO.Name = "labelFIO"; + labelFIO.Size = new Size(42, 15); + labelFIO.TabIndex = 6; + labelFIO.Text = "Name:"; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(96, 38); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(322, 23); + textBoxPassword.TabIndex = 12; + // + // numericUpDownQualification + // + numericUpDownQualification.Location = new Point(96, 67); + numericUpDownQualification.Name = "numericUpDownQualification"; + numericUpDownQualification.Size = new Size(322, 23); + numericUpDownQualification.TabIndex = 13; + // + // numericUpDownWorkExpirience + // + numericUpDownWorkExpirience.Location = new Point(96, 96); + numericUpDownWorkExpirience.Name = "numericUpDownWorkExpirience"; + numericUpDownWorkExpirience.Size = new Size(322, 23); + numericUpDownWorkExpirience.TabIndex = 14; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(12, 41); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(60, 15); + labelPassword.TabIndex = 15; + labelPassword.Text = "Password:"; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(12, 69); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(78, 15); + labelQualification.TabIndex = 16; + labelQualification.Text = "Qualification:"; + labelQualification.TextAlign = ContentAlignment.TopRight; + // + // labelExpirience + // + labelExpirience.AutoSize = true; + labelExpirience.Location = new Point(12, 98); + labelExpirience.Name = "labelExpirience"; + labelExpirience.Size = new Size(64, 15); + labelExpirience.TabIndex = 17; + labelExpirience.Text = "Expirience:"; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(425, 156); + Controls.Add(labelExpirience); + Controls.Add(labelQualification); + Controls.Add(labelPassword); + Controls.Add(numericUpDownWorkExpirience); + Controls.Add(numericUpDownQualification); + Controls.Add(textBoxPassword); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFIO); + Controls.Add(labelFIO); + Name = "FormImplementer"; + Text = "Implementer"; + Load += FormImplementer_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownQualification).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkExpirience).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxCost; + private TextBox textBoxFIO; + private Label labelCost; + private Label labelFIO; + private TextBox textBoxPassword; + private NumericUpDown numericUpDownQualification; + private NumericUpDown numericUpDownWorkExpirience; + private Label labelPassword; + private Label labelQualification; + private Label labelExpirience; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementer.cs b/AutomobilePlant/AutomobilePlantView/FormImplementer.cs new file mode 100644 index 0000000..99917b3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormImplementer.cs @@ -0,0 +1,101 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlantView +{ + public partial class FormImplementer : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormImplementer(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormImplementer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение информации исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFIO.Text = view.ImplementerFIO; + textBoxPassword.Text = view.Password; + numericUpDownQualification.Value = view.Qualification; + numericUpDownWorkExpirience.Value = view.WorkExperience; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + Qualification = (int)numericUpDownQualification.Value, + WorkExperience = (int)numericUpDownWorkExpirience.Value, + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementer.resx b/AutomobilePlant/AutomobilePlantView/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementers.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormImplementers.Designer.cs new file mode 100644 index 0000000..9702d7e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormImplementers.Designer.cs @@ -0,0 +1,113 @@ +namespace AutomobilePlantView +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(678, 105); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(116, 23); + buttonRefresh.TabIndex = 9; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(678, 76); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(116, 23); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(678, 47); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(116, 23); + buttonUpdate.TabIndex = 7; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(678, 18); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(116, 23); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonCreate_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(6, 6); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(666, 438); + dataGridView.TabIndex = 5; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormImplementers"; + Text = "Implementers"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementers.cs b/AutomobilePlant/AutomobilePlantView/FormImplementers.cs new file mode 100644 index 0000000..d0820bd --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormImplementers.cs @@ -0,0 +1,114 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AutomobilePlantView +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public FormImplementers(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormImplementers_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка исполнителей"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementer)); + if (service is FormImplementer form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление исполнителя"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormImplementers.resx b/AutomobilePlant/AutomobilePlantView/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs index b6778c0..b21572c 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -32,17 +32,16 @@ toolStripMenuItemCatalogs = new ToolStripMenuItem(); toolStripMenuItemComponents = new ToolStripMenuItem(); toolStripMenuItemCars = new ToolStripMenuItem(); + clientsToolStripMenuItem = new ToolStripMenuItem(); reportsToolStripMenuItem = new ToolStripMenuItem(); carsListToolStripMenuItem = new ToolStripMenuItem(); componentsByCarsToolStripMenuItem = new ToolStripMenuItem(); ordersListToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRefresh = new Button(); - clientsToolStripMenuItem = new ToolStripMenuItem(); + implementersToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -58,7 +57,7 @@ // // toolStripMenuItemCatalogs // - toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, clientsToolStripMenuItem }); + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars, clientsToolStripMenuItem, implementersToolStripMenuItem }); toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; toolStripMenuItemCatalogs.Size = new Size(65, 20); toolStripMenuItemCatalogs.Text = "Catalogs"; @@ -66,17 +65,24 @@ // toolStripMenuItemComponents // toolStripMenuItemComponents.Name = "toolStripMenuItemComponents"; - toolStripMenuItemComponents.Size = new Size(180, 22); + toolStripMenuItemComponents.Size = new Size(143, 22); toolStripMenuItemComponents.Text = "Components"; toolStripMenuItemComponents.Click += ComponentsToolStripMenuItem_Click; // // toolStripMenuItemCars // toolStripMenuItemCars.Name = "toolStripMenuItemCars"; - toolStripMenuItemCars.Size = new Size(180, 22); + toolStripMenuItemCars.Size = new Size(143, 22); toolStripMenuItemCars.Text = "Cars"; toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; // + // clientsToolStripMenuItem + // + clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; + clientsToolStripMenuItem.Size = new Size(143, 22); + clientsToolStripMenuItem.Text = "Clients"; + clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; + // // reportsToolStripMenuItem // reportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carsListToolStripMenuItem, componentsByCarsToolStripMenuItem, ordersListToolStripMenuItem }); @@ -124,29 +130,9 @@ buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += ButtonCreateOrder_Click; // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(677, 56); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(111, 23); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Take order in work"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(677, 85); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(111, 23); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Order is ready"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(677, 114); + buttonIssuedOrder.Location = new Point(677, 56); buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Size = new Size(111, 23); buttonIssuedOrder.TabIndex = 5; @@ -156,7 +142,7 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(677, 143); + buttonRefresh.Location = new Point(677, 85); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(111, 23); buttonRefresh.TabIndex = 6; @@ -164,12 +150,12 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRef_Click; // - // clientsToolStripMenuItem + // implementersToolStripMenuItem // - clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; - clientsToolStripMenuItem.Size = new Size(180, 22); - clientsToolStripMenuItem.Text = "Clients"; - clientsToolStripMenuItem.Click += clientsToolStripMenuItem_Click; + implementersToolStripMenuItem.Name = "implementersToolStripMenuItem"; + implementersToolStripMenuItem.Size = new Size(180, 22); + implementersToolStripMenuItem.Text = "Implementers"; + implementersToolStripMenuItem.Click += implementersToolStripMenuItem_Click; // // FormMain // @@ -178,8 +164,6 @@ ClientSize = new Size(800, 450); Controls.Add(buttonRefresh); Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(dataGridView); Controls.Add(menuStrip1); @@ -201,8 +185,6 @@ private ToolStripMenuItem toolStripMenuItemCars; private DataGridView dataGridView; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRefresh; private ToolStripMenuItem reportsToolStripMenuItem; @@ -210,5 +192,6 @@ private ToolStripMenuItem componentsByCarsToolStripMenuItem; private ToolStripMenuItem ordersListToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem; + private ToolStripMenuItem implementersToolStripMenuItem; } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs index 01d0850..b4e1a73 100644 --- a/AutomobilePlant/AutomobilePlantView/FormMain.cs +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -1,17 +1,7 @@ -using AutomobilePlantBusinessLogic.BusinessLogics; -using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BindingModels; using AutomobilePlantContracts.BusinessLogicsContracts; using AutomobilePlantDataModels.Enums; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace AutomobilePlantView { @@ -42,6 +32,7 @@ namespace AutomobilePlantView dataGridView.DataSource = list; dataGridView.Columns["CarId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); @@ -78,6 +69,15 @@ namespace AutomobilePlantView } } + private void implementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } + private void carsListToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; diff --git a/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index df8f743..0ddc955 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -39,11 +39,13 @@ namespace AutomobilePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -57,6 +59,8 @@ namespace AutomobilePlantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file