From 40bc9189838651c6a215a22592641b858075ce77 Mon Sep 17 00:00:00 2001 From: ikswi Date: Sun, 12 May 2024 00:06:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=BE=20=D0=B8=D0=B7=D0=B1=D0=B5=D0=B6?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=84=D0=BB=D0=B8?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 11.txt | 3 + 12.txt | 3 + .../AbstractCompany.cs | 2 +- .../ICollectionGenericObjects.cs | 17 +- .../ListGenericObjects.cs | 25 ++- .../MassiveGenericObjects.cs | 16 +- .../StorageCollection.cs | 162 +++++++++++++++++- .../Drawnings/DrawningAirFighter.cs | 16 ++ .../Drawnings/DrawningMilitaryAircraft.cs | 9 + .../ExtentionDrawningMilitaryAircraft.cs | 54 ++++++ .../AirFighter/Entities/EntityAirFighter.cs | 20 +++ .../Entities/EntityMilitaryAircraft.cs | 24 +++ ...FormMilitaryAircraftCollection.Designer.cs | 77 ++++++++- .../FormMilitaryAircraftCollection.cs | 31 ++++ .../FormMilitaryAircraftCollection.resx | 9 + 15 files changed, 452 insertions(+), 16 deletions(-) create mode 100644 11.txt create mode 100644 12.txt create mode 100644 AirFighter/AirFighter/Drawnings/ExtentionDrawningMilitaryAircraft.cs diff --git a/11.txt b/11.txt new file mode 100644 index 0000000..db43816 --- /dev/null +++ b/11.txt @@ -0,0 +1,3 @@ +CollectionsStorage +11|Massive|45|EntityMilitaryAircraft:100:100:Gray;EntityAirFighter:100:100:Gray:True:True:Gray;EntityAirFighter:100:100:Gray:True:True:Gray; +12|Massive|45|EntityAirFighter:100:100:BlueViolet:True:True:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet;EntityAirFighter:100:100:BlueViolet:True:True:BlueViolet; \ No newline at end of file diff --git a/12.txt b/12.txt new file mode 100644 index 0000000..80b13fc --- /dev/null +++ b/12.txt @@ -0,0 +1,3 @@ +CollectionsStorage +11|Massive|45|EntityMilitaryAircraft:100:100:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet; +12|Massive|45|EntityMilitaryAircraft:100:100:Yellow;EntityMilitaryAircraft:100:100:Yellow;EntityMilitaryAircraft:100:100:Yellow; \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs b/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs index 268c3d5..1e6c381 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs +++ b/AirFighter/AirFighter/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/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs index 37a865f..23cee8c 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,4 +1,6 @@ -namespace ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Drawnings; + +namespace ProjectAirFighter.CollectionGenericObjects; /// /// Интерфейс описания действий для набора хранимых объектов @@ -15,7 +17,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -45,4 +47,15 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); } \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs index daf6f3c..64884c3 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs @@ -19,7 +19,22 @@ public class ListGenericObjects : ICollectionGenericObjects 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; /// /// Конструктор @@ -57,4 +72,12 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.RemoveAt(position); return pos; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } } \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs index 45f854a..ccda1cf 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/AirFighter/AirFighter/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; + /// /// Конструктор /// @@ -105,4 +111,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects _collection[position] = null; return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } } \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs index c1cc672..f457172 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs @@ -1,11 +1,14 @@ -namespace ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Drawnings; +using System.Text; + +namespace ProjectAirFighter.CollectionGenericObjects; /// /// Класс-хранилище коллекций /// /// public class StorageCollection - where T : class + where T : DrawningMilitaryAircraft { /// /// Словарь (хранилище) с коллекциями @@ -17,6 +20,20 @@ public class StorageCollection /// public List Keys => _storages.Keys.ToList(); + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// @@ -70,4 +87,145 @@ 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); + } + + using (StreamWriter writer = new StreamWriter(filename)) + { + writer.Write(_collectionKey); + + foreach (KeyValuePair> value in _storages) + { + StringBuilder sb = new(); + + 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); + } + writer.Write(sb); + } + + } + + 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?.CreateDrawningMilitaryAircraft() is T militaryAircraft) + { + if (collection.Insert(militaryAircraft) == -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/AirFighter/AirFighter/Drawnings/DrawningAirFighter.cs b/AirFighter/AirFighter/Drawnings/DrawningAirFighter.cs index 588e8b7..02fcff3 100644 --- a/AirFighter/AirFighter/Drawnings/DrawningAirFighter.cs +++ b/AirFighter/AirFighter/Drawnings/DrawningAirFighter.cs @@ -22,6 +22,22 @@ public class DrawningAirFighter : DrawningMilitaryAircraft EntityMilitaryAircraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, wings, rockets); } + /// + /// Конструктор + /// + public DrawningAirFighter(EntityAirFighter militaryAircraft) : base(110, 60) + { + EntityMilitaryAircraft = new EntityAirFighter(militaryAircraft.Speed, militaryAircraft.Weight, militaryAircraft.BodyColor, militaryAircraft.AdditionalColor, militaryAircraft.Wings, militaryAircraft.Rockets); + } + + //public DrawningAirFighter(EntityMilitaryAircraft entityMilitaryAircraft) : base(110, 60) + //{ + // if (entityMilitaryAircraft != null) + // { + // EntityMilitaryAircraft = entityMilitaryAircraft; + // } + //} + public override void DrawTransport(Graphics g) { if (EntityMilitaryAircraft == null || EntityMilitaryAircraft is not EntityAirFighter airFighter || !_startPosX.HasValue || !_startPosY.HasValue) diff --git a/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraft.cs b/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraft.cs index 05c716f..985bfab 100644 --- a/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraft.cs +++ b/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraft.cs @@ -84,6 +84,15 @@ public class DrawningMilitaryAircraft EntityMilitaryAircraft = new EntityMilitaryAircraft(speed, weight, bodyColor); } + /// + /// Конструктор + /// + /// Класс-сущность + public DrawningMilitaryAircraft(EntityMilitaryAircraft militaryAircraft) : this() + { + EntityMilitaryAircraft = militaryAircraft; + } + /// /// Конструктор для наследников /// diff --git a/AirFighter/AirFighter/Drawnings/ExtentionDrawningMilitaryAircraft.cs b/AirFighter/AirFighter/Drawnings/ExtentionDrawningMilitaryAircraft.cs new file mode 100644 index 0000000..61788e9 --- /dev/null +++ b/AirFighter/AirFighter/Drawnings/ExtentionDrawningMilitaryAircraft.cs @@ -0,0 +1,54 @@ +using ProjectAirFighter.Entities; + +namespace ProjectAirFighter.Drawnings; + +/// +/// Расширение для класса EntityCar +/// +public static class ExtentionDrawningMilitaryAircraft +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningMilitaryAircraft? CreateDrawningMilitaryAircraft(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityMilitaryAircraft? militaryAircraft = EntityAirFighter.CreateEntityAirFighter(strs); + if (militaryAircraft != null) + { + return new DrawningAirFighter((EntityAirFighter)militaryAircraft); + } + + militaryAircraft = EntityMilitaryAircraft.CreateEntityMilitaryAircraft(strs); + if (militaryAircraft != null) + { + return new DrawningMilitaryAircraft(militaryAircraft); + } + + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningMilitaryAircraft drawningMilitaryAircraft) + { + string[]? array = drawningMilitaryAircraft?.EntityMilitaryAircraft?.GetStringRepresentation(); + + if (array == null) + { + return string.Empty; + } + + return string.Join(_separatorForObject, array); + } +} \ No newline at end of file diff --git a/AirFighter/AirFighter/Entities/EntityAirFighter.cs b/AirFighter/AirFighter/Entities/EntityAirFighter.cs index c377bfd..3f246d5 100644 --- a/AirFighter/AirFighter/Entities/EntityAirFighter.cs +++ b/AirFighter/AirFighter/Entities/EntityAirFighter.cs @@ -22,4 +22,24 @@ public class EntityAirFighter : EntityMilitaryAircraft Rockets = rockets; Wings = wings; } + + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityAirFighter), Speed.ToString(), Weight.ToString(), BodyColor.Name, Wings.ToString(), Rockets.ToString(), AdditionalColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + 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])); + } } \ No newline at end of file diff --git a/AirFighter/AirFighter/Entities/EntityMilitaryAircraft.cs b/AirFighter/AirFighter/Entities/EntityMilitaryAircraft.cs index 3f52185..2474f69 100644 --- a/AirFighter/AirFighter/Entities/EntityMilitaryAircraft.cs +++ b/AirFighter/AirFighter/Entities/EntityMilitaryAircraft.cs @@ -31,4 +31,28 @@ public class EntityMilitaryAircraft Weight = weight; BodyColor = bodyColor; } + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityMilitaryAircraft), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityMilitaryAircraft? CreateEntityMilitaryAircraft(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityMilitaryAircraft)) + { + return null; + } + + return new EntityMilitaryAircraft(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } } diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs index da5b642..0dbd8f4 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.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(744, 0); + groupBoxTools.Location = new Point(744, 28); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(206, 667); + groupBoxTools.Size = new Size(206, 639); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -77,13 +84,13 @@ panelCompanyTools.Enabled = false; panelCompanyTools.Location = new Point(3, 357); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(200, 307); + panelCompanyTools.Size = new Size(200, 279); panelCompanyTools.TabIndex = 10; // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(3, 252); + buttonRefresh.Location = new Point(0, 227); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(192, 49); buttonRefresh.TabIndex = 7; @@ -94,7 +101,7 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(3, 197); + buttonGoToCheck.Location = new Point(3, 178); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(192, 49); buttonGoToCheck.TabIndex = 6; @@ -105,7 +112,7 @@ // buttonRemoveMilitaryAircraft // buttonRemoveMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveMilitaryAircraft.Location = new Point(4, 142); + buttonRemoveMilitaryAircraft.Location = new Point(4, 129); buttonRemoveMilitaryAircraft.Name = "buttonRemoveMilitaryAircraft"; buttonRemoveMilitaryAircraft.Size = new Size(191, 49); buttonRemoveMilitaryAircraft.TabIndex = 5; @@ -127,7 +134,7 @@ // maskedTextBoxPosition // maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBoxPosition.Location = new Point(3, 109); + maskedTextBoxPosition.Location = new Point(3, 96); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(192, 27); @@ -241,12 +248,53 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 28); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(744, 667); + pictureBox.Size = new Size(744, 639); 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(950, 28); + menuStrip.TabIndex = 4; + 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"; + // // FormMilitaryAircraftCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -254,6 +302,8 @@ ClientSize = new Size(950, 667); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormMilitaryAircraftCollection"; Text = "Коллекция военных самолётов"; groupBoxTools.ResumeLayout(false); @@ -262,7 +312,10 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -285,5 +338,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/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs index 1e6fea7..a0dc7cd 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs @@ -226,4 +226,35 @@ public partial class FormMilitaryAircraftCollection : 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/AirFighter/AirFighter/FormMilitaryAircraftCollection.resx b/AirFighter/AirFighter/FormMilitaryAircraftCollection.resx index af32865..ee1748a 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.resx +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.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