diff --git a/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs b/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs
index 44c72f7..405244d 100644
--- a/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectElectroTrans/CollectionGenericObjects/AbstractCompany.cs
@@ -61,7 +61,8 @@ public abstract class AbstractCompany
///
public static int operator +(AbstractCompany company, DrawingTrans trans)
{
- return company._collection.Insert(trans);
+ return company._collection?.Insert(trans, new DrawingTransEquitables()) ??
+ throw new DrawingEquitablesException();
}
///
@@ -75,6 +76,13 @@ public abstract class AbstractCompany
return company._collection?.Remove(position);
}
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) =>
+ _collection?.CollectionSort(comparer);
+
///
/// Получение случайного объекта из коллекции
///
diff --git a/ProjectElectroTrans/CollectionGenericObjects/CollectionInfo.cs b/ProjectElectroTrans/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..e1d48ac
--- /dev/null
+++ b/ProjectElectroTrans/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,82 @@
+namespace ProjectElectroTrans.CollectionGenericObjects;
+
+public class CollectionInfo : IEquatable
+{
+ ///
+ /// Название
+ ///
+ public string Name { get; private set; }
+
+ ///
+ /// Тип
+ ///
+ public CollectionType CollectionType { get; private set; }
+
+ ///
+ /// Описание
+ ///
+ public string Description { get; private set; }
+
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly string _separator = "-";
+
+ ///
+ /// Конструктор
+ ///
+ /// Название
+ /// Тип
+ /// Описание
+ public CollectionInfo(string name, CollectionType collectionType, string
+ description)
+ {
+ Name = name;
+ CollectionType = collectionType;
+ Description = description;
+ }
+
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка
+ /// Объект или null
+ public static CollectionInfo? GetCollectionInfo(string data)
+ {
+ string[] strs = data.Split(_separator,
+ StringSplitOptions.RemoveEmptyEntries);
+ if (strs.Length < 1 || strs.Length > 3)
+ {
+ return null;
+ }
+
+ return new CollectionInfo(strs[0],
+ (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
+ }
+
+ public override string ToString()
+ {
+ return Name + _separator + CollectionType + _separator + Description;
+ }
+
+ public bool Equals(CollectionInfo? other)
+ {
+ return Name == other?.Name;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as CollectionInfo);
+ }
+
+ public bool IsEmpty()
+ {
+ if (string.IsNullOrEmpty(Name) && CollectionType != CollectionType.None) return true;
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return Name.GetHashCode();
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs
index b68ae47..286a623 100644
--- a/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectElectroTrans/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -22,7 +22,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -30,7 +30,7 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
@@ -56,4 +56,11 @@ public interface ICollectionGenericObjects
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+
+ ///
+ /// Сортировка коллекции
+ ///
+ /// Сравнитель объектов
+ void CollectionSort(IComparer comparer);
+
}
\ No newline at end of file
diff --git a/ProjectElectroTrans/CollectionGenericObjects/ListGenericObjects.cs b/ProjectElectroTrans/CollectionGenericObjects/ListGenericObjects.cs
index ef589a5..9bd7c71 100644
--- a/ProjectElectroTrans/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectElectroTrans/CollectionGenericObjects/ListGenericObjects.cs
@@ -49,17 +49,40 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
if (Count == _maxCount) throw new CollectionOverflowException(Count);
+ if (comparer != null)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(_collection[i], obj))
+ {
+ throw new CollectionInsertException(obj);
+ }
+ }
+ }
+
_collection.Add(obj);
return Count;
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
+
+ if (comparer != null)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(_collection[i], obj))
+ {
+ throw new CollectionInsertException(obj);
+ }
+ }
+ }
+
_collection.Insert(position, obj);
return position;
}
@@ -79,4 +102,9 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
\ No newline at end of file
diff --git a/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs
index 2cf890f..fcfcf75 100644
--- a/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectElectroTrans/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,5 @@
using ProjectElectroTrans.Exceptions;
+using System.Collections.Generic;
namespace ProjectElectroTrans.CollectionGenericObjects;
@@ -52,8 +53,20 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
+ if (comparer != null)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(_collection[i], obj))
+ {
+ throw new CollectionInsertException(obj);
+ }
+ }
+ }
+
+
// вставка в свободное место набора
for (int i = 0; i < Count; i++)
{
@@ -67,14 +80,22 @@ public class MassiveGenericObjects : ICollectionGenericObjects
throw new CollectionOverflowException(Count);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
// проверка позиции
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
- // проверка, что элемент массива по этой позиции пустой, если нет, то
- // ищется свободное место после этой позиции и идет вставка туда
- // если нет после, ищем до
+ if (comparer != null)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (comparer.Equals(_collection[i], obj))
+ {
+ throw new CollectionInsertException(obj);
+ }
+ }
+ }
+
if (_collection[position] != null)
{
bool pushed = false;
@@ -107,7 +128,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
}
- // вставка
_collection[position] = obj;
return position;
}
@@ -131,4 +151,14 @@ public class MassiveGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ List lst = [.._collection];
+ lst.Sort(comparer.Compare);
+ for (int i = 0; i < _collection.Length; ++i)
+ {
+ _collection[i] = lst[i];
+ }
+ }
}
\ No newline at end of file
diff --git a/ProjectElectroTrans/CollectionGenericObjects/StorageCollection.cs b/ProjectElectroTrans/CollectionGenericObjects/StorageCollection.cs
index 375d8a7..c41d904 100644
--- a/ProjectElectroTrans/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectElectroTrans/CollectionGenericObjects/StorageCollection.cs
@@ -17,12 +17,12 @@ public class StorageCollection
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> _storages;
+ readonly Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
///
/// Ключевое слово, с которого должен начинаться файл
@@ -44,33 +44,32 @@ public class StorageCollection
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
/// Добавление коллекции в хранилище
///
- /// Название коллекции
- /// тип коллекции
- public void AddCollection(string name, CollectionType collectionType)
+ /// тип коллекции
+ public void AddCollection(CollectionInfo collectionInfo)
{
- if (_storages.ContainsKey(name)) throw new CollectionAlreadyExistsException(name);
- if (collectionType == CollectionType.None) throw new CollectionTypeException("Пустой тип коллекции");
- if (collectionType == CollectionType.Massive)
- _storages[name] = new MassiveGenericObjects();
- else if (collectionType == CollectionType.List)
- _storages[name] = new ListGenericObjects();
+ if (_storages.ContainsKey(collectionInfo)) throw new CollectionAlreadyExistsException(collectionInfo);
+ if (collectionInfo.CollectionType == CollectionType.None)
+ throw new CollectionTypeException("Пустой тип коллекции");
+ if (collectionInfo.CollectionType == CollectionType.Massive)
+ _storages[collectionInfo] = new MassiveGenericObjects();
+ else if (collectionInfo.CollectionType == CollectionType.List)
+ _storages[collectionInfo] = new ListGenericObjects();
}
///
/// Удаление коллекции
///
- /// Название коллекции
- public void DelCollection(string name)
+ /// тип коллекции
+ public void DelCollection(CollectionInfo collectionInfo)
{
- if (_storages.ContainsKey(name))
- _storages.Remove(name);
-
+ if (_storages.ContainsKey(collectionInfo))
+ _storages.Remove(collectionInfo);
}
///
@@ -78,12 +77,12 @@ public class StorageCollection
///
/// Название коллекции
///
- public ICollectionGenericObjects? this[string name]
+ public ICollectionGenericObjects? this[CollectionInfo collectionInfo]
{
get
{
- if (_storages.ContainsKey(name))
- return _storages[name];
+ if (_storages.ContainsKey(collectionInfo))
+ return _storages[collectionInfo];
return null;
}
}
@@ -93,7 +92,7 @@ public class StorageCollection
///
/// Путь и имя файла
/// true - сохранение прошло успешно, false - ошибка при сохранении данных
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (_storages.Count == 0)
{
@@ -108,7 +107,7 @@ public class StorageCollection
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
StringBuilder sb = new();
sb.Append(Environment.NewLine);
@@ -120,8 +119,6 @@ public class StorageCollection
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
- sb.Append(value.Value.GetCollectionType);
- sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
@@ -139,8 +136,6 @@ public class StorageCollection
writer.Write(sb);
}
}
-
- return true;
}
///
@@ -148,11 +143,11 @@ public class StorageCollection
///
/// Путь и имя файла
/// true - загрузка прошла успешно, false - ошибка при загрузке данных
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new FileNotFoundException(filename);
}
using (StreamReader fs = File.OpenText(filename))
@@ -160,8 +155,7 @@ public class StorageCollection
string str = fs.ReadLine();
if (string.IsNullOrEmpty(str))
{
- throw new FileNotFoundException(filename);
-
+ throw new EmptyFileExeption(filename);
}
if (!str.StartsWith(_collectionKey))
@@ -174,20 +168,21 @@ public class StorageCollection
while ((strs = fs.ReadLine()) != null)
{
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
+ if (record.Length != 3)
{
continue;
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
- if (collection == null)
- {
- throw new CollectionTypeException("Не удалось определить тип коллекции:" + record[1]);
- }
+ CollectionInfo? collectionInfo =
+ CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new CollectionInfoException("Не удалось определить информацию коллекции:" + record[0]);
- collection.MaxCount = Convert.ToInt32(record[2]);
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ ICollectionGenericObjects? collection =
+ StorageCollection.CreateCollection(collectionInfo.CollectionType) ??
+ throw new CollectionTypeException("Не удалось определить тип коллекции:" + record[1]);
+ collection.MaxCount = Convert.ToInt32(record[1]);
+
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningTrans() is T ship)
@@ -203,67 +198,8 @@ public class StorageCollection
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
-
- return true;
- }
- if (!File.Exists(filename))
- {
- }
-
- using (StreamReader fs = File.OpenText(filename))
- {
- string str = fs.ReadLine();
- if (string.IsNullOrEmpty(str))
- {
- throw new EmptyFileExeption(filename);
- }
-
- if (!str.StartsWith(_collectionKey))
- {
- }
-
- _storages.Clear();
- string strs = "";
- while ((strs = fs.ReadLine()) != null)
- {
- string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
- {
- continue;
- }
-
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
- if (collection == null)
- {
- }
-
- collection.MaxCount = Convert.ToInt32(record[2]);
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
- foreach (string elem in set)
- {
- if (elem?.CreateDrawningTrans() is T ship)
- {
- try
- {
- if (collection.Insert(ship) == -1)
- {
- throw new CollectionTypeException("Объект не удалось добавить в коллекцию: " + record[3]);
- }
- }
- catch (CollectionOverflowException ex)
- {
- throw ex.InnerException!;
- }
- }
- }
-
- _storages.Add(record[0], collection);
- }
-
- return true;
}
}
@@ -272,7 +208,8 @@ public class StorageCollection
///
///
///
- private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType)
+ private static ICollectionGenericObjects?
+ CreateCollection(CollectionType collectionType)
{
return collectionType switch
{
diff --git a/ProjectElectroTrans/Drawnings/DrawingTransCompareByColor.cs b/ProjectElectroTrans/Drawnings/DrawingTransCompareByColor.cs
new file mode 100644
index 0000000..8f4ebb5
--- /dev/null
+++ b/ProjectElectroTrans/Drawnings/DrawingTransCompareByColor.cs
@@ -0,0 +1,35 @@
+namespace ProjectElectroTrans.Drawnings;
+
+public class DrawingTransCompareByColor : IComparer
+{
+ public int Compare(DrawingTrans? x, DrawingTrans? y)
+ {
+ if (x == null && y == null) return 0;
+ if (x == null || x.EntityTrans == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityTrans == null)
+ {
+ return -1;
+ }
+
+ if (ToHex(x.EntityTrans.BodyColor) != ToHex(y.EntityTrans.BodyColor))
+ {
+ return String.Compare(ToHex(x.EntityTrans.BodyColor), ToHex(y.EntityTrans.BodyColor),
+ StringComparison.Ordinal);
+ }
+
+ var speedCompare = x.EntityTrans.Speed.CompareTo(y.EntityTrans.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+
+ return x.EntityTrans.Weight.CompareTo(y.EntityTrans.Weight);
+ }
+
+ private static String ToHex(Color c)
+ => $"#{c.R:X2}{c.G:X2}{c.B:X2}";
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/Drawnings/DrawingTransCompareByType.cs b/ProjectElectroTrans/Drawnings/DrawingTransCompareByType.cs
new file mode 100644
index 0000000..edd3c47
--- /dev/null
+++ b/ProjectElectroTrans/Drawnings/DrawingTransCompareByType.cs
@@ -0,0 +1,31 @@
+namespace ProjectElectroTrans.Drawnings;
+
+public class DrawingTransCompareByType : IComparer
+{
+ public int Compare(DrawingTrans? x, DrawingTrans? y)
+ {
+ if (x == null && y == null) return 0;
+ if (x == null || x.EntityTrans == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityTrans == null)
+ {
+ return -1;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return x.GetType().Name.CompareTo(y.GetType().Name);
+ }
+
+ var speedCompare = x.EntityTrans.Speed.CompareTo(y.EntityTrans.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+
+ return x.EntityTrans.Weight.CompareTo(y.EntityTrans.Weight);
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/Drawnings/DrawingTransEquitables.cs b/ProjectElectroTrans/Drawnings/DrawingTransEquitables.cs
new file mode 100644
index 0000000..af8ea33
--- /dev/null
+++ b/ProjectElectroTrans/Drawnings/DrawingTransEquitables.cs
@@ -0,0 +1,59 @@
+using System.Diagnostics.CodeAnalysis;
+using ProjectElectroTrans.Entities;
+
+namespace ProjectElectroTrans.Drawnings;
+
+public class DrawingTransEquitables : IEqualityComparer
+{
+ public bool Equals(DrawingTrans? x, DrawingTrans? y)
+ {
+ if (ReferenceEquals(x, null)) return false;
+ if (ReferenceEquals(y, null)) return false;
+ if (x.GetType() != y.GetType()) return false;
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return false;
+ }
+
+ if (x.EntityTrans != null && y.EntityTrans != null && x.EntityTrans.Speed != y.EntityTrans.Speed)
+ {
+ return false;
+ }
+
+ if (x.EntityTrans.Weight != y.EntityTrans.Weight)
+ {
+ return false;
+ }
+
+ if (x.EntityTrans.BodyColor != y.EntityTrans.BodyColor)
+ {
+ return false;
+ }
+ if (x is DrawingElectroTrans && y is DrawingElectroTrans)
+ {
+ if (((EntityElectroTrans)x.EntityTrans).AdditionalColor !=
+ ((EntityElectroTrans)y.EntityTrans).AdditionalColor)
+ {
+ return false;
+ }
+ if (((EntityElectroTrans)x.EntityTrans).Battery!=
+ ((EntityElectroTrans)y.EntityTrans).Battery)
+ {
+ return false;
+ }
+ if (((EntityElectroTrans)x.EntityTrans).Horns!=
+ ((EntityElectroTrans)y.EntityTrans).Horns)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public int GetHashCode([DisallowNull] DrawingTrans obj)
+ {
+ return obj.GetHashCode();
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/Exceptions/CollectionAlreadyExistsException.cs b/ProjectElectroTrans/Exceptions/CollectionAlreadyExistsException.cs
index eab928f..d5d59c2 100644
--- a/ProjectElectroTrans/Exceptions/CollectionAlreadyExistsException.cs
+++ b/ProjectElectroTrans/Exceptions/CollectionAlreadyExistsException.cs
@@ -1,11 +1,12 @@
using System.Runtime.Serialization;
+using ProjectElectroTrans.CollectionGenericObjects;
namespace ProjectElectroTrans.Exceptions;
public class CollectionAlreadyExistsException : Exception
{
public CollectionAlreadyExistsException() : base() { }
- public CollectionAlreadyExistsException(string name) : base($"Коллекция {name} уже существует!") { }
+ public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base($"Коллекция {collectionInfo} уже существует!") { }
public CollectionAlreadyExistsException(string name, Exception exception) :
base($"Коллекция {name} уже существует!", exception) { }
protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext
diff --git a/ProjectElectroTrans/Exceptions/CollectionInfoException.cs b/ProjectElectroTrans/Exceptions/CollectionInfoException.cs
new file mode 100644
index 0000000..e53be8b
--- /dev/null
+++ b/ProjectElectroTrans/Exceptions/CollectionInfoException.cs
@@ -0,0 +1,13 @@
+using System.Runtime.Serialization;
+
+namespace ProjectElectroTrans.Exceptions;
+
+public class CollectionInfoException : Exception
+{
+ public CollectionInfoException() : base() { }
+ public CollectionInfoException(string message) : base(message) { }
+ public CollectionInfoException(string message, Exception exception) :
+ base(message, exception) { }
+ protected CollectionInfoException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/Exceptions/CollectionInsertException.cs b/ProjectElectroTrans/Exceptions/CollectionInsertException.cs
index d107dd0..1391aa1 100644
--- a/ProjectElectroTrans/Exceptions/CollectionInsertException.cs
+++ b/ProjectElectroTrans/Exceptions/CollectionInsertException.cs
@@ -1,9 +1,11 @@
using System.Runtime.Serialization;
+using ProjectElectroTrans.Drawnings;
namespace ProjectElectroTrans.Exceptions;
public class CollectionInsertException : Exception
{
+ public CollectionInsertException(object obj) : base($"Объект {obj} не удволетворяет уникальности") { }
public CollectionInsertException() : base() { }
public CollectionInsertException(string message) : base(message) { }
public CollectionInsertException(string message, Exception exception) :
diff --git a/ProjectElectroTrans/Exceptions/DrawingEquitablesException.cs b/ProjectElectroTrans/Exceptions/DrawingEquitablesException.cs
new file mode 100644
index 0000000..dfd6159
--- /dev/null
+++ b/ProjectElectroTrans/Exceptions/DrawingEquitablesException.cs
@@ -0,0 +1,13 @@
+using System.Runtime.Serialization;
+
+namespace ProjectElectroTrans.Exceptions;
+
+public class DrawingEquitablesException : Exception
+{
+ public DrawingEquitablesException() : base("Объекты прорисовки одинаковые") { }
+ public DrawingEquitablesException(string message) : base(message) { }
+ public DrawingEquitablesException(string message, Exception exception) :
+ base(message, exception) { }
+ protected DrawingEquitablesException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/FormTransCollection.Designer.cs b/ProjectElectroTrans/FormTransCollection.Designer.cs
index a13535f..883ce7e 100644
--- a/ProjectElectroTrans/FormTransCollection.Designer.cs
+++ b/ProjectElectroTrans/FormTransCollection.Designer.cs
@@ -33,291 +33,317 @@ namespace ProjectElectroTrans
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
- panelCompanyTools = new Panel();
- buttonAddCar = new Button();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonRefresh = new Button();
- buttonRemoveCar = new Button();
- buttonGoToCheck = new Button();
- buttonCreateCompany = new Button();
- panelStorage = new Panel();
- buttonCollectionDel = new Button();
- listBoxCollection = new ListBox();
- buttonCollectionAdd = new Button();
- radioButtonList = new RadioButton();
- radioButtonMassive = new RadioButton();
- textBoxCollectionName = new TextBox();
- labelCollectionName = new Label();
- comboBoxSelectorCompany = new ComboBox();
- pictureBox = new PictureBox();
- menuStrip = new MenuStrip();
- файлToolStripMenuItem = new ToolStripMenuItem();
- saveToolStripMenuItem = new ToolStripMenuItem();
- loadToolStripMenuItem = new ToolStripMenuItem();
- saveFileDialog = new SaveFileDialog();
- openFileDialog = new OpenFileDialog();
- groupBoxTools.SuspendLayout();
- panelCompanyTools.SuspendLayout();
- panelStorage.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
- menuStrip.SuspendLayout();
- SuspendLayout();
- //
- // groupBoxTools
- //
- groupBoxTools.Controls.Add(panelCompanyTools);
- groupBoxTools.Controls.Add(buttonCreateCompany);
- groupBoxTools.Controls.Add(panelStorage);
- groupBoxTools.Controls.Add(comboBoxSelectorCompany);
- groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(783, 24);
- groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(179, 608);
- groupBoxTools.TabIndex = 0;
- groupBoxTools.TabStop = false;
- groupBoxTools.Text = "Инструменты";
- //
- // panelCompanyTools
- //
- panelCompanyTools.Controls.Add(buttonAddCar);
- panelCompanyTools.Controls.Add(maskedTextBoxPosition);
- panelCompanyTools.Controls.Add(buttonRefresh);
- panelCompanyTools.Controls.Add(buttonRemoveCar);
- panelCompanyTools.Controls.Add(buttonGoToCheck);
- panelCompanyTools.Dock = DockStyle.Bottom;
- panelCompanyTools.Enabled = false;
- panelCompanyTools.Location = new Point(3, 352);
- panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(173, 253);
- panelCompanyTools.TabIndex = 9;
- //
- // buttonAddCar
- //
- buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddCar.Location = new Point(3, 3);
- buttonAddCar.Name = "buttonAddCar";
- buttonAddCar.Size = new Size(167, 40);
- buttonAddCar.TabIndex = 1;
- buttonAddCar.Text = "Добавление автомобиля";
- buttonAddCar.UseVisualStyleBackColor = true;
- buttonAddCar.Click += ButtonAddTrans_Click;
- //
- // maskedTextBoxPosition
- //
- maskedTextBoxPosition.Location = new Point(3, 95);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(167, 23);
- maskedTextBoxPosition.TabIndex = 3;
- maskedTextBoxPosition.ValidatingType = typeof(int);
- //
- // buttonRefresh
- //
- buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(3, 210);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(167, 40);
- buttonRefresh.TabIndex = 6;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += ButtonRefresh_Click;
- //
- // buttonRemoveCar
- //
- buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveCar.Location = new Point(3, 124);
- buttonRemoveCar.Name = "buttonRemoveCar";
- buttonRemoveCar.Size = new Size(167, 40);
- buttonRemoveCar.TabIndex = 4;
- buttonRemoveCar.Text = "Удалить автомобиль";
- buttonRemoveCar.UseVisualStyleBackColor = true;
- buttonRemoveCar.Click += ButtonRemoveTrans_Click;
- //
- // buttonGoToCheck
- //
- buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(3, 170);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(167, 40);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Передать на тесты";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += ButtonGoToCheck_Click;
- //
- // buttonCreateCompany
- //
- buttonCreateCompany.Location = new Point(6, 320);
- buttonCreateCompany.Name = "buttonCreateCompany";
- buttonCreateCompany.Size = new Size(167, 23);
- buttonCreateCompany.TabIndex = 8;
- buttonCreateCompany.Text = "Создать компанию";
- buttonCreateCompany.UseVisualStyleBackColor = true;
- buttonCreateCompany.Click += ButtonCreateCompany_Click;
- //
- // panelStorage
- //
- panelStorage.Controls.Add(buttonCollectionDel);
- panelStorage.Controls.Add(listBoxCollection);
- panelStorage.Controls.Add(buttonCollectionAdd);
- panelStorage.Controls.Add(radioButtonList);
- panelStorage.Controls.Add(radioButtonMassive);
- panelStorage.Controls.Add(textBoxCollectionName);
- panelStorage.Controls.Add(labelCollectionName);
- panelStorage.Dock = DockStyle.Top;
- panelStorage.Location = new Point(3, 19);
- panelStorage.Name = "panelStorage";
- panelStorage.Size = new Size(173, 266);
- panelStorage.TabIndex = 7;
- //
- // buttonCollectionDel
- //
- buttonCollectionDel.Location = new Point(3, 227);
- buttonCollectionDel.Name = "buttonCollectionDel";
- buttonCollectionDel.Size = new Size(167, 23);
- buttonCollectionDel.TabIndex = 6;
- buttonCollectionDel.Text = "Удалить коллекцию";
- buttonCollectionDel.UseVisualStyleBackColor = true;
- buttonCollectionDel.Click += ButtonCollectionDel_Click;
- //
- // listBoxCollection
- //
- listBoxCollection.FormattingEnabled = true;
- listBoxCollection.ItemHeight = 15;
- listBoxCollection.Location = new Point(3, 112);
- listBoxCollection.Name = "listBoxCollection";
- listBoxCollection.Size = new Size(167, 109);
- listBoxCollection.TabIndex = 5;
- //
- // buttonCollectionAdd
- //
- buttonCollectionAdd.Location = new Point(3, 83);
- buttonCollectionAdd.Name = "buttonCollectionAdd";
- buttonCollectionAdd.Size = new Size(167, 23);
- buttonCollectionAdd.TabIndex = 4;
- buttonCollectionAdd.Text = "Добавить коллекцию";
- buttonCollectionAdd.UseVisualStyleBackColor = true;
- buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
- //
- // radioButtonList
- //
- radioButtonList.AutoSize = true;
- radioButtonList.Location = new Point(98, 58);
- radioButtonList.Name = "radioButtonList";
- radioButtonList.Size = new Size(66, 19);
- radioButtonList.TabIndex = 3;
- radioButtonList.TabStop = true;
- radioButtonList.Text = "Список";
- radioButtonList.UseVisualStyleBackColor = true;
- //
- // radioButtonMassive
- //
- radioButtonMassive.AutoSize = true;
- radioButtonMassive.Location = new Point(16, 58);
- radioButtonMassive.Name = "radioButtonMassive";
- radioButtonMassive.Size = new Size(67, 19);
- radioButtonMassive.TabIndex = 2;
- radioButtonMassive.TabStop = true;
- radioButtonMassive.Text = "Массив";
- radioButtonMassive.UseVisualStyleBackColor = true;
- //
- // textBoxCollectionName
- //
- textBoxCollectionName.Location = new Point(3, 29);
- textBoxCollectionName.Name = "textBoxCollectionName";
- textBoxCollectionName.Size = new Size(167, 23);
- textBoxCollectionName.TabIndex = 1;
- //
- // labelCollectionName
- //
- labelCollectionName.AutoSize = true;
- labelCollectionName.Location = new Point(26, 11);
- labelCollectionName.Name = "labelCollectionName";
- labelCollectionName.Size = new Size(125, 15);
- labelCollectionName.TabIndex = 0;
- labelCollectionName.Text = "Название коллекции:";
- //
- // comboBoxSelectorCompany
- //
- comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
- comboBoxSelectorCompany.FormattingEnabled = true;
- comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 291);
- comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(167, 23);
- comboBoxSelectorCompany.TabIndex = 0;
- comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
- //
- // pictureBox
- //
- pictureBox.Dock = DockStyle.Fill;
- pictureBox.Location = new Point(0, 24);
- pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(783, 608);
- pictureBox.TabIndex = 1;
- pictureBox.TabStop = false;
- //
- // menuStrip
- //
- menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
- menuStrip.Location = new Point(0, 0);
- menuStrip.Name = "menuStrip";
- menuStrip.Size = new Size(962, 24);
- menuStrip.TabIndex = 2;
- menuStrip.Text = "menuStrip";
- //
- // файлToolStripMenuItem
- //
- файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
- файлToolStripMenuItem.Name = "файлToolStripMenuItem";
- файлToolStripMenuItem.Size = new Size(48, 20);
- файлToolStripMenuItem.Text = "Файл";
- //
- // saveToolStripMenuItem
- //
- saveToolStripMenuItem.Name = "saveToolStripMenuItem";
- saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
- saveToolStripMenuItem.Size = new Size(181, 22);
- saveToolStripMenuItem.Text = "Сохранение";
- saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
- //
- // loadToolStripMenuItem
- //
- loadToolStripMenuItem.Name = "loadToolStripMenuItem";
- loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
- loadToolStripMenuItem.Size = new Size(181, 22);
- loadToolStripMenuItem.Text = "Загрузка";
- loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
- //
- // saveFileDialog
- //
- saveFileDialog.Filter = "txt file | *.txt";
- //
- // openFileDialog
- //
- openFileDialog.Filter = "txt file | *.txt";
- //
- // FormCarCollection
- //
- AutoScaleDimensions = new SizeF(7F, 15F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(962, 632);
- Controls.Add(pictureBox);
- Controls.Add(groupBoxTools);
- Controls.Add(menuStrip);
- MainMenuStrip = menuStrip;
- Name = "FormCarCollection";
- Text = "Коллекция автомобилей";
- groupBoxTools.ResumeLayout(false);
- panelCompanyTools.ResumeLayout(false);
- panelCompanyTools.PerformLayout();
- panelStorage.ResumeLayout(false);
- panelStorage.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
- menuStrip.ResumeLayout(false);
- menuStrip.PerformLayout();
- ResumeLayout(false);
- PerformLayout();
+ panelCompanyTools = new Panel();
+ buttonSortByColor = new Button();
+ buttonSortByType = new Button();
+ buttonAddCar = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonRefresh = new Button();
+ buttonRemoveCar = new Button();
+ buttonGoToCheck = new Button();
+ buttonCreateCompany = new Button();
+ panelStorage = new Panel();
+ buttonCollectionDel = new Button();
+ listBoxCollection = new ListBox();
+ buttonCollectionAdd = new Button();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
+ comboBoxSelectorCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ menuStrip = new MenuStrip();
+ файлToolStripMenuItem = new ToolStripMenuItem();
+ saveToolStripMenuItem = new ToolStripMenuItem();
+ loadToolStripMenuItem = new ToolStripMenuItem();
+ saveFileDialog = new SaveFileDialog();
+ openFileDialog = new OpenFileDialog();
+ groupBoxTools.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
+ panelStorage.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ menuStrip.SuspendLayout();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(783, 24);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(179, 657);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonSortByColor);
+ panelCompanyTools.Controls.Add(buttonSortByType);
+ panelCompanyTools.Controls.Add(buttonAddCar);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonRemoveCar);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 355);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(173, 299);
+ panelCompanyTools.TabIndex = 9;
+ //
+ // buttonSortByColor
+ //
+ buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByColor.Location = new Point(3, 250);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(167, 40);
+ buttonSortByColor.TabIndex = 8;
+ buttonSortByColor.Text = "Сортировка по цвету";
+ buttonSortByColor.UseVisualStyleBackColor = true;
+ buttonSortByColor.Click += ButtonSortByColor_Click;
+ //
+ // buttonSortByType
+ //
+ buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByType.Location = new Point(3, 210);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(167, 40);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += ButtonSortByType_Click;
+ //
+ // buttonAddCar
+ //
+ buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCar.Location = new Point(3, 3);
+ buttonAddCar.Name = "buttonAddCar";
+ buttonAddCar.Size = new Size(167, 40);
+ buttonAddCar.TabIndex = 1;
+ buttonAddCar.Text = "Добавление поезда";
+ buttonAddCar.UseVisualStyleBackColor = true;
+ buttonAddCar.Click += ButtonAddTrans_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(3, 49);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(167, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(3, 164);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(167, 40);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonRemoveCar
+ //
+ buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveCar.Location = new Point(3, 78);
+ buttonRemoveCar.Name = "buttonRemoveCar";
+ buttonRemoveCar.Size = new Size(167, 40);
+ buttonRemoveCar.TabIndex = 4;
+ buttonRemoveCar.Text = "Удалить поезд";
+ buttonRemoveCar.UseVisualStyleBackColor = true;
+ buttonRemoveCar.Click += ButtonRemoveTrans_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(3, 124);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(167, 40);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(6, 320);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(167, 23);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
+ //
+ // panelStorage
+ //
+ panelStorage.Controls.Add(buttonCollectionDel);
+ panelStorage.Controls.Add(listBoxCollection);
+ panelStorage.Controls.Add(buttonCollectionAdd);
+ panelStorage.Controls.Add(radioButtonList);
+ panelStorage.Controls.Add(radioButtonMassive);
+ panelStorage.Controls.Add(textBoxCollectionName);
+ panelStorage.Controls.Add(labelCollectionName);
+ panelStorage.Dock = DockStyle.Top;
+ panelStorage.Location = new Point(3, 19);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(173, 266);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(3, 227);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(167, 23);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(3, 112);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(167, 109);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(3, 83);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(167, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(98, 58);
+ radioButtonList.Name = "radioButtonList";
+ radioButtonList.Size = new Size(66, 19);
+ radioButtonList.TabIndex = 3;
+ radioButtonList.TabStop = true;
+ radioButtonList.Text = "Список";
+ radioButtonList.UseVisualStyleBackColor = true;
+ //
+ // radioButtonMassive
+ //
+ radioButtonMassive.AutoSize = true;
+ radioButtonMassive.Location = new Point(16, 58);
+ radioButtonMassive.Name = "radioButtonMassive";
+ radioButtonMassive.Size = new Size(67, 19);
+ radioButtonMassive.TabIndex = 2;
+ radioButtonMassive.TabStop = true;
+ radioButtonMassive.Text = "Массив";
+ radioButtonMassive.UseVisualStyleBackColor = true;
+ //
+ // textBoxCollectionName
+ //
+ textBoxCollectionName.Location = new Point(3, 29);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(167, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(26, 11);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(125, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
+ // comboBoxSelectorCompany
+ //
+ comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectorCompany.FormattingEnabled = true;
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Location = new Point(6, 291);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(167, 23);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 24);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(783, 657);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // menuStrip
+ //
+ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
+ menuStrip.Location = new Point(0, 0);
+ menuStrip.Name = "menuStrip";
+ menuStrip.Size = new Size(962, 24);
+ menuStrip.TabIndex = 2;
+ menuStrip.Text = "menuStrip";
+ //
+ // файлToolStripMenuItem
+ //
+ файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
+ файлToolStripMenuItem.Name = "файлToolStripMenuItem";
+ файлToolStripMenuItem.Size = new Size(48, 20);
+ файлToolStripMenuItem.Text = "Файл";
+ //
+ // saveToolStripMenuItem
+ //
+ saveToolStripMenuItem.Name = "saveToolStripMenuItem";
+ saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
+ saveToolStripMenuItem.Size = new Size(181, 22);
+ saveToolStripMenuItem.Text = "Сохранение";
+ saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
+ //
+ // loadToolStripMenuItem
+ //
+ loadToolStripMenuItem.Name = "loadToolStripMenuItem";
+ loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
+ loadToolStripMenuItem.Size = new Size(181, 22);
+ loadToolStripMenuItem.Text = "Загрузка";
+ loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
+ //
+ // saveFileDialog
+ //
+ saveFileDialog.Filter = "txt file | *.txt";
+ //
+ // openFileDialog
+ //
+ openFileDialog.Filter = "txt file | *.txt";
+ //
+ // FormCarCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(962, 681);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Controls.Add(menuStrip);
+ MainMenuStrip = menuStrip;
+ Name = "FormTransCollection";
+ Text = "Коллекция электропоездов";
+ groupBoxTools.ResumeLayout(false);
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ menuStrip.ResumeLayout(false);
+ menuStrip.PerformLayout();
+ ResumeLayout(false);
+ PerformLayout();
}
#endregion
@@ -346,5 +372,7 @@ namespace ProjectElectroTrans
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
+ private Button buttonSortByColor;
+ private Button buttonSortByType;
}
}
\ No newline at end of file
diff --git a/ProjectElectroTrans/FormTransCollection.cs b/ProjectElectroTrans/FormTransCollection.cs
index f6f6d61..41a5106 100644
--- a/ProjectElectroTrans/FormTransCollection.cs
+++ b/ProjectElectroTrans/FormTransCollection.cs
@@ -69,6 +69,7 @@ public partial class FormTransCollection : Form
{
return;
}
+
try
{
var res = _company + drawingTrans;
@@ -195,7 +196,7 @@ public partial class FormTransCollection : Form
try
{
- _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
+ _storageCollection.AddCollection(new CollectionInfo(textBoxCollectionName.Text, collectionType, "ХЗ"));
_logger.LogInformation("Добавление коллекции");
RerfreshListBoxItems();
}
@@ -204,7 +205,6 @@ public partial class FormTransCollection : Form
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
}
-
}
///
@@ -226,7 +226,8 @@ public partial class FormTransCollection : Form
return;
}
- _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(listBoxCollection.SelectedItem.ToString()!);
+ _storageCollection.DelCollection(collectionInfo!);
_logger.LogInformation("Коллекция удалена");
RerfreshListBoxItems();
}
@@ -239,10 +240,10 @@ public partial class FormTransCollection : Form
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
- string? colName = _storageCollection.Keys?[i];
- if (!string.IsNullOrEmpty(colName))
+ CollectionInfo? col = _storageCollection.Keys?[i];
+ if (!col!.IsEmpty())
{
- listBoxCollection.Items.Add(colName);
+ listBoxCollection.Items.Add(col);
}
}
}
@@ -261,7 +262,9 @@ public partial class FormTransCollection : Form
}
ICollectionGenericObjects? collection =
- _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
+ _storageCollection[
+ CollectionInfo.GetCollectionInfo(listBoxCollection.SelectedItem.ToString()!) ??
+ new CollectionInfo("", CollectionType.None, "")];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
@@ -332,4 +335,39 @@ public partial class FormTransCollection : Form
}
}
}
+
+ ///
+ /// Сортировка по типу
+ ///
+ ///
+ ///
+ private void ButtonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareCars(new DrawingTransCompareByType());
+ }
+
+ ///
+ /// Сортировка по цвету
+ ///
+ ///
+ ///
+ private void ButtonSortByColor_Click(object sender, EventArgs e)
+ {
+ CompareCars(new DrawingTransCompareByColor());
+ }
+
+ ///
+ /// Сортировка по сравнителю
+ ///
+ /// Сравнитель объектов
+ private void CompareCars(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}
\ No newline at end of file