diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/CollectionType.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..7bafc69 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,22 @@ +namespace ProjectAircraftCarrier.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..01ce279 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,64 @@ +namespace ProjectAircraftCarrier.CollectionGenericObjects; + +public class ListGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Список объектов, которые храним + /// + private readonly List _collection; + + /// + /// Максимально допустимое число объектов в списке + /// + private int _maxCount; + + public int Count => _collection.Count; + + public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + + /// + /// Конструктор + /// + 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; + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..aae0670 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,68 @@ +namespace ProjectAircraftCarrier.CollectionGenericObjects; + +public class StorageCollection + where T : class +{ + /// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> _storages; + + /// + /// Возвращение списка названий коллекций + /// + public List Keys => _storages.Keys.ToList(); + + /// + /// Конструктор + /// + public StorageCollection() + { + _storages = new Dictionary>(); + } + + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// тип коллекции + 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(); + else if (collectionType == CollectionType.List) + _storages[name] = new ListGenericObjects(); + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + + // TODO Прописать логику для удаления коллекции + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + if (_storages.ContainsKey(name)) + return _storages[name]; + return null; + } + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs index 5086a3a..22fdb45 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs @@ -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; //