diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/AbstractCompany.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/AbstractCompany.cs
index cf6e208..de42684 100644
--- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/AbstractCompany.cs
@@ -48,7 +48,7 @@ public abstract class AbstractCompany
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
- _collection.SetMaxCount = GetMaxCount;
+ _collection.MaxCount = GetMaxCount;
}
///
diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs
index e0f246d..18a2d07 100644
--- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -13,9 +13,9 @@ public interface ICollectionGenericObjects
int Count { get; }
///
- /// Установка максимального количества элементов
- ///
- int SetMaxCount { set; }
+ /// Установка максимального количества элементов
+ ///
+ int MaxCount { get; set; }
///
/// Добавление объекта в коллекцию
@@ -45,4 +45,15 @@ public interface ICollectionGenericObjects
/// Позиция
/// Объект
T? Get(int position);
+
+ ///
+ /// Получение типа коллекции
+ ///
+ CollectionType GetCollectionType { get; }
+
+ ///
+ /// Получение объектов коллекции по одному
+ ///
+ /// Поэлементый вывод элементов коллекции
+ IEnumerable GetItems();
}
diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs
index 817e959..220fad8 100644
--- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/ListGenericObjects.cs
@@ -12,19 +12,30 @@ public class ListGenericObjects : ICollectionGenericObjects
///
private readonly List _collection;
- ///
- /// Максимально допустимое число объектов в списке
- ///
- private int _maxCount;
+ ///
+ /// Максимально допустимое число объектов в списке
+ ///
+ private int _maxCount;
- public int Count => _collection.Count;
+ public int Count => _collection.Count;
- public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
+ public int MaxCount
+ {
+ get => _maxCount;
+ set
+ {
+ if (value > 0)
+ {
+ _maxCount = value;
+ }
+ }
+ }
+ public CollectionType GetCollectionType => CollectionType.List;
- ///
- /// Конструктор
- ///
- public ListGenericObjects()
+ ///
+ /// Конструктор
+ ///
+ public ListGenericObjects()
{
_collection = new();
}
@@ -84,4 +95,12 @@ public class ListGenericObjects : ICollectionGenericObjects
}
+
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Count; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs
index 1831f84..c3bd8fd 100644
--- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -14,8 +14,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public int Count => _collection.Length;
- public int SetMaxCount
+ public int MaxCount
{
+ get
+ {
+ return _collection.Length;
+ }
set
{
if (value > 0)
@@ -32,6 +36,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
}
+ public CollectionType GetCollectionType => CollectionType.Massive;
+
///
/// Конструктор
///
@@ -118,4 +124,11 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return obj;
}
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Length; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
}
diff --git a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/StorageCollection.cs b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/StorageCollection.cs
index 128c57e..f539dc8 100644
--- a/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectExcavator/ProjectExcavator/CollectionGenericObjects/StorageCollection.cs
@@ -1,4 +1,6 @@
-using System.Collections.Generic;
+using ProjectExcavator.Drawnings;
+using System.Collections.Generic;
+using System.Text;
using System.Xml.Linq;
namespace ProjectExcavator.CollectionGenericObjects;
@@ -8,18 +10,35 @@ namespace ProjectExcavator.CollectionGenericObjects;
///
///
public class StorageCollection
- where T : class
+ where T : DrawningTrackedVehicle
{
- ///
+ ///
/// Словарь (хранилище) с коллекциями
///
readonly Dictionary> _storages;
- ///
- /// Возвращение списка названий коллекций
- ///
- public List Keys => _storages.Keys.ToList();
-
+
+ ///
+ /// Возвращение списка названий коллекций
+ ///
+ public List Keys => _storages.Keys.ToList();
+
+ ///
+ /// Ключевое слово, с которого должен начинаться файл
+ ///
+ private readonly string _collectionKey = "CollectionsStorage";
+
+ ///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private readonly string _separatorForKeyValue = "|";
+
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly string _separatorItems = ";";
+
+
///
/// Конструктор
///
@@ -79,4 +98,146 @@ public class StorageCollection
return _storages[name];
}
}
+
+ ///
+ /// Сохранение информации по автомобилям в хранилище в файл
+ ///
+ /// Путь и имя файла
+ /// 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 (StreamWriter fs = new StreamWriter(filename))
+ {
+ fs.WriteLine(_collectionKey.ToString());
+ foreach (KeyValuePair> kvpair in _storages)
+ {
+ // не сохраняем пустые коллекции
+ if (kvpair.Value.Count == 0)
+ continue;
+ sb.Append(kvpair.Key);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(kvpair.Value.GetCollectionType);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(kvpair.Value.MaxCount);
+ sb.Append(_separatorForKeyValue);
+ foreach (T? item in kvpair.Value.GetItems())
+ {
+ string data = item?.GetDataForSave() ?? string.Empty;
+ if (string.IsNullOrEmpty(data))
+ continue;
+ sb.Append(data);
+ sb.Append(_separatorItems);
+ }
+ fs.WriteLine(sb.ToString());
+ sb.Clear();
+ }
+ }
+ return true;
+ }
+
+ ///
+ /// Загрузка информации по автомобилям в хранилище из файла
+ ///
+ /// Путь и имя файла
+ /// true - загрузка прошла успешно, false - ошибка при загрузке данных
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader sr = new StreamReader(filename))
+ {
+ string? str;
+ str = sr.ReadLine();
+ if (str != _collectionKey.ToString())
+ return false;
+ _storages.Clear();
+ while ((str = sr.ReadLine()) != null)
+ {
+ string[] record = str.Split(_separatorForKeyValue);
+ 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?.CreateDrawningTrackedVehicle() is T boat)
+ {
+ if (collection.Insert(boat) == -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/ProjectExcavator/ProjectExcavator/Drawnings/DrawningExcavator.cs b/ProjectExcavator/ProjectExcavator/Drawnings/DrawningExcavator.cs
index fef274d..5826f76 100644
--- a/ProjectExcavator/ProjectExcavator/Drawnings/DrawningExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/Drawnings/DrawningExcavator.cs
@@ -16,10 +16,20 @@ public class DrawningExcavator : DrawningTrackedVehicle
/// Дополнительный цвет
/// Признак наличия ковша
/// Признак наличия поддержки
- public DrawningExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports) : base(135, 82)
+ public DrawningExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports) : base(125, 60)
{
EntityTrackedVehicle = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, supports);
}
+ /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах
+
+ ///
+ /// Конструктор через сущность
+ ///
+ /// Объект класса-сущность
+ public DrawningExcavator(EntityTrackedVehicle trackedVehicle) : base(125,60)
+ {
+ EntityTrackedVehicle = trackedVehicle;
+ }
public override void DrawTransport(Graphics g)
{
diff --git a/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs b/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs
index 3811e37..2124ce8 100644
--- a/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs
+++ b/ProjectExcavator/ProjectExcavator/Drawnings/DrawningTrackedVehicle.cs
@@ -35,12 +35,12 @@ public class DrawningTrackedVehicle
///
/// Ширина прорисовки гусеничной машины
///
- private readonly int _drawningExcavatorWidth = 78;
+ private readonly int _drawningTrackedVehicleWidth = 78;
///
/// Высота прорисовки гусеничной машины
///
- private readonly int _drawningExcavatorHeight = 63;
+ private readonly int _drawningTrackedVehicleHeight = 63;
///
/// Координата X объекта
@@ -55,17 +55,17 @@ public class DrawningTrackedVehicle
///
/// Ширина объекта
///
- public int GetWidth => _drawningExcavatorWidth;
+ public int GetWidth => _drawningTrackedVehicleWidth;
///
/// Высота объекта
///
- public int GetHeight => _drawningExcavatorHeight;
+ public int GetHeight => _drawningTrackedVehicleHeight;
///
/// Пустой конструктор
///
- private DrawningTrackedVehicle()
+ protected DrawningTrackedVehicle()
{
_pictureWidth = null;
_pictureHeight = null;
@@ -84,6 +84,15 @@ public class DrawningTrackedVehicle
EntityTrackedVehicle = new EntityTrackedVehicle(speed, weight, bodyColor);
}
+ ///
+ /// Конструктор
+ ///
+ /// Класс-сущность
+ public DrawningTrackedVehicle(EntityTrackedVehicle trackedVehicle) : base()
+ {
+ EntityTrackedVehicle = trackedVehicle;
+ }
+
///
/// Конструктор для наследников
///
@@ -91,8 +100,8 @@ public class DrawningTrackedVehicle
/// Высота прорисовки гусеничной машины
protected DrawningTrackedVehicle(int drawningExcavatorWidth, int drawningExcavatorHeight) : this()
{
- _drawningExcavatorWidth = drawningExcavatorWidth;
- _drawningExcavatorHeight = drawningExcavatorHeight;
+ _drawningTrackedVehicleWidth = drawningExcavatorWidth;
+ _drawningTrackedVehicleHeight = drawningExcavatorHeight;
}
///
@@ -104,7 +113,7 @@ public class DrawningTrackedVehicle
public bool SetPictureSize(int width, int height)
{
//проверка, что объект "влезает" в размеры поля
- if (_drawningExcavatorWidth > width || _drawningExcavatorHeight > height)
+ if (_drawningTrackedVehicleWidth > width || _drawningTrackedVehicleHeight > height)
{
EntityTrackedVehicle = null;
return false;
@@ -116,14 +125,14 @@ public class DrawningTrackedVehicle
_pictureWidth = width;
_pictureHeight = height;
- if (_startPosX.HasValue && (_startPosX.Value + _drawningExcavatorWidth > _pictureWidth))
+ if (_startPosX.HasValue && (_startPosX.Value + _drawningTrackedVehicleWidth > _pictureWidth))
{
- _startPosX = _pictureWidth - _drawningExcavatorWidth;
+ _startPosX = _pictureWidth - _drawningTrackedVehicleWidth;
}
- if (_startPosY.HasValue && (_startPosY + _drawningExcavatorHeight > _pictureHeight))
+ if (_startPosY.HasValue && (_startPosY + _drawningTrackedVehicleHeight > _pictureHeight))
{
- _startPosY = _pictureHeight - _drawningExcavatorHeight;
+ _startPosY = _pictureHeight - _drawningTrackedVehicleHeight;
}
return true;
@@ -141,9 +150,9 @@ public class DrawningTrackedVehicle
// то надо изменить координаты, чтобы он оставался в этих границах
_startPosX = x;
_startPosY = y;
- if (_startPosX + _drawningExcavatorWidth > _pictureWidth)
+ if (_startPosX + _drawningTrackedVehicleWidth > _pictureWidth)
{
- _startPosX = _pictureWidth - _drawningExcavatorWidth;
+ _startPosX = _pictureWidth - _drawningTrackedVehicleWidth;
}
if (_startPosX < 0)
@@ -151,9 +160,9 @@ public class DrawningTrackedVehicle
_startPosX = 0;
}
- if (_startPosY + _drawningExcavatorHeight > _pictureHeight)
+ if (_startPosY + _drawningTrackedVehicleHeight > _pictureHeight)
{
- _startPosY = _pictureHeight - _drawningExcavatorHeight;
+ _startPosY = _pictureHeight - _drawningTrackedVehicleHeight;
}
if (_startPosY < 0)
@@ -192,14 +201,14 @@ public class DrawningTrackedVehicle
return true;
// вправо
case DirectionType.Right:
- if (_startPosX.Value + EntityTrackedVehicle.Step < _pictureWidth - _drawningExcavatorWidth)
+ if (_startPosX.Value + EntityTrackedVehicle.Step < _pictureWidth - _drawningTrackedVehicleWidth)
{
_startPosX += (int)EntityTrackedVehicle.Step;
}
return true;
//вниз
case DirectionType.Down:
- if (_startPosY.Value + EntityTrackedVehicle.Step < _pictureHeight - _drawningExcavatorHeight)
+ if (_startPosY.Value + EntityTrackedVehicle.Step < _pictureHeight - _drawningTrackedVehicleHeight)
{
_startPosY += (int)EntityTrackedVehicle.Step;
}
diff --git a/ProjectExcavator/ProjectExcavator/Drawnings/ExtentionDrawningTrackedVehicle.cs b/ProjectExcavator/ProjectExcavator/Drawnings/ExtentionDrawningTrackedVehicle.cs
new file mode 100644
index 0000000..fc4c3b2
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/Drawnings/ExtentionDrawningTrackedVehicle.cs
@@ -0,0 +1,53 @@
+using ProjectExcavator.Drawnings;
+using ProjectExcavator.Entities;
+
+///
+/// Расширение для класса TrackedVehicle
+///
+public static class ExtentionDrawningTrackedVehicle
+{
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly string _separatorForObject = ":";
+
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка с данными для создания объекта
+ /// Объект
+ public static DrawningTrackedVehicle? CreateDrawningTrackedVehicle(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ EntityTrackedVehicle? trackedVehicle = EntityExcavator.CreateEntityExcavator(strs);
+ if (trackedVehicle != null)
+ {
+ return new DrawningExcavator(trackedVehicle);
+ }
+
+ trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
+ if (trackedVehicle != null)
+ {
+ return new DrawningTrackedVehicle(trackedVehicle);
+ }
+
+ return null;
+ }
+
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ /// Сохраняемый объект
+ /// Строка с данными по объекту
+ public static string GetDataForSave(this DrawningTrackedVehicle drawningTrackedVehicle)
+ {
+ string[]? array = drawningTrackedVehicle?.EntityTrackedVehicle?.GetStringRepresentation();
+
+ if (array == null)
+ {
+ return string.Empty;
+ }
+
+ return string.Join(_separatorForObject, array);
+ }
+}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs b/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs
index 0325a92..3f74103 100644
--- a/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/Entities/EntityExcavator.cs
@@ -1,4 +1,7 @@
-namespace ProjectExcavator.Entities;
+using System.ComponentModel;
+using System.Net.Sockets;
+
+namespace ProjectExcavator.Entities;
///
/// Класс-сущность "Экскаватор"
@@ -42,4 +45,28 @@ public class EntityExcavator : EntityTrackedVehicle
Bucket = bucket;
Supports = supports;
}
+
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public override string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityExcavator), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Bucket.ToString(), Supports.ToString()};
+ }
+
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityExcavator? CreateEntityExcavator(string[] strs)
+ {
+ if (strs.Length != 7 || strs[0] != nameof(EntityExcavator))
+ {
+ return null;
+ }
+ return new EntityExcavator(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
+ }
+
}
diff --git a/ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs b/ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs
index 3e173d2..5855e5a 100644
--- a/ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs
+++ b/ProjectExcavator/ProjectExcavator/Entities/EntityTrackedVehicle.cs
@@ -43,4 +43,27 @@ public class EntityTrackedVehicle
Weight = weight;
BodyColor = bodyColor;
}
+
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public virtual string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityTrackedVehicle), Speed.ToString(), Weight.ToString(), BodyColor.Name };
+ }
+
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityTrackedVehicle? CreateEntityTrackedVehicle(string[] strs)
+ {
+ if (strs.Length != 4 || strs[0] != nameof(EntityTrackedVehicle))
+ {
+ return null;
+ }
+ return new EntityTrackedVehicle(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
+ }
}
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
index 4f676fa..a27b209 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.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(777, 0);
+ groupBoxTools.Location = new Point(777, 28);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(225, 639);
+ groupBoxTools.Size = new Size(225, 646);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -251,19 +258,63 @@
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
- pictureBox.Location = new Point(0, 0);
+ pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(777, 639);
+ pictureBox.Size = new Size(777, 646);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // menuStrip
+ //
+ menuStrip.ImageScalingSize = new Size(20, 20);
+ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
+ menuStrip.Location = new Point(0, 0);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Size = new Size(1002, 28);
+ menuStrip.TabIndex = 2;
+ menuStrip.Text = "menuStrip1";
+ //
+ // файлToolStripMenuItem
+ //
+ файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
+ файлToolStripMenuItem.Name = "файлToolStripMenuItem";
+ файлToolStripMenuItem.Size = new Size(59, 24);
+ файлToolStripMenuItem.Text = "Файл";
+ //
+ // saveToolStripMenuItem
+ //
+ saveToolStripMenuItem.Name = "saveToolStripMenuItem";
+ saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
+ saveToolStripMenuItem.Size = new Size(227, 26);
+ saveToolStripMenuItem.Text = "Сохранение";
+ saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
+ //
+ // loadToolStripMenuItem
+ //
+ loadToolStripMenuItem.Name = "loadToolStripMenuItem";
+ loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
+ loadToolStripMenuItem.Size = new Size(227, 26);
+ loadToolStripMenuItem.Text = "Загрузка";
+ loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
+ //
+ // saveFileDialog
+ //
+ saveFileDialog.Filter = "txt file | *.txt";
+ //
+ // openFileDialog
+ //
+ openFileDialog.FileName = "openFileDialog1";
+ openFileDialog.Filter = "txt file | *.txt";
+ //
// FormExcavatorCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1002, 639);
+ ClientSize = new Size(1002, 674);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
+ Controls.Add(menuStrip);
+ MainMenuStrip = menuStrip;
Name = "FormExcavatorCollection";
Text = "Коллекция экскаваторов";
groupBoxTools.ResumeLayout(false);
@@ -272,7 +323,10 @@
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
ResumeLayout(false);
+ PerformLayout();
}
#endregion
@@ -295,5 +349,11 @@
private Button buttonCollectionDel;
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/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
index 37ef523..58dc318 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
@@ -1,5 +1,6 @@
using ProjectExcavator.CollectionGenericObjects;
using ProjectExcavator.Drawnings;
+using System.Windows.Forms;
namespace ProjectExcavator;
///
@@ -46,9 +47,9 @@ public partial class FormExcavatorCollection : Form
///
///
///
- private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) {
+ private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e)
+ {
FormExcavatorConfig form = new();
- // TODO передать метод(c)
form.Show();
form.AddEvent(SetTrackedVehicle);
}
@@ -179,7 +180,7 @@ public partial class FormExcavatorCollection : Form
}
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
- RerfreshListBoxItems();
+ RefreshListBoxItems();
}
@@ -201,13 +202,13 @@ public partial class FormExcavatorCollection : Form
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
- RerfreshListBoxItems();
+ RefreshListBoxItems();
}
///
/// Обновление списка в listBoxCollection
///
- private void RerfreshListBoxItems()
+ private void RefreshListBoxItems()
{
listBoxCollection.Items.Clear();
@@ -250,7 +251,47 @@ public partial class FormExcavatorCollection : Form
}
panelCompanyTools.Enabled = true;
- RerfreshListBoxItems();
+ RefreshListBoxItems();
}
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ ///
+ 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))
+ {
+ RefreshListBoxItems();
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Загрузка не выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
index af32865..5e23909 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
@@ -117,4 +117,16 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 145, 17
+
+
+ 310, 17
+
+
+ 62
+
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs
index e0eabf4..d027f7b 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorConfig.cs
@@ -35,7 +35,7 @@ public partial class FormExcavatorConfig : Form
panelBlack.MouseDown += Panel_MouseDown;
panelPurple.MouseDown += Panel_MouseDown;
- // TODO buttonCancel.Click привязать анонимный метод через lambda с закрытием формы(c)
+ // buttonCancel.Click привязать анонимный метод через lambda с закрытием формы(c)
buttonCancel.Click += (sender, e) => Close();
}
@@ -49,7 +49,6 @@ public partial class FormExcavatorConfig : Form
_trackedVehicleDelegate += excavatorDelegate;
}
-
///
/// Прорисовка объекта
///