From 0490384d1e039858fa2f67217c065cbd21434669 Mon Sep 17 00:00:00 2001 From: Egor_Shtyrkin Date: Sat, 11 May 2024 17:23:54 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 22 ++++++ .../ListGenericObjects.cs | 64 +++++++++++++++++ .../StorageCollection.cs | 68 +++++++++++++++++++ .../FormWarshipCollection.Designer.cs | 18 ++--- 4 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs 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; // -- 2.25.1 From 069ada4a3370e65d9d54c839e85b0f969bd930b5 Mon Sep 17 00:00:00 2001 From: Egor_Shtyrkin Date: Sat, 11 May 2024 19:00:19 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MassiveGenericObjects.cs | 18 +- .../FormWarshipCollection.Designer.cs | 165 ++++++++++++++++-- .../FormWarshipCollection.cs | 94 +++++++++- 3 files changed, 251 insertions(+), 26 deletions(-) diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs index f3c079d..1dd14d5 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/MassiveGenericObjects.cs @@ -20,7 +20,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects 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]; + } + } + } + } /// /// Конструктор diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs index 22fdb45..1615060 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); buttonRemoveWarship = new Button(); @@ -37,31 +46,123 @@ buttonAddWarship = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); + panelCompanyTools = new Panel(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveWarship); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddAircraftCarrier); - groupBoxTools.Controls.Add(buttonAddWarship); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(902, 0); + groupBoxTools.Location = new Point(916, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(205, 682); + groupBoxTools.Size = new Size(205, 759); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 369); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(193, 29); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + 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(199, 290); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 241); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(193, 29); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 20; + listBoxCollection.Location = new Point(6, 131); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(193, 104); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 96); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(193, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(101, 66); + 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(13, 66); + 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(3, 33); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(193, 27); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(20, 10); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(158, 20); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 624); + buttonRefresh.Location = new Point(3, 268); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(193, 52); buttonRefresh.TabIndex = 6; @@ -72,7 +173,7 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 566); + buttonGoToCheck.Location = new Point(3, 210); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(193, 52); buttonGoToCheck.TabIndex = 5; @@ -83,7 +184,7 @@ // buttonRemoveWarship // buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveWarship.Location = new Point(6, 508); + buttonRemoveWarship.Location = new Point(3, 152); buttonRemoveWarship.Name = "buttonRemoveWarship"; buttonRemoveWarship.Size = new Size(193, 52); buttonRemoveWarship.TabIndex = 4; @@ -93,7 +194,7 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(6, 475); + maskedTextBox.Location = new Point(3, 119); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(193, 27); @@ -103,7 +204,7 @@ // buttonAddAircraftCarrier // buttonAddAircraftCarrier.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAircraftCarrier.Location = new Point(6, 417); + buttonAddAircraftCarrier.Location = new Point(3, 61); buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier"; buttonAddAircraftCarrier.Size = new Size(193, 52); buttonAddAircraftCarrier.TabIndex = 2; @@ -114,7 +215,7 @@ // buttonAddWarship // buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddWarship.Location = new Point(6, 359); + buttonAddWarship.Location = new Point(3, 3); buttonAddWarship.Name = "buttonAddWarship"; buttonAddWarship.Size = new Size(193, 52); buttonAddWarship.TabIndex = 1; @@ -128,7 +229,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 325); + comboBoxSelectorCompany.Location = new Point(6, 335); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(193, 28); comboBoxSelectorCompany.TabIndex = 0; @@ -139,22 +240,40 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(902, 682); + pictureBox.Size = new Size(916, 759); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddWarship); + panelCompanyTools.Controls.Add(buttonAddAircraftCarrier); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveWarship); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 428); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(199, 328); + panelCompanyTools.TabIndex = 9; + // // FormWarshipCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1110, 682); + ClientSize = new Size(1121, 759); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormWarshipCollection"; Text = "Коллекция военных кораблей"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -169,5 +288,15 @@ private Button buttonRemoveWarship; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs index c2a3d45..f2e0c3b 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs @@ -17,6 +17,8 @@ namespace ProjectAircraftCarrier; /// public partial class FormWarshipCollection : Form { + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -28,6 +30,7 @@ public partial class FormWarshipCollection : Form public FormWarshipCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -37,12 +40,7 @@ public partial class FormWarshipCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new WarshipDockService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -153,7 +151,7 @@ public partial class FormWarshipCollection : Form }; form.ShowDialog(); } - + private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) @@ -163,4 +161,86 @@ public partial class FormWarshipCollection : Form pictureBox.Image = _company.Show(); } + + 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); + } + } + } + + 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(); + } + + 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(); + } + + private void ButtonCreateCompany_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new WarshipDockService(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } \ No newline at end of file -- 2.25.1