ready lab 8

This commit is contained in:
ekallin 2023-12-17 00:38:29 +04:00
parent 0afbadbc68
commit af1f332edc
4 changed files with 29 additions and 15 deletions

View File

@ -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);
}
//проверяем, удалось ли нам загрузить объект
}

View File

@ -46,7 +46,7 @@ namespace ProjectElectricLocomotive.Generics
{
return -1;
}
return collect._collection.Insert(loco);
return collect._collection.Insert(loco, new DrawingLocoEqutables());
}
/// Перегрузка оператора вычитания

View File

@ -28,6 +28,16 @@ namespace ProjectElectricLocomotive.Generics
/// Добавление объекта в набор
public int Insert(T loco, IEqualityComparer<T?>? 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;
}