diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs index e8dda77..a06a63c 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/ComponentStorage.cs @@ -24,7 +24,6 @@ namespace SoftwareInstallationFileImplement.Implements return new(); } return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); - } public ComponentViewModel? GetElement(ComponentSearchModel model) { @@ -71,7 +70,6 @@ namespace SoftwareInstallationFileImplement.Implements return element.GetViewModel; } return null; - } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs index 76dd01c..74271aa 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/DataFileSingleton.cs @@ -1,8 +1,6 @@ using SoftwareInstallationFileImplement.Models; using System.Xml.Linq; - - namespace SoftwareInstallationFileImplement { public class DataFileSingleton @@ -14,6 +12,7 @@ namespace SoftwareInstallationFileImplement public List Components { get; private set; } public List Orders { get; private set; } public List Packages { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -25,6 +24,7 @@ namespace SoftwareInstallationFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName,"Components", x => x.GetXElement); public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; @@ -47,4 +47,4 @@ namespace SoftwareInstallationFileImplement } } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs index 11dfbfb..1f8828d 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/Order.cs @@ -37,7 +37,6 @@ namespace SoftwareInstallationFileImplement.Models DateCreate = model.DateCreate, DateImplement = model.DateImplement, Id = model.Id, - }; } @@ -72,6 +71,7 @@ namespace SoftwareInstallationFileImplement.Models public OrderViewModel GetViewModel => new() { + PackageName = DataFileSingleton.GetInstance().Packages.FirstOrDefault(x => x.Id == PackageId)?.PackageName ?? string.Empty, PackageId = PackageId, Count = Count, Sum = Sum, diff --git a/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs b/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs index a104e83..ffcd255 100644 --- a/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs +++ b/SoftwareInstallation/SoftWareInstallationFileImplement/OrderStorage.cs @@ -39,16 +39,7 @@ namespace SoftwareInstallationFileImplement.Implements } public List GetFullList() { - var a = new List(); - //var result = _source.Orders - // .Select(x => x.GetViewModel) - // .ToList(); - //TODO - foreach (var order in _source.Orders) - { - a.Add(GetViewModel(order)); - } - return a; + return _source.Orders.Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) { @@ -73,18 +64,5 @@ namespace SoftwareInstallationFileImplement.Implements _source.SaveOrders(); return order.GetViewModel; } - private OrderViewModel GetViewModel(Order model) - { - var res = model.GetViewModel; - foreach (var package in _source.Packages) - { - if (package.Id == model.PackageId) - { - res.PackageName = package.PackageName; - break; - } - } - return res; - } } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs index 709c661..9f64c77 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormComponents.Designer.cs @@ -102,6 +102,7 @@ this.Controls.Add(this.buttonAdd); this.Name = "FormComponents"; this.Text = "Компоненты"; + this.Load += new System.EventHandler(this.FormComponents_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false); diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs index 06898ce..31af1e3 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs @@ -157,6 +157,7 @@ this.Controls.Add(this.menuStrip1); this.Name = "FormMain"; this.Text = "Установка ПО"; + this.Load += new System.EventHandler(this.FormMain_Load); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); diff --git a/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs index ebcc51a..ec656f1 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormPackages.Designer.cs @@ -105,6 +105,7 @@ this.Controls.Add(this.dataGridView); this.Name = "FormPackages"; this.Text = "Изделия"; + this.Load += new System.EventHandler(this.FormViewPackage_Load); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.ResumeLayout(false);