From f7d998f50db31b755db9fb582e1ed966875fa885 Mon Sep 17 00:00:00 2001 From: ikswi Date: Sun, 14 Apr 2024 09:25:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../ICollectionGenericObjects.cs | 13 +- .../ListGenericObjects.cs | 22 +- .../MassiveGenericObjects.cs | 16 +- .../StorageCollection.cs | 165 +++++++++++- .../Drawnings/DrawningAirFighter.cs | 11 + .../Drawnings/DrawningMilitaryAircraft.cs | 9 + .../ExtentionDrawningMilitaryAircraft.cs | 54 ++++ .../AirFighter/Entities/EntityAirFighter.cs | 20 ++ .../Entities/EntityMilitaryAircraft.cs | 24 ++ ...FormMilitaryAircraftCollection.Designer.cs | 241 +++++++++++------- .../FormMilitaryAircraftCollection.cs | 40 +++ .../FormMilitaryAircraftCollection.resx | 9 + 13 files changed, 522 insertions(+), 104 deletions(-) create mode 100644 AirFighter/AirFighter/Drawnings/ExtentionDrawningMilitaryAircraft.cs 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..75d1b0e 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -15,7 +15,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -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/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs index daf6f3c..c582091 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs @@ -19,7 +19,19 @@ public class ListGenericObjects : ICollectionGenericObjects public int Count => _collection.Count; - public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + public int MaxCount + { + get => _maxCount; + set + { + if (value > 0) + { + _maxCount = value; + } + } + } + + public CollectionType GetCollectionType => CollectionType.List; /// /// Конструктор @@ -57,4 +69,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..9fc86d9 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs @@ -1,11 +1,15 @@ -namespace ProjectAirFighter.CollectionGenericObjects; +using ProjectAirFighter.Drawnings; +using System.Text; + +namespace ProjectAirFighter.CollectionGenericObjects; /// /// Класс-хранилище коллекций /// /// public class StorageCollection - where T : class + where T : DrawningMilitaryAircraft + { /// /// Словарь (хранилище) с коллекциями @@ -17,12 +21,26 @@ public class StorageCollection /// public List Keys => _storages.Keys.ToList(); + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// public StorageCollection() { - _storages = new Dictionary>(); //вот тут какое-то свойство + _storages = new Dictionary>(); } /// @@ -70,4 +88,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); + } + + StringBuilder sb = new(); + + sb.Append(_collectionKey); + foreach (KeyValuePair> value in _storages) + { + sb.Append(Environment.NewLine); + // не сохраняем пустые коллекции + if (value.Value.Count == 0) + { + continue; + } + + sb.Append(value.Key); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.MaxCount); + sb.Append(_separatorForKeyValue); + + foreach (T? item in value.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + { + continue; + } + + sb.Append(data); + sb.Append(_separatorItems); + } + } + + using FileStream fs = new(filename, FileMode.Create); + byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString()); + fs.Write(info, 0, info.Length); + 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?.CreateDrawningMilitaryAircraft() is T militaryAircraft) + { + if (!collection.Insert(militaryAircraft)) + { + 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..24b3b0b 100644 --- a/AirFighter/AirFighter/Drawnings/DrawningAirFighter.cs +++ b/AirFighter/AirFighter/Drawnings/DrawningAirFighter.cs @@ -22,6 +22,17 @@ public class DrawningAirFighter : DrawningMilitaryAircraft EntityMilitaryAircraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, wings, 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..3feead0 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..bf62953 --- /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(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 d107903..4916ec0 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelCompanyTools = new Panel(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveMilitaryAircraft = new Button(); + buttonAddMilitaryAircraft = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -38,19 +44,19 @@ radioButtonMassive = new RadioButton(); radioButtonList = new RadioButton(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveMilitaryAircraft = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddAirFighter = new Button(); - buttonAddMilitaryAircraft = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + openFileDialog = new OpenFileDialog(); + saveFileDialog = new SaveFileDialog(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -60,18 +66,86 @@ 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 = "Инструменты"; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRemoveMilitaryAircraft); + panelCompanyTools.Controls.Add(buttonAddMilitaryAircraft); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 350); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(200, 286); + panelCompanyTools.TabIndex = 10; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(4, 234); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(192, 49); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(3, 181); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(192, 49); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonRemoveMilitaryAircraft + // + buttonRemoveMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveMilitaryAircraft.Location = new Point(4, 113); + buttonRemoveMilitaryAircraft.Name = "buttonRemoveMilitaryAircraft"; + buttonRemoveMilitaryAircraft.Size = new Size(191, 49); + buttonRemoveMilitaryAircraft.TabIndex = 5; + buttonRemoveMilitaryAircraft.Text = "Удаление военного самолёта"; + buttonRemoveMilitaryAircraft.UseVisualStyleBackColor = true; + buttonRemoveMilitaryAircraft.Click += buttonRemoveMilitaryAircraft_Click; + // + // buttonAddMilitaryAircraft + // + buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddMilitaryAircraft.Location = new Point(4, 25); + buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft"; + buttonAddMilitaryAircraft.Size = new Size(191, 49); + buttonAddMilitaryAircraft.TabIndex = 1; + buttonAddMilitaryAircraft.Text = "Добавление военного самолёта"; + buttonAddMilitaryAircraft.UseVisualStyleBackColor = true; + buttonAddMilitaryAircraft.Click += buttonAddMilitaryAircraft_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBoxPosition.Location = new Point(3, 80); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(192, 27); + maskedTextBoxPosition.TabIndex = 4; + maskedTextBoxPosition.ValidatingType = typeof(int); + // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(7, 322); + buttonCreateCompany.Location = new Point(6, 315); buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(191, 29); + buttonCreateCompany.Size = new Size(192, 29); buttonCreateCompany.TabIndex = 9; buttonCreateCompany.Text = "Создание компании"; buttonCreateCompany.UseVisualStyleBackColor = true; @@ -89,12 +163,12 @@ panelStorage.Dock = DockStyle.Top; panelStorage.Location = new Point(3, 23); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(200, 256); + panelStorage.Size = new Size(200, 252); panelStorage.TabIndex = 8; // // buttonCollectionDel // - buttonCollectionDel.Location = new Point(6, 224); + buttonCollectionDel.Location = new Point(6, 220); buttonCollectionDel.Name = "buttonCollectionDel"; buttonCollectionDel.Size = new Size(189, 29); buttonCollectionDel.TabIndex = 6; @@ -159,77 +233,13 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(3, 252); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(192, 49); - buttonRefresh.TabIndex = 7; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += buttonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(3, 197); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(192, 49); - buttonGoToCheck.TabIndex = 6; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += buttonGoToCheck_Click; - // - // buttonRemoveMilitaryAircraft - // - buttonRemoveMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveMilitaryAircraft.Location = new Point(4, 142); - buttonRemoveMilitaryAircraft.Name = "buttonRemoveMilitaryAircraft"; - buttonRemoveMilitaryAircraft.Size = new Size(191, 49); - buttonRemoveMilitaryAircraft.TabIndex = 5; - buttonRemoveMilitaryAircraft.Text = "Удаление военного самолёта"; - buttonRemoveMilitaryAircraft.UseVisualStyleBackColor = true; - buttonRemoveMilitaryAircraft.Click += buttonRemoveMilitaryAircraft_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBoxPosition.Location = new Point(3, 109); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(192, 27); - maskedTextBoxPosition.TabIndex = 4; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddAirFighter - // - buttonAddAirFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirFighter.Location = new Point(3, 54); - buttonAddAirFighter.Name = "buttonAddAirFighter"; - buttonAddAirFighter.Size = new Size(192, 49); - buttonAddAirFighter.TabIndex = 2; - buttonAddAirFighter.Text = "Добавление истребителя"; - buttonAddAirFighter.UseVisualStyleBackColor = true; - // - // buttonAddMilitaryAircraft - // - buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddMilitaryAircraft.Location = new Point(4, 3); - buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft"; - buttonAddMilitaryAircraft.Size = new Size(191, 49); - buttonAddMilitaryAircraft.TabIndex = 1; - buttonAddMilitaryAircraft.Text = "Добавление военного самолёта"; - buttonAddMilitaryAircraft.UseVisualStyleBackColor = true; - buttonAddMilitaryAircraft.Click += buttonAddMilitaryAircraft_Click; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(7, 285); + comboBoxSelectorCompany.Location = new Point(6, 281); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(193, 28); comboBoxSelectorCompany.TabIndex = 0; @@ -238,26 +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; // - // panelCompanyTools + // menuStrip // - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(buttonGoToCheck); - panelCompanyTools.Controls.Add(buttonRemoveMilitaryAircraft); - panelCompanyTools.Controls.Add(buttonAddMilitaryAircraft); - panelCompanyTools.Controls.Add(buttonAddAirFighter); - panelCompanyTools.Controls.Add(maskedTextBoxPosition); - panelCompanyTools.Dock = DockStyle.Bottom; - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 357); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(200, 307); - panelCompanyTools.TabIndex = 10; + 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 = "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; + // + // openFileDialog + // + openFileDialog.FileName = "openFileDialog1"; + openFileDialog.Filter = "txt file | *.txt"; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; // // FormMilitaryAircraftCollection // @@ -266,22 +303,26 @@ ClientSize = new Size(950, 667); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormMilitaryAircraftCollection"; Text = "Коллекция военных самолётов"; groupBoxTools.ResumeLayout(false); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTools.ResumeLayout(false); - panelCompanyTools.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion private GroupBox groupBoxTools; private ComboBox comboBoxSelectorCompany; - private Button buttonAddAirFighter; private Button buttonAddMilitaryAircraft; private MaskedTextBox maskedTextBoxPosition; private PictureBox pictureBox; @@ -298,5 +339,11 @@ private Button buttonCollectionAdd; private Button buttonCreateCompany; private Panel panelCompanyTools; + private MenuStrip menuStrip; + private ToolStripMenuItem файлToolStripMenuItem; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripMenuItem loadToolStripMenuItem; + private OpenFileDialog openFileDialog; + private SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs index 1e6fea7..8a16875 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs @@ -226,4 +226,44 @@ 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); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.resx b/AirFighter/AirFighter/FormMilitaryAircraftCollection.resx index af32865..b7ad5cc 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 + + + 315, 17 + \ No newline at end of file