diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs index f4fef06..022bd14 100644 --- a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs @@ -13,7 +13,22 @@ 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/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs b/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs index 073fc60..82025f1 100644 --- a/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.Designer.cs @@ -153,7 +153,7 @@ buttonCreateCompany.TabIndex = 7; buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.UseVisualStyleBackColor = true; - buttonCreateCompany.Click += buttonCreateCompany_Click; + buttonCreateCompany.Click += ButtonCreateCompany_Click; // // panelStorage // diff --git a/ProjectTank/ProjectTank/FormBattleTankCollection.cs b/ProjectTank/ProjectTank/FormBattleTankCollection.cs index 07e5a4e..c2a18ab 100644 --- a/ProjectTank/ProjectTank/FormBattleTankCollection.cs +++ b/ProjectTank/ProjectTank/FormBattleTankCollection.cs @@ -156,10 +156,10 @@ namespace ProjectTank { if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { - MessageBox.Show("Не все данные заполнены", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + CollectionType collectionType = CollectionType.None; if (radioButtonMassive.Checked) { @@ -169,6 +169,7 @@ namespace ProjectTank { collectionType = CollectionType.List; } + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); RerfreshListBoxItems(); } @@ -206,37 +207,37 @@ namespace ProjectTank listBoxСollection.Items.Add(colName); } } + } /// /// Создание компании /// /// /// - private void buttonCreateCompany_Click(object sender, EventArgs e) + private void ButtonCreateCompany_Click(object sender, EventArgs e) { - if (listBoxСollection.SelectedIndex < 0 || listBoxСollection.SelectedItems == null) + if (listBoxСollection.SelectedIndex < 0 || listBoxСollection.SelectedItem == null) { MessageBox.Show("Коллекция не выбрана"); return; } ICollectionGenericObjects? collection = _storageCollection[listBoxСollection.SelectedItem.ToString() ?? string.Empty]; - if (collection == null) { MessageBox.Show("Коллекция не проинициализирована"); return; } + switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new TankBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + _company = new TankBase(pictureBox.Width, pictureBox.Height, collection); break; } + panelCompanyTools.Enabled = true; RerfreshListBoxItems(); } - - } }