From b1d6629c1deb2c203a24d902e9bc965b035f05ae Mon Sep 17 00:00:00 2001 From: "safiulova.k" Date: Tue, 27 Feb 2024 23:28:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=20=D1=8D=D1=82=D0=BE=D0=BC=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B8=20=D0=BF=D0=BE=D0=BB=D0=BD=D0=BE=D0=BC=D0=BE?= =?UTF-8?q?=D1=87=D0=B8=D1=8F=20=D0=B2=D1=81=D1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftPlantListImplement.csproj | 18 ++ .../AbstractShopListImplement/Component.cs | 72 +++++ .../ComponentStorage.cs | 108 +++++++ .../DataListSingleton.cs | 58 ++++ .../AbstractShopListImplement/Order.cs | 106 +++++++ .../AbstractShopListImplement/OrderStorage.cs | 173 +++++++++++ .../AbstractShopListImplement/Plane.cs | 90 ++++++ .../AbstractShopListImplement/PlaneStorage.cs | 154 ++++++++++ AircraftPlant/AircraftPlant.sln | 24 ++ .../AircraftPlantBusinessLogic.csproj | 17 ++ .../ComponentLogic.cs | 116 +++++++ .../AircraftPlantBusinessLogic/OrderLogic.cs | 187 ++++++++++++ .../AircraftPlantBusinessLogic/PlaneLogic.cs | 174 +++++++++++ .../AircraftPlantContracts.csproj | 18 ++ .../BindingModels/ComponentBindingModel.cs | 16 + .../BindingModels/OrderBindingModel.cs | 52 ++++ .../BindingModels/PlaneBindingModel.cs | 40 +++ .../IComponentLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 20 ++ .../BusinessLogicsContracts/IPlaneLogic.cs | 20 ++ .../SearchModels/ComponentSearchModel.cs | 14 + .../SearchModels/OrderSearchModel.cs | 14 + .../SearchModels/PlaneSearchModel.cs | 25 ++ .../StoragesContracts/IComponentStorage.cs | 22 ++ .../StoragesContracts/IOrderStorage.cs | 21 ++ .../StoragesContracts/IPlaneStorage.cs | 21 ++ .../ViewModels/ComponentViewModel.cs | 20 ++ .../ViewModels/OrderViewModel.cs | 65 ++++ .../ViewModels/PlaneViewModel.cs | 43 +++ .../AircraftPlantDataModels.csproj | 13 + .../IComponentModel.cs | 14 + AircraftPlant/AircraftPlantDataModels/IId.cs | 14 + .../AircraftPlantDataModels/IOrderModel.cs | 45 +++ .../AircraftPlantDataModels/IPlaneModel.cs | 27 ++ .../AircraftPlantDataModels/OrderStatus.cs | 11 + .../AircraftPlantView.csproj | 11 + .../AircraftPlantView/Form1.Designer.cs | 39 --- AircraftPlant/AircraftPlantView/Form1.cs | 10 - .../FormComponent.Designer.cs | 119 ++++++++ .../AircraftPlantView/FormComponent.cs | 98 ++++++ .../AircraftPlantView/FormComponent.resx | 60 ++++ .../FormComponents.Designer.cs | 115 +++++++ .../AircraftPlantView/FormComponents.cs | 116 +++++++ .../AircraftPlantView/FormComponents.resx | 60 ++++ .../FormCreateOrder.Designer.cs | 144 +++++++++ .../AircraftPlantView/FormCreateOrder.cs | 171 +++++++++++ .../AircraftPlantView/FormCreateOrder.resx | 60 ++++ .../AircraftPlantView/FormMain.Designer.cs | 183 +++++++++++ AircraftPlant/AircraftPlantView/FormMain.cs | 216 +++++++++++++ AircraftPlant/AircraftPlantView/FormMain.resx | 63 ++++ .../AircraftPlantView/FormPlane.Designer.cs | 232 ++++++++++++++ AircraftPlant/AircraftPlantView/FormPlane.cs | 284 ++++++++++++++++++ .../AircraftPlantView/FormPlane.resx | 60 ++++ .../FormPlaneComponent.Designer.cs | 119 ++++++++ .../AircraftPlantView/FormPlaneComponent.cs | 90 ++++++ .../AircraftPlantView/FormPlaneComponent.resx | 60 ++++ .../AircraftPlantView/FormPlanes.Designer.cs | 116 +++++++ AircraftPlant/AircraftPlantView/FormPlanes.cs | 158 ++++++++++ .../AircraftPlantView/FormPlanes.resx | 60 ++++ AircraftPlant/AircraftPlantView/Program.cs | 51 +++- AircraftPlant/AircraftPlantView/nlog.config | 15 + 61 files changed, 4512 insertions(+), 50 deletions(-) create mode 100644 AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj create mode 100644 AircraftPlant/AbstractShopListImplement/Component.cs create mode 100644 AircraftPlant/AbstractShopListImplement/ComponentStorage.cs create mode 100644 AircraftPlant/AbstractShopListImplement/DataListSingleton.cs create mode 100644 AircraftPlant/AbstractShopListImplement/Order.cs create mode 100644 AircraftPlant/AbstractShopListImplement/OrderStorage.cs create mode 100644 AircraftPlant/AbstractShopListImplement/Plane.cs create mode 100644 AircraftPlant/AbstractShopListImplement/PlaneStorage.cs create mode 100644 AircraftPlant/AircraftPlantBusinessLogic/AircraftPlantBusinessLogic.csproj create mode 100644 AircraftPlant/AircraftPlantBusinessLogic/ComponentLogic.cs create mode 100644 AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs create mode 100644 AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj create mode 100644 AircraftPlant/AircraftPlantContracts»/BindingModels/ComponentBindingModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/BindingModels/OrderBindingModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/BindingModels/PlaneBindingModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IComponentLogic.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IOrderLogic.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IPlaneLogic.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/SearchModels/ComponentSearchModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/SearchModels/OrderSearchModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/SearchModels/PlaneSearchModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/StoragesContracts/IComponentStorage.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/StoragesContracts/IOrderStorage.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/StoragesContracts/IPlaneStorage.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs create mode 100644 AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs create mode 100644 AircraftPlant/AircraftPlantDataModels/AircraftPlantDataModels.csproj create mode 100644 AircraftPlant/AircraftPlantDataModels/IComponentModel.cs create mode 100644 AircraftPlant/AircraftPlantDataModels/IId.cs create mode 100644 AircraftPlant/AircraftPlantDataModels/IOrderModel.cs create mode 100644 AircraftPlant/AircraftPlantDataModels/IPlaneModel.cs create mode 100644 AircraftPlant/AircraftPlantDataModels/OrderStatus.cs delete mode 100644 AircraftPlant/AircraftPlantView/Form1.Designer.cs delete mode 100644 AircraftPlant/AircraftPlantView/Form1.cs create mode 100644 AircraftPlant/AircraftPlantView/FormComponent.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormComponent.cs create mode 100644 AircraftPlant/AircraftPlantView/FormComponent.resx create mode 100644 AircraftPlant/AircraftPlantView/FormComponents.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormComponents.cs create mode 100644 AircraftPlant/AircraftPlantView/FormComponents.resx create mode 100644 AircraftPlant/AircraftPlantView/FormCreateOrder.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormCreateOrder.cs create mode 100644 AircraftPlant/AircraftPlantView/FormCreateOrder.resx create mode 100644 AircraftPlant/AircraftPlantView/FormMain.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormMain.cs create mode 100644 AircraftPlant/AircraftPlantView/FormMain.resx create mode 100644 AircraftPlant/AircraftPlantView/FormPlane.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormPlane.cs create mode 100644 AircraftPlant/AircraftPlantView/FormPlane.resx create mode 100644 AircraftPlant/AircraftPlantView/FormPlaneComponent.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormPlaneComponent.cs create mode 100644 AircraftPlant/AircraftPlantView/FormPlaneComponent.resx create mode 100644 AircraftPlant/AircraftPlantView/FormPlanes.Designer.cs create mode 100644 AircraftPlant/AircraftPlantView/FormPlanes.cs create mode 100644 AircraftPlant/AircraftPlantView/FormPlanes.resx create mode 100644 AircraftPlant/AircraftPlantView/nlog.config diff --git a/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj b/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj new file mode 100644 index 0000000..9d5c14b --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/AircraftPlantListImplement.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/AircraftPlant/AbstractShopListImplement/Component.cs b/AircraftPlant/AbstractShopListImplement/Component.cs new file mode 100644 index 0000000..a47a44e --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/Component.cs @@ -0,0 +1,72 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.ViewModels; +using AircraftPlantDataModels.Models; + +namespace AircraftPlantListImplement.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/AircraftPlant/AbstractShopListImplement/ComponentStorage.cs b/AircraftPlant/AbstractShopListImplement/ComponentStorage.cs new file mode 100644 index 0000000..e3e5bd0 --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/ComponentStorage.cs @@ -0,0 +1,108 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.ViewModels; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement.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/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs b/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs new file mode 100644 index 0000000..37a8bec --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs @@ -0,0 +1,58 @@ +using AircraftPlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement +{ + /// + /// Класс для хранения списков классов-моделей (паттерн Singleton) + /// + public class DataListSingleton + { + /// + /// Ссылка на класс + /// + private static DataListSingleton? _instance; + + /// + /// Список классов-моделей компонентов + /// + public List Components { get; set; } + + /// + /// Список классов-моделей заказов + /// + public List Orders { get; set; } + + /// + /// Список классов-моделей изделий + /// + public List Planes { get; set; } + + /// + /// Конструктор + /// + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Planes = new List(); + } + + /// + /// Получить ссылку на класс + /// + /// + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/AircraftPlant/AbstractShopListImplement/Order.cs b/AircraftPlant/AbstractShopListImplement/Order.cs new file mode 100644 index 0000000..bac9930 --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/Order.cs @@ -0,0 +1,106 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.ViewModels; +using AircraftPlantDataModels.Enums; +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement.Models +{ + /// + /// Сущность "Заказ" + /// + public class Order : IOrderModel + { + /// + /// Идентификатор + /// + public int Id { get; private set; } + + /// + /// Идентификатор изделия + /// + public int PlaneId { get; private set; } + + /// + /// Количество изделий + /// + public int Count { get; private set; } + + /// + /// Сумма заказа + /// + public double Sum { get; private set; } + + /// + /// Статус заказа + /// + public OrderStatus Status { get; private set; } + + /// + /// Дата создания заказа + /// + public DateTime DateCreate { get; private set; } + + /// + /// Дата выполнения заказа + /// + public DateTime? DateImplement { get; private set; } + + /// + /// Создание модели заказа + /// + /// + /// + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Order + { + Id = model.Id, + PlaneId = model.PlaneId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + /// + /// Изменение модели заказа + /// + /// + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + Status = model.Status; + DateImplement = model.DateImplement; + } + + /// + /// Получение модели заказа + /// + public OrderViewModel GetViewModel => new() + { + Id = Id, + PlaneId = PlaneId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs new file mode 100644 index 0000000..3a5b908 --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs @@ -0,0 +1,173 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantContracts.ViewModels; +using AircraftPlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement.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(GetViewModel(order)); + } + 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(GetViewModel(order)); + } + } + 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 GetViewModel(order); + } + } + 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 GetViewModel(newOrder); + } + + /// + /// Редактирование элемента + /// + /// + /// + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return GetViewModel(order); + } + } + 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 GetViewModel(element); + } + } + return null; + } + + /// + /// Получение модели заказа + /// + /// + /// + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var sushi in _source.Planes) + { + if (sushi.Id == order.PlaneId) + { + viewModel.PlaneName = sushi.PlaneName; + break; + } + } + return viewModel; + } + } +} \ No newline at end of file diff --git a/AircraftPlant/AbstractShopListImplement/Plane.cs b/AircraftPlant/AbstractShopListImplement/Plane.cs new file mode 100644 index 0000000..f31183d --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/Plane.cs @@ -0,0 +1,90 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.ViewModels; +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement.Models +{ + /// + /// Сущность "Изделие" + /// + public class Plane : IPlaneModel + { + /// + /// Идентификатор + /// + public int Id { get; private set; } + + /// + /// Название изделия + /// + public string PlaneName { get; private set; } = string.Empty; + + /// + /// Стоимость изделия + /// + public double Price { get; private set; } + + /// + /// Коллекция компонентов изделия + /// + public Dictionary PlaneComponents + { + get; + private set; + } = new Dictionary(); + + /// + /// Создание модели изделия + /// + /// + /// + public static Plane? Create(PlaneBindingModel? model) + { + if (model == null) + { + return null; + } + + return new Plane() + { + Id = model.Id, + PlaneName = model.PlaneName, + Price = model.Price, + PlaneComponents = model.PlaneComponents + }; + } + + /// + /// Изменение модели изделия + /// + /// + public void Update(PlaneBindingModel? model) + { + if (model == null) + { + return; + } + + PlaneName = model.PlaneName; + Price = model.Price; + PlaneComponents = model.PlaneComponents; + } + + /// + /// Получение модели изделия + /// + public PlaneViewModel GetViewModel => new() + { + Id = Id, + PlaneName = PlaneName, + Price = Price, + PlaneComponents = PlaneComponents + }; + } +} diff --git a/AircraftPlant/AbstractShopListImplement/PlaneStorage.cs b/AircraftPlant/AbstractShopListImplement/PlaneStorage.cs new file mode 100644 index 0000000..1a41eb6 --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/PlaneStorage.cs @@ -0,0 +1,154 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantContracts.ViewModels; +using AircraftPlantListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement.Implements +{ + /// + /// Реализация интерфейса хранилища для изделий + /// + public class PlaneStorage : IPlaneStorage + { + /// + /// Хранилище + /// + private readonly DataListSingleton _source; + + /// + /// Конструктор + /// + public PlaneStorage() + { + _source = DataListSingleton.GetInstance(); + } + + /// + /// Получение полного списка + /// + /// + public List GetFullList() + { + var result = new List(); + foreach (var plane in _source.Planes) + { + result.Add(plane.GetViewModel); + } + return result; + } + + /// + /// Получение фильтрованного списка + /// + /// + /// + public List GetFilteredList(PlaneSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PlaneName)) + { + return result; + } + + foreach (var plane in _source.Planes) + { + if (plane.PlaneName.Contains(model.PlaneName)) + { + result.Add(plane.GetViewModel); + } + } + return result; + } + + /// + /// Получение элемента + /// + /// + /// + public PlaneViewModel? GetElement(PlaneSearchModel model) + { + if (string.IsNullOrEmpty(model.PlaneName) && !model.Id.HasValue) + { + return null; + } + + foreach (var plane in _source.Planes) + { + if ((!string.IsNullOrEmpty(model.PlaneName) && plane.PlaneName == model.PlaneName) || (model.Id.HasValue && plane.Id == model.Id)) + { + return plane.GetViewModel; + } + } + return null; + } + + /// + /// Добавление элемента + /// + /// + /// + public PlaneViewModel? Insert(PlaneBindingModel model) + { + model.Id = 1; + foreach (var plane in _source.Planes) + { + if (model.Id <= plane.Id) + { + model.Id = plane.Id + 1; + } + } + + var newPlane = Plane.Create(model); + if (newPlane == null) + { + return null; + } + + _source.Planes.Add(newPlane); + return newPlane.GetViewModel; + } + + /// + /// Редактирование элемента + /// + /// + /// + public PlaneViewModel? Update(PlaneBindingModel model) + { + foreach (var plane in _source.Planes) + { + if (plane.Id == model.Id) + { + plane.Update(model); + return plane.GetViewModel; + } + } + return null; + } + + /// + /// Удаление элемента + /// + /// + /// + public PlaneViewModel? Delete(PlaneBindingModel model) + { + for (int i = 0; i < _source.Planes.Count; ++i) + { + if (_source.Planes[i].Id == model.Id) + { + var element = _source.Planes[i]; + _source.Planes.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlant.sln b/AircraftPlant/AircraftPlant.sln index 6f08efe..9325f37 100644 --- a/AircraftPlant/AircraftPlant.sln +++ b/AircraftPlant/AircraftPlant.sln @@ -5,6 +5,14 @@ VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantView", "AircraftPlantView\AircraftPlantView.csproj", "{3D6CD163-7D74-421D-8C33-4697F3BA0808}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantDataModels", "AircraftPlantDataModels\AircraftPlantDataModels.csproj", "{6E099419-3E14-4B53-88F1-FC2A82D3D504}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantContracts", "AircraftPlantContracts»\AircraftPlantContracts.csproj", "{C07B18D1-0947-4741-B289-07200B6CC2AC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantBusinessLogic", "AircraftPlantBusinessLogic\AircraftPlantBusinessLogic.csproj", "{F3E5FE0D-2CAE-43D3-868E-A782D7519DE2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantListImplement", "AbstractShopListImplement\AircraftPlantListImplement.csproj", "{69BB512A-F548-45B7-B983-C3E9600CFC5D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +23,22 @@ Global {3D6CD163-7D74-421D-8C33-4697F3BA0808}.Debug|Any CPU.Build.0 = Debug|Any CPU {3D6CD163-7D74-421D-8C33-4697F3BA0808}.Release|Any CPU.ActiveCfg = Release|Any CPU {3D6CD163-7D74-421D-8C33-4697F3BA0808}.Release|Any CPU.Build.0 = Release|Any CPU + {6E099419-3E14-4B53-88F1-FC2A82D3D504}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E099419-3E14-4B53-88F1-FC2A82D3D504}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E099419-3E14-4B53-88F1-FC2A82D3D504}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E099419-3E14-4B53-88F1-FC2A82D3D504}.Release|Any CPU.Build.0 = Release|Any CPU + {C07B18D1-0947-4741-B289-07200B6CC2AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C07B18D1-0947-4741-B289-07200B6CC2AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C07B18D1-0947-4741-B289-07200B6CC2AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C07B18D1-0947-4741-B289-07200B6CC2AC}.Release|Any CPU.Build.0 = Release|Any CPU + {F3E5FE0D-2CAE-43D3-868E-A782D7519DE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3E5FE0D-2CAE-43D3-868E-A782D7519DE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3E5FE0D-2CAE-43D3-868E-A782D7519DE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3E5FE0D-2CAE-43D3-868E-A782D7519DE2}.Release|Any CPU.Build.0 = Release|Any CPU + {69BB512A-F548-45B7-B983-C3E9600CFC5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69BB512A-F548-45B7-B983-C3E9600CFC5D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69BB512A-F548-45B7-B983-C3E9600CFC5D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69BB512A-F548-45B7-B983-C3E9600CFC5D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/AircraftPlant/AircraftPlantBusinessLogic/AircraftPlantBusinessLogic.csproj b/AircraftPlant/AircraftPlantBusinessLogic/AircraftPlantBusinessLogic.csproj new file mode 100644 index 0000000..bf154e6 --- /dev/null +++ b/AircraftPlant/AircraftPlantBusinessLogic/AircraftPlantBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/AircraftPlant/AircraftPlantBusinessLogic/ComponentLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..d2e4334 --- /dev/null +++ b/AircraftPlant/AircraftPlantBusinessLogic/ComponentLogic.cs @@ -0,0 +1,116 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantContracts.ViewModels; +using Microsoft.Extensions.Logging; + + +namespace AircraftPlantBusinessLogic.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/AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..d59c278 --- /dev/null +++ b/AircraftPlant/AircraftPlantBusinessLogic/OrderLogic.cs @@ -0,0 +1,187 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantContracts.ViewModels; +using AircraftPlantDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantBusinessLogic.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. Order.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.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Смена статуса заказа (Выполняется) + /// + /// + /// + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется); + } + + /// + /// Смена статуса заказа (Выдан) + /// + /// + /// + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выдан); + } + + /// + /// Смена статуса заказа (Готов) + /// + /// + /// + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Готов); + } + + /// + /// Проверка модели заказа + /// + /// + /// + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PlaneId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.PlaneId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderID:{Id}.Sum:{ Sum}. PlaneId: { PlaneId}", model.Id, model.Sum, model.PlaneId); + } + + /// + /// Смена статуса заказа + /// + /// + /// + /// + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) + { + var element = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (element.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + + model.Status = newStatus; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = element.DateImplement; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs b/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs new file mode 100644 index 0000000..82de87f --- /dev/null +++ b/AircraftPlant/AircraftPlantBusinessLogic/PlaneLogic.cs @@ -0,0 +1,174 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantBusinessLogic.BusinessLogics +{ + /// + /// Реализация интерфейса бизнес-логики для изделия + /// + public class PlaneLogic : IPlaneLogic + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Взаимодействие с хранилищем изделий + /// + private readonly IPlaneStorage _planeStorage; + + /// + /// Конструктор + /// + /// + /// + public PlaneLogic(ILogger logger, IPlaneStorage +planeStorage) + { + _logger = logger; + _planeStorage = planeStorage; + } + + /// + /// Получение списка + /// + /// + /// + public List? ReadList(PlaneSearchModel? model) + { + _logger.LogInformation("ReadList. PlaneName:{PlaneName}.Id:{ Id}", model?.PlaneName, model?.Id); + + var list = model == null ? _planeStorage.GetFullList() : _planeStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + /// + /// Получение отдельной записи + /// + /// + /// + /// + public PlaneViewModel? ReadElement(PlaneSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. PlaneName:{PlaneName}.Id:{ Id}", model.PlaneName, model.Id); + + var element = _planeStorage.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(PlaneBindingModel model) + { + CheckModel(model); + + if (_planeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + /// + /// Изменение записи + /// + /// + /// + public bool Update(PlaneBindingModel model) + { + CheckModel(model); + + if (_planeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + /// + /// Удаление записи + /// + /// + /// + public bool Delete(PlaneBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_planeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + /// + /// Проверка модели изделия + /// + /// + /// + private void CheckModel(PlaneBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PlaneName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.PlaneName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Plane. PlaneName:{PlaneName}.Price:{ Price}. Id: { Id}", model.PlaneName, model.Price, model.Id); + var element = _planeStorage.GetElement(new PlaneSearchModel + { + PlaneName = model.PlaneName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj b/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj new file mode 100644 index 0000000..825be74 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/AircraftPlantContracts.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + AircraftPlantContracts_ + enable + enable + + + + + + + + + + + diff --git a/AircraftPlant/AircraftPlantContracts»/BindingModels/ComponentBindingModel.cs b/AircraftPlant/AircraftPlantContracts»/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..3322594 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/BindingModels/OrderBindingModel.cs b/AircraftPlant/AircraftPlantContracts»/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..8d4a12b --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BindingModels/OrderBindingModel.cs @@ -0,0 +1,52 @@ +using AircraftPlantDataModels.Enums; +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.BindingModels +{ + /// + /// Модель для передачи данных пользователя + /// в методы для сохранения данных для заказов + /// + public class OrderBindingModel : IOrderModel + { + /// + /// Идентификатор + /// + public int Id { get; set; } + + /// + /// Идентификатор изделия + /// + public int PlaneId { 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/AircraftPlant/AircraftPlantContracts»/BindingModels/PlaneBindingModel.cs b/AircraftPlant/AircraftPlantContracts»/BindingModels/PlaneBindingModel.cs new file mode 100644 index 0000000..ca69baf --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BindingModels/PlaneBindingModel.cs @@ -0,0 +1,40 @@ +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.BindingModels +{ + /// + /// Модель для передачи данных пользователя + /// в методы для сохранения данных для изделий + /// + public class PlaneBindingModel : IPlaneModel + { + /// + /// Идентификатор + /// + public int Id { get; set; } + + /// + /// Название изделия + /// + public string PlaneName { get; set; } = string.Empty; + + /// + /// Стоимость изделия + /// + public double Price { get; set; } + + /// + /// Коллекция компонентов изделия + /// + public Dictionary PlaneComponents + { + get; + set; + } = new(); + } +} diff --git a/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IComponentLogic.cs b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..9ef09cc --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IOrderLogic.cs b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..a3b5ca4 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IPlaneLogic.cs b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IPlaneLogic.cs new file mode 100644 index 0000000..6d8f209 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/BusinessLogicsContracts/IPlaneLogic.cs @@ -0,0 +1,20 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.ViewModels; +using AircraftPlantContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.BusinessLogicsContracts +{ + public interface IPlaneLogic + { + List? ReadList(PlaneSearchModel? model); + PlaneViewModel? ReadElement(PlaneSearchModel model); + bool Create(PlaneBindingModel model); + bool Update(PlaneBindingModel model); + bool Delete(PlaneBindingModel model); + } +} diff --git a/AircraftPlant/AircraftPlantContracts»/SearchModels/ComponentSearchModel.cs b/AircraftPlant/AircraftPlantContracts»/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..82021af --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/AircraftPlant/AircraftPlantContracts»/SearchModels/OrderSearchModel.cs b/AircraftPlant/AircraftPlantContracts»/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..872e436 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/SearchModels/OrderSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } + +} diff --git a/AircraftPlant/AircraftPlantContracts»/SearchModels/PlaneSearchModel.cs b/AircraftPlant/AircraftPlantContracts»/SearchModels/PlaneSearchModel.cs new file mode 100644 index 0000000..5950036 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/SearchModels/PlaneSearchModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.SearchModels +{ + /// + /// Модель для передачи данных пользователя + /// в методы для поиска данных для изделий + /// + public class PlaneSearchModel + { + /// + /// Идентификатор + /// + public int? Id { get; set; } + + /// + /// Название изделия + /// + public string? PlaneName { get; set; } + } +} diff --git a/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IComponentStorage.cs b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..8725e3c --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IOrderStorage.cs b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..6a76192 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IPlaneStorage.cs b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IPlaneStorage.cs new file mode 100644 index 0000000..9b6406b --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/StoragesContracts/IPlaneStorage.cs @@ -0,0 +1,21 @@ +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.StoragesContracts +{ + public interface IPlaneStorage + { + List GetFullList(); + List GetFilteredList(PlaneSearchModel model); + PlaneViewModel? GetElement(PlaneSearchModel model); + PlaneViewModel? Insert(PlaneBindingModel model); + PlaneViewModel? Update(PlaneBindingModel model); + PlaneViewModel? Delete(PlaneBindingModel model); + } +} diff --git a/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..dec85b2 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/ComponentViewModel.cs @@ -0,0 +1,20 @@ +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.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/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..c99b460 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/OrderViewModel.cs @@ -0,0 +1,65 @@ +using AircraftPlantDataModels.Models; +using AircraftPlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.ViewModels +{ + /// + /// Модель для передачи данных пользователю + /// для отображения для заказов + /// + public class OrderViewModel : IOrderModel + { + /// + /// Идентификатор + /// + [DisplayName("Номер")] + public int Id { get; set; } + + /// + /// Идентификатор изделия + /// + public int PlaneId { get; set; } + + /// + /// Название изделия + /// + [DisplayName("Изделие")] + public string PlaneName { 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/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs b/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs new file mode 100644 index 0000000..0e60ba4 --- /dev/null +++ b/AircraftPlant/AircraftPlantContracts»/ViewModels/PlaneViewModel.cs @@ -0,0 +1,43 @@ +using AircraftPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantContracts.ViewModels +{ + /// + /// Модель для передачи данных пользователю + /// для отображения для изделий + /// + public class PlaneViewModel : IPlaneModel + { + /// + /// Идентификатор + /// + public int Id { get; set; } + + /// + /// Название изделия + /// + [DisplayName("Название изделия")] + public string PlaneName { get; set; } = string.Empty; + + /// + /// Стоимость изделия + /// + [DisplayName("Цена")] + public double Price { get; set; } + + /// + /// Коллекция компонентов изделия + /// + public Dictionary PlaneComponents + { + get; + set; + } = new(); + } +} diff --git a/AircraftPlant/AircraftPlantDataModels/AircraftPlantDataModels.csproj b/AircraftPlant/AircraftPlantDataModels/AircraftPlantDataModels.csproj new file mode 100644 index 0000000..28e9bd0 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/AircraftPlantDataModels.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/AircraftPlant/AircraftPlantDataModels/IComponentModel.cs b/AircraftPlant/AircraftPlantDataModels/IComponentModel.cs new file mode 100644 index 0000000..09da449 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/IComponentModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantDataModels/IId.cs b/AircraftPlant/AircraftPlantDataModels/IId.cs new file mode 100644 index 0000000..f94dce7 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/IId.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantDataModels +{ + public interface IId + { + int Id { get; } + } +} + diff --git a/AircraftPlant/AircraftPlantDataModels/IOrderModel.cs b/AircraftPlant/AircraftPlantDataModels/IOrderModel.cs new file mode 100644 index 0000000..5e60ef2 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/IOrderModel.cs @@ -0,0 +1,45 @@ +using AircraftPlantDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantDataModels.Models +{ + /// + /// Интерфейс для модели заказа + /// + public interface IOrderModel : IId + { + /// + /// Идентификатор изделия + /// + int PlaneId { get; } + + /// + /// Количество изделий + /// + int Count { get; } + + /// + /// Сумма заказа + /// + double Sum { get; } + + /// + /// Статус заказа + /// + OrderStatus Status { get; } + + /// + /// Дата создания заказа + /// + DateTime DateCreate { get; } + + /// + /// Дата выполнения заказа + /// + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantDataModels/IPlaneModel.cs b/AircraftPlant/AircraftPlantDataModels/IPlaneModel.cs new file mode 100644 index 0000000..7146635 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/IPlaneModel.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantDataModels.Models +{ + /// + /// Интерфейс для модели изделия + /// + public interface IPlaneModel : IId + { + /// + /// Название изделия + /// + string PlaneName { get; } + /// + /// Стоимость изделия + /// + double Price { get; } + /// + /// Коллекция компонентов изделия + /// + Dictionary PlaneComponents { get; } + } +} diff --git a/AircraftPlant/AircraftPlantDataModels/OrderStatus.cs b/AircraftPlant/AircraftPlantDataModels/OrderStatus.cs new file mode 100644 index 0000000..1f2dc78 --- /dev/null +++ b/AircraftPlant/AircraftPlantDataModels/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace AircraftPlantDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3 + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/AircraftPlantView.csproj b/AircraftPlant/AircraftPlantView/AircraftPlantView.csproj index b57c89e..086144d 100644 --- a/AircraftPlant/AircraftPlantView/AircraftPlantView.csproj +++ b/AircraftPlant/AircraftPlantView/AircraftPlantView.csproj @@ -8,4 +8,15 @@ enable + + + + + + + + + + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/Form1.Designer.cs b/AircraftPlant/AircraftPlantView/Form1.Designer.cs deleted file mode 100644 index 73275c9..0000000 --- a/AircraftPlant/AircraftPlantView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AircraftPlantView -{ - 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 - } -} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/Form1.cs b/AircraftPlant/AircraftPlantView/Form1.cs deleted file mode 100644 index bbd4354..0000000 --- a/AircraftPlant/AircraftPlantView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AircraftPlantView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormComponent.Designer.cs b/AircraftPlant/AircraftPlantView/FormComponent.Designer.cs new file mode 100644 index 0000000..7162e0c --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace AircraftPlantView +{ + 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() + { + this.labelName = new System.Windows.Forms.Label(); + this.labelCost = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxCost = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 19); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelCost + // + this.labelCost.AutoSize = true; + this.labelCost.Location = new System.Drawing.Point(12, 49); + this.labelCost.Name = "labelCost"; + this.labelCost.Size = new System.Drawing.Size(38, 15); + this.labelCost.TabIndex = 1; + this.labelCost.Text = "Цена:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(80, 16); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(179, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxCost + // + this.textBoxCost.Location = new System.Drawing.Point(80, 46); + this.textBoxCost.Name = "textBoxCost"; + this.textBoxCost.Size = new System.Drawing.Size(179, 23); + this.textBoxCost.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(102, 85); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(184, 85); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(276, 116); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCost); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelCost); + this.Controls.Add(this.labelName); + this.Name = "FormComponent"; + this.Text = "Компонент"; + this.Load += new System.EventHandler(this.FormComponent_Load); + this.ResumeLayout(false); + this.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/AircraftPlant/AircraftPlantView/FormComponent.cs b/AircraftPlant/AircraftPlantView/FormComponent.cs new file mode 100644 index 0000000..a287ef0 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormComponent.cs @@ -0,0 +1,98 @@ +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 AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.SearchModels; +using Microsoft.Extensions.Logging; + + +namespace AircraftPlantView +{ + 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/AircraftPlant/AircraftPlantView/FormComponent.resx b/AircraftPlant/AircraftPlantView/FormComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormComponents.Designer.cs b/AircraftPlant/AircraftPlantView/FormComponents.Designer.cs new file mode 100644 index 0000000..626a862 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace AircraftPlantView +{ + 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() + { + this.dataGridViewComponents = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewComponents)).BeginInit(); + this.SuspendLayout(); + // + // dataGridViewComponents + // + this.dataGridViewComponents.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridViewComponents.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewComponents.Location = new System.Drawing.Point(2, 1); + this.dataGridViewComponents.Name = "dataGridViewComponents"; + this.dataGridViewComponents.RowTemplate.Height = 25; + this.dataGridViewComponents.Size = new System.Drawing.Size(450, 450); + this.dataGridViewComponents.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(473, 12); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(75, 23); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(473, 53); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(75, 23); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(473, 96); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(75, 23); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(473, 139); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(75, 23); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(572, 451); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridViewComponents); + this.Name = "FormComponents"; + this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewComponents)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridViewComponents; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormComponents.cs b/AircraftPlant/AircraftPlantView/FormComponents.cs new file mode 100644 index 0000000..9fc4a76 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormComponents.cs @@ -0,0 +1,116 @@ +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 AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AircraftPlantView +{ + 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) + { + dataGridViewComponents.DataSource = list; + dataGridViewComponents.Columns["Id"].Visible = false; + dataGridViewComponents.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 (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridViewComponents.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/AircraftPlant/AircraftPlantView/FormComponents.resx b/AircraftPlant/AircraftPlantView/FormComponents.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormComponents.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormCreateOrder.Designer.cs b/AircraftPlant/AircraftPlantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..2b57908 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace AircraftPlantView +{ + 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() + { + this.labelPlane = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.labelSum = new System.Windows.Forms.Label(); + this.comboBoxPlane = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.textBoxSum = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelPlane + // + this.labelPlane.AutoSize = true; + this.labelPlane.Location = new System.Drawing.Point(12, 13); + this.labelPlane.Name = "labelPlane"; + this.labelPlane.Size = new System.Drawing.Size(56, 15); + this.labelPlane.TabIndex = 0; + this.labelPlane.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 42); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelSum + // + this.labelSum.AutoSize = true; + this.labelSum.Location = new System.Drawing.Point(12, 71); + this.labelSum.Name = "labelSum"; + this.labelSum.Size = new System.Drawing.Size(48, 15); + this.labelSum.TabIndex = 2; + this.labelSum.Text = "Сумма:"; + // + // comboBoxPlane + // + this.comboBoxPlane.FormattingEnabled = true; + this.comboBoxPlane.Location = new System.Drawing.Point(111, 10); + this.comboBoxPlane.Name = "comboBoxPlane"; + this.comboBoxPlane.Size = new System.Drawing.Size(236, 23); + this.comboBoxPlane.TabIndex = 3; + this.comboBoxPlane.SelectedIndexChanged += new System.EventHandler(this.comboBoxPlane_SelectedIndexChanged); + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(111, 39); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(236, 23); + this.textBoxCount.TabIndex = 4; + this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCount_TextChanged); + // + // textBoxSum + // + this.textBoxSum.Location = new System.Drawing.Point(111, 68); + this.textBoxSum.Name = "textBoxSum"; + this.textBoxSum.Size = new System.Drawing.Size(236, 23); + this.textBoxSum.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(179, 97); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(75, 23); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(272, 97); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(359, 128); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxSum); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxPlane); + this.Controls.Add(this.labelSum); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelPlane); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelPlane; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPlane; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormCreateOrder.cs b/AircraftPlant/AircraftPlantView/FormCreateOrder.cs new file mode 100644 index 0000000..77c1baf --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormCreateOrder.cs @@ -0,0 +1,171 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.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 AircraftPlantView +{ + public partial class FormCreateOrder : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для изделий + /// + private readonly IPlaneLogic _logicP; + + /// + /// Бизнес-логика для заказов + /// + private readonly IOrderLogic _logicO; + + /// + /// Конструктор + /// + /// + /// + /// + public FormCreateOrder(ILogger logger, IPlaneLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + /// + /// Загрузка списка изделий для заказа + /// + /// + /// + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxPlane.DisplayMember = "PlaneName"; + comboBoxPlane.ValueMember = "Id"; + comboBoxPlane.DataSource = list; + comboBoxPlane.SelectedItem = null; + } + + } + 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 comboBoxPlane_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 (comboBoxPlane.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + PlaneId = Convert.ToInt32(comboBoxPlane.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(); + } + + /// + /// Подсчет суммы заказа + /// + private void CalcSum() + { + if (comboBoxPlane.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPlane.SelectedValue); + var product = _logicP.ReadElement(new PlaneSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + } +} diff --git a/AircraftPlant/AircraftPlantView/FormCreateOrder.resx b/AircraftPlant/AircraftPlantView/FormCreateOrder.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormCreateOrder.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs new file mode 100644 index 0000000..5fec25f --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs @@ -0,0 +1,183 @@ +namespace AircraftPlantView +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonCreateOrder = new System.Windows.Forms.Button(); + this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); + this.ButtonOrderReady = new System.Windows.Forms.Button(); + this.ButtonIssuedOrder = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.GridColor = System.Drawing.Color.White; + this.dataGridView.Location = new System.Drawing.Point(0, 24); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(780, 377); + this.dataGridView.TabIndex = 0; + // + // ButtonCreateOrder + // + this.ButtonCreateOrder.Location = new System.Drawing.Point(804, 42); + this.ButtonCreateOrder.Name = "ButtonCreateOrder"; + this.ButtonCreateOrder.Size = new System.Drawing.Size(153, 23); + this.ButtonCreateOrder.TabIndex = 1; + this.ButtonCreateOrder.Text = "Создать заказ"; + this.ButtonCreateOrder.UseVisualStyleBackColor = true; + this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // ButtonTakeOrderInWork + // + this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(804, 89); + this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(153, 23); + this.ButtonTakeOrderInWork.TabIndex = 2; + this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // ButtonOrderReady + // + this.ButtonOrderReady.Location = new System.Drawing.Point(804, 139); + this.ButtonOrderReady.Name = "ButtonOrderReady"; + this.ButtonOrderReady.Size = new System.Drawing.Size(153, 23); + this.ButtonOrderReady.TabIndex = 3; + this.ButtonOrderReady.Text = "Заказ готов"; + this.ButtonOrderReady.UseVisualStyleBackColor = true; + this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // ButtonIssuedOrder + // + this.ButtonIssuedOrder.Location = new System.Drawing.Point(804, 187); + this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + this.ButtonIssuedOrder.Size = new System.Drawing.Size(153, 23); + this.ButtonIssuedOrder.TabIndex = 4; + this.ButtonIssuedOrder.Text = "Заказ выдан"; + this.ButtonIssuedOrder.UseVisualStyleBackColor = true; + this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(804, 236); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(153, 23); + this.ButtonRef.TabIndex = 5; + this.ButtonRef.Text = "Обновить список"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(977, 24); + this.menuStrip1.TabIndex = 6; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.компонентыToolStripMenuItem, + this.изделияToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.компонентыToolStripMenuItem.Text = "Компоненты"; + this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); + // + // изделияToolStripMenuItem + // + this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.изделияToolStripMenuItem.Text = "Изделия"; + this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(977, 401); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonIssuedOrder); + this.Controls.Add(this.ButtonOrderReady); + this.Controls.Add(this.ButtonTakeOrderInWork); + this.Controls.Add(this.ButtonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Авиационный завод"; + this.Load += new System.EventHandler(this.FormMain_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonCreateOrder; + private Button ButtonTakeOrderInWork; + private Button ButtonOrderReady; + private Button ButtonIssuedOrder; + private Button ButtonRef; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs new file mode 100644 index 0000000..5ece09a --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormMain.cs @@ -0,0 +1,216 @@ +using AircraftPlantBusinessLogic.BusinessLogics; +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AircraftPlantView +{ + /// + /// Главная форма + /// + public partial class FormMain : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для заказов + /// + private readonly IOrderLogic _orderLogic; + + /// + /// Конструктор + /// + /// + /// + public FormMain(ILogger logger, IOrderLogic logic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = logic; + } + + /// + /// Загрузка списка заказов + /// + /// + /// + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Показать список всех компонентов + /// + /// + /// + private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + /// + /// Показать список всех изделий + /// + /// + /// + private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPlanes)); + if (service is FormPlanes 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 void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + /// + /// Кнопка "Заказ готов" + /// + /// + /// + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + /// + /// Кнопка "Заказ выдан" + /// + /// + /// + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _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(); + } + + /// + /// Метод загрузки списка заказов + /// + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["PlaneName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PlaneId"].Visible = false; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/AircraftPlant/AircraftPlantView/FormMain.resx b/AircraftPlant/AircraftPlantView/FormMain.resx new file mode 100644 index 0000000..938108a --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormMain.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/AircraftPlant/AircraftPlantView/FormPlane.Designer.cs b/AircraftPlant/AircraftPlantView/FormPlane.Designer.cs new file mode 100644 index 0000000..3cd15e2 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlane.Designer.cs @@ -0,0 +1,232 @@ +namespace AircraftPlantView +{ + partial class FormPlane + { + /// + /// 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.ButtonRef = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 45); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(70, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Стоимость:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(93, 10); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(230, 23); + this.textBoxName.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(93, 42); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(230, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.ButtonRef); + this.groupBox1.Controls.Add(this.ButtonDel); + this.groupBox1.Controls.Add(this.ButtonUpd); + this.groupBox1.Controls.Add(this.ButtonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(12, 82); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(590, 332); + this.groupBox1.TabIndex = 4; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Компоненты"; + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(485, 140); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(75, 23); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(485, 100); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(75, 23); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(485, 61); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(75, 23); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(485, 22); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(75, 23); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Добавить"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnId, + this.ColumnName, + this.ColumnCount}); + this.dataGridView.GridColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridView.Location = new System.Drawing.Point(7, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(453, 304); + this.dataGridView.TabIndex = 0; + // + // ColumnId + // + this.ColumnId.HeaderText = "Id"; + this.ColumnId.Name = "ColumnId"; + this.ColumnId.ReadOnly = true; + this.ColumnId.Visible = false; + // + // ColumnName + // + this.ColumnName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ColumnName.HeaderText = "Компонент"; + this.ColumnName.Name = "ColumnName"; + this.ColumnName.ReadOnly = true; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(498, 420); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(407, 420); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(75, 23); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // FormPlane + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(614, 450); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPlane"; + this.Text = "Изделие"; + this.Load += new System.EventHandler(this.FormPlane_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private Button ButtonRef; + private Button ButtonDel; + private Button ButtonUpd; + private Button ButtonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private Button ButtonCancel; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormPlane.cs b/AircraftPlant/AircraftPlantView/FormPlane.cs new file mode 100644 index 0000000..c777e3e --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlane.cs @@ -0,0 +1,284 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.SearchModels; +using AircraftPlantDataModels.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; + +namespace AircraftPlantView +{ + /// + /// Форма для изделий + /// + public partial class FormPlane : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для изделий + /// + private readonly IPlaneLogic _logic; + + /// + /// Идентификатор + /// + private int? _id; + public int Id { set { _id = value; } } + + /// + /// Список компонентов изделия + /// + private Dictionary _planeComponents; + + /// + /// Конструктор + /// + /// + /// + public FormPlane(ILogger logger, IPlaneLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _planeComponents = new Dictionary(); + } + + /// + /// Загрузка списка компонентов изделия + /// + /// + /// + private void FormPlane_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new PlaneSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.PlaneName; + textBoxPrice.Text = view.Price.ToString(); + _planeComponents = view.PlaneComponents ?? new Dictionary(); + LoadData(); + } + } + 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(FormPlaneComponent)); + if (service is FormPlaneComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_planeComponents.ContainsKey(form.Id)) + { + _planeComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _planeComponents.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(FormPlaneComponent)); + if (service is FormPlaneComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _planeComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента:{ ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _planeComponents[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, dataGridView.SelectedRows[0].Cells[2].Value); + _planeComponents?.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 (_planeComponents == null || _planeComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new PlaneBindingModel + { + Id = _id ?? 0, + PlaneName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + PlaneComponents = _planeComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + /// + /// Кнопка "Отмена" + /// + /// + /// + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + /// + /// Метод загрузки компонентов изделия + /// + private void LoadData() + { + _logger.LogInformation("Загрузка компонентов изделия"); + try + { + if (_planeComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _planeComponents) + { + 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 double CalcPrice() + { + double price = 0; + foreach (var elem in _planeComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/AircraftPlant/AircraftPlantView/FormPlane.resx b/AircraftPlant/AircraftPlantView/FormPlane.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlane.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormPlaneComponent.Designer.cs b/AircraftPlant/AircraftPlantView/FormPlaneComponent.Designer.cs new file mode 100644 index 0000000..29fdd0e --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlaneComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace AircraftPlantView +{ + partial class FormPlaneComponent + { + /// + /// 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 20); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(69, 15); + this.label1.TabIndex = 0; + this.label1.Text = "Компонент"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(12, 54); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(72, 15); + this.label2.TabIndex = 1; + this.label2.Text = "Количество"; + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(101, 17); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(223, 23); + this.comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(101, 51); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(223, 23); + this.textBoxCount.TabIndex = 3; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(155, 96); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(75, 23); + this.ButtonSave.TabIndex = 4; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(249, 96); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 5; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormPlaneComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(340, 134); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormPlaneComponent"; + this.Text = "Компонент изделия"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormPlaneComponent.cs b/AircraftPlant/AircraftPlantView/FormPlaneComponent.cs new file mode 100644 index 0000000..4f1862d --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlaneComponent.cs @@ -0,0 +1,90 @@ +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 AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.ViewModels; +using AircraftPlantDataModels.Models; + +namespace AircraftPlantView +{ + public partial class FormPlaneComponent : 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 FormPlaneComponent(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(); + } + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormPlaneComponent.resx b/AircraftPlant/AircraftPlantView/FormPlaneComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlaneComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormPlanes.Designer.cs b/AircraftPlant/AircraftPlantView/FormPlanes.Designer.cs new file mode 100644 index 0000000..9ad513c --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlanes.Designer.cs @@ -0,0 +1,116 @@ +namespace AircraftPlantView +{ + partial class FormPlanes + { + /// + /// 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.dataGridViewPlanes = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewPlanes)).BeginInit(); + this.SuspendLayout(); + // + // dataGridViewPlanes + // + this.dataGridViewPlanes.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight; + this.dataGridViewPlanes.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridViewPlanes.GridColor = System.Drawing.SystemColors.ControlDarkDark; + this.dataGridViewPlanes.Location = new System.Drawing.Point(1, 2); + this.dataGridViewPlanes.Name = "dataGridViewPlanes"; + this.dataGridViewPlanes.RowTemplate.Height = 25; + this.dataGridViewPlanes.Size = new System.Drawing.Size(470, 446); + this.dataGridViewPlanes.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(500, 22); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(500, 69); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(500, 113); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(500, 160); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // FormPlanes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(603, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridViewPlanes); + this.Name = "FormPlanes"; + this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormPlanes_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewPlanes)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridViewPlanes; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormPlanes.cs b/AircraftPlant/AircraftPlantView/FormPlanes.cs new file mode 100644 index 0000000..2fb285c --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlanes.cs @@ -0,0 +1,158 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AircraftPlantView +{ + /// + /// Форма для вывода всех изделий + /// + public partial class FormPlanes : Form + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Бизнес-логика для изделий + /// + private readonly IPlaneLogic _logic; + + /// + /// Конструктор + /// + /// + /// + public FormPlanes(ILogger logger, IPlaneLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + /// + /// Загрузка списка изделий + /// + /// + /// + private void FormPlanes_Load(object sender, EventArgs e) + { + LoadData(); + } + + /// + /// Кнопка "Добавить" + /// + /// + /// + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPlane)); + if (service is FormPlane form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + /// + /// Кнопка "Изменить" + /// + /// + /// + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridViewPlanes.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPlane)); + if (service is FormPlane form) + { + form.Id = Convert.ToInt32(dataGridViewPlanes.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + /// + /// Кнопка "Удалить" + /// + /// + /// + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridViewPlanes.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewPlanes.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление изделия"); + try + { + if (!_logic.Delete(new PlaneBindingModel + { + 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(); + } + + /// + /// Метод загрузки списка изделий + /// + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridViewPlanes.DataSource = list; + dataGridViewPlanes.Columns["Id"].Visible = false; + dataGridViewPlanes.Columns["PlaneName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridViewPlanes.Columns["PlaneComponents"].Visible = false; + } + _logger.LogInformation("Загрузка изделий"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/AircraftPlant/AircraftPlantView/FormPlanes.resx b/AircraftPlant/AircraftPlantView/FormPlanes.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormPlanes.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/Program.cs b/AircraftPlant/AircraftPlantView/Program.cs index d11019f..90280e1 100644 --- a/AircraftPlant/AircraftPlantView/Program.cs +++ b/AircraftPlant/AircraftPlantView/Program.cs @@ -1,7 +1,22 @@ +using AircraftPlantBusinessLogic.BusinessLogics; +using AircraftPlantContracts.BusinessLogicsContracts; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System; + namespace AircraftPlantView { internal static class Program { + /// + /// IoC- + /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -11,7 +26,41 @@ namespace AircraftPlantView // 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()); + } + + /// + /// IoC- + /// + /// + 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/AircraftPlant/AircraftPlantView/nlog.config b/AircraftPlant/AircraftPlantView/nlog.config new file mode 100644 index 0000000..cfe664d --- /dev/null +++ b/AircraftPlant/AircraftPlantView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file