Лабораторная работа №4
This commit is contained in:
parent
3ac1dab1c9
commit
56593b237c
@ -24,6 +24,9 @@ public abstract class AbstractCompany
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected int _pictureHeight;
|
protected int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Коллекция объектов
|
||||||
|
/// </summary>
|
||||||
protected ICollectionGenericObjects<DrawingWarship>? _collection = null;
|
protected ICollectionGenericObjects<DrawingWarship>? _collection = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,7 +34,6 @@ public abstract class AbstractCompany
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight) + 2;
|
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight) + 2;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
namespace Battleship.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Тип коллекции
|
||||||
|
/// </summary>
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неопределено
|
||||||
|
/// </summary>
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Массив
|
||||||
|
/// </summary>
|
||||||
|
Massive = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Список
|
||||||
|
/// </summary>
|
||||||
|
List = 2
|
||||||
|
}
|
@ -6,7 +6,6 @@
|
|||||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
public interface ICollectionGenericObjects<T>
|
public interface ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в коллекции
|
/// Количество объектов в коллекции
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
namespace Battleship.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Список объектов, которые храним
|
||||||
|
/// </summary>
|
||||||
|
private readonly List<T?> _collection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Максимально допустимое число объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
private int _maxCount;
|
||||||
|
|
||||||
|
public int Count => _collection.Count;
|
||||||
|
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public ListGenericObjects()
|
||||||
|
{
|
||||||
|
_collection = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
return null;
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO вставка по позиции
|
||||||
|
if (Count == _maxCount) return -1;
|
||||||
|
_collection.Add(obj);
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO вставка по позиции
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (Count == _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
_collection.Insert(position, obj);
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO удаление объекта из списка
|
||||||
|
if (position >= Count || position < 0)
|
||||||
|
return null;
|
||||||
|
T obj = _collection[position];
|
||||||
|
_collection.RemoveAt(position);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
using Battleship.CollectionGenericObjects;
|
namespace Battleship.CollectionGenericObjects;
|
||||||
|
|
||||||
//namespace Battleship.CollectionGenericObjects;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметризованный набор объектов
|
/// Параметризованный набор объектов
|
||||||
@ -16,7 +14,23 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public int Count => _collection.Length;
|
public int Count => _collection.Length;
|
||||||
|
|
||||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
public int SetMaxCount
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
if (Count > 0)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _collection, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_collection = new T?[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -26,7 +40,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
if (position >= _collection.Length || position < 0)
|
if (position >= _collection.Length || position < 0)
|
||||||
@ -47,7 +61,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
_collection[index] = obj;
|
_collection[index] = obj;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
index++;
|
++index;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -61,48 +75,42 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
// TODO вставка
|
// TODO вставка
|
||||||
if (position >= _collection.Length || position < 0)
|
if (position >= _collection.Length || position < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (_collection[position] == null)
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
|
||||||
if (_collection[position] != null)
|
|
||||||
{
|
{
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
|
||||||
int nullIndex = -1;
|
|
||||||
for (int i = position + 1; i < Count; i++)
|
|
||||||
{
|
|
||||||
if (_collection[i] == null)
|
|
||||||
{
|
|
||||||
nullIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Если пустого элемента нет, то выходим
|
|
||||||
if (nullIndex < 0)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
|
||||||
int j = nullIndex - 1;
|
|
||||||
while (j >= position)
|
|
||||||
{
|
|
||||||
_collection[j + 1] = _collection[j];
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO вставка по позиции
|
|
||||||
_collection[position] = obj;
|
_collection[position] = obj;
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
int index = position + 1;
|
||||||
|
while (index < _collection.Length)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
index = position - 1;
|
||||||
|
while (index >= 0)
|
||||||
|
{
|
||||||
|
if (_collection[index] == null)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
--index;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
if (position >= _collection.Length || position < 0)
|
if (position >= _collection.Length || position < 0)
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
T obj = _collection[position];
|
||||||
T temp = _collection[position];
|
|
||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return temp;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
namespace Battleship.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-хранилище коллекций
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class StorageCollection<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище) с коллекциями
|
||||||
|
/// </summary>
|
||||||
|
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий коллекции
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _storages.Keys.ToList();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public StorageCollection()
|
||||||
|
{
|
||||||
|
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление коллекции в хранилище
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <param name="collectionType">Тип коллекции</param>
|
||||||
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
|
{
|
||||||
|
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||||
|
if (_storages.ContainsKey(name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
if (collectionType == CollectionType.List)
|
||||||
|
{
|
||||||
|
_storages.Add(name, new ListGenericObjects<T>());
|
||||||
|
}
|
||||||
|
if (collectionType == CollectionType.Massive)
|
||||||
|
{
|
||||||
|
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
public void DelCollection(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления коллекции
|
||||||
|
if (!_storages.ContainsKey(name))
|
||||||
|
return;
|
||||||
|
_storages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ICollectionGenericObjects<T> this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения объекта
|
||||||
|
if (_storages.ContainsKey((string)name))
|
||||||
|
{
|
||||||
|
return _storages[name];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
259
Battleship/Battleship/FormWarshipCollection.Designer.cs
generated
259
Battleship/Battleship/FormWarshipCollection.Designer.cs
generated
@ -29,138 +29,261 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
|
panelCompanyTools = new Panel();
|
||||||
buttonRefresh = new Button();
|
buttonRefresh = new Button();
|
||||||
|
maskedTextBox1 = new MaskedTextBox();
|
||||||
buttonGoToCheck = new Button();
|
buttonGoToCheck = new Button();
|
||||||
|
buttonAddWarship = new Button();
|
||||||
buttonRemoveWarship = new Button();
|
buttonRemoveWarship = new Button();
|
||||||
buttonAddBattleship = new Button();
|
buttonAddBattleship = new Button();
|
||||||
buttonAddWarship = new Button();
|
panelStorage = new Panel();
|
||||||
comboBoxSelectionCompany = new ComboBox();
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
buttonCollectionDel = new Button();
|
||||||
|
buttonCreateCompany = new Button();
|
||||||
|
listBoxCollection = new ListBox();
|
||||||
|
buttonCollectionAdd = new Button();
|
||||||
|
radioButtonList = new RadioButton();
|
||||||
|
radioButtonMassive = new RadioButton();
|
||||||
|
textBoxCollectionName = new TextBox();
|
||||||
|
labelCollectionName = new Label();
|
||||||
pictureBox = new PictureBox();
|
pictureBox = new PictureBox();
|
||||||
maskedTextBox1 = new MaskedTextBox();
|
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
|
panelCompanyTools.SuspendLayout();
|
||||||
|
panelStorage.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
groupBoxTools.Controls.Add(maskedTextBox1);
|
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||||
groupBoxTools.Controls.Add(buttonRefresh);
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
|
||||||
groupBoxTools.Controls.Add(buttonRemoveWarship);
|
|
||||||
groupBoxTools.Controls.Add(buttonAddBattleship);
|
|
||||||
groupBoxTools.Controls.Add(buttonAddWarship);
|
|
||||||
groupBoxTools.Controls.Add(comboBoxSelectionCompany);
|
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(861, 0);
|
groupBoxTools.Location = new Point(876, 0);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(292, 583);
|
groupBoxTools.Size = new Size(292, 656);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// panelCompanyTools
|
||||||
|
//
|
||||||
|
panelCompanyTools.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
|
panelCompanyTools.Controls.Add(maskedTextBox1);
|
||||||
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
|
panelCompanyTools.Controls.Add(buttonAddWarship);
|
||||||
|
panelCompanyTools.Controls.Add(buttonRemoveWarship);
|
||||||
|
panelCompanyTools.Controls.Add(buttonAddBattleship);
|
||||||
|
panelCompanyTools.Location = new Point(6, 374);
|
||||||
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
|
panelCompanyTools.Size = new Size(283, 276);
|
||||||
|
panelCompanyTools.TabIndex = 10;
|
||||||
|
//
|
||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRefresh.Location = new Point(12, 477);
|
buttonRefresh.Location = new Point(3, 228);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
buttonRefresh.Size = new Size(274, 42);
|
buttonRefresh.Size = new Size(277, 42);
|
||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
buttonRefresh.Text = "Обновить";
|
buttonRefresh.Text = "Обновить";
|
||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
buttonRefresh.Click += ButtonRefresh_Click;
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
//
|
//
|
||||||
|
// maskedTextBox1
|
||||||
|
//
|
||||||
|
maskedTextBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
maskedTextBox1.Location = new Point(3, 99);
|
||||||
|
maskedTextBox1.Mask = "00";
|
||||||
|
maskedTextBox1.Name = "maskedTextBox1";
|
||||||
|
maskedTextBox1.Size = new Size(277, 27);
|
||||||
|
maskedTextBox1.TabIndex = 7;
|
||||||
|
//
|
||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonGoToCheck.Location = new Point(12, 381);
|
buttonGoToCheck.Location = new Point(3, 180);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(274, 42);
|
buttonGoToCheck.Size = new Size(277, 42);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
buttonGoToCheck.Text = "Передать на тесты";
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||||
//
|
//
|
||||||
// buttonRemoveWarship
|
|
||||||
//
|
|
||||||
buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
buttonRemoveWarship.Location = new Point(12, 283);
|
|
||||||
buttonRemoveWarship.Name = "buttonRemoveWarship";
|
|
||||||
buttonRemoveWarship.Size = new Size(274, 42);
|
|
||||||
buttonRemoveWarship.TabIndex = 4;
|
|
||||||
buttonRemoveWarship.Text = "Удалить корабль";
|
|
||||||
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
|
||||||
buttonRemoveWarship.Click += buttonRemoveWarship_Click_1;
|
|
||||||
//
|
|
||||||
// buttonAddBattleship
|
|
||||||
//
|
|
||||||
buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
buttonAddBattleship.Location = new Point(12, 143);
|
|
||||||
buttonAddBattleship.Name = "buttonAddBattleship";
|
|
||||||
buttonAddBattleship.Size = new Size(274, 42);
|
|
||||||
buttonAddBattleship.TabIndex = 2;
|
|
||||||
buttonAddBattleship.Text = "Добавление линкора";
|
|
||||||
buttonAddBattleship.UseVisualStyleBackColor = true;
|
|
||||||
buttonAddBattleship.Click += ButtonAddBattleship_Click;
|
|
||||||
//
|
|
||||||
// buttonAddWarship
|
// buttonAddWarship
|
||||||
//
|
//
|
||||||
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonAddWarship.Location = new Point(12, 95);
|
buttonAddWarship.Location = new Point(3, 3);
|
||||||
buttonAddWarship.Name = "buttonAddWarship";
|
buttonAddWarship.Name = "buttonAddWarship";
|
||||||
buttonAddWarship.Size = new Size(274, 42);
|
buttonAddWarship.Size = new Size(277, 42);
|
||||||
buttonAddWarship.TabIndex = 1;
|
buttonAddWarship.TabIndex = 1;
|
||||||
buttonAddWarship.Text = "Добавление корабля";
|
buttonAddWarship.Text = "Добавление корабля";
|
||||||
buttonAddWarship.UseVisualStyleBackColor = true;
|
buttonAddWarship.UseVisualStyleBackColor = true;
|
||||||
buttonAddWarship.Click += ButtonAddWarship_Click;
|
buttonAddWarship.Click += ButtonAddWarship_Click;
|
||||||
//
|
//
|
||||||
// comboBoxSelectionCompany
|
// buttonRemoveWarship
|
||||||
//
|
//
|
||||||
comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
buttonRemoveWarship.Location = new Point(0, 132);
|
||||||
comboBoxSelectionCompany.FormattingEnabled = true;
|
buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||||
comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" });
|
buttonRemoveWarship.Size = new Size(280, 42);
|
||||||
comboBoxSelectionCompany.Location = new Point(12, 26);
|
buttonRemoveWarship.TabIndex = 4;
|
||||||
comboBoxSelectionCompany.Name = "comboBoxSelectionCompany";
|
buttonRemoveWarship.Text = "Удалить корабль";
|
||||||
comboBoxSelectionCompany.Size = new Size(274, 28);
|
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||||
comboBoxSelectionCompany.TabIndex = 0;
|
buttonRemoveWarship.Click += ButtonRemoveWarship_Click_1;
|
||||||
comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
//
|
||||||
|
// buttonAddBattleship
|
||||||
|
//
|
||||||
|
buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddBattleship.Location = new Point(3, 51);
|
||||||
|
buttonAddBattleship.Name = "buttonAddBattleship";
|
||||||
|
buttonAddBattleship.Size = new Size(277, 42);
|
||||||
|
buttonAddBattleship.TabIndex = 2;
|
||||||
|
buttonAddBattleship.Text = "Добавление линкора";
|
||||||
|
buttonAddBattleship.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddBattleship.Click += ButtonAddBattleship_Click;
|
||||||
|
//
|
||||||
|
// panelStorage
|
||||||
|
//
|
||||||
|
panelStorage.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
panelStorage.Controls.Add(buttonCollectionDel);
|
||||||
|
panelStorage.Controls.Add(buttonCreateCompany);
|
||||||
|
panelStorage.Controls.Add(listBoxCollection);
|
||||||
|
panelStorage.Controls.Add(buttonCollectionAdd);
|
||||||
|
panelStorage.Controls.Add(radioButtonList);
|
||||||
|
panelStorage.Controls.Add(radioButtonMassive);
|
||||||
|
panelStorage.Controls.Add(textBoxCollectionName);
|
||||||
|
panelStorage.Controls.Add(labelCollectionName);
|
||||||
|
panelStorage.Dock = DockStyle.Top;
|
||||||
|
panelStorage.Location = new Point(3, 23);
|
||||||
|
panelStorage.Name = "panelStorage";
|
||||||
|
panelStorage.Size = new Size(286, 345);
|
||||||
|
panelStorage.TabIndex = 8;
|
||||||
|
//
|
||||||
|
// 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(9, 310);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(271, 28);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// buttonCollectionDel
|
||||||
|
//
|
||||||
|
buttonCollectionDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonCollectionDel.Location = new Point(9, 240);
|
||||||
|
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||||
|
buttonCollectionDel.Size = new Size(274, 29);
|
||||||
|
buttonCollectionDel.TabIndex = 6;
|
||||||
|
buttonCollectionDel.Text = "Удаление из коллекции";
|
||||||
|
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||||
|
//
|
||||||
|
// buttonCreateCompany
|
||||||
|
//
|
||||||
|
buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonCreateCompany.Location = new Point(35, 275);
|
||||||
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
|
buttonCreateCompany.Size = new Size(218, 29);
|
||||||
|
buttonCreateCompany.TabIndex = 9;
|
||||||
|
buttonCreateCompany.Text = "Создать компанию";
|
||||||
|
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateCompany.Click += ButtonCreateCompany_Click;
|
||||||
|
//
|
||||||
|
// listBoxCollection
|
||||||
|
//
|
||||||
|
listBoxCollection.FormattingEnabled = true;
|
||||||
|
listBoxCollection.Location = new Point(9, 130);
|
||||||
|
listBoxCollection.Name = "listBoxCollection";
|
||||||
|
listBoxCollection.Size = new Size(274, 104);
|
||||||
|
listBoxCollection.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonCollectionAdd
|
||||||
|
//
|
||||||
|
buttonCollectionAdd.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonCollectionAdd.Location = new Point(9, 95);
|
||||||
|
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||||
|
buttonCollectionAdd.Size = new Size(274, 29);
|
||||||
|
buttonCollectionAdd.TabIndex = 4;
|
||||||
|
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||||
|
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||||
|
//
|
||||||
|
// radioButtonList
|
||||||
|
//
|
||||||
|
radioButtonList.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
|
radioButtonList.AutoSize = true;
|
||||||
|
radioButtonList.Location = new Point(203, 65);
|
||||||
|
radioButtonList.Name = "radioButtonList";
|
||||||
|
radioButtonList.Size = new Size(80, 24);
|
||||||
|
radioButtonList.TabIndex = 3;
|
||||||
|
radioButtonList.TabStop = true;
|
||||||
|
radioButtonList.Text = "Список";
|
||||||
|
radioButtonList.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// radioButtonMassive
|
||||||
|
//
|
||||||
|
radioButtonMassive.AutoSize = true;
|
||||||
|
radioButtonMassive.Location = new Point(9, 65);
|
||||||
|
radioButtonMassive.Name = "radioButtonMassive";
|
||||||
|
radioButtonMassive.Size = new Size(82, 24);
|
||||||
|
radioButtonMassive.TabIndex = 2;
|
||||||
|
radioButtonMassive.TabStop = true;
|
||||||
|
radioButtonMassive.Text = "Массив";
|
||||||
|
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// textBoxCollectionName
|
||||||
|
//
|
||||||
|
textBoxCollectionName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
textBoxCollectionName.Location = new Point(9, 32);
|
||||||
|
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||||
|
textBoxCollectionName.Size = new Size(274, 27);
|
||||||
|
textBoxCollectionName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCollectionName
|
||||||
|
//
|
||||||
|
labelCollectionName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
labelCollectionName.AutoSize = true;
|
||||||
|
labelCollectionName.Location = new Point(67, 9);
|
||||||
|
labelCollectionName.Name = "labelCollectionName";
|
||||||
|
labelCollectionName.Size = new Size(155, 20);
|
||||||
|
labelCollectionName.TabIndex = 0;
|
||||||
|
labelCollectionName.Text = "Название коллекции";
|
||||||
//
|
//
|
||||||
// pictureBox
|
// pictureBox
|
||||||
//
|
//
|
||||||
pictureBox.Dock = DockStyle.Fill;
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
pictureBox.Location = new Point(0, 0);
|
pictureBox.Location = new Point(0, 0);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(861, 583);
|
pictureBox.Size = new Size(876, 656);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
// maskedTextBox1
|
|
||||||
//
|
|
||||||
maskedTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
|
|
||||||
maskedTextBox1.Location = new Point(12, 250);
|
|
||||||
maskedTextBox1.Mask = "00";
|
|
||||||
maskedTextBox1.Name = "maskedTextBox1";
|
|
||||||
maskedTextBox1.Size = new Size(274, 27);
|
|
||||||
maskedTextBox1.TabIndex = 7;
|
|
||||||
//
|
|
||||||
// FormWarshipCollection
|
// FormWarshipCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1153, 583);
|
ClientSize = new Size(1168, 656);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Name = "FormWarshipCollection";
|
Name = "FormWarshipCollection";
|
||||||
Text = "Коллекция кораблей";
|
Text = "Коллекция кораблей";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
groupBoxTools.PerformLayout();
|
panelCompanyTools.ResumeLayout(false);
|
||||||
|
panelCompanyTools.PerformLayout();
|
||||||
|
panelStorage.ResumeLayout(false);
|
||||||
|
panelStorage.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private GroupBox groupBoxTools;
|
private GroupBox groupBoxTools;
|
||||||
private ComboBox comboBoxSelectionCompany;
|
private ComboBox comboBoxSelectorCompany;
|
||||||
private Button buttonAddBattleship;
|
private Button buttonAddBattleship;
|
||||||
private Button buttonAddWarship;
|
private Button buttonAddWarship;
|
||||||
private Button buttonRemoveWarship;
|
private Button buttonRemoveWarship;
|
||||||
@ -168,5 +291,15 @@
|
|||||||
private Button buttonRefresh;
|
private Button buttonRefresh;
|
||||||
private Button buttonGoToCheck;
|
private Button buttonGoToCheck;
|
||||||
private MaskedTextBox maskedTextBox1;
|
private MaskedTextBox maskedTextBox1;
|
||||||
|
private Panel panelStorage;
|
||||||
|
private Label labelCollectionName;
|
||||||
|
private RadioButton radioButtonList;
|
||||||
|
private RadioButton radioButtonMassive;
|
||||||
|
private TextBox textBoxCollectionName;
|
||||||
|
private Button buttonCollectionAdd;
|
||||||
|
private ListBox listBoxCollection;
|
||||||
|
private Button buttonCreateCompany;
|
||||||
|
private Button buttonCollectionDel;
|
||||||
|
private Panel panelCompanyTools;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,11 @@ namespace Battleship;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class FormWarshipCollection : Form
|
public partial class FormWarshipCollection : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Хранилище коллекций
|
||||||
|
/// </summary>
|
||||||
|
private readonly StorageCollection<DrawingWarship> _storageCollection;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Компания
|
/// Компания
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -19,6 +24,7 @@ public partial class FormWarshipCollection : Form
|
|||||||
public FormWarshipCollection()
|
public FormWarshipCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_storageCollection = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -28,12 +34,27 @@ public partial class FormWarshipCollection : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
switch (comboBoxSelectionCompany.Text)
|
panelCompanyTools.Enabled = false;
|
||||||
{
|
|
||||||
case "Хранилище":
|
|
||||||
_company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingWarship>());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление линкора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddBattleship_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingBattleship));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление военного корабля
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddWarship_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingWarship));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -46,6 +67,7 @@ public partial class FormWarshipCollection : Form
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Random random = new();
|
Random random = new();
|
||||||
DrawingWarship drawingWarship;
|
DrawingWarship drawingWarship;
|
||||||
switch (type)
|
switch (type)
|
||||||
@ -57,7 +79,7 @@ public partial class FormWarshipCollection : Form
|
|||||||
drawingWarship = new DrawingBattleship(random.Next(100, 300), random.Next(1000, 3000),
|
drawingWarship = new DrawingBattleship(random.Next(100, 300), random.Next(1000, 3000),
|
||||||
GetColor(random),
|
GetColor(random),
|
||||||
GetColor(random),
|
GetColor(random),
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@ -90,6 +112,35 @@ public partial class FormWarshipCollection : Form
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRemoveWarship_Click_1(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pos = Convert.ToInt32(maskedTextBox1.Text);
|
||||||
|
if (_company - pos != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект удален");
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Передача на тесты
|
/// Передача на тесты
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -122,55 +173,6 @@ public partial class FormWarshipCollection : Form
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление линкора
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonAddBattleship_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CreateObject(nameof(DrawingBattleship));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление военного корабля
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ButtonAddWarship_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CreateObject(nameof(DrawingWarship));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Удаление объекта
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void buttonRemoveWarship_Click_1(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pos = Convert.ToInt32(maskedTextBox1.Text);
|
|
||||||
if (_company - pos != null)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Объект удален");
|
|
||||||
pictureBox.Image = _company.Show();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновление
|
/// Обновление
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -184,4 +186,102 @@ public partial class FormWarshipCollection : Form
|
|||||||
}
|
}
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обновление списка в listBoxCollection
|
||||||
|
/// </summary>
|
||||||
|
private void RerfreshListBoxItems()
|
||||||
|
{
|
||||||
|
listBoxCollection.Items.Clear();
|
||||||
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||||
|
{
|
||||||
|
string? colName = _storageCollection.Keys?[i];
|
||||||
|
if (!string.IsNullOrEmpty(colName))
|
||||||
|
{
|
||||||
|
listBoxCollection.Items.Add(colName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCollectionAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CollectionType collectionType = CollectionType.None;
|
||||||
|
if (radioButtonMassive.Checked)
|
||||||
|
{
|
||||||
|
collectionType = CollectionType.Massive;
|
||||||
|
}
|
||||||
|
else if (radioButtonList.Checked)
|
||||||
|
{
|
||||||
|
collectionType = CollectionType.List;
|
||||||
|
}
|
||||||
|
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||||
|
RerfreshListBoxItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCollectionDel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
// TODO прописать логику удаления элемента из коллекции
|
||||||
|
// нужно убедиться, что есть выбранная коллекция
|
||||||
|
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
||||||
|
// удалить и обновить ListBox
|
||||||
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||||
|
RerfreshListBoxItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание компании
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateCompany_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ICollectionGenericObjects<DrawingWarship>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не проинициализирована");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
panelCompanyTools.Enabled = true;
|
||||||
|
RerfreshListBoxItems();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user