diff --git a/ProjectMonorail/FormMonorailCollection.Designer.cs b/ProjectMonorail/FormMonorailCollection.Designer.cs index 512821d..e0a7434 100644 --- a/ProjectMonorail/FormMonorailCollection.Designer.cs +++ b/ProjectMonorail/FormMonorailCollection.Designer.cs @@ -46,10 +46,17 @@ labelCollectionName = new Label(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + saveFileDialog = new SaveFileDialog(); + openFileDialog = new OpenFileDialog(); groupBoxTools.SuspendLayout(); panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + menuStrip.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -59,9 +66,9 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(970, 0); + groupBoxTools.Location = new Point(970, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(241, 662); + groupBoxTools.Size = new Size(241, 638); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -75,7 +82,7 @@ panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 337); + panelCompanyTools.Location = new Point(3, 313); panelCompanyTools.Margin = new Padding(3, 2, 3, 2); panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Size = new Size(235, 322); @@ -249,12 +256,52 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(970, 662); + pictureBox.Size = new Size(970, 638); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1211, 24); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip1"; + // + // файлToolStripMenuItem + // + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); + файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + файлToolStripMenuItem.Size = new Size(48, 20); + файлToolStripMenuItem.Text = "Файл"; + // + // saveToolStripMenuItem + // + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + saveToolStripMenuItem.Size = new Size(184, 22); + saveToolStripMenuItem.Text = "Сохранение "; + saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; + // + // loadToolStripMenuItem + // + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(184, 22); + loadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; + // // FormMonorailCollection // AutoScaleDimensions = new SizeF(7F, 15F); @@ -262,6 +309,8 @@ ClientSize = new Size(1211, 662); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormMonorailCollection"; Text = "Коллекция монорельсов"; groupBoxTools.ResumeLayout(false); @@ -270,7 +319,10 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -293,5 +345,11 @@ private ListBox listBoxCollection; private Button buttonCreateCompany; private Panel panelCompanyTools; + private MenuStrip menuStrip; + private ToolStripMenuItem файлToolStripMenuItem; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripMenuItem loadToolStripMenuItem; + private SaveFileDialog saveFileDialog; + private OpenFileDialog openFileDialog; } } \ No newline at end of file diff --git a/ProjectMonorail/FormMonorailCollection.cs b/ProjectMonorail/FormMonorailCollection.cs index 9b887cd..7ad561b 100644 --- a/ProjectMonorail/FormMonorailCollection.cs +++ b/ProjectMonorail/FormMonorailCollection.cs @@ -202,5 +202,46 @@ namespace ProjectMonorail panelCompanyTools.Enabled = true; RerfreshListBoxItems(); } + + /// + /// Обработка нажатия "Сохранения" + /// + /// + /// + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storageCollection.SaveData(saveFileDialog.FileName)) + { + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + /// + /// Обработка нажатия "Загрузки" + /// + /// + /// + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storageCollection.LoadData(openFileDialog.FileName)) + { + MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + RerfreshListBoxItems(); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/ProjectMonorail/FormMonorailCollection.resx b/ProjectMonorail/FormMonorailCollection.resx index af32865..8b1dfa1 100644 --- a/ProjectMonorail/FormMonorailCollection.resx +++ b/ProjectMonorail/FormMonorailCollection.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 126, 17 + + + 261, 17 + \ No newline at end of file diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs index 9c29fae..e335623 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/AbstractCompany.cs @@ -48,7 +48,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// @@ -70,7 +70,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects /// public static DrawingMonorail operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? null; + return company._collection?.Remove(position); } /// diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs index 86200c9..ab2eec1 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/DepotSharingService.cs @@ -1,6 +1,4 @@ using ProjectMonorail.Scripts.Monorail.Drawnings; -using System.Diagnostics; -using System.Drawing; namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects { @@ -8,8 +6,6 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects { public DepotSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects collection) : base(pictureWidth, pictureHeight, collection) {} - private int maxCountX; - private int maxCountY; private int offsetX = 30; protected override void DrawBackgound(Graphics g) diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs index 182b693..a8bd3bc 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -17,7 +17,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -48,5 +48,15 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects /// Объект T? Get(int position); + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементный вывод элементов коллекции + IEnumerable GetItems(); } } diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ListGenericObjects.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ListGenericObjects.cs index 0fd7fc8..67fdfc7 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ListGenericObjects.cs @@ -1,4 +1,5 @@ -namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects + +namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects { /// /// Параметризованный набор объектов @@ -19,8 +20,13 @@ public int Count => _collection.Count; - public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } - + public int MaxCount { + get { return Count; } + set { if (value > 0) { _maxCount = value; } } + } + + public CollectionType GetCollectionType => CollectionType.List; + /// /// Конструктор /// @@ -72,5 +78,13 @@ return temp; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } } } diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs index 81ca0b2..a7d033d 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/MassiveGenericObjects.cs @@ -13,8 +13,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects public int Count => _collection.Length; - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -31,6 +35,8 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор @@ -108,5 +114,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects return true; } + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } } } \ No newline at end of file diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs index 23fe9a6..8c17858 100644 --- a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs @@ -1,11 +1,15 @@ -namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects +using ProjectMonorail.Scripts.Monorail.Drawnings; +using System.Diagnostics; +using System.Text; + +namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects { /// /// Класс-хранилище коллекций /// /// public class StorageCollection - where T : class + where T : DrawingMonorail { /// /// Словарь (хранилище) с коллекциями @@ -17,6 +21,21 @@ /// public List Keys => _storages.Keys.ToList(); + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// @@ -34,15 +53,16 @@ { // TODO проверка, что name не пустой и нет в словаре записи с таким ключом // TODO Прописать логику для добавления - if (!_storages.ContainsKey(name)) { + if (!_storages.ContainsKey(name)) + { ICollectionGenericObjects collection; - switch(collectionType) + switch (collectionType) { - case CollectionType.List: + case CollectionType.List: collection = new ListGenericObjects(); break; - case CollectionType.Massive: + case CollectionType.Massive: collection = new MassiveGenericObjects(); break; default: @@ -79,5 +99,132 @@ return null; } } + + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (_storages.Count == 0) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder sb = new(); + sb.Append(_collectionKey); + foreach (KeyValuePair> value in + _storages) + { + sb.Append(Environment.NewLine); + // не сохраняем пустые коллекции + if (value.Value.Count == 0) + { + continue; + } + sb.Append(value.Key); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.MaxCount); + sb.Append(_separatorForKeyValue); + foreach (T? item in value.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + { + continue; + } + sb.Append(data); + sb.Append(_separatorItems); + } + } + using FileStream fs = new(filename, FileMode.Create); + byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString()); + fs.Write(info, 0, info.Length); + return true; + } + + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + string bufferTextFromFile = ""; + using (FileStream fs = new(filename, FileMode.Open)) + { + byte[] b = new byte[fs.Length]; + UTF8Encoding temp = new(true); + while (fs.Read(b, 0, b.Length) > 0) + { + bufferTextFromFile += temp.GetString(b); + } + } + string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + if (strs == null || strs.Length == 0) + { + return false; + } + + if (!strs[0].Equals(_collectionKey)) + { + //если нет такой записи, то это не те данные + return false; + } + + _storages.Clear(); + foreach (string data in strs) + { + string[] record = data.Split(_separatorForKeyValue, + StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 4) + { + continue; + } + CollectionType collectionType = + (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); + ICollectionGenericObjects? collection = + StorageCollection.CreateCollection(collectionType); + if (collection == null) + { + return false; + } + collection.MaxCount = Convert.ToInt32(record[2]); + string[] set = record[3].Split(_separatorItems, + StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawingMonorail() is T monorail) + { + if (collection.Insert(monorail) == -1) + { + return false; + } + } + } + _storages.Add(record[0], collection); + } + return true; + } + + private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) + { + return collectionType switch + { + CollectionType.Massive => new MassiveGenericObjects(), + CollectionType.List => new ListGenericObjects(), + _ => null, + }; + } } } \ No newline at end of file diff --git a/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs b/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs index be1faf7..91c2a45 100644 --- a/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs +++ b/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingModernMonorail.cs @@ -1,4 +1,5 @@ -using System.Drawing.Drawing2D; +using System.Diagnostics; +using System.Drawing.Drawing2D; using ProjectMonorail.Scripts.Monorail.Entities; namespace ProjectMonorail.Scripts.Monorail.Drawnings @@ -8,6 +9,15 @@ namespace ProjectMonorail.Scripts.Monorail.Drawnings /// public class DrawingModernMonorail : DrawingMonorail { + /// + /// Конструктор + /// + /// + public DrawingModernMonorail(EntityModernMonorail entityModernMonorail) : base((entityModernMonorail.Cabin ? 170 : 90), 40) + { + EntityMonorail = new EntityModernMonorail(entityModernMonorail.Speed, entityModernMonorail.Weight, entityModernMonorail.BodyColor, entityModernMonorail.AdditionalColor, entityModernMonorail.MonorailTrack, entityModernMonorail.Cabin); + } + /// /// Конструктор /// diff --git a/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingMonorail.cs b/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingMonorail.cs index 11ef869..f31e731 100644 --- a/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingMonorail.cs +++ b/ProjectMonorail/Scripts/Monorail/Drawnings/DrawingMonorail.cs @@ -1,4 +1,5 @@ using ProjectMonorail.Scripts.Monorail.Entities; +using System.Diagnostics; using System.Drawing.Drawing2D; namespace ProjectMonorail.Scripts.Monorail.Drawnings @@ -85,6 +86,16 @@ namespace ProjectMonorail.Scripts.Monorail.Drawnings EntityMonorail = new EntityMonorail(speed, weight, bodyColor); } + /// + /// Конструктор + /// + /// + public DrawingMonorail(EntityMonorail entityMonorail) : this() + { + Debug.WriteLine(entityMonorail.BodyColor.ToString() + " " + entityMonorail.Speed + " " + entityMonorail.Weight); + EntityMonorail = new EntityMonorail(entityMonorail.Speed, entityMonorail.Weight, entityMonorail.BodyColor); + } + /// /// Конструктор для наследников /// @@ -209,6 +220,8 @@ namespace ProjectMonorail.Scripts.Monorail.Drawnings Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor); + Debug.WriteLine("+"); + Debug.WriteLine(EntityMonorail.BodyColor.Name); //Кузов монорельса GraphicsPath pointsMonorailBody_LeftBody = new GraphicsPath(); diff --git a/ProjectMonorail/Scripts/Monorail/Drawnings/ExtentionDrawningMonorail.cs b/ProjectMonorail/Scripts/Monorail/Drawnings/ExtentionDrawningMonorail.cs new file mode 100644 index 0000000..c9a40d6 --- /dev/null +++ b/ProjectMonorail/Scripts/Monorail/Drawnings/ExtentionDrawningMonorail.cs @@ -0,0 +1,44 @@ +using ProjectMonorail.Scripts.Monorail.Entities; + +namespace ProjectMonorail.Scripts.Monorail.Drawnings +{ + /// + /// Расширение для класса EntityMonorail + /// + public static class ExtentionDrawningMonorail + { + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + public static DrawingMonorail? CreateDrawingMonorail(this string info) + { + string[] args = info.Split(_separatorForObject); + EntityMonorail? monorail = EntityModernMonorail.CreateEntityModernMonorail(args); + + if (monorail != null) return new DrawingModernMonorail((EntityModernMonorail)monorail); + + monorail = EntityMonorail.CreateEntityMonorail(args); + + if (monorail != null) return new DrawingMonorail(monorail); + + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// + /// + public static string GetDataForSave(this DrawingMonorail drawingMonorail) + { + string[]? array = drawingMonorail?.EntityMonorail?.GetStringRepresention(); + + if (array == null) + return string.Empty; + + return string.Join(_separatorForObject, array); + } + } +} diff --git a/ProjectMonorail/Scripts/Monorail/Entities/EntityModernMonorail.cs b/ProjectMonorail/Scripts/Monorail/Entities/EntityModernMonorail.cs index 434a146..452a93f 100644 --- a/ProjectMonorail/Scripts/Monorail/Entities/EntityModernMonorail.cs +++ b/ProjectMonorail/Scripts/Monorail/Entities/EntityModernMonorail.cs @@ -40,5 +40,26 @@ MonorailTrack = monorailTrack; Cabin = cabin; } + + /// + /// Получение строк с значениями свойств объекта класса-сущности + /// + /// + public override string[] GetStringRepresention() + { + return new string[] { nameof(EntityModernMonorail), Speed.ToString(), Weight.ToString(), BodyColor.Name.ToString(), AdditionalColor.Name.ToString(), MonorailTrack.ToString(), Cabin.ToString()}; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityModernMonorail? CreateEntityModernMonorail(string[] args) + { + if (args.Length == 0 || args[0] != nameof(EntityModernMonorail)) return null; + + return new EntityModernMonorail(Convert.ToInt32(args[1]), Convert.ToDouble(args[2]), Color.FromName(args[3]), Color.FromName(args[4]), Convert.ToBoolean(args[5]), Convert.ToBoolean(args[6])); + } } } diff --git a/ProjectMonorail/Scripts/Monorail/Entities/EntityMonorail.cs b/ProjectMonorail/Scripts/Monorail/Entities/EntityMonorail.cs index 387bbf8..9326fd8 100644 --- a/ProjectMonorail/Scripts/Monorail/Entities/EntityMonorail.cs +++ b/ProjectMonorail/Scripts/Monorail/Entities/EntityMonorail.cs @@ -42,5 +42,26 @@ Weight = weight; BodyColor = bodyColor; } + + /// + /// Получение строк с значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresention() + { + return new string[] { nameof(EntityMonorail), Speed.ToString(), Weight.ToString(), BodyColor.Name.ToString() }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityMonorail? CreateEntityMonorail(string[] args) + { + if (args.Length == 0 || args[0] != nameof(EntityMonorail)) return null; + + return new EntityMonorail(Convert.ToInt32(args[1]), Convert.ToDouble(args[2]), Color.FromName(args[3])); + } } }