From d533dd8a04319c2e75441d3d5d7aa1e6a29c42c4 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Fri, 11 Nov 2022 20:54:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20ExtentionLocomotive,=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=86=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B2=20FormLocomotiveConfig=20=D1=80=D0=B5?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectLocomotive/ExtentionLocomotive.cs | 48 +++++++++++++++++++ .../FormLocomotiveConfig.Designer.cs | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs diff --git a/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs new file mode 100644 index 0000000..7f4d18b --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectLocomotive +{ + internal static class ExtentionLocomotive + { + private static readonly char _separatorForObject = ':'; + public static string getDataForSave(this DrawningLocomotive drawningLocomotive) + { + var locomotive = drawningLocomotive.Locomotivе; + var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}"; + if (locomotive is not EntityElectricLocomotive warmlyLocomotive) + { + return str; + } + return $"{str}{_separatorForObject}{warmlyLocomotive.DopColor.Name}{_separatorForObject}{warmlyLocomotive.ElectroLines}{_separatorForObject}{warmlyLocomotive.ElectroBattery}"; + } + + public static DrawningLocomotive createDrawningLocomotive(this string info) + { + string[] strs = info.Split(_separatorForObject); + if (strs.Length == 3) + { + return new DrawningLocomotive( + Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]) + ); + } + if (strs.Length == 6) + { + return new DrawningElectroLocomotive( + 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; + } + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs index 9057d41..9314077 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs @@ -172,7 +172,7 @@ // // panelGreen // - this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.BackColor = System.Drawing.Color.Green; this.panelGreen.Location = new System.Drawing.Point(90, 39); this.panelGreen.Margin = new System.Windows.Forms.Padding(4); this.panelGreen.Name = "panelGreen";