From cd38b2626b7095326bb5dc9809eee504b4ce1fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Wed, 28 Feb 2024 11:10:20 +0400 Subject: [PATCH] lab2 --- JewelryStore/JewelryStore/JewelryStore.sln | 18 ++-- .../DataFileSingleton.cs | 61 ++++++++++++ .../Implements/ComponentStorage.cs | 90 ++++++++++++++++++ .../Implements/JewelStorage.cs | 85 +++++++++++++++++ .../Implements/OrderStorage.cs | 84 +++++++++++++++++ .../JewerlyStoreFileImplement.csproj | 14 +++ .../Models/Component.cs | 69 ++++++++++++++ .../JewerlyStoreFileImplement/Models/Jewel.cs | 93 +++++++++++++++++++ .../JewerlyStoreFileImplement/Models/Order.cs | 91 ++++++++++++++++++ .../FormComponents.Designer.cs | 1 + .../JewerlyStoreView/FormJewels.Designer.cs | 1 + .../JewerlyStoreView/JewerlyStoreView.csproj | 1 + JewelryStore/JewerlyStoreView/Program.cs | 2 +- 13 files changed, 603 insertions(+), 7 deletions(-) create mode 100644 JewelryStore/JewerlyStoreFileImplement/DataFileSingleton.cs create mode 100644 JewelryStore/JewerlyStoreFileImplement/Implements/ComponentStorage.cs create mode 100644 JewelryStore/JewerlyStoreFileImplement/Implements/JewelStorage.cs create mode 100644 JewelryStore/JewerlyStoreFileImplement/Implements/OrderStorage.cs create mode 100644 JewelryStore/JewerlyStoreFileImplement/JewerlyStoreFileImplement.csproj create mode 100644 JewelryStore/JewerlyStoreFileImplement/Models/Component.cs create mode 100644 JewelryStore/JewerlyStoreFileImplement/Models/Jewel.cs create mode 100644 JewelryStore/JewerlyStoreFileImplement/Models/Order.cs diff --git a/JewelryStore/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore/JewelryStore.sln index 9d3921e..596352c 100644 --- a/JewelryStore/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore/JewelryStore.sln @@ -3,17 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34202.233 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStore", "JewelryStore.csproj", "{AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{AE4DC4C1-2347-4521-BE6F-C5B80BB7F0F0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{7A3E84A4-6C9D-4C8D-BCCB-58F7BAEE52B9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{F3E87835-779D-4974-96D4-51A6723C37D3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{F3E87835-779D-4974-96D4-51A6723C37D3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{76C0344A-4C9E-42D1-84DB-6D39D595B57D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{76C0344A-4C9E-42D1-84DB-6D39D595B57D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewerlyStoreDataModels", "..\JewerlyStoreDataModels\JewerlyStoreDataModels.csproj", "{4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewerlyStoreDataModels", "..\JewerlyStoreDataModels\JewerlyStoreDataModels.csproj", "{4AD0B4DC-8F85-401B-8938-B49E4A3ACCF7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewerlyStoreView", "..\JewerlyStoreView\JewerlyStoreView.csproj", "{F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewerlyStoreView", "..\JewerlyStoreView\JewerlyStoreView.csproj", "{F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewerlyStoreFileImplement", "..\JewerlyStoreFileImplement\JewerlyStoreFileImplement.csproj", "{CBCAFAE3-4CF6-43BB-A053-97FA6FD7A90B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +47,10 @@ Global {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Debug|Any CPU.Build.0 = Debug|Any CPU {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Release|Any CPU.ActiveCfg = Release|Any CPU {F61608F4-B4AA-47D7-A6A0-74F9FFCF9A5B}.Release|Any CPU.Build.0 = Release|Any CPU + {CBCAFAE3-4CF6-43BB-A053-97FA6FD7A90B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CBCAFAE3-4CF6-43BB-A053-97FA6FD7A90B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CBCAFAE3-4CF6-43BB-A053-97FA6FD7A90B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CBCAFAE3-4CF6-43BB-A053-97FA6FD7A90B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JewelryStore/JewerlyStoreFileImplement/DataFileSingleton.cs b/JewelryStore/JewerlyStoreFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..9aa8563 --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/DataFileSingleton.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewerlyStoreFileImplement.Models; +using System.Xml.Linq; + + +namespace JewerlyStoreFileImplement +{ + internal class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string JewelFileName = "Jewel.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Jewels { get; private set; } + + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + + public void SaveJewels() => SaveData(Jewels, JewelFileName, "Jewels", x => x.GetXElement); + + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/JewelryStore/JewerlyStoreFileImplement/Implements/ComponentStorage.cs b/JewelryStore/JewerlyStoreFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..7dc1b54 --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,90 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewerlyStoreFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Components + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/JewelryStore/JewerlyStoreFileImplement/Implements/JewelStorage.cs b/JewelryStore/JewerlyStoreFileImplement/Implements/JewelStorage.cs new file mode 100644 index 0000000..c9a8f06 --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/Implements/JewelStorage.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewerlyStoreFileImplement.Models; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; + +namespace JewerlyStoreFileImplement.Implements +{ + public class JewelStorage : IJewelStorage + { + private readonly DataFileSingleton source; + + public JewelStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public JewelViewModel? GetElement(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue) + { + return null; + } + return source.Jewels.FirstOrDefault(x => (!string.IsNullOrEmpty(model.JewelName) && x.JewelName == model.JewelName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(JewelSearchModel model) + { + if (string.IsNullOrEmpty(model.JewelName)) + { + return new(); + } + return source.Jewels.Where(x => x.JewelName.Contains(model.JewelName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Jewels.Select(x => x.GetViewModel).ToList(); + } + + public JewelViewModel? Insert(JewelBindingModel model) + { + model.Id = source.Jewels.Count > 0 ? source.Jewels.Max(x => x.Id) + 1 : 1; + var newJewel = Jewel.Create(model); + if (newJewel == null) + { + return null; + } + source.Jewels.Add(newJewel); + source.SaveJewels(); + + return newJewel.GetViewModel; + } + + public JewelViewModel? Update(JewelBindingModel model) + { + var jewel = source.Jewels.FirstOrDefault(x => x.Id == model.Id); + if (jewel == null) + { + return null; + } + jewel.Update(model); + source.SaveJewels(); + return jewel.GetViewModel; + } + + public JewelViewModel? Delete(JewelBindingModel model) + { + var jewel = source.Jewels.FirstOrDefault(x => x.Id == model.Id); + if (jewel == null) + { + return null; + } + source.Jewels.Remove(jewel); + source.SaveJewels(); + return jewel.GetViewModel; + } + } +} diff --git a/JewelryStore/JewerlyStoreFileImplement/Implements/OrderStorage.cs b/JewelryStore/JewerlyStoreFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..8ad5bf2 --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JewerlyStoreFileImplement.Models; +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; + + +namespace JewerlyStoreFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton _source; + public OrderStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return _source.Orders.Select(x => SAddJewelName(x.GetViewModel)).ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return _source.Orders.Where(x => x.Id == model.Id).Select(x => SAddJewelName(x.GetViewModel)).ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return SAddJewelName(_source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + _source.SaveOrders(); + return SAddJewelName(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 SAddJewelName(order.GetViewModel); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = _source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Orders.Remove(element); + _source.SaveOrders(); + return SAddJewelName(element.GetViewModel); + } + return null; + } + + public OrderViewModel SAddJewelName(OrderViewModel fullModel) + { + string? jewelName = _source.Jewels.FirstOrDefault(x => x.Id == fullModel?.JewelId)?.JewelName; + if (jewelName != null) fullModel.JewelName = jewelName; + return fullModel; + } + } +} diff --git a/JewelryStore/JewerlyStoreFileImplement/JewerlyStoreFileImplement.csproj b/JewelryStore/JewerlyStoreFileImplement/JewerlyStoreFileImplement.csproj new file mode 100644 index 0000000..eaba351 --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/JewerlyStoreFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/JewelryStore/JewerlyStoreFileImplement/Models/Component.cs b/JewelryStore/JewerlyStoreFileImplement/Models/Component.cs new file mode 100644 index 0000000..88426cf --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/Models/Component.cs @@ -0,0 +1,69 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewerlyStoreFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/JewelryStore/JewerlyStoreFileImplement/Models/Jewel.cs b/JewelryStore/JewerlyStoreFileImplement/Models/Jewel.cs new file mode 100644 index 0000000..23c9f2c --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/Models/Jewel.cs @@ -0,0 +1,93 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewerlyStoreFileImplement.Models +{ + public class Jewel : IJewelModel + { + public int Id { get; private set; } + public string JewelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _jewelComponents = null; + public Dictionary JewelComponents + { + get + { + if (_jewelComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _jewelComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); + } + return _jewelComponents; + } + } + + public static Jewel? Create(JewelBindingModel model) + { + if (model == null) + { + return null; + } + return new Jewel() + { + Id = model.Id, + JewelName = model.JewelName, + Price = model.Price, + Components = model.JewelComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Jewel? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Jewel() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + JewelName = element.Element("JewelName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("JewelComponents")!.Elements("JewelComponent") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(JewelBindingModel model) + { + if (model == null) + { + return; + } + JewelName = model.JewelName; + Price = model.Price; + Components = model.JewelComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _jewelComponents = null; + } + + public JewelViewModel GetViewModel => new() + { + Id = Id, + JewelName = JewelName, + Price = Price, + JewelComponents = JewelComponents + }; + + public XElement GetXElement => new("Jewel", + new XAttribute("Id", Id), + new XElement("JewelName", JewelName), + new XElement("Price", Price.ToString()), + new XElement("JewelComponents", Components.Select(x => + new XElement("JewelComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/JewelryStore/JewerlyStoreFileImplement/Models/Order.cs b/JewelryStore/JewerlyStoreFileImplement/Models/Order.cs new file mode 100644 index 0000000..424c430 --- /dev/null +++ b/JewelryStore/JewerlyStoreFileImplement/Models/Order.cs @@ -0,0 +1,91 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.ViewModels; +using JewerlyStoreDataModels.Enums; +using JewerlyStoreDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace JewerlyStoreFileImplement.Models +{ + public class Order : IOrderModel + { + public int JewelId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + JewelId = model.JewelId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + JewelId = Convert.ToInt32(element.Element("JewelId")!.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 = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + JewelId = JewelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("JewelId", JewelId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs b/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs index 9bb464b..8f89139 100644 --- a/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs +++ b/JewelryStore/JewerlyStoreView/FormComponents.Designer.cs @@ -98,6 +98,7 @@ Controls.Add(dataGridView); Name = "FormComponents"; Text = "Компоненты"; + Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs b/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs index 8b1e38e..92de2f1 100644 --- a/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs +++ b/JewelryStore/JewerlyStoreView/FormJewels.Designer.cs @@ -98,6 +98,7 @@ Controls.Add(dataGridView); Name = "FormJewels"; Text = "Изделия"; + Load += FormJewels_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } diff --git a/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj b/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj index ea0fd13..1b1bb14 100644 --- a/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj +++ b/JewelryStore/JewerlyStoreView/JewerlyStoreView.csproj @@ -18,6 +18,7 @@ + \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/Program.cs b/JewelryStore/JewerlyStoreView/Program.cs index 528100e..d44eff3 100644 --- a/JewelryStore/JewerlyStoreView/Program.cs +++ b/JewelryStore/JewerlyStoreView/Program.cs @@ -1,6 +1,6 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.StoragesContracts; -using JewelryStoreListImplement.Implements; +using JewerlyStoreFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging;