From 85704d9e33cf6aa3768406a1400d8adea44ad18c Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 11:03:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=204=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.cs | 10 +-- .../LogicFormLocomotiveCollection.cs | 72 ++++++++++++++++++- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/FormLocomotiveCollection.cs index 8c29ce8..60aefa7 100644 --- a/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/FormLocomotiveCollection.cs @@ -24,11 +24,6 @@ namespace ProjectElectricLocomotive ButtonRefreshCollection_Click(sender, e); } - private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) - { - ListBoxObjects_SelectedIndexChanged(sender, e); - } - private void buttonAddObject_Click(object sender, EventArgs e) { ButtonAddObject_Click(sender, e); @@ -38,5 +33,10 @@ namespace ProjectElectricLocomotive { ButtonDelObject_Click(sender, e); } + + private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) + { + ListBoxObjects_SelectedIndexChanged(sender, e); + } } } diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index 5acfa68..a39d3fe 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -98,6 +98,73 @@ namespace ProjectElectricLocomotive } } + /// + /// Заполнение listBoxObjects + /// + private void ReloadObjects() + { + int index = listBoxStorages.SelectedIndex; + listBoxStorages.Items.Clear(); + for (int i = 0; i < _storage.Keys.Count; i++) + { + listBoxStorages.Items.Add(_storage.Keys[i]); + } + if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count)) + { + listBoxStorages.SelectedIndex = 0; + } + else if (listBoxStorages.Items.Count > 0 && index > -1 && + index < listBoxStorages.Items.Count) + { + listBoxStorages.SelectedIndex = index; + } + } + /// + /// Добавление набора в коллекцию + /// + /// + /// + private void ButtonAddObject_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxStorageName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _storage.AddSet(textBoxStorageName.Text); + ReloadObjects(); + } + + /// + /// Выбор набора + /// + /// + /// + private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives(); + } + /// + /// Удаление набора + /// + /// + /// + private void ButtonDelObject_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", + "Удаление", MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.Yes) + { + _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); + ReloadObjects(); + } + } + /// /// Добавление объекта в набор /// @@ -174,7 +241,10 @@ namespace ProjectElectricLocomotive return; } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - + if (obj == null) + { + return; + } pictureBoxCollection.Image = obj.ShowLocomotives(); } }