From fa9031723a73752c67444d8003ba259f174e9b5d Mon Sep 17 00:00:00 2001 From: Arklightning Date: Sat, 10 Dec 2022 15:08:00 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Trolleybus/FormMapWithSetTrolleybus.cs | 48 ++++++++----------- Trolleybus/Trolleybus/SetTrolleybusGeneric.cs | 4 ++ .../Trolleybus/StorageOverflowException.cs | 19 ++++++++ Trolleybus/Trolleybus/Trolleybus.csproj | 2 + .../Trolleybus/TrolleybusNotFoundException.cs | 18 +++++++ 5 files changed, 64 insertions(+), 27 deletions(-) create mode 100644 Trolleybus/Trolleybus/StorageOverflowException.cs create mode 100644 Trolleybus/Trolleybus/TrolleybusNotFoundException.cs diff --git a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs index a5fc4fb..654d6b4 100644 --- a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs +++ b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs @@ -131,24 +131,6 @@ namespace Trolleybus formTrolleybusConfig.AddEvent(AddTrolleybus); formTrolleybusConfig.Show(); - /*if (listBoxMaps.SelectedIndex == -1) - { - return; - } - Form1 form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - DrawningObjectTrolleybus tractor = new(form.SelectedTrolleybus); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tractor != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - }*/ } /// /// Удаление объекта @@ -162,15 +144,26 @@ namespace Trolleybus { return; } - int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + try { - MessageBox.Show("Объект удален"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } } - else + catch (TrolleybusNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } } /// @@ -235,13 +228,14 @@ namespace Trolleybus { 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); } } } diff --git a/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs b/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs index ff6dbdf..d4317e9 100644 --- a/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs +++ b/Trolleybus/Trolleybus/SetTrolleybusGeneric.cs @@ -29,6 +29,10 @@ namespace Trolleybus // Добавление объекта в набор public int Insert(T trolleybus) { + if (_places.Count > _maxCount) + { + return -1; + } // вставка в начало набора return Insert(trolleybus, 0); } diff --git a/Trolleybus/Trolleybus/StorageOverflowException.cs b/Trolleybus/Trolleybus/StorageOverflowException.cs new file mode 100644 index 0000000..2661901 --- /dev/null +++ b/Trolleybus/Trolleybus/StorageOverflowException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Trolleybus +{ + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException() : base() { } + public StorageOverflowException(int count) : base($"В наборе превышино количество: {count} элементов") { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception exception) : base(message, exception) { } + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/Trolleybus/Trolleybus/Trolleybus.csproj b/Trolleybus/Trolleybus/Trolleybus.csproj index 9ded4bf..71ede53 100644 --- a/Trolleybus/Trolleybus/Trolleybus.csproj +++ b/Trolleybus/Trolleybus/Trolleybus.csproj @@ -89,7 +89,9 @@ + + Form1.cs diff --git a/Trolleybus/Trolleybus/TrolleybusNotFoundException.cs b/Trolleybus/Trolleybus/TrolleybusNotFoundException.cs new file mode 100644 index 0000000..02c8b43 --- /dev/null +++ b/Trolleybus/Trolleybus/TrolleybusNotFoundException.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace Trolleybus +{ + internal class TrolleybusNotFoundException : ApplicationException + { + public TrolleybusNotFoundException() : base() { } + public TrolleybusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + public TrolleybusNotFoundException(string message) : base(message) { } + public TrolleybusNotFoundException(string message, Exception exception) : base(message, exception) { } + protected TrolleybusNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +}