diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index f16b53a..aafde6a 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -95,14 +95,26 @@ namespace Artilleries return; } - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + new DrawingObjectArtillery(artillery) != -1) + try { - MessageBox.Show("Объект добавлен"); - } else - { - MessageBox.Show("Не удалось добавить объект"); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + new DrawingObjectArtillery(artillery) != -1) + { + MessageBox.Show("Объект добавлен"); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); + } + catch (StorageOverflowException ex) + { + MessageBox.Show($"Ошибка переполнения хранилища: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } - pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); }); formArtilleryConfig.Show(); } @@ -122,14 +134,21 @@ namespace Artilleries return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } } - else + catch (ArtilleryNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); } } @@ -182,13 +201,14 @@ namespace Artilleries { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.SaveData(saveFileDialog.FileName)) + try { + _mapsCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch (Exception ex) { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -197,16 +217,17 @@ namespace Artilleries { if (loadFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(loadFileDialog.FileName)) + try { + _mapsCollection.LoadData(loadFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadMaps(); + pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } - else + catch (Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } - ReloadMaps(); - pictureBoxArtilleries.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } } }