diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs index 060b842..30ee7a7 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs @@ -1,18 +1,7 @@ using Microsoft.Extensions.Logging; -//using ElectricLocomotive; using ProjectElectricLocomotive.DrawingObjects; using ProjectElectricLocomotive.Exceptions; using ProjectElectricLocomotive.Generics; -/*using ProjectElectricLocomotive.MovementStrategy; -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 ProjectElectricLocomotive @@ -115,17 +104,21 @@ namespace ProjectElectricLocomotive MessageBox.Show("Объект добавлен"); pictureBoxCollections.Image = obj.ShowLocomotives(); _logger.LogInformation($"Добавлен объект {obj}"); - ; - } + } else { MessageBox.Show("Не удалось добавить объект"); + _logger.LogWarning("Переполнение коллекции"); } } catch (StorageOverflowException ex) { MessageBox.Show(ex.Message); } + catch(Exception ex) + { + MessageBox.Show(ex.Message); + } //проверяем, удалось ли нам загрузить объект } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveConfig.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveConfig.cs index d1bd132..fd8c797 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveConfig.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveConfig.cs @@ -157,7 +157,7 @@ namespace ProjectElectricLocomotive } DrawLoco(); } - + private void LabelColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color))) diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs index 9f76e4f..87fc844 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs @@ -46,7 +46,7 @@ namespace ProjectElectricLocomotive.Generics { return -1; } - return collect._collection.Insert(loco); + return collect._collection.Insert(loco, new DrawingLocoEqutables()); } /// Перегрузка оператора вычитания diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs index 12c42d7..ed29c71 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs @@ -28,6 +28,16 @@ namespace ProjectElectricLocomotive.Generics /// Добавление объекта в набор public int Insert(T loco, IEqualityComparer? equal = null) { + if (equal != null) + { + foreach (var secondLoco in _places) + { + if (equal.Equals(loco, secondLoco)) + { + throw new Exception("Такой объект уже есть в коллекции"); + } + } + } return Insert(loco, 0); } @@ -41,6 +51,17 @@ namespace ProjectElectricLocomotive.Generics return -1; } + if(equal != null) + { + foreach (var secondLoco in _places) + { + if(equal.Equals(loco, secondLoco)) + { + throw new ApplicationException("Такой объект уже есть в коллекции"); + } + } + } + _places.Insert(position, loco); return position; }