From 806c01dafd99dd4c35f7ced7333b862046fd6110 Mon Sep 17 00:00:00 2001 From: Timourka Date: Sun, 11 Feb 2024 16:43:19 +0400 Subject: [PATCH 1/4] half work --- AutomobilePlant/AutomobilePlant.sln | 24 ++++ .../AutomobilePlantBusinessLogic.csproj | 17 +++ .../BusinessLogics/CarLogic.cs | 120 +++++++++++++++++ .../BusinessLogics/ComponentLogic.cs | 113 ++++++++++++++++ .../BusinessLogics/OrderLogic.cs | 124 ++++++++++++++++++ .../AutomobilePlantContracts.csproj | 13 ++ .../BindingModels/CarBindingModel.cs | 22 ++++ .../BindingModels/ComponentBindingModel.cs | 16 +++ .../BindingModels/OrderBindingModel.cs | 21 +++ .../BusinessLogicsContracts/ICarLogic.cs | 20 +++ .../IComponentLogic.cs | 20 +++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 +++ .../SearchModels/CarSearchModel.cs | 14 ++ .../SearchModels/ComponentSearchModel.cs | 15 +++ .../SearchModels/OrderSearchModel.cs | 13 ++ .../StoragesContracts/ICarStorage.cs | 21 +++ .../StoragesContracts/IComponentStorage.cs | 21 +++ .../StoragesContracts/IOrderStorage.cs | 22 ++++ .../ViewModels/CarViewModel.cs | 25 ++++ .../ViewModels/ComponentViewModel.cs | 19 +++ .../ViewModels/OrderViewModel.cs | 30 +++++ .../AutomobilePlantDataModels.csproj | 9 ++ .../Enums/OrderStatus.cs | 17 +++ .../AutomobilePlantDataModels/IId.cs | 13 ++ .../Models/ICarModel.cs | 15 +++ .../Models/IComponentModel.cs | 14 ++ .../Models/IOrderModel.cs | 19 +++ .../AutomobilePlantListImplement.csproj | 14 ++ .../DataListSingleton.cs | 31 +++++ .../Implements/CarStorage.cs | 110 ++++++++++++++++ .../Implements/ComponentStorage.cs | 109 +++++++++++++++ .../Implements/OrderStorage.cs | 107 +++++++++++++++ .../Models/Car.cs | 57 ++++++++ .../Models/Component.cs | 46 +++++++ .../Models/Order.cs | 73 +++++++++++ 35 files changed, 1344 insertions(+) create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj create mode 100644 AutomobilePlant/AutomobilePlantContracts/BindingModels/CarBindingModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/ICarLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/SearchModels/CarSearchModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/StoragesContracts/ICarStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IComponentStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IOrderStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs create mode 100644 AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj create mode 100644 AutomobilePlant/AutomobilePlantDataModels/Enums/OrderStatus.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/IId.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/Models/ICarModel.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/Models/IComponentModel.cs create mode 100644 AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj create mode 100644 AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Implements/CarStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Implements/ComponentStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Models/Car.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Models/Component.cs create mode 100644 AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs diff --git a/AutomobilePlant/AutomobilePlant.sln b/AutomobilePlant/AutomobilePlant.sln index d631254..b1eee1b 100644 --- a/AutomobilePlant/AutomobilePlant.sln +++ b/AutomobilePlant/AutomobilePlant.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.8.34309.116 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantView", "AutomobilePlantView\AutomobilePlantView.csproj", "{090C8696-D089-4462-8EE9-0C8A0CA5BD3B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantDataModels", "AutomobilePlantDataModels\AutomobilePlantDataModels.csproj", "{1E106BB0-3F72-4FB5-AF34-D8823FA89AEE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantContracts", "AutomobilePlantContracts\AutomobilePlantContracts.csproj", "{6EE45F8D-8373-446F-9269-4CB68CD4B27B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantBusinessLogic", "AutomobilePlantBusinessLogic\AutomobilePlantBusinessLogic.csproj", "{A435700B-34D0-4E80-9C8C-EA6848EBE806}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutomobilePlantListImplement", "AutomobilePlantListImplement\AutomobilePlantListImplement.csproj", "{930FF252-E97A-4634-A772-E07684AA6091}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {090C8696-D089-4462-8EE9-0C8A0CA5BD3B}.Debug|Any CPU.Build.0 = Debug|Any CPU {090C8696-D089-4462-8EE9-0C8A0CA5BD3B}.Release|Any CPU.ActiveCfg = Release|Any CPU {090C8696-D089-4462-8EE9-0C8A0CA5BD3B}.Release|Any CPU.Build.0 = Release|Any CPU + {1E106BB0-3F72-4FB5-AF34-D8823FA89AEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E106BB0-3F72-4FB5-AF34-D8823FA89AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E106BB0-3F72-4FB5-AF34-D8823FA89AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E106BB0-3F72-4FB5-AF34-D8823FA89AEE}.Release|Any CPU.Build.0 = Release|Any CPU + {6EE45F8D-8373-446F-9269-4CB68CD4B27B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6EE45F8D-8373-446F-9269-4CB68CD4B27B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6EE45F8D-8373-446F-9269-4CB68CD4B27B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6EE45F8D-8373-446F-9269-4CB68CD4B27B}.Release|Any CPU.Build.0 = Release|Any CPU + {A435700B-34D0-4E80-9C8C-EA6848EBE806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A435700B-34D0-4E80-9C8C-EA6848EBE806}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A435700B-34D0-4E80-9C8C-EA6848EBE806}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A435700B-34D0-4E80-9C8C-EA6848EBE806}.Release|Any CPU.Build.0 = Release|Any CPU + {930FF252-E97A-4634-A772-E07684AA6091}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {930FF252-E97A-4634-A772-E07684AA6091}.Debug|Any CPU.Build.0 = Debug|Any CPU + {930FF252-E97A-4634-A772-E07684AA6091}.Release|Any CPU.ActiveCfg = Release|Any CPU + {930FF252-E97A-4634-A772-E07684AA6091}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj b/AutomobilePlant/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj new file mode 100644 index 0000000..dae74de --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/AutomobilePlantBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs new file mode 100644 index 0000000..0832d67 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/CarLogic.cs @@ -0,0 +1,120 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class CarLogic : ICarLogic + { + private readonly ILogger _logger; + + private readonly ICarStorage _carStorage; + + public CarLogic(ILogger logger, ICarStorage carStorage) + { + _logger = logger; + _carStorage = carStorage; + } + + public List? ReadList(CarSearchModel? model) + { + _logger.LogInformation("ReadList. CarName:{CarName}. Id:{Id}", model?.CarName, model?.Id); + var list = model == null ? _carStorage.GetFullList() : _carStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public CarViewModel? ReadElement(CarSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. CarName:{CarName}. Id:{Id}", model.CarName, model.Id); + var element = _carStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(CarBindingModel model) + { + CheckModel(model); + if (_carStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(CarBindingModel model) + { + CheckModel(model); + if (_carStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(CarBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_carStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(CarBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CarName)) + { + throw new ArgumentNullException("Нет названия машины", nameof(model.CarName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена машины должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Car. CarName:{CarName}. Price:{Price}. Id:{Id}", model.CarName, model.Price, model.Id); + var element = _carStorage.GetElement(new CarSearchModel + { + CarName = model.CarName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Машина с таким названием уже есть"); + } + } + } +} diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..c259f98 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,113 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{ Cost}. Id: { Id} ", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } + +} diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..215cdf4 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,124 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) return false; + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool ChangeStatus(OrderBindingModel model, OrderStatus status) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + OrderStatus oldStatus = model.Status; + model.Status = status; + if (model.Status == OrderStatus.Выдан) + model.DateImplement = DateTime.Now; + if (_orderStorage.Update(model) == null) + { + model.Status = oldStatus; + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.CarId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор машин", nameof(model.CarId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество машин в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count)); + } + _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj b/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj new file mode 100644 index 0000000..743e9bf --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/AutomobilePlantContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/CarBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/CarBindingModel.cs new file mode 100644 index 0000000..fbcc1f6 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/CarBindingModel.cs @@ -0,0 +1,22 @@ +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BindingModels +{ + public class CarBindingModel : ICarModel + { + public int Id { get; set; } + public string CarName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary CarComponents + { + get; + set; + } = new(); + } + +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..027d13c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..a0e90ae --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int CarId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/ICarLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/ICarLogic.cs new file mode 100644 index 0000000..64c83da --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/ICarLogic.cs @@ -0,0 +1,20 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface ICarLogic + { + List? ReadList(CarSearchModel? model); + CarViewModel? ReadElement(CarSearchModel model); + bool Create(CarBindingModel model); + bool Update(CarBindingModel model); + bool Delete(CarBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IComponentLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..83d30f5 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..b2d87f2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/SearchModels/CarSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/CarSearchModel.cs new file mode 100644 index 0000000..8994576 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/CarSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.SearchModels +{ + public class CarSearchModel + { + public int? Id { get; set; } + public string? CarName { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..dc2354b --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } + +} diff --git a/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs b/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..afbc5f1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/ICarStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/ICarStorage.cs new file mode 100644 index 0000000..5d80368 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/ICarStorage.cs @@ -0,0 +1,21 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface ICarStorage + { + List GetFullList(); + List GetFilteredList(CarSearchModel model); + CarViewModel? GetElement(CarSearchModel model); + CarViewModel? Insert(CarBindingModel model); + CarViewModel? Update(CarBindingModel model); + CarViewModel? Delete(CarBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IComponentStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..0a75e37 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IOrderStorage.cs b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..609219d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,22 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } + +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs new file mode 100644 index 0000000..8b947f3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs @@ -0,0 +1,25 @@ +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.ViewModels +{ + public class CarViewModel : ICarModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string CarName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary CarComponents + { + get; + set; + } = new(); + } + +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..92d581d --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..06dcbe1 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,30 @@ +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantContracts.ViewModels +{ + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int CarId { get; set; } + [DisplayName("Изделие")] + public string CarName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj b/AutomobilePlant/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/AutomobilePlantDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/AutomobilePlant/AutomobilePlantDataModels/Enums/OrderStatus.cs b/AutomobilePlant/AutomobilePlantDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..b257d0e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/Enums/OrderStatus.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/IId.cs b/AutomobilePlant/AutomobilePlantDataModels/IId.cs new file mode 100644 index 0000000..1dd266c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/ICarModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/ICarModel.cs new file mode 100644 index 0000000..53e8864 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/ICarModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataModels.Models +{ + public interface ICarModel : IId + { + string CarName { get; } + double Price { get; } + Dictionary CarComponents { get; } + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IComponentModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..65039ce --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..ee46a2c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs @@ -0,0 +1,19 @@ +using AutomobilePlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantDataModels.Models +{ + public interface IOrderModel : IId + { + int CarId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj b/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj new file mode 100644 index 0000000..a6820c2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/AutomobilePlantListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs b/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs new file mode 100644 index 0000000..2406e38 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Cars { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Cars = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/CarStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/CarStorage.cs new file mode 100644 index 0000000..e54edd5 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/CarStorage.cs @@ -0,0 +1,110 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class CarStorage : ICarStorage + { + private readonly DataListSingleton _source; + + public CarStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var car in _source.Cars) + { + result.Add(car.GetViewModel); + } + return result; + } + + public List GetFilteredList(CarSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.CarName)) + { + return result; + } + foreach (var car in _source.Cars) + { + if (car.CarName.Contains(model.CarName)) + { + result.Add(car.GetViewModel); + } + } + return result; + } + public CarViewModel? GetElement(CarSearchModel model) + { + if (string.IsNullOrEmpty(model.CarName) && !model.Id.HasValue) + { + return null; + } + foreach (var car in _source.Cars) + { + if ((!string.IsNullOrEmpty(model.CarName) && car.CarName == model.CarName) || (model.Id.HasValue && car.Id == model.Id)) + { + return car.GetViewModel; + } + } + return null; + } + + public CarViewModel? Insert(CarBindingModel model) + { + model.Id = 1; + foreach (var car in _source.Cars) + { + if (model.Id <= car.Id) + { + model.Id = car.Id + 1; + } + } + var newCar = Car.Create(model); + if (newCar == null) + { + return null; + } + _source.Cars.Add(newCar); + return newCar.GetViewModel; + } + + public CarViewModel? Update(CarBindingModel model) + { + foreach (var car in _source.Cars) + { + if (car.Id == model.Id) + { + car.Update(model); + return car.GetViewModel; + } + } + return null; + } + public CarViewModel? Delete(CarBindingModel model) + { + for (int i = 0; i < _source.Cars.Count; ++i) + { + if (_source.Cars[i].Id == model.Id) + { + var element = _source.Cars[i]; + _source.Cars.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/ComponentStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e30f589 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,109 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ( + (!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id) + ) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d7091fc --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs @@ -0,0 +1,107 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(order.GetViewModel); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if ( + (model.Id.HasValue && order.Id == model.Id) + ) + { + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return order.GetViewModel; + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Car.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Car.cs new file mode 100644 index 0000000..2f26083 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Car.cs @@ -0,0 +1,57 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Car : ICarModel + { + public int Id { get; private set; } + + public string CarName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary CarComponents { get; private set; } = new Dictionary(); + + public static Car? Create(CarBindingModel? model) + { + if (model == null) + { + return null; + } + return new Car() + { + Id = model.Id, + CarName = model.CarName, + Price = model.Price, + CarComponents = model.CarComponents + }; + } + + public void Update(CarBindingModel? model) + { + if (model == null) + { + return; + } + CarName = model.CarName; + Price = model.Price; + CarComponents = model.CarComponents; + } + + public CarViewModel GetViewModel => new() + { + Id = Id, + CarName = CarName, + Price = Price, + CarComponents = CarComponents + }; + } + +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Component.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Component.cs new file mode 100644 index 0000000..924aae2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Component.cs @@ -0,0 +1,46 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs new file mode 100644 index 0000000..6250a8e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs @@ -0,0 +1,73 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Enums; +using AutomobilePlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AutomobilePlantListImplement.Models +{ + public class Order : IOrderModel + { + public int CarId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + Id = model.Id, + CarId = model.CarId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + CarId = model.CarId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + CarId = CarId, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + } +} -- 2.25.1 From 6ed057e371257e7a497100cdf7f8f78bdcdf0bc5 Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 12 Feb 2024 14:42:27 +0400 Subject: [PATCH 2/4] final 1 lab --- .../ViewModels/CarViewModel.cs | 4 +- .../ViewModels/ComponentViewModel.cs | 4 +- .../ViewModels/OrderViewModel.cs | 14 +- .../Implements/OrderStorage.cs | 15 +- .../AutomobilePlantView.csproj | 16 ++ .../AutomobilePlantView/Form1.Designer.cs | 39 --- AutomobilePlant/AutomobilePlantView/Form1.cs | 10 - .../AutomobilePlantView/FormCar.Designer.cs | 226 ++++++++++++++++++ .../AutomobilePlantView/FormCar.cs | 211 ++++++++++++++++ .../AutomobilePlantView/FormCar.resx | 129 ++++++++++ .../FormCarComponent.Designer.cs | 118 +++++++++ .../AutomobilePlantView/FormCarComponent.cs | 87 +++++++ .../{Form1.resx => FormCarComponent.resx} | 50 ++-- .../AutomobilePlantView/FormCars.Designer.cs | 113 +++++++++ .../AutomobilePlantView/FormCars.cs | 107 +++++++++ .../AutomobilePlantView/FormCars.resx | 120 ++++++++++ .../FormComponent.Designer.cs | 118 +++++++++ .../AutomobilePlantView/FormComponent.cs | 91 +++++++ .../AutomobilePlantView/FormComponent.resx | 120 ++++++++++ .../FormComponents.Designer.cs | 113 +++++++++ .../AutomobilePlantView/FormComponents.cs | 95 ++++++++ .../AutomobilePlantView/FormComponents.resx | 120 ++++++++++ .../FormCreateOrder.Designer.cs | 144 +++++++++++ .../AutomobilePlantView/FormCreateOrder.cs | 122 ++++++++++ .../AutomobilePlantView/FormCreateOrder.resx | 120 ++++++++++ .../AutomobilePlantView/FormMain.Designer.cs | 169 +++++++++++++ .../AutomobilePlantView/FormMain.cs | 162 +++++++++++++ .../AutomobilePlantView/FormMain.resx | 123 ++++++++++ .../AutomobilePlantView/Program.cs | 39 ++- .../AutomobilePlantView/nlog.config | 18 ++ 30 files changed, 2729 insertions(+), 88 deletions(-) delete mode 100644 AutomobilePlant/AutomobilePlantView/Form1.Designer.cs delete mode 100644 AutomobilePlant/AutomobilePlantView/Form1.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCar.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCar.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCarComponent.cs rename AutomobilePlant/AutomobilePlantView/{Form1.resx => FormCarComponent.resx} (93%) create mode 100644 AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCars.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCars.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponent.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponent.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponents.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponents.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCreateOrder.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormMain.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormMain.resx create mode 100644 AutomobilePlant/AutomobilePlantView/nlog.config diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs index 8b947f3..0629033 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs @@ -11,9 +11,9 @@ namespace AutomobilePlantContracts.ViewModels public class CarViewModel : ICarModel { public int Id { get; set; } - [DisplayName("Название изделия")] + [DisplayName("Car's name")] public string CarName { get; set; } = string.Empty; - [DisplayName("Цена")] + [DisplayName("Price")] public double Price { get; set; } public Dictionary CarComponents { diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs index 92d581d..f5bf1a9 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs @@ -11,9 +11,9 @@ namespace AutomobilePlantContracts.ViewModels public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название компонента")] + [DisplayName("Component's name")] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [DisplayName("Cost")] public double Cost { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs index 06dcbe1..0340d8a 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs @@ -11,20 +11,20 @@ namespace AutomobilePlantContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [DisplayName("Number")] public int Id { get; set; } public int CarId { get; set; } - [DisplayName("Изделие")] + [DisplayName("Car's name")] public string CarName { get; set; } = string.Empty; - [DisplayName("Количество")] + [DisplayName("Count")] public int Count { get; set; } - [DisplayName("Сумма")] + [DisplayName("Sum")] public double Sum { get; set; } - [DisplayName("Статус")] + [DisplayName("Status")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [DisplayName("Date of creation")] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [DisplayName("Date of completion")] public DateTime? DateImplement { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs index d7091fc..02c6c3f 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs @@ -23,7 +23,7 @@ namespace AutomobilePlantListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } @@ -103,5 +103,18 @@ namespace AutomobilePlantListImplement.Implements } return null; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var car in _source.Cars) + { + if (car.Id == order.CarId) + { + viewModel.CarName = car.CarName; + break; + } + } + return viewModel; + } } } diff --git a/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj b/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj index b57c89e..3eba142 100644 --- a/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj +++ b/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj @@ -8,4 +8,20 @@ enable + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/Form1.Designer.cs b/AutomobilePlant/AutomobilePlantView/Form1.Designer.cs deleted file mode 100644 index d0013f5..0000000 --- a/AutomobilePlant/AutomobilePlantView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AutomobilePlantView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/AutomobilePlant/AutomobilePlantView/Form1.cs b/AutomobilePlant/AutomobilePlantView/Form1.cs deleted file mode 100644 index d4d11b9..0000000 --- a/AutomobilePlant/AutomobilePlantView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AutomobilePlantView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs new file mode 100644 index 0000000..494be90 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs @@ -0,0 +1,226 @@ +namespace AutomobilePlantView +{ + partial class FormCar + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponents = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + IdCol = new DataGridViewTextBoxColumn(); + ComponentCol = new DataGridViewTextBoxColumn(); + CountCol = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(42, 15); + labelName.TabIndex = 0; + labelName.Text = "Name:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 38); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(36, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Price:"; + // + // textBoxName + // + textBoxName.Location = new Point(60, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(641, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(60, 35); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(337, 23); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRefresh); + groupBoxComponents.Controls.Add(buttonDelete); + groupBoxComponents.Controls.Add(buttonUpdate); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(12, 64); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(776, 345); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Components"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(695, 109); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(695, 80); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(695, 51); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(695, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdCol, ComponentCol, CountCol }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(683, 317); + dataGridView.TabIndex = 0; + // + // IdCol + // + IdCol.HeaderText = "Id"; + IdCol.Name = "IdCol"; + IdCol.Visible = false; + // + // ComponentCol + // + ComponentCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentCol.HeaderText = "Component"; + ComponentCol.Name = "ComponentCol"; + // + // CountCol + // + CountCol.HeaderText = "Count"; + CountCol.Name = "CountCol"; + // + // buttonSave + // + buttonSave.Location = new Point(632, 415); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(713, 415); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCar + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormCar"; + Text = "Car"; + Load += FormCar_Load; + groupBoxComponents.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponents; + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn IdCol; + private DataGridViewTextBoxColumn ComponentCol; + private DataGridViewTextBoxColumn CountCol; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.cs b/AutomobilePlant/AutomobilePlantView/FormCar.cs new file mode 100644 index 0000000..45bc080 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCar.cs @@ -0,0 +1,211 @@ +using AutomobilePlantDataModels.Models; +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; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.BindingModels; + +namespace AutomobilePlantView +{ + public partial class FormCar : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + private int? _id; + private Dictionary _carComponents; + public int Id { set { _id = value; } } + public FormCar(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _carComponents = new Dictionary(); + } + private void FormCar_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new CarSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.CarName; + textBoxPrice.Text = view.Price.ToString(); + _carComponents = view.CarComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_carComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _carComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCarComponent)); + if (service is FormCarComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_carComponents.ContainsKey(form.Id)) + { + _carComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _carComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCarComponent)); + if (service is FormCarComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _carComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _carComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value); + _carComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_carComponents == null || _carComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new CarBindingModel + { + Id = _id ?? 0, CarName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + CarComponents = _carComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private double CalcPrice() + { + double price = 0; + foreach (var elem in _carComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.resx b/AutomobilePlant/AutomobilePlantView/FormCar.resx new file mode 100644 index 0000000..89c9ec3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCar.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs new file mode 100644 index 0000000..671647c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace AutomobilePlantView +{ + partial class FormCarComponent + { + /// + /// 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() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(12, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(74, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Component:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(43, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Count:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(92, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(520, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(92, 35); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(520, 23); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(456, 64); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(537, 64); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCarComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(624, 94); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormCarComponent"; + Text = "Car's component"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCarComponent.cs b/AutomobilePlant/AutomobilePlantView/FormCarComponent.cs new file mode 100644 index 0000000..519b833 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCarComponent.cs @@ -0,0 +1,87 @@ +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.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 AutomobilePlantView +{ + public partial class FormCarComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormCarComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } + +} diff --git a/AutomobilePlant/AutomobilePlantView/Form1.resx b/AutomobilePlant/AutomobilePlantView/FormCarComponent.resx similarity index 93% rename from AutomobilePlant/AutomobilePlantView/Form1.resx rename to AutomobilePlant/AutomobilePlantView/FormCarComponent.resx index 1af7de1..af32865 100644 --- a/AutomobilePlant/AutomobilePlantView/Form1.resx +++ b/AutomobilePlant/AutomobilePlantView/FormCarComponent.resx @@ -1,17 +1,17 @@  - diff --git a/AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs new file mode 100644 index 0000000..eba9911 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs @@ -0,0 +1,113 @@ +namespace AutomobilePlantView +{ + partial class FormCars + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(707, 438); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(713, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(713, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(713, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(713, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormCars + // + 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 = "FormCars"; + Text = "Cars"; + Load += FormCars_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCars.cs b/AutomobilePlant/AutomobilePlantView/FormCars.cs new file mode 100644 index 0000000..c1875a7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCars.cs @@ -0,0 +1,107 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.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 FormCars : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + public FormCars(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCars_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["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["CarComponents"].Visible = false; + } + _logger.LogInformation("Загрузка машин"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки Машин"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + if (service is FormCar form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCar)); + if (service is FormCar form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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 CarBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления машины"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormCars.resx b/AutomobilePlant/AutomobilePlantView/FormCars.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCars.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/FormComponent.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs new file mode 100644 index 0000000..9bb1942 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace AutomobilePlantView +{ + partial class FormComponent + { + /// + /// 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() + { + labelName = new Label(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(42, 15); + labelName.TabIndex = 0; + labelName.Text = "Name:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(12, 43); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(34, 15); + labelCost.TabIndex = 1; + labelCost.Text = "Cost:"; + // + // textBoxName + // + textBoxName.Location = new Point(60, 9); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(344, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(60, 40); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(133, 23); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(248, 83); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(329, 83); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(416, 118); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + Text = "Component"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormComponent.cs b/AutomobilePlant/AutomobilePlantView/FormComponent.cs new file mode 100644 index 0000000..051db60 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponent.cs @@ -0,0 +1,91 @@ +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 FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + 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(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + 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/FormComponent.resx b/AutomobilePlant/AutomobilePlantView/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponent.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/FormComponents.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs new file mode 100644 index 0000000..2d653aa --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs @@ -0,0 +1,113 @@ +namespace AutomobilePlantView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(666, 438); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(672, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(116, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(672, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(116, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(672, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(116, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(672, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(116, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormComponents + // + 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 = "FormComponents"; + Text = "Components"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormComponents.cs b/AutomobilePlant/AutomobilePlantView/FormComponents.cs new file mode 100644 index 0000000..0aa581c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.cs @@ -0,0 +1,95 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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 ComponentBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormComponents.resx b/AutomobilePlant/AutomobilePlantView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.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/FormCreateOrder.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..f0490bb --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace AutomobilePlantView +{ + partial class FormCreateOrder + { + /// + /// 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() + { + labelCar = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxCar = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelCar + // + labelCar.AutoSize = true; + labelCar.Location = new Point(12, 9); + labelCar.Name = "labelCar"; + labelCar.Size = new Size(28, 15); + labelCar.TabIndex = 0; + labelCar.Text = "Car:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(43, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Count:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(12, 67); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(34, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Sum:"; + // + // comboBoxCar + // + comboBoxCar.FormattingEnabled = true; + comboBoxCar.Location = new Point(61, 6); + comboBoxCar.Name = "comboBoxCar"; + comboBoxCar.Size = new Size(727, 23); + comboBoxCar.TabIndex = 3; + comboBoxCar.SelectedIndexChanged += ComboBoxCar_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(61, 35); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(727, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(61, 64); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(727, 23); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(632, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(713, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 125); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxCar); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelCar); + Name = "FormCreateOrder"; + Text = "Create Order"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCar; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxCar; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs new file mode 100644 index 0000000..8b528b2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs @@ -0,0 +1,122 @@ +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 FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logicC; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ICarLogic logicC, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicC = logicC; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxCar.DisplayMember = "CarName"; + comboBoxCar.ValueMember = "Id"; + comboBoxCar.DataSource = list; + comboBoxCar.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка автомобилей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxCar.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxCar.SelectedValue); + var car = _logicC.ReadElement(new CarSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (car?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ComboBoxCar_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxCar.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + CarId = Convert.ToInt32(comboBoxCar.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + 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/FormCreateOrder.resx b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.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 new file mode 100644 index 0000000..e5d1a4e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -0,0 +1,169 @@ +namespace AutomobilePlantView +{ + partial class FormMain + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + toolStripMenuItemCatalogs = new ToolStripMenuItem(); + toolStripMenuItemComponents = new ToolStripMenuItem(); + toolStripMenuItemCars = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItemCatalogs }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItemCatalogs + // + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars }); + toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; + toolStripMenuItemCatalogs.Size = new Size(65, 20); + toolStripMenuItemCatalogs.Text = "Catalogs"; + // + // toolStripMenuItemComponents + // + toolStripMenuItemComponents.Name = "toolStripMenuItemComponents"; + toolStripMenuItemComponents.Size = new Size(180, 22); + toolStripMenuItemComponents.Text = "Components"; + toolStripMenuItemComponents.Click += ComponentsToolStripMenuItem_Click; + // + // toolStripMenuItemCars + // + toolStripMenuItemCars.Name = "toolStripMenuItemCars"; + toolStripMenuItemCars.Size = new Size(180, 22); + toolStripMenuItemCars.Text = "Cars"; + toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(659, 411); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(677, 27); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(111, 23); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Create order"; + 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.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(111, 23); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Order is issued"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(677, 143); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(111, 23); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + 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); + Name = "FormMain"; + Text = "Automobile plant"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem toolStripMenuItemCatalogs; + private ToolStripMenuItem toolStripMenuItemComponents; + private ToolStripMenuItem toolStripMenuItemCars; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs new file mode 100644 index 0000000..3321de7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -0,0 +1,162 @@ +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 +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["CarId"].Visible = false; + + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void CarsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCars)); + if (service is FormCars form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private OrderBindingModel CreateBindingModel(int id) + { + return new OrderBindingModel + { + Id = id, + CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].Value), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + }; + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } + +} diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.resx b/AutomobilePlant/AutomobilePlantView/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index fdfd874..cc61535 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -1,9 +1,20 @@ +using AutomobilePlantBusinessLogic.BusinessLogics; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; + namespace AutomobilePlantView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +22,31 @@ namespace AutomobilePlantView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/nlog.config b/AutomobilePlant/AutomobilePlantView/nlog.config new file mode 100644 index 0000000..95bc762 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/nlog.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.25.1 From c0e90f428c859885201d18ad1a21be090d5f793e Mon Sep 17 00:00:00 2001 From: Timourka Date: Fri, 23 Feb 2024 16:13:00 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs index 6250a8e..2d8b684 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Models/Order.cs @@ -50,12 +50,7 @@ namespace AutomobilePlantListImplement.Models { return; } - Id = model.Id; - CarId = model.CarId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } -- 2.25.1 From b9d34dbc2e6bf037fcd7f81395df5c500258eb46 Mon Sep 17 00:00:00 2001 From: Timourka Date: Fri, 23 Feb 2024 23:57:41 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AutomobilePlant/AutomobilePlantView/FormCar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.cs b/AutomobilePlant/AutomobilePlantView/FormCar.cs index 45bc080..118c17f 100644 --- a/AutomobilePlant/AutomobilePlantView/FormCar.cs +++ b/AutomobilePlant/AutomobilePlantView/FormCar.cs @@ -133,7 +133,7 @@ namespace AutomobilePlantView { try { - _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value); + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value); _carComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) -- 2.25.1