From 250ef4516fa85c219059af039a721370621868b4 Mon Sep 17 00:00:00 2001 From: ekallin Date: Tue, 14 Nov 2023 00:59:34 +0400 Subject: [PATCH] create extension (ExtentionDrawingLocomotive) --- .../ExtentionDrawningCar.cs | 79 +++++++++++++++++++ .../FormLocomotiveCollections.cs | 1 - 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 ProjectElectricLocomotive/ProjectElectricLocomotive/ExtentionDrawningCar.cs diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/ExtentionDrawningCar.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/ExtentionDrawningCar.cs new file mode 100644 index 0000000..e9858b2 --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/ExtentionDrawningCar.cs @@ -0,0 +1,79 @@ +using ProjectElectricLocomotive.DrawingObjects; +using ProjectElectricLocomotive.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive +{ + /// + /// Расширение для класса EntityLocomotive + /// + public static class ExtentionDrawingLocomotive + { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawingLocomotive? CreateDrawingLocomotive(this string info, char + separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawingLocomotive( + Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), + width, + height + ); + } + if (strs.Length == 7) + { + return new DrawingElectricLocomotive( + Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), + Color.FromName(strs[3]), + Convert.ToBoolean(strs[4]), + Convert.ToBoolean(strs[5]), + width, + height + ); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Разделитель даннных + /// Строка с данными по объекту + public static string GetDataForSave(this DrawingLocomotive drawningLoco, char separatorForObject) + { + var loco = drawningLoco.EntityLocomotive; + if (loco == null) + { + return string.Empty; + } + var str = + $"{loco.Speed}{separatorForObject}{loco.Weight}{separatorForObject}{loco.BodyColor.Name}"; + if (loco is not EntityElectricLocomotive electroLoco) + { + return str; + } + return + $"{str}{separatorForObject}{electroLoco.AdditionalColor.Name}{separatorForObject}" + + $"{electroLoco.Horns}{separatorForObject}{electroLoco.SeifBatteries}" /*+ + $"{separatorForObject}{electroLoco.SportLine}"*/; + } + + } +} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs index c04158a..7d4cae9 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs @@ -15,7 +15,6 @@ using System.Windows.Forms; namespace ProjectElectricLocomotive { - //create 6 branch public partial class FormLocomotiveCollections : Form { private readonly LocomotiveGenericStorage _storage;