Лабораторная работа №6

This commit is contained in:
ENDORFIT 2024-04-21 21:24:49 +04:00
parent dfa2816ba9
commit e1cc1e40ad
14 changed files with 420 additions and 23 deletions

View File

@ -46,10 +46,17 @@
labelCollectionName = new Label(); labelCollectionName = new Label();
comboBoxSelectorCompany = new ComboBox(); comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
menuStrip = new MenuStrip();
файлToolStripMenuItem = new ToolStripMenuItem();
saveToolStripMenuItem = new ToolStripMenuItem();
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout(); panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout(); panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // groupBoxTools
@ -59,9 +66,9 @@
groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(970, 0); groupBoxTools.Location = new Point(970, 24);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(241, 662); groupBoxTools.Size = new Size(241, 638);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
@ -75,7 +82,7 @@
panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false; panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 337); panelCompanyTools.Location = new Point(3, 313);
panelCompanyTools.Margin = new Padding(3, 2, 3, 2); panelCompanyTools.Margin = new Padding(3, 2, 3, 2);
panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(235, 322); panelCompanyTools.Size = new Size(235, 322);
@ -249,12 +256,52 @@
// pictureBox // pictureBox
// //
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0); pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(970, 662); pictureBox.Size = new Size(970, 638);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; 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 // FormMonorailCollection
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -262,6 +309,8 @@
ClientSize = new Size(1211, 662); ClientSize = new Size(1211, 662);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormMonorailCollection"; Name = "FormMonorailCollection";
Text = "Коллекция монорельсов"; Text = "Коллекция монорельсов";
groupBoxTools.ResumeLayout(false); groupBoxTools.ResumeLayout(false);
@ -270,7 +319,10 @@
panelStorage.ResumeLayout(false); panelStorage.ResumeLayout(false);
panelStorage.PerformLayout(); panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
@ -293,5 +345,11 @@
private ListBox listBoxCollection; private ListBox listBoxCollection;
private Button buttonCreateCompany; private Button buttonCreateCompany;
private Panel panelCompanyTools; private Panel panelCompanyTools;
private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
} }
} }

View File

@ -202,5 +202,46 @@ namespace ProjectMonorail
panelCompanyTools.Enabled = true; panelCompanyTools.Enabled = true;
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
/// <summary>
/// Обработка нажатия "Сохранения"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
/// <summary>
/// Обработка нажатия "Загрузки"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}
} }
} }

View File

@ -117,4 +117,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>126, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>261, 17</value>
</metadata>
</root> </root>

View File

@ -48,7 +48,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
_collection = collection; _collection = collection;
_collection.SetMaxCount = GetMaxCount; _collection.MaxCount = GetMaxCount;
} }
/// <summary> /// <summary>
@ -70,7 +70,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
/// <returns></returns> /// <returns></returns>
public static DrawingMonorail operator -(AbstractCompany company, int position) public static DrawingMonorail operator -(AbstractCompany company, int position)
{ {
return company._collection?.Remove(position) ?? null; return company._collection?.Remove(position);
} }
/// <summary> /// <summary>

View File

@ -1,6 +1,4 @@
using ProjectMonorail.Scripts.Monorail.Drawnings; using ProjectMonorail.Scripts.Monorail.Drawnings;
using System.Diagnostics;
using System.Drawing;
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
{ {
@ -8,8 +6,6 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
{ {
public DepotSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingMonorail> collection) : base(pictureWidth, pictureHeight, collection) {} public DepotSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects<DrawingMonorail> collection) : base(pictureWidth, pictureHeight, collection) {}
private int maxCountX;
private int maxCountY;
private int offsetX = 30; private int offsetX = 30;
protected override void DrawBackgound(Graphics g) protected override void DrawBackgound(Graphics g)

View File

@ -17,7 +17,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
/// <summary> /// <summary>
/// Установка максимального количества элементов /// Установка максимального количества элементов
/// </summary> /// </summary>
int SetMaxCount { set; } int MaxCount { get; set; }
/// <summary> /// <summary>
/// Добавление объекта в коллекцию /// Добавление объекта в коллекцию
@ -48,5 +48,15 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
/// <returns>Объект</returns> /// <returns>Объект</returns>
T? Get(int position); T? Get(int position);
/// <summary>
/// Получение типа коллекции
/// </summary>
CollectionType GetCollectionType { get; }
/// <summary>
/// Получение объектов коллекции по одному
/// </summary>
/// <returns>Поэлементный вывод элементов коллекции</returns>
IEnumerable<T?> GetItems();
} }
} }

View File

@ -1,4 +1,5 @@
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects 
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
{ {
/// <summary> /// <summary>
/// Параметризованный набор объектов /// Параметризованный набор объектов
@ -19,7 +20,12 @@
public int Count => _collection.Count; 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;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
@ -72,5 +78,13 @@
return temp; return temp;
} }
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < _collection.Count; ++i)
{
yield return _collection[i];
}
}
} }
} }

View File

@ -13,8 +13,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
public int Count => _collection.Length; public int Count => _collection.Length;
public int SetMaxCount public int MaxCount
{ {
get
{
return _collection.Length;
}
set set
{ {
if (value > 0) if (value > 0)
@ -31,6 +35,8 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
} }
} }
public CollectionType GetCollectionType => CollectionType.Massive;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
@ -108,5 +114,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
return true; return true;
} }
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < _collection.Length; ++i)
{
yield return _collection[i];
}
}
} }
} }

View File

@ -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
{ {
/// <summary> /// <summary>
/// Класс-хранилище коллекций /// Класс-хранилище коллекций
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class StorageCollection<T> public class StorageCollection<T>
where T : class where T : DrawingMonorail
{ {
/// <summary> /// <summary>
/// Словарь (хранилище) с коллекциями /// Словарь (хранилище) с коллекциями
@ -17,6 +21,21 @@
/// </summary> /// </summary>
public List<string> Keys => _storages.Keys.ToList(); public List<string> Keys => _storages.Keys.ToList();
/// <summary>
/// Ключевое слово, с которого должен начинаться файл
/// </summary>
private readonly string _collectionKey = "CollectionsStorage";
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private readonly string _separatorForKeyValue = "|";
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly string _separatorItems = ";";
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -34,7 +53,8 @@
{ {
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления // TODO Прописать логику для добавления
if (!_storages.ContainsKey(name)) { if (!_storages.ContainsKey(name))
{
ICollectionGenericObjects<T> collection; ICollectionGenericObjects<T> collection;
switch (collectionType) switch (collectionType)
@ -79,5 +99,132 @@
return null; return null;
} }
} }
/// <summary>
/// Сохранение информации по автомобилям в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
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<string, ICollectionGenericObjects<T>> 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;
}
/// <summary>
/// Загрузка информации по автомобилям в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
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<T>? collection =
StorageCollection<T>.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<T>? CreateCollection(CollectionType collectionType)
{
return collectionType switch
{
CollectionType.Massive => new MassiveGenericObjects<T>(),
CollectionType.List => new ListGenericObjects<T>(),
_ => null,
};
}
} }
} }

View File

@ -1,4 +1,5 @@
using System.Drawing.Drawing2D; using System.Diagnostics;
using System.Drawing.Drawing2D;
using ProjectMonorail.Scripts.Monorail.Entities; using ProjectMonorail.Scripts.Monorail.Entities;
namespace ProjectMonorail.Scripts.Monorail.Drawnings namespace ProjectMonorail.Scripts.Monorail.Drawnings
@ -8,6 +9,15 @@ namespace ProjectMonorail.Scripts.Monorail.Drawnings
/// </summary> /// </summary>
public class DrawingModernMonorail : DrawingMonorail public class DrawingModernMonorail : DrawingMonorail
{ {
/// <summary>
/// Конструктор
/// </summary>
/// <param name="entityModernMonorail"></param>
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);
}
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
using ProjectMonorail.Scripts.Monorail.Entities; using ProjectMonorail.Scripts.Monorail.Entities;
using System.Diagnostics;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
namespace ProjectMonorail.Scripts.Monorail.Drawnings namespace ProjectMonorail.Scripts.Monorail.Drawnings
@ -85,6 +86,16 @@ namespace ProjectMonorail.Scripts.Monorail.Drawnings
EntityMonorail = new EntityMonorail(speed, weight, bodyColor); EntityMonorail = new EntityMonorail(speed, weight, bodyColor);
} }
/// <summary>
/// Конструктор
/// </summary>
/// <param name="entityMonorail"></param>
public DrawingMonorail(EntityMonorail entityMonorail) : this()
{
Debug.WriteLine(entityMonorail.BodyColor.ToString() + " " + entityMonorail.Speed + " " + entityMonorail.Weight);
EntityMonorail = new EntityMonorail(entityMonorail.Speed, entityMonorail.Weight, entityMonorail.BodyColor);
}
/// <summary> /// <summary>
/// Конструктор для наследников /// Конструктор для наследников
/// </summary> /// </summary>
@ -209,6 +220,8 @@ namespace ProjectMonorail.Scripts.Monorail.Drawnings
Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor); Brush brush_Body = new SolidBrush(EntityMonorail.BodyColor);
Debug.WriteLine("+");
Debug.WriteLine(EntityMonorail.BodyColor.Name);
//Кузов монорельса //Кузов монорельса
GraphicsPath pointsMonorailBody_LeftBody = new GraphicsPath(); GraphicsPath pointsMonorailBody_LeftBody = new GraphicsPath();

View File

@ -0,0 +1,44 @@
using ProjectMonorail.Scripts.Monorail.Entities;
namespace ProjectMonorail.Scripts.Monorail.Drawnings
{
/// <summary>
/// Расширение для класса EntityMonorail
/// </summary>
public static class ExtentionDrawningMonorail
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
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;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawingMonorail"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawingMonorail drawingMonorail)
{
string[]? array = drawingMonorail?.EntityMonorail?.GetStringRepresention();
if (array == null)
return string.Empty;
return string.Join(_separatorForObject, array);
}
}
}

View File

@ -40,5 +40,26 @@
MonorailTrack = monorailTrack; MonorailTrack = monorailTrack;
Cabin = cabin; Cabin = cabin;
} }
/// <summary>
/// Получение строк с значениями свойств объекта класса-сущности
/// </summary>
/// <returns></returns>
public override string[] GetStringRepresention()
{
return new string[] { nameof(EntityModernMonorail), Speed.ToString(), Weight.ToString(), BodyColor.Name.ToString(), AdditionalColor.Name.ToString(), MonorailTrack.ToString(), Cabin.ToString()};
}
/// <summary>
/// Создание объекта из массива строк
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
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]));
}
} }
} }

View File

@ -42,5 +42,26 @@
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
/// <summary>
/// Получение строк с значениями свойств объекта класса-сущности
/// </summary>
/// <returns></returns>
public virtual string[] GetStringRepresention()
{
return new string[] { nameof(EntityMonorail), Speed.ToString(), Weight.ToString(), BodyColor.Name.ToString() };
}
/// <summary>
/// Создание объекта из массива строк
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
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]));
}
} }
} }