Лабораторная работа №6
This commit is contained in:
parent
dfa2816ba9
commit
e1cc1e40ad
68
ProjectMonorail/FormMonorailCollection.Designer.cs
generated
68
ProjectMonorail/FormMonorailCollection.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
@ -202,5 +202,46 @@ namespace ProjectMonorail
|
||||
panelCompanyTools.Enabled = true;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</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>
|
@ -48,7 +48,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
_collection.MaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -70,7 +70,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// <returns></returns>
|
||||
public static DrawingMonorail operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position) ?? null;
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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<DrawingMonorail> collection) : base(pictureWidth, pictureHeight, collection) {}
|
||||
|
||||
private int maxCountX;
|
||||
private int maxCountY;
|
||||
private int offsetX = 30;
|
||||
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
|
@ -17,7 +17,7 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
int MaxCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
@ -48,5 +48,15 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение типа коллекции
|
||||
/// </summary>
|
||||
CollectionType GetCollectionType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции по одному
|
||||
/// </summary>
|
||||
/// <returns>Поэлементный вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
|
||||
namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
@ -19,7 +20,12 @@
|
||||
|
||||
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>
|
||||
/// Конструктор
|
||||
@ -72,5 +78,13 @@
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection.Count; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -108,5 +114,12 @@ namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects
|
||||
return true;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection.Length; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class StorageCollection<T>
|
||||
where T : class
|
||||
where T : DrawingMonorail
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с коллекциями
|
||||
@ -17,6 +21,21 @@
|
||||
/// </summary>
|
||||
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>
|
||||
@ -34,10 +53,11 @@
|
||||
{
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
if (!_storages.ContainsKey(name)) {
|
||||
if (!_storages.ContainsKey(name))
|
||||
{
|
||||
ICollectionGenericObjects<T> collection;
|
||||
|
||||
switch(collectionType)
|
||||
switch (collectionType)
|
||||
{
|
||||
case CollectionType.List:
|
||||
collection = new ListGenericObjects<T>();
|
||||
@ -79,5 +99,132 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
/// </summary>
|
||||
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>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -40,5 +40,26 @@
|
||||
MonorailTrack = monorailTrack;
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,5 +42,26 @@
|
||||
Weight = weight;
|
||||
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]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user