4 лабораторнапя работа
This commit is contained in:
parent
7a26e24c82
commit
b307608955
@ -28,7 +28,7 @@ namespace ProjectCruiser.CollectionGenericObjects
|
|||||||
protected readonly int _pictureHeight;
|
protected readonly int _pictureHeight;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Коллекция автомобилей
|
/// Коллекция крейсеров
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected ICollectionGenericObjects<DrawningCruiser>? _collection = null;
|
protected ICollectionGenericObjects<DrawningCruiser>? _collection = null;
|
||||||
|
|
||||||
|
18
ProjectCruiser/CollectionGenericObjects/CollectionType.cs
Normal file
18
ProjectCruiser/CollectionGenericObjects/CollectionType.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
namespace ProjectCruiser.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неопределено
|
||||||
|
/// </summary>
|
||||||
|
None = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// Массив
|
||||||
|
/// </summary>
|
||||||
|
Massive = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Список
|
||||||
|
/// </summary>
|
||||||
|
List = 2
|
||||||
|
}
|
||||||
|
}
|
@ -11,16 +11,19 @@
|
|||||||
/// Количество объектов в коллекции
|
/// Количество объектов в коллекции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка максимального количества элементов
|
/// Установка максимального количества элементов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int SetMaxCount { set; }
|
int SetMaxCount { set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию
|
/// Добавление объекта в коллекцию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
int Insert(T obj);
|
int Insert(T obj);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,12 +31,14 @@
|
|||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
int Insert(T obj, int position);
|
int Insert(T obj, int position);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
T? Remove(int position);
|
T? Remove(int position);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта по позиции
|
/// Получение объекта по позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
namespace ProjectCruiser.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 вставка в конец набора
|
||||||
|
if (Count == _maxCount) return -1;
|
||||||
|
_collection.Add(obj);
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO вставка по позиции
|
||||||
|
if (Count == _maxCount) return -1;
|
||||||
|
if (position >= Count || position < 0) 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,7 +14,23 @@ namespace ProjectCruiser.CollectionGenericObjects
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private T?[] _collection;
|
private T?[] _collection;
|
||||||
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 (_collection.Length > 0)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _collection, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_collection = new T?[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -27,11 +43,10 @@ namespace ProjectCruiser.CollectionGenericObjects
|
|||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
if (position >= _collection.Length || position < 0)
|
if (position >= _collection.Length || position < 0)
|
||||||
{
|
{ return null; }
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj)
|
||||||
{
|
{
|
||||||
// TODO вставка в свободное место набора
|
// TODO вставка в свободное место набора
|
||||||
@ -43,10 +58,12 @@ namespace ProjectCruiser.CollectionGenericObjects
|
|||||||
_collection[index] = obj;
|
_collection[index] = obj;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
@ -83,15 +100,16 @@ namespace ProjectCruiser.CollectionGenericObjects
|
|||||||
}
|
}
|
||||||
return -1;
|
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 drawningCruiser = _collection[position];
|
T obj = _collection[position];
|
||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return drawningCruiser;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
ProjectCruiser/CollectionGenericObjects/StorageCollection.cs
Normal file
73
ProjectCruiser/CollectionGenericObjects/StorageCollection.cs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
namespace ProjectCruiser.CollectionGenericObjects
|
||||||
|
{
|
||||||
|
// Класс-хранилище коллекций
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
public class StorageCollection<T>
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище) с коллекциями
|
||||||
|
/// </summary>
|
||||||
|
readonly 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 не пустой и нет в словаре записи с таким ключом
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
|
||||||
|
if (_storages.ContainsKey(name)) return;
|
||||||
|
|
||||||
|
if (collectionType == CollectionType.None) return;
|
||||||
|
else if (collectionType == CollectionType.Massive)
|
||||||
|
_storages[name] = new MassiveGenericObjects<T>();
|
||||||
|
else if (collectionType == CollectionType.List)
|
||||||
|
_storages[name] = new ListGenericObjects<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
public void DelCollection(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления коллекции
|
||||||
|
if (_storages.ContainsKey(name))
|
||||||
|
_storages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ICollectionGenericObjects<T>? this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения объекта
|
||||||
|
if (_storages.ContainsKey(name))
|
||||||
|
return _storages[name];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
268
ProjectCruiser/FormCruisersCollection.Designer.cs
generated
268
ProjectCruiser/FormCruisersCollection.Designer.cs
generated
@ -29,93 +29,166 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
maskedTextBoxPosision = new MaskedTextBox();
|
buttonCreateCompany = new Button();
|
||||||
buttonRefresh = new Button();
|
panelStorage = new Panel();
|
||||||
buttonGetToTest = new Button();
|
buttonCollectionDel = new Button();
|
||||||
ButtonRemoveCruiser = new Button();
|
listBoxCollection = new ListBox();
|
||||||
ButtonAddMilitaryCruiser = new Button();
|
buttonCollecctionAdd = new Button();
|
||||||
ButtonAddCruiser = new Button();
|
radioButtonList = new RadioButton();
|
||||||
|
radioButtonMassive = new RadioButton();
|
||||||
|
textBoxCollectionName = new TextBox();
|
||||||
|
labelCollectionName = new Label();
|
||||||
comboBoxSelectorCompany = new ComboBox();
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
|
panelCompanyTools = new Panel();
|
||||||
|
ButtonAddCruiser = new Button();
|
||||||
|
ButtonAddMilitaryCruiser = new Button();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
ButtonRemoveCruiser = new Button();
|
||||||
|
maskedTextBoxPosision = new MaskedTextBox();
|
||||||
|
buttonGetToTest = new Button();
|
||||||
pictureBoxCruiser = new PictureBox();
|
pictureBoxCruiser = new PictureBox();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
|
panelStorage.SuspendLayout();
|
||||||
|
panelCompanyTools.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
groupBoxTools.Controls.Add(maskedTextBoxPosision);
|
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||||
groupBoxTools.Controls.Add(buttonRefresh);
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
groupBoxTools.Controls.Add(buttonGetToTest);
|
|
||||||
groupBoxTools.Controls.Add(ButtonRemoveCruiser);
|
|
||||||
groupBoxTools.Controls.Add(ButtonAddMilitaryCruiser);
|
|
||||||
groupBoxTools.Controls.Add(ButtonAddCruiser);
|
|
||||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(596, 0);
|
groupBoxTools.Location = new Point(583, 0);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(222, 574);
|
groupBoxTools.Size = new Size(222, 653);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "инструменты";
|
groupBoxTools.Text = "инструменты";
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosision
|
// buttonCreateCompany
|
||||||
//
|
//
|
||||||
maskedTextBoxPosision.Location = new Point(20, 229);
|
buttonCreateCompany.Location = new Point(21, 345);
|
||||||
maskedTextBoxPosision.Mask = "00";
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
maskedTextBoxPosision.Name = "maskedTextBoxPosision";
|
buttonCreateCompany.Size = new Size(186, 27);
|
||||||
maskedTextBoxPosision.Size = new Size(186, 27);
|
buttonCreateCompany.TabIndex = 7;
|
||||||
maskedTextBoxPosision.TabIndex = 2;
|
buttonCreateCompany.Text = "Создать компанию";
|
||||||
maskedTextBoxPosision.ValidatingType = typeof(int);
|
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateCompany.Click += ButtonCreateCompany_Click;
|
||||||
//
|
//
|
||||||
// buttonRefresh
|
// panelStorage
|
||||||
//
|
//
|
||||||
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
panelStorage.Controls.Add(buttonCollectionDel);
|
||||||
buttonRefresh.Location = new Point(20, 479);
|
panelStorage.Controls.Add(listBoxCollection);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
panelStorage.Controls.Add(buttonCollecctionAdd);
|
||||||
buttonRefresh.Size = new Size(186, 40);
|
panelStorage.Controls.Add(radioButtonList);
|
||||||
buttonRefresh.TabIndex = 5;
|
panelStorage.Controls.Add(radioButtonMassive);
|
||||||
buttonRefresh.Text = "обновить";
|
panelStorage.Controls.Add(textBoxCollectionName);
|
||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
panelStorage.Controls.Add(labelCollectionName);
|
||||||
buttonRefresh.Click += ButtonRefresh_Click;
|
panelStorage.Dock = DockStyle.Top;
|
||||||
|
panelStorage.Location = new Point(3, 23);
|
||||||
|
panelStorage.Name = "panelStorage";
|
||||||
|
panelStorage.Size = new Size(216, 283);
|
||||||
|
panelStorage.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// buttonGetToTest
|
// buttonCollectionDel
|
||||||
//
|
//
|
||||||
buttonGetToTest.Anchor = AnchorStyles.Right;
|
buttonCollectionDel.Location = new Point(17, 247);
|
||||||
buttonGetToTest.Location = new Point(20, 366);
|
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||||
buttonGetToTest.Name = "buttonGetToTest";
|
buttonCollectionDel.Size = new Size(186, 27);
|
||||||
buttonGetToTest.Size = new Size(186, 40);
|
buttonCollectionDel.TabIndex = 6;
|
||||||
buttonGetToTest.TabIndex = 4;
|
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||||
buttonGetToTest.Text = "передать на тесты";
|
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||||
buttonGetToTest.UseVisualStyleBackColor = true;
|
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||||
buttonGetToTest.Click += ButtonGetToTest_Click;
|
|
||||||
//
|
//
|
||||||
// ButtonRemoveCruiser
|
// listBoxCollection
|
||||||
//
|
//
|
||||||
ButtonRemoveCruiser.Anchor = AnchorStyles.Right;
|
listBoxCollection.FormattingEnabled = true;
|
||||||
ButtonRemoveCruiser.Location = new Point(20, 271);
|
listBoxCollection.ItemHeight = 20;
|
||||||
ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
|
listBoxCollection.Location = new Point(17, 137);
|
||||||
ButtonRemoveCruiser.Size = new Size(186, 40);
|
listBoxCollection.Name = "listBoxCollection";
|
||||||
ButtonRemoveCruiser.TabIndex = 3;
|
listBoxCollection.Size = new Size(186, 104);
|
||||||
ButtonRemoveCruiser.Text = "удалить крейсер";
|
listBoxCollection.TabIndex = 5;
|
||||||
ButtonRemoveCruiser.UseVisualStyleBackColor = true;
|
|
||||||
ButtonRemoveCruiser.Click += ButtonRemoveCruiser_Click;
|
|
||||||
//
|
//
|
||||||
// ButtonAddMilitaryCruiser
|
// buttonCollecctionAdd
|
||||||
//
|
//
|
||||||
ButtonAddMilitaryCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonCollecctionAdd.Location = new Point(17, 104);
|
||||||
ButtonAddMilitaryCruiser.Location = new Point(20, 152);
|
buttonCollecctionAdd.Name = "buttonCollecctionAdd";
|
||||||
ButtonAddMilitaryCruiser.Name = "ButtonAddMilitaryCruiser";
|
buttonCollecctionAdd.Size = new Size(186, 27);
|
||||||
ButtonAddMilitaryCruiser.Size = new Size(186, 50);
|
buttonCollecctionAdd.TabIndex = 4;
|
||||||
ButtonAddMilitaryCruiser.TabIndex = 2;
|
buttonCollecctionAdd.Text = "Добавить коллекцию";
|
||||||
ButtonAddMilitaryCruiser.Text = "добваление военного крейсера";
|
buttonCollecctionAdd.UseVisualStyleBackColor = true;
|
||||||
ButtonAddMilitaryCruiser.UseVisualStyleBackColor = true;
|
buttonCollecctionAdd.Click += ButtonCollecctionAdd_Click;
|
||||||
ButtonAddMilitaryCruiser.Click += ButtonAddMilitaryCruiser_Click;
|
//
|
||||||
|
// radioButtonList
|
||||||
|
//
|
||||||
|
radioButtonList.AutoSize = true;
|
||||||
|
radioButtonList.Location = new Point(123, 75);
|
||||||
|
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(17, 75);
|
||||||
|
radioButtonMassive.Name = "radioButtonMassive";
|
||||||
|
radioButtonMassive.Size = new Size(82, 24);
|
||||||
|
radioButtonMassive.TabIndex = 2;
|
||||||
|
radioButtonMassive.TabStop = true;
|
||||||
|
radioButtonMassive.Text = "Массив";
|
||||||
|
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// textBoxCollectionName
|
||||||
|
//
|
||||||
|
textBoxCollectionName.Location = new Point(17, 32);
|
||||||
|
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||||
|
textBoxCollectionName.Size = new Size(186, 27);
|
||||||
|
textBoxCollectionName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCollectionName
|
||||||
|
//
|
||||||
|
labelCollectionName.AutoSize = true;
|
||||||
|
labelCollectionName.Location = new Point(26, 9);
|
||||||
|
labelCollectionName.Name = "labelCollectionName";
|
||||||
|
labelCollectionName.Size = new Size(155, 20);
|
||||||
|
labelCollectionName.TabIndex = 0;
|
||||||
|
labelCollectionName.Text = "Название коллекции";
|
||||||
|
//
|
||||||
|
// comboBoxSelectorCompany
|
||||||
|
//
|
||||||
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
|
comboBoxSelectorCompany.Location = new Point(21, 311);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(186, 28);
|
||||||
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
|
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
|
||||||
|
//
|
||||||
|
// panelCompanyTools
|
||||||
|
//
|
||||||
|
panelCompanyTools.Controls.Add(ButtonAddCruiser);
|
||||||
|
panelCompanyTools.Controls.Add(ButtonAddMilitaryCruiser);
|
||||||
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
|
panelCompanyTools.Controls.Add(ButtonRemoveCruiser);
|
||||||
|
panelCompanyTools.Controls.Add(maskedTextBoxPosision);
|
||||||
|
panelCompanyTools.Controls.Add(buttonGetToTest);
|
||||||
|
panelCompanyTools.Enabled = false;
|
||||||
|
panelCompanyTools.Location = new Point(3, 379);
|
||||||
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
|
panelCompanyTools.Size = new Size(216, 274);
|
||||||
|
panelCompanyTools.TabIndex = 8;
|
||||||
//
|
//
|
||||||
// ButtonAddCruiser
|
// ButtonAddCruiser
|
||||||
//
|
//
|
||||||
ButtonAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
ButtonAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
ButtonAddCruiser.BackgroundImageLayout = ImageLayout.Center;
|
ButtonAddCruiser.BackgroundImageLayout = ImageLayout.Center;
|
||||||
ButtonAddCruiser.Location = new Point(20, 106);
|
ButtonAddCruiser.Location = new Point(18, 3);
|
||||||
ButtonAddCruiser.Name = "ButtonAddCruiser";
|
ButtonAddCruiser.Name = "ButtonAddCruiser";
|
||||||
ButtonAddCruiser.Size = new Size(186, 40);
|
ButtonAddCruiser.Size = new Size(186, 40);
|
||||||
ButtonAddCruiser.TabIndex = 1;
|
ButtonAddCruiser.TabIndex = 1;
|
||||||
@ -123,23 +196,65 @@
|
|||||||
ButtonAddCruiser.UseVisualStyleBackColor = true;
|
ButtonAddCruiser.UseVisualStyleBackColor = true;
|
||||||
ButtonAddCruiser.Click += ButtonAddCruiser_Click;
|
ButtonAddCruiser.Click += ButtonAddCruiser_Click;
|
||||||
//
|
//
|
||||||
// comboBoxSelectorCompany
|
// ButtonAddMilitaryCruiser
|
||||||
//
|
//
|
||||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
ButtonAddMilitaryCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
ButtonAddMilitaryCruiser.Location = new Point(18, 49);
|
||||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" });
|
ButtonAddMilitaryCruiser.Name = "ButtonAddMilitaryCruiser";
|
||||||
comboBoxSelectorCompany.Location = new Point(20, 26);
|
ButtonAddMilitaryCruiser.Size = new Size(186, 51);
|
||||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
ButtonAddMilitaryCruiser.TabIndex = 2;
|
||||||
comboBoxSelectorCompany.Size = new Size(186, 28);
|
ButtonAddMilitaryCruiser.Text = "добваление военного крейсера";
|
||||||
comboBoxSelectorCompany.TabIndex = 0;
|
ButtonAddMilitaryCruiser.UseVisualStyleBackColor = true;
|
||||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
|
ButtonAddMilitaryCruiser.Click += ButtonAddMilitaryCruiser_Click;
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRefresh.Location = new Point(18, 227);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(186, 41);
|
||||||
|
buttonRefresh.TabIndex = 5;
|
||||||
|
buttonRefresh.Text = "обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveCruiser
|
||||||
|
//
|
||||||
|
ButtonRemoveCruiser.Anchor = AnchorStyles.Right;
|
||||||
|
ButtonRemoveCruiser.Location = new Point(18, 138);
|
||||||
|
ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
|
||||||
|
ButtonRemoveCruiser.Size = new Size(186, 40);
|
||||||
|
ButtonRemoveCruiser.TabIndex = 3;
|
||||||
|
ButtonRemoveCruiser.Text = "удалить крейсер";
|
||||||
|
ButtonRemoveCruiser.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveCruiser.Click += ButtonRemoveCruiser_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosision
|
||||||
|
//
|
||||||
|
maskedTextBoxPosision.Location = new Point(17, 105);
|
||||||
|
maskedTextBoxPosision.Mask = "00";
|
||||||
|
maskedTextBoxPosision.Name = "maskedTextBoxPosision";
|
||||||
|
maskedTextBoxPosision.Size = new Size(187, 27);
|
||||||
|
maskedTextBoxPosision.TabIndex = 2;
|
||||||
|
maskedTextBoxPosision.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonGetToTest
|
||||||
|
//
|
||||||
|
buttonGetToTest.Anchor = AnchorStyles.Right;
|
||||||
|
buttonGetToTest.Location = new Point(18, 184);
|
||||||
|
buttonGetToTest.Name = "buttonGetToTest";
|
||||||
|
buttonGetToTest.Size = new Size(186, 40);
|
||||||
|
buttonGetToTest.TabIndex = 4;
|
||||||
|
buttonGetToTest.Text = "передать на тесты";
|
||||||
|
buttonGetToTest.UseVisualStyleBackColor = true;
|
||||||
|
buttonGetToTest.Click += ButtonGetToTest_Click;
|
||||||
//
|
//
|
||||||
// pictureBoxCruiser
|
// pictureBoxCruiser
|
||||||
//
|
//
|
||||||
pictureBoxCruiser.Dock = DockStyle.Fill;
|
pictureBoxCruiser.Dock = DockStyle.Fill;
|
||||||
pictureBoxCruiser.Location = new Point(0, 0);
|
pictureBoxCruiser.Location = new Point(0, 0);
|
||||||
pictureBoxCruiser.Name = "pictureBoxCruiser";
|
pictureBoxCruiser.Name = "pictureBoxCruiser";
|
||||||
pictureBoxCruiser.Size = new Size(596, 574);
|
pictureBoxCruiser.Size = new Size(583, 653);
|
||||||
pictureBoxCruiser.TabIndex = 1;
|
pictureBoxCruiser.TabIndex = 1;
|
||||||
pictureBoxCruiser.TabStop = false;
|
pictureBoxCruiser.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -147,13 +262,16 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(818, 574);
|
ClientSize = new Size(805, 653);
|
||||||
Controls.Add(pictureBoxCruiser);
|
Controls.Add(pictureBoxCruiser);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Name = "FormCruisersCollection";
|
Name = "FormCruisersCollection";
|
||||||
Text = "FormCruisersCollection";
|
Text = "FormCruisersCollection";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
groupBoxTools.PerformLayout();
|
panelStorage.ResumeLayout(false);
|
||||||
|
panelStorage.PerformLayout();
|
||||||
|
panelCompanyTools.ResumeLayout(false);
|
||||||
|
panelCompanyTools.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -169,5 +287,15 @@
|
|||||||
private Button buttonGetToTest;
|
private Button buttonGetToTest;
|
||||||
private PictureBox pictureBoxCruiser;
|
private PictureBox pictureBoxCruiser;
|
||||||
private MaskedTextBox maskedTextBoxPosision;
|
private MaskedTextBox maskedTextBoxPosision;
|
||||||
|
private Panel panelStorage;
|
||||||
|
private TextBox textBoxCollectionName;
|
||||||
|
private Label labelCollectionName;
|
||||||
|
private ListBox listBoxCollection;
|
||||||
|
private Button buttonCollecctionAdd;
|
||||||
|
private RadioButton radioButtonList;
|
||||||
|
private RadioButton radioButtonMassive;
|
||||||
|
private Button buttonCreateCompany;
|
||||||
|
private Button buttonCollectionDel;
|
||||||
|
private Panel panelCompanyTools;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,16 +5,23 @@ namespace ProjectCruiser
|
|||||||
{
|
{
|
||||||
public partial class FormCruisersCollection : Form
|
public partial class FormCruisersCollection : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Хранилише коллекций
|
||||||
|
/// </summary>
|
||||||
|
private readonly StorageCollection<DrawningCruiser> _storageCollection;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Компания
|
/// Компания
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractCompany? _company = null;
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormCruisersCollection()
|
public FormCruisersCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_storageCollection = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -24,13 +31,7 @@ namespace ProjectCruiser
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
|
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
switch (comboBoxSelectorCompany.Text)
|
panelCompanyTools.Enabled = false;
|
||||||
{
|
|
||||||
case "хранилище":
|
|
||||||
_company = new CruiserDockingService(pictureBoxCruiser.Width,
|
|
||||||
pictureBoxCruiser.Height, new MassiveGenericObjects<DrawningCruiser>());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -51,23 +52,22 @@ namespace ProjectCruiser
|
|||||||
drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||||
break;
|
break;
|
||||||
case nameof(DrawningMilitaryCruiser):
|
case nameof(DrawningMilitaryCruiser):
|
||||||
|
// TODO вызов диалогового окна для выбора цвета
|
||||||
drawningCruiser = new DrawningMilitaryCruiser(random.Next(100, 300), random.Next(1000, 3000),
|
drawningCruiser = new DrawningMilitaryCruiser(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(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_company + drawningCruiser != -1)
|
if (_company + drawningCruiser != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCruiser.Image = _company.Show();
|
pictureBoxCruiser.Image = _company.Show();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +164,97 @@ namespace ProjectCruiser
|
|||||||
pictureBoxCruiser.Image = _company.Show();
|
pictureBoxCruiser.Image = _company.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCollecctionAdd_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)
|
||||||
|
{
|
||||||
|
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>
|
||||||
|
/// Обновление списка в 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 ButtonCreateCompany_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ICollectionGenericObjects<DrawningCruiser>? collection =
|
||||||
|
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не проинициализирована");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new CruiserDockingService(pictureBoxCruiser.Width, pictureBoxCruiser.Height, collection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
panelCompanyTools.Enabled = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user