diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index bc25791..2a3a2e0 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -59,13 +59,13 @@ namespace Sailboat.Generics /// /// /// - public static bool operator +(BoatsGenericCollection collect, T? obj) + public static int operator +(BoatsGenericCollection collect, T? obj) { if (obj == null) { - return false; + return -1; } - return (bool)collect?._collection.Insert(obj); + return collect._collection.Insert(obj, new DrawingBoatEqutables()); } /// /// Перегрузка оператора вычитания diff --git a/Sailboat/Sailboat/BoatsGenericStorage.cs b/Sailboat/Sailboat/BoatsGenericStorage.cs index a4b4fdb..464bf8c 100644 --- a/Sailboat/Sailboat/BoatsGenericStorage.cs +++ b/Sailboat/Sailboat/BoatsGenericStorage.cs @@ -156,7 +156,7 @@ namespace Sailboat.Generics DrawingBoat? truck = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight); if (truck != null) { - if (!(collection + truck)) + if (collection + truck == -1) { throw new ApplicationException("Ошибка добавления в коллекцию"); } diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index ddac986..00050b0 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -77,7 +77,7 @@ namespace Sailboat _logger.LogWarning("Добавление пустого объекта"); return; } - if (obj + drawingBoat) + if (obj + drawingBoat != -1) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowBoats(); diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 7d72c81..e7e30c0 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -38,14 +38,9 @@ namespace Sailboat.Generics /// /// Добавляемая лодка /// - public bool Insert(T boat, IEqualityComparer? equal = null) + public int Insert(T boat, IEqualityComparer? equal = null) { - if (_places.Count == _maxCount) - { - throw new StorageOverflowException(_maxCount); - } - Insert(boat, 0, equal); - return true; + return Insert(boat, 0, equal); } /// /// Добавление объекта в набор на конкретную позицию @@ -53,22 +48,20 @@ namespace Sailboat.Generics /// Добавляемая лодка /// Позиция /// - public bool Insert(T boat, int position, IEqualityComparer? equal = null) + public int Insert(T boat, int position, IEqualityComparer? equal = null) { - if (position < 0 || position >= _maxCount) + if (position < 0 || position > Count) throw new BoatNotFoundException(position); - - if (_places.Count >= _maxCount) + if (Count >= _maxCount) throw new StorageOverflowException(_maxCount); - - if (equal != null) + if (equal != null && _places.Contains(boat, equal)) { - if (_places.Contains(boat, equal)) - throw new ArgumentException(nameof(boat)); + //throw new StorageOverflowException("Данный объект уже есть в коллекции"); + //MessageBox.Show("Данный объект уже есть в коллекции"); + return -1; } - - _places.Insert(0, boat); - return true; + _places.Insert(position, boat); + return position; } /// /// Удаление объекта из набора с конкретной позиции