From 335a1b41f7e429da0368ba76296fc28b3e2673a6 Mon Sep 17 00:00:00 2001 From: song2remaster Date: Sun, 5 May 2024 21:43:24 +0400 Subject: [PATCH] done... --- .../Aparyan.ISE_22.MotorPlant.sln | 8 +- .../MotorPlantFileImplement/Component.cs | 59 +++ .../ComponentStorage.cs | 72 ++++ .../DataFileSingleton.cs | 53 +++ .../MotorPlantFileImplement/Engine.cs | 89 ++++ .../MotorPlantFileImplement/EngineStorage.cs | 71 +++ .../MotorPlantFileImplement.csproj | 9 + .../MotorPlantFileImplement/Order.cs | 88 ++++ .../MotorPlantFileImplement/OrderStorage.cs | 79 ++++ .../MotorPlantFileImplement/Shop.cs | 103 +++++ .../MotorPlantFileImplement/ShopStorage.cs | 145 +++++++ MoorPlantListImplement/DataListSingleton.cs | 39 +- .../Implements/OrderStorage.cs | 205 ++++----- .../Implements/ShopStorage.cs | 193 +++++---- MoorPlantListImplement/Models/Order.cs | 104 +++-- MoorPlantListImplement/Models/Shop.cs | 87 ++-- .../BusinessLogics/OrderLogic.cs | 237 +++++----- .../BusinessLogics/ShopLogic.cs | 309 ++++++++------ .../BindingModels/ShopBindingModel.cs | 17 +- .../BindingModels/SupplyBindingModel.cs | 16 + .../BusinessLogicsContracts/IOrderLogic.cs | 19 +- .../BusinessLogicsContracts/IShopLogic.cs | 20 +- .../SearchModels/ShopSearchModel.cs | 17 +- .../SearchModels/SupplySearchModel.cs | 14 + .../StoragesContracts/IOrderStorage.cs | 21 +- .../StoragesContracts/IShopStorage.cs | 4 +- .../ViewModels/OrderViewModel.cs | 49 +-- .../ViewModels/ShopViewModel.cs | 31 +- MotorPlantDataModels/Models/IShopModel.cs | 18 +- MotorPlantDataModels/Models/ISupplyModel.cs | 15 + MotorPlantView/FormCreateSupply.Designer.cs | 143 +++++++ MotorPlantView/FormCreateSupply.cs | 93 ++++ MotorPlantView/FormCreateSupply.resx | 120 ++++++ MotorPlantView/FormMain.Designer.cs | 403 +++++++++--------- MotorPlantView/FormMain.cs | 319 +++++++------- MotorPlantView/FormSellEngines.Designer.cs | 124 ++++++ MotorPlantView/FormSellEngines.cs | 82 ++++ MotorPlantView/FormSellEngines.resx | 120 ++++++ MotorPlantView/Program.cs | 85 ++-- 39 files changed, 2626 insertions(+), 1054 deletions(-) create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Component.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ComponentStorage.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Engine.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/EngineStorage.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Order.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/OrderStorage.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Shop.cs create mode 100644 Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ShopStorage.cs create mode 100644 MotorPlantContracts/BindingModels/SupplyBindingModel.cs create mode 100644 MotorPlantContracts/SearchModels/SupplySearchModel.cs create mode 100644 MotorPlantDataModels/Models/ISupplyModel.cs create mode 100644 MotorPlantView/FormCreateSupply.Designer.cs create mode 100644 MotorPlantView/FormCreateSupply.cs create mode 100644 MotorPlantView/FormCreateSupply.resx create mode 100644 MotorPlantView/FormSellEngines.Designer.cs create mode 100644 MotorPlantView/FormSellEngines.cs create mode 100644 MotorPlantView/FormSellEngines.resx diff --git a/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln b/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln index b834603..8b1fd33 100644 --- a/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln +++ b/Aparyan.ISE_22.MotorPlant/Aparyan.ISE_22.MotorPlant.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantListImplement", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantBusinessLogic", "..\MotorPlantBusinessLogic\MotorPlantBusinessLogic.csproj", "{BE9E33C8-F7AD-4952-80B8-68FAE35E0BDC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantView", "..\MotorPlantView\MotorPlantView.csproj", "{76FE3E67-6BFC-4C12-AD2F-2267F8986605}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantView", "..\MotorPlantView\MotorPlantView.csproj", "{76FE3E67-6BFC-4C12-AD2F-2267F8986605}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotorPlantFileImplement", "MotorPlantFileImplement\MotorPlantFileImplement.csproj", "{3216A68E-02C0-4B3E-A608-6CD4D4B12CB4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {76FE3E67-6BFC-4C12-AD2F-2267F8986605}.Debug|Any CPU.Build.0 = Debug|Any CPU {76FE3E67-6BFC-4C12-AD2F-2267F8986605}.Release|Any CPU.ActiveCfg = Release|Any CPU {76FE3E67-6BFC-4C12-AD2F-2267F8986605}.Release|Any CPU.Build.0 = Release|Any CPU + {3216A68E-02C0-4B3E-A608-6CD4D4B12CB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3216A68E-02C0-4B3E-A608-6CD4D4B12CB4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3216A68E-02C0-4B3E-A608-6CD4D4B12CB4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3216A68E-02C0-4B3E-A608-6CD4D4B12CB4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Component.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Component.cs new file mode 100644 index 0000000..5f29da5 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Component.cs @@ -0,0 +1,59 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System.Xml.Linq; + +namespace MotorPlantFileImplement.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 static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + 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 + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ComponentStorage.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ComponentStorage.cs new file mode 100644 index 0000000..fb47e04 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ComponentStorage.cs @@ -0,0 +1,72 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantFileImplement.Models; + +namespace MotorPlantFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} \ No newline at end of file diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..c5610e4 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/DataFileSingleton.cs @@ -0,0 +1,53 @@ +using MotorPlantFileImplement.Models; +using System.Xml.Linq; + +namespace MotorPlantFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string EngineFileName = "Engine.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Engines { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SaveEngines() => SaveData(Engines, EngineFileName, "Engines", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Engines = LoadData(EngineFileName, "Engine", x => Engine.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Engine.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Engine.cs new file mode 100644 index 0000000..5f283a5 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Engine.cs @@ -0,0 +1,89 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System.Xml.Linq; + +namespace MotorPlantFileImplement.Models +{ + public class Engine : IEngineModel + { + public int Id { get; private set; } + public string EngineName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _EngineComponents = null; + public Dictionary EngineComponents + { + get + { + if (_EngineComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _EngineComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _EngineComponents; + } + } + public static Engine? Create(EngineBindingModel model) + { + if (model == null) + { + return null; + } + return new Engine() + { + Id = model.Id, + EngineName = model.EngineName, + Price = model.Price, + Components = model.EngineComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Engine? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Engine() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + EngineName = element.Element("EngineName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("EngineComponents")!.Elements("EngineComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(EngineBindingModel model) + { + if (model == null) + { + return; + } + EngineName = model.EngineName; + Price = model.Price; + Components = model.EngineComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _EngineComponents = null; + } + public EngineViewModel GetViewModel => new() + { + Id = Id, + EngineName = EngineName, + Price = Price, + EngineComponents = EngineComponents + }; + public XElement GetXElement => new("Engine", + new XAttribute("Id", Id), + new XElement("EngineName", EngineName), + new XElement("Price", Price.ToString()), + new XElement("EngineComponents", Components.Select(x => new XElement("EngineComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))) + + .ToArray())); + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/EngineStorage.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/EngineStorage.cs new file mode 100644 index 0000000..393fd2d --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/EngineStorage.cs @@ -0,0 +1,71 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantFileImplement.Models; + +namespace MotorPlantFileImplement.Implements +{ + public class EngineStorage : IEngineStorage + { + private readonly DataFileSingleton source; + public EngineStorage() + { + source = DataFileSingleton.GetInstance(); + } + public EngineViewModel? GetElement(EngineSearchModel model) + { + if (string.IsNullOrEmpty(model.EngineName) && !model.Id.HasValue) + { + return null; + } + return source.Engines.FirstOrDefault(x => (!string.IsNullOrEmpty(model.EngineName) && x.EngineName == model.EngineName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public List GetFilteredList(EngineSearchModel model) + { + if (string.IsNullOrEmpty(model.EngineName)) + { + return new(); + } + return source.Engines.Where(x => x.EngineName.Contains(model.EngineName)).Select(x => x.GetViewModel).ToList(); + } + public List GetFullList() + { + return source.Engines.Select(x => x.GetViewModel).ToList(); + } + public EngineViewModel? Insert(EngineBindingModel model) + { + model.Id = source.Engines.Count > 0 ? source.Engines.Max(x => x.Id) + 1 : 1; + var newDoc = Engine.Create(model); + if (newDoc == null) + { + return null; + } + source.Engines.Add(newDoc); + source.SaveEngines(); + return newDoc.GetViewModel; + } + public EngineViewModel? Update(EngineBindingModel model) + { + var document = source.Engines.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveEngines(); + return document.GetViewModel; + } + public EngineViewModel? Delete(EngineBindingModel model) + { + var document = source.Engines.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveEngines(); + return document.GetViewModel; + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/MotorPlantFileImplement.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Order.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Order.cs new file mode 100644 index 0000000..7df5906 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Order.cs @@ -0,0 +1,88 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Enums; +using MotorPlantDataModels.Models; +using System.Xml.Linq; + +namespace MotorPlantFileImplement.Models +{ + public class Order : IOrderModel + { + public int EngineId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + EngineId = model.EngineId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + EngineId = Convert.ToInt32(element.Element("EngineId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + + order.DateImplement = dateImpl; + + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + EngineId = EngineId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("EngineId", EngineId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/OrderStorage.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/OrderStorage.cs new file mode 100644 index 0000000..8aff0bf --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/OrderStorage.cs @@ -0,0 +1,79 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantFileImplement.Models; + +namespace MotorPlantFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + } + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + } + public List GetFullList() + { + return source.Orders.Select(x => GetViewModel(x)).ToList(); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return GetViewModel(newOrder); + } + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + var engine = source.Engines.FirstOrDefault(x => x.Id == order.EngineId); + viewModel.EngineName = engine?.EngineName; + return viewModel; + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Shop.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Shop.cs new file mode 100644 index 0000000..344360d --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/Shop.cs @@ -0,0 +1,103 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace MotorPlantFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary Engines { get; private set; } = new(); + private Dictionary? _shopEngines = null; + public Dictionary ShopEngines + { + get + { + if (_shopEngines == null) + { + var source = DataFileSingleton.GetInstance(); + _shopEngines = Engines.ToDictionary(x => x.Key, y => ((source.Engines.FirstOrDefault(z => z.Id == y.Key) as IEngineModel)!, y.Value)); + } + return _shopEngines; + } + } + public int EngineMaxCount { get; private set; } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + Engines = model.ShopEngines.ToDictionary(x => x.Key, x => x.Value.Item2), + EngineMaxCount = model.EngineMaxCount + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Adress = element.Element("Adress")!.Value, + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Engines = element.Element("ShopEngines")!.Elements("ShopEngine")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)), + EngineMaxCount = Convert.ToInt32(element.Element("EngineMaxCount")!.Value) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + EngineMaxCount = model.EngineMaxCount; + Engines = model.ShopEngines.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopEngines = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopEngines = ShopEngines, + EngineMaxCount = EngineMaxCount + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopEngines", Engines.Select( + x => new XElement("ShopEngine", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()), + new XElement("EngineMaxCount", EngineMaxCount.ToString()) + ); + public void EnginesUpdate() + { + _shopEngines = null; + } + } +} diff --git a/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ShopStorage.cs b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ShopStorage.cs new file mode 100644 index 0000000..7323c04 --- /dev/null +++ b/Aparyan.ISE_22.MotorPlant/MotorPlantFileImplement/ShopStorage.cs @@ -0,0 +1,145 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + public bool Sale(SupplySearchModel model) + { + if (model == null || !model.EngineId.HasValue || !model.Count.HasValue) + return false; + int remainingSpace = source.Shops.Select(x => x.Engines.ContainsKey(model.EngineId.Value) ? x.Engines[model.EngineId.Value] : 0).Sum(); + if (remainingSpace < model.Count) + { + return false; + } + var shops = source.Shops.Where(x => x.Engines.ContainsKey(model.EngineId.Value)).OrderByDescending(x => x.Engines[model.EngineId.Value]).ToList(); + foreach (var shop in shops) + { + int residue = model.Count.Value - shop.Engines[model.EngineId.Value]; + if (residue > 0) + { + shop.Engines.Remove(model.EngineId.Value); + shop.EnginesUpdate(); + model.Count = residue; + } + else + { + if (residue == 0) + { + shop.Engines.Remove(model.EngineId.Value); + } + else + { + shop.Engines[model.EngineId.Value] = -residue; + } + shop.EnginesUpdate(); + source.SaveShops(); + return true; + } + } + source.SaveShops(); + return false; + } + public bool RestockingShops(SupplyBindingModel model) + { + if (model == null || source.Shops.Select(x => x.EngineMaxCount - x.ShopEngines.Select(y => y.Value.Item2).Sum()).Sum() < model.Count) + { + return false; + } + foreach (Shop shop in source.Shops) + { + int free_places = shop.EngineMaxCount - shop.ShopEngines.Select(x => x.Value.Item2).Sum(); + if (free_places <= 0) + continue; + free_places = Math.Min(free_places, model.Count); + model.Count -= free_places; + if (shop.Engines.ContainsKey(model.EngineId)) + { + shop.Engines[model.EngineId] += free_places; + } + else + { + shop.Engines.Add(model.EngineId, free_places); + } + shop.EnginesUpdate(); + if (model.Count == 0) + { + source.SaveShops(); + return true; + } + } + return false; + } + } +} diff --git a/MoorPlantListImplement/DataListSingleton.cs b/MoorPlantListImplement/DataListSingleton.cs index 25b459c..03edbaf 100644 --- a/MoorPlantListImplement/DataListSingleton.cs +++ b/MoorPlantListImplement/DataListSingleton.cs @@ -1,29 +1,28 @@ using MotorPlantListImplement.Models; + namespace MotorPlantListImplement { - public class DataListSingleton - { - private static DataListSingleton? _instance; - public List Components { get; set; } - public List Orders { get; set; } - public List Engines { get; set; } + public class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Engines { get; set; } public List Shops { get; set; } - private DataListSingleton() - { - Components = new List(); - Orders = new List(); - Engines = new List(); + { + Components = new List(); + Orders = new List(); + Engines = new List(); Shops = new List(); - } public static DataListSingleton GetInstance() - { - if (_instance == null) - { - _instance = new DataListSingleton(); - } - return _instance; - } - } + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } } diff --git a/MoorPlantListImplement/Implements/OrderStorage.cs b/MoorPlantListImplement/Implements/OrderStorage.cs index eccfcae..8a26836 100644 --- a/MoorPlantListImplement/Implements/OrderStorage.cs +++ b/MoorPlantListImplement/Implements/OrderStorage.cs @@ -1,103 +1,112 @@ -using MotorPlantContracts.StoragesContracts; -using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; +using MotorPlantContracts.ViewModels; using MotorPlantListImplement.Models; -using MotorPlantContracts.VeiwModels; + namespace MotorPlantListImplement.Implements { - public class OrderStorage : IOrderStorage - { - private readonly DataListSingleton _source; - public OrderStorage() - { - _source = DataListSingleton.GetInstance(); - } - public OrderViewModel? Delete(OrderBindingModel model) - { - for (int i = 0; i < _source.Orders.Count; ++i) - { - if (_source.Orders[i].Id == model.Id) - { - var element = _source.Orders[i]; - _source.Orders.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - foreach (var order in _source.Orders) - { - if (model.Id.HasValue && order.Id == model.Id) - { - return order.GetViewModel; - } - } - return null; - } - public List GetFilteredList(OrderSearchModel model) - { - var result = new List(); - - if (!model.Id.HasValue) - { - return result; - } - foreach (var order in _source.Orders) - { - if (model.Id.HasValue && order.Id == model.Id) - { - result.Add(order.GetViewModel); - } - } - return result; - } - public List GetFullList() - { - var result = new List(); - - foreach (var order in _source.Orders) - { - result.Add(order.GetViewModel); - } - return result; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = 1; - - foreach (var order in _source.Orders) - { - if (model.Id <= order.Id) - { - model.Id = order.Id + 1; - } - } - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - - _source.Orders.Add(newOrder); - return newOrder.GetViewModel; - } - public OrderViewModel? Update(OrderBindingModel model) - { - foreach (var order in _source.Orders) - { - if (order.Id == model.Id) - { - order.Update(model); - return order.GetViewModel; - } - } - return null; - } - } + public 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(AttachEngineName(order.GetViewModel)); + } + return result; + } + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachEngineName(order.GetViewModel)); + } + } + return result; + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return AttachEngineName(order.GetViewModel); + } + } + return null; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AttachEngineName(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachEngineName(order.GetViewModel); + } + } + return null; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AttachEngineName(element.GetViewModel); + } + } + return null; + } + private OrderViewModel AttachEngineName(OrderViewModel model) + { + foreach (var Engine in _source.Engines) + { + if (Engine.Id == model.EngineId) + { + model.EngineName = Engine.EngineName; + return model; + } + } + return model; + } + } } diff --git a/MoorPlantListImplement/Implements/ShopStorage.cs b/MoorPlantListImplement/Implements/ShopStorage.cs index 6ba0064..93c4a30 100644 --- a/MoorPlantListImplement/Implements/ShopStorage.cs +++ b/MoorPlantListImplement/Implements/ShopStorage.cs @@ -11,97 +11,104 @@ using System.Threading.Tasks; namespace MotorPlantListImplement.Implements { - public class ShopStorage : IShopStorage - { - private readonly DataListSingleton _source; - public ShopStorage() - { - _source = DataListSingleton.GetInstance(); - } - public List GetFullList() - { - var result = new List(); - foreach (var shop in _source.Shops) - { - result.Add(shop.GetViewModel); - } - return result; - } - public List GetFilteredList(ShopSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.Name)) - { - return result; - } - foreach (var shop in _source.Shops) - { - if (shop.ShopName.Contains(model.Name)) - { - result.Add(shop.GetViewModel); - } - } - return result; - } - public ShopViewModel? GetElement(ShopSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) - { - return null; - } - foreach (var shop in _source.Shops) - { - if ((!string.IsNullOrEmpty(model.Name) && - shop.ShopName == model.Name) || - (model.Id.HasValue && shop.Id == model.Id)) - { - return shop.GetViewModel; - } - } - return null; - } - public ShopViewModel? Insert(ShopBindingModel model) - { - model.Id = 1; - foreach (var shop in _source.Shops) - { - if (model.Id <= shop.Id) - { - model.Id = shop.Id + 1; - } - } - var newShop = Shop.Create(model); - if (newShop == null) - { - return null; - } - _source.Shops.Add(newShop); - return newShop.GetViewModel; - } - public ShopViewModel? Update(ShopBindingModel model) - { - foreach (var shop in _source.Shops) - { - if (shop.Id == model.Id) - { - shop.Update(model); - return shop.GetViewModel; - } - } - return null; - } - public ShopViewModel? Delete(ShopBindingModel model) - { - for (int i = 0; i < _source.Shops.Count; ++i) - { - if (_source.Shops[i].Id == model.Id) - { - var element = _source.Shops[i]; - _source.Shops.RemoveAt(i); - return element.GetViewModel; - } - } - return null; - } - } + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + public bool Sale(SupplySearchModel model) + { + throw new NotImplementedException(); + } + public bool RestockingShops(SupplyBindingModel model) + { + throw new NotImplementedException(); + } + } } diff --git a/MoorPlantListImplement/Models/Order.cs b/MoorPlantListImplement/Models/Order.cs index b07282f..2b17cec 100644 --- a/MoorPlantListImplement/Models/Order.cs +++ b/MoorPlantListImplement/Models/Order.cs @@ -1,62 +1,54 @@ using MotorPlantContracts.BindingModels; -using MotorPlantDataModels.Models; +using MotorPlantContracts.ViewModels; using MotorPlantDataModels.Enums; -using MotorPlantContracts.VeiwModels; +using MotorPlantDataModels.Models; namespace MotorPlantListImplement.Models { - public class Order : IOrderModel - { - public int EngineId { get; private set; } - public string EngineName { get; private set; } - public int Count { get; private set; } - public double Sum { get; private set; } - public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; - public DateTime DateCreate { get; private set; } = DateTime.Now; - public DateTime? DateImplement { get; private set; } - public int Id { get; private set; } - public static Order? Create(OrderBindingModel? model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - EngineId = model.EngineId, - EngineName = model.EngineName, - Count = model.Count, - Sum = model.Sum, - Status = model.Status, - DateCreate = model.DateCreate, - DateImplement = model.DateImplement - }; - } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - EngineId = model.EngineId; - EngineName = model.EngineName; - Count = model.Count; - Sum = model.Sum; - Status = model.Status; - DateCreate = model.DateCreate; - DateImplement = model.DateImplement; - } - public OrderViewModel GetViewModel => new() - { - Id = Id, - EngineId = EngineId, - EngineName = EngineName, - Count = Count, - Sum = Sum, - Status = Status, - DateCreate = DateCreate, - DateImplement = DateImplement - }; - } + public class Order : IOrderModel + { + public int Id { get; private set; } + public int EngineId { 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, + EngineId = model.EngineId, + 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, + EngineId = EngineId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } } diff --git a/MoorPlantListImplement/Models/Shop.cs b/MoorPlantListImplement/Models/Shop.cs index ef03e2e..6a9d981 100644 --- a/MoorPlantListImplement/Models/Shop.cs +++ b/MoorPlantListImplement/Models/Shop.cs @@ -9,46 +9,49 @@ using System.Threading.Tasks; namespace MotorPlantListImplement.Models { - public class Shop : IShopModel - { - public int Id { get; private set; } - public string ShopName { get; private set; } - public string Adress { get; private set; } - public DateTime DateOpen { get; private set; } - public Dictionary ShopEngines { get; private set; } = new(); - public static Shop? Create(ShopBindingModel model) - { - if (model == null) - { - return null; - } - return new Shop() - { - Id = model.Id, - ShopName = model.ShopName, - Adress = model.Adress, - DateOpen = model.DateOpen, - ShopEngines = new() - }; - } - public void Update(ShopBindingModel? model) - { - if (model == null) - { - return; - } - ShopName = model.ShopName; - Adress = model.Adress; - DateOpen = model.DateOpen; - ShopEngines = model.ShopEngines; - } - public ShopViewModel GetViewModel => new() - { - Id = Id, - ShopName = ShopName, - Adress = Adress, - DateOpen = DateOpen, - ShopEngines = ShopEngines - }; - } + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopEngines { get; private set; } = new(); + public int EngineMaxCount { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate, + EngineMaxCount = model.EngineMaxCount, + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + EngineMaxCount = model.EngineMaxCount; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopEngines = ShopEngines, + EngineMaxCount = EngineMaxCount, + }; + } } diff --git a/MotorPlantBusinessLogic/BusinessLogics/OrderLogic.cs b/MotorPlantBusinessLogic/BusinessLogics/OrderLogic.cs index f1d5d59..f7c4265 100644 --- a/MotorPlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/MotorPlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,115 +1,138 @@ -using Microsoft.Extensions.Logging; -using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.BusinessLogicsContracts; using MotorPlantContracts.SearchModels; using MotorPlantContracts.StoragesContracts; -using MotorPlantContracts.VeiwModels; +using MotorPlantContracts.ViewModels; +using Microsoft.Extensions.Logging; using MotorPlantDataModels.Enums; namespace MotorPlantBusinessLogic.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. OrderId:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) - return false; - model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool TakeOrderInWork(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выполняется); - } - public bool FinishOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Готов); - } - public bool DeliveryOrder(OrderBindingModel model) - { - return ChangeStatus(model, OrderStatus.Выдан); - } - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Count <= 0) - { - throw new ArgumentException("Колличество моторов в заказе не может быть меньше 1", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum)); - } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) - { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}"); - } - _logger.LogInformation("Engine. EngineId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", - model.EngineId, model.Count, model.Sum, model.Id); - } - private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() - { - Id = model.Id - }); - if (element == null) - { - throw new ArgumentNullException(nameof(element)); - } - model.DateCreate = element.DateCreate; - model.EngineId = element.EngineId; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - if (requiredStatus - model.Status == 1) - { - model.Status = requiredStatus; - if (model.Status == OrderStatus.Выдан) - model.DateImplement = DateTime.Now; - if (_orderStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - _logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus); - throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}"); - } - } + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) + { + _logger = logger; + _orderStorage = orderStorage; + _shopStorage = shopStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выполняется); + } + public bool FinishOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Готов); + } + public bool DeliveryOrder(OrderBindingModel model) + { + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id, + }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + EngineId = order.EngineId, + Count = order.Count + })) + { + throw new ArgumentException("Недостаточно места"); + } + return ToNextStatus(model, OrderStatus.Выдан); + } + public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + model.EngineId = element.EngineId; + model.DateCreate = element.DateCreate; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + if (model.Status != orderStatus - 1) + { + _logger.LogWarning("Status update to " + orderStatus + " operation failed"); + return false; + } + model.Status = orderStatus; + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Changing status operation faled"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Engine. EngineId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.EngineId, model.Count, model.Sum, model.Id); + } + } } diff --git a/MotorPlantBusinessLogic/BusinessLogics/ShopLogic.cs b/MotorPlantBusinessLogic/BusinessLogics/ShopLogic.cs index 479e5c3..1553a41 100644 --- a/MotorPlantBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/MotorPlantBusinessLogic/BusinessLogics/ShopLogic.cs @@ -11,146 +11,177 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace MotorPlantBusinessLogic.BusinessLogic +namespace MotorPlantBusinessLogic.BusinessLogics { - public class ShopLogic : IShopLogic - { - private readonly ILogger _logger; - private readonly IShopStorage _shopStorage; - public ShopLogic(ILogger logger, IShopStorage shopStorage) - { - _logger = logger; - _shopStorage = shopStorage; - } - public List ReadList(ShopSearchModel model) - { - _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, model?.Id); - var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ShopViewModel ReadElement(ShopSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); - var element = _shopStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly IEngineStorage _EngineStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage, IEngineStorage EngineStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _EngineStorage = EngineStorage; + } + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.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(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopEngines.ContainsKey(model.EngineId)) + { + var oldValue = shop.ShopEngines[model.EngineId]; + oldValue.Item2 += model.Count; + shop.ShopEngines[model.EngineId] = oldValue; + } + else + { + var Engine = _EngineStorage.GetElement(new EngineSearchModel + { + Id = model.EngineId + }); + if (Engine == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.EngineId} не найденн"); + } + if (shop.ShopEngines.Sum(kv => kv.Value.Item2) + model.Count > shop.EngineMaxCount) + { + throw new ArgumentException("Превышена максимальная вместимость магазина"); + } + shop.ShopEngines.Add(model.EngineId, (Engine, model.Count)); + } + _shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + ShopEngines = shop.ShopEngines, + EngineMaxCount = shop.EngineMaxCount, + }); - public bool Create(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + return true; + } + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + public bool Sale(SupplySearchModel model) + { + if (!model.EngineId.HasValue || !model.Count.HasValue) + { + return false; + } + _logger.LogInformation("Check Engine count in all shops"); + if (_shopStorage.Sale(model)) + { + _logger.LogInformation("Selling sucsess"); + return true; + } + _logger.LogInformation("Selling failed"); + return false; + } - public bool Update(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ShopBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_shopStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - - private void CheckModel(ShopBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentNullException("Нет названия магазина", - nameof(model.ShopName)); - } - if (string.IsNullOrEmpty(model.Adress)) - { - throw new ArgumentNullException("Нет адресса магазина", - nameof(model.ShopName)); - } - if (model.DateOpen == null) - { - throw new ArgumentNullException("Нет даты открытия магазина", - nameof(model.ShopName)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Adress, model.DateOpen, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - Name = model.ShopName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Магазин с таким названием уже есть"); - } - } - public bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (engine == null) - throw new ArgumentNullException(nameof(engine)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - ShopViewModel? curModel = _shopStorage.GetElement(model); - _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}", model.Id, model.Name); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopEngines.TryGetValue(engine.Id, out var pair)) - { - curModel.ShopEngines[engine.Id] = (pair.Item1, pair.Item2 + count); - _logger.LogInformation("Make Supply. Add Engine. EngineName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); - } - else - { - curModel.ShopEngines.Add(engine.Id, (engine, count)); - _logger.LogInformation("Make Supply. Add new Engine. EngineName: {Name}. Count: {Count}", pair.Item1, count); - } - - return Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Adress = curModel.Adress, - ShopEngines = curModel.ShopEngines, - }); - } - } + public bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count) + { + throw new NotImplementedException(); + } + } } diff --git a/MotorPlantContracts/BindingModels/ShopBindingModel.cs b/MotorPlantContracts/BindingModels/ShopBindingModel.cs index 855a76f..b51eed2 100644 --- a/MotorPlantContracts/BindingModels/ShopBindingModel.cs +++ b/MotorPlantContracts/BindingModels/ShopBindingModel.cs @@ -7,12 +7,13 @@ using System.Threading.Tasks; namespace MotorPlantContracts.BindingModels { - public class ShopBindingModel : IShopModel - { - public int Id { get; set; } - public string ShopName { get; set; } - public string Adress { get; set; } - public DateTime DateOpen { get; set; } - public Dictionary ShopEngines { get; set; } = new(); - } + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopEngines { get; set; } = new(); + public int EngineMaxCount { get; set; } + } } diff --git a/MotorPlantContracts/BindingModels/SupplyBindingModel.cs b/MotorPlantContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..332cfee --- /dev/null +++ b/MotorPlantContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using MotorPlantDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int EngineId { get; set; } + public int Count { get; set; } + } +} diff --git a/MotorPlantContracts/BusinessLogicsContracts/IOrderLogic.cs b/MotorPlantContracts/BusinessLogicsContracts/IOrderLogic.cs index 39b8bda..4f08f38 100644 --- a/MotorPlantContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/MotorPlantContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,16 +1,15 @@ using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; -using MotorPlantContracts.VeiwModels; +using MotorPlantContracts.ViewModels; namespace MotorPlantContracts.BusinessLogicsContracts { - public interface IOrderLogic - { - List? ReadList(OrderSearchModel? model); - bool CreateOrder(OrderBindingModel model); - bool TakeOrderInWork(OrderBindingModel model); - bool FinishOrder(OrderBindingModel model); - bool DeliveryOrder(OrderBindingModel model); - - } + 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/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs b/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs index 919d97f..55b238f 100644 --- a/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/MotorPlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -10,13 +10,15 @@ using System.Threading.Tasks; namespace MotorPlantContracts.BusinessLogicsContracts { - public interface IShopLogic - { - List? ReadList(ShopSearchModel? model); - ShopViewModel? ReadElement(ShopSearchModel? model); - bool Create(ShopBindingModel? model); - bool Update(ShopBindingModel? model); - bool Delete(ShopBindingModel? model); - bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count); - } + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool Sale(SupplySearchModel model); + bool MakeSupply(ShopSearchModel model, IEngineModel engine, int count); + + } } diff --git a/MotorPlantContracts/SearchModels/ShopSearchModel.cs b/MotorPlantContracts/SearchModels/ShopSearchModel.cs index 470bafb..b117a2f 100644 --- a/MotorPlantContracts/SearchModels/ShopSearchModel.cs +++ b/MotorPlantContracts/SearchModels/ShopSearchModel.cs @@ -1,14 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - + namespace MotorPlantContracts.SearchModels { - public class ShopSearchModel - { - public int? Id { get; set; } - public string? Name { get; set; } - } + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } } diff --git a/MotorPlantContracts/SearchModels/SupplySearchModel.cs b/MotorPlantContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..b7dc7e7 --- /dev/null +++ b/MotorPlantContracts/SearchModels/SupplySearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantContracts.SearchModels +{ + public class SupplySearchModel + { + public int? EngineId { get; set; } + public int? Count { get; set; } + } +} diff --git a/MotorPlantContracts/StoragesContracts/IOrderStorage.cs b/MotorPlantContracts/StoragesContracts/IOrderStorage.cs index b4b196c..9f195e3 100644 --- a/MotorPlantContracts/StoragesContracts/IOrderStorage.cs +++ b/MotorPlantContracts/StoragesContracts/IOrderStorage.cs @@ -1,17 +1,16 @@ using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; -using MotorPlantContracts.VeiwModels; - +using MotorPlantContracts.ViewModels; namespace MotorPlantContracts.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); - } + 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/MotorPlantContracts/StoragesContracts/IShopStorage.cs b/MotorPlantContracts/StoragesContracts/IShopStorage.cs index 48c46db..e578fde 100644 --- a/MotorPlantContracts/StoragesContracts/IShopStorage.cs +++ b/MotorPlantContracts/StoragesContracts/IShopStorage.cs @@ -17,5 +17,7 @@ namespace MotorPlantContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - } + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); + } } diff --git a/MotorPlantContracts/ViewModels/OrderViewModel.cs b/MotorPlantContracts/ViewModels/OrderViewModel.cs index 7024c25..946d5e7 100644 --- a/MotorPlantContracts/ViewModels/OrderViewModel.cs +++ b/MotorPlantContracts/ViewModels/OrderViewModel.cs @@ -1,33 +1,26 @@ using MotorPlantDataModels.Enums; using MotorPlantDataModels.Models; using System.ComponentModel; -namespace MotorPlantContracts.VeiwModels + +namespace MotorPlantContracts.ViewModels { - public class OrderViewModel : IOrderModel - { - [DisplayName("Номер")] - public int Id { get; set; } - - public int EngineId { get; set; } - - [DisplayName("Изделие")] - public string EngineName { 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; } - } - } - + public class OrderViewModel : IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int EngineId { get; set; } + [DisplayName("Изделие")] + public string EngineName { 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/MotorPlantContracts/ViewModels/ShopViewModel.cs b/MotorPlantContracts/ViewModels/ShopViewModel.cs index 4cd1610..a11508c 100644 --- a/MotorPlantContracts/ViewModels/ShopViewModel.cs +++ b/MotorPlantContracts/ViewModels/ShopViewModel.cs @@ -8,22 +8,17 @@ using System.Threading.Tasks; namespace MotorPlantContracts.ViewModels { - public class ShopViewModel : IShopModel - { - public int Id { get; set; } - - [DisplayName("Название магазина")] - - public string ShopName { get; set; } = string.Empty; - - [DisplayName("Адрес")] - - public string Adress { get; set; } = string.Empty; - - [DisplayName("Дата открытия")] - - public DateTime DateOpen { get; set; } - - public Dictionary ShopEngines { get; set; } = new(); - } + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopEngines { get; set; } = new(); + [DisplayName("Вместимость")] + public int EngineMaxCount { get; set; } + } } diff --git a/MotorPlantDataModels/Models/IShopModel.cs b/MotorPlantDataModels/Models/IShopModel.cs index 7552320..cda7239 100644 --- a/MotorPlantDataModels/Models/IShopModel.cs +++ b/MotorPlantDataModels/Models/IShopModel.cs @@ -1,4 +1,6 @@ -using System; +using MotorPlantDataModels; +using MotorPlantDataModels.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,10 +8,12 @@ using System.Threading.Tasks; namespace MotorPlantDataModels.Models { - public interface IShopModel : IId - { - string ShopName { get; } - string Adress { get; } - DateTime DateOpen { get; } - } + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopEngines { get; } + public int EngineMaxCount { get; } + } } diff --git a/MotorPlantDataModels/Models/ISupplyModel.cs b/MotorPlantDataModels/Models/ISupplyModel.cs new file mode 100644 index 0000000..f243749 --- /dev/null +++ b/MotorPlantDataModels/Models/ISupplyModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorPlantDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int EngineId { get; } + int Count { get; } + } +} diff --git a/MotorPlantView/FormCreateSupply.Designer.cs b/MotorPlantView/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..d66a9fb --- /dev/null +++ b/MotorPlantView/FormCreateSupply.Designer.cs @@ -0,0 +1,143 @@ +namespace MotorPlantView.Forms +{ + partial class FormCreateSupply + { + /// + /// 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.labelShop = new System.Windows.Forms.Label(); + this.labelEngine = new System.Windows.Forms.Label(); + this.comboBoxEngine = new System.Windows.Forms.ComboBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(115, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(344, 28); + this.comboBoxShop.TabIndex = 0; + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 15); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(76, 20); + this.labelShop.TabIndex = 1; + this.labelShop.Text = "Магазин: "; + // + // labelEngine + // + this.labelEngine.AutoSize = true; + this.labelEngine.Location = new System.Drawing.Point(12, 49); + this.labelEngine.Name = "labelEngine"; + this.labelEngine.Size = new System.Drawing.Size(75, 20); + this.labelEngine.TabIndex = 2; + this.labelEngine.Text = "Изделие: "; + // + // comboBoxEngine + // + this.comboBoxEngine.FormattingEnabled = true; + this.comboBoxEngine.Location = new System.Drawing.Point(115, 46); + this.comboBoxEngine.Name = "comboBoxEngine"; + this.comboBoxEngine.Size = new System.Drawing.Size(344, 28); + this.comboBoxEngine.TabIndex = 3; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 83); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(97, 20); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество: "; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(115, 80); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(344, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(300, 113); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(116, 39); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(168, 113); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(116, 39); + this.buttonSave.TabIndex = 7; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormCreateSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(471, 164); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.comboBoxEngine); + this.Controls.Add(this.labelEngine); + this.Controls.Add(this.labelShop); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormCreateSupply"; + this.Text = "Создание поставки"; + this.Load += new System.EventHandler(this.FormCreateSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private Label labelShop; + private Label labelEngine; + private ComboBox comboBoxEngine; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/MotorPlantView/FormCreateSupply.cs b/MotorPlantView/FormCreateSupply.cs new file mode 100644 index 0000000..444d84d --- /dev/null +++ b/MotorPlantView/FormCreateSupply.cs @@ -0,0 +1,93 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.ViewModels; +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 MotorPlantView.Forms +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly IEngineLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _EngineList = new List(); + public FormCreateSupply(ILogger logger, IEngineLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _EngineList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_EngineList != null) + { + comboBoxEngine.DisplayMember = "EngineName"; + comboBoxEngine.ValueMember = "Id"; + comboBoxEngine.DataSource = _EngineList; + comboBoxEngine.SelectedItem = null; + _logger.LogInformation("Загрузка двигателей для поставок"); + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxEngine.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/MotorPlantView/FormCreateSupply.resx b/MotorPlantView/FormCreateSupply.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MotorPlantView/FormCreateSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MotorPlantView/FormMain.Designer.cs b/MotorPlantView/FormMain.Designer.cs index ae78275..fd8cd1f 100644 --- a/MotorPlantView/FormMain.Designer.cs +++ b/MotorPlantView/FormMain.Designer.cs @@ -1,206 +1,213 @@ namespace MotorPlantView.Forms { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + 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); - } + /// + /// 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 + #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() - { - toolStrip1 = new ToolStrip(); - toolStripDropDownButton1 = new ToolStripDropDownButton(); - КомпонентыToolStripMenuItem = new ToolStripMenuItem(); - ДвигателиToolStripMenuItem = new ToolStripMenuItem(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - поставкиToolStripMenuItem = new ToolStripMenuItem(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - dataGridView = new DataGridView(); - toolStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // toolStrip1 - // - toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); - toolStrip1.Location = new Point(0, 0); - toolStrip1.Name = "toolStrip1"; - toolStrip1.Size = new Size(985, 25); - toolStrip1.TabIndex = 0; - toolStrip1.Text = "toolStrip1"; - // - // toolStripDropDownButton1 - // - toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, ShopsToolStripMenuItem, поставкиToolStripMenuItem }); - toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; - toolStripDropDownButton1.Name = "toolStripDropDownButton1"; - toolStripDropDownButton1.Size = new Size(90, 22); - toolStripDropDownButton1.Text = "Справочник"; - // - // КомпонентыToolStripMenuItem - // - КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - КомпонентыToolStripMenuItem.Size = new Size(148, 22); - КомпонентыToolStripMenuItem.Text = "Компоненты"; - КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; - // - // ДвигателиToolStripMenuItem - // - ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; - ДвигателиToolStripMenuItem.Size = new Size(148, 22); - ДвигателиToolStripMenuItem.Text = "Двигатели"; - ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; - // - // ShopsToolStripMenuItem - // - ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(148, 22); - ShopsToolStripMenuItem.Text = "Магазины"; - ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // поставкиToolStripMenuItem - // - поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; - поставкиToolStripMenuItem.Size = new Size(148, 22); - поставкиToolStripMenuItem.Text = "Поставки"; - поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; - // - // buttonCreateOrder - // - buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonCreateOrder.BackColor = SystemColors.ControlLight; - buttonCreateOrder.Location = new Point(860, 114); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(87, 48); - buttonCreateOrder.TabIndex = 1; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = false; - buttonCreateOrder.Click += buttonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonTakeOrderInWork.BackColor = SystemColors.ControlLight; - buttonTakeOrderInWork.Location = new Point(860, 178); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(87, 48); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = false; - buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonOrderReady.BackColor = SystemColors.ControlLight; - buttonOrderReady.Location = new Point(860, 245); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(87, 48); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = false; - buttonOrderReady.Click += buttonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.BackColor = SystemColors.ControlLight; - buttonIssuedOrder.Location = new Point(860, 311); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(87, 48); - buttonIssuedOrder.TabIndex = 4; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = false; - buttonIssuedOrder.Click += buttonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRef.BackColor = SystemColors.ControlLight; - buttonRef.Location = new Point(860, 60); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(87, 48); - buttonRef.TabIndex = 5; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = false; - buttonRef.Click += buttonRef_Click; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.BackgroundColor = SystemColors.ButtonHighlight; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(11, 28); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 24; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(780, 441); - dataGridView.TabIndex = 6; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(985, 467); - Controls.Add(dataGridView); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(toolStrip1); - Name = "FormMain"; - Text = "Моторный завод"; - Load += FormMain_Load; - toolStrip1.ResumeLayout(false); - toolStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + КомпонентыToolStripMenuItem = new ToolStripMenuItem(); + ДвигателиToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + operationToolStripMenuItem = new ToolStripMenuItem(); + transactionToolStripMenuItem = new ToolStripMenuItem(); + продажаToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + toolStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, operationToolStripMenuItem }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(969, 25); + toolStrip1.TabIndex = 0; + toolStrip1.Text = "toolStrip1"; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыToolStripMenuItem, ДвигателиToolStripMenuItem, магазиныToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(88, 22); + toolStripDropDownButton1.Text = "Справочник"; + // + // КомпонентыToolStripMenuItem + // + КомпонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + КомпонентыToolStripMenuItem.Size = new Size(180, 22); + КомпонентыToolStripMenuItem.Text = "Компоненты"; + КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; + // + // ДвигателиToolStripMenuItem + // + ДвигателиToolStripMenuItem.Name = "ДвигателиToolStripMenuItem"; + ДвигателиToolStripMenuItem.Size = new Size(180, 22); + ДвигателиToolStripMenuItem.Text = "Двигатели"; + ДвигателиToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(800, 56); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(141, 24); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(800, 100); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(141, 24); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(800, 142); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(141, 24); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(800, 181); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(141, 24); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(800, 222); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(141, 24); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(763, 435); + dataGridView.TabIndex = 6; + // + // operationToolStripMenuItem + // + operationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { transactionToolStripMenuItem, продажаToolStripMenuItem }); + operationToolStripMenuItem.Name = "operationToolStripMenuItem"; + operationToolStripMenuItem.Size = new Size(75, 25); + operationToolStripMenuItem.Text = "Операции"; + // + // transactionToolStripMenuItem + // + transactionToolStripMenuItem.Name = "transactionToolStripMenuItem"; + transactionToolStripMenuItem.Size = new Size(180, 22); + transactionToolStripMenuItem.Text = "Поставка"; + transactionToolStripMenuItem.Click += transactionToolStripMenuItem_Click; + // + // продажаToolStripMenuItem + // + продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + продажаToolStripMenuItem.Size = new Size(180, 22); + продажаToolStripMenuItem.Text = "Продажа"; + продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(180, 22); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(969, 461); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(toolStrip1); + Name = "FormMain"; + Text = "Моторный завод"; + Load += FormMain_Load; + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private ToolStrip toolStrip1; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonRef; - private DataGridView dataGridView; - private ToolStripDropDownButton toolStripDropDownButton1; - private ToolStripMenuItem КомпонентыToolStripMenuItem; - private ToolStripMenuItem ДвигателиToolStripMenuItem; - private ToolStripMenuItem ShopsToolStripMenuItem; - private ToolStripMenuItem поставкиToolStripMenuItem; - } + private ToolStrip toolStrip1; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private DataGridView dataGridView; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem КомпонентыToolStripMenuItem; + private ToolStripMenuItem ДвигателиToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem operationToolStripMenuItem; + private ToolStripMenuItem transactionToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; + } } \ No newline at end of file diff --git a/MotorPlantView/FormMain.cs b/MotorPlantView/FormMain.cs index d35c54f..4c036a0 100644 --- a/MotorPlantView/FormMain.cs +++ b/MotorPlantView/FormMain.cs @@ -1,167 +1,170 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using MotorPlantContracts.BindingModels; using MotorPlantContracts.BusinessLogicsContracts; -using MotorPlantView; namespace MotorPlantView.Forms { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation(" "); - try - { - var list = _orderLogic.ReadList(null); + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["EngineId"].Visible = false; - dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["EngineId"].Visible = false; + dataGridView.Columns["EngineName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } - _logger.LogInformation(" "); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - } - } - private void ToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + } + } + 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(FormEngines)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void ToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormEngines)); - - if (service is FormEngines 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.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception(" . ."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - 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(" . ."); - } - _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 ShopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - - if (service is FormShops form) - { - form.ShowDialog(); - } - } - - private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); - - if (service is FormSupply form) - { - form.ShowDialog(); - } - } - } + if (service is FormEngines 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.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + 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("Ошибка при сохранении. Дополнительная информация в логах."); + } + _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 shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellEngines)); + if (service is FormSellEngines form) + { + form.ShowDialog(); + } + } + } } diff --git a/MotorPlantView/FormSellEngines.Designer.cs b/MotorPlantView/FormSellEngines.Designer.cs new file mode 100644 index 0000000..4cf010d --- /dev/null +++ b/MotorPlantView/FormSellEngines.Designer.cs @@ -0,0 +1,124 @@ +namespace MotorPlantView.Forms +{ + partial class FormSellEngines + { + /// + /// 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() + { + labelEngine = new Label(); + comboBoxEngine = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonSell = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelEngine + // + labelEngine.AutoSize = true; + labelEngine.Location = new Point(10, 10); + labelEngine.Name = "labelEngine"; + labelEngine.Size = new Size(69, 15); + labelEngine.TabIndex = 0; + labelEngine.Text = "Двигатель: "; + // + // comboBoxEngine + // + comboBoxEngine.FormattingEnabled = true; + comboBoxEngine.Location = new Point(101, 8); + comboBoxEngine.Margin = new Padding(3, 2, 3, 2); + comboBoxEngine.Name = "comboBoxEngine"; + comboBoxEngine.Size = new Size(210, 23); + comboBoxEngine.TabIndex = 1; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(10, 41); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(78, 15); + labelCount.TabIndex = 2; + labelCount.Text = "Количество: "; + // + // textBoxCount + // + textBoxCount.Location = new Point(101, 39); + textBoxCount.Margin = new Padding(3, 2, 3, 2); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(210, 23); + textBoxCount.TabIndex = 3; + // + // buttonSell + // + buttonSell.Location = new Point(112, 74); + buttonSell.Margin = new Padding(3, 2, 3, 2); + buttonSell.Name = "buttonSell"; + buttonSell.Size = new Size(82, 22); + buttonSell.TabIndex = 4; + buttonSell.Text = "Продать"; + buttonSell.UseVisualStyleBackColor = true; + buttonSell.Click += ButtonSell_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(212, 74); + buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(82, 22); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSellEngines + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(320, 105); + Controls.Add(buttonCancel); + Controls.Add(buttonSell); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxEngine); + Controls.Add(labelEngine); + Margin = new Padding(3, 2, 3, 2); + Name = "FormSellEngines"; + Text = "Продажа двигателей"; + Load += FormSellingEngine_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelEngine; + private ComboBox comboBoxEngine; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/MotorPlantView/FormSellEngines.cs b/MotorPlantView/FormSellEngines.cs new file mode 100644 index 0000000..397170e --- /dev/null +++ b/MotorPlantView/FormSellEngines.cs @@ -0,0 +1,82 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +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 MotorPlantView.Forms +{ + public partial class FormSellEngines : Form + { + private readonly ILogger _logger; + private readonly IEngineLogic _logicP; + private readonly IShopLogic _logicS; + private List _EngineList = new List(); + public FormSellEngines(ILogger logger, IEngineLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + private void FormSellingEngine_Load(object sender, EventArgs e) + { + _EngineList = _logicP.ReadList(null); + if (_EngineList != null) + { + comboBoxEngine.DisplayMember = "EngineName"; + comboBoxEngine.ValueMember = "Id"; + comboBoxEngine.DataSource = _EngineList; + comboBoxEngine.SelectedItem = null; + _logger.LogInformation("Загрузка двигателей для продажи"); + } + } + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxEngine.SelectedValue == null) + { + MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание покупки"); + try + { + bool resout = _logicS.Sale(new SupplySearchModel + { + EngineId = Convert.ToInt32(comboBoxEngine.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (resout) + { + _logger.LogInformation("Проверка пройдена, продажа проведена"); + MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + else + { + _logger.LogInformation("Проверка не пройдена"); + MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + } + 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/MotorPlantView/FormSellEngines.resx b/MotorPlantView/FormSellEngines.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlantView/FormSellEngines.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MotorPlantView/Program.cs b/MotorPlantView/Program.cs index f1ef3c5..3ef4066 100644 --- a/MotorPlantView/Program.cs +++ b/MotorPlantView/Program.cs @@ -1,54 +1,61 @@ -using Microsoft.Extensions.DependencyInjection; using MotorPlantContracts.BusinessLogicsContracts; using MotorPlantContracts.StoragesContracts; -using MotorPlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using MotorPlantBusinessLogic.BusinessLogics; using MotorPlantBusinessLogic.BusinessLogic; -using MotorPlantView.Forms; +using MotorPlantListImplement.Implements; -namespace MotorPlantView +namespace MotorPlantView.Forms { - internal static class Program - { - private static ServiceProvider? _serviceProvider; - public static ServiceProvider? ServiceProvider => _serviceProvider; - [STAThread] - static void Main() - { - ApplicationConfiguration.Initialize(); - var services = new ServiceCollection(); - ConfigureServices(services); - _serviceProvider = services.BuildServiceProvider(); - Application.Run(_serviceProvider.GetRequiredService()); - } + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); - 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(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } - } + } } \ No newline at end of file