From 2f4c7b4db47bc9ba9d8ca526c7047acbe08b8b9d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 13 Feb 2023 23:46:35 +0400 Subject: [PATCH 01/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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/12] =?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