From 2f4c7b4db47bc9ba9d8ca526c7047acbe08b8b9d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 13 Feb 2023 23:46:35 +0400 Subject: [PATCH 01/21] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B2=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B5=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop.sln | 8 +- .../BlacksmithWorkshopFileImplement.csproj | 9 ++ .../Models/Manufacture.cs | 108 ++++++++++++++++++ .../Models/WorkPiece.cs | 75 ++++++++++++ .../Models/Manufacture.cs | 2 +- 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 1c793e7..0834832 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{58737D93-9A12-4D07-BF3F-86AC512CE626}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.Build.0 = Release|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58737D93-9A12-4D07-BF3F-86AC512CE626}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs new file mode 100644 index 0000000..28bc89f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs @@ -0,0 +1,108 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + //класс реализующий интерфейс модели изделия + public class Manufacture : IManufactureModel + { + public int Id { get; private set; } + + public string ManufactureName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary WorkPieces { get; private set; } = new(); + + + private Dictionary? _manufactureWorkPieces = null; + + public Dictionary ManufactureWorkPieces + { + get + { + if (_manufactureWorkPieces == null) + { + var source = DataFileSingleton.GetInstance(); + + _manufactureWorkPieces = WorkPieces.ToDictionary(x => x.Key, + y => ((source.WorkPieces.FirstOrDefault(z => z.Id == y.Key) as IWorkPieceModel)!, y.Value)); + } + + return _manufactureWorkPieces; + } + } + + public static Manufacture? Create(ManufactureBindingModel model) + { + if (model == null) + { + return null; + } + + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + WorkPieces = model.ManufactureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Manufacture? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new Manufacture() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ManufactureName = element.Element("ManufactureName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureComponent").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ManufactureBindingModel model) + { + if (model == null) + { + return; + } + + ManufactureName = model.ManufactureName; + Price = model.Price; + WorkPieces = model.ManufactureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2); + _manufactureWorkPieces = null; + } + + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureWorkPieces = ManufactureWorkPieces + }; + + public XElement GetXElement => new("Manufacture", + new XAttribute("Id", Id), + new XElement("ManufactureName", ManufactureName), + new XElement("Price", Price.ToString()), + new XElement("ManufactureWorkPieces", WorkPieces.Select( + x => new XElement("ManufactureComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs new file mode 100644 index 0000000..aab56a3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs @@ -0,0 +1,75 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + //реализация интерфейса модели заготовки + public class WorkPiece : IWorkPieceModel + { + public int Id { get; private set; } + + public string WorkPieceName { get; private set; } = string.Empty; + + public double Cost { get; set; } + + public static WorkPiece? Create(WorkPieceBindingModel model) + { + if (model == null) + { + return null; + } + + return new WorkPiece() + { + Id = model.Id, + WorkPieceName = model.WorkPieceName, + Cost = model.Cost + }; + } + + public static WorkPiece? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new WorkPiece() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + WorkPieceName = element.Element("WorkPieceName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(WorkPieceBindingModel model) + { + if (model == null) + { + return; + } + + WorkPieceName = model.WorkPieceName; + Cost = model.Cost; + } + public WorkPieceViewModel GetViewModel => new() + { + Id = Id, + WorkPieceName = WorkPieceName, + Cost = Cost + }; + + public XElement GetXElement => new("WorkPiece", + new XAttribute("Id", Id), + new XElement("WorkPieceName", WorkPieceName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs index ed71631..70c563b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Manufacture.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopListImplement.Models { - //класс реализующий интерфейс модели изделия + //класс, реализующий интерфейс модели изделия public class Manufacture : IManufactureModel { //методы set делаем приватным, чтобы исключить неразрешённые манипуляции -- 2.25.1 From 38d9a88d6b413f0461804952a6ed89aa87a63b11 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 00:15:13 +0400 Subject: [PATCH 02/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8=20Order.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Order.cs | 102 ++++++++++++++++++ .../Models/WorkPiece.cs | 9 +- 2 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs new file mode 100644 index 0000000..d9c33fd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -0,0 +1,102 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + //класс, реализующий интерфейс модели заказа + public class Order : IOrderModel + { + public int Id { get; private set; } + + public int ManufactureId { 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 static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + 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; + } + + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : + Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + + public void Update(OrderBindingModel model) + { + if(model == null) + { + return; + } + + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetOrderModel => new() + { + Id = Id, + ManufactureId = ManufactureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ManufactureId", ManufactureId.ToString()), + new XElement("Count", Count.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs index aab56a3..b4f6a61 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/WorkPiece.cs @@ -60,6 +60,7 @@ namespace BlacksmithWorkshopFileImplement.Models WorkPieceName = model.WorkPieceName; Cost = model.Cost; } + public WorkPieceViewModel GetViewModel => new() { Id = Id, @@ -67,9 +68,9 @@ namespace BlacksmithWorkshopFileImplement.Models Cost = Cost }; - public XElement GetXElement => new("WorkPiece", - new XAttribute("Id", Id), - new XElement("WorkPieceName", WorkPieceName), - new XElement("Cost", Cost.ToString())); + public XElement GetXElement => new("WorkPiece", + new XAttribute("Id", Id), + new XElement("WorkPieceName", WorkPieceName), + new XElement("Cost", Cost.ToString())); } } -- 2.25.1 From 74c4cb4d9d2fe5d01104963db02e5c4c6fe04eb6 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 00:17:04 +0400 Subject: [PATCH 03/21] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopFileImplement.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj index 132c02c..b65badc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -6,4 +6,9 @@ enable + + + + + -- 2.25.1 From a60b8e7edc03a77c4b64286ae6ed07f423acbf84 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 00:22:30 +0400 Subject: [PATCH 04/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20DataFile=20=D0=B4=D0=BB=D1=8F=20FileImplement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataFileSingleton.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..b6628a3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using BlacksmithWorkshopFileImplement.Models; + +namespace BlacksmithWorkshopFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + + private readonly string WorkPieceFileName = "WorkPiece.xml"; + + private readonly string OrderFileName = "Order.xml"; + + private readonly string ManufactureFileName = "Manufacture.xml"; + + public List WorkPieces { get; private set; } + + public List Orders { get; private set; } + + public List Manufactures { get; private set; } + + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + + return instance; + } + + public void SaveWorkPieces() => SaveData(WorkPieces, WorkPieceFileName, "WorkPieces", x => x.GetXElement); + + public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, "Manufactures", x => x.GetXElement); + + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!; + Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.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); + } + } + } +} -- 2.25.1 From c0fa37bd4bca233878cc6cdac8f9259b1ed81f46 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 00:34:36 +0400 Subject: [PATCH 05/21] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=D1=89=D0=B0=20=D0=B7=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/WorkPieceStorage.cs | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs new file mode 100644 index 0000000..cd66646 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs @@ -0,0 +1,97 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + //реализация интерфейса хранилища заготовок + public class WorkPieceStorage : IWorkPieceStorage + { + private readonly DataFileSingleton source; + + public WorkPieceStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.WorkPieces.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(WorkPieceSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkPieceName)) + { + return new(); + } + + return source.WorkPieces.Where(x => x.WorkPieceName.Contains(model.WorkPieceName)).Select(x => x.GetViewModel).ToList(); + } + + public WorkPieceViewModel? GetElement(WorkPieceSearchModel model) + { + if (string.IsNullOrEmpty(model.WorkPieceName) && !model.Id.HasValue) + { + return null; + } + + return source.WorkPieces.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkPieceName) && x.WorkPieceName == model.WorkPieceName) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public WorkPieceViewModel? Insert(WorkPieceBindingModel model) + { + model.Id = source.WorkPieces.Count > 0 ? source.WorkPieces.Max(x => x.Id) + 1 : 1; + + var newWorkPiece = WorkPiece.Create(model); + + if (newWorkPiece == null) + { + return null; + } + + source.WorkPieces.Add(newWorkPiece); + source.SaveWorkPieces(); + + return newWorkPiece.GetViewModel; + } + + public WorkPieceViewModel? Update(WorkPieceBindingModel model) + { + var workPiece = source.WorkPieces.FirstOrDefault(x => x.Id == model.Id); + + if (workPiece == null) + { + return null; + } + + workPiece.Update(model); + source.SaveWorkPieces(); + return workPiece.GetViewModel; + } + + public WorkPieceViewModel? Delete(WorkPieceBindingModel model) + { + var element = source.WorkPieces.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.WorkPieces.Remove(element); + source.SaveWorkPieces(); + return element.GetViewModel; + } + + return null; + + } + } +} -- 2.25.1 From 660ea2894fabad3b0a408e6c3f5d470bd0d93f5d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 09:48:56 +0400 Subject: [PATCH 06/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ManufactureStorage.cs | 97 +++++++++++++++++++ .../Implements/OrderStorage.cs | 96 ++++++++++++++++++ .../Implements/WorkPieceStorage.cs | 3 +- 3 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..753b070 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,97 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + //реализация интерфейса хранилища изделий + public class ManufactureStorage : IManufactureStorage + { + private readonly DataFileSingleton source; + + public ManufactureStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Manufactures.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return new(); + } + + return source.Manufactures.Where(x => x.ManufactureName.Contains(model.ManufactureName)).Select(x => x.GetViewModel).ToList(); + } + + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue) + { + return null; + } + + return source.Manufactures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + model.Id = source.Manufactures.Count > 0 ? source.Manufactures.Max(x => x.Id) + 1 : 1; + + var newManufacture = Manufacture.Create(model); + + if (newManufacture == null) + { + return null; + } + + source.Manufactures.Add(newManufacture); + source.SaveWorkPieces(); + + return newManufacture.GetViewModel; + } + + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + + if (manufacture == null) + { + return null; + } + + manufacture.Update(model); + source.SaveWorkPieces(); + + return manufacture.GetViewModel; + } + + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + var element = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Manufactures.Remove(element); + source.SaveWorkPieces(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..819b55a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,96 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + //реализация интерфейса хранилища заказов + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + + 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 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.SaveWorkPieces(); + + 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.SaveWorkPieces(); + + return order.GetViewModel; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (element != null) + { + source.Orders.Remove(element); + source.SaveWorkPieces(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs index cd66646..b4e6084 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/WorkPieceStorage.cs @@ -76,6 +76,7 @@ namespace BlacksmithWorkshopFileImplement.Implements workPiece.Update(model); source.SaveWorkPieces(); + return workPiece.GetViewModel; } @@ -87,11 +88,11 @@ namespace BlacksmithWorkshopFileImplement.Implements { source.WorkPieces.Remove(element); source.SaveWorkPieces(); + return element.GetViewModel; } return null; - } } } -- 2.25.1 From 3b17272252117003164c2e4f7fa9862a73100838 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 09:50:35 +0400 Subject: [PATCH 07/21] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopFileImplement/Models/Order.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index d9c33fd..f69975d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -79,7 +79,7 @@ namespace BlacksmithWorkshopFileImplement.Models DateImplement = model.DateImplement; } - public OrderViewModel GetOrderModel => new() + public OrderViewModel GetViewModel => new() { Id = Id, ManufactureId = ManufactureId, -- 2.25.1 From 1c7e4211d18ad75f4cd64afb2a50e57737dfdda9 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 10:04:54 +0400 Subject: [PATCH 08/21] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20Program.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/BlacksmithWorkshop.csproj | 1 + BlacksmithWorkshop/BlacksmithWorkshop/Program.cs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 8844615..f51fc76 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -17,6 +17,7 @@ + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index f0537ce..e76d044 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,19 +1,19 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogic; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopListImplement.Implements; +using BlacksmithWorkshopFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System.Drawing; - namespace BlacksmithWorkshop { internal static class Program { private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -28,6 +28,7 @@ namespace BlacksmithWorkshop _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => -- 2.25.1 From e41554b69c530f407f83d68fd27cfc0091578a6e Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 14 Feb 2023 12:53:11 +0400 Subject: [PATCH 09/21] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ManufactureStorage.cs | 6 ++-- .../Implements/OrderStorage.cs | 34 ++++++++++++++----- .../Models/Manufacture.cs | 4 +-- .../Models/Order.cs | 1 + 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs index 753b070..56f4c07 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs @@ -59,7 +59,7 @@ namespace BlacksmithWorkshopFileImplement.Implements } source.Manufactures.Add(newManufacture); - source.SaveWorkPieces(); + source.SaveManufactures(); return newManufacture.GetViewModel; } @@ -74,7 +74,7 @@ namespace BlacksmithWorkshopFileImplement.Implements } manufacture.Update(model); - source.SaveWorkPieces(); + source.SaveManufactures(); return manufacture.GetViewModel; } @@ -86,7 +86,7 @@ namespace BlacksmithWorkshopFileImplement.Implements if (element != null) { source.Manufactures.Remove(element); - source.SaveWorkPieces(); + source.SaveManufactures(); return element.GetViewModel; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index 819b55a..bcb6ffb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -23,7 +23,7 @@ namespace BlacksmithWorkshopFileImplement.Implements public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => GetViewModel(x)).ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -33,7 +33,7 @@ namespace BlacksmithWorkshopFileImplement.Implements return new(); } - return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -46,6 +46,24 @@ namespace BlacksmithWorkshopFileImplement.Implements return source.Orders.FirstOrDefault(x =>(model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } + //для загрузки названий изделия в заказе + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + + foreach(var manufacture in source.Manufactures) + { + if(manufacture.Id == order.ManufactureId) + { + viewModel.ManufactureName = manufacture.ManufactureName; + + break; + } + } + + return viewModel; + } + public OrderViewModel? Insert(OrderBindingModel model) { model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; @@ -58,9 +76,9 @@ namespace BlacksmithWorkshopFileImplement.Implements } source.Orders.Add(newOrder); - source.SaveWorkPieces(); + source.SaveOrders(); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -73,9 +91,9 @@ namespace BlacksmithWorkshopFileImplement.Implements } order.Update(model); - source.SaveWorkPieces(); + source.SaveOrders(); - return order.GetViewModel; + return GetViewModel(order); } public OrderViewModel? Delete(OrderBindingModel model) @@ -85,9 +103,9 @@ namespace BlacksmithWorkshopFileImplement.Implements if (element != null) { source.Orders.Remove(element); - source.SaveWorkPieces(); + source.SaveOrders(); - return element.GetViewModel; + return GetViewModel(element); } return null; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs index 28bc89f..fb73403 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs @@ -68,7 +68,7 @@ namespace BlacksmithWorkshopFileImplement.Models Id = Convert.ToInt32(element.Attribute("Id")!.Value), ManufactureName = element.Element("ManufactureName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), - WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureComponent").ToDictionary( + WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureWorkPieces").ToDictionary( x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) }; @@ -100,7 +100,7 @@ namespace BlacksmithWorkshopFileImplement.Models new XElement("ManufactureName", ManufactureName), new XElement("Price", Price.ToString()), new XElement("ManufactureWorkPieces", WorkPieces.Select( - x => new XElement("ManufactureComponent", + x => new XElement("ManufactureWorkPieces", new XElement("Key", x.Key), new XElement("Value", x.Value)) ).ToArray())); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index f69975d..dbd7ffe 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -95,6 +95,7 @@ namespace BlacksmithWorkshopFileImplement.Models new XAttribute("Id", Id), new XElement("ManufactureId", ManufactureId.ToString()), 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())); -- 2.25.1 From d11fc9960ba2daa1e62421f823234b5883bfa135 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 24 Feb 2023 11:58:18 +0400 Subject: [PATCH 10/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B0=D0=BB=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=BC=D0=B0=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.cs | 21 +++---------------- .../BusinessLogic/OrderLogic.cs | 20 ++++++++++++++---- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 37a970d..a8faa65 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -99,12 +99,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + Id = id }); if (!operationResult) @@ -133,12 +128,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + Id = id }); if (!operationResult) @@ -167,12 +157,7 @@ namespace BlacksmithWorkshop { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + Id = id }); if (!operationResult) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index d1b08bb..ab54224 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -128,10 +128,16 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic //обновление статуса заказа public bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) { - CheckModel(model); + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + + //если не смогли найти указанный заказ по его Id + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } //проверка на возможность обновления статуса на следующий - if(model.Status + 1 != newOrderStatus) + if (viewModel.Status + 1 != newOrderStatus) { _logger.LogWarning("Status update operation failed. New status " + newOrderStatus.ToString() + " incorrect"); return false; @@ -140,13 +146,19 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic model.Status = newOrderStatus; //проверка на выдачу - if(model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Выдан) { model.DateImplement = DateTime.Now; } + else + { + model.DateImplement = viewModel.DateImplement; + } + + CheckModel(model, false); //финальная проверка на возможность обновления - if(_orderStorage.Update(model) == null) + if (_orderStorage.Update(model) == null) { model.Status--; -- 2.25.1 From f83986aa7bbb60f311ec52094f4ed7c5212c0317 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 24 Feb 2023 12:27:33 +0400 Subject: [PATCH 11/21] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index bcb6ffb..250a67e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -51,14 +51,11 @@ namespace BlacksmithWorkshopFileImplement.Implements { var viewModel = order.GetViewModel; - foreach(var manufacture in source.Manufactures) - { - if(manufacture.Id == order.ManufactureId) - { - viewModel.ManufactureName = manufacture.ManufactureName; + var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == order.ManufactureId); - break; - } + if(manufacture != null) + { + viewModel.ManufactureName = manufacture.ManufactureName; } return viewModel; -- 2.25.1 From edcc92c6818dc6ef1b9251b07ae6ff32cd15b89b Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 24 Feb 2023 12:38:23 +0400 Subject: [PATCH 12/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=84=D0=BB?= =?UTF-8?q?=D0=B8=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index a8faa65..879038a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -94,7 +94,7 @@ namespace BlacksmithWorkshop { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - + try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel @@ -182,4 +182,4 @@ namespace BlacksmithWorkshop LoadData(); } } -} +} \ No newline at end of file -- 2.25.1 From 3c1388cbafa3f7ed84437169b41d77c4a2b9e516 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 10:26:18 +0400 Subject: [PATCH 13/21] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs index 5499622..e5a1dec 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; using BlacksmithWorkshopListImplement.Models; using System; using System.Collections.Generic; @@ -124,5 +125,10 @@ namespace BlacksmithWorkshopListImplement.Implements return null; } + + public bool SellManufactures(IManufactureModel model, int count) + { + throw new NotImplementedException(); + } } } -- 2.25.1 From 1e56812c080258351ce4d6c03b318aef4d620259 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 10:28:44 +0400 Subject: [PATCH 14/21] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=B5=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopListImplement/Models/Shop.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs index f5ca3bf..a6221c2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs @@ -19,6 +19,8 @@ namespace BlacksmithWorkshopListImplement.Models public int Id { get; set; } + public int MaxCountManufactures { get; set; } + public Dictionary Manufactures { get; private set; } = new Dictionary(); -- 2.25.1 From a0d1981beed7a8a958956b7a4c0d2fe1bb4c5805 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 11:05:00 +0400 Subject: [PATCH 15/21] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ShopBindingModel.cs | 2 + .../BusinessLogicsContracts/IShopLogic.cs | 4 + .../StoragesContracts/IShopStorage.cs | 3 + .../ViewModels/ShopViewModel.cs | 3 + .../Models/IShopModel.cs | 3 + .../DataFileSingleton.cs | 7 + .../Implements/ShopStorage.cs | 139 ++++++++++++++++++ .../Models/Shop.cs | 110 ++++++++++++++ 8 files changed, 271 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs index ac86b1c..0afcf18 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs @@ -18,5 +18,7 @@ namespace BlacksmithWorkshopContracts.BindingModels public Dictionary Manufactures { get; set; } = new(); public int Id { get; set; } + + public int MaxCountManufactures { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs index 5264ee8..8a2052c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -23,5 +23,9 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts bool Delete(ShopBindingModel model); bool AddManufacture(ShopSearchModel model, IManufactureModel manufacture, int count); + + bool SellManufatures(IManufactureModel model, int count); + + bool AddManufactures(IManufactureModel model, int count); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs index dcc0c25..8807186 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using BlacksmithWorkshopContracts.BindingModels; using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -22,5 +23,7 @@ namespace BlacksmithWorkshopContracts.StoragesContracts ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + + bool SellManufactures(IManufactureModel, int count); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs index 1248cd6..9604850 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs @@ -22,5 +22,8 @@ namespace BlacksmithWorkshopContracts.ViewModels public DateTime DateOpen { get; set; } = DateTime.Now; public Dictionary Manufactures { get; set; } = new(); + + [DisplayName("Вместимость магазина")] + public int MaxCountManufactures { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs index f2e631b..46e4d68 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs @@ -19,6 +19,9 @@ namespace BlacksmithWorkshopDataModels.Models //дата открытия магазина DateTime DateOpen { get; } + //максимальное кол-во изделий в магазине + int MaxCountManufactures { get; } + //изделия в магазине Dictionary Manufactures { get; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs index b6628a3..cdfa5b6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -18,12 +18,16 @@ namespace BlacksmithWorkshopFileImplement private readonly string ManufactureFileName = "Manufacture.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List WorkPieces { get; private set; } public List Orders { get; private set; } public List Manufactures { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -40,11 +44,14 @@ namespace BlacksmithWorkshopFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + private DataFileSingleton() { WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!; Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.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/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..fb812ac --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,139 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using BlacksmithWorkshopFileImplement.Models; +using System.Net; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.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.ShopName.Contains(model.ShopName) || x.Id == model.Id); + + if (shop == null) + { + return null; + } + + shop.Update(model); + _source.SaveShops(); + + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + 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 bool SellIceCreams(IIceCreamModel model, int count) + { + if (_source.Shops.Select(x => x.IceCreams.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count) + { + return false; + } + + var list = _source.Shops.Where(x => x.IceCreams.ContainsKey(model.Id)); + + foreach (var shop in list) + { + if (shop.IceCreams[model.Id].Item2 < count) + { + count -= shop.IceCreams[model.Id].Item2; + shop.IceCreams[model.Id] = (shop.IceCreams[model.Id].Item1, 0); + } + else + { + shop.IceCreams[model.Id] = (shop.IceCreams[model.Id].Item1, shop.IceCreams[model.Id].Item2 - count); + count -= count; + } + + Update(new() + { + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCountManufactures = shop.MaxCountManufacturess, + Manufactures = shop.Manufactures + }); + + if (count == 0) + { + return true; + } + } + + return true; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs new file mode 100644 index 0000000..1f578b0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs @@ -0,0 +1,110 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpen { get; set; } + + public int MaxCountManufactures { get; set; } + + public Dictionary countManufacture { get; private set; } = new(); + + public Dictionary _manufactures = null; + + public Dictionary Manufactures + { + get + { + if (_manufactures == null) + { + var source = DataFileSingleton.GetInstance(); + _manufactures = countManufacture.ToDictionary(x => x.Key, y => ((source.Manufactures.FirstOrDefault(z => z.Id == y.Key) as IManufactureModel)!, y.Value)); + } + + return _manufactures; + } + } + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + MaxCountManufactures = model.MaxCountManufactures, + countManufacture = model.Manufactures.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + MaxCountManufactures = Convert.ToInt32(element.Element("MaxCountManufactures")!.Value), + countManufacture = element.Element("Manufactures")!.Elements("Manufactures").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + MaxCountManufactures = model.MaxCountManufactures; + countManufacture = model.Manufactures.ToDictionary(x => x.Key, x => x.Value.Item2); + _manufactures = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + MaxCountManufactures = MaxCountManufactures, + Manufactures = Manufactures + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", DateOpen.ToString()), + new XElement("MaxCountManufactures", MaxCountManufactures.ToString()), + new XElement("Manufactures", countManufature.Select(x => new XElement("Manufactures", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} -- 2.25.1 From d377511cba893b5b9911aa9c57231143a80dab9c Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 11:23:25 +0400 Subject: [PATCH 16/21] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=BC=D0=B5=D0=B6?= =?UTF-8?q?=D1=83=D1=82=D0=BE=D1=87=D0=BD=D0=BE=D0=B5=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 24 +++++++- .../BusinessLogic/ShopLogic.cs | 61 ++++++++++++++++++- .../StoragesContracts/IShopStorage.cs | 2 +- .../DataFileSingleton.cs | 2 +- .../Implements/ShopStorage.cs | 16 ++--- .../Models/Shop.cs | 2 +- 6 files changed, 91 insertions(+), 16 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs index ab54224..0fa275f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -20,10 +20,16 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopLogic _shopLogic; + + private readonly IManufactureStorage _manufactureStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IManufactureStorage manufactureStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _manufactureStorage = manufactureStorage; } //вывод отфильтрованного списка компонентов @@ -122,7 +128,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения"); } - _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ManufactureId:{Id}", model.Id, model.Sum, model.ManufactureId); + _logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ManufactureId:{Id}. Sum:{Sum}", model.Id, model.Sum, model.ManufactureId, model.Sum); } //обновление статуса заказа @@ -146,9 +152,21 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic model.Status = newOrderStatus; //проверка на выдачу - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; + + var manufacture = _manufactureStorage.GetElement(new() { Id = viewModel.ManufactureId }); + + if (manufacture == null) + { + throw new ArgumentNullException(nameof(manufacture)); + } + + if (!_shopLogic.AddManufactures(manufacture, viewModel.Count)) + { + throw new Exception($"AddManufactures operation failed. Shop is full."); + } } else { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs index 313d497..2ac74b1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs @@ -72,10 +72,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic if (count <= 0) { - throw new ArgumentNullException("Количество добавляемого мороженого должно быть больше 0", nameof(count)); + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); } - _logger.LogInformation("AddIceCream. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); + _logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); var shop = _shopStorage.GetElement(model); if (shop == null) @@ -99,6 +99,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic ShopName = shop.ShopName, Address = shop.Address, DateOpen = shop.DateOpen, + MaxCountManufactures = shop.MaxCountManufactures, Manufactures = shop.Manufactures }); @@ -181,5 +182,61 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + + public bool AddManufactures(IManufactureModel model, int count) + { + if (count <= 0) + { + throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count)); + } + + _logger.LogInformation("AddManufactures. Manufacture: {Manufacture}. Count: {Count}", model?.ManufactureName, count); + + var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountManufactures - x.Manufactures.Select(x => x.Value.Item2).Sum()).Sum() - count; + + if (capacity < 0) + { + _logger.LogWarning("AddManufactures operation failed. Sell {count} Manufactures ", -capacity); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count) + { + if (!AddManufacture(new() { Id = shop.Id }, model, shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum())) + { + _logger.LogWarning("AddManufactures operation failed."); + + return false; + } + + count -= shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum(); + } + else + { + if (!AddManufacture(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddManufactures operation failed."); + + return false; + } + + count -= count; + } + + if (count == 0) + { + return true; + } + } + + return true; + } + + public bool SellManufatures(IManufactureModel model, int count) + { + return _shopStorage.SellManufactures(model, count); + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs index 8807186..b930656 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -24,6 +24,6 @@ namespace BlacksmithWorkshopContracts.StoragesContracts ShopViewModel? Delete(ShopBindingModel model); - bool SellManufactures(IManufactureModel, int count); + bool SellManufactures(IManufactureModel model, int count); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs index cdfa5b6..e501fc8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -26,7 +26,7 @@ namespace BlacksmithWorkshopFileImplement public List Manufactures { get; private set; } - public List Shops { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs index fb812ac..65a67cc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ShopStorage.cs @@ -96,25 +96,25 @@ namespace BlacksmithWorkshopFileImplement.Implements return null; } - public bool SellIceCreams(IIceCreamModel model, int count) + public bool SellManufactures(IManufactureModel model, int count) { - if (_source.Shops.Select(x => x.IceCreams.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count) + if (_source.Shops.Select(x => x.Manufactures.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count) { return false; } - var list = _source.Shops.Where(x => x.IceCreams.ContainsKey(model.Id)); + var list = _source.Shops.Where(x => x.Manufactures.ContainsKey(model.Id)); foreach (var shop in list) { - if (shop.IceCreams[model.Id].Item2 < count) + if (shop.Manufactures[model.Id].Item2 < count) { - count -= shop.IceCreams[model.Id].Item2; - shop.IceCreams[model.Id] = (shop.IceCreams[model.Id].Item1, 0); + count -= shop.Manufactures[model.Id].Item2; + shop.Manufactures[model.Id] = (shop.Manufactures[model.Id].Item1, 0); } else { - shop.IceCreams[model.Id] = (shop.IceCreams[model.Id].Item1, shop.IceCreams[model.Id].Item2 - count); + shop.Manufactures[model.Id] = (shop.Manufactures[model.Id].Item1, shop.Manufactures[model.Id].Item2 - count); count -= count; } @@ -123,7 +123,7 @@ namespace BlacksmithWorkshopFileImplement.Implements ShopName = shop.ShopName, Address = shop.Address, DateOpen = shop.DateOpen, - MaxCountManufactures = shop.MaxCountManufacturess, + MaxCountManufactures = shop.MaxCountManufactures, Manufactures = shop.Manufactures }); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs index 1f578b0..fa00ef2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Shop.cs @@ -103,7 +103,7 @@ namespace BlacksmithWorkshopFileImplement.Models new XElement("Address", Address), new XElement("DateOpen", DateOpen.ToString()), new XElement("MaxCountManufactures", MaxCountManufactures.ToString()), - new XElement("Manufactures", countManufature.Select(x => new XElement("Manufactures", + new XElement("Manufactures", countManufacture.Select(x => new XElement("Manufactures", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); } -- 2.25.1 From d1dc6f93d8bee19a532412f82008f150917db299 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 16:26:01 +0400 Subject: [PATCH 17/21] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=BD=D0=B0=20FormMain.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 90 +++++++------ .../BlacksmithWorkshop/FormMain.cs | 20 +++ .../BlacksmithWorkshop/FormMain.resx | 5 +- .../FormSellManufacture.Designer.cs | 39 ++++++ .../BlacksmithWorkshop/FormSellManufacture.cs | 20 +++ .../FormSellManufacture.resx | 120 ++++++++++++++++++ 6 files changed, 251 insertions(+), 43 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 6248df9..a432484 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -34,33 +34,32 @@ this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.workPieceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.manufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.shopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addManufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonSellManufacture = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.menuStrip1.SuspendLayout(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(10, 27); - this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Location = new System.Drawing.Point(11, 36); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(820, 302); + this.dataGridView.Size = new System.Drawing.Size(937, 448); this.dataGridView.TabIndex = 0; // // buttonCreateOrder // - this.buttonCreateOrder.Location = new System.Drawing.Point(887, 50); - this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCreateOrder.Location = new System.Drawing.Point(1014, 67); this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(206, 22); + this.buttonCreateOrder.Size = new System.Drawing.Size(235, 29); this.buttonCreateOrder.TabIndex = 1; this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.UseVisualStyleBackColor = true; @@ -68,10 +67,9 @@ // // buttonTakeOrderInWork // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(887, 107); - this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1014, 143); this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(206, 22); + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(235, 29); this.buttonTakeOrderInWork.TabIndex = 2; this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; @@ -79,10 +77,9 @@ // // buttonOrderReady // - this.buttonOrderReady.Location = new System.Drawing.Point(887, 165); - this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonOrderReady.Location = new System.Drawing.Point(1014, 220); this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(206, 22); + this.buttonOrderReady.Size = new System.Drawing.Size(235, 29); this.buttonOrderReady.TabIndex = 3; this.buttonOrderReady.Text = "Заказ готов"; this.buttonOrderReady.UseVisualStyleBackColor = true; @@ -90,10 +87,9 @@ // // buttonIssuedOrder // - this.buttonIssuedOrder.Location = new System.Drawing.Point(887, 222); - this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonIssuedOrder.Location = new System.Drawing.Point(1014, 296); this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(206, 22); + this.buttonIssuedOrder.Size = new System.Drawing.Size(235, 29); this.buttonIssuedOrder.TabIndex = 4; this.buttonIssuedOrder.Text = "Заказ выдан"; this.buttonIssuedOrder.UseVisualStyleBackColor = true; @@ -101,26 +97,25 @@ // // buttonRef // - this.buttonRef.Location = new System.Drawing.Point(887, 277); - this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRef.Location = new System.Drawing.Point(1014, 369); this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(206, 22); + this.buttonRef.Size = new System.Drawing.Size(235, 29); this.buttonRef.TabIndex = 5; this.buttonRef.Text = "Обновить"; this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // - // menuStrip1 + // menuStrip // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2); - this.menuStrip1.Size = new System.Drawing.Size(1135, 24); - this.menuStrip1.TabIndex = 6; - this.menuStrip1.Text = "menuStrip1"; + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Padding = new System.Windows.Forms.Padding(6, 3, 0, 3); + this.menuStrip.Size = new System.Drawing.Size(1297, 30); + this.menuStrip.TabIndex = 6; + this.menuStrip.Text = "menuStrip1"; // // toolStripMenuItem // @@ -130,57 +125,67 @@ this.shopToolStripMenuItem, this.addManufactureToolStripMenuItem}); this.toolStripMenuItem.Name = "toolStripMenuItem"; - this.toolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.toolStripMenuItem.Size = new System.Drawing.Size(117, 24); this.toolStripMenuItem.Text = "Справочники"; // // workPieceToolStripMenuItem // this.workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem"; - this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(251, 26); this.workPieceToolStripMenuItem.Text = "Заготовки"; this.workPieceToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceToolStripMenuItem_Click); // // manufactureToolStripMenuItem // this.manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem"; - this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(251, 26); this.manufactureToolStripMenuItem.Text = "Изделия"; this.manufactureToolStripMenuItem.Click += new System.EventHandler(this.ManufactureToolStripMenuItem_Click); // // shopToolStripMenuItem // this.shopToolStripMenuItem.Name = "shopToolStripMenuItem"; - this.shopToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.shopToolStripMenuItem.Size = new System.Drawing.Size(251, 26); this.shopToolStripMenuItem.Text = "Магазины"; this.shopToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); // // addManufactureToolStripMenuItem // this.addManufactureToolStripMenuItem.Name = "addManufactureToolStripMenuItem"; - this.addManufactureToolStripMenuItem.Size = new System.Drawing.Size(198, 22); + this.addManufactureToolStripMenuItem.Size = new System.Drawing.Size(251, 26); this.addManufactureToolStripMenuItem.Text = "Пополнение магазина"; this.addManufactureToolStripMenuItem.Click += new System.EventHandler(this.AddManufactureToolStripMenuItem_Click); // + // buttonSellManufacture + // + this.buttonSellManufacture.Location = new System.Drawing.Point(1014, 440); + this.buttonSellManufacture.Name = "buttonSellManufacture"; + this.buttonSellManufacture.Size = new System.Drawing.Size(233, 29); + this.buttonSellManufacture.TabIndex = 7; + this.buttonSellManufacture.Text = "Продажа изделий"; + this.buttonSellManufacture.UseVisualStyleBackColor = true; + this.buttonSellManufacture.Click += new System.EventHandler(this.ButtonSellManufacture_Click); + // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1135, 338); + this.ClientSize = new System.Drawing.Size(1297, 496); + this.Controls.Add(this.buttonSellManufacture); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); this.Controls.Add(this.buttonOrderReady); this.Controls.Add(this.buttonTakeOrderInWork); this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; this.Name = "FormMain"; this.Text = "Кузнечная мастерская"; this.Load += new System.EventHandler(this.FormMain_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -194,11 +199,12 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; - private MenuStrip menuStrip1; + private MenuStrip menuStrip; private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem workPieceToolStripMenuItem; private ToolStripMenuItem manufactureToolStripMenuItem; private ToolStripMenuItem shopToolStripMenuItem; private ToolStripMenuItem addManufactureToolStripMenuItem; + private Button buttonSellManufacture; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index b740d55..a3c9c40 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -177,11 +177,31 @@ namespace BlacksmithWorkshop } } + private void ButtonSellIceCream_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture)); + if (service is FormSellManufacture form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonRef_Click(object sender, EventArgs e) { LoadData(); } + private void ButtonSellManufacture_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture)); + if (service is FormSellManufacture form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ShopToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormShops)); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx index 938108a..019817b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.resx @@ -57,7 +57,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + 63 + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs new file mode 100644 index 0000000..05b68d7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs @@ -0,0 +1,39 @@ +namespace BlacksmithWorkshop +{ + partial class FormSellManufacture + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormSellManufacture"; + } + + #endregion + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs new file mode 100644 index 0000000..baf2751 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs @@ -0,0 +1,20 @@ +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 BlacksmithWorkshop +{ + public partial class FormSellManufacture : Form + { + public FormSellManufacture() + { + InitializeComponent(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.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 -- 2.25.1 From e1b22db805249676600a8b103f6449bdd7ff4c04 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 16:36:11 +0400 Subject: [PATCH 18/21] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=B0=D0=B6=D0=B8=20=D0=B8=D0=B7=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormSellManufacture.Designer.cs | 88 ++++++++++++++++++- .../BlacksmithWorkshop/FormSellManufacture.cs | 84 +++++++++++++++++- .../FormSellManufacture.resx | 62 +------------ 3 files changed, 168 insertions(+), 66 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs index 05b68d7..546bd48 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.Designer.cs @@ -28,12 +28,94 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.labelManufacture = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxManufacture = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelManufacture + // + this.labelManufacture.AutoSize = true; + this.labelManufacture.Location = new System.Drawing.Point(32, 32); + this.labelManufacture.Name = "labelManufacture"; + this.labelManufacture.Size = new System.Drawing.Size(71, 20); + this.labelManufacture.TabIndex = 0; + this.labelManufacture.Text = "Изделие:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(34, 85); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // comboBoxManufacture + // + this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxManufacture.FormattingEnabled = true; + this.comboBoxManufacture.Location = new System.Drawing.Point(170, 32); + this.comboBoxManufacture.Name = "comboBoxManufacture"; + this.comboBoxManufacture.Size = new System.Drawing.Size(262, 28); + this.comboBoxManufacture.TabIndex = 3; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(170, 85); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(262, 27); + this.textBoxCount.TabIndex = 4; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(239, 141); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 6; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(339, 141); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormSellManufacture + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormSellManufacture"; + this.ClientSize = new System.Drawing.Size(440, 180); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxManufacture); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelManufacture); + this.Name = "FormSellManufacture"; + this.Text = "Продажа изделий"; + this.Load += new System.EventHandler(this.FormSellManufacture_Load); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private Label labelManufacture; + private Label labelCount; + private ComboBox comboBoxManufacture; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs index baf2751..8c017a6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.cs @@ -1,4 +1,7 @@ -using System; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,86 @@ namespace BlacksmithWorkshop { public partial class FormSellManufacture : Form { - public FormSellManufacture() + private readonly ILogger _logger; + + private readonly IManufactureLogic _logicI; + + private readonly IShopLogic _logicS; + + public FormSellManufacture(ILogger logger, IManufactureLogic logicI, IShopLogic logicS) { InitializeComponent(); + + _logger = logger; + _logicI = logicI; + _logicS = logicS; + } + + private void FormSellManufacture_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка изделий для продажи"); + + try + { + var list = _logicI.ReadList(null); + if (list != null) + { + comboBoxManufacture.DisplayMember = "ManufactureName"; + comboBoxManufacture.ValueMember = "Id"; + comboBoxManufacture.DataSource = list; + comboBoxManufacture.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (comboBoxManufacture.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Продажа изделия"); + + try + { + var operationResult = _logicS.SellManufatures(_logicI.ReadElement(new ManufactureSearchModel() + { + Id = Convert.ToInt32(comboBoxManufacture.SelectedValue) + })!, 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/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx index 1af7de1..f298a7b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSellManufacture.resx @@ -1,64 +1,4 @@ - - - + -- 2.25.1 From bf266b777d14adc82a549aa12faa1b17dc278275 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 16:48:20 +0400 Subject: [PATCH 19/21] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=87=D1=82=D0=B8=20=D0=B2=D1=81=D1=91.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormShop.Designer.cs | 142 ++++++++++-------- .../BlacksmithWorkshop/FormShop.cs | 9 +- .../BlacksmithWorkshop/Program.cs | 1 + 3 files changed, 90 insertions(+), 62 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs index 24ee0ca..6eab97c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs @@ -34,59 +34,58 @@ this.textBoxAddress = new System.Windows.Forms.TextBox(); this.groupBoxIceCreams = new System.Windows.Forms.GroupBox(); this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.labelDate = new System.Windows.Forms.Label(); this.dateTimePickerDate = new System.Windows.Forms.DateTimePicker(); - this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.labelCount = new System.Windows.Forms.Label(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); this.groupBoxIceCreams.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); this.SuspendLayout(); // // labelName // this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(18, 10); + this.labelName.Location = new System.Drawing.Point(21, 13); this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.Size = new System.Drawing.Size(80, 20); this.labelName.TabIndex = 0; this.labelName.Text = "Название:"; // // labelAddress // this.labelAddress.AutoSize = true; - this.labelAddress.Location = new System.Drawing.Point(266, 9); + this.labelAddress.Location = new System.Drawing.Point(304, 12); this.labelAddress.Name = "labelAddress"; - this.labelAddress.Size = new System.Drawing.Size(43, 15); + this.labelAddress.Size = new System.Drawing.Size(54, 20); this.labelAddress.TabIndex = 1; this.labelAddress.Text = "Адрес:"; // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(86, 7); - this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Location = new System.Drawing.Point(107, 10); this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(138, 23); + this.textBoxName.Size = new System.Drawing.Size(157, 27); this.textBoxName.TabIndex = 2; // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(315, 6); - this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxAddress.Location = new System.Drawing.Point(364, 9); this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(138, 23); + this.textBoxAddress.Size = new System.Drawing.Size(157, 27); this.textBoxAddress.TabIndex = 3; // // groupBoxIceCreams // this.groupBoxIceCreams.Controls.Add(this.dataGridView); - this.groupBoxIceCreams.Location = new System.Drawing.Point(12, 62); - this.groupBoxIceCreams.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxIceCreams.Location = new System.Drawing.Point(14, 94); this.groupBoxIceCreams.Name = "groupBoxIceCreams"; - this.groupBoxIceCreams.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.groupBoxIceCreams.Size = new System.Drawing.Size(720, 206); + this.groupBoxIceCreams.Size = new System.Drawing.Size(823, 275); this.groupBoxIceCreams.TabIndex = 4; this.groupBoxIceCreams.TabStop = false; this.groupBoxIceCreams.Text = "Изделия"; @@ -98,57 +97,20 @@ this.ID, this.ColumnManufactureName, this.ColumnCount}); - this.dataGridView.Location = new System.Drawing.Point(5, 20); - this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Location = new System.Drawing.Point(6, 27); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(709, 182); + this.dataGridView.Size = new System.Drawing.Size(810, 243); this.dataGridView.TabIndex = 0; // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(411, 286); - this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(136, 22); - this.buttonSave.TabIndex = 5; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(579, 286); - this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(136, 22); - this.buttonCancel.TabIndex = 6; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // labelDate - // - this.labelDate.AutoSize = true; - this.labelDate.Location = new System.Drawing.Point(492, 9); - this.labelDate.Name = "labelDate"; - this.labelDate.Size = new System.Drawing.Size(90, 15); - this.labelDate.TabIndex = 7; - this.labelDate.Text = "Дата открытия:"; - // - // dateTimePickerDate - // - this.dateTimePickerDate.Location = new System.Drawing.Point(588, 7); - this.dateTimePickerDate.Name = "dateTimePickerDate"; - this.dateTimePickerDate.Size = new System.Drawing.Size(127, 23); - this.dateTimePickerDate.TabIndex = 9; - // // ID // this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; this.ID.Name = "ID"; this.ID.Visible = false; + this.ID.Width = 125; // // ColumnManufactureName // @@ -165,11 +127,67 @@ this.ColumnCount.Name = "ColumnCount"; this.ColumnCount.Width = 125; // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(470, 381); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(155, 29); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(662, 381); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(155, 29); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(562, 12); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(113, 20); + this.labelDate.TabIndex = 7; + this.labelDate.Text = "Дата открытия:"; + // + // dateTimePickerDate + // + this.dateTimePickerDate.Location = new System.Drawing.Point(681, 9); + this.dateTimePickerDate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dateTimePickerDate.Name = "dateTimePickerDate"; + this.dateTimePickerDate.Size = new System.Drawing.Size(145, 27); + this.dateTimePickerDate.TabIndex = 9; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(21, 55); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(173, 20); + this.labelCount.TabIndex = 10; + this.labelCount.Text = "Вместимость магазина:"; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(200, 53); + this.numericUpDownCount.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(145, 27); + this.numericUpDownCount.TabIndex = 11; + // // FormShop // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(744, 319); + this.ClientSize = new System.Drawing.Size(850, 425); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.labelCount); this.Controls.Add(this.dateTimePickerDate); this.Controls.Add(this.labelDate); this.Controls.Add(this.buttonCancel); @@ -179,12 +197,12 @@ this.Controls.Add(this.textBoxName); this.Controls.Add(this.labelAddress); this.Controls.Add(this.labelName); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormShop"; this.Text = "Магазин"; this.Load += new System.EventHandler(this.FormShop_Load); this.groupBoxIceCreams.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -205,5 +223,7 @@ private DataGridViewTextBoxColumn ID; private DataGridViewTextBoxColumn ColumnManufactureName; private DataGridViewTextBoxColumn ColumnCount; + private Label labelCount; + private NumericUpDown numericUpDownCount; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs index dc28673..86043c9 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs @@ -30,6 +30,7 @@ namespace BlacksmithWorkshop public FormShop(ILogger logger, IShopLogic logic) { InitializeComponent(); + _logger = logger; _logic = logic; _shopManufactures = new Dictionary(); @@ -46,11 +47,13 @@ namespace BlacksmithWorkshop { Id = _id.Value }); + if (view != null) { textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address.ToString(); dateTimePickerDate.Value = view.DateOpen; + numericUpDownCount.Value = view.MaxCountManufactures; _shopManufactures = view.Manufactures ?? new Dictionary(); LoadData(); } @@ -104,13 +107,17 @@ namespace BlacksmithWorkshop Id = _id ?? 0, ShopName = textBoxName.Text, Address = textBoxAddress.Text, - DateOpen = dateTimePickerDate.Value.Date + DateOpen = dateTimePickerDate.Value.Date, + MaxCountManufactures = (int)numericUpDownCount.Value }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 8e76a27..09752bf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -57,6 +57,7 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } -- 2.25.1 From 119050cef31c96c563239c291e07efb0cb144713 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 23 Mar 2023 22:00:37 +0400 Subject: [PATCH 20/21] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B0=D0=B3=D0=B0?= =?UTF-8?q?=D0=B7=D0=B8=D0=BD=D0=B0=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=D1=8F=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.cs | 1 - .../BusinessLogic/ShopLogic.cs | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index a3c9c40..6420d72 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -212,7 +212,6 @@ namespace BlacksmithWorkshop } } - private void AddManufactureToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormAddManufacture)); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs index 2ac74b1..acb9128 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -78,7 +79,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); var shop = _shopStorage.GetElement(model); - if (shop == null) + if (shop == null || !CheckShopCount(shop, count)) { _logger.LogWarning("Add Manufacture operation failed"); @@ -106,6 +107,24 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } + //проверка на переполнение магазина + private bool CheckShopCount(ShopViewModel model, int count) + { + int _countManufactures = 0; + + foreach (var manufacture in model.Manufactures) + { + _countManufactures += model.Manufactures[manufacture.Key].Item2; + } + + if(_countManufactures + count > model.MaxCountManufactures) + { + return false; + } + + return true; + } + public bool Create(ShopBindingModel model) { CheckModel(model); -- 2.25.1 From 5afff36beef3c4a58f7b591f2a31323fe6587641 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 24 Mar 2023 00:35:13 +0400 Subject: [PATCH 21/21] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ShopLogic.cs | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs index acb9128..2985011 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogic/ShopLogic.cs @@ -79,13 +79,18 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic _logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id); var shop = _shopStorage.GetElement(model); - if (shop == null || !CheckShopCount(shop, count)) + if (shop == null) { _logger.LogWarning("Add Manufacture operation failed"); return false; } + if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count)); + } + if (!shop.Manufactures.ContainsKey(manufacture.Id)) { shop.Manufactures[manufacture.Id] = (manufacture, count); @@ -107,24 +112,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic return true; } - //проверка на переполнение магазина - private bool CheckShopCount(ShopViewModel model, int count) - { - int _countManufactures = 0; - - foreach (var manufacture in model.Manufactures) - { - _countManufactures += model.Manufactures[manufacture.Key].Item2; - } - - if(_countManufactures + count > model.MaxCountManufactures) - { - return false; - } - - return true; - } - public bool Create(ShopBindingModel model) { CheckModel(model); -- 2.25.1