From d862c865214984a9302b1d3230eb617dfbff338b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Tue, 21 Feb 2023 00:38:10 +0400 Subject: [PATCH 01/11] lab2Complete --- PrecastConcretePlant/PrecastConcretePlant.sln | 6 ++ .../PrecastConcretePlantView.csproj | 1 + .../PrecastConcretePlant/Program.cs | 11 ++- .../ReinforcedLogic.cs | 2 +- .../Component.cs | 62 +++++++++++++ .../ComponentStorage.cs | 80 +++++++++++++++++ .../DataFileSingleton.cs | 50 +++++++++++ .../Order.cs | 90 +++++++++++++++++++ .../OrderStorage.cs | 76 ++++++++++++++++ .../PrecastConcretePlantFileImplement.csproj | 14 +++ .../Reinforced.cs | 86 ++++++++++++++++++ .../ReinforcedStorage.cs | 85 ++++++++++++++++++ 12 files changed, 556 insertions(+), 7 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant.sln b/PrecastConcretePlant/PrecastConcretePlant.sln index eb09aac..bed8fc1 100644 --- a/PrecastConcretePlant/PrecastConcretePlant.sln +++ b/PrecastConcretePlant/PrecastConcretePlant.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantBusines EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantListImplement", "PrecastConcretePlantListImplement\PrecastConcretePlantListImplement.csproj", "{471A4697-59C0-40C0-8B5E-8BEC01BD20BD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantFileImplement", "PrecastConcretePlantFileImplement\PrecastConcretePlantFileImplement.csproj", "{6251B4B7-A78D-458B-A926-FD0A8DF31076}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {471A4697-59C0-40C0-8B5E-8BEC01BD20BD}.Debug|Any CPU.Build.0 = Debug|Any CPU {471A4697-59C0-40C0-8B5E-8BEC01BD20BD}.Release|Any CPU.ActiveCfg = Release|Any CPU {471A4697-59C0-40C0-8B5E-8BEC01BD20BD}.Release|Any CPU.Build.0 = Release|Any CPU + {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6251B4B7-A78D-458B-A926-FD0A8DF31076}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj b/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj index 9ebf5ea..34aaa18 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj +++ b/PrecastConcretePlant/PrecastConcretePlant/PrecastConcretePlantView.csproj @@ -16,6 +16,7 @@ + diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 523f664..bcfe3c4 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -1,13 +1,12 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; +using PrecastConcretePlantFileImplement.Implements; using PrecastConcretePlantBusinessLogic.BusinessLogic; using PrecastConcretePlantContracts.BusinessLogicsContracts; using PrecastConcretePlantContracts.StoragesContract; -using PrecastConcretePlantListImplement.Implements; -using PrecastConcretePlantListImplement; +using PrecastConcretePlantFileImplement; using PrecastConcretePlantView; -using ConfectioneryBusinessLogic.BusinessLogic; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; namespace PrecastConcretePlant diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReinforcedLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReinforcedLogic.cs index 65224b3..bbb5bae 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReinforcedLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ReinforcedLogic.cs @@ -5,7 +5,7 @@ using PrecastConcretePlantContracts.StoragesContract; using PrecastConcretePlantContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace ConfectioneryBusinessLogic.BusinessLogic +namespace PrecastConcretePlantBusinessLogic.BusinessLogic { public class ReinforcedLogic : IReinforcedLogic { diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs new file mode 100644 index 0000000..00c37c8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Component.cs @@ -0,0 +1,62 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System.Xml.Linq; + + + +namespace PrecastConcretePlantFileImplement.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs new file mode 100644 index 0000000..37c3ae8 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ComponentStorage.cs @@ -0,0 +1,80 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContract; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; + +namespace PrecastConcretePlantFileImplement.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; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..5ae7a7d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -0,0 +1,50 @@ +using PrecastConcretePlantFileImplement.Models; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string ReinforcedFileName = "Reinforced.xml"; + public List Components { get; set; } + public List Orders { get; set; } + public List Reinforceds { get; 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 SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.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/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs new file mode 100644 index 0000000..e71490b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Order.cs @@ -0,0 +1,90 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Enums; +using PrecastConcretePlantDataModels.Models; +using System.Xml.Linq; + + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ReinforcedId { 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() + { + ReinforcedId = model.ReinforcedId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var dateImplement = element.Element("DateImplement")!.Value; + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value), + ReinforcedId = Convert.ToInt32(element.Element("ReinforcedId")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(dateImplement) ? null : Convert.ToDateTime(dateImplement), + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + ReinforcedId = ReinforcedId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + }; + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ReinforcedId", ReinforcedId), + new XElement("Count", Count), + new XElement("Sum", Sum.ToString()), + new XElement("Status", (int)Status), + new XElement("DateCreate", DateCreate), + new XElement("DateImplement", DateImplement) +); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs new file mode 100644 index 0000000..c9c760f --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/OrderStorage.cs @@ -0,0 +1,76 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContract; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; + +namespace PrecastConcretePlantFileImplement +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton _source; + public OrderStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Orders.Remove(element); + _source.SaveOrders(); + return element.GetViewModel; + } + return null; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return _source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = GetElement(model); + return result != null ? new() { result } : new(); + } + + public List GetFullList() + { + return _source.Orders + .Select(x => x.GetViewModel) + .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 newOrder.GetViewModel; + } + + 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 order.GetViewModel; + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj new file mode 100644 index 0000000..3b2c1a9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/PrecastConcretePlantFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs new file mode 100644 index 0000000..a710fb4 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Reinforced.cs @@ -0,0 +1,86 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement.Models +{ + public class Reinforced : IReinforcedModel + { + public int Id { get; private set; } + public string ReinforcedName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _ReinforcedComponents = null; + public Dictionary ReinforcedComponents + { + get + { + if (_ReinforcedComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _ReinforcedComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _ReinforcedComponents; + } + } + public static Reinforced? Create(ReinforcedBindingModel model) + { + if (model == null) + { + return null; + } + return new Reinforced() + { + Id = model.Id, + ReinforcedName = model.ReinforcedName, + Price = model.Price, + Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Reinforced? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Reinforced() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ReinforcedName = element.Element("ReinforcedName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("ReinforcedComponents")!.Elements("ReinforcedComponent").ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ReinforcedBindingModel model) + { + if (model == null) + { + return; + } + ReinforcedName = model.ReinforcedName; + Price = model.Price; + Components = model.ReinforcedComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _ReinforcedComponents = null; + } + public ReinforcedViewModel GetViewModel => new() + { + Id = Id, + ReinforcedName = ReinforcedName, + Price = Price, + ReinforcedComponents = ReinforcedComponents + }; + public XElement GetXElement => new("Reinforced", + new XAttribute("Id", Id), + new XElement("ReinforcedName", ReinforcedName), + new XElement("Price", Price.ToString()), + new XElement("ReinforcedComponents", Components.Select(x => + new XElement("ReinforcedComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs new file mode 100644 index 0000000..e8a565e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs @@ -0,0 +1,85 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.StoragesContract; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantFileImplement.Models; + +namespace PrecastConcretePlantFileImplement +{ + public class ReinforcedStorage : IReinforcedStorage + { + private readonly DataFileSingleton _source; + public ReinforcedStorage() + { + _source = DataFileSingleton.GetInstance(); + } + + public ReinforcedViewModel? Delete(ReinforcedBindingModel model) + { + var element = _source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Reinforceds.Remove(element); + _source.SaveReinforceds(); + return element.GetViewModel; + } + return null; + } + + public ReinforcedViewModel? GetElement(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName) && !model.Id.HasValue) + { + return null; + } + return _source.Reinforceds.FirstOrDefault + (x => (!string.IsNullOrEmpty(model.ReinforcedName) && x.ReinforcedName == model.ReinforcedName) || + (model.Id.HasValue && x.Id == model.Id) + )?.GetViewModel; + } + + public List GetFilteredList(ReinforcedSearchModel model) + { + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + return new(); + } + return _source.Reinforceds + .Select(x => x.GetViewModel) + .Where(x => x.ReinforcedName.Contains(model.ReinforcedName)) + .ToList(); + } + + public List GetFullList() + { + return _source.Reinforceds + .Select(x => x.GetViewModel) + .ToList(); + } + + public ReinforcedViewModel? Insert(ReinforcedBindingModel model) + { + model.Id = _source.Reinforceds.Count > 0 ? _source.Reinforceds.Max(x => x.Id) + 1 : 1; + var newPastry = Reinforced.Create(model); + if (newPastry == null) + { + return null; + } + _source.Reinforceds.Add(newPastry); + _source.SaveReinforceds(); + return newPastry.GetViewModel; + } + + public ReinforcedViewModel? Update(ReinforcedBindingModel model) + { + var reinforced = _source.Reinforceds.FirstOrDefault(x => x.Id == model.Id); + if (reinforced == null) + { + return null; + } + reinforced.Update(model); + _source.SaveReinforceds(); + return reinforced.GetViewModel; + } + } +} -- 2.25.1 From 4fec97ed4471a9073dd230aef79677bbe6c3684c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Mon, 6 Mar 2023 19:18:57 +0400 Subject: [PATCH 02/11] fix --- PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index a2e34f9..36fff37 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -156,6 +156,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormMain"; this.Text = "FormMain"; + this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); -- 2.25.1 From a4f141b711a9f1f06d03cbdbbfd4477ed2763f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Fri, 21 Apr 2023 22:31:33 +0400 Subject: [PATCH 03/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BC=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BA=D0=BE=D0=BB-=D0=B2?= =?UTF-8?q?=D0=BE=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PrecastConcretePlant/FormShop.Designer.cs | 24 ++++ .../PrecastConcretePlant/FormShop.cs | 2 + .../OrderLogic.cs | 6 +- .../BindingModels/ShopBindingModel.cs | 2 + .../StoragesContract/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 3 + .../IShopModel.cs | 1 + .../PrecastConcretePlantFileImplement/Shop.cs | 109 ++++++++++++++++++ .../ShopStorage.cs | 16 ++- 9 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs index 035854b..5dec33e 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.Designer.cs @@ -40,7 +40,10 @@ this.comboBoxShop = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.dateTimePickerOpening = new System.Windows.Forms.DateTimePicker(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDownMaxReinforced = new System.Windows.Forms.NumericUpDown(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxReinforced)).BeginInit(); this.SuspendLayout(); // // buttonSave @@ -145,11 +148,29 @@ this.dateTimePickerOpening.Size = new System.Drawing.Size(200, 23); this.dateTimePickerOpening.TabIndex = 18; // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(606, 10); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(115, 15); + this.label4.TabIndex = 19; + this.label4.Text = "Максимум изделий"; + // + // numericUpDownMaxReinforced + // + this.numericUpDownMaxReinforced.Location = new System.Drawing.Point(606, 26); + this.numericUpDownMaxReinforced.Name = "numericUpDownMaxReinforced"; + this.numericUpDownMaxReinforced.Size = new System.Drawing.Size(120, 23); + this.numericUpDownMaxReinforced.TabIndex = 20; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(737, 319); + this.Controls.Add(this.numericUpDownMaxReinforced); + this.Controls.Add(this.label4); this.Controls.Add(this.dateTimePickerOpening); this.Controls.Add(this.buttonSave); this.Controls.Add(this.buttonCancel); @@ -163,6 +184,7 @@ this.Text = "Изделия магазина"; this.Load += new System.EventHandler(this.FormShop_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxReinforced)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -182,5 +204,7 @@ private TextBox comboBoxShop; private Label label1; private DateTimePicker dateTimePickerOpening; + private Label label4; + private NumericUpDown numericUpDownMaxReinforced; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs index 6daff3e..ed629e3 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormShop.cs @@ -48,6 +48,7 @@ namespace PrecastConcretePlantView var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.Text)); if (model != null) { + numericUpDownMaxReinforced.Value = model.MaxCountReinforceds; comboBoxShop.Text = model.Name; textBoxAddress.Text = model.Address; dateTimePickerOpening.Value = model.DateOpening; @@ -91,6 +92,7 @@ namespace PrecastConcretePlantView { ShopBindingModel model = new() { + MaxCountReinforceds = (int)numericUpDownMaxReinforced.Value, Name = comboBoxShop.Text, Address = textBoxAddress.Text, DateOpening = dateTimePickerOpening.Value, diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs index b40d4ad..bc2fc77 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs @@ -12,10 +12,14 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IReinforcedStorage _reinforcedStorage; + private readonly IShopLogic _shopLogic; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IReinforcedStorage reinforcedStorage, IShopLogic shopLogic) { _logger = logger; _orderStorage = orderStorage; + _reinforcedStorage = reinforcedStorage; + _shopLogic = shopLogic; } public bool CreateOrder(OrderBindingModel model) diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs index 3f9f982..7ddddc4 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BindingModels/ShopBindingModel.cs @@ -9,6 +9,8 @@ namespace PrecastConcretePlantContracts.BindingModels public string Address { get; set; } = string.Empty; + public int MaxCountReinforceds { get; set; } + public DateTime DateOpening { get; set; } = DateTime.Now; public Dictionary Reinforceds diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs index 060b96a..c493ea3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs @@ -13,5 +13,7 @@ namespace PrecastConcretePlantContracts.StoragesContract ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount); + public bool SellReinforceds(IReinforcedModel reinforced, int needCount); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs index 49cc4c2..3ecfc28 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/ViewModels/ShopViewModel.cs @@ -13,6 +13,9 @@ namespace PrecastConcretePlantContracts.ViewModels [DisplayName("Адрес магазина")] public string Address { get; set; } = string.Empty; + [DisplayName("Максимальное количество изделий в магазине")] + public int MaxCountReinforceds { get; set; } + [DisplayName("Время открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; diff --git a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs index 7522011..5e252ae 100644 --- a/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs +++ b/PrecastConcretePlant/PrecastConcretePlantDataModels/IShopModel.cs @@ -6,6 +6,7 @@ namespace PrecastConcretePlantDataModels { string Name { get; } string Address { get; } + int MaxCountReinforceds { get; } DateTime DateOpening { get; } Dictionary Reinforceds { get; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs new file mode 100644 index 0000000..ce969c9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs @@ -0,0 +1,109 @@ +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels; +using PrecastConcretePlantDataModels.Models; +using System.Xml.Linq; + +namespace PrecastConcretePlantFileImplement +{ + public class Shop : IShopModel + { + public string Name { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public int MaxCountReinforceds { get; private set; } + + public DateTime DateOpening { get; private set; } + + public Dictionary CountReinforceds { get; private set; } = new(); + + private Dictionary? _cachedReinforceds = null; + public Dictionary Reinforceds + { + get + { + if (_cachedReinforceds == null) + { + var source = DataFileSingleton.GetInstance(); + _cachedReinforceds = CountReinforceds + .ToDictionary(x => x.Key, x => (source.Reinforceds + .FirstOrDefault(y => y.Id == x.Key)! as IReinforcedModel, x.Value)); + } + return _cachedReinforceds; + } + } + + public int Id { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Address = model.Address, + DateOpening = model.DateOpening, + MaxCountReinforceds = model.MaxCountReinforceds, + CountReinforceds = new() + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Name = element.Element("Name")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + MaxCountReinforceds = Convert.ToInt32(element.Element("MaxCountReinforceds")!.Value), + CountReinforceds = element.Element("CountReinforceds")!.Elements("CountReinforced") + .ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Address = model.Address; + DateOpening = model.DateOpening; + CountReinforceds = model.Reinforceds.ToDictionary(x => x.Key, x => x.Value.Item2); + _cachedReinforceds = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Address = Address, + Reinforceds = Reinforceds, + DateOpening = DateOpening, + MaxCountReinforceds = MaxCountReinforceds, + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening), + new XElement("MaxCountReinforceds", MaxCountReinforceds), + new XElement("CountReinforceds", CountReinforceds + .Select(x => new XElement("CountReinforced", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + )) + ); + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs index af859f5..a10b774 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs @@ -2,11 +2,7 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContract; using PrecastConcretePlantContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using PrecastConcretePlantDataModels.Models; namespace PrecastConcretePlantFileImplement { @@ -32,11 +28,21 @@ namespace PrecastConcretePlantFileImplement throw new NotImplementedException(); } + public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount) + { + throw new NotImplementedException(); + } + public ShopViewModel? Insert(ShopBindingModel model) { throw new NotImplementedException(); } + public bool SellReinforceds(IReinforcedModel reinforced, int needCount) + { + throw new NotImplementedException(); + } + public ShopViewModel? Update(ShopBindingModel model) { throw new NotImplementedException(); -- 2.25.1 From e05c2bfeb3bec97d628e7e22c593c16ab1eb246a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Fri, 21 Apr 2023 22:48:59 +0400 Subject: [PATCH 04/11] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BC=D0=B0=D0=BA=D1=81=D0=B8=D0=BC?= =?UTF-8?q?=D0=B0=D0=BB=D0=BD=D1=8C=D0=BE=D0=B5=20=D0=BA=D0=BE=D0=BB-?= =?UTF-8?q?=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ShopLogic.cs | 54 +++++++++++ .../DataFileSingleton.cs | 4 + .../ShopStorage.cs | 94 +++++++++++++++---- .../PrecastConcretePlantListImplement/Shop.cs | 5 + .../ShopStorage.cs | 11 +++ 5 files changed, 152 insertions(+), 16 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs index 6929890..de45dd1 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs @@ -100,6 +100,12 @@ namespace PrecastConcretePlantBusinessLogic throw new ArgumentNullException("Нет названия магазина", nameof(model.Name)); } + if (model.MaxCountReinforceds < 0) + { + throw new ArgumentException( + "Максимальное количество изделий в магазине не должно быть отрицательным", + nameof(model.MaxCountReinforceds)); + } _logger.LogInformation("Shop. ShopName:{0}.Address:{1}. Id: {2}", model.Name, model.Address, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel @@ -149,5 +155,53 @@ namespace PrecastConcretePlantBusinessLogic }); return true; } + + public int GetFreePlacesWithReinforcedsInShops(int countReinforceds) + { + return _shopStorage.GetFullList() + .Select(x => x.MaxCountReinforceds - x.Reinforceds + .Select(p => p.Value.Item2).Sum()) + .Sum() - countReinforceds; + } + + public bool AddReinforcedsInShops(IReinforcedModel reinforced, int count) + { + if (count <= 0) + { + _logger.LogWarning("AddReinforcedsInShops. Количество добавляемых изделий должно быть больше 0. Количество - {count}", count); + return false; + } + var freePlaces = GetFreePlacesWithReinforcedsInShops(count); + if (freePlaces < 0) + { + _logger.LogInformation("AddReinforcedsInShops. Не удалось добавить изделия в магазины, поскольку они переполнены." + + "Освободите магазины на {places} изделий", -freePlaces); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + var cnt = Math.Min(count, shop.MaxCountReinforceds - shop.Reinforceds.Select(x => x.Value.Item2).Sum()); + if (cnt <= 0) + { + continue; + } + if (!AddReinforced(new() { Id = shop.Id }, reinforced, cnt)) + { + _logger.LogWarning("При добавления изделий во все магазины произошла ошибка"); + return false; + } + count -= cnt; + if (count == 0) + { + return true; + } + } + return true; + } + + public bool SellReinforceds(IReinforcedModel reinforced, int needCount) + { + return _shopStorage.SellReinforceds(reinforced, needCount); + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs index 5ae7a7d..2a44e84 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace PrecastConcretePlantFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string ReinforcedFileName = "Reinforced.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; set; } public List Orders { get; set; } public List Reinforceds { get; set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { @@ -24,12 +26,14 @@ namespace PrecastConcretePlantFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveReinforceds() => SaveData(Reinforceds, ReinforcedFileName, "Reinforceds", 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)!)!; Reinforceds = LoadData(ReinforcedFileName, "Reinforced", x => Reinforced.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) { diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs index a10b774..eda8adb 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs @@ -8,44 +8,106 @@ namespace PrecastConcretePlantFileImplement { public class ShopStorage : IShopStorage { + private readonly DataFileSingleton _source; + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? Delete(ShopBindingModel model) { - throw new NotImplementedException(); + var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Shops.Remove(element); + _source.SaveShops(); + return element.GetViewModel; + } + return null; } public ShopViewModel? GetElement(ShopSearchModel model) { - throw new NotImplementedException(); + if (!model.Id.HasValue) + { + return null; + } + return _source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; } public List GetFilteredList(ShopSearchModel model) { - throw new NotImplementedException(); + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return _source.Shops + .Select(x => x.GetViewModel) + .Where(x => x.Name.Contains(model.Name ?? string.Empty)) + .ToList(); } public List GetFullList() { - throw new NotImplementedException(); - } - - public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount) - { - throw new NotImplementedException(); + return _source.Shops + .Select(shop => shop.GetViewModel) + .ToList(); } public ShopViewModel? Insert(ShopBindingModel model) { - throw new NotImplementedException(); - } - - public bool SellReinforceds(IReinforcedModel reinforced, int needCount) - { - throw new NotImplementedException(); + 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) { - throw new NotImplementedException(); + var shop = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + _source.SaveShops(); + return shop.GetViewModel; + } + + public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount) + { + var resultCount = _source.Shops + .Select(shop => shop.Reinforceds + .FirstOrDefault(x => x.Key == reinforced.Id).Value.Item2) + .Sum(); + return resultCount >= needCount; + } + + public bool SellReinforceds(IReinforcedModel reinforced, int needCount) + { + if (!HasNeedReinforceds(reinforced, needCount)) + { + return false; + } + foreach (var shop in _source.Shops.Where(shop => shop.Reinforceds.ContainsKey(reinforced.Id))) + { + var tuple = shop.Reinforceds[reinforced.Id]; + var diff = Math.Min(tuple.Item2, needCount); + shop.Reinforceds[reinforced.Id] = (tuple.Item1, tuple.Item2 - diff); + + needCount -= diff; + if (needCount <= 0) + { + return true; + } + } + + return true; } } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs index 1d07d25..fcbaa3c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/Shop.cs @@ -11,6 +11,8 @@ namespace PrecastConcretePlantListImplement public string Address { get; private set; } = string.Empty; + public int MaxCountReinforceds { get; private set; } + public DateTime DateOpening { get; private set; } public Dictionary Reinforceds @@ -33,6 +35,7 @@ namespace PrecastConcretePlantListImplement Name = model.Name, Address = model.Address, DateOpening = model.DateOpening, + MaxCountReinforceds = model.MaxCountReinforceds, Reinforceds = new() }; } @@ -45,6 +48,7 @@ namespace PrecastConcretePlantListImplement Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; + MaxCountReinforceds = model.MaxCountReinforceds; Reinforceds = model.Reinforceds; } public ShopViewModel GetViewModel => new() @@ -54,6 +58,7 @@ namespace PrecastConcretePlantListImplement Address = Address, Reinforceds = Reinforceds, DateOpening = DateOpening, + MaxCountReinforceds = MaxCountReinforceds, }; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs index fab9bd4..1a0e2bd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs @@ -2,6 +2,7 @@ using PrecastConcretePlantContracts.SearchModels; using PrecastConcretePlantContracts.StoragesContract; using PrecastConcretePlantContracts.ViewModels; +using PrecastConcretePlantDataModels.Models; namespace PrecastConcretePlantListImplement { @@ -103,5 +104,15 @@ namespace PrecastConcretePlantListImplement } return null; } + + public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount) + { + throw new NotImplementedException(); + } + + public bool SellReinforceds(IReinforcedModel reinforced, int needCount) + { + throw new NotImplementedException(); + } } } -- 2.25.1 From 9f4419ada0e4cad5cd416d5d13ccc62ef24c4f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Fri, 21 Apr 2023 22:54:02 +0400 Subject: [PATCH 05/11] fix --- .../PrecastConcretePlantBusinessLogic/OrderLogic.cs | 9 +++++++++ .../BusinessLogicsContracts/IShopLogic.cs | 2 ++ 2 files changed, 11 insertions(+) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs index bc2fc77..25156cf 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/OrderLogic.cs @@ -98,6 +98,15 @@ namespace PrecastConcretePlantBusinessLogic.BusinessLogic $"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}", nameof(vmodel)); } + if (orderStatus == OrderStatus.Готов) + { + var vreinforced = _reinforcedStorage.GetElement(new() { Id = vmodel.ReinforcedId }); + + if (vreinforced == null || !_shopLogic.AddReinforcedsInShops(vreinforced, vmodel.Count)) + { + throw new Exception($"Не удалось заполнить магазины изделием '{vreinforced?.ReinforcedName ?? string.Empty}' из заказа {vmodel.Id}"); + } + } model.Status = orderStatus; model.ReinforcedId = vmodel.ReinforcedId; model.Sum = vmodel.Sum; diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index 6460d8b..cee1038 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -13,5 +13,7 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count); + bool AddReinforcedsInShops(IReinforcedModel reinforceds, int count); + public bool SellReinforceds(IReinforcedModel reinforceds, int needCount); } } -- 2.25.1 From 203097dbddab8d0f973371e48aa8d898875b1f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Fri, 21 Apr 2023 23:22:44 +0400 Subject: [PATCH 06/11] fix and complete --- .../PrecastConcretePlant/FormMain.Designer.cs | 47 ++++--- .../PrecastConcretePlant/FormMain.cs | 9 ++ .../FormSellReinforced.Designer.cs | 133 ++++++++++++++++++ .../FormSellReinforced.cs | 56 ++++++++ .../FormSellReinforced.resx | 60 ++++++++ .../PrecastConcretePlant/Program.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 4 +- .../ReinforcedStorage.cs | 8 +- 8 files changed, 295 insertions(+), 23 deletions(-) create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs create mode 100644 PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs index 73c89fc..9fc0826 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.Designer.cs @@ -38,8 +38,9 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reinforcedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.buttonAddReinforcedInShop = new System.Windows.Forms.Button(); this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonAddReinforcedInShop = new System.Windows.Forms.Button(); + this.buttonSellReinforced = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -47,7 +48,7 @@ // buttonRef // this.buttonRef.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRef.Location = new System.Drawing.Point(840, 276); + this.buttonRef.Location = new System.Drawing.Point(786, 276); this.buttonRef.Name = "buttonRef"; this.buttonRef.Size = new System.Drawing.Size(147, 32); this.buttonRef.TabIndex = 12; @@ -58,7 +59,7 @@ // buttonFinish // this.buttonFinish.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonFinish.Location = new System.Drawing.Point(840, 217); + this.buttonFinish.Location = new System.Drawing.Point(786, 217); this.buttonFinish.Name = "buttonFinish"; this.buttonFinish.Size = new System.Drawing.Size(147, 32); this.buttonFinish.TabIndex = 11; @@ -69,7 +70,7 @@ // buttonReady // this.buttonReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonReady.Location = new System.Drawing.Point(840, 159); + this.buttonReady.Location = new System.Drawing.Point(786, 159); this.buttonReady.Name = "buttonReady"; this.buttonReady.Size = new System.Drawing.Size(147, 32); this.buttonReady.TabIndex = 10; @@ -80,7 +81,7 @@ // buttonTakeOrderInWork // this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(840, 100); + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(786, 100); this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; this.buttonTakeOrderInWork.Size = new System.Drawing.Size(147, 32); this.buttonTakeOrderInWork.TabIndex = 9; @@ -91,7 +92,7 @@ // buttonCreateOrder // this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCreateOrder.Location = new System.Drawing.Point(840, 41); + this.buttonCreateOrder.Location = new System.Drawing.Point(786, 41); this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Size = new System.Drawing.Size(147, 32); this.buttonCreateOrder.TabIndex = 8; @@ -108,7 +109,7 @@ this.dataGridView.Location = new System.Drawing.Point(12, 29); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(805, 348); + this.dataGridView.Size = new System.Drawing.Size(751, 396); this.dataGridView.TabIndex = 7; // // menuStrip1 @@ -117,7 +118,7 @@ this.справочникиToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(999, 24); + this.menuStrip1.Size = new System.Drawing.Size(945, 24); this.menuStrip1.TabIndex = 13; this.menuStrip1.Text = "menuStrip1"; // @@ -145,10 +146,17 @@ this.componentToolStripMenuItem.Text = "Компоненты"; this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + // // buttonAddReinforcedInShop // - this.buttonAddReinforcedInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(840, 337); + this.buttonAddReinforcedInShop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonAddReinforcedInShop.Location = new System.Drawing.Point(786, 337); this.buttonAddReinforcedInShop.Name = "buttonAddReinforcedInShop"; this.buttonAddReinforcedInShop.Size = new System.Drawing.Size(147, 31); this.buttonAddReinforcedInShop.TabIndex = 14; @@ -156,18 +164,23 @@ this.buttonAddReinforcedInShop.UseVisualStyleBackColor = true; this.buttonAddReinforcedInShop.Click += new System.EventHandler(this.ButtonAddReinforcedInShop_Click); // - // магазиныToolStripMenuItem + // buttonSellReinforced // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click); + this.buttonSellReinforced.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSellReinforced.Location = new System.Drawing.Point(786, 395); + this.buttonSellReinforced.Name = "buttonSellReinforced"; + this.buttonSellReinforced.Size = new System.Drawing.Size(147, 31); + this.buttonSellReinforced.TabIndex = 15; + this.buttonSellReinforced.Text = "Продать изделие"; + this.buttonSellReinforced.UseVisualStyleBackColor = true; + this.buttonSellReinforced.Click += new System.EventHandler(this.ButtonSellReinforced_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(999, 389); + this.ClientSize = new System.Drawing.Size(945, 437); + this.Controls.Add(this.buttonSellReinforced); this.Controls.Add(this.buttonAddReinforcedInShop); this.Controls.Add(this.menuStrip1); this.Controls.Add(this.buttonRef); @@ -178,7 +191,6 @@ this.Controls.Add(this.dataGridView); this.Name = "FormMain"; this.Text = "Заказы"; - this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.menuStrip1.ResumeLayout(false); @@ -202,5 +214,6 @@ private ToolStripMenuItem componentToolStripMenuItem; private Button buttonAddReinforcedInShop; private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonSellReinforced; } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs index 3c41bda..9601a51 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormMain.cs @@ -170,5 +170,14 @@ namespace PrecastConcretePlantView form.ShowDialog(); } } + + private void ButtonSellReinforced_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellReinforced)); + if (service is FormSellReinforced form) + { + form.ShowDialog(); + } + } } } diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs new file mode 100644 index 0000000..8a5b68e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs @@ -0,0 +1,133 @@ +namespace PrecastConcretePlantView +{ + partial class FormSellReinforced + { + /// + /// 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.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSell = new System.Windows.Forms.Button(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxReinforced = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(179, 79); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(123, 23); + this.buttonCancel.TabIndex = 11; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // buttonSell + // + this.buttonSell.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSell.Location = new System.Drawing.Point(32, 79); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(123, 23); + this.buttonSell.TabIndex = 10; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click); + // + // numericUpDownCount + // + this.numericUpDownCount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.numericUpDownCount.Location = new System.Drawing.Point(142, 40); + this.numericUpDownCount.Maximum = new decimal(new int[] { + 10000000, + 0, + 0, + 0}); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.RightToLeft = System.Windows.Forms.RightToLeft.No; + this.numericUpDownCount.Size = new System.Drawing.Size(160, 23); + this.numericUpDownCount.TabIndex = 9; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(60, 40); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 8; + this.label2.Text = "Количество:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(123, 15); + this.label1.TabIndex = 7; + this.label1.Text = "Изделие на продажу:"; + // + // comboBoxReinforced + // + this.comboBoxReinforced.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxReinforced.FormattingEnabled = true; + this.comboBoxReinforced.Location = new System.Drawing.Point(141, 6); + this.comboBoxReinforced.Name = "comboBoxReinforced"; + this.comboBoxReinforced.Size = new System.Drawing.Size(161, 23); + this.comboBoxReinforced.TabIndex = 6; + // + // FormSellReinforced + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(314, 114); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxReinforced); + this.Name = "FormSellReinforced"; + this.Text = "FormSellReinforced"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonCancel; + private Button buttonSell; + private NumericUpDown numericUpDownCount; + private Label label2; + private Label label1; + private ComboBox comboBoxReinforced; + } +} \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs new file mode 100644 index 0000000..46626c9 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.cs @@ -0,0 +1,56 @@ +using PrecastConcretePlantContracts.BusinessLogicsContracts; + +namespace PrecastConcretePlantView +{ + public partial class FormSellReinforced : Form + { + private readonly IShopLogic _shopLogic; + private readonly IReinforcedLogic _reinforcedLogic; + public FormSellReinforced(IReinforcedLogic logic, IShopLogic shopLogic) + { + InitializeComponent(); + _reinforcedLogic = logic; + _shopLogic = shopLogic; + var list = logic.ReadList(null); + if (list != null) + { + comboBoxReinforced.DisplayMember = "ReinforcedName"; + comboBoxReinforced.ValueMember = "Id"; + comboBoxReinforced.DataSource = list; + comboBoxReinforced.SelectedItem = null; + } + } + + private void ButtonSell_Click(object sender, EventArgs e) + { + if (comboBoxReinforced.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (numericUpDownCount.Value <= 0) + { + MessageBox.Show("Количество должно быть больше нуля", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var count = (int)numericUpDownCount.Value; + var reinforced = _reinforcedLogic.ReadElement(new() { Id = (int)comboBoxReinforced.SelectedValue }); + if (reinforced == null || !_shopLogic.SellReinforceds(reinforced, count)) + { + MessageBox.Show("Не удалось продать изделия. Информацию смотрите в логах", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlant/Program.cs b/PrecastConcretePlant/PrecastConcretePlant/Program.cs index 4303847..d6086ea 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/Program.cs @@ -58,6 +58,7 @@ namespace PrecastConcretePlant services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs index cee1038..0094dce 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/BusinessLogicsContracts/IShopLogic.cs @@ -13,7 +13,7 @@ namespace PrecastConcretePlantContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool AddReinforced(ShopSearchModel model, IReinforcedModel reinforced, int count); - bool AddReinforcedsInShops(IReinforcedModel reinforceds, int count); - public bool SellReinforceds(IReinforcedModel reinforceds, int needCount); + bool AddReinforcedsInShops(IReinforcedModel reinforced, int count); + public bool SellReinforceds(IReinforcedModel reinforced, int needCount); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs index e8a565e..c31a0b1 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ReinforcedStorage.cs @@ -60,14 +60,14 @@ namespace PrecastConcretePlantFileImplement public ReinforcedViewModel? Insert(ReinforcedBindingModel model) { model.Id = _source.Reinforceds.Count > 0 ? _source.Reinforceds.Max(x => x.Id) + 1 : 1; - var newPastry = Reinforced.Create(model); - if (newPastry == null) + var newReinforced = Reinforced.Create(model); + if (newReinforced == null) { return null; } - _source.Reinforceds.Add(newPastry); + _source.Reinforceds.Add(newReinforced); _source.SaveReinforceds(); - return newPastry.GetViewModel; + return newReinforced.GetViewModel; } public ReinforcedViewModel? Update(ReinforcedBindingModel model) -- 2.25.1 From 3110a0425c48c3721e7bdbc73c33862dd37dcaf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Sun, 23 Apr 2023 15:59:33 +0400 Subject: [PATCH 07/11] fix --- .../PrecastConcretePlant/FormSellReinforced.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs index 8a5b68e..28e6a01 100644 --- a/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs +++ b/PrecastConcretePlant/PrecastConcretePlant/FormSellReinforced.Designer.cs @@ -114,7 +114,7 @@ this.Controls.Add(this.label1); this.Controls.Add(this.comboBoxReinforced); this.Name = "FormSellReinforced"; - this.Text = "FormSellReinforced"; + this.Text = "Продать изделие"; ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); -- 2.25.1 From eadf7da8361afe6278cf62cedee7be2a07b24411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Tue, 25 Apr 2023 20:24:58 +0400 Subject: [PATCH 08/11] fix --- .../PrecastConcretePlantBusinessLogic/ShopLogic.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs index de45dd1..86cba03 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs @@ -128,9 +128,14 @@ namespace PrecastConcretePlantBusinessLogic { throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count)); } + _logger.LogInformation("AddreinforcedInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id); var element = _shopStorage.GetElement(model); + if (element.MaxCountReinforceds < count + element.Reinforceds.Sum(x => x.Value.Item2)) + { + throw new ArgumentException("Количество добавляемого изделия не должно быть больше максимального кол-ва изделий в магазине", nameof(count)); + } if (element == null) { _logger.LogWarning("AddreinforcedInShop element not found"); -- 2.25.1 From 85dd33db61b1a4c9cfcc09ca7ef965c64cdd8322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Tue, 25 Apr 2023 20:45:54 +0400 Subject: [PATCH 09/11] fix --- .../StoragesContract/IShopStorage.cs | 1 - .../PrecastConcretePlantFileImplement/ShopStorage.cs | 10 ++-------- .../PrecastConcretePlantListImplement/ShopStorage.cs | 5 ----- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs index c493ea3..43e86b2 100644 --- a/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantContracts/StoragesContract/IShopStorage.cs @@ -13,7 +13,6 @@ namespace PrecastConcretePlantContracts.StoragesContract ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount); public bool SellReinforceds(IReinforcedModel reinforced, int needCount); } } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs index eda8adb..0cba134 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs @@ -79,18 +79,13 @@ namespace PrecastConcretePlantFileImplement return shop.GetViewModel; } - public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount) + public bool SellReinforceds(IReinforcedModel reinforced, int needCount) { var resultCount = _source.Shops .Select(shop => shop.Reinforceds .FirstOrDefault(x => x.Key == reinforced.Id).Value.Item2) .Sum(); - return resultCount >= needCount; - } - - public bool SellReinforceds(IReinforcedModel reinforced, int needCount) - { - if (!HasNeedReinforceds(reinforced, needCount)) + if (resultCount >= needCount) { return false; } @@ -106,7 +101,6 @@ namespace PrecastConcretePlantFileImplement return true; } } - return true; } } diff --git a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs index 1a0e2bd..de78c61 100644 --- a/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantListImplement/ShopStorage.cs @@ -105,11 +105,6 @@ namespace PrecastConcretePlantListImplement return null; } - public bool HasNeedReinforceds(IReinforcedModel reinforced, int needCount) - { - throw new NotImplementedException(); - } - public bool SellReinforceds(IReinforcedModel reinforced, int needCount) { throw new NotImplementedException(); -- 2.25.1 From 81925a414b00018c8db73569aba09055a7b7cb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Wed, 26 Apr 2023 10:19:14 +0400 Subject: [PATCH 10/11] fix --- .../PrecastConcretePlantFileImplement/ShopStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs index 0cba134..45d6baf 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs @@ -85,7 +85,7 @@ namespace PrecastConcretePlantFileImplement .Select(shop => shop.Reinforceds .FirstOrDefault(x => x.Key == reinforced.Id).Value.Item2) .Sum(); - if (resultCount >= needCount) + if (resultCount < needCount) { return false; } -- 2.25.1 From 5a7dbc9d732b57c541a4b1374ce6f570c0cdaec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=9F=D1=83=D1=82=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BD?= Date: Wed, 26 Apr 2023 11:20:34 +0400 Subject: [PATCH 11/11] fix --- .../PrecastConcretePlantBusinessLogic/ShopLogic.cs | 1 + PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs | 1 + .../PrecastConcretePlantFileImplement/ShopStorage.cs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs index 86cba03..ed8fabd 100644 --- a/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs +++ b/PrecastConcretePlant/PrecastConcretePlantBusinessLogic/ShopLogic.cs @@ -155,6 +155,7 @@ namespace PrecastConcretePlantBusinessLogic Id = element.Id, Address = element.Address, Name = element.Name, + MaxCountReinforceds = element.MaxCountReinforceds, DateOpening = element.DateOpening, Reinforceds = element.Reinforceds }); diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs index ce969c9..1c105ed 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/Shop.cs @@ -81,6 +81,7 @@ namespace PrecastConcretePlantFileImplement Name = model.Name; Address = model.Address; DateOpening = model.DateOpening; + MaxCountReinforceds = model.MaxCountReinforceds; CountReinforceds = model.Reinforceds.ToDictionary(x => x.Key, x => x.Value.Item2); _cachedReinforceds = null; } diff --git a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs index 45d6baf..92d2ffc 100644 --- a/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs +++ b/PrecastConcretePlant/PrecastConcretePlantFileImplement/ShopStorage.cs @@ -83,7 +83,7 @@ namespace PrecastConcretePlantFileImplement { var resultCount = _source.Shops .Select(shop => shop.Reinforceds - .FirstOrDefault(x => x.Key == reinforced.Id).Value.Item2) + .FirstOrDefault(x => x.Key == reinforced.Id).Value.Item2) .Sum(); if (resultCount < needCount) { -- 2.25.1