PIbd-21_Krasnikov_Lab1.base/WinFormsApp1/ExtentionTraktor.cs

46 lines
1.5 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinFormsApp1;
namespace WinFormsApp1
{
internal static class ExtentionTraktor
{
private static readonly char _separatorForObject = ':';
public static TractorDraw CreateDrawingTraktor(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new TractorDraw(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 6)
{
return new MultiTraktorDraw(
Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]),
Color.FromName(strs[2]), Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]));
}
return null;
}
public static string GetDataForSave(this TractorDraw drawingTraktor)
{
var traktor = drawingTraktor.Tractor;
var str = $"{traktor.Speed}{_separatorForObject}{traktor.Weight}{_separatorForObject}{traktor.BodyColor.Name}";
if (traktor is not MultiTraktor multiTraktor)
{
return str;
}
return $"{str}{_separatorForObject}{multiTraktor.DopColor.Name}{_separatorForObject}{multiTraktor.dopAhead}{_separatorForObject}{multiTraktor.dopBehind}";
}
}
}