2024-10-03 01:44:06 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ProjectGasolineTanker.Entities;
|
|
|
|
|
|
|
|
|
|
namespace ProjectGasolineTanker.Drawings
|
|
|
|
|
{
|
|
|
|
|
public static class ExtentionDrawingTruck
|
|
|
|
|
{
|
|
|
|
|
// создание объекта из строки
|
|
|
|
|
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 == 6)
|
|
|
|
|
{
|
|
|
|
|
return new DrawingGasolineTanker(
|
|
|
|
|
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 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 EntityGasolineTanker GasolineTanker)
|
|
|
|
|
{
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
return $"{str}{separatorForObject}{GasolineTanker.Add_Color.Name}{separatorForObject}{GasolineTanker.IsTank}{separatorForObject}{GasolineTanker.IsWheel}";
|
|
|
|
|
}
|
2024-10-03 01:46:41 +04:00
|
|
|
|
}
|
2024-10-03 01:44:06 +04:00
|
|
|
|
}
|