diff --git a/GasolineTanker/GasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/GasolineTanker/GasolineTanker/CollectionGenericObjects/AbstractCompany.cs
index cc8fcd0..4079664 100644
--- a/GasolineTanker/GasolineTanker/CollectionGenericObjects/AbstractCompany.cs
+++ b/GasolineTanker/GasolineTanker/CollectionGenericObjects/AbstractCompany.cs
@@ -76,7 +76,7 @@ public abstract class AbstractCompany
///
public static bool operator +(AbstractCompany company, DrawningTanker tanker)
{
- return company._collection?.Insert(tanker) ?? false;
+ return company._collection?.Insert(tanker, new DrawningTankerEqutables()) ?? false;
}
///
@@ -100,6 +100,12 @@ public abstract class AbstractCompany
return _collection?.Get(rnd.Next(GetMaxCount));
}
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
+
///
/// Вывод всей коллекции
///
diff --git a/GasolineTanker/GasolineTanker/CollectionGenericObjects/CollectionInfo.cs b/GasolineTanker/GasolineTanker/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..64a3081
--- /dev/null
+++ b/GasolineTanker/GasolineTanker/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,76 @@
+namespace GasolineTanker.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 override int GetHashCode()
+ {
+ return Name.GetHashCode();
+ }
+}
diff --git a/GasolineTanker/GasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/GasolineTanker/GasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
index 968bd7c..b6f3e52 100644
--- a/GasolineTanker/GasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/GasolineTanker/GasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -21,16 +21,18 @@ public interface ICollectionGenericObjects
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
+ /// Cравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ bool Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
+ /// Cравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ bool Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
@@ -56,4 +58,10 @@ public interface ICollectionGenericObjects
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+
+ ///
+ /// Сортировка коллекции
+ ///
+ /// Сравнитель объектов
+ void CollectionSort(IComparer comparer);
}
\ No newline at end of file
diff --git a/GasolineTanker/GasolineTanker/CollectionGenericObjects/ListGenericObjects.cs b/GasolineTanker/GasolineTanker/CollectionGenericObjects/ListGenericObjects.cs
index 261e8e9..743571e 100644
--- a/GasolineTanker/GasolineTanker/CollectionGenericObjects/ListGenericObjects.cs
+++ b/GasolineTanker/GasolineTanker/CollectionGenericObjects/ListGenericObjects.cs
@@ -54,18 +54,25 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public bool Insert(T obj)
- {
+ public bool Insert(T obj, IEqualityComparer? comparer = null)
+ {
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
}
+
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new Exception("Такой объект уже существует в коллекции");
+ }
+
_collection.Add(obj);
return true;
}
- public bool Insert(T obj, int position)
+ public bool Insert(T obj, int position, IEqualityComparer? comparer = null)
{
+
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
@@ -74,6 +81,10 @@ public class ListGenericObjects : ICollectionGenericObjects
{
throw new PositionOutOfCollectionException(position);
}
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new Exception("Такой объект уже существует в коллекции");
+ }
_collection.Insert(position, obj);
return true;
}
@@ -84,6 +95,10 @@ public class ListGenericObjects : ICollectionGenericObjects
{
throw new PositionOutOfCollectionException(position);
}
+ if (_collection[position] == null)
+ {
+ throw new ObjectNotFoundException(position);
+ }
_collection.RemoveAt(position);
return true;
@@ -96,4 +111,12 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ if (_collection != null && _collection.Count > 0)
+ {
+ _collection.Sort(comparer);
+ }
+ }
}
\ No newline at end of file
diff --git a/GasolineTanker/GasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/GasolineTanker/GasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
index d8ec037..e51d037 100644
--- a/GasolineTanker/GasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/GasolineTanker/GasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -53,7 +53,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
if (position < 0 || position >= _collection.Length)
{
throw new PositionOutOfCollectionException(position);
- }
+ }
return _collection[position];
}
@@ -61,8 +61,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects
/// Вставка в пустое место
///
- public bool Insert(T obj)
+ public bool Insert(T obj, IEqualityComparer? comparer = null)
{
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new Exception("Такой объект уже существует в коллекции");
+ }
for (int i = 0; i < _collection.Length; ++i)
{
if (_collection[i] == null)
@@ -70,7 +74,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
_collection[i] = obj;
return true;
}
- }
+ }
throw new CollectionOverflowException(Count);
}
@@ -78,8 +82,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects
/// Вставка по позиции
///
- public bool Insert(T obj, int position)
+ public bool Insert(T obj, int position, IEqualityComparer? comparer = null)
{
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new Exception("Такой объект уже существует в коллекции");
+ }
if (position < 0 || position >= Count)
{
throw new PositionOutOfCollectionException(position);
@@ -133,4 +141,14 @@ public class MassiveGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ ;
+ if (_collection != null && _collection.Length > 0)
+ {
+ Array.Sort(_collection, comparer);
+ _collection = _collection.OrderBy(element => element == null).ToArray();
+ }
+ }
}
diff --git a/GasolineTanker/GasolineTanker/CollectionGenericObjects/StorageCollection.cs b/GasolineTanker/GasolineTanker/CollectionGenericObjects/StorageCollection.cs
index e69f405..7e5529e 100644
--- a/GasolineTanker/GasolineTanker/CollectionGenericObjects/StorageCollection.cs
+++ b/GasolineTanker/GasolineTanker/CollectionGenericObjects/StorageCollection.cs
@@ -14,12 +14,12 @@ public class StorageCollection
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> _storages;
+ readonly Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
///
/// Ключевое слово, с которого должен начинаться файл
@@ -42,7 +42,7 @@ public class StorageCollection
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
@@ -52,17 +52,19 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (_storages.ContainsKey(name) || name == null)
+ CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
+
+ if (_storages.ContainsKey(collectionInfo) || name == null)
{
throw new Exception("Неверное имя коллекции");
}
if (collectionType == CollectionType.Massive)
{
- _storages.Add(name, new MassiveGenericObjects());
+ _storages.Add(collectionInfo, new MassiveGenericObjects());
}
if (collectionType == CollectionType.List)
{
- _storages.Add(name, new ListGenericObjects());
+ _storages.Add(collectionInfo, new ListGenericObjects());
}
}
@@ -72,9 +74,10 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- if (_storages.ContainsKey(name) && name != null)
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo) && name != null)
{
- _storages.Remove(name);
+ _storages.Remove(collectionInfo);
}
}
@@ -87,9 +90,10 @@ public class StorageCollection
{
get
{
- if (_storages.ContainsKey(name) && name != null)
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo) && name != null)
{
- return _storages[name];
+ return _storages[collectionInfo];
}
return null;
}
@@ -114,7 +118,7 @@ public class StorageCollection
StringBuilder sb = new();
sb.Append(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
sb.Append(Environment.NewLine);
// не сохраняем пустые коллекции
@@ -125,8 +129,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);
@@ -185,18 +187,19 @@ public class StorageCollection
foreach (string data in strs)
{
string[] record = data.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) ??
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new Exception("Не удалось определить информацию коллекции:" + record[0]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ??
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
- collection.MaxCount = Convert.ToInt32(record[2]);
+ collection.MaxCount = Convert.ToInt32(record[1]);
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningTanker() is T tanker)
@@ -205,7 +208,7 @@ public class StorageCollection
{
if (!collection.Insert(tanker))
{
- throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ throw new Exception("Объект не удалось добавить в коллекцию: " + record[2]);
}
}
catch (CollectionOverflowException ex)
@@ -215,7 +218,7 @@ public class StorageCollection
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
}
diff --git a/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerCompareByColor.cs b/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerCompareByColor.cs
new file mode 100644
index 0000000..4779113
--- /dev/null
+++ b/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerCompareByColor.cs
@@ -0,0 +1,30 @@
+namespace GasolineTanker.Drawnings;
+
+///
+/// Сравнение по цвету, скорости, весу
+///
+public class DrawningTankerCompareByColor : IComparer
+{
+ public int Compare(DrawningTanker? x, DrawningTanker? y)
+ {
+ if (x == null || x.EntityTanker == null)
+ {
+ return -1;
+ }
+
+ if (y == null || y.EntityTanker == null)
+ {
+ return 1;
+ }
+ if (x.EntityTanker.BodyColor.Name != y.EntityTanker.BodyColor.Name)
+ {
+ return x.EntityTanker.BodyColor.Name.CompareTo(y.EntityTanker.BodyColor.Name);
+ }
+ var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight);
+ }
+}
diff --git a/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerCompareByType.cs b/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerCompareByType.cs
new file mode 100644
index 0000000..298788c
--- /dev/null
+++ b/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerCompareByType.cs
@@ -0,0 +1,33 @@
+namespace GasolineTanker.Drawnings;
+
+///
+/// Сравнение по типу, скорости, весу
+///
+public class DrawningTankerCompareByType : IComparer
+{
+ public int Compare(DrawningTanker? x, DrawningTanker? y)
+ {
+ if (x == null || x.EntityTanker == null)
+ {
+ return -1;
+ }
+
+ if (y == null || y.EntityTanker == null)
+ {
+ return 1;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return x.GetType().Name.CompareTo(y.GetType().Name);
+ }
+
+ var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+
+ return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight);
+ }
+}
diff --git a/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerEqutables.cs b/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerEqutables.cs
new file mode 100644
index 0000000..43e48ad
--- /dev/null
+++ b/GasolineTanker/GasolineTanker/Drawnings/DrawningTankerEqutables.cs
@@ -0,0 +1,68 @@
+using GasolineTanker.Entities;
+using System.Diagnostics.CodeAnalysis;
+
+namespace GasolineTanker.Drawnings;
+
+///
+/// Реализация сравнения двух объектов класса-прорисовки
+///
+public class DrawningTankerEqutables : IEqualityComparer
+{
+ public bool Equals(DrawningTanker? x, DrawningTanker? y)
+ {
+ if (x == null || x.EntityTanker == null)
+ {
+ return false;
+ }
+
+ if (y == null || y.EntityTanker == null)
+ {
+ return false;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return false;
+ }
+
+ if (x.EntityTanker.Speed != y.EntityTanker.Speed)
+ {
+ return false;
+ }
+
+ if (x.EntityTanker.Weight != y.EntityTanker.Weight)
+ {
+ return false;
+ }
+
+ if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor)
+ {
+ return false;
+ }
+
+ if (x is DrawningGasolineTanker && y is DrawningGasolineTanker)
+ {
+ EntityGasolineTanker entityGasolineTankerX = (EntityGasolineTanker)x.EntityTanker;
+ EntityGasolineTanker entityGasolineTankerY = (EntityGasolineTanker)y.EntityTanker;
+ if (entityGasolineTankerX.AdditionalColor != entityGasolineTankerY.AdditionalColor)
+ {
+ return false;
+ }
+ if (entityGasolineTankerX.SignalBeacon != entityGasolineTankerY.SignalBeacon)
+ {
+ return false;
+ }
+ if (entityGasolineTankerX.Cistern != entityGasolineTankerY.Cistern)
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public int GetHashCode([DisallowNull] DrawningTanker obj)
+ {
+ return obj.GetHashCode();
+ }
+}
diff --git a/GasolineTanker/GasolineTanker/FormTankerCollection.Designer.cs b/GasolineTanker/GasolineTanker/FormTankerCollection.Designer.cs
index cead587..e469854 100644
--- a/GasolineTanker/GasolineTanker/FormTankerCollection.Designer.cs
+++ b/GasolineTanker/GasolineTanker/FormTankerCollection.Designer.cs
@@ -30,6 +30,8 @@
{
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
+ buttonSortByColor = new Button();
+ buttonSortByType = new Button();
buttonAddTanker = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonRefresh = new Button();
@@ -68,13 +70,15 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(874, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(179, 531);
+ groupBoxTools.Size = new Size(179, 615);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
+ panelCompanyTools.Controls.Add(buttonSortByColor);
+ panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonAddTanker);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
@@ -83,9 +87,31 @@
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(14, 331);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(159, 196);
+ panelCompanyTools.Size = new Size(159, 284);
panelCompanyTools.TabIndex = 9;
//
+ // buttonSortByColor
+ //
+ buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByColor.Location = new Point(10, 239);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(143, 33);
+ 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(10, 203);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(143, 33);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += buttonSortByType_Click;
+ //
// buttonAddTanker
//
buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@@ -109,7 +135,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(8, 147);
+ buttonRefresh.Location = new Point(8, 164);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(143, 33);
buttonRefresh.TabIndex = 6;
@@ -133,7 +159,7 @@
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(10, 110);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(141, 31);
+ buttonGoToCheck.Size = new Size(141, 48);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Отправить на проверку";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -247,7 +273,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(874, 531);
+ pictureBox.Size = new Size(874, 615);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -293,7 +319,7 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1053, 555);
+ ClientSize = new Size(1053, 639);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -338,5 +364,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
+ private Button buttonSortByColor;
+ private Button buttonSortByType;
}
}
\ No newline at end of file
diff --git a/GasolineTanker/GasolineTanker/FormTankerCollection.cs b/GasolineTanker/GasolineTanker/FormTankerCollection.cs
index f80c861..891d9bd 100644
--- a/GasolineTanker/GasolineTanker/FormTankerCollection.cs
+++ b/GasolineTanker/GasolineTanker/FormTankerCollection.cs
@@ -69,14 +69,14 @@ public partial class FormTankerCollection : Form
return;
}
- try
+ try
{
if (_company + tanker)
{
MessageBox.Show("Объект добавлен");
- pictureBox.Image = _company.Show();
+ pictureBox.Image = _company.Show();
_logger.LogInformation("Добавлен объект: {tanker}", tanker.GetDataForSave());
- }
+ }
}
catch (Exception ex)
{
@@ -225,13 +225,12 @@ public partial class FormTankerCollection : Form
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
- string? colName = _storageCollection.Keys?[i];
+ string? colName = _storageCollection.Keys?[i].Name;
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
}
}
-
}
///
@@ -313,4 +312,41 @@ public partial class FormTankerCollection : Form
}
RerfreshListBoxItems();
}
+
+ ///
+ /// Сортировка по типу
+ ///
+ ///
+ ///
+
+ private void buttonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareTankers(new DrawningTankerCompareByType());
+ }
+
+ ///
+ /// Сортировка по цвету
+ ///
+ ///
+ ///
+
+ private void buttonSortByColor_Click(object sender, EventArgs e)
+ {
+ CompareTankers(new DrawningTankerCompareByColor());
+ }
+
+ ///
+ /// Сортировка по сравнителю
+ ///
+ /// Сравнитель объектов
+ private void CompareTankers(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}
\ No newline at end of file