From 3509e44ad6967ced033c5d5e9d1952dbbaca2159 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Mon, 7 Nov 2022 20:42:17 +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=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArmoredCar/FormMapWithSetArmoredCars.cs | 51 ++++++++++++++----- .../ArmoredCar/SetArmoredCarsGeneric.cs | 4 +- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs index 3306a27..bb3ce84 100644 --- a/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs +++ b/ArmoredCar/ArmoredCar/FormMapWithSetArmoredCars.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Windows.Forms; using System; +using Microsoft.Extensions.Logging; namespace ArmoredCar { @@ -73,6 +74,7 @@ namespace ArmoredCar } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); + } /// /// Выбор карты @@ -100,6 +102,7 @@ namespace ArmoredCar { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); ReloadMaps(); + } } /// @@ -109,9 +112,9 @@ namespace ArmoredCar /// private void ButtonAddarmoredCar_Click(object sender, EventArgs e) { - var form = new FormArmoredCarConfig(); + var form = new FormArmoredCarConfig(); form.AddEvent(AddArmoredCar); - form.Show(); + form.Show(); } private void AddArmoredCar(DrawningArmoredCar drawningArmoredCar) @@ -122,16 +125,26 @@ namespace ArmoredCar } DrawningObjectArmCar armoredCar = new(drawningArmoredCar); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + armoredCar > -1) + try { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + armoredCar > -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } } - else + catch (StorageOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); + MessageBox.Show($"Ошибка добавления: {ex.Message}"); } - + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); + } } /// /// Удаление объекта @@ -153,15 +166,27 @@ namespace ArmoredCar 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(); + 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 (ArmoredCarNotFoundException ex) { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show($"Ошибка удаления: {ex.Message}"); } + catch (Exception ex) + { + MessageBox.Show($"Неизвестная ошибка: {ex.Message}"); + } + } /// /// Вывод набора diff --git a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs index bd7f915..6d63325 100644 --- a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs +++ b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs @@ -45,7 +45,7 @@ namespace ArmoredCar public int Insert(T armoredCar, int position) { if (Count >= _maxCount) - throw new StorageOverflowException(); + throw new StorageOverflowException(Count); if (position < 0 || position >= _maxCount) return -1; @@ -64,7 +64,7 @@ namespace ArmoredCar return null; T armoredCar = _places[position]; if (armoredCar == null) - throw new ArmoredCarNotFoundException(); + throw new ArmoredCarNotFoundException(position); _places.RemoveAt(position); return armoredCar; }