From dfbed5bdd55a2e54770b8a47e573f0ffabd835fc Mon Sep 17 00:00:00 2001 From: "Nikolaeva_Y.A" Date: Tue, 6 Dec 2022 09:03:54 +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 --- Airbus/Airbus/FormMapWithSetPlanes.cs | 50 ++++++++++++++++------- Airbus/Airbus/MapsCollection.cs | 16 +++----- Airbus/Airbus/PlaneNotFoundException.cs | 24 +++++++++++ Airbus/Airbus/SetPlanesGeneric.cs | 2 + Airbus/Airbus/StorageOverflowException.cs | 24 +++++++++++ 5 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 Airbus/Airbus/PlaneNotFoundException.cs create mode 100644 Airbus/Airbus/StorageOverflowException.cs diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 9dd90b0..98043b9 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -122,6 +122,8 @@ namespace Airbus //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { + //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ ВСТАВКИ + var formPlaneConfig = new FormPlaneConfig(); formPlaneConfig.AddEvent(AddPlane); @@ -130,6 +132,8 @@ namespace Airbus //удаление объекта private void ButtonRemovePlane_Click(object sender, EventArgs e) { + //ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ УДАЛЕНИЯ + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; @@ -143,14 +147,25 @@ namespace Airbus 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(); + 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 (PlaneNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); + } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); } } @@ -211,15 +226,19 @@ namespace Airbus { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.SaveData(saveFileDialog.FileName)) - { - MessageBox.Show("Сохранение прошло успешно", "Результат", + 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); } } } @@ -229,15 +248,16 @@ namespace Airbus { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_mapsCollection.LoadData(openFileDialog.FileName)) + try { - ReloadMaps(); + _mapsCollection.LoadData(openFileDialog.FileName); + MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + catch (Exception ex) { - MessageBox.Show("Ошибка загрузки данных", "Результат", + MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 240ca3f..8d3cf91 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -53,8 +53,8 @@ namespace Airbus } } - // сохранение информации по автомобилям в хранилище в файл - public bool SaveData(string filename) + // сохранение информации по самолётам в ангарах в файл + public void SaveData(string filename) { if (File.Exists(filename)) { @@ -71,16 +71,14 @@ namespace Airbus $"{Environment.NewLine}"); } } - - return true; } - // загрузка информации по автомобилям на парковках из файла - public bool LoadData(string filename) + // загрузка информации по самолётам в ангарах из файла + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не найден"); } using (StreamReader sr = new(filename)) @@ -90,7 +88,7 @@ namespace Airbus //если не содержит такую запись или пустой файл if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection")) { - return false; + throw new Exception("Формат данных в файле неправильный"); } _mapStorage.Clear(); @@ -117,8 +115,6 @@ namespace Airbus _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } } - - return true; } //доступ к аэродрому diff --git a/Airbus/Airbus/PlaneNotFoundException.cs b/Airbus/Airbus/PlaneNotFoundException.cs new file mode 100644 index 0000000..8b90594 --- /dev/null +++ b/Airbus/Airbus/PlaneNotFoundException.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + [Serializable] + + //класс собственных исключений + internal class PlaneNotFoundException: ApplicationException + { + public PlaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + + public PlaneNotFoundException() : base() { } + + public PlaneNotFoundException(string message) : base(message) { } + + public PlaneNotFoundException(string message, Exception exception) : base(message, exception) { } + + protected PlaneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +} diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 65edf3a..3c8b277 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -64,6 +64,8 @@ namespace Airbus return null; } + //TODO проверка позиции??? + //что-то типа throw new PlaneNotFoundException(position); //получение объекта из набора по позиции public T this[int position] diff --git a/Airbus/Airbus/StorageOverflowException.cs b/Airbus/Airbus/StorageOverflowException.cs new file mode 100644 index 0000000..7ddeb57 --- /dev/null +++ b/Airbus/Airbus/StorageOverflowException.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + [Serializable] + + //класс собственных исключений + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { } + + public StorageOverflowException() : base() { } + + public StorageOverflowException(string message) : base(message) { } + + public StorageOverflowException(string message, Exception exception) : base(message, exception) { } + + protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } + } +}