From 911543fd4376a43f45f8180d3bc7140498a9bb33 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 20 Nov 2023 20:42:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BC=D1=8B=D1=85=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectStormtrooper/FormPlaneCollection.cs | 10 +++++++++- .../ProjectStormtrooper/PlanesGenericStorage.cs | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs index b59932f..5c76ab5 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs @@ -99,6 +99,7 @@ namespace ProjectStormtrooper _logger.LogInformation($"Удален набор: {name}"); ReloadObjects(); } + _logger.LogWarning("Отмена удаления набора"); } /// /// Добавление объекта в набор @@ -129,6 +130,7 @@ namespace ProjectStormtrooper if (obj + plane > -1) { MessageBox.Show("Объект добавлен"); + _logger.LogInformation($"Добавлен объект {plane}"); pictureBoxCollection.Image = obj.ShowPlanes(); } else @@ -165,9 +167,11 @@ namespace ProjectStormtrooper int pos = Convert.ToInt32(maskedTextBoxNumber.Text); try { - if (obj - pos != null) + var removedObj = obj - pos; + if (removedObj != null) { MessageBox.Show("Объект удален"); + _logger.LogInformation($"Удален объект {removedObj} с позиции {pos}"); pictureBoxCollection.Image = obj.ShowPlanes(); } else @@ -211,10 +215,12 @@ namespace ProjectStormtrooper { _storage.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Данные сохранены в файл {saveFileDialog.FileName}"); } catch (Exception ex) { MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не удалось сохранить информацию в файл: {ex.Message}"); } } } @@ -229,10 +235,12 @@ namespace ProjectStormtrooper ReloadObjects(); RefreshCollection(); MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}"); } catch (Exception ex) { MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning($"Не удалось загрузить информацию из файла: {ex.Message}"); } } } diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs index b3a634b..3bf2e09 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericStorage.cs @@ -117,18 +117,18 @@ namespace ProjectStormtrooper { if (!File.Exists(filename)) { - throw new Exception("Ошибка открытия файла"); + throw new FileNotFoundException("Ошибка открытия файла"); } using (StreamReader sr = new StreamReader(filename)) { string? currentLine = sr.ReadLine(); if (currentLine == null) { - throw new Exception("Нет данных для загрузки"); + throw new IOException("Нет данных для загрузки"); } if (!currentLine.Contains("PlaneStorage")) { - throw new Exception("Неверный формат данных"); + throw new FileFormatException("Неверный формат данных"); } _planeStorages.Clear(); currentLine = sr.ReadLine();