diff --git a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/AbstractCompany.cs b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/AbstractCompany.cs
index 2ec4ac9..5105be1 100644
--- a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/AbstractCompany.cs
+++ b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/AbstractCompany.cs
@@ -45,7 +45,7 @@ private int GetMaxCount => _pictureWidth * _pictureHeight /(_placeSizeWidth * _p
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
- _collection.SetMaxCount = GetMaxCount;
+ _collection.MaxCount = GetMaxCount;
}
///
/// Перегрузка оператора сложения для класса
diff --git a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ICollectionGenericObjects.cs b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ICollectionGenericObjects.cs
index 1c7f803..166273f 100644
--- a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -11,16 +11,17 @@ public interface ICollectionGenericObjects
{///Количество объектов в коллекции
///
int Count { get; }
+
///
/// Установка максимального количества элементов
///
- int SetMaxCount { set; }
+ int MaxCount { get; set; }
///
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
@@ -40,4 +41,14 @@ int Insert(T obj, int position);
/// Позиция
/// Объект
T? Get(int position);
+
+ ///
+ /// Получение типа коллекции
+ ///
+ CollectionType GetCollectionType { get; }
+ ///
+ /// Получение объектов коллекции по одному
+ ///
+ /// Поэлементый вывод элементов коллекции
+ IEnumerable GetItems();
}
diff --git a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ListGenericObjects.cs b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ListGenericObjects.cs
index 7db938b..e9c1a10 100644
--- a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ListGenericObjects.cs
+++ b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/ListGenericObjects.cs
@@ -16,9 +16,20 @@ public class ListGenericObjects : ICollectionGenericObjects
/// Максимально допустимое число объектов в списке
///
private int _maxCount;
+ public int MaxCount
+ {
+ get => _maxCount;
+ set
+ {
+ if (value > 0)
+ {
+ _maxCount = value;
+ }
+ }
+ }
public int Count => _collection.Count;
- public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
- public int MaxCount => _maxCount;
+
+ public CollectionType GetCollectionType => CollectionType.List;
///
/// Конструктор
@@ -68,5 +79,14 @@ public class ListGenericObjects : ICollectionGenericObjects
return obj;
}
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Count; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
+
}
+
diff --git a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/MassiveGenericObjects.cs b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/MassiveGenericObjects.cs
index 4b7ac38..a661f5f 100644
--- a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -16,8 +16,12 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
public int Count => _collection.Length;
- public int SetMaxCount
+ public int MaxCount
{
+ get
+ {
+ return _collection.Length;
+ }
set
{
if (value > 0)
@@ -34,6 +38,8 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
}
}
+ public CollectionType GetCollectionType => CollectionType.Massive;
+
///
/// Конструктор
///
@@ -110,4 +116,11 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
return temp;
}
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Length; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
}
diff --git a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/StorageCollection.cs b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/StorageCollection.cs
index dc393ec..5586c45 100644
--- a/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/StorageCollection.cs
+++ b/TrolleybusProject/TrolleybusProject/CollectionGenericObjects/StorageCollection.cs
@@ -3,23 +3,42 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using TrolleybusProject.Drawnings;
namespace TrolleybusProject.CollectionGenericObjects;
public class StorageCollection
- where T : class
+ where T :DrawningBus
{
+
///
/// Словарь (хранилище) с коллекциями
///
readonly Dictionary> _storages;
+
///
/// Возвращение списка названий коллекций
///
public List Keys => _storages.Keys.ToList();
+
+ ///
+ /// Ключевое слово, с которого должен начинаться файл
+ ///
+ private readonly string _collectionKey = "CollectionsStorage";
+ ///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private readonly string _separatorForKeyValue = "|";
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly string _separatorItems = ";";
+
+
///
/// Конструктор
///
+ ///
public StorageCollection()
{
_storages = new Dictionary>();
@@ -70,6 +89,117 @@ public class StorageCollection
return _storages[name];
}
}
+
+ public bool SaveData(string filename)
+ {
+ if (_storages.Count == 0)
+ {
+ return false;
+ }
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ using (StreamWriter writer = new(filename))
+ {
+ writer.Write(_collectionKey);
+ foreach (KeyValuePair> value in _storages)
+ {
+ writer.Write(Environment.NewLine);
+ // не сохраняем пустые коллекции
+ if (value.Value.Count == 0)
+ {
+ continue;
+ }
+ writer.Write(value.Key);
+ writer.Write(_separatorForKeyValue);
+ writer.Write(value.Value.GetCollectionType);
+ writer.Write(_separatorForKeyValue);
+ writer.Write(value.Value.MaxCount);
+ writer.Write(_separatorForKeyValue);
+
+ foreach (T? item in value.Value.GetItems())
+ {
+ string data = item?.GetDataForSave() ?? string.Empty;
+ if (string.IsNullOrEmpty(data))
+ {
+ continue;
+ }
+ writer.Write(data);
+ writer.Write(_separatorItems);
+ }
+ }
+ }
+ return true;
+ }
+
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader reader = new(filename))
+ {
+ string line = reader.ReadLine();
+ if (line == null || line.Length == 0)
+ {
+ return false;
+ }
+ if (!line.Equals(_collectionKey))
+ {
+ return false;
+ }
+ _storages.Clear();
+ while ((line = reader.ReadLine()) != null)
+ {
+ string[] record = line.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?.CreateDrawningBus() is T bus)
+ {
+ if (collection.Insert(bus) <0)
+ {
+ 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,
+ };
+ }
+
}
diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs
index d84bcad..19b3f92 100644
--- a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs
+++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningBus.cs
@@ -33,11 +33,11 @@ public class DrawningBus
///
/// Ширина прорисовки троллейбуса
///
- public readonly int _drawningBusWidth = 150;
+ private readonly int _drawningBusWidth = 150;
///
/// Высота прорисовки троллейбуса
///
- public readonly int _drawningBusHeight = 86;
+ private readonly int _drawningBusHeight = 86;
///
/// Координата X объекта
///
@@ -55,12 +55,10 @@ public class DrawningBus
///
public int GetHeight => _drawningBusHeight;
-
-
///
/// Конструктор пустой
///
- private DrawningBus()
+ public DrawningBus()
{
_pictureWidth = null;
_pictureHeight = null;
@@ -68,9 +66,6 @@ public class DrawningBus
_startPosY = null;
}
-
-
-
///
/// Конструктор
///
@@ -84,14 +79,12 @@ public class DrawningBus
}
-
///
/// Конструктор для наследников
///
/// Ширина прорисовки автобуса
/// Высота прорисовки автобуса
-
protected DrawningBus(int drawningBusWidth, int drawningBusHeight) : this()
{
_drawningBusWidth= drawningBusWidth;
@@ -99,10 +92,13 @@ public class DrawningBus
}
-
-
-
-
+ public DrawningBus(EntityBus? entityBus)
+ {
+ if (entityBus != null)
+ {
+ EntityBus = entityBus;
+ }
+ }
///
/// Установка границ поля
@@ -117,23 +113,17 @@ public class DrawningBus
_pictureWidth = width;
_pictureHeight = height;
-
-
if (_startPosY.HasValue && _startPosX.HasValue)
{
if (_startPosX + _drawningBusWidth > width)
{
-
_startPosX = width - _drawningBusWidth;
-
}
if (_startPosY + _drawningBusHeight > height)
{
-
_startPosY = height - _drawningBusHeight;
-
}
if (_startPosX < 0)
{
@@ -144,20 +134,11 @@ public class DrawningBus
_startPosY = 0;
}
-
-
}
-
-
return true;
}
-
-
-
-
-
return false;
}
///
@@ -171,13 +152,9 @@ public class DrawningBus
{
return;
}
-
-
_startPosX = x;
_startPosY = y;
-
-
if (_startPosX < 0)
{ _startPosX = 0; }
if (_startPosY < 0)
@@ -185,20 +162,15 @@ public class DrawningBus
if (x + _drawningBusWidth > _pictureWidth)
{
-
_startPosX = _pictureWidth - _drawningBusWidth;
-
}
if (y + _drawningBusHeight > _pictureHeight)
{
-
_startPosY = _pictureHeight - _drawningBusHeight;
-
}
-
}
///
/// Изменение направления перемещения
@@ -259,30 +231,21 @@ public class DrawningBus
return;
}
Pen pen = new(Color.Black);
-
-
Brush brushBodyColor = new SolidBrush(EntityBus.BodyColor);
-
- //троллейбус границы
+ //троллейбус границы
g.DrawEllipse(pen, _startPosX.Value + 22, _startPosY.Value +
42, 20, 20);
g.DrawEllipse(pen, _startPosX.Value + 104, _startPosY.Value +
42, 20, 20);
-
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value +
8, 140, 41);
-
-
//троллейбус
g.FillRectangle(brushBodyColor, _startPosX.Value + 5, _startPosY.Value +
8, 140, 41);
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value +
8, 140, 41);
-
-
-
//дверь
g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value +
18, 24, 31);
@@ -308,14 +271,6 @@ public class DrawningBus
g.FillEllipse(brBlue, _startPosX.Value + 129, _startPosY.Value +
12, 15, 20);
-
-
-
-
-
-
-
-
g.DrawEllipse(pen, _startPosX.Value + 8, _startPosY.Value +
12, 15, 20);
@@ -333,19 +288,5 @@ public class DrawningBus
12, 15, 20);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
}
}
diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs
index 3e3c86b..67f048e 100644
--- a/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs
+++ b/TrolleybusProject/TrolleybusProject/Drawnings/DrawningTrolleybus.cs
@@ -28,7 +28,13 @@ public class DrawningTrolleybus:DrawningBus
doors, roga, otsek);
}
-
+ public DrawningTrolleybus(EntityBus? entityBus)
+ {
+ if (entityBus != null)
+ {
+ EntityBus = entityBus;
+ }
+ }
public override void DrawTransport(Graphics g)
{
if (EntityBus == null || EntityBus is not EntityTrolleybus trolleybus|| !_startPosX.HasValue ||
diff --git a/TrolleybusProject/TrolleybusProject/Drawnings/ExtentionDrawningBus.cs b/TrolleybusProject/TrolleybusProject/Drawnings/ExtentionDrawningBus.cs
new file mode 100644
index 0000000..9d66f43
--- /dev/null
+++ b/TrolleybusProject/TrolleybusProject/Drawnings/ExtentionDrawningBus.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using TrolleybusProject.Entities;
+
+namespace TrolleybusProject.Drawnings {
+
+ public static class ExtentionDrawningBus
+ {
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly string _separatorForObject = ":";
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка с данными для создания объекта
+ /// Объект
+ public static DrawningBus? CreateDrawningBus(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ EntityBus? bus = EntityTrolleybus.CreateEntityTrolleybus(strs);
+ if (bus != null)
+ {
+ return new DrawningTrolleybus(bus);
+ }
+ bus = EntityBus.CreateEntityBus(strs);
+ if (bus != null)
+ {
+ return new DrawningBus(bus);
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ /// Сохраняемый объект
+ /// Строка с данными по объекту
+ public static string GetDataForSave(this DrawningBus drawningBus)
+ {
+ string[]? array = drawningBus?.EntityBus?.GetStringRepresentation();
+ if (array == null)
+ {
+ return string.Empty;
+ }
+ return string.Join(_separatorForObject, array);
+ }
+
+
+
+
+ }
+
+}
diff --git a/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs b/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs
index 84b2ebe..5f99f88 100644
--- a/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs
+++ b/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs
@@ -7,12 +7,6 @@ using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
-
-
-
-
-
-
namespace TrolleybusProject.Entities;
///
@@ -54,4 +48,33 @@ public class EntityBus
BodyColor = bodyColor;
}
+
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public virtual string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityBus), Speed.ToString(),Weight.ToString(), BodyColor.Name };
+ }
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityBus? CreateEntityBus(string[] strs)
+ {
+ if (strs.Length != 4 || strs[0] != nameof(EntityBus))
+ {
+ return null;
+ }
+ return new EntityBus(Convert.ToInt32(strs[1]),
+ Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
+ }
}
+
+
+
+
+
+
diff --git a/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs
index dd3ef67..0b0e706 100644
--- a/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs
+++ b/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace TrolleybusProject.Entities;
@@ -57,7 +58,22 @@ public class EntityTrolleybus: EntityBus
Doors = doors;
}
+ public override string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityTrolleybus), Speed.ToString(), Weight.ToString(), BodyColor.Name,
+ AdditionalColor.Name, Roga.ToString(),Otsek.ToString(),Doors.ToString() };
+ }
+ public static EntityTrolleybus? CreateEntityTrolleybus(string[] strs)
+ {
+ if (strs.Length != 8 || strs[0] != nameof(EntityTrolleybus))
+ {
+ return null;
+ }
+
+ return new EntityTrolleybus(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]),
+ Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7]));
+ }
diff --git a/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs b/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs
index 75caab5..74448a6 100644
--- a/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs
+++ b/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs
@@ -46,10 +46,20 @@
labelCollectionName = new Label();
comboBoxSelectionCompany = new ComboBox();
pictureBox = new PictureBox();
+ menuStrip = new MenuStrip();
+ FileToolStripMenuItem = new ToolStripMenuItem();
+ файлToolStripMenuItem = new ToolStripMenuItem();
+ save_ToolStripMenuItem = new ToolStripMenuItem();
+ load_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 +69,9 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectionCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(904, 0);
+ groupBoxTools.Location = new Point(904, 33);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(300, 656);
+ groupBoxTools.Size = new Size(300, 623);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -92,7 +102,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(24, 215);
+ buttonRefresh.Location = new Point(26, 175);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(246, 34);
buttonRefresh.TabIndex = 6;
@@ -103,7 +113,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(24, 175);
+ buttonGoToCheck.Location = new Point(26, 135);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(246, 34);
buttonGoToCheck.TabIndex = 5;
@@ -125,7 +135,7 @@
// buttonDelTrolleybus
//
buttonDelTrolleybus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonDelTrolleybus.Location = new Point(22, 135);
+ buttonDelTrolleybus.Location = new Point(26, 95);
buttonDelTrolleybus.Name = "buttonDelTrolleybus";
buttonDelTrolleybus.Size = new Size(244, 34);
buttonDelTrolleybus.TabIndex = 4;
@@ -135,7 +145,7 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(68, 98);
+ maskedTextBox.Location = new Point(68, 58);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(150, 31);
@@ -238,12 +248,73 @@
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
- pictureBox.Location = new Point(0, 0);
+ pictureBox.Location = new Point(0, 33);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(904, 656);
+ pictureBox.Size = new Size(904, 623);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // menuStrip
+ //
+ menuStrip.ImageScalingSize = new Size(24, 24);
+ menuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem, файлToolStripMenuItem });
+ menuStrip.Location = new Point(0, 0);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Size = new Size(1204, 33);
+ menuStrip.TabIndex = 2;
+ menuStrip.Text = "Фаил";
+
+ //
+ // FileToolStripMenuItem
+ //
+ FileToolStripMenuItem.Name = "FileToolStripMenuItem";
+ FileToolStripMenuItem.Size = new Size(16, 29);
+ //
+ // файлToolStripMenuItem
+ //
+ файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { save_ToolStripMenuItem, load_ToolStripMenuItem });
+ файлToolStripMenuItem.Name = "файлToolStripMenuItem";
+ файлToolStripMenuItem.Size = new Size(69, 29);
+ файлToolStripMenuItem.Text = "Фаил";
+ //
+ // save_ToolStripMenuItem
+ //
+ save_ToolStripMenuItem.Name = "save_ToolStripMenuItem";
+ save_ToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
+ save_ToolStripMenuItem.Size = new Size(270, 34);
+ save_ToolStripMenuItem.Text = "Сохранить";
+ save_ToolStripMenuItem.Click += save_ToolStripMenuItem_Click;
+ //
+ // load_ToolStripMenuItem
+ //
+ load_ToolStripMenuItem.Name = "load_ToolStripMenuItem";
+ load_ToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
+ load_ToolStripMenuItem.Size = new Size(270, 34);
+ load_ToolStripMenuItem.Text = "Загрузить";
+ load_ToolStripMenuItem.Click += load_ToolStripMenuItem_Click;
+ //
+ // SaveToolStripMenuItem
+ //
+ SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
+ SaveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
+ SaveToolStripMenuItem.Size = new Size(273, 34);
+ SaveToolStripMenuItem.Text = "Сохранение";
+ //
+ // LoadToolStripMenuItem
+ //
+ LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
+ LoadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
+ LoadToolStripMenuItem.Size = new Size(273, 34);
+ LoadToolStripMenuItem.Text = "Загрузка";
+ //
+ // saveFileDialog
+ //
+ saveFileDialog.Filter = "txt file | *.txt";
+ //
+ // openFileDialog
+ //
+ openFileDialog.Filter = "txt file | *.txt";
+ //
// FormBusCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
@@ -251,6 +322,8 @@
ClientSize = new Size(1204, 656);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
+ Controls.Add(menuStrip);
+ MainMenuStrip = menuStrip;
Name = "FormBusCollection";
Text = "Коллекция автобусов";
groupBoxTools.ResumeLayout(false);
@@ -259,7 +332,10 @@
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
ResumeLayout(false);
+ PerformLayout();
}
#endregion
@@ -282,5 +358,14 @@
private Button buttonCreateCompany;
private Button buttonCollectionDel;
private Panel panelCompanyTools;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem FileToolStripMenuItem;
+ private ToolStripMenuItem SaveToolStripMenuItem;
+ private ToolStripMenuItem LoadToolStripMenuItem;
+ private SaveFileDialog saveFileDialog;
+ private OpenFileDialog openFileDialog;
+ private ToolStripMenuItem файлToolStripMenuItem;
+ private ToolStripMenuItem save_ToolStripMenuItem;
+ private ToolStripMenuItem load_ToolStripMenuItem;
}
}
\ No newline at end of file
diff --git a/TrolleybusProject/TrolleybusProject/FormBusCollection.cs b/TrolleybusProject/TrolleybusProject/FormBusCollection.cs
index 5e3cea7..8c60c4a 100644
--- a/TrolleybusProject/TrolleybusProject/FormBusCollection.cs
+++ b/TrolleybusProject/TrolleybusProject/FormBusCollection.cs
@@ -29,11 +29,9 @@ public partial class FormBusCollection : Form
_storageCollection = new();
}
-
-
private void buttonAddBus_Click(object sender, EventArgs e)
{
- BusConfig form= new ();
+ BusConfig form = new();
form.Show();
form.AddEvent(SetBus);
}
@@ -60,9 +58,9 @@ public partial class FormBusCollection : Form
}
-
-
+
+
private void buttonDelTrolleybus_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
@@ -117,11 +115,10 @@ public partial class FormBusCollection : Form
{
return;
}
+
pictureBox.Image = _company.Show();
}
-
-
private void buttonCollectionAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCollectionName.Text) ||
@@ -203,8 +200,44 @@ public partial class FormBusCollection : Form
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
-
+
+ private void save_ToolStripMenuItem_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 load_ToolStripMenuItem_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/TrolleybusProject/TrolleybusProject/FormBusCollection.resx b/TrolleybusProject/TrolleybusProject/FormBusCollection.resx
index af32865..cfb2cea 100644
--- a/TrolleybusProject/TrolleybusProject/FormBusCollection.resx
+++ b/TrolleybusProject/TrolleybusProject/FormBusCollection.resx
@@ -117,4 +117,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 165, 17
+
+
+ 355, 17
+
\ No newline at end of file
diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs
index 69bdae0..ee1b6f9 100644
--- a/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs
+++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/ObjectParameters.cs
@@ -64,7 +64,5 @@ namespace TrolleybusProject.MovementStrategy
}
-
-
}
}
diff --git a/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs b/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs
index 5c85260..84f8bcc 100644
--- a/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs
+++ b/TrolleybusProject/TrolleybusProject/MovementStrategy/StrategyStatus.cs
@@ -21,5 +21,4 @@ public enum StrategyStatus
///
Finish
-
}