From 5c08bba55ba658cceab1fc4484de6c045d61fd33 Mon Sep 17 00:00:00 2001 From: sqdselo <147947144+sqdselo@users.noreply.github.com> Date: Mon, 1 Apr 2024 02:15:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BF=D0=B8=D1=81=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D1=83=20=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=8D=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B8=D0=B7=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HoistingCrane/FormCarCollection.cs | 64 ++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 0b01400..2885274 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -15,9 +15,12 @@ namespace HoistingCrane public partial class FormCarCollection : Form { private AbstractCompany? _company; + + private readonly StorageCollection _storageCollection; public FormCarCollection() { InitializeComponent(); + _storageCollection = new(); } private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) @@ -128,19 +131,76 @@ namespace HoistingCrane } + /// + /// Обновление списка в 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 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 buttonDeleteCollection_Click(object sender, EventArgs e) { + // TODO прописать логику удаления элемента из коллекции + // нужно убедиться, что есть выбранная коллекция + // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + // удалить и обновить ListBox + 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 Garage(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelStorage.Enabled = true; + RerfreshListBoxItems(); } } + }