From 4f67d6f78ab04206dd50baf4787c4901d1f47f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Wed, 27 Dec 2023 19:43:17 +0400 Subject: [PATCH] Add warning --- .../FormLocomotiveCollection.cs | 15 +++------------ .../LocomotivesGenericCollection.cs | 6 +++--- .../ElectricLocomotive/SetGeneric.cs | 14 ++++++++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 651cabd..051b4c6 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -3,15 +3,6 @@ using ElectricLocomotive.Generics; using Microsoft.Extensions.Logging; using ProjectElectricLocomotive; using ProjectElectricLocomotive.Exceptions; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; namespace ElectricLocomotive { @@ -113,11 +104,11 @@ namespace ElectricLocomotive MessageBox.Show("Объект добавлен"); CollectionPictureBox.Image = obj.ShowLocomotives(); _logger.LogInformation($"Добавлен объект {obj}"); - ; } else { MessageBox.Show("Не удалось добавить объект"); + _logger.LogInformation("Не удалось добавить объект"); } } catch (StorageOverflowException ex) @@ -154,13 +145,13 @@ namespace ElectricLocomotive else { MessageBox.Show("Не удалось удалить объект"); - _logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}"); + _logger.LogWarning($"Не найден объект по позиции: {pos}"); } } catch (LocoNotFoundException ex) { MessageBox.Show(ex.Message); - _logger.LogWarning($"Не найден объект по позиции: {obj}"); + _logger.LogWarning($"Не найден объект по позиции: {pos}"); } } diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index 5b95146..41373ce 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -27,13 +27,13 @@ namespace ElectricLocomotive.Generics _pictureHeight = picHeight; _collection = new SetGeneric(width * height); } - public static int operator +(LocomotivesGenericCollection collect, T? loco) + public static int operator +(LocomotivesGenericCollection collect, T? locomotive) { - if (loco == null) + if (locomotive == null) { return -1; } - return collect._collection.Insert(loco); + return collect._collection.Insert(locomotive); } diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index c7d91a1..92bc661 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -36,14 +36,16 @@ namespace ProjectElectricLocomotive.Generics _places.Insert(position, loco); return position; } - public bool Remove(int position) + public T? Remove(int position) { - if (position < 0 || position >= _places.Count) - { + if (position >= Count || position < 0) + return null; + + T? tmp = _places[position]; + if (tmp == null) throw new LocoNotFoundException(position); - } - _places.RemoveAt(position); - return true; + _places[position] = null; + return tmp; } public T? this[int position] {