From d4e32d2ba9d3492a82917ca5064567a81f5eecf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 20 Dec 2023 09:04:12 +0400 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/FormBoatCollection.cs | 32 ++++++++----------------- Sailboat/Sailboat/SetGeneric.cs | 14 +++++------ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 76c12fe..a24afc8 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -77,32 +77,20 @@ namespace Sailboat _logger.LogWarning("Добавление пустого объекта"); return; } - if (obj + drawingBoat) + try { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowBoats(); - _logger.LogInformation($"Объект {obj.GetType()} добавлен"); + if (obj + drawingBoat) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowBoats(); + _logger.LogInformation($"Объект {obj.GetType()} добавлен"); + } } - else + catch (StorageOverflowException ex) { - MessageBox.Show("Не удалось добавить объект"); - _logger.LogInformation($"Не удалось добавить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}"); } - //try - //{ - // if (obj + drawingBoat) - // { - // MessageBox.Show("Объект добавлен"); - // pictureBoxCollection.Image = obj.ShowBoats(); - // _logger.LogInformation($"Объект {obj.GetType()} добавлен"); - // } - //} - //catch (StorageOverflowException ex) - //{ - // MessageBox.Show(ex.Message); - // MessageBox.Show("Не удалось добавить объект"); - // _logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}"); - //} } private void buttonRemoveBoat_Click(object sender, EventArgs e) diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 05134f9..b49c7e8 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -38,12 +38,7 @@ namespace Sailboat.Generics /// public bool Insert(T boat) { - if (_places.Count == _maxCount) - { - return false; - } - Insert(boat, 0); - return true; + return Insert(boat, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -53,10 +48,15 @@ namespace Sailboat.Generics /// public bool Insert(T boat, int position) { + if (boat == null) + { + throw new ArgumentNullException(nameof(boat)); + } + if (position < 0 || position >= _maxCount) throw new BoatNotFoundException(position); - if (_places.Count >= _maxCount) + if (Count >= _maxCount) throw new StorageOverflowException(_maxCount); _places.Insert(0, boat); return true;