From 64c102ea3c0a6d407631f5109f3ce71e89fcf954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B7=D0=B0=D0=BC=D0=B0=D1=82=20=D0=98=D1=88=D1=82?= =?UTF-8?q?=D1=83=D0=B3=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Mon, 8 Apr 2024 22:06:33 +0400 Subject: [PATCH] =?UTF-8?q?4=20=D0=BB=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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 22 +++ .../ListGenericObjects.cs | 60 ++++++ .../MassiveGenericObjects.cs | 89 ++++----- .../StorageCollection.cs | 80 ++++++++ .../MotorBoat/FormBoatCollection.Designer.cs | 172 +++++++++++++++--- MotorBoat/MotorBoat/FormBoatCollection.cs | 114 ++++++++++-- 6 files changed, 453 insertions(+), 84 deletions(-) create mode 100644 MotorBoat/MotorBoat/CollectionGenericObjects/CollectionType.cs create mode 100644 MotorBoat/MotorBoat/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 MotorBoat/MotorBoat/CollectionGenericObjects/StorageCollection.cs diff --git a/MotorBoat/MotorBoat/CollectionGenericObjects/CollectionType.cs b/MotorBoat/MotorBoat/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..732f3b5 --- /dev/null +++ b/MotorBoat/MotorBoat/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,22 @@ +namespace MotorBoat.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/MotorBoat/MotorBoat/CollectionGenericObjects/ListGenericObjects.cs b/MotorBoat/MotorBoat/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..5c05942 --- /dev/null +++ b/MotorBoat/MotorBoat/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,60 @@ +namespace MotorBoat.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) + { + if (position < 0 || position >= Count) + { + return null; + } + + return _collection[position]; + + } + public int Insert(T obj) + { + if (Count + 1 > _maxCount) return -1; + _collection.Add(obj); + return Count; + + } + public int Insert(T obj, int position) + { + if (Count + 1 > _maxCount) return -1; + if (position < 0 || position > Count) return -1; + _collection.Insert(position, obj); + return 1; + } + public T? Remove(int position) + { + if (position < 0 || position > Count) return null; + T? temp = _collection[position]; + _collection.RemoveAt(position); + return temp; + } +} diff --git a/MotorBoat/MotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs b/MotorBoat/MotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs index 5dd8570..b484231 100644 --- a/MotorBoat/MotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/MotorBoat/MotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,11 +1,5 @@ -using MotorBoat.Drawnings; +namespace MotorBoat.CollectionGenericObjects; -namespace MotorBoat.CollectionGenericObjects; - -/// -/// Параметризованный набор объектов -/// -/// Параметр: ограничение - ссылочный тип public class MassiveGenericObjects : ICollectionGenericObjects where T : class { @@ -14,32 +8,34 @@ public class MassiveGenericObjects : ICollectionGenericObjects /// private T?[] _collection; 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]; + } + } + } + } public MassiveGenericObjects() { _collection = Array.Empty(); } public T? Get(int position) { - // TODO проверка позиции - - // return _collection[position]; - if (position <= Count) - { - return _collection[position]; - } - else - return null; + if (position < 0 || position >= Count) return null; + return _collection[position]; } public int Insert(T obj) { - // TODO вставка в свободное место набора - - // return false; - for (int i = 0; i < Count; i++) { if (_collection[i] == null) @@ -52,41 +48,36 @@ public class MassiveGenericObjects : ICollectionGenericObjects } public int Insert(T obj, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до - // TODO вставка - - // return false; - - if (position < Count) + if (position >= Count || position < 0) return -1; + if (_collection[position] == null) { - if (_collection[position] == null) + _collection[position] = obj; + return position; + } + int temp = position + 1; + while (temp < Count) + { + if (_collection[temp] == null) { - _collection[position] = obj; - return position; + _collection[temp] = obj; + return temp; } - else + ++temp; + } + temp = position - 1; + while (temp >= 0) + { + if (_collection[temp] == null) { - for (int i = 0; i < Count; i++) - { - if (_collection[i] == null) - { - _collection[i] = obj; - return i; - } - } + _collection[temp] = obj; + return temp; } + --temp; } return -1; } public T? Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - - // return true; if (position >= Count || position < 0) return null; T? myObject = _collection[position]; _collection[position] = null; diff --git a/MotorBoat/MotorBoat/CollectionGenericObjects/StorageCollection.cs b/MotorBoat/MotorBoat/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..509b72e --- /dev/null +++ b/MotorBoat/MotorBoat/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,80 @@ +namespace MotorBoat.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 (name == null || _storages.ContainsKey(name)) { return; } + switch (collectionType) + + { + case CollectionType.None: + return; + case CollectionType.Massive: + _storages[name] = new MassiveGenericObjects(); + return; + case CollectionType.List: + _storages[name] = new ListGenericObjects(); + return; + } + + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + if (_storages.ContainsKey(name)) + { + _storages.Remove(name); + } + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (name == null || !_storages.ContainsKey(name)) { return null; } + return _storages[name]; + } + } +} diff --git a/MotorBoat/MotorBoat/FormBoatCollection.Designer.cs b/MotorBoat/MotorBoat/FormBoatCollection.Designer.cs index d9c695f..0d76e82 100644 --- a/MotorBoat/MotorBoat/FormBoatCollection.Designer.cs +++ b/MotorBoat/MotorBoat/FormBoatCollection.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(); buttonRemoveBoat = new Button(); @@ -37,33 +46,125 @@ buttonAddBoat = 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(buttonRemoveBoat); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddMotorBoat); - groupBoxTools.Controls.Add(buttonAddBoat); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(630, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(170, 483); + groupBoxTools.Size = new Size(170, 509); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 287); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(158, 23); + buttonCreateCompany.TabIndex = 7; + 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, 19); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(164, 241); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 210); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(158, 23); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(3, 110); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(158, 94); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 81); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(158, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(95, 56); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(66, 19); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(3, 56); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(67, 19); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 27); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(158, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(18, 9); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(125, 15); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 401); + buttonRefresh.Location = new Point(3, 162); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(158, 33); + buttonRefresh.Size = new Size(158, 25); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +173,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 319); + buttonGoToCheck.Location = new Point(3, 131); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(158, 33); + buttonGoToCheck.Size = new Size(158, 25); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +184,9 @@ // buttonRemoveBoat // buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveBoat.Location = new Point(6, 227); + buttonRemoveBoat.Location = new Point(3, 99); buttonRemoveBoat.Name = "buttonRemoveBoat"; - buttonRemoveBoat.Size = new Size(158, 32); + buttonRemoveBoat.Size = new Size(158, 26); buttonRemoveBoat.TabIndex = 4; buttonRemoveBoat.Text = "Удалить лодку"; buttonRemoveBoat.UseVisualStyleBackColor = true; @@ -93,7 +194,7 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(6, 198); + maskedTextBoxPosition.Location = new Point(3, 70); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(158, 23); @@ -103,9 +204,9 @@ // buttonAddMotorBoat // buttonAddMotorBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddMotorBoat.Location = new Point(6, 112); + buttonAddMotorBoat.Location = new Point(3, 36); buttonAddMotorBoat.Name = "buttonAddMotorBoat"; - buttonAddMotorBoat.Size = new Size(158, 38); + buttonAddMotorBoat.Size = new Size(158, 28); buttonAddMotorBoat.TabIndex = 2; buttonAddMotorBoat.Text = "Добавление моторной лодки"; buttonAddMotorBoat.UseVisualStyleBackColor = true; @@ -114,9 +215,9 @@ // buttonAddBoat // buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBoat.Location = new Point(6, 71); + buttonAddBoat.Location = new Point(3, 3); buttonAddBoat.Name = "buttonAddBoat"; - buttonAddBoat.Size = new Size(158, 35); + buttonAddBoat.Size = new Size(158, 27); buttonAddBoat.TabIndex = 1; buttonAddBoat.Text = "Добавление лодки"; buttonAddBoat.UseVisualStyleBackColor = true; @@ -128,7 +229,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Location = new Point(6, 258); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(158, 23); comboBoxSelectorCompany.TabIndex = 0; @@ -139,22 +240,39 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(630, 483); + pictureBox.Size = new Size(630, 509); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddBoat); + panelCompanyTools.Controls.Add(buttonAddMotorBoat); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveBoat); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 316); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(164, 193); + panelCompanyTools.TabIndex = 8; + // // FormBoatCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 483); + ClientSize = new Size(800, 509); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormBoatCollection"; 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 +287,15 @@ private Button buttonRemoveBoat; private MaskedTextBox maskedTextBoxPosition; private Button buttonRefresh; + private Panel panelStorage; + private Label labelCollectionName; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/MotorBoat/MotorBoat/FormBoatCollection.cs b/MotorBoat/MotorBoat/FormBoatCollection.cs index e6784d6..d213b7d 100644 --- a/MotorBoat/MotorBoat/FormBoatCollection.cs +++ b/MotorBoat/MotorBoat/FormBoatCollection.cs @@ -8,6 +8,10 @@ namespace MotorBoat; /// public partial class FormBoatCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; /// /// Компания /// @@ -18,6 +22,7 @@ public partial class FormBoatCollection : Form public FormBoatCollection() { InitializeComponent(); + _storageCollection = new(); } /// /// Выбор компании @@ -26,13 +31,7 @@ public partial class FormBoatCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Harbor(pictureBox.Width, - pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = true; } /// @@ -54,13 +53,10 @@ public partial class FormBoatCollection : Form random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningMotorBoat): - // TODO вызов диалогового окна для выбора цвета drawningBoat = new DrawningMotorBoat(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)), + GetColor(random), + GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; @@ -132,7 +128,6 @@ public partial class FormBoatCollection : Form { MessageBox.Show("Не удалось удалить объект"); } - } /// /// Передача объекта в другую форму @@ -179,4 +174,97 @@ public partial class FormBoatCollection : Form } pictureBox.Image = _company.Show(); } + /// + /// Добавление коллекции + /// + /// + /// + 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) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + if (MessageBox.Show("Удалить коллекцию?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + /// + /// Обновление списка в listBoxCollection + /// + 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 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 Harbor(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } -- 2.25.1