From f813e603f63ec1cb309f76867e95584ea18d59fb Mon Sep 17 00:00:00 2001 From: zolotovart Date: Tue, 23 Apr 2024 09:55:59 +0300 Subject: [PATCH] =?UTF-8?q?6=20=D0=BB=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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../ICollectionGenericObjects.cs | 13 +- .../ListGenericObjects.cs | 24 +++- .../MassiveGenericObjects.cs | 17 ++- .../StorageCollection.cs | 134 +++++++++++++++++- .../ProjectAirbus/Drawnings/DrawingLinkor.cs | 7 +- .../ProjectAirbus/Drawnings/DrawingShip.cs | 6 + .../Drawnings/ExtentionDrawingShip.cs | 52 +++++++ .../ProjectAirbus/Entities/EntityLinkor.cs | 25 ++++ .../ProjectAirbus/Entities/EntityShip.cs | 24 ++++ .../FormShipCollection.Designer.cs | 79 +++++++++-- .../ProjectAirbus/FormShipCollection.cs | 44 +++++- .../ProjectAirbus/FormShipCollection.resx | 9 ++ ProjectAirbus/ProjectAirbus/FormShipConfig.cs | 8 +- 14 files changed, 420 insertions(+), 24 deletions(-) create mode 100644 ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawingShip.cs diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs index f7639ac..98858a8 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs @@ -45,7 +45,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// /// Перегрузка оператора сложения для класса diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs index 9810b72..2ee36f3 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -16,10 +16,11 @@ where T : class /// Количество объектов в коллекции /// int Count { get; } + /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию /// @@ -45,4 +46,14 @@ where T : class /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs index 9a82f34..708bdf0 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs @@ -18,7 +18,22 @@ 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 _collection.Count; + } + set + { + if (value > 0) + { + _maxCount = value; + } + } + } + + public CollectionType GetCollectionType => CollectionType.List; + /// /// Конструктор /// @@ -69,4 +84,11 @@ public class ListGenericObjects : ICollectionGenericObjects return temp; } + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs index c8cc17a..01a5f43 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -15,8 +15,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) @@ -32,6 +36,9 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } } + + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -102,4 +109,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects _collection[position] = null; return myObject; } + + public IEnumerable GetItems() + { + for (int i = 0; i<_collection.Length; i++) + { + yield return _collection[i]; + } + } } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs index e7caf44..c9b152e 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ -using System; +using ProjectLinkor.Drawnings; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,7 +11,7 @@ namespace ProjectLinkor.CollectionGenericObjects; /// /// public class StorageCollection - where T : class + where T : DrawingShip { /// /// Словарь (хранилище) с коллекциями @@ -20,6 +21,20 @@ public class StorageCollection /// Возвращение списка названий коллекций /// public List Keys => _storages.Keys.ToList(); + + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// @@ -38,7 +53,7 @@ public class StorageCollection // TODO Прописать логику для добавления if (name == null || _storages.ContainsKey(name)) return; - switch (collectionType) + switch (collectionType) { case CollectionType.None: return; @@ -76,5 +91,118 @@ public class StorageCollection return _storages[name]; } } + public bool SaveData(string filename) + { + if (_storages.Count == 0) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter writer = new(filename)) + { + writer.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) + { + writer.Write(Environment.NewLine); + // не сохраняем пустые коллекции + if (value.Value.Count == 0) + { + continue; + } + writer.Write(value.Key); + writer.Write(_separatorForKeyValue); + writer.Write(value.Value.GetCollectionType); + writer.Write(_separatorForKeyValue); + writer.Write(value.Value.MaxCount); + writer.Write(_separatorForKeyValue); + + foreach (T? item in value.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + { + continue; + } + writer.Write(data); + writer.Write(_separatorItems); + } + } + } + return true; + } + /// + /// Загрузка информации по кораблям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + using (StreamReader reader = new(filename)) + { + string line = reader.ReadLine(); + if (line == null || line.Length == 0) + { + return false; + } + if (!line.Equals(_collectionKey)) + { + //если нет такой записи, то это не те данные + return false; + } + _storages.Clear(); + while ((line = reader.ReadLine()) != null) + { + string[] record = line.Split(_separatorForKeyValue, + StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 4) + { + continue; + } + CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); + if (collection == null) + { + return false; + } + collection.MaxCount = Convert.ToInt32(record[2]); + string[] set = record[3].Split(_separatorItems, + StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawingShip() is T ship) + { + if (collection.Insert(ship) == -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, + }; + } } diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingLinkor.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingLinkor.cs index f9c43af..05ab450 100644 --- a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingLinkor.cs +++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingLinkor.cs @@ -29,7 +29,12 @@ namespace ProjectLinkor.Drawnings { EntityShip = new EntityLinkor(speed, weight, bodyColor, additionalColor, rocket, gun); } - + public DrawingLinkor(EntityLinkor? linkor) : base(132, 65) + { + if (linkor == null) return; + EntityShip = new EntityLinkor(linkor.Speed, linkor.Weight, linkor.BodyColor, + linkor.AdditionalColor, linkor.Rocket, linkor.Gun); + } public override void DrawTransport(Graphics g) { if (EntityShip == null || EntityShip is not EntityLinkor linkor || !_startPosX.HasValue || !_startPosY.HasValue) diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShip.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShip.cs index a3e5dd6..2e3abcd 100644 --- a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShip.cs +++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShip.cs @@ -86,6 +86,12 @@ public class DrawingShip _drawningShipWidth = drawningLinkorWidth; _drawningShipHeight = drawningLinkorHeight; } + + public DrawingShip(EntityShip? ship) : this() + { + if (ship == null) return; + EntityShip = new EntityShip(ship.Speed, ship.Weight, ship.BodyColor); + } /// /// Установка границ поля /// diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawingShip.cs b/ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawingShip.cs new file mode 100644 index 0000000..db8d143 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawingShip.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectLinkor.Entities; + +namespace ProjectLinkor.Drawnings; + +public static class ExtentionDrawingShip +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawingShip? CreateDrawingShip(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityShip? ship = EntityLinkor.CreateEntityLinkor(strs); + + if (ship != null) + { + return new DrawingLinkor((EntityLinkor)ship); + } + ship = EntityShip.CreateEntityShip(strs); + if (ship != null) + { + return new DrawingShip(ship); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawingShip drawingShip) + { + string[]? array = drawingShip?.EntityShip?.GetStringRepresentation(); + if (array == null) + { + return string.Empty; + } + return string.Join(_separatorForObject, array); + } + +} diff --git a/ProjectAirbus/ProjectAirbus/Entities/EntityLinkor.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityLinkor.cs index 04ec4d6..d187dec 100644 --- a/ProjectAirbus/ProjectAirbus/Entities/EntityLinkor.cs +++ b/ProjectAirbus/ProjectAirbus/Entities/EntityLinkor.cs @@ -47,5 +47,30 @@ namespace ProjectLinkor.Entities Gun = gun; } + /// + /// Получение строк со значениями свойств продвинутого объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityLinkor), Speed.ToString(), Weight.ToString(), + BodyColor.Name, AdditionalColor.Name, Rocket.ToString(), Gun.ToString()}; + } + /// + /// Создание продвинутого объекта из массива строк + /// + /// + /// + public static EntityLinkor? CreateEntityLinkor(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityLinkor)) + { + return null; + } + return new EntityLinkor(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/ProjectAirbus/ProjectAirbus/Entities/EntityShip.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityShip.cs index 41778c8..38482f4 100644 --- a/ProjectAirbus/ProjectAirbus/Entities/EntityShip.cs +++ b/ProjectAirbus/ProjectAirbus/Entities/EntityShip.cs @@ -45,4 +45,28 @@ public class EntityShip Weight = weight; BodyColor = bodyColor; } + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityShip), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityShip? CreateEntityShip(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityShip)) + { + return null; + } + return new EntityShip(Convert.ToInt32(strs[1]), + Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } + } diff --git a/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs index 877b8ea..4793339 100644 --- a/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs +++ b/ProjectAirbus/ProjectAirbus/FormShipCollection.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(752, 0); + groupBoxTools.Location = new Point(752, 33); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(300, 887); + groupBoxTools.Size = new Size(300, 854); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -74,9 +81,9 @@ panelCompanyTools.Controls.Add(buttonRemoveShip); panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Dock = DockStyle.Bottom; - panelCompanyTools.Location = new Point(3, 486); + panelCompanyTools.Location = new Point(3, 479); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(294, 398); + panelCompanyTools.Size = new Size(294, 372); panelCompanyTools.TabIndex = 8; // // buttonAddShip @@ -91,7 +98,7 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(17, 155); + maskedTextBoxPosition.Location = new Point(17, 125); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(264, 31); @@ -101,7 +108,7 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(17, 333); + buttonRefresh.Location = new Point(17, 303); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(264, 60); buttonRefresh.TabIndex = 6; @@ -112,7 +119,7 @@ // buttonRemoveShip // buttonRemoveShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveShip.Location = new Point(17, 201); + buttonRemoveShip.Location = new Point(17, 171); buttonRemoveShip.Name = "buttonRemoveShip"; buttonRemoveShip.Size = new Size(264, 60); buttonRemoveShip.TabIndex = 4; @@ -123,7 +130,7 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(17, 267); + buttonGoToCheck.Location = new Point(17, 237); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(264, 60); buttonGoToCheck.TabIndex = 5; @@ -238,12 +245,53 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 33); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(752, 887); + pictureBox.Size = new Size(752, 854); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(24, 24); + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1052, 33); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip"; + // + // файлToolStripMenuItem + // + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); + файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + файлToolStripMenuItem.Size = new Size(69, 29); + файлToolStripMenuItem.Text = "Файл"; + // + // saveToolStripMenuItem + // + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + saveToolStripMenuItem.Size = new Size(273, 34); + saveToolStripMenuItem.Text = "Сохранение"; + saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; + // + // loadToolStripMenuItem + // + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(273, 34); + loadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; + // // FormShipCollection // AutoScaleDimensions = new SizeF(10F, 25F); @@ -251,6 +299,8 @@ ClientSize = new Size(1052, 887); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormShipCollection"; Text = "Коллекция кораблей"; groupBoxTools.ResumeLayout(false); @@ -259,7 +309,10 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -282,5 +335,11 @@ private RadioButton radioButtonMassive; 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/ProjectAirbus/ProjectAirbus/FormShipCollection.cs b/ProjectAirbus/ProjectAirbus/FormShipCollection.cs index 544c266..53998ff 100644 --- a/ProjectAirbus/ProjectAirbus/FormShipCollection.cs +++ b/ProjectAirbus/ProjectAirbus/FormShipCollection.cs @@ -65,7 +65,7 @@ public partial class FormShipCollection : Form { MessageBox.Show("Не удалось добавить объект"); } - } + } private void ButtonRemoveShip_Click(object sender, EventArgs e) { @@ -233,5 +233,45 @@ public partial class FormShipCollection : Form 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/ProjectAirbus/ProjectAirbus/FormShipCollection.resx b/ProjectAirbus/ProjectAirbus/FormShipCollection.resx index af32865..cfb2cea 100644 --- a/ProjectAirbus/ProjectAirbus/FormShipCollection.resx +++ b/ProjectAirbus/ProjectAirbus/FormShipCollection.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 165, 17 + + + 355, 17 + \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormShipConfig.cs b/ProjectAirbus/ProjectAirbus/FormShipConfig.cs index 14a0701..dc2ea0b 100644 --- a/ProjectAirbus/ProjectAirbus/FormShipConfig.cs +++ b/ProjectAirbus/ProjectAirbus/FormShipConfig.cs @@ -26,7 +26,7 @@ public partial class FormShipConfig : Form /// /// Событие для передачи объекта /// - private event ShipDelegate? ShipDelegate; + private event Action? _shipDelegate; /// /// Конструктор /// @@ -48,9 +48,9 @@ public partial class FormShipConfig : Form /// Привязка внешнего метода и событие /// /// - public void AddEvent(ShipDelegate shipDelegate) + public void AddEvent(Action? shipDelegate) { - ShipDelegate += shipDelegate; + _shipDelegate += shipDelegate; } /// @@ -123,7 +123,7 @@ public partial class FormShipConfig : Form { if (_ship != null) { - ShipDelegate?.Invoke(_ship); + _shipDelegate?.Invoke(_ship); Close(); } }