diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
index 6b52aba..e0135f9 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
@@ -43,13 +43,12 @@ public abstract class AbstractCompany
/// Ширина окна
/// Высота окна
/// Коллекция автомобилей
- public AbstractCompany(int picWidth, int picHeight,
- ICollectionGenericObjects collection)
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
- _collection.SetMaxCount = GetMaxCount;
+ _collection.MaxCount = GetMaxCount;
}
///
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
index 3538adf..fc4ea8e 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -21,7 +21,7 @@ where T : class
///
/// Установка максимального количества элементов
///
- int SetMaxCount { set; }
+ int MaxCount { get; set; }
///
/// Добавление объекта в коллекцию
///
@@ -48,4 +48,15 @@ where T : class
/// Объект
T? Get(int position);
+ ///
+ /// Получение типа коллекции
+ ///
+ CollectionType GetCollectionType { get; }
+ ///
+ /// Получение объектов коллекции по одному
+ ///
+ /// Поэлементый вывод элементов коллекции
+ IEnumerable GetItems();
+
+
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs
index 0dad494..ba3b83f 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs
@@ -22,7 +22,23 @@ public class ListGenericObjects : ICollectionGenericObjects
///
private int _maxCount;
public int Count => _collection.Count;
- public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
+ public int MaxCount
+ {
+ get
+ {
+ return MaxCount;
+ }
+ set
+ {
+ if (value > 0)
+ {
+ _maxCount = value;
+ }
+ }
+ }
+
+ public CollectionType GetCollectionType => CollectionType.List;
+
///
/// Конструктор
///
@@ -36,10 +52,9 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
return null;
}
+
public int Insert(T obj)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO вставка в конец набора
if (_collection.Count > _maxCount)
{
return -1;
@@ -47,11 +62,9 @@ public class ListGenericObjects : ICollectionGenericObjects
_collection.Add(obj);
return _collection.Count;
}
+
public int Insert(T obj, int position)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO проверка позиции
- // TODO вставка по позиции
if (_collection.Count > _maxCount || position < 0 || position > _maxCount)
{
return -1;
@@ -80,10 +93,9 @@ public class ListGenericObjects : ICollectionGenericObjects
}
return -1;
}
+
public T Remove(int position)
{
- // TODO проверка позиции
- // TODO удаление объекта из списка
if (position < 0 || position > _maxCount)
{
return null;
@@ -92,5 +104,13 @@ public class ListGenericObjects : ICollectionGenericObjects
_collection.RemoveAt(position);
return temp;
}
+
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _maxCount; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
index ae7f672..703321a 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -19,8 +19,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects
///
private T?[] _collection;
public int Count => _collection.Length;
- public int SetMaxCount
+ public int MaxCount
{
+ get
+ {
+ return _collection.Length;
+ }
set
{
if (value > 0)
@@ -36,6 +40,9 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
}
}
+
+ public CollectionType GetCollectionType => CollectionType.Massive;
+
///
/// Конструктор
///
@@ -100,5 +107,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
return null;
}
+
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Length; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs
index f3cd33a..061aa07 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs
@@ -1,4 +1,5 @@
-using System;
+using ProjectDumpTruck.Drawnings;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -11,7 +12,7 @@ namespace ProjectDumpTruck.CollectionGenericObjects;
///
///
public class StorageCollection
- where T : class
+ where T : DrawningTruck
{
///
/// Словарь (хранилище) с коллекциями
@@ -21,6 +22,20 @@ public class StorageCollection
/// Возвращение списка названий коллекций
///
public List Keys => _storages.Keys.ToList();
+
+ ///
+ /// Ключевое слово, с которого должен начинаться файл
+ ///
+ private readonly string _collectionKey = "CollectionsStorage";
+ ///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private readonly string _separatorForKeyValue = "|";
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly string _separatorItems = ";";
+
///
/// Конструктор
///
@@ -36,9 +51,6 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
- // TODO Прописать логику для добавления
-
if (_storages.ContainsKey(name))
{
return;
@@ -62,15 +74,13 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- // TODO Прописать логику для удаления коллекции
- /*if (name == null)
- return;*/
- if ( _storages.ContainsKey(name))
+ if (_storages.ContainsKey(name))
{
_storages.Remove(name);
}
-
+
}
+
///
/// Доступ к коллекции
///
@@ -80,7 +90,6 @@ public class StorageCollection
{
get
{
- // TODO Продумать логику получения объекта
if (_storages.ContainsKey(name))
{
return _storages[name];
@@ -88,4 +97,129 @@ public class StorageCollection
return null;
}
}
+
+ ///
+ /// Сохранение информации по грузовикам в хранилище в файл
+ ///
+ /// Путь и имя файла
+ /// true - сохранение прошло успешно, false - ошибка при сохранении данных
+ public bool SaveData(string filename)
+ {
+
+ if (_storages.Count == 0)
+ {
+ return false;
+ }
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+
+ using StreamWriter wr = new StreamWriter(filename);
+
+ wr.Write(_collectionKey);
+
+ foreach (KeyValuePair> value in _storages)
+ {
+ wr.Write(Environment.NewLine);
+ if (value.Value.Count == 0)
+ {
+ continue;
+ }
+ wr.Write(value.Key);
+ wr.Write(_separatorForKeyValue);
+ wr.Write(value.Value.GetCollectionType);
+ wr.Write(_separatorForKeyValue);
+ wr.Write(value.Value.MaxCount);
+ wr.Write(_separatorForKeyValue);
+ foreach (T? item in value.Value.GetItems())
+ {
+ string data = item?.GetDataForSave() ?? string.Empty;
+ if (string.IsNullOrEmpty(data))
+ {
+ continue;
+ }
+ wr.Write(data);
+ wr.Write(_separatorItems);
+ }
+ }
+ return true;
+ }
+ ///
+ /// Загрузка информации по автомобилям в хранилище из файла
+ ///
+ /// Путь и имя файла
+ /// true - загрузка прошла успешно, false - ошибка при загрузке данных
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ string bufferTextFromFile = "";
+ using (FileStream fs = new(filename, FileMode.Open))
+ {
+ byte[] b = new byte[fs.Length];
+ UTF8Encoding temp = new(true);
+ while (fs.Read(b, 0, b.Length) > 0)
+ {
+ bufferTextFromFile += temp.GetString(b);
+ }
+ }
+ string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
+ if (strs == null || strs.Length == 0)
+ {
+ return false;
+ }
+ if (!strs[0].Equals(_collectionKey))
+ {
+ //если нет такой записи, то это не те данные
+ return false;
+ }
+ _storages.Clear();
+ foreach (string data in strs)
+ {
+ string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ if (record.Length != 4)
+ {
+ continue;
+ }
+ CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
+ if (collection == null)
+ {
+ return false;
+ }
+ collection.MaxCount = Convert.ToInt32(record[2]);
+ string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
+ {
+ if (elem?.CreateDrawningTruck() is T truck)
+ {
+ if (collection.Insert(truck) < 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/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs
index 66c37c7..a0399d8 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs
@@ -4,6 +4,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectDumpTruck.Entities;
+using static System.Net.Mime.MediaTypeNames;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
namespace ProjectDumpTruck.Drawnings;
@@ -24,7 +26,12 @@ public class DrawningDumpTruck : DrawningTruck
public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool body, bool tent) : base(110, 100)
{
EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, body, tent);
+ }
+ public DrawningDumpTruck(EntityDumpTruck dumpTruck) : base(110, 100)
+ {
+ EntityTruck = new EntityDumpTruck(dumpTruck.Speed, dumpTruck.Weight, dumpTruck.BodyColor,
+ dumpTruck.AdditionalColor, dumpTruck.Body, dumpTruck.Tent);
}
public override void DrawTransport(Graphics g)
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTruck.cs
index 9c772ac..a1e0b0d 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTruck.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTruck.cs
@@ -78,6 +78,11 @@ public class DrawningTruck
}
+ public DrawningTruck(EntityTruck truck) : this()
+ {
+ EntityTruck = new EntityTruck(truck.Speed, truck.Weight, truck.BodyColor);
+ }
+
///
///
/// Конструктор для наследников
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs
new file mode 100644
index 0000000..552a9fd
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTruck.cs
@@ -0,0 +1,51 @@
+using ProjectDumpTruck.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.Drawnings;
+
+public static class ExtentionDrawningTruck
+{
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly string _separatorForObject = ":";
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка с данными для создания объекта
+ /// Объект
+ public static DrawningTruck? CreateDrawningTruck(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ EntityTruck? truck = EntityDumpTruck.CreateEntityDumpTruck(strs);
+ if (truck != null)
+ {
+ return new DrawningDumpTruck((EntityDumpTruck)truck);
+ }
+ truck = EntityTruck.CreateEntityTruck(strs);
+ if (truck != null)
+ {
+ return new DrawningTruck(truck);
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ /// Сохраняемый объект
+ /// Строка с данными по объекту
+ public static string GetDataForSave(this DrawningTruck drawningTruck)
+ {
+ string[]? array = drawningTruck?.EntityTruck?.GetStringRepresentation();
+ if (array == null)
+ {
+ return string.Empty;
+ }
+ return string.Join(_separatorForObject, array);
+ }
+
+}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs
index 0495b91..d6a5bad 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs
@@ -42,4 +42,29 @@ public class EntityDumpTruck : EntityTruck
Body = body;
Tent = tent;
}
+
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public override string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityDumpTruck), Speed.ToString(), Weight.ToString(), BodyColor.Name,
+ AdditionalColor.Name, Body.ToString(), Tent.ToString() };
+ }
+
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityTruck? CreateEntityDumpTruck(string[] strs)
+ {
+ if (strs.Length != 7 || strs[0] != nameof(EntityDumpTruck))
+ {
+ return null;
+ }
+ return new EntityDumpTruck(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/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs
index 4532346..74c1819 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTruck.cs
@@ -45,4 +45,27 @@ public class EntityTruck
BodyColor = bodyColor;
}
+
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public virtual string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityTruck), Speed.ToString(), Weight.ToString(), BodyColor.Name };
+ }
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityTruck? CreateEntityTruck(string[] strs)
+ {
+ if (strs.Length != 4 || strs[0] != nameof(EntityTruck))
+ {
+ return null;
+ }
+ return new EntityTruck(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
+ }
+
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
index e02b76b..2ae6507 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.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(832, 0);
+ groupBoxTools.Location = new Point(832, 28);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(250, 827);
+ groupBoxTools.Size = new Size(250, 799);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -74,9 +81,9 @@
panelCompanyTools.Controls.Add(buttonGoToChek);
panelCompanyTools.Controls.Add(buttonRemoveTruck);
panelCompanyTools.Dock = DockStyle.Bottom;
- panelCompanyTools.Location = new Point(3, 450);
+ panelCompanyTools.Location = new Point(3, 464);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(244, 374);
+ panelCompanyTools.Size = new Size(244, 332);
panelCompanyTools.TabIndex = 4;
//
// buttonAddTruck
@@ -92,7 +99,7 @@
//
// buttonRefresh
//
- buttonRefresh.Location = new Point(15, 300);
+ buttonRefresh.Location = new Point(15, 245);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(220, 57);
buttonRefresh.TabIndex = 7;
@@ -102,7 +109,7 @@
//
// maskedTextBoxPosition
//
- maskedTextBoxPosition.Location = new Point(15, 139);
+ maskedTextBoxPosition.Location = new Point(15, 85);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(223, 27);
@@ -111,7 +118,7 @@
//
// buttonGoToChek
//
- buttonGoToChek.Location = new Point(15, 237);
+ buttonGoToChek.Location = new Point(15, 181);
buttonGoToChek.Name = "buttonGoToChek";
buttonGoToChek.Size = new Size(220, 57);
buttonGoToChek.TabIndex = 6;
@@ -121,7 +128,7 @@
//
// buttonRemoveTruck
//
- buttonRemoveTruck.Location = new Point(15, 174);
+ buttonRemoveTruck.Location = new Point(15, 118);
buttonRemoveTruck.Name = "buttonRemoveTruck";
buttonRemoveTruck.Size = new Size(220, 57);
buttonRemoveTruck.TabIndex = 5;
@@ -131,7 +138,7 @@
//
// buttonCreateCompany
//
- buttonCreateCompany.Location = new Point(18, 406);
+ buttonCreateCompany.Location = new Point(18, 410);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(220, 29);
buttonCreateCompany.TabIndex = 9;
@@ -227,7 +234,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(18, 353);
+ comboBoxSelectorCompany.Location = new Point(18, 361);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(220, 28);
comboBoxSelectorCompany.TabIndex = 0;
@@ -236,12 +243,54 @@
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
- pictureBox.Location = new Point(0, 0);
+ pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(832, 827);
+ pictureBox.Size = new Size(832, 799);
pictureBox.TabIndex = 3;
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(1082, 28);
+ menuStrip.TabIndex = 4;
+ 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";
+ //
// FormTruckCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -249,6 +298,8 @@
ClientSize = new Size(1082, 827);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
+ Controls.Add(menuStrip);
+ MainMenuStrip = menuStrip;
Name = "FormTruckCollection";
Text = "Коллекция грузовиков";
groupBoxTools.ResumeLayout(false);
@@ -257,7 +308,10 @@
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
ResumeLayout(false);
+ PerformLayout();
}
#endregion
@@ -280,5 +334,11 @@
private Button buttonCollectionDel;
private ListBox listBoxCollection;
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/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
index 2891422..0d6f976 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
@@ -240,5 +240,41 @@ public partial class FormTruckCollection : Form
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
+
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ ///
+ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_storageCollection.SaveData(saveFileDialog.FileName))
+ {
+ MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_storageCollection.LoadData(openFileDialog.FileName))
+ {
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ RerfreshListBoxItems();
+ }
+ else
+ {
+ MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx
index 139c828..50cc400 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx
@@ -120,4 +120,13 @@
True
+
+ 17, 17
+
+
+ 145, 17
+
+
+ 310, 17
+
\ No newline at end of file