From b5492713413b48c30605cef0b72bc10d64386c5a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 15:30:32 +0400 Subject: [PATCH 01/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm.sln | 8 +- .../LawFirmFileImplement.csproj | 14 +++ LawFirm/LawFirmFileImplement/Models/Blank.cs | 74 ++++++++++++ .../LawFirmFileImplement/Models/Document.cs | 105 +++++++++++++++++ LawFirm/LawFirmFileImplement/Models/Order.cs | 110 ++++++++++++++++++ 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj create mode 100644 LawFirm/LawFirmFileImplement/Models/Blank.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Document.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Order.cs diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 93a0ebb..362180a 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.Build.0 = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj new file mode 100644 index 0000000..7c491f4 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Blank.cs b/LawFirm/LawFirmFileImplement/Models/Blank.cs new file mode 100644 index 0000000..2e7bbfd --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Blank.cs @@ -0,0 +1,74 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.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 LawFirmFileImplement.Models +{ + public class Blank : IBlankModel + { + public string BlankName { get; private set; } = String.Empty; + + public double Cost { get; set; } + + public int Id { get; private set; } + + public static Blank? Create(BlankBindingModel? model) + { + if (model == null) + { + return null; + } + return new Blank() + { + Id = model.Id, + BlankName = model.BlankName, + Cost = model.Cost + }; + } + + public static Blank? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Blank() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + BlankName = element.Element("BlankName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(BlankBindingModel? model) + { + if (model == null) + { + return; + } + BlankName = model.BlankName; + Cost = model.Cost; + } + public BlankViewModel GetViewModel => new() + { + Id = Id, + BlankName = BlankName, + Cost = Cost + }; + + public XElement GetXElement => new( + "Blank", + new XAttribute("Id", Id), + new XElement("BlankName", BlankName), + new XElement("Cost", Cost.ToString()) + ); + + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs new file mode 100644 index 0000000..6484a59 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -0,0 +1,105 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Document : IDocumentModel + { + public string DocumentName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public int Id { get; private set; } + + public Dictionary Blanks { get; private set; } = new(); + + private Dictionary? _documentBlanks = null; + public Dictionary DocumentBlanks + { + get + { + if (_documentBlanks == null) + { + var source = DataFileSingleton.GetInstance(); + _documentBlanks = Blanks.ToDictionary( + x => x.Key, + y => ((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!, y.Value) + ); + } + return _documentBlanks; + } + } + + + public static Document? Create(DocumentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Document? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Document() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Blanks = element.Element("DocumentBlanks")!.Elements("DocumentBlank").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + + + public void Update(DocumentBindingModel? model) + { + if (model == null) + { + return; + } + DocumentName = model.DocumentName; + Price = model.Price; + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2); + _documentBlanks = null; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentBlanks = DocumentBlanks + }; + + public XElement GetXElement => new( + "Document", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("DocumentBlanks", Blanks.Select(x => + new XElement("DocumentBlank", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs new file mode 100644 index 0000000..28a6a3a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -0,0 +1,110 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Order : IOrderModel + { + public int DocumentId { get; private set; } + + public string DocumentName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + DocumentId = model.DocumentId, + DocumentName = model.DocumentName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value) + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + DocumentId = model.DocumentId; + DocumentName = model.DocumentName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + + public OrderViewModel GetViewModel => new() + { + DocumentId = DocumentId, + DocumentName = DocumentName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + + public XElement GetXElement => new( + "Order", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("DocumentId", DocumentId.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 2554343f45a9f3e95005754de42a55524372ed90 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 16:28:53 +0400 Subject: [PATCH 02/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D1=81=D0=B8=D0=BD=D0=B3=D0=BB=D1=82=D0=BE=D0=BD=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawFirmFileImplement/DataFileSingleton.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/DataFileSingleton.cs diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..baa110a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -0,0 +1,55 @@ +using LawFirmFileImplement.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 LawFirmFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string BlankFileName = "Blank.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string DocumentFileName = "Document.xml"; + public List Blanks { get; private set; } + public List Orders { get; private set; } + public List Documents { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement); + public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; + Documents = LoadData(DocumentFileName, "Document", x => Document.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 1e40bf95cb9ca17b12b45b466ff5cdcd8eab75b8 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:28:24 +0400 Subject: [PATCH 03/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BlankStorage.cs | 88 +++++++++++++++++++ .../Implements/DocumentStorage.cs | 87 ++++++++++++++++++ .../Implements/OrderStorage.cs | 87 ++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs new file mode 100644 index 0000000..47b885b --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -0,0 +1,88 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class BlankStorage : IBlankStorage + { + private readonly DataFileSingleton source; + + public BlankStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public BlankViewModel? GetElement(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue) + { + return null; + } + return source.Blanks + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName)) + { + return new(); + } + return source.Blanks + .Where(x => x.BlankName.Contains(model.BlankName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Blanks.Select(x => x.GetViewModel).ToList(); + } + + public BlankViewModel? Insert(BlankBindingModel model) + { + model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1; + var newBlank = Blank.Create(model); + if (newBlank == null) + { + return null; + } + source.Blanks.Add(newBlank); + source.SaveBlanks(); + return newBlank.GetViewModel; + } + + public BlankViewModel? Update(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + public BlankViewModel? Delete(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..8de8fd2 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class DocumentStorage : IDocumentStorage + { + private readonly DataFileSingleton source; + + public DocumentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue) + { + return null; + } + return source.Documents + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + return source.Documents + .Where(x => x.DocumentName.Contains(model.DocumentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Documents.Select(x => x.GetViewModel).ToList(); + } + + public DocumentViewModel? Insert(DocumentBindingModel model) + { + model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1; + var newDoc = Document.Create(model); + if (newDoc == null) + { + return null; + } + source.Documents.Add(newDoc); + source.SaveDocuments(); + return newDoc.GetViewModel; + } + + public DocumentViewModel? Update(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..7b35304 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + + } +} -- 2.25.1 From 8ecffb665ca4df20a1766b36826b341fedeed029 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:41:53 +0400 Subject: [PATCH 04/32] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/LawFirmView.csproj | 1 + LawFirm/LawFirm/Program.cs | 4 +++- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 45754fd..7f7c8cf 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -17,6 +17,7 @@ + diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index b634a21..09dd87f 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -1,7 +1,7 @@ using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.StorageContracts; -using LawFirmListImplements.Implements; +using LawFirmFileImplement.Implements; using LawFirmView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -41,9 +41,11 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 8de8fd2..7629dfa 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class DocumentStorage : IDocumentStorage + public class DocumentStorage : IDocumentStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 7b35304..baee8c5 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class OrderStorage : IOrderStorage + public class OrderStorage : IOrderStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj index 7c491f4..77fe5b1 100644 --- a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 -- 2.25.1 From 9f25b5734cce46c4ae6969948bd2d2172df2d978 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 15:30:32 +0400 Subject: [PATCH 05/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm.sln | 8 +- .../LawFirmFileImplement.csproj | 14 +++ LawFirm/LawFirmFileImplement/Models/Blank.cs | 74 ++++++++++++ .../LawFirmFileImplement/Models/Document.cs | 105 +++++++++++++++++ LawFirm/LawFirmFileImplement/Models/Order.cs | 110 ++++++++++++++++++ 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj create mode 100644 LawFirm/LawFirmFileImplement/Models/Blank.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Document.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Order.cs diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 93a0ebb..362180a 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.Build.0 = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj new file mode 100644 index 0000000..7c491f4 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Blank.cs b/LawFirm/LawFirmFileImplement/Models/Blank.cs new file mode 100644 index 0000000..2e7bbfd --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Blank.cs @@ -0,0 +1,74 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.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 LawFirmFileImplement.Models +{ + public class Blank : IBlankModel + { + public string BlankName { get; private set; } = String.Empty; + + public double Cost { get; set; } + + public int Id { get; private set; } + + public static Blank? Create(BlankBindingModel? model) + { + if (model == null) + { + return null; + } + return new Blank() + { + Id = model.Id, + BlankName = model.BlankName, + Cost = model.Cost + }; + } + + public static Blank? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Blank() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + BlankName = element.Element("BlankName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(BlankBindingModel? model) + { + if (model == null) + { + return; + } + BlankName = model.BlankName; + Cost = model.Cost; + } + public BlankViewModel GetViewModel => new() + { + Id = Id, + BlankName = BlankName, + Cost = Cost + }; + + public XElement GetXElement => new( + "Blank", + new XAttribute("Id", Id), + new XElement("BlankName", BlankName), + new XElement("Cost", Cost.ToString()) + ); + + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs new file mode 100644 index 0000000..6484a59 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -0,0 +1,105 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Document : IDocumentModel + { + public string DocumentName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public int Id { get; private set; } + + public Dictionary Blanks { get; private set; } = new(); + + private Dictionary? _documentBlanks = null; + public Dictionary DocumentBlanks + { + get + { + if (_documentBlanks == null) + { + var source = DataFileSingleton.GetInstance(); + _documentBlanks = Blanks.ToDictionary( + x => x.Key, + y => ((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!, y.Value) + ); + } + return _documentBlanks; + } + } + + + public static Document? Create(DocumentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Document? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Document() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Blanks = element.Element("DocumentBlanks")!.Elements("DocumentBlank").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + + + public void Update(DocumentBindingModel? model) + { + if (model == null) + { + return; + } + DocumentName = model.DocumentName; + Price = model.Price; + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2); + _documentBlanks = null; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentBlanks = DocumentBlanks + }; + + public XElement GetXElement => new( + "Document", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("DocumentBlanks", Blanks.Select(x => + new XElement("DocumentBlank", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs new file mode 100644 index 0000000..28a6a3a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -0,0 +1,110 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Order : IOrderModel + { + public int DocumentId { get; private set; } + + public string DocumentName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + DocumentId = model.DocumentId, + DocumentName = model.DocumentName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value) + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + DocumentId = model.DocumentId; + DocumentName = model.DocumentName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + + public OrderViewModel GetViewModel => new() + { + DocumentId = DocumentId, + DocumentName = DocumentName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + + public XElement GetXElement => new( + "Order", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("DocumentId", DocumentId.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 2d57093fb6a6de2bc0a6415008550b2991ff67fa Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 16:28:53 +0400 Subject: [PATCH 06/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D1=81=D0=B8=D0=BD=D0=B3=D0=BB=D1=82=D0=BE=D0=BD=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawFirmFileImplement/DataFileSingleton.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/DataFileSingleton.cs diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..baa110a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -0,0 +1,55 @@ +using LawFirmFileImplement.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 LawFirmFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string BlankFileName = "Blank.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string DocumentFileName = "Document.xml"; + public List Blanks { get; private set; } + public List Orders { get; private set; } + public List Documents { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement); + public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; + Documents = LoadData(DocumentFileName, "Document", x => Document.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 8345b53f15ec9952354886fb06a4394d57067cd5 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:28:24 +0400 Subject: [PATCH 07/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BlankStorage.cs | 88 +++++++++++++++++++ .../Implements/DocumentStorage.cs | 87 ++++++++++++++++++ .../Implements/OrderStorage.cs | 87 ++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs new file mode 100644 index 0000000..47b885b --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -0,0 +1,88 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class BlankStorage : IBlankStorage + { + private readonly DataFileSingleton source; + + public BlankStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public BlankViewModel? GetElement(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue) + { + return null; + } + return source.Blanks + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName)) + { + return new(); + } + return source.Blanks + .Where(x => x.BlankName.Contains(model.BlankName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Blanks.Select(x => x.GetViewModel).ToList(); + } + + public BlankViewModel? Insert(BlankBindingModel model) + { + model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1; + var newBlank = Blank.Create(model); + if (newBlank == null) + { + return null; + } + source.Blanks.Add(newBlank); + source.SaveBlanks(); + return newBlank.GetViewModel; + } + + public BlankViewModel? Update(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + public BlankViewModel? Delete(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..8de8fd2 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class DocumentStorage : IDocumentStorage + { + private readonly DataFileSingleton source; + + public DocumentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue) + { + return null; + } + return source.Documents + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + return source.Documents + .Where(x => x.DocumentName.Contains(model.DocumentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Documents.Select(x => x.GetViewModel).ToList(); + } + + public DocumentViewModel? Insert(DocumentBindingModel model) + { + model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1; + var newDoc = Document.Create(model); + if (newDoc == null) + { + return null; + } + source.Documents.Add(newDoc); + source.SaveDocuments(); + return newDoc.GetViewModel; + } + + public DocumentViewModel? Update(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..7b35304 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + + } +} -- 2.25.1 From a342566d62eb3d2cd38b36eee6d5314c2168ebd2 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:41:53 +0400 Subject: [PATCH 08/32] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/LawFirmView.csproj | 1 + LawFirm/LawFirm/Program.cs | 4 +++- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 45754fd..7f7c8cf 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -17,6 +17,7 @@ + diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index b634a21..09dd87f 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -1,7 +1,7 @@ using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.StorageContracts; -using LawFirmListImplements.Implements; +using LawFirmFileImplement.Implements; using LawFirmView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -41,9 +41,11 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 8de8fd2..7629dfa 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class DocumentStorage : IDocumentStorage + public class DocumentStorage : IDocumentStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 7b35304..baee8c5 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class OrderStorage : IOrderStorage + public class OrderStorage : IOrderStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj index 7c491f4..77fe5b1 100644 --- a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 -- 2.25.1 From f4370b5d958f3df3f8758764bfb7aa3d8214117e Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 13 Feb 2023 09:29:17 +0400 Subject: [PATCH 09/32] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=202=20=D0=B1=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Models/Order.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 28a6a3a..7672d1a 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -63,7 +63,7 @@ namespace LawFirmFileImplement.Models Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value) + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) }; } -- 2.25.1 From faef920c5018c3d68de6d4036aed45da1ea69973 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Feb 2023 23:20:43 +0400 Subject: [PATCH 10/32] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D1=82=D0=B0=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BC=D0=B0?= =?UTF-8?q?=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ShopBindingModel.cs | 2 + .../ViewModels/ShopViewModel.cs | 3 + .../LawFirmDataModels/Models/IShopModel.cs | 1 + .../LawFirmFileImplement/DataFileSingleton.cs | 5 + .../Implements/BlankStorage.cs | 2 +- .../Implements/DocumentStorage.cs | 3 +- .../Implements/OrderStorage.cs | 2 +- .../Implements/ShopStorage.cs | 84 ++++++++++++ .../LawFirmFileImplement/Models/Document.cs | 2 +- LawFirm/LawFirmFileImplement/Models/Shop.cs | 121 ++++++++++++++++++ 10 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Shop.cs diff --git a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs index 167e727..462e6ed 100644 --- a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs +++ b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs @@ -18,5 +18,7 @@ namespace LawFirmContracts.BindingModels public Dictionary ShopDocuments { get; set; } = new(); public int Id { get; set; } + + public int MaxCountDocuments { get; set; } } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs index 8912255..a58ba7a 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs @@ -20,5 +20,8 @@ namespace LawFirmContracts.ViewModels public Dictionary ShopDocuments { get; set; } = new(); public int Id { get; set; } + + [DisplayName("Макс. документов в магазине")] + public int MaxCountDocuments { get; set; } } } diff --git a/LawFirm/LawFirmDataModels/Models/IShopModel.cs b/LawFirm/LawFirmDataModels/Models/IShopModel.cs index 9f7b436..0b00d18 100644 --- a/LawFirm/LawFirmDataModels/Models/IShopModel.cs +++ b/LawFirm/LawFirmDataModels/Models/IShopModel.cs @@ -12,5 +12,6 @@ namespace LawFirmDataModels.Models String Adress { get; } DateTime OpeningDate { get; } Dictionary ShopDocuments { get; } + int MaxCountDocuments { get; } } } diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs index baa110a..564e833 100644 --- a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -15,9 +15,12 @@ namespace LawFirmFileImplement private readonly string BlankFileName = "Blank.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string DocumentFileName = "Document.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Blanks { get; private set; } public List Orders { get; private set; } public List Documents { get; private set; } + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -29,11 +32,13 @@ namespace LawFirmFileImplement public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement); public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; Documents = LoadData(DocumentFileName, "Document", x => Document.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/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs index 47b885b..bb10978 100644 --- a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -79,7 +79,7 @@ namespace LawFirmFileImplement.Implements { return null; } - blank.Update(model); + source.Blanks.Remove(blank); source.SaveBlanks(); return blank.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 7629dfa..601bcd2 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace LawFirmFileImplement.Implements { @@ -78,7 +79,7 @@ namespace LawFirmFileImplement.Implements { return null; } - document.Update(model); + source.Documents.Remove(document); source.SaveDocuments(); return document.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index baee8c5..46a8d01 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - order.Update(model); + source.Orders.Remove(order); source.SaveOrders(); return order.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..7463c78 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,84 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return source.Shops + .Select(x => x.GetViewModel) + .Where(x => x.Name.Contains(model.Name ?? string.Empty)) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(shop => shop.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs index 6484a59..30ce0bb 100644 --- a/LawFirm/LawFirmFileImplement/Models/Document.cs +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -92,7 +92,7 @@ namespace LawFirmFileImplement.Models }; public XElement GetXElement => new( - "Document", + "Document", new XAttribute("Id", Id), new XElement("DocumentName", DocumentName), new XElement("Price", Price.ToString()), diff --git a/LawFirm/LawFirmFileImplement/Models/Shop.cs b/LawFirm/LawFirmFileImplement/Models/Shop.cs new file mode 100644 index 0000000..f3e0b1f --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Shop.cs @@ -0,0 +1,121 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public string Adress { get; private set; } = string.Empty; + + public int MaxCountDocuments { get; private set; } + + public DateTime OpeningDate { get; private set; } + + public Dictionary Documents { get; private set; } = new(); + + private Dictionary? _shopDocuments = null; + + public Dictionary ShopDocuments + { + get + { + if (_shopDocuments == null) + { + var source = DataFileSingleton.GetInstance(); + _shopDocuments = Documents.ToDictionary( + x => x.Key, + y => ((source.Documents.FirstOrDefault(z => z.Id == y.Key) as IDocumentModel)!, y.Value) + ); + } + return _shopDocuments; + } + } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + Name = model.Name, + Adress = model.Adress, + MaxCountDocuments = model.MaxCountDocuments, + OpeningDate = model.OpeningDate, + Documents = model.ShopDocuments.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), + Name = element.Element("Name")!.Value, + Adress = element.Element("Address")!.Value, + MaxCountDocuments = Convert.ToInt32(element.Element("MaxCountDocuments")!.Value), + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Documents= element.Element("ShopDocuments")!.Elements("ShopDocument").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + Name = model.Name; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + MaxCountDocuments = model.MaxCountDocuments; + Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopDocuments = null; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Adress = Adress, + OpeningDate = OpeningDate, + ShopDocuments = ShopDocuments, + MaxCountDocuments = MaxCountDocuments + }; + + public XElement GetXElement => new( + "Shop", + new XAttribute("Id", Id), + new XElement("Name", Name), + new XElement("Address", Adress), + new XElement("MaxCountDocuments", MaxCountDocuments.ToString()), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopDocuments", Documents.Select (x => + new XElement("ShopDocument", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} + -- 2.25.1 From ccfe49dde98d3914b9b28ae1ab4f3904b8ff0a4c Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Feb 2023 23:22:27 +0400 Subject: [PATCH 11/32] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs index 47b885b..bb10978 100644 --- a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -79,7 +79,7 @@ namespace LawFirmFileImplement.Implements { return null; } - blank.Update(model); + source.Blanks.Remove(blank); source.SaveBlanks(); return blank.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 7629dfa..dd74260 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - document.Update(model); + source.Documents.Remove(document); source.SaveDocuments(); return document.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index baee8c5..46a8d01 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - order.Update(model); + source.Orders.Remove(order); source.SaveOrders(); return order.GetViewModel; } -- 2.25.1 From 5b5b8cc6ac6636956856d5e8ff3930c9e73a4775 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 27 Feb 2023 08:49:14 +0400 Subject: [PATCH 12/32] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 4 ++++ .../Implements/ShopStorage.cs | 21 +++++++++++++++++++ LawFirm/LawFirmFileImplement/Models/Shop.cs | 2 +- LawFirm/LawFirmListImplements/Models/Shop.cs | 9 +++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index b5de351..47dd9df 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -154,6 +154,10 @@ namespace LawFirmBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name)); } + if (model.MaxCountDocuments < 0) + { + throw new InvalidOperationException("Магазин с отрицательным количеством максимального количества документов!"); + } _logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id); var element = _shopStorage.GetElement(new ShopSearchModel { diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 7463c78..68a4838 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -11,6 +11,27 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { + + + // Нужно узнать, проверять ли на наличие всех товаров, или только + // наличие определенного товара + // То же самое с продажей + + + + + + + + + + + + + + + + public class ShopStorage : IShopStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/Models/Shop.cs b/LawFirm/LawFirmFileImplement/Models/Shop.cs index f3e0b1f..2abbcf9 100644 --- a/LawFirm/LawFirmFileImplement/Models/Shop.cs +++ b/LawFirm/LawFirmFileImplement/Models/Shop.cs @@ -109,7 +109,7 @@ namespace LawFirmFileImplement.Models new XAttribute("Id", Id), new XElement("Name", Name), new XElement("Address", Adress), - new XElement("MaxCountDocuments", MaxCountDocuments.ToString()), + new XElement("MaxCountDocuments", MaxCountDocuments), new XElement("OpeningDate", OpeningDate.ToString()), new XElement("ShopDocuments", Documents.Select (x => new XElement("ShopDocument", diff --git a/LawFirm/LawFirmListImplements/Models/Shop.cs b/LawFirm/LawFirmListImplements/Models/Shop.cs index 82805db..3de9b41 100644 --- a/LawFirm/LawFirmListImplements/Models/Shop.cs +++ b/LawFirm/LawFirmListImplements/Models/Shop.cs @@ -21,6 +21,8 @@ namespace LawFirmListImplements.Models public DateTime OpeningDate { get; private set; } + public int MaxCountDocuments { get; private set; } + public Dictionary ShopDocuments { get; private set; } = new(); public static Shop? Create (ShopBindingModel model) @@ -35,6 +37,7 @@ namespace LawFirmListImplements.Models Name = model.Name, Adress = model.Adress, OpeningDate = model.OpeningDate, + MaxCountDocuments = model.MaxCountDocuments, ShopDocuments = new() }; } @@ -49,6 +52,7 @@ namespace LawFirmListImplements.Models Adress = model.Adress; OpeningDate = model.OpeningDate; ShopDocuments = model.ShopDocuments; + MaxCountDocuments= model.MaxCountDocuments; } public ShopViewModel GetViewModel => new() @@ -57,7 +61,10 @@ namespace LawFirmListImplements.Models Name = Name, Adress = Adress, OpeningDate = OpeningDate, - ShopDocuments = ShopDocuments + ShopDocuments = ShopDocuments, + MaxCountDocuments = MaxCountDocuments }; + + } } -- 2.25.1 From 35ee01f5528965c82dc7e370bae12de2e0adbc5e Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 27 Feb 2023 09:49:29 +0400 Subject: [PATCH 13/32] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=BA=D0=B0=D1=8F-=D1=82=D0=BE=20?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B0=D0=B6=D0=B8=20=D0=B2=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7?= =?UTF-8?q?=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 106 ++++++++++++++---- 1 file changed, 85 insertions(+), 21 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 68a4838..fc2f25f 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -11,27 +11,6 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - - - // Нужно узнать, проверять ли на наличие всех товаров, или только - // наличие определенного товара - // То же самое с продажей - - - - - - - - - - - - - - - - public class ShopStorage : IShopStorage { private readonly DataFileSingleton source; @@ -101,5 +80,90 @@ namespace LawFirmFileImplement.Implements return shop.GetViewModel; } + public bool SellDocument(DocumentSearchModel model, int count) + { + var document = source.Documents.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id); + + var countStore = count; + + if (document == null) + { + return false; + } + + foreach (var shop in source.Shops) + { + foreach (var doc in shop.ShopDocuments) + { + if (doc.Value.Item1.Id == document.Id) + { + if (count > 0) + { + count = count - doc.Value.Item2; + } + } + if (count < 1) + { + break; + } + } + } + + if (count > 0) + { + return false; + } + + count = countStore; + + for (int i = 0; i < source.Shops.Count; i++) + { + var shop = source.Shops[i]; + var documents = shop.ShopDocuments; + + for (int j = 0; j < documents.Count; j++) + { + if (documents[j].Item1.Id == document.Id) + { + while (documents[j].Item2 > 0 || count > 0) + { + int tempItem2 = documents[j].Item2; + tempItem2--; + count--; + documents[j] = (documents[j].Item1, tempItem2); + } + } + + if (count < 1) + { + shop.Update(new ShopBindingModel + { + Id = shop.Id, + Name = shop.Name, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + MaxCountDocuments = shop.MaxCountDocuments, + ShopDocuments= documents + }); + break; + } + } + shop.Update(new ShopBindingModel + { + Id = shop.Id, + Name = shop.Name, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + MaxCountDocuments = shop.MaxCountDocuments, + ShopDocuments = documents + }); + } + + if (count > 0) + { + return false; + } + return true; + } } } -- 2.25.1 From de6f3af8df37523c020373e5f22dce9b5b06cdf6 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 27 Feb 2023 10:19:40 +0400 Subject: [PATCH 14/32] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0=20=D1=81=20=D1=83?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=D0=BC=20=D0=B5=D0=B3=D0=BE=20=D0=BC?= =?UTF-8?q?=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B8=D0=BC=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ShopLogic.cs | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index 47dd9df..19c676b 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -82,26 +82,37 @@ namespace LawFirmBusinessLogic.BusinessLogics } _logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name); - if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument)) + var countDocs = 0; + foreach (var doc in shopElement.ShopDocuments) { - shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count); - _logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + countDocs += doc.Value.Item2; + } + if (shopElement.MaxCountDocuments - countDocs >= count) + { + if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument)) + { + shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count); + _logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + } + else + { + shopElement.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + } + _shopStorage.Update(new() + { + Id = shopElement.Id, + Name = shopElement.Name, + Adress = shopElement.Adress, + OpeningDate = shopElement.OpeningDate, + ShopDocuments = shopElement.ShopDocuments + }); } else { - shopElement.ShopDocuments[document.Id] = (document, count); - _logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name); + _logger.LogWarning("Required shop is overflowed"); + return false; } - - _shopStorage.Update(new() - { - Id = shopElement.Id, - Name = shopElement.Name, - Adress = shopElement.Adress, - OpeningDate = shopElement.OpeningDate, - ShopDocuments = shopElement.ShopDocuments - }); - return true; } -- 2.25.1 From f20984c4ba085715b2f1866c99976ae66d739c88 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 27 Feb 2023 10:31:58 +0400 Subject: [PATCH 15/32] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BC=D0=B0=D0=B3=D0=B0?= =?UTF-8?q?=D0=B7=D0=B8=D0=BD=D0=B0=20=D1=81=20=D1=83=D1=87=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=BC=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormShop.Designer.cs | 70 ++++++++++++------- LawFirm/LawFirm/FormShop.cs | 8 ++- .../Implements/ShopStorage.cs | 12 ++-- 3 files changed, 58 insertions(+), 32 deletions(-) diff --git a/LawFirm/LawFirm/FormShop.Designer.cs b/LawFirm/LawFirm/FormShop.Designer.cs index 8c908c0..3c4d933 100644 --- a/LawFirm/LawFirm/FormShop.Designer.cs +++ b/LawFirm/LawFirm/FormShop.Designer.cs @@ -35,11 +35,13 @@ this.labelOpeningDate = new System.Windows.Forms.Label(); this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnDocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonSave = new System.Windows.Forms.Button(); + this.labelMaxCount = new System.Windows.Forms.Label(); + this.textBoxMaxCountDocs = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // @@ -98,33 +100,13 @@ this.ColumnId, this.ColumnDocumentName, this.ColumnCount}); - this.dataGridView.Location = new System.Drawing.Point(14, 138); + this.dataGridView.Location = new System.Drawing.Point(14, 173); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(401, 300); + this.dataGridView.Size = new System.Drawing.Size(401, 265); this.dataGridView.TabIndex = 10; // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(228, 448); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(155, 29); - this.buttonCancel.TabIndex = 12; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); - // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(48, 448); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(155, 29); - this.buttonSave.TabIndex = 11; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); - // // ColumnId // this.ColumnId.HeaderText = "ID"; @@ -147,11 +129,49 @@ this.ColumnCount.Name = "ColumnCount"; this.ColumnCount.Width = 125; // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(228, 448); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(155, 29); + this.buttonCancel.TabIndex = 12; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(48, 448); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(155, 29); + this.buttonSave.TabIndex = 11; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // labelMaxCount + // + this.labelMaxCount.AutoSize = true; + this.labelMaxCount.Location = new System.Drawing.Point(18, 128); + this.labelMaxCount.Name = "labelMaxCount"; + this.labelMaxCount.Size = new System.Drawing.Size(216, 20); + this.labelMaxCount.TabIndex = 13; + this.labelMaxCount.Text = "Макс. количество документов"; + // + // textBoxMaxCountDocs + // + this.textBoxMaxCountDocs.Location = new System.Drawing.Point(240, 128); + this.textBoxMaxCountDocs.Name = "textBoxMaxCountDocs"; + this.textBoxMaxCountDocs.Size = new System.Drawing.Size(175, 27); + this.textBoxMaxCountDocs.TabIndex = 14; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(445, 489); + this.Controls.Add(this.textBoxMaxCountDocs); + this.Controls.Add(this.labelMaxCount); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonSave); this.Controls.Add(this.dataGridView); @@ -184,5 +204,7 @@ private DataGridViewTextBoxColumn ColumnId; private DataGridViewTextBoxColumn ColumnDocumentName; private DataGridViewTextBoxColumn ColumnCount; + private Label labelMaxCount; + private TextBox textBoxMaxCountDocs; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormShop.cs b/LawFirm/LawFirm/FormShop.cs index 8091c6a..7083dd2 100644 --- a/LawFirm/LawFirm/FormShop.cs +++ b/LawFirm/LawFirm/FormShop.cs @@ -102,6 +102,11 @@ namespace LawFirmView MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (string.IsNullOrEmpty(textBoxMaxCountDocs.Text)) + { + MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Сохранение магазина"); try { @@ -110,7 +115,8 @@ namespace LawFirmView Id = _id ?? 0, Name = textBoxName.Text, Adress = textBoxAddress.Text, - OpeningDate = dateTimePicker.Value.Date + OpeningDate = dateTimePicker.Value.Date, + MaxCountDocuments = Convert.ToInt32(textBoxMaxCountDocs.Text) }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index fc2f25f..7a48f54 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -97,12 +97,9 @@ namespace LawFirmFileImplement.Implements { if (doc.Value.Item1.Id == document.Id) { - if (count > 0) - { - count = count - doc.Value.Item2; - } + count -= doc.Value.Item2; } - if (count < 1) + if (count <= 0) { break; } @@ -134,7 +131,7 @@ namespace LawFirmFileImplement.Implements } } - if (count < 1) + if (count <= 0) { shop.Update(new ShopBindingModel { @@ -145,9 +142,10 @@ namespace LawFirmFileImplement.Implements MaxCountDocuments = shop.MaxCountDocuments, ShopDocuments= documents }); - break; + return true; } } + shop.Update(new ShopBindingModel { Id = shop.Id, -- 2.25.1 From 94dde9c5d91bf49d9fd2362198484c00e016c278 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Wed, 1 Mar 2023 18:13:57 +0400 Subject: [PATCH 16/32] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D1=88=D0=BE=D0=B9=20=D0=B4=D0=B5=D0=B1=D0=B0=D0=B3=20=D1=81?= =?UTF-8?q?=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormShop.cs | 1 + LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/LawFirm/LawFirm/FormShop.cs b/LawFirm/LawFirm/FormShop.cs index 7083dd2..fdf3e0d 100644 --- a/LawFirm/LawFirm/FormShop.cs +++ b/LawFirm/LawFirm/FormShop.cs @@ -50,6 +50,7 @@ namespace LawFirmView textBoxName.Text = view.Name; textBoxAddress.Text = view.Adress; _shopDocuments = view.ShopDocuments ?? new Dictionary(); + textBoxMaxCountDocs.Text = view.MaxCountDocuments.ToString(); LoadData(); } } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index 19c676b..4affe1c 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -105,7 +105,8 @@ namespace LawFirmBusinessLogic.BusinessLogics Name = shopElement.Name, Adress = shopElement.Adress, OpeningDate = shopElement.OpeningDate, - ShopDocuments = shopElement.ShopDocuments + ShopDocuments = shopElement.ShopDocuments, + MaxCountDocuments = shopElement.MaxCountDocuments }); } else -- 2.25.1 From 6a68de1873eac1a354b8aac728d2d926b126b35a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Wed, 1 Mar 2023 19:04:30 +0400 Subject: [PATCH 17/32] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?,=20=D0=BD=D0=BE=20=D0=B1=D1=8B=D0=BB=D0=BE=20=D0=B1=D1=8B=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=BF=D0=BB=D0=BE=D1=85=D0=BE=20=D0=BF=D0=BE=D1=80?= =?UTF-8?q?=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormMain.Designer.cs | 19 ++- LawFirm/LawFirm/FormMain.cs | 9 ++ LawFirm/LawFirm/FormShopSell.Designer.cs | 119 ++++++++++++++++++ LawFirm/LawFirm/FormShopSell.cs | 97 ++++++++++++++ LawFirm/LawFirm/FormShopSell.resx | 60 +++++++++ LawFirm/LawFirm/Program.cs | 1 + .../BusinessLogics/ShopLogic.cs | 5 + .../BusinessLogicContracts/IShopLogic.cs | 2 + .../StorageContracts/IShopStorage.cs | 1 + .../Implements/ShopStorage.cs | 8 +- .../Implements/ShopStorage.cs | 4 + 11 files changed, 318 insertions(+), 7 deletions(-) create mode 100644 LawFirm/LawFirm/FormShopSell.Designer.cs create mode 100644 LawFirm/LawFirm/FormShopSell.cs create mode 100644 LawFirm/LawFirm/FormShopSell.resx diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index f3d664b..9f9a50c 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); + this.buttonSellDocuments = new System.Windows.Forms.Button(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -68,21 +69,21 @@ // бланкиToolStripMenuItem // this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; - this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(170, 26); this.бланкиToolStripMenuItem.Text = "Бланки"; this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.бланкиToolStripMenuItem_Click); // // документыToolStripMenuItem // this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - this.документыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.документыToolStripMenuItem.Size = new System.Drawing.Size(170, 26); this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click); // // магазиныToolStripMenuItem // this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(170, 26); this.магазиныToolStripMenuItem.Text = "Магазины"; this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); // @@ -156,11 +157,22 @@ this.buttonSupplyShop.UseVisualStyleBackColor = true; this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click); // + // buttonSellDocuments + // + this.buttonSellDocuments.Location = new System.Drawing.Point(933, 220); + this.buttonSellDocuments.Name = "buttonSellDocuments"; + this.buttonSellDocuments.Size = new System.Drawing.Size(194, 29); + this.buttonSellDocuments.TabIndex = 8; + this.buttonSellDocuments.Text = "Продажа документов"; + this.buttonSellDocuments.UseVisualStyleBackColor = true; + this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1139, 450); + this.Controls.Add(this.buttonSellDocuments); this.Controls.Add(this.buttonSupplyShop); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); @@ -195,5 +207,6 @@ private Button buttonUpdate; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonSupplyShop; + private Button buttonSellDocuments; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 46d6790..db140dc 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -181,5 +181,14 @@ namespace LawFirmView form.ShowDialog(); } } + + private void buttonSellDocuments_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSell)); + if (service is FormShopSell form) + { + form.ShowDialog(); + } + } } } diff --git a/LawFirm/LawFirm/FormShopSell.Designer.cs b/LawFirm/LawFirm/FormShopSell.Designer.cs new file mode 100644 index 0000000..074f8c2 --- /dev/null +++ b/LawFirm/LawFirm/FormShopSell.Designer.cs @@ -0,0 +1,119 @@ +namespace LawFirmView +{ + partial class FormShopSell + { + /// + /// 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.labelCount = new System.Windows.Forms.Label(); + this.labelDocument = new System.Windows.Forms.Label(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(23, 76); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelDocument + // + this.labelDocument.AutoSize = true; + this.labelDocument.Location = new System.Drawing.Point(23, 24); + this.labelDocument.Name = "labelDocument"; + this.labelDocument.Size = new System.Drawing.Size(79, 20); + this.labelDocument.TabIndex = 2; + this.labelDocument.Text = "Документ:"; + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(124, 24); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(278, 28); + this.comboBoxDocument.TabIndex = 4; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(124, 73); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(158, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(188, 142); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(94, 29); + this.buttonSell.TabIndex = 6; + this.buttonSell.Text = "Продажа"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(308, 142); + 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); + // + // FormShopSell + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(459, 198); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDocument); + this.Controls.Add(this.labelDocument); + this.Controls.Add(this.labelCount); + this.Name = "FormShopSell"; + this.Text = "Продажа из магазина"; + this.Load += new System.EventHandler(this.FormShopSell_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Label labelCount; + private Label labelDocument; + private ComboBox comboBoxDocument; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormShopSell.cs b/LawFirm/LawFirm/FormShopSell.cs new file mode 100644 index 0000000..5255aa2 --- /dev/null +++ b/LawFirm/LawFirm/FormShopSell.cs @@ -0,0 +1,97 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormShopSell : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicD; + private readonly IShopLogic _logicS; + + public FormShopSell(ILogger logger, IDocumentLogic logicD, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicS = logicS; + } + + private void FormShopSell_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка документов для продажи"); + try + { + var list = _logicD.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSell_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание продажи"); + try + { + var operationResult = _logicS.SellDocument( + new DocumentSearchModel + { + Id = Convert.ToInt32(comboBoxDocument.SelectedValue), + DocumentName = comboBoxDocument.Text + }, + 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/LawFirm/LawFirm/FormShopSell.resx b/LawFirm/LawFirm/FormShopSell.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormShopSell.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 60500aa..5acabed 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -56,6 +56,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index 4affe1c..b3250a1 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -117,6 +117,11 @@ namespace LawFirmBusinessLogic.BusinessLogics return true; } + public bool SellDocument(DocumentSearchModel document, int count) + {; + return _shopStorage.SellDocument(document, count); + } + public bool Create(ShopBindingModel model) { CheckModel(model); diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs index 0b47a27..ab76086 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs @@ -18,5 +18,7 @@ namespace LawFirmContracts.BusinessLogicContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); + + bool SellDocument(DocumentSearchModel document, int count); } } diff --git a/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs index f84055a..b51b90c 100644 --- a/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs +++ b/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs @@ -17,5 +17,6 @@ namespace LawFirmContracts.StorageContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellDocument(DocumentSearchModel model, int count); } } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 7a48f54..bfa4a5d 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -118,11 +118,11 @@ namespace LawFirmFileImplement.Implements var shop = source.Shops[i]; var documents = shop.ShopDocuments; - for (int j = 0; j < documents.Count; j++) + for (int j =1; j < documents.Count + 1; j++) { if (documents[j].Item1.Id == document.Id) { - while (documents[j].Item2 > 0 || count > 0) + while (documents[j].Item2 > 0 && count > 0) { int tempItem2 = documents[j].Item2; tempItem2--; @@ -140,12 +140,12 @@ namespace LawFirmFileImplement.Implements Adress = shop.Adress, OpeningDate = shop.OpeningDate, MaxCountDocuments = shop.MaxCountDocuments, - ShopDocuments= documents + ShopDocuments = documents }); return true; } } - + shop.Update(new ShopBindingModel { Id = shop.Id, diff --git a/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs index 11f9ac9..15f5c4e 100644 --- a/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs @@ -116,5 +116,9 @@ namespace LawFirmListImplements.Implements return null; } + public bool SellDocument(DocumentSearchModel model, int count) + { + throw new NotImplementedException(); + } } } -- 2.25.1 From 0f604b38fe20067a64cdc6e7a1159cd7db4c54f3 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Wed, 1 Mar 2023 19:09:58 +0400 Subject: [PATCH 18/32] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=D0=B6=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index bfa4a5d..4e76ac6 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -142,7 +142,9 @@ namespace LawFirmFileImplement.Implements MaxCountDocuments = shop.MaxCountDocuments, ShopDocuments = documents }); + source.SaveShops(); return true; + } } @@ -155,6 +157,7 @@ namespace LawFirmFileImplement.Implements MaxCountDocuments = shop.MaxCountDocuments, ShopDocuments = documents }); + source.SaveShops(); } if (count > 0) -- 2.25.1 From bb74221578f917d9ed37b97071012ee3c4bd1393 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Thu, 2 Mar 2023 22:09:15 +0400 Subject: [PATCH 19/32] =?UTF-8?q?=D0=92=D0=BE=D1=82=20=D1=82=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= =?UTF-8?q?=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=20(=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E=D1=81=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/FormShopSell.cs | 5 +- .../BusinessLogics/OrderLogic.cs | 23 ++++++- .../BusinessLogics/ShopLogic.cs | 62 ++++++++++++++++++- .../BusinessLogicContracts/IShopLogic.cs | 4 +- .../StorageContracts/IShopStorage.cs | 3 +- .../Implements/ShopStorage.cs | 5 +- .../Implements/ShopStorage.cs | 3 +- 7 files changed, 94 insertions(+), 11 deletions(-) diff --git a/LawFirm/LawFirm/FormShopSell.cs b/LawFirm/LawFirm/FormShopSell.cs index 5255aa2..b7e9b89 100644 --- a/LawFirm/LawFirm/FormShopSell.cs +++ b/LawFirm/LawFirm/FormShopSell.cs @@ -66,10 +66,9 @@ namespace LawFirmView try { var operationResult = _logicS.SellDocument( - new DocumentSearchModel + new DocumentBindingModel { - Id = Convert.ToInt32(comboBoxDocument.SelectedValue), - DocumentName = comboBoxDocument.Text + Id = Convert.ToInt32(comboBoxDocument.SelectedValue) }, Convert.ToInt32(textBoxCount.Text) ); diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs index 75cacbd..bc5dd2b 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,11 +17,16 @@ namespace LawFirmBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopLogic _shopLogic; + private readonly IDocumentStorage _documentStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _documentStorage = documentStorage; } public bool CreateOrder(OrderBindingModel model) @@ -73,6 +78,22 @@ namespace LawFirmBusinessLogic.BusinessLogics _logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect."); return false; } + + if (newStatus == OrderStatus.Готов) + { + var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId}); + if (document == null) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found."); + return false; + } + if (_shopLogic.CheckThenSupplyMany(document, model.Count) == false) + { + _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error."); + return false; + } + } + model.Status = newStatus; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (_orderStorage.Update(model) == null) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index b3250a1..2e26e7d 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -116,8 +116,68 @@ namespace LawFirmBusinessLogic.BusinessLogics } return true; } + public bool CheckThenSupplyMany(IDocumentModel document, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check then supply operation error. Document count < 0."); + return false; + } - public bool SellDocument(DocumentSearchModel document, int count) + int freeSpace = 0; + foreach(var shop in _shopStorage.GetFullList()) + { + freeSpace += shop.MaxCountDocuments; + foreach (var doc in shop.ShopDocuments) + { + freeSpace -= doc.Value.Item2; + } + } + + if (freeSpace - count < 0) + { + _logger.LogWarning("Check then supply operation error. There's no place for new docs in shops."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace = shop.MaxCountDocuments; + foreach (var doc in shop.ShopDocuments) + { + freeSpace -= doc.Value.Item2; + } + if (freeSpace == 0) + { + continue; + } + if (freeSpace - count >= 0) + { + if (SupplyDocuments(new() { Id = shop.Id}, document, count)) count = 0; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (freeSpace - count < 0) + { + if (SupplyDocuments(new() { Id = shop.Id }, document, freeSpace)) count-= freeSpace; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } + + public bool SellDocument(IDocumentModel document, int count) {; return _shopStorage.SellDocument(document, count); } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs index ab76086..48c5760 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs @@ -18,7 +18,7 @@ namespace LawFirmContracts.BusinessLogicContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); - - bool SellDocument(DocumentSearchModel document, int count); + bool SellDocument(IDocumentModel document, int count); + bool CheckThenSupplyMany(IDocumentModel document, int count); } } diff --git a/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs index b51b90c..6063bd2 100644 --- a/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs +++ b/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using LawFirmContracts.BindingModels; using LawFirmContracts.SearchModels; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,6 +18,6 @@ namespace LawFirmContracts.StorageContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool SellDocument(DocumentSearchModel model, int count); + bool SellDocument(IDocumentModel model, int count); } } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 4e76ac6..81c5de4 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StorageContracts; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using LawFirmFileImplement.Models; using System; using System.Collections.Generic; @@ -80,9 +81,9 @@ namespace LawFirmFileImplement.Implements return shop.GetViewModel; } - public bool SellDocument(DocumentSearchModel model, int count) + public bool SellDocument(IDocumentModel model, int count) { - var document = source.Documents.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id); + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); var countStore = count; diff --git a/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs index 15f5c4e..d8d0555 100644 --- a/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StorageContracts; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using LawFirmListImplements.Models; using System; using System.Collections.Generic; @@ -116,7 +117,7 @@ namespace LawFirmListImplements.Implements return null; } - public bool SellDocument(DocumentSearchModel model, int count) + public bool SellDocument(IDocumentModel model, int count) { throw new NotImplementedException(); } -- 2.25.1 From 9c80b7fd37afd078a0959d1c17b63b9fc458247f Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 15:30:32 +0400 Subject: [PATCH 20/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm.sln | 8 +- .../LawFirmFileImplement.csproj | 14 +++ LawFirm/LawFirmFileImplement/Models/Blank.cs | 74 ++++++++++++ .../LawFirmFileImplement/Models/Document.cs | 105 +++++++++++++++++ LawFirm/LawFirmFileImplement/Models/Order.cs | 110 ++++++++++++++++++ 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj create mode 100644 LawFirm/LawFirmFileImplement/Models/Blank.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Document.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Order.cs diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 93a0ebb..362180a 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.Build.0 = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj new file mode 100644 index 0000000..7c491f4 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Blank.cs b/LawFirm/LawFirmFileImplement/Models/Blank.cs new file mode 100644 index 0000000..2e7bbfd --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Blank.cs @@ -0,0 +1,74 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.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 LawFirmFileImplement.Models +{ + public class Blank : IBlankModel + { + public string BlankName { get; private set; } = String.Empty; + + public double Cost { get; set; } + + public int Id { get; private set; } + + public static Blank? Create(BlankBindingModel? model) + { + if (model == null) + { + return null; + } + return new Blank() + { + Id = model.Id, + BlankName = model.BlankName, + Cost = model.Cost + }; + } + + public static Blank? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Blank() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + BlankName = element.Element("BlankName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(BlankBindingModel? model) + { + if (model == null) + { + return; + } + BlankName = model.BlankName; + Cost = model.Cost; + } + public BlankViewModel GetViewModel => new() + { + Id = Id, + BlankName = BlankName, + Cost = Cost + }; + + public XElement GetXElement => new( + "Blank", + new XAttribute("Id", Id), + new XElement("BlankName", BlankName), + new XElement("Cost", Cost.ToString()) + ); + + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs new file mode 100644 index 0000000..6484a59 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -0,0 +1,105 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Document : IDocumentModel + { + public string DocumentName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public int Id { get; private set; } + + public Dictionary Blanks { get; private set; } = new(); + + private Dictionary? _documentBlanks = null; + public Dictionary DocumentBlanks + { + get + { + if (_documentBlanks == null) + { + var source = DataFileSingleton.GetInstance(); + _documentBlanks = Blanks.ToDictionary( + x => x.Key, + y => ((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!, y.Value) + ); + } + return _documentBlanks; + } + } + + + public static Document? Create(DocumentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Document? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Document() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Blanks = element.Element("DocumentBlanks")!.Elements("DocumentBlank").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value) + ) + }; + } + + + public void Update(DocumentBindingModel? model) + { + if (model == null) + { + return; + } + DocumentName = model.DocumentName; + Price = model.Price; + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2); + _documentBlanks = null; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentBlanks = DocumentBlanks + }; + + public XElement GetXElement => new( + "Document", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("DocumentBlanks", Blanks.Select(x => + new XElement("DocumentBlank", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs new file mode 100644 index 0000000..28a6a3a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -0,0 +1,110 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Order : IOrderModel + { + public int DocumentId { get; private set; } + + public string DocumentName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order + { + DocumentId = model.DocumentId, + DocumentName = model.DocumentName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.Value, + DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value) + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + DocumentId = model.DocumentId; + DocumentName = model.DocumentName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + + public OrderViewModel GetViewModel => new() + { + DocumentId = DocumentId, + DocumentName = DocumentName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + + public XElement GetXElement => new( + "Order", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("DocumentId", DocumentId.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 e390ece7b691edd38f7d4ffc41915de3eefdd1ea Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 16:28:53 +0400 Subject: [PATCH 21/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D1=81=D0=B8=D0=BD=D0=B3=D0=BB=D1=82=D0=BE=D0=BD=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawFirmFileImplement/DataFileSingleton.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/DataFileSingleton.cs diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..baa110a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -0,0 +1,55 @@ +using LawFirmFileImplement.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 LawFirmFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string BlankFileName = "Blank.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string DocumentFileName = "Document.xml"; + public List Blanks { get; private set; } + public List Orders { get; private set; } + public List Documents { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement); + public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; + Documents = LoadData(DocumentFileName, "Document", x => Document.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 75a544e690e59722bbcff0e14fecf559208bdcb0 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:28:24 +0400 Subject: [PATCH 22/32] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BlankStorage.cs | 88 +++++++++++++++++++ .../Implements/DocumentStorage.cs | 87 ++++++++++++++++++ .../Implements/OrderStorage.cs | 87 ++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs new file mode 100644 index 0000000..47b885b --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -0,0 +1,88 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class BlankStorage : IBlankStorage + { + private readonly DataFileSingleton source; + + public BlankStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public BlankViewModel? GetElement(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue) + { + return null; + } + return source.Blanks + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName)) + { + return new(); + } + return source.Blanks + .Where(x => x.BlankName.Contains(model.BlankName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Blanks.Select(x => x.GetViewModel).ToList(); + } + + public BlankViewModel? Insert(BlankBindingModel model) + { + model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1; + var newBlank = Blank.Create(model); + if (newBlank == null) + { + return null; + } + source.Blanks.Add(newBlank); + source.SaveBlanks(); + return newBlank.GetViewModel; + } + + public BlankViewModel? Update(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + public BlankViewModel? Delete(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..8de8fd2 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class DocumentStorage : IDocumentStorage + { + private readonly DataFileSingleton source; + + public DocumentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue) + { + return null; + } + return source.Documents + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + return source.Documents + .Where(x => x.DocumentName.Contains(model.DocumentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Documents.Select(x => x.GetViewModel).ToList(); + } + + public DocumentViewModel? Insert(DocumentBindingModel model) + { + model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1; + var newDoc = Document.Create(model); + if (newDoc == null) + { + return null; + } + source.Documents.Add(newDoc); + source.SaveDocuments(); + return newDoc.GetViewModel; + } + + public DocumentViewModel? Update(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..7b35304 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + + } +} -- 2.25.1 From daf95e27b6bce80312797a7e8925326b50201a61 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:41:53 +0400 Subject: [PATCH 23/32] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/LawFirmView.csproj | 1 + LawFirm/LawFirm/Program.cs | 4 +++- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 45754fd..7f7c8cf 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -17,6 +17,7 @@ + diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index b634a21..09dd87f 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -1,7 +1,7 @@ using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.StorageContracts; -using LawFirmListImplements.Implements; +using LawFirmFileImplement.Implements; using LawFirmView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -41,9 +41,11 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 8de8fd2..7629dfa 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class DocumentStorage : IDocumentStorage + public class DocumentStorage : IDocumentStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 7b35304..baee8c5 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class OrderStorage : IOrderStorage + public class OrderStorage : IOrderStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj index 7c491f4..77fe5b1 100644 --- a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 -- 2.25.1 From 862baf93b68b90a828dc40f5d01abd3675407e26 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 13 Feb 2023 09:29:17 +0400 Subject: [PATCH 24/32] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=202=20=D0=B1=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Models/Order.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 28a6a3a..7672d1a 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -63,7 +63,7 @@ namespace LawFirmFileImplement.Models Count = Convert.ToInt32(element.Element("Count")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = Convert.ToDateTime(element.Element("DateCreate")!.Value) + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) }; } -- 2.25.1 From b2c61a619a9f9706b4bebb43ff26f982eb812aa2 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Feb 2023 23:22:27 +0400 Subject: [PATCH 25/32] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs index 47b885b..bb10978 100644 --- a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -79,7 +79,7 @@ namespace LawFirmFileImplement.Implements { return null; } - blank.Update(model); + source.Blanks.Remove(blank); source.SaveBlanks(); return blank.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 7629dfa..dd74260 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - document.Update(model); + source.Documents.Remove(document); source.SaveDocuments(); return document.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index baee8c5..46a8d01 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - order.Update(model); + source.Orders.Remove(order); source.SaveOrders(); return order.GetViewModel; } -- 2.25.1 From 8507a11132518a7e9b441da1b689bf95c37b793f Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 10 Mar 2023 19:37:13 +0400 Subject: [PATCH 26/32] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 28 ++++++++++++++----- LawFirm/LawFirmFileImplement/Models/Order.cs | 12 -------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 46a8d01..3220716 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -26,8 +26,8 @@ namespace LawFirmFileImplement.Implements { return null; } - return source.Orders - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return GetViewModel(source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } public List GetFilteredList(OrderSearchModel model) @@ -38,13 +38,13 @@ namespace LawFirmFileImplement.Implements } return source.Orders .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) + .Select(x => GetViewModel(x)) .ToList(); } public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -57,7 +57,7 @@ namespace LawFirmFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -69,7 +69,7 @@ namespace LawFirmFileImplement.Implements } order.Update(model); source.SaveOrders(); - return order.GetViewModel; + return GetViewModel(order); } public OrderViewModel? Delete(OrderBindingModel model) { @@ -80,7 +80,21 @@ namespace LawFirmFileImplement.Implements } source.Orders.Remove(order); source.SaveOrders(); - return order.GetViewModel; + return GetViewModel(order); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var document in source.Documents) + { + if (document.Id == order.DocumentId) + { + viewModel.DocumentName = document.DocumentName; + break; + } + } + return viewModel; } } diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 7672d1a..31bb7e8 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -15,8 +15,6 @@ namespace LawFirmFileImplement.Models { public int DocumentId { get; private set; } - public string DocumentName { get; private set; } = string.Empty; - public int Count { get; private set; } public double Sum { get; private set; } @@ -38,7 +36,6 @@ namespace LawFirmFileImplement.Models return new Order { DocumentId = model.DocumentId, - DocumentName = model.DocumentName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,7 +54,6 @@ namespace LawFirmFileImplement.Models return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - DocumentName = element.Element("DocumentName")!.Value, DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), @@ -73,20 +69,13 @@ namespace LawFirmFileImplement.Models { return; } - DocumentId = model.DocumentId; - DocumentName = model.DocumentName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; - Id = model.Id; } public OrderViewModel GetViewModel => new() { DocumentId = DocumentId, - DocumentName = DocumentName, Count = Count, Sum = Sum, DateCreate = DateCreate, @@ -98,7 +87,6 @@ namespace LawFirmFileImplement.Models public XElement GetXElement => new( "Order", new XAttribute("Id", Id), - new XElement("DocumentName", DocumentName), new XElement("DocumentId", DocumentId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), -- 2.25.1 From 80460ececdc9710005253f58c9b5c832cd8dfa3e Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 10 Mar 2023 21:06:09 +0400 Subject: [PATCH 27/32] =?UTF-8?q?=D0=A2=D1=80=D0=B5=D0=B1=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20LINQ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 3220716..93cbffe 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -86,13 +86,10 @@ namespace LawFirmFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - foreach (var document in source.Documents) + var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId); + if (document != null) { - if (document.Id == order.DocumentId) - { - viewModel.DocumentName = document.DocumentName; - break; - } + viewModel.DocumentName = document.DocumentName; } return viewModel; } -- 2.25.1 From 2036d05b3ad591f3bc88e78d5c0ac06c1024df10 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 12 Mar 2023 14:58:17 +0400 Subject: [PATCH 28/32] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Models/Shop.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Models/Shop.cs b/LawFirm/LawFirmFileImplement/Models/Shop.cs index 2abbcf9..46162f0 100644 --- a/LawFirm/LawFirmFileImplement/Models/Shop.cs +++ b/LawFirm/LawFirmFileImplement/Models/Shop.cs @@ -91,8 +91,11 @@ namespace LawFirmFileImplement.Models Adress = model.Adress; OpeningDate = model.OpeningDate; MaxCountDocuments = model.MaxCountDocuments; - Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2); - _shopDocuments = null; + if (model.ShopDocuments.Count > 0) + { + Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopDocuments = null; + } } public ShopViewModel GetViewModel => new() { -- 2.25.1 From 51738e8616aefb74edd2f2bd74453c461fa4a9ac Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 12 Mar 2023 19:00:22 +0400 Subject: [PATCH 29/32] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B4=D0=B0=D0=B6=D0=B8=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=BC=D0=B0=D0=B3=D0=B0=D0=B7=D0=B8=D0=BD=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 81c5de4..1aea266 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -119,33 +119,15 @@ namespace LawFirmFileImplement.Implements var shop = source.Shops[i]; var documents = shop.ShopDocuments; - for (int j =1; j < documents.Count + 1; j++) + foreach (var doc in documents.Where(x => x.Value.Item1.Id == document.Id)) { - if (documents[j].Item1.Id == document.Id) - { - while (documents[j].Item2 > 0 && count > 0) - { - int tempItem2 = documents[j].Item2; - tempItem2--; - count--; - documents[j] = (documents[j].Item1, tempItem2); - } - } - + var min = Math.Min(doc.Value.Item2, count); + documents[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min); + count -= min; + if (count <= 0) { - shop.Update(new ShopBindingModel - { - Id = shop.Id, - Name = shop.Name, - Adress = shop.Adress, - OpeningDate = shop.OpeningDate, - MaxCountDocuments = shop.MaxCountDocuments, - ShopDocuments = documents - }); - source.SaveShops(); - return true; - + break; } } -- 2.25.1 From 00c2a39c41f9ca356d80d5fa05420e7ed722ca1b Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 13 Mar 2023 10:14:57 +0400 Subject: [PATCH 30/32] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=B0=202=20?= =?UTF-8?q?=D1=85=D0=B0=D1=80=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 68 ++++++++++++++++++- .../BusinessLogics/ShopLogic.cs | 60 ---------------- .../BusinessLogicContracts/IShopLogic.cs | 1 - .../Implements/ShopStorage.cs | 2 + 4 files changed, 68 insertions(+), 63 deletions(-) diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs index f6e83eb..e806a16 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs @@ -4,6 +4,7 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StorageContracts; using LawFirmContracts.ViewModels; using LawFirmDataModels.Enums; +using LawFirmDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -17,16 +18,18 @@ namespace LawFirmBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly IShopLogic _shopLogic; private readonly IDocumentStorage _documentStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; _shopLogic = shopLogic; _documentStorage = documentStorage; + _shopStorage = shopStorage; } public bool CreateOrder(OrderBindingModel model) @@ -86,7 +89,7 @@ namespace LawFirmBusinessLogic.BusinessLogics _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found."); return false; } - if (_shopLogic.CheckThenSupplyMany(document, model.Count) == false) + if (CheckThenSupplyMany(document, model.Count) == false) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error."); return false; @@ -104,6 +107,67 @@ namespace LawFirmBusinessLogic.BusinessLogics return true; } + public bool CheckThenSupplyMany(IDocumentModel document, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check then supply operation error. Document count < 0."); + return false; + } + + int freeSpace = 0; + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace += shop.MaxCountDocuments; + foreach (var doc in shop.ShopDocuments) + { + freeSpace -= doc.Value.Item2; + } + } + + if (freeSpace - count < 0) + { + _logger.LogWarning("Check then supply operation error. There's no place for new docs in shops."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace = shop.MaxCountDocuments; + foreach (var doc in shop.ShopDocuments) + { + freeSpace -= doc.Value.Item2; + } + if (freeSpace == 0) + { + continue; + } + if (freeSpace - count >= 0) + { + if (_shopLogic.SupplyDocuments(new() { Id = shop.Id }, document, count)) count = 0; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (freeSpace - count < 0) + { + if (_shopLogic.SupplyDocuments(new() { Id = shop.Id }, document, freeSpace)) count -= freeSpace; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } + public bool TakeOrderInWork(OrderBindingModel model) { return StatusUpdate(model, OrderStatus.Выполняется); diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index 2e26e7d..e2092d3 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -116,66 +116,6 @@ namespace LawFirmBusinessLogic.BusinessLogics } return true; } - public bool CheckThenSupplyMany(IDocumentModel document, int count) - { - if (count <= 0) - { - _logger.LogWarning("Check then supply operation error. Document count < 0."); - return false; - } - - int freeSpace = 0; - foreach(var shop in _shopStorage.GetFullList()) - { - freeSpace += shop.MaxCountDocuments; - foreach (var doc in shop.ShopDocuments) - { - freeSpace -= doc.Value.Item2; - } - } - - if (freeSpace - count < 0) - { - _logger.LogWarning("Check then supply operation error. There's no place for new docs in shops."); - return false; - } - - foreach (var shop in _shopStorage.GetFullList()) - { - freeSpace = shop.MaxCountDocuments; - foreach (var doc in shop.ShopDocuments) - { - freeSpace -= doc.Value.Item2; - } - if (freeSpace == 0) - { - continue; - } - if (freeSpace - count >= 0) - { - if (SupplyDocuments(new() { Id = shop.Id}, document, count)) count = 0; - else - { - _logger.LogWarning("Supply error"); - return false; - } - } - if (freeSpace - count < 0) - { - if (SupplyDocuments(new() { Id = shop.Id }, document, freeSpace)) count-= freeSpace; - else - { - _logger.LogWarning("Supply error"); - return false; - } - } - if (count <= 0) - { - return true; - } - } - return false; - } public bool SellDocument(IDocumentModel document, int count) {; diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs index 48c5760..725111d 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs @@ -19,6 +19,5 @@ namespace LawFirmContracts.BusinessLogicContracts bool Delete(ShopBindingModel model); bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); bool SellDocument(IDocumentModel document, int count); - bool CheckThenSupplyMany(IDocumentModel document, int count); } } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 1aea266..fb006e0 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -83,6 +83,8 @@ namespace LawFirmFileImplement.Implements public bool SellDocument(IDocumentModel model, int count) { + // переделать под linq + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); var countStore = count; -- 2.25.1 From 0b3b9b391a014c616e73fba93ecc64c9c65d5fcc Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 7 Apr 2023 16:04:49 +0400 Subject: [PATCH 31/32] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=20=D0=BF=D0=BE=D0=B4=20LINQ=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=20SellDocument?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 66 ++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index fb006e0..a4128a2 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -81,7 +81,7 @@ namespace LawFirmFileImplement.Implements return shop.GetViewModel; } - public bool SellDocument(IDocumentModel model, int count) +/* public bool SellDocument(IDocumentModel model, int count) { // переделать под linq @@ -151,5 +151,69 @@ namespace LawFirmFileImplement.Implements } return true; } +*/ + public bool SellDocument(IDocumentModel model, int count) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + + if (document == null) + { + return false; + } + + var countStore = count; + + var shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(doc => doc.Value.Item1.Id == document.Id)); + + foreach (var doc in shopDocuments) + { + count -= doc.Value.Item2; + + if (count <= 0) + { + break; + } + } + + if (count > 0) + { + return false; + } + + count = countStore; + + foreach (var shop in source.Shops) + { + var documents = shop.ShopDocuments; + + foreach (var doc in documents.Where(x => x.Value.Item1.Id == document.Id)) + { + var min = Math.Min(doc.Value.Item2, count); + documents[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min); + count -= min; + + if (count <= 0) + { + break; + } + } + + shop.Update(new ShopBindingModel + { + Id = shop.Id, + Name = shop.Name, + Adress = shop.Adress, + OpeningDate = shop.OpeningDate, + MaxCountDocuments = shop.MaxCountDocuments, + ShopDocuments = documents + }); + + source.SaveShops(); + + if (count <= 0) break; + } + + return count <= 0; + } } } -- 2.25.1 From 71f60ebf7a36756de4656dfbe73503058eace038 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 7 Apr 2023 16:05:54 +0400 Subject: [PATCH 32/32] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 71 ------------------- 1 file changed, 71 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index a4128a2..09a4599 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -81,77 +81,6 @@ namespace LawFirmFileImplement.Implements return shop.GetViewModel; } -/* public bool SellDocument(IDocumentModel model, int count) - { - // переделать под linq - - var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); - - var countStore = count; - - if (document == null) - { - return false; - } - - foreach (var shop in source.Shops) - { - foreach (var doc in shop.ShopDocuments) - { - if (doc.Value.Item1.Id == document.Id) - { - count -= doc.Value.Item2; - } - if (count <= 0) - { - break; - } - } - } - - if (count > 0) - { - return false; - } - - count = countStore; - - for (int i = 0; i < source.Shops.Count; i++) - { - var shop = source.Shops[i]; - var documents = shop.ShopDocuments; - - foreach (var doc in documents.Where(x => x.Value.Item1.Id == document.Id)) - { - var min = Math.Min(doc.Value.Item2, count); - documents[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min); - count -= min; - - if (count <= 0) - { - break; - } - } - - shop.Update(new ShopBindingModel - { - Id = shop.Id, - Name = shop.Name, - Adress = shop.Adress, - OpeningDate = shop.OpeningDate, - MaxCountDocuments = shop.MaxCountDocuments, - ShopDocuments = documents - }); - source.SaveShops(); - } - - if (count > 0) - { - return false; - } - return true; - } -*/ public bool SellDocument(IDocumentModel model, int count) { var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); -- 2.25.1