diff --git a/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs b/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs index 2adcccc..8225125 100644 --- a/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs +++ b/Battleship/Battleship/CollectionGenericObjects/AbstractCompany.cs @@ -1,9 +1,4 @@ using Battleship.Drawnings; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Battleship.CollectionGenericObjects; /// @@ -51,14 +46,14 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// /// Перегрузка оператора сложения для класса /// /// Компания - /// Добавляемый объект + /// Добавляемый объект /// public static int operator +(AbstractCompany company, DrawningShip ship) { diff --git a/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs b/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs index a500b27..443e1bd 100644 --- a/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs +++ b/Battleship/Battleship/CollectionGenericObjects/CollectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectSportCar.CollectionGenericObjects; +namespace Battleship.CollectionGenericObjects; /// /// Тип коллекции diff --git a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs index bd3f705..73a6aef 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Battleship.CollectionGenericObjects; +namespace Battleship.CollectionGenericObjects; /// /// Интерфейс описания действий для набора хранимых объектов @@ -20,7 +15,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -41,7 +36,7 @@ public interface ICollectionGenericObjects /// /// Позиция /// true - удачно, false - удаление не удалось - T? Remove(int position); + T Remove(int position); /// /// Получение объекта по позиции @@ -49,4 +44,14 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); -} \ No newline at end of file + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); +} diff --git a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs index 1a773bd..05cd404 100644 --- a/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/ListGenericObjects.cs @@ -1,11 +1,4 @@ -using System; -using System.CodeDom.Compiler; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Battleship.CollectionGenericObjects; +namespace Battleship.CollectionGenericObjects; public class ListGenericObjects : ICollectionGenericObjects where T : class @@ -14,12 +7,28 @@ public class ListGenericObjects : ICollectionGenericObjects /// Список объектов, которые храним /// private readonly List _collection; + /// /// Максимально допустимое число объектов в списке /// private int _maxCount; + 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; + /// /// Конструктор /// @@ -27,12 +36,14 @@ public class ListGenericObjects : ICollectionGenericObjects { _collection = new(); } + public T? Get(int position) { if (position < 0 || position >= _collection.Count) return null; return _collection[position]; } + public int Insert(T obj) { if (_collection.Count + 1 <= _maxCount) @@ -42,19 +53,29 @@ public class ListGenericObjects : ICollectionGenericObjects } return -1; } + public bool Insert(T obj, int position) { - if (_collection.Count + 1 > _maxCount || position < 0 || position >= _collection.Count) + if (_collection.Count + 1 > _maxCount || position < 0 || position >= _collection.Count) return false; _collection.Insert(position, obj); return true; } - public T? Remove(int position) + + public T Remove(int position) { if (position < 0 || position >= _collection.Count) return null; - T? temp = _collection[position]; + T temp = _collection[position]; _collection.RemoveAt(position); return temp; } -} \ No newline at end of file + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } +} diff --git a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs index 23e085a..6f35a82 100644 --- a/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Battleship/Battleship/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,11 +1,4 @@ -using Battleship.Drawnings; -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Battleship.CollectionGenericObjects; +namespace Battleship.CollectionGenericObjects; /// /// Параметризованный набор объектов /// @@ -21,8 +14,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects /// /// Установка максимального кол-ва объектов /// - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -39,6 +36,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -57,7 +56,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects return null; return _collection[position]; } - public int Insert(T obj) + public int Insert(T obj) //??? Уточнить реализацию { for (int i = 0; i < _collection.Length; i++) { @@ -69,7 +68,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects } return -1; } - public bool Insert(T obj, int position) { if (position < 0 || position >= _collection.Length) // проверка позиции @@ -98,13 +96,21 @@ public class MassiveGenericObjects : ICollectionGenericObjects return false; } - public T? Remove(int position) + public T Remove(int position) { - if (position < 0 || position >= _collection.Length || _collection[position] == null) // проверка позиции и наличия объекта + if (position < 0 || position >= _collection.Length || _collection[position]==null) // проверка позиции и наличия объекта return null; - T? temp = _collection[position]; + T temp = _collection[position]; _collection[position] = null; return temp; } -} \ No newline at end of file + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } +} diff --git a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs index 1aeddf1..a336f91 100644 --- a/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs +++ b/Battleship/Battleship/CollectionGenericObjects/StorageCollection.cs @@ -1,70 +1,205 @@ -using Battleship.CollectionGenericObjects; -namespace ProjectSportCar.CollectionGenericObjects; +using Battleship.Drawnings; +using System.Text; + +namespace Battleship.CollectionGenericObjects; /// /// Класс-хранилище коллекций /// /// public class StorageCollection - where T : class + where T : DrawningShip { + /// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> _storages; + + /// + /// Возвращение списка названий коллекций + /// + public List Keys => _storages.Keys.ToList(); + /// - /// Словарь (хранилище) с коллекциями + /// Ключевое слово, с которого должен начинаться файл /// - readonly Dictionary> _storages; + private readonly string _collectionKey = "CollectionsStorage"; + /// - /// Возвращение списка названий коллекций + /// Разделитель для записи ключа и значения элемента словаря /// - public List Keys => _storages.Keys.ToList(); + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// public StorageCollection() - { - _storages = new Dictionary>(); - } - /// - /// Добавление коллекции в хранилище - /// - /// Название коллекции - /// тип коллекции - public void AddCollection(string name, CollectionType collectionType) - { - if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) - return; - switch (collectionType) - { - case CollectionType.List: + { + _storages = new Dictionary>(); + } + + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// тип коллекции + public void AddCollection(string name, CollectionType collectionType) + { + if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) + return; + switch (collectionType) + { + case CollectionType.List: _storages.Add(name, new ListGenericObjects()); - break; + break; case CollectionType.Massive: _storages.Add(name, new MassiveGenericObjects()); - break; - default: - break; + break; + default: + break; } } + /// /// Удаление коллекции /// /// Название коллекции public void DelCollection(string name) - { - if (_storages.ContainsKey(name)) - _storages.Remove(name); - } + { + if (_storages.ContainsKey(name)) //??? спрросить, зачем проверка + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (_storages.TryGetValue(name, out ICollectionGenericObjects? value)) + return value; + return null; + } + } /// - /// Доступ к коллекции + /// Сохранение информации по кораблям в хранилище в файл /// - /// Название коллекции - /// - public ICollectionGenericObjects? this[string name] + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) { - get + if (_storages.Count == 0) { - if (_storages.TryGetValue(name, out ICollectionGenericObjects? value)) - return value; - return null; + return false; } + + if (File.Exists(filename)) + { + File.Delete(filename); + } + + StringBuilder sb = new(); + + using (StreamWriter sw = new StreamWriter(filename)) + { + sw.WriteLine(_collectionKey.ToString()); + foreach (KeyValuePair> kvpair in _storages) + { + // не сохраняем пустые коллекции + if (kvpair.Value.Count == 0) + continue; + sb.Append(kvpair.Key); + sb.Append(_separatorForKeyValue); + sb.Append(kvpair.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(kvpair.Value.MaxCount); + sb.Append(_separatorForKeyValue); + foreach (T? item in kvpair.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + continue; + sb.Append(data); + sb.Append(_separatorItems); + } + sw.WriteLine(sb.ToString()); + sb.Clear(); + } + } + return true; } + + /// + /// Загрузка информации по кораблям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + + using (StreamReader sr = new StreamReader(filename)) + { + string? str; + str = sr.ReadLine(); + if (str != _collectionKey.ToString()) + return false; + _storages.Clear(); + while ((str = sr.ReadLine()) != null) + { + string[] record = str.Split(_separatorForKeyValue); + 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?.CreateDrawningShip() 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, + }; + } + } \ No newline at end of file diff --git a/Battleship/Battleship/Drawnings/DrawningBattleship.cs b/Battleship/Battleship/Drawnings/DrawningBattleship.cs index 2bc5fdb..9aefc14 100644 --- a/Battleship/Battleship/Drawnings/DrawningBattleship.cs +++ b/Battleship/Battleship/Drawnings/DrawningBattleship.cs @@ -9,6 +9,14 @@ namespace Battleship.Drawnings; // класс прорисовки и пермещения public class DrawningBattleship : DrawningShip { + /// + /// Конструктор через сущность + /// + /// Объект класса-сущность + public DrawningBattleship(EntityShip ship) : base(143, 75) + { + EntityShip = ship; + } /// /// Конструктор /// diff --git a/Battleship/Battleship/Drawnings/DrawningShip.cs b/Battleship/Battleship/Drawnings/DrawningShip.cs index 8ed7510..3718b58 100644 --- a/Battleship/Battleship/Drawnings/DrawningShip.cs +++ b/Battleship/Battleship/Drawnings/DrawningShip.cs @@ -64,6 +64,15 @@ public class DrawningShip _drawningShipHeight = drawningShipHeight; _drawningShipWidth = drawningShipWidth; } + /// + /// Конструктор через сущность + /// + /// объект класса-сущность + public DrawningShip(EntityShip ship) : this() + { + EntityShip = ship; + } + public bool SetPictureSize(int width, int height) // установка размеров окна { if (width > _drawningShipWidth && height > _drawningShipHeight) //если размеры окна позволяют вместить корабль, то присваиваем diff --git a/Battleship/Battleship/Drawnings/ExtentionDrawningShip.cs b/Battleship/Battleship/Drawnings/ExtentionDrawningShip.cs new file mode 100644 index 0000000..5ec263e --- /dev/null +++ b/Battleship/Battleship/Drawnings/ExtentionDrawningShip.cs @@ -0,0 +1,51 @@ +using Battleship.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship.Drawnings; +public static class ExtentionDrawningShip +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningShip? CreateDrawningShip(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityShip? ship = EntityBattleship.CreateEntityBattleship(strs); + if (ship != null) + { + return new DrawningBattleship(ship); + } + ship = EntityShip.CreateEntityShip(strs); + if (ship != null) + { + return new DrawningShip(ship); + } + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningShip drawningShip) + { + string[]? array = drawningShip?.EntityShip?.GetStringRepresentation(); + if (array == null) + { + return string.Empty; + } + return string.Join(_separatorForObject, array); + } +} diff --git a/Battleship/Battleship/Entities/EntityBattleship.cs b/Battleship/Battleship/Entities/EntityBattleship.cs index 09e5600..212897f 100644 --- a/Battleship/Battleship/Entities/EntityBattleship.cs +++ b/Battleship/Battleship/Entities/EntityBattleship.cs @@ -34,4 +34,25 @@ public class EntityBattleship : EntityShip { AdditionalColor = addColor ?? AdditionalColor; } + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityBattleship), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Weapon.ToString(), Rockets.ToString() }; + } + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityBattleship? CreateEntityBattleship(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityBattleship)) + { + return null; + } + return new EntityBattleship(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/Battleship/Battleship/Entities/EntityShip.cs b/Battleship/Battleship/Entities/EntityShip.cs index a7b9b2a..bfada95 100644 --- a/Battleship/Battleship/Entities/EntityShip.cs +++ b/Battleship/Battleship/Entities/EntityShip.cs @@ -33,4 +33,26 @@ public class EntityShip { BodyColor = color ?? 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])); + } } \ No newline at end of file diff --git a/Battleship/Battleship/FormShipCollection.Designer.cs b/Battleship/Battleship/FormShipCollection.Designer.cs index d98eb94..af1d2dd 100644 --- a/Battleship/Battleship/FormShipCollection.Designer.cs +++ b/Battleship/Battleship/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(); Tools.SuspendLayout(); panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + menuStrip.SuspendLayout(); SuspendLayout(); // // Tools @@ -59,9 +66,9 @@ Tools.Controls.Add(panelStorage); Tools.Controls.Add(comboBoxSelectorCompany); Tools.Dock = DockStyle.Right; - Tools.Location = new Point(1605, 0); + Tools.Location = new Point(1605, 40); Tools.Name = "Tools"; - Tools.Size = new Size(488, 1236); + Tools.Size = new Size(488, 1224); Tools.TabIndex = 0; Tools.TabStop = false; Tools.Text = "Инструменты"; @@ -240,19 +247,62 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 40); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1605, 1236); + pictureBox.Size = new Size(1605, 1224); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(32, 32); + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(2093, 40); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip"; + // + // файлToolStripMenuItem + // + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); + файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + файлToolStripMenuItem.Size = new Size(90, 36); + файлToolStripMenuItem.Text = "Файл"; + // + // saveToolStripMenuItem + // + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + saveToolStripMenuItem.Size = new Size(343, 44); + saveToolStripMenuItem.Text = "Сохранить"; + saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; + // + // loadToolStripMenuItem + // + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(343, 44); + loadToolStripMenuItem.Text = "Загрузить"; + loadToolStripMenuItem.Click += loadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; + // // FormShipCollection // AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(2093, 1236); + ClientSize = new Size(2093, 1264); Controls.Add(pictureBox); Controls.Add(Tools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormShipCollection"; Text = "Коллекция кораблей"; Tools.ResumeLayout(false); @@ -261,7 +311,10 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -284,5 +337,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/Battleship/Battleship/FormShipCollection.cs b/Battleship/Battleship/FormShipCollection.cs index 33cc580..bd2fa9a 100644 --- a/Battleship/Battleship/FormShipCollection.cs +++ b/Battleship/Battleship/FormShipCollection.cs @@ -1,15 +1,6 @@ using Battleship.CollectionGenericObjects; using Battleship.Drawnings; -using ProjectSportCar.CollectionGenericObjects; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; + namespace Battleship; @@ -236,5 +227,43 @@ public partial class FormShipCollection : Form } #endregion - + /// + /// Обработка кнопки сохранения + /// + /// + /// + 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)) + { + RerfreshListBoxItems(); + MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Загрузка не выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } diff --git a/Battleship/Battleship/FormShipCollection.resx b/Battleship/Battleship/FormShipCollection.resx index af32865..9340a84 100644 --- a/Battleship/Battleship/FormShipCollection.resx +++ b/Battleship/Battleship/FormShipCollection.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 204, 17 + + + 447, 17 + + + 25 + \ No newline at end of file