create extension (ExtentionDrawingLocomotive)
This commit is contained in:
parent
683a6c1382
commit
250ef4516f
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса EntityLocomotive
|
||||||
|
/// </summary>
|
||||||
|
public static class ExtentionDrawingLocomotive
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <param name="width">Ширина</param>
|
||||||
|
/// <param name="height">Высота</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningCar">Сохраняемый объект</param>
|
||||||
|
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
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}"*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,6 @@ using System.Windows.Forms;
|
|||||||
|
|
||||||
namespace ProjectElectricLocomotive
|
namespace ProjectElectricLocomotive
|
||||||
{
|
{
|
||||||
//create 6 branch
|
|
||||||
public partial class FormLocomotiveCollections : Form
|
public partial class FormLocomotiveCollections : Form
|
||||||
{
|
{
|
||||||
private readonly LocomotiveGenericStorage _storage;
|
private readonly LocomotiveGenericStorage _storage;
|
||||||
|
Loading…
Reference in New Issue
Block a user