diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs index 4eb41ad..40ef205 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSPAUCollection.cs @@ -164,11 +164,17 @@ namespace SelfPropelledArtilleryUnit _logger.LogWarning("Неудачная попытка добавления"); } } - catch (Exception ex) + catch (ArgumentException) + { + Serilog.Log.Warning($"Добавляемый объект уже существует в коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty}"); + MessageBox.Show("Добавляемый объект уже сущесвует в коллекции"); + } + catch (StorageOverflowException ex) { MessageBox.Show("Не удалось добавить объект"); _logger.LogWarning($"Неудачная попытка добавления: {ex}"); } + } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs index a45d839..01d9b48 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SPAUGenericCollection.cs @@ -17,6 +17,10 @@ namespace SelfPropelledArtilleryUnit.Generics where T : DrawningSPAU where U : IMoveableObject { + /// + /// Получение объектов коллекции + /// + public IEnumerable GetSPAUs => _collection.GetSPAUs(); /// /// Ширина окна прорисовки /// @@ -66,7 +70,7 @@ namespace SelfPropelledArtilleryUnit.Generics { return -1; } - return collect._collection.Insert(obj); + return collect._collection.Insert(obj, new DrawiningSPAUEqutables()); } /// /// Перегрузка оператора вычитания diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs index 1afdda9..d409cfa 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs @@ -44,7 +44,9 @@ namespace SelfPropelledArtilleryUnit.Generics /// public int Insert(T spau, IEqualityComparer? equal = null) { - return Insert(spau, 0); + if (_places.Count == _maxCount) + throw new StorageOverflowException(_maxCount); + return Insert(spau, 0, equal); } /// /// Добавление объекта в набор на конкретную позицию @@ -64,7 +66,11 @@ namespace SelfPropelledArtilleryUnit.Generics if (position < 0 || position > _maxCount) throw new SPAUNotFoundException(position); - + if (equal != null) + { + if (_places.Contains(spau, equal)) + throw new ArgumentException(nameof(spau)); + } if (Count == 0) { _places.Add(spau);