Лабораторная работа №4 1

This commit is contained in:
Egor_Shtyrkin 2024-05-11 17:23:54 +04:00
parent be06a94172
commit 0490384d1e
4 changed files with 163 additions and 9 deletions

View File

@ -0,0 +1,22 @@
namespace ProjectAircraftCarrier.CollectionGenericObjects;
/// <summary>
/// Тип коллекции
/// </summary>
public enum CollectionType
{
/// <summary>
/// Неопределено
/// </summary>
None = 0,
/// <summary>
/// Массив
/// </summary>
Massive = 1,
/// <summary>
/// Список
/// </summary>
List = 2
}

View File

@ -0,0 +1,64 @@
namespace ProjectAircraftCarrier.CollectionGenericObjects;
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;
}
}

View File

@ -0,0 +1,68 @@
namespace ProjectAircraftCarrier.CollectionGenericObjects;
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;
}
}
}

View File

@ -51,7 +51,7 @@
groupBoxTools.Controls.Add(buttonAddWarship);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(905, 0);
groupBoxTools.Location = new Point(902, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(205, 682);
groupBoxTools.TabIndex = 0;
@ -61,7 +61,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 549);
buttonRefresh.Location = new Point(6, 624);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(193, 52);
buttonRefresh.TabIndex = 6;
@ -72,7 +72,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 414);
buttonGoToCheck.Location = new Point(6, 566);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(193, 52);
buttonGoToCheck.TabIndex = 5;
@ -83,7 +83,7 @@
// buttonRemoveWarship
//
buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveWarship.Location = new Point(6, 300);
buttonRemoveWarship.Location = new Point(6, 508);
buttonRemoveWarship.Name = "buttonRemoveWarship";
buttonRemoveWarship.Size = new Size(193, 52);
buttonRemoveWarship.TabIndex = 4;
@ -93,7 +93,7 @@
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 267);
maskedTextBox.Location = new Point(6, 475);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(193, 27);
@ -103,7 +103,7 @@
// buttonAddAircraftCarrier
//
buttonAddAircraftCarrier.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAircraftCarrier.Location = new Point(6, 180);
buttonAddAircraftCarrier.Location = new Point(6, 417);
buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier";
buttonAddAircraftCarrier.Size = new Size(193, 52);
buttonAddAircraftCarrier.TabIndex = 2;
@ -114,7 +114,7 @@
// buttonAddWarship
//
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddWarship.Location = new Point(6, 122);
buttonAddWarship.Location = new Point(6, 359);
buttonAddWarship.Name = "buttonAddWarship";
buttonAddWarship.Size = new Size(193, 52);
buttonAddWarship.TabIndex = 1;
@ -128,7 +128,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 26);
comboBoxSelectorCompany.Location = new Point(6, 325);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(193, 28);
comboBoxSelectorCompany.TabIndex = 0;
@ -139,7 +139,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(905, 682);
pictureBox.Size = new Size(902, 682);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//