From 880d600b2f94f1d1fb77ff362e75d87d4df200a4 Mon Sep 17 00:00:00 2001 From: VirBiuM Date: Sun, 5 May 2024 17:26:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=966?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../ICollectionGenericObjects.cs | 13 +- .../ListGenericObjects.cs | 29 +++- .../MassiveGenericObjects.cs | 20 ++- .../StorageCollection.cs | 138 +++++++++++++++++- .../Drawnings/DrawningAirFighter.cs | 9 ++ .../Drawnings/DrawningWarPlane.cs | 9 ++ .../Drawnings/ExtentionDrawningWarPlane.cs | 50 +++++++ .../Entities/EntityAirFighter.cs | 25 ++++ .../Entities/EntityWarPlane.cs | 23 +++ .../FormPlaneCollection.Designer.cs | 77 ++++++++-- .../ProjectAirFighter/FormPlaneCollection.cs | 45 ++++++ .../FormPlaneCollection.resx | 9 ++ 13 files changed, 432 insertions(+), 17 deletions(-) create mode 100644 ProjectAirFighter/ProjectAirFighter/Drawnings/ExtentionDrawningWarPlane.cs diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs index c418756..813b44f 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -46,7 +46,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// /// Перегрузка оператора сложения для класса diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs index bf54acf..405c43d 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -15,7 +15,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { set; get; } /// /// Добавление объекта в коллекцию @@ -45,4 +45,15 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs index 4dee2e6..5b9f0e5 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs @@ -1,4 +1,5 @@ -namespace ProjectAirFighter.CollectionGenericObjects; + +namespace ProjectAirFighter.CollectionGenericObjects; public class ListGenericObjects : ICollectionGenericObjects where T : class @@ -12,7 +13,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 Count; + } + set + { + if (value > 0) + { + _maxCount = value; + } + } + } + + public CollectionType GetCollectionType => CollectionType.List; + /// /// Конструктор /// @@ -51,4 +68,12 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.RemoveAt(position); return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < Count; ++i) + { + yield return _collection[i]; + } + } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs index 0411e6c..f3a753a 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,4 +1,5 @@ -namespace ProjectAirFighter.CollectionGenericObjects; + +namespace ProjectAirFighter.CollectionGenericObjects; public class MassiveGenericObjects : ICollectionGenericObjects where T : class @@ -10,8 +11,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects public int Count => _collection.Length; - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -27,6 +32,9 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } } + + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -94,4 +102,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects } return null; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs index c02b8c4..c31cad0 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -1,7 +1,9 @@ -namespace ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Drawnings; + +namespace ProjectAirFighter.CollectionGenericObjects; public class StorageCollection - where T : class + where T : DrawningWarPlane { /// /// Словарь (хранилище) с коллекциями @@ -60,4 +62,136 @@ public class StorageCollection return null; } } + + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + + /// + /// Сохранение информации по самолетам в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (_storages.Count == 0) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter writer = new StreamWriter(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; + } + + /// + /// Загрузка информации по самолетам в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + using (StreamReader fs = File.OpenText(filename)) + { + string str = fs.ReadLine(); + if (str == null || str.Length == 0) + { + return false; + } + if (!str.StartsWith(_collectionKey)) + { + return false; + } + _storages.Clear(); + string strs = ""; + while ((strs = fs.ReadLine()) != null) + { + string[] record = strs.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?.CreateDrawningWarPlane() is T plane) + { + if (collection.Insert(plane) == -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/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs index 6c772c8..8194b4d 100644 --- a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs @@ -22,6 +22,15 @@ public class DrawningAirFighter : DrawningWarPlane EntityWarPlane = new EntityAirFighter(speed, weight, bodyColor, additionalColor, engines, extraWings, rockets); } + /// + /// Конструктор параметров + /// + /// + public DrawningAirFighter(EntityAirFighter plane) : base(150, 150) + { + EntityWarPlane = new EntityAirFighter(plane.Speed, plane.Weight, plane.BodyColor, plane.AdditionalColor, plane.Engines, plane.ExtraWings, plane.Rockets); + } + public override void DrawTransport(Graphics g) { if (EntityWarPlane == null || EntityWarPlane is not EntityAirFighter airFighter || !_startPosX.HasValue || !_startPosY.HasValue) diff --git a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningWarPlane.cs b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningWarPlane.cs index 67d604e..a88429d 100644 --- a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningWarPlane.cs +++ b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningWarPlane.cs @@ -92,6 +92,15 @@ public class DrawningWarPlane _drawningPlaneHeight = drawningPlaneHeight; } + /// + /// Конструктор параметров + /// + /// + public DrawningWarPlane(EntityWarPlane plane) : this() + { + EntityWarPlane = new EntityWarPlane(plane.Speed, plane.Weight, plane.BodyColor); + } + /// /// Установка границ поля /// diff --git a/ProjectAirFighter/ProjectAirFighter/Drawnings/ExtentionDrawningWarPlane.cs b/ProjectAirFighter/ProjectAirFighter/Drawnings/ExtentionDrawningWarPlane.cs new file mode 100644 index 0000000..8ae4b78 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/Drawnings/ExtentionDrawningWarPlane.cs @@ -0,0 +1,50 @@ +using ProjectAirFighter.Entities; + +namespace ProjectAirFighter.Drawnings; + +/// +/// Расширение для класса EntityWarPlane +/// +public static class ExtentionDrawningWarPlane +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningWarPlane? CreateDrawningWarPlane(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityWarPlane? plane = EntityAirFighter.CreateEntityAirFighter(strs); + if (plane != null) + { + return new DrawningAirFighter((EntityAirFighter)plane); + } + plane = EntityWarPlane.CreateEntityWarPlane(strs); + if (plane != null) + { + return new DrawningWarPlane(plane); + } + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningWarPlane drawningWarPlane) + { + string[]? array = drawningWarPlane?.EntityWarPlane?.GetStringRepresentation(); + if (array == null) + { + return string.Empty; + } + return string.Join(_separatorForObject, array); + } +} \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs index 29cc02d..40d8c33 100644 --- a/ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs +++ b/ProjectAirFighter/ProjectAirFighter/Entities/EntityAirFighter.cs @@ -46,4 +46,29 @@ public class EntityAirFighter : EntityWarPlane ExtraWings = extraWings; Rockets = rockets; } + + /// + /// Получение строк со значениями свойств продвинутого объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityAirFighter), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, + Engines.ToString(), ExtraWings.ToString(), Rockets.ToString()}; + } + + /// + /// Создание продвинутого объекта из массива строк + /// + /// + /// + public static EntityAirFighter? CreateEntityAirFighter(string[] strs) + { + if (strs.Length != 8 || strs[0] != nameof(EntityAirFighter)) + { + return null; + } + return new EntityAirFighter(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])); + } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs b/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs index a5c9c5c..64278f0 100644 --- a/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs +++ b/ProjectAirFighter/ProjectAirFighter/Entities/EntityWarPlane.cs @@ -41,4 +41,27 @@ public class EntityWarPlane Weight = weight; BodyColor = bodyColor; } + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityWarPlane), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityWarPlane? CreateEntityWarPlane(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityWarPlane)) + { + return null; + } + return new EntityWarPlane(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.Designer.cs index ed79def..283ebf9 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.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,11 +66,11 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(991, 0); + groupBoxTools.Location = new Point(991, 28); groupBoxTools.Margin = new Padding(3, 4, 3, 4); groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Padding = new Padding(3, 4, 3, 4); - groupBoxTools.Size = new Size(238, 828); + groupBoxTools.Size = new Size(238, 800); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -78,7 +85,7 @@ panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Location = new Point(3, 446); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(232, 378); + panelCompanyTools.Size = new Size(232, 350); panelCompanyTools.TabIndex = 8; // // buttonAddWarPlane @@ -96,7 +103,7 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(14, 316); + buttonRefresh.Location = new Point(14, 279); buttonRefresh.Margin = new Padding(3, 4, 3, 4); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(206, 61); @@ -107,7 +114,7 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(14, 143); + maskedTextBoxPosition.Location = new Point(14, 106); maskedTextBoxPosition.Margin = new Padding(3, 4, 3, 4); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; @@ -118,7 +125,7 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(14, 247); + buttonGoToCheck.Location = new Point(14, 210); buttonGoToCheck.Margin = new Padding(3, 4, 3, 4); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(206, 61); @@ -130,7 +137,7 @@ // buttonRemovePlane // buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemovePlane.Location = new Point(14, 178); + buttonRemovePlane.Location = new Point(14, 141); buttonRemovePlane.Margin = new Padding(3, 4, 3, 4); buttonRemovePlane.Name = "buttonRemovePlane"; buttonRemovePlane.Size = new Size(206, 61); @@ -247,13 +254,54 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 28); pictureBox.Margin = new Padding(3, 4, 3, 4); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(991, 828); + pictureBox.Size = new Size(991, 800); 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(1229, 28); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip"; + // + // файл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.Filter = "txt file | *.txt"; + // // FormPlaneCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -261,6 +309,8 @@ ClientSize = new Size(1229, 828); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Margin = new Padding(3, 4, 3, 4); Name = "FormPlaneCollection"; Text = "Коллекция самолетов"; @@ -270,7 +320,10 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -293,5 +346,11 @@ private Button buttonCollectionAdd; 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/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs index 271312a..95bb750 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.cs @@ -186,4 +186,49 @@ public partial class FormPlaneCollection : 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); + } + } + } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.resx b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.resx index af32865..ee1748a 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.resx +++ b/ProjectAirFighter/ProjectAirFighter/FormPlaneCollection.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 145, 17 + + + 310, 17 + \ No newline at end of file