64 lines
2.6 KiB
C#
64 lines
2.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using DumpTruck.Entities;
|
||
|
||
namespace DumpTruck.DrawingObjects
|
||
{
|
||
public static class ExtentionDrawingTruck
|
||
{
|
||
/// <summary>
|
||
/// Создание объекта из строки
|
||
/// </summary>
|
||
/// <param name="info">Строка с данными для создания объекта</param>
|
||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||
/// <param name="width">Ширина</param>
|
||
/// <param name="height">Высота</param>
|
||
/// <returns>Объект</returns>
|
||
public static DrawingTruck? CreateDrawingTruck(this string info, char
|
||
separatorForObject, int width, int height)
|
||
{
|
||
string[] strs = info.Split(separatorForObject);
|
||
if (strs.Length == 3)
|
||
{
|
||
return new DrawingTruck(Convert.ToInt32(strs[0]),
|
||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||
}
|
||
if (strs.Length == 7)
|
||
{
|
||
return new DrawingDumpTruck(Convert.ToInt32(strs[0]),
|
||
Convert.ToInt32(strs[1]),
|
||
Color.FromName(strs[2]),
|
||
Convert.ToBoolean(strs[3]),
|
||
Convert.ToBoolean(strs[4]),
|
||
Color.FromName(strs[5]),
|
||
Color.FromName(strs[6]), width, height);
|
||
}
|
||
return null;
|
||
}
|
||
/// <summary>
|
||
/// Получение данных для сохранения в файл
|
||
/// </summary>
|
||
/// <param name="drawingTruck">Сохраняемый объект</param>
|
||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||
/// <returns>Строка с данными по объекту</returns>
|
||
public static string GetDataForSave(this DrawingTruck drawingTruck, char separatorForObject)
|
||
{
|
||
var truck = drawingTruck.EntityTruck;
|
||
if (truck == null)
|
||
{
|
||
return string.Empty;
|
||
}
|
||
var str = $"{truck.Speed}{separatorForObject}{truck.Weight}{separatorForObject}{truck.BodyColor.Name}";
|
||
if (truck is not EntityDumpTruck dumpTruck)
|
||
{
|
||
return str;
|
||
}
|
||
return
|
||
$"{str}{separatorForObject}{dumpTruck.Tent}{separatorForObject}{dumpTruck.DumpBox}{separatorForObject}{dumpTruck.TentColor.Name}{separatorForObject}{dumpTruck.DumpBoxColor.Name}";
|
||
}
|
||
}
|
||
}
|