готовая 4 лаба

This commit is contained in:
Garifullin-Farid 2024-04-21 00:12:09 +04:00
parent 9855506d43
commit 40e23830ff
3 changed files with 26 additions and 10 deletions

View File

@ -13,7 +13,22 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
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];
}
}
}
}
/// <summary>
/// Конструктор

View File

@ -153,7 +153,7 @@
buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click;
buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// panelStorage
//

View File

@ -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);
}
}
}
/// <summary>
/// Создание компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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<DrawningTank>? 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<DrawningTank>());
_company = new TankBase(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
}
}