LabWork02_Basic

This commit is contained in:
parent 828ee7d1db
commit c53a3d9e65
12 changed files with 941 additions and 3 deletions

View File

@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftPlantContracts", "A
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftPlantBusinessLogic", "AircraftPlantBusinessLogic\AircraftPlantBusinessLogic.csproj", "{6F6FDED9-615A-4272-951B-E1F3B0CC5005}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftPlantBusinessLogic", "AircraftPlantBusinessLogic\AircraftPlantBusinessLogic.csproj", "{6F6FDED9-615A-4272-951B-E1F3B0CC5005}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantListImplement", "AircraftPlantListImplement\AircraftPlantListImplement.csproj", "{C7152B1B-4582-4B31-9F1E-0208118BD9D9}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AircraftPlantListImplement", "AircraftPlantListImplement\AircraftPlantListImplement.csproj", "{C7152B1B-4582-4B31-9F1E-0208118BD9D9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AircraftPlantFileImplement", "AircraftPlantFileImplement\AircraftPlantFileImplement.csproj", "{4456EC84-CEFC-419B-9A30-F1EE409120E4}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{C7152B1B-4582-4B31-9F1E-0208118BD9D9}.Debug|Any CPU.Build.0 = Debug|Any CPU {C7152B1B-4582-4B31-9F1E-0208118BD9D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7152B1B-4582-4B31-9F1E-0208118BD9D9}.Release|Any CPU.ActiveCfg = Release|Any CPU {C7152B1B-4582-4B31-9F1E-0208118BD9D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7152B1B-4582-4B31-9F1E-0208118BD9D9}.Release|Any CPU.Build.0 = Release|Any CPU {C7152B1B-4582-4B31-9F1E-0208118BD9D9}.Release|Any CPU.Build.0 = Release|Any CPU
{4456EC84-CEFC-419B-9A30-F1EE409120E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4456EC84-CEFC-419B-9A30-F1EE409120E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4456EC84-CEFC-419B-9A30-F1EE409120E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4456EC84-CEFC-419B-9A30-F1EE409120E4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\AircraftPlantContracts\AircraftPlantContracts.csproj" />
<ProjectReference Include="..\AircraftPlantDataModels\AircraftPlantDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,122 @@
using AircraftPlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement
{
/// <summary>
/// Класс для хранения списков классов-моделей (паттерн Singleton)
/// </summary>
public class DataFileSingleton
{
/// <summary>
/// Ссылка на класс
/// </summary>
private static DataFileSingleton? _instance;
/// <summary>
/// Название файла для хранения информации о компонентах
/// </summary>
private readonly string ComponentFileName = "Component.xml";
/// <summary>
/// Название файла для хранения информации о заказах
/// </summary>
private readonly string OrderFileName = "Order.xml";
/// <summary>
/// Название файла для хранения информации о изделиях
/// </summary>
private readonly string PlaneFileName = "Plane.xml";
/// <summary>
/// Список классов-моделей компонентов
/// </summary>
public List<Component> Components { get; set; }
/// <summary>
/// Список классов-моделей заказов
/// </summary>
public List<Order> Orders { get; set; }
/// <summary>
/// Список классов-моделей изделий
/// </summary>
public List<Plane> Planes { get; set; }
/// <summary>
/// Конструктор
/// </summary>
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Planes = LoadData(PlaneFileName, "Plane", x => Plane.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
/// <summary>
/// Получить ссылку на класс
/// </summary>
/// <returns></returns>
public static DataFileSingleton GetInstance()
{
if (_instance == null)
{
_instance = new DataFileSingleton();
}
return _instance;
}
/// <summary>
/// Сохранение компонентов
/// </summary>
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
/// <summary>
/// Сохранение изделий
/// </summary>
public void SavePlanes() => SaveData(Planes, PlaneFileName, "Planes", x => x.GetXElement);
/// <summary>
/// Сохранение заказов
/// </summary>
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
/// <summary>
/// Метод для загрузки данных из xml-файла
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="filename"></param>
/// <param name="xmlNodeName"></param>
/// <param name="selectFunction"></param>
/// <returns></returns>
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
/// <summary>
/// Метод для сохранения данных в xml-файл
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <param name="filename"></param>
/// <param name="xmlNodeName"></param>
/// <param name="selectFunction"></param>
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,136 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.StoragesContracts;
using AircraftPlantContracts.ViewModels;
using AircraftPlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantFileImplement.Implements
{
/// <summary>
/// Реализация интерфейса хранилища для компонентов
/// </summary>
public class ComponentStorage : IComponentStorage
{
/// <summary>
/// Хранилище
/// </summary>
private readonly DataFileSingleton _source;
/// <summary>
/// Конструктор
/// </summary>
public ComponentStorage()
{
_source = DataFileSingleton.GetInstance();
}
/// <summary>
/// Получение полного списка
/// </summary>
/// <returns></returns>
public List<ComponentViewModel> GetFullList()
{
return _source.Components
.Select(x => x.GetViewModel)
.ToList();
}
/// <summary>
/// Получение фильтрованного списка
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ComponentViewModel> 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();
}
/// <summary>
/// Получение элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Добавление элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Редактирование элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Удаление элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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;
}
}
}

View File

@ -0,0 +1,133 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.StoragesContracts;
using AircraftPlantContracts.ViewModels;
using AircraftPlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantFileImplement.Implements
{
/// <summary>
/// Реализация интерфейса хранилища для заказов
/// </summary>
public class OrderStorage : IOrderStorage
{
/// <summary>
/// Хранилище
/// </summary>
private readonly DataFileSingleton _source;
/// <summary>
/// Конструктор
/// </summary>
public OrderStorage()
{
_source = DataFileSingleton.GetInstance();
}
/// <summary>
/// Получение полного списка
/// </summary>
/// <returns></returns>
public List<OrderViewModel> GetFullList()
{
return _source.Orders
.Select(x => x.GetViewModel)
.ToList();
}
/// <summary>
/// Получение фильтрованного списка
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return _source.Orders
.Where(x => x.Id.Equals(model.Id))
.Select(x => x.GetViewModel)
.ToList();
}
/// <summary>
/// Получение элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return _source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
/// <summary>
/// Добавление элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Редактирование элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Удаление элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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 element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,137 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.SearchModels;
using AircraftPlantContracts.StoragesContracts;
using AircraftPlantContracts.ViewModels;
using AircraftPlantFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantFileImplement.Implements
{
/// <summary>
/// Реализация интерфейса хранилища для изделий
/// </summary>
public class PlaneStorage : IPlaneStorage
{
/// <summary>
/// Хранилище
/// </summary>
private readonly DataFileSingleton _source;
/// <summary>
/// Конструктор
/// </summary>
public PlaneStorage()
{
_source = DataFileSingleton.GetInstance();
}
/// <summary>
/// Получение полного списка
/// </summary>
/// <returns></returns>
public List<PlaneViewModel> GetFullList()
{
return _source.Planes
.Select(x => x.GetViewModel)
.ToList();
}
/// <summary>
/// Получение фильтрованного списка
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<PlaneViewModel> GetFilteredList(PlaneSearchModel model)
{
if (string.IsNullOrEmpty(model.PlaneName))
{
return new();
}
return _source.Planes
.Where(x => x.PlaneName.Contains(model.PlaneName))
.Select(x => x.GetViewModel)
.ToList();
}
/// <summary>
/// Получение элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public PlaneViewModel? GetElement(PlaneSearchModel model)
{
if (string.IsNullOrEmpty(model.PlaneName) && !model.Id.HasValue)
{
return null;
}
return _source.Planes
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.PlaneName) &&
x.PlaneName == model.PlaneName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
/// <summary>
/// Добавление элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public PlaneViewModel? Insert(PlaneBindingModel model)
{
model.Id = _source.Planes.Count > 0 ? _source.Planes.Max(x => x.Id) + 1 : 1;
var newPlane = Plane.Create(model);
if (newPlane == null)
{
return null;
}
_source.Planes.Add(newPlane);
_source.SavePlanes();
return newPlane.GetViewModel;
}
/// <summary>
/// Редактирование элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public PlaneViewModel? Update(PlaneBindingModel model)
{
var plane = _source.Planes.FirstOrDefault(x => x.Id == model.Id);
if (plane == null)
{
return null;
}
plane.Update(model);
_source.SavePlanes();
return plane.GetViewModel;
}
/// <summary>
/// Удаление элемента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public PlaneViewModel? Delete(PlaneBindingModel model)
{
var element = _source.Planes.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Planes.Remove(element);
_source.SavePlanes();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,106 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement.Models
{
/// <summary>
/// Сущность "Компонент"
/// </summary>
public class Component : IComponentModel
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; private set; }
/// <summary>
/// Название компонента
/// </summary>
public string ComponentName { get; private set; } = string.Empty;
/// <summary>
/// Стоимость компонента
/// </summary>
public double Cost { get; set; }
/// <summary>
/// Создание модели компонента
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static Component? Create(ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
/// <summary>
/// Создание модели компонента из данных файла
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
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)
};
}
/// <summary>
/// Изменение модели компонента
/// </summary>
/// <param name="model"></param>
public void Update(ComponentBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
/// <summary>
/// Получение модели компонента
/// </summary>
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
/// <summary>
/// Запись данных о модели компонента в файл
/// </summary>
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,143 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Enums;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement.Models
{
/// <summary>
/// Сущность "Заказ"
/// </summary>
public class Order : IOrderModel
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; private set; }
/// <summary>
/// Идентификатор изделия
/// </summary>
public int PlaneId { get; private set; }
/// <summary>
/// Количество изделий
/// </summary>
public int Count { get; private set; }
/// <summary>
/// Сумма заказа
/// </summary>
public double Sum { get; private set; }
/// <summary>
/// Статус заказа
/// </summary>
public OrderStatus Status { get; private set; }
/// <summary>
/// Дата создания заказа
/// </summary>
public DateTime DateCreate { get; private set; }
/// <summary>
/// Дата выполнения заказа
/// </summary>
public DateTime? DateImplement { get; private set; }
/// <summary>
/// Создание модели заказа
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order
{
Id = model.Id,
PlaneId = model.PlaneId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
/// <summary>
/// Создание модели заказа из данных файла
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PlaneId = Convert.ToInt32(element.Element("PlaneId")!.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)
};
}
/// <summary>
/// Изменение модели заказа
/// </summary>
/// <param name="model"></param>
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
/// <summary>
/// Получение модели заказа
/// </summary>
public OrderViewModel GetViewModel => new()
{
Id = Id,
PlaneId = PlaneId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
/// <summary>
/// Запись данных о модели заказа в файл
/// </summary>
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("PlaneId", PlaneId),
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()));
}
}

View File

@ -0,0 +1,140 @@
using AircraftPlantContracts.BindingModels;
using AircraftPlantContracts.ViewModels;
using AircraftPlantDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AircraftPlantFileImplement.Models
{
/// <summary>
/// Сущность "Изделие"
/// </summary>
public class Plane : IPlaneModel
{
/// <summary>
/// Идентификатор
/// </summary>
public int Id { get; private set; }
/// <summary>
/// Название изделия
/// </summary>
public string PlaneName { get; private set; } = string.Empty;
/// <summary>
/// Стоимость изделия
/// </summary>
public double Price { get; private set; }
/// <summary>
/// Коллекция компонентов изделия в виде
/// «идентификатор компонента количество компонентов»
/// </summary>
public Dictionary<int, int> Components { get; private set; } = new();
/// <summary>
/// Коллекция компонентов изделия
/// </summary>
private Dictionary<int, (IComponentModel, int)>? _planeComponents = null;
public Dictionary<int, (IComponentModel, int)> PlaneComponents
{
get
{
if (_planeComponents == null)
{
var source = DataFileSingleton.GetInstance();
_planeComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
}
return _planeComponents;
}
}
/// <summary>
/// Создание модели изделия
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static Plane? Create(PlaneBindingModel? model)
{
if (model == null)
{
return null;
}
return new Plane()
{
Id = model.Id,
PlaneName = model.PlaneName,
Price = model.Price,
Components = model.PlaneComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
/// <summary>
/// Создание модели изделия из данных файла
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
public static Plane? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Plane()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
PlaneName = element.Element("PlaneName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("PlaneComponents")!.Elements("PlaneComponent")
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
/// <summary>
/// Изменение модели изделия
/// </summary>
/// <param name="model"></param>
public void Update(PlaneBindingModel? model)
{
if (model == null)
{
return;
}
PlaneName = model.PlaneName;
Price = model.Price;
Components = model.PlaneComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_planeComponents = null;
}
/// <summary>
/// Получение модели изделия
/// </summary>
public PlaneViewModel GetViewModel => new()
{
Id = Id,
PlaneName = PlaneName,
Price = Price,
PlaneComponents = PlaneComponents
};
/// <summary>
/// Запись данных о модели изделия в файл
/// </summary>
public XElement GetXElement => new("Plane",
new XAttribute("Id", Id),
new XElement("PlaneName", PlaneName),
new XElement("Price", Price.ToString()),
new XElement("PlaneComponents", Components.Select(x =>
new XElement("PlaneComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

@ -27,6 +27,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\AircraftPlantBusinessLogic\AircraftPlantBusinessLogic.csproj" /> <ProjectReference Include="..\AircraftPlantBusinessLogic\AircraftPlantBusinessLogic.csproj" />
<ProjectReference Include="..\AircraftPlantContracts\AircraftPlantContracts.csproj" /> <ProjectReference Include="..\AircraftPlantContracts\AircraftPlantContracts.csproj" />
<ProjectReference Include="..\AircraftPlantFileImplement\AircraftPlantFileImplement.csproj" />
<ProjectReference Include="..\AircraftPlantListImplement\AircraftPlantListImplement.csproj" /> <ProjectReference Include="..\AircraftPlantListImplement\AircraftPlantListImplement.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -155,7 +155,7 @@ namespace AircraftPlantView
{ {
try try
{ {
_logger.LogInformation("Удаление компонента:{ ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _logger.LogInformation("Удаление компонента:{ ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value);
_planeComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); _planeComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
} }
catch (Exception ex) catch (Exception ex)

View File

@ -1,7 +1,7 @@
using AircraftPlantBusinessLogic.BusinessLogics; using AircraftPlantBusinessLogic.BusinessLogics;
using AircraftPlantContracts.BusinessLogicsContracts; using AircraftPlantContracts.BusinessLogicsContracts;
using AircraftPlantContracts.StoragesContracts; using AircraftPlantContracts.StoragesContracts;
using AircraftPlantListImplement.Implements; using AircraftPlantFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;