From 755078a597416b4a32a48bf30f2d95c1ba7b1772 Mon Sep 17 00:00:00 2001 From: RomanovEgor Date: Sun, 25 Dec 2022 10:42:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'HoistingCrane/HoistingCrane/FormMapWi?= =?UTF-8?q?thSetHoistingCrane.cs'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RomanovEgor --- .../FormMapWithSetHoistingCrane.cs | 145 +++++++++++++----- 1 file changed, 108 insertions(+), 37 deletions(-) diff --git a/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs index 8784862..124aab0 100644 --- a/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs @@ -12,62 +12,141 @@ namespace HoistingCrane { public partial class FormMapWithSetHoistingCrane : Form { - + /// Словарь для выпадающего списка + /// + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap() }, + { "Вторая карта", new SecondMap() }, + }; + /// + /// Объект от коллекции карт + /// + private readonly MapsCollection _mapsCollection; + /// private MapWithSetHoistingCraneGeneric _mapHoistingCraneCollectionGeneric; - public FormMapWithSetHoistingCrane() { InitializeComponent(); + _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); + comboBoxSelectorMap.Items.Clear(); + foreach (var elem in _mapsDict) + { + comboBoxSelectorMap.Items.Add(elem.Key); + } } + /// + /// Заполнение listBoxMaps + /// + private void ReloadMaps() + { + int index = listBoxMaps.SelectedIndex; + listBoxMaps.Items.Clear(); + for (int i = 0; i < _mapsCollection.Keys.Count; i++) + { + listBoxMaps.Items.Add(_mapsCollection.Keys[i]); + } + + if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count)) + { + listBoxMaps.SelectedIndex = 0; + } + else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count) + { + listBoxMaps.SelectedIndex = index; + } + } private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { AbstractMap map = null; switch (comboBoxSelectorMap.Text) { - case "Первая карта": + case "Простая карта": map = new SimpleMap(); break; case "Вторая карта": map = new SecondMap(); - break; + break; } if (map != null) { _mapHoistingCraneCollectionGeneric = new MapWithSetHoistingCraneGeneric( - pictureBox.Width, pictureBox.Height, map); + pictureBox.Width, pictureBox.Height, map); } else { _mapHoistingCraneCollectionGeneric = null; } } - - private void ButtonAddHoistingCrane_Click(object sender, EventArgs e) + /// + /// Добавление карты + /// + /// + /// + private void buttonAddMap_Click_1(object sender, EventArgs e) { - if (_mapHoistingCraneCollectionGeneric == null) + if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) + { + MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); + ReloadMaps(); + } + private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + /// + /// Удаление карты + /// + /// + /// + private void buttonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) { return; } - FormHoistingCrane form = new(); - if (form.ShowDialog() == DialogResult.OK) + + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - DrawingObjectHoistingCrane hoistingCrane = new(form.SelectedHoistingCrane); - if (_mapHoistingCraneCollectionGeneric + hoistingCrane == 1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); + } + } + private void ButtonAddHoistingCrane_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + var formHoistingCraneConfig = new FormHoistingCraneConfig(); + formHoistingCraneConfig.AddEvent(AddHoistingCrane); + formHoistingCraneConfig.Show(); + } + private void AddHoistingCrane(DrawingHoistingCrane drawingHoistingCrane) + { + DrawingObjectHoistingCrane hoistingCrane = new DrawingObjectHoistingCrane(drawingHoistingCrane); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + hoistingCrane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); } } - private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -76,38 +155,35 @@ namespace HoistingCrane return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapHoistingCraneCollectionGeneric - pos == null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { MessageBox.Show("Не удалось удалить объект"); } } - private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapHoistingCraneCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } - private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapHoistingCraneCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } - private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapHoistingCraneCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -130,10 +206,5 @@ namespace HoistingCrane } pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums); } - - private void pictureBox_Click(object sender, EventArgs e) - { - - } } }