From ad010d910219ea3f02d1294a764e6c5a9c123b09 Mon Sep 17 00:00:00 2001 From: bulatova_karina Date: Wed, 20 Dec 2023 09:09:19 +0300 Subject: [PATCH] laba7: done --- WarmlyShip/WarmlyShip/FormShipCollection.cs | 17 ++++++++++------- WarmlyShip/WarmlyShip/SetGeneric.cs | 9 ++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/WarmlyShip/WarmlyShip/FormShipCollection.cs b/WarmlyShip/WarmlyShip/FormShipCollection.cs index 29613ca..4e89f0f 100644 --- a/WarmlyShip/WarmlyShip/FormShipCollection.cs +++ b/WarmlyShip/WarmlyShip/FormShipCollection.cs @@ -145,16 +145,19 @@ namespace WarmlyShip _logger.LogWarning("Добавление пустого объекта"); return; } - if (obj + drawingWarmlyShip) + try { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowShips(); - _logger.LogInformation($"Объект {obj.GetType()} добавлен"); + if (obj + drawingWarmlyShip) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowShips(); + _logger.LogInformation($"Объект {obj.GetType()} добавлен"); + } } - else + catch (StorageOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); - _logger.LogInformation($"Не удалось добавить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}"); } } diff --git a/WarmlyShip/WarmlyShip/SetGeneric.cs b/WarmlyShip/WarmlyShip/SetGeneric.cs index 0ac82af..39b0e72 100644 --- a/WarmlyShip/WarmlyShip/SetGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetGeneric.cs @@ -39,12 +39,7 @@ namespace WarmlyShip.Generics /// public bool Insert(T warmlyship) { - if (_places.Count == _maxCount) - { - return false; - } - Insert(warmlyship, 0); - return true; + return Insert(warmlyship, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -57,7 +52,7 @@ namespace WarmlyShip.Generics if (position < 0 || position >= _maxCount) throw new ShipNotFoundException(position); - if (_places.Count >= _maxCount) + if (Count >= _maxCount) throw new StorageOverflowException(_maxCount); _places.Insert(0, warmlyship); return true;