diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
index 7aad03d..d2c5767 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/AbstractCompany.cs
@@ -1,5 +1,4 @@
using ProjectLiner.Drawnings;
-using ProjectLiner.Exceptions;
namespace ProjectLiner.CollectionGenericObjects;
@@ -64,7 +63,7 @@ public abstract class AbstractCompany
{
return -1;
}
- return company._collection.Insert(ship);
+ return company._collection.Insert(ship, new DrawiningShipEqutables());
}
///
@@ -106,8 +105,8 @@ public abstract class AbstractCompany
{
try
{
- DrawningShip? obj = _collection?.Get(i);
- obj?.DrawTransport(graphics);
+ DrawningShip? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
}
catch (Exception)
{
@@ -117,6 +116,12 @@ public abstract class AbstractCompany
return bitmap;
}
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
+
///
/// Вывод заднего фона
///
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionInfo.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..e729c39
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,78 @@
+namespace ProjectLiner.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();
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/DrawningShipCompareByType.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/DrawningShipCompareByType.cs
new file mode 100644
index 0000000..595467b
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/DrawningShipCompareByType.cs
@@ -0,0 +1,34 @@
+using ProjectLiner.Drawnings;
+
+///
+/// Сравнение по типу, скорости, весу
+///
+public class DrawningShipCompareByType : IComparer
+{
+ public int Compare(DrawningShip? x, DrawningShip? y)
+ {
+ if (x == null && y == null)
+ {
+ return 0;
+ }
+ if (x == null || x.EntityShip == null)
+ {
+ return -1;
+ }
+
+ if (y == null || y.EntityShip == null)
+ {
+ return 1;
+ }
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return x.GetType().Name.CompareTo(y.GetType().Name);
+ }
+ var speedCompare = x.EntityShip.Speed.CompareTo(y.EntityShip.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityShip.Weight.CompareTo(y.EntityShip.Weight);
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
index 0bc81b3..a01f609 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -21,16 +21,18 @@ public interface ICollectionGenericObjects
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
+ /// Cравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
+ /// Cравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int 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/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs
index b475557..11901a0 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/ListGenericObjects.cs
@@ -21,8 +21,7 @@ public class ListGenericObjects : ICollectionGenericObjects
public int Count => _collection.Count;
- public int MaxCount
- {
+ public int MaxCount {
get
{
return _maxCount;
@@ -57,32 +56,32 @@ public class ListGenericObjects : ICollectionGenericObjects
}
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- return Insert(obj, Count);
+ return Insert(obj, Count, comparer);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectNotUniqueException();
+ }
if (Count >= _maxCount)
{
throw new CollectionOverflowException(Count);
}
- if (position > _collection.Count || position < 0)
- {
- throw new PositionOutOfCollectionException();
- }
_collection.Insert(position, obj);
return Count;
}
public T? Remove(int position)
- {
+ {
try
- {
- T obj = _collection[position];
- _collection.RemoveAt(position);
- return obj;
+ {
+ T obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
}
catch (IndexOutOfRangeException)
{
@@ -97,4 +96,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/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
index 1fafd03..cb2b339 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,5 @@
using ProjectLiner.Exceptions;
+using ProjectLiner.Drawnings;
namespace ProjectLiner.CollectionGenericObjects;
@@ -52,10 +53,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects
{
try
{
- if (_collection[position] == null)
- {
- throw new ObjectNotFoundException();
- }
return _collection[position];
}
catch (IndexOutOfRangeException)
@@ -64,17 +61,25 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- return Insert(obj, 0);
+ return Insert(obj, 0, comparer);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
if (position < 0 || position > _collection.Length - 1)
{
throw new PositionOutOfCollectionException();
}
+ if (comparer != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningShip, item as DrawningShip))
+ throw new ObjectNotUniqueException();
+ }
+ }
for (int i = position; i < Count; i++)
{
if (_collection[i] == null)
@@ -119,4 +124,10 @@ public class MassiveGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ Array.Sort(_collection, comparer);
+ Array.Reverse(_collection);
+ }
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs
index bf12f6b..3d1be68 100644
--- a/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectLiner/ProjectLiner/CollectionGenericObjects/StorageCollection.cs
@@ -1,5 +1,6 @@
using ProjectLiner.Drawnings;
using ProjectLiner.Exceptions;
+using System.IO;
namespace ProjectLiner.CollectionGenericObjects;
@@ -29,19 +30,19 @@ public class StorageCollection
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> _storages;
+ readonly Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
///
/// Конструктор
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
@@ -51,21 +52,20 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
- {
+ CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
+ if (collectionInfo.Name == null || _storages.ContainsKey(collectionInfo))
+ {
return;
}
- if (collectionType == CollectionType.None)
- {
- return;
- }
- if (collectionType == CollectionType.Massive)
- {
- _storages[name] = new MassiveGenericObjects();
- }
- else if (collectionType == CollectionType.List)
- {
- _storages[name] = new ListGenericObjects();
+ switch (collectionType){
+ case CollectionType.None:
+ return;
+ case CollectionType.Massive:
+ _storages.Add(collectionInfo, new MassiveGenericObjects { });
+ return;
+ case CollectionType.List:
+ _storages.Add(collectionInfo, new ListGenericObjects { });
+ return;
}
}
@@ -75,11 +75,12 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- if (name == null || !_storages.ContainsKey(name))
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (collectionInfo.Name == null || !_storages.ContainsKey(collectionInfo))
{
return;
}
- _storages.Remove(name);
+ _storages.Remove(collectionInfo);
}
///
@@ -91,14 +92,12 @@ public class StorageCollection
{
get
{
- if (_storages.ContainsKey(name))
- {
- return _storages[name];
- }
- else
- {
- return null;
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (collectionInfo == null || !_storages.ContainsKey(collectionInfo))
+ {
+ return null;
}
+ return _storages[collectionInfo];
}
}
@@ -120,16 +119,17 @@ public class StorageCollection
using (StreamWriter writer = new StreamWriter(filename))
{
writer.WriteLine(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
- writer.Write($"{value.Key}{_separatorForKeyValue}{value.Value.GetCollectionType}{_separatorForKeyValue}{value.Value.MaxCount}{_separatorForKeyValue}");
+ writer.Write($"{value.Key}{_separatorForKeyValue}{value.Value.MaxCount}{_separatorForKeyValue}");
foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
if (!string.IsNullOrEmpty(data))
{
- writer.WriteLine(data);
+ writer.Write(data);
+ writer.Write(_separatorItems);
}
}
}
@@ -165,22 +165,18 @@ public class StorageCollection
while (line != null)
{
string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
+ if (record.Length != 3)
{
line = reader.ReadLine();
continue;
}
-
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
- if (collection == null)
- {
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ??
throw new InvalidCastException("Не удалось создать коллекцию");
- }
+ collection.MaxCount = Convert.ToInt32(record[1]);
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
@@ -197,7 +193,7 @@ public class StorageCollection
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
line = reader.ReadLine();
}
}
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawiningShipEqutables.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawiningShipEqutables.cs
new file mode 100644
index 0000000..e2d3491
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawiningShipEqutables.cs
@@ -0,0 +1,61 @@
+using ProjectLiner.Entities;
+using System.Diagnostics.CodeAnalysis;
+namespace ProjectLiner.Drawnings;
+
+///
+/// Реализация сравнения двух объектов класса-прорисовки
+///
+public class DrawiningShipEqutables : IEqualityComparer
+{
+ public bool Equals(DrawningShip? x, DrawningShip? y)
+ {
+ if (x == null || x.EntityShip == null)
+ {
+ return false;
+ }
+ if (y == null || y.EntityShip == null)
+ {
+ return false;
+ }
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return false;
+ }
+ if (x.EntityShip.Speed != y.EntityShip.Speed)
+ {
+ return false;
+ }
+ if (x.EntityShip.Weight != y.EntityShip.Weight)
+ {
+ return false;
+ }
+ if (x.EntityShip.BodyColor != y.EntityShip.BodyColor)
+ {
+ return false;
+ }
+ if (x is DrawningLiner && y is DrawningLiner)
+ {
+ EntityLiner _x = (EntityLiner)x.EntityShip;
+ EntityLiner _y = (EntityLiner)x.EntityShip;
+
+ if (_x.AdditionalColor != _y.AdditionalColor)
+ {
+ return false;
+ }
+ if (_x.SecondDeck != _y.SecondDeck)
+ {
+ return false;
+ }
+ if (_x.Pool != _y.Pool)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public int GetHashCode([DisallowNull] DrawningShip obj)
+ {
+ return obj.GetHashCode();
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/Drawnings/DrawningShipCompareByColor.cs b/ProjectLiner/ProjectLiner/Drawnings/DrawningShipCompareByColor.cs
new file mode 100644
index 0000000..284cd13
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/Drawnings/DrawningShipCompareByColor.cs
@@ -0,0 +1,37 @@
+namespace ProjectLiner.Drawnings;
+///
+/// Сравнение по цвету, скорости, весу
+///
+public class DrawningShipCompareByColor : IComparer
+{
+ public int Compare(DrawningShip? x, DrawningShip? y)
+ {
+ if (x == null && y == null)
+ {
+ return 0;
+ }
+ if (x == null || x.EntityShip == null)
+ {
+ return -1;
+ }
+
+ if (y == null || y.EntityShip == null)
+ {
+ return 1;
+ }
+
+ var bodycolorCompare = y.EntityShip.BodyColor.Name.CompareTo(x.EntityShip.BodyColor.Name);
+ if (bodycolorCompare != 0)
+ {
+ return bodycolorCompare;
+ }
+
+ var speedCompare = y.EntityShip.Speed.CompareTo(x.EntityShip.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+
+ return y.EntityShip.Weight.CompareTo(x.EntityShip.Weight);
+ }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/Exceptions/ObjectNotUniqueException.cs b/ProjectLiner/ProjectLiner/Exceptions/ObjectNotUniqueException.cs
new file mode 100644
index 0000000..507d73b
--- /dev/null
+++ b/ProjectLiner/ProjectLiner/Exceptions/ObjectNotUniqueException.cs
@@ -0,0 +1,15 @@
+using System.Runtime.Serialization;
+
+namespace ProjectLiner.Exceptions;
+
+///
+/// Класс, описывающий ошибку наличия такого же объекта в коллекции
+///
+[Serializable]
+internal class ObjectNotUniqueException : ApplicationException
+{
+ public ObjectNotUniqueException() : base("Такой объект уже присутствует в колекции") { }
+ public ObjectNotUniqueException(string message) : base(message) { }
+ public ObjectNotUniqueException(string message, Exception exception) : base(message, exception) { }
+ protected ObjectNotUniqueException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs b/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs
index a275372..2e0743b 100644
--- a/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs
+++ b/ProjectLiner/ProjectLiner/FormShipCollection.Designer.cs
@@ -34,6 +34,8 @@ namespace ProjectLiner
{
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
+ buttonSortByColor = new Button();
+ buttonSortByType = new Button();
buttonAddShip = new Button();
buttonRefresh = new Button();
maskedTextBoxPosition = new MaskedTextBox();
@@ -72,13 +74,15 @@ namespace ProjectLiner
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(793, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(144, 547);
+ groupBoxTools.Size = new Size(144, 588);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
+ panelCompanyTools.Controls.Add(buttonSortByColor);
+ panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonAddShip);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
@@ -88,9 +92,29 @@ namespace ProjectLiner
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 321);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(138, 223);
+ panelCompanyTools.Size = new Size(138, 264);
panelCompanyTools.TabIndex = 10;
//
+ // buttonSortByColor
+ //
+ buttonSortByColor.Location = new Point(4, 218);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(126, 43);
+ buttonSortByColor.TabIndex = 8;
+ buttonSortByColor.Text = "Сортировка по цвету";
+ buttonSortByColor.UseVisualStyleBackColor = true;
+ buttonSortByColor.Click += ButtonSortByColor_Click;
+ //
+ // buttonSortByType
+ //
+ buttonSortByType.Location = new Point(4, 182);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(126, 30);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += ButtonSortByType_Click;
+ //
// buttonAddShip
//
buttonAddShip.Location = new Point(4, 3);
@@ -103,9 +127,9 @@ namespace ProjectLiner
//
// buttonRefresh
//
- buttonRefresh.Location = new Point(4, 172);
+ buttonRefresh.Location = new Point(3, 153);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(126, 42);
+ buttonRefresh.Size = new Size(126, 26);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -113,7 +137,7 @@ namespace ProjectLiner
//
// maskedTextBoxPosition
//
- maskedTextBoxPosition.Location = new Point(4, 71);
+ maskedTextBoxPosition.Location = new Point(3, 52);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(126, 23);
@@ -122,7 +146,7 @@ namespace ProjectLiner
//
// buttonGoToCheck
//
- buttonGoToCheck.Location = new Point(4, 136);
+ buttonGoToCheck.Location = new Point(3, 117);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(126, 30);
buttonGoToCheck.TabIndex = 5;
@@ -132,7 +156,7 @@ namespace ProjectLiner
//
// buttonRemoveShip
//
- buttonRemoveShip.Location = new Point(4, 100);
+ buttonRemoveShip.Location = new Point(3, 81);
buttonRemoveShip.Name = "buttonRemoveShip";
buttonRemoveShip.Size = new Size(126, 30);
buttonRemoveShip.TabIndex = 4;
@@ -251,7 +275,7 @@ namespace ProjectLiner
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(793, 547);
+ pictureBox.Size = new Size(793, 588);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -299,7 +323,7 @@ namespace ProjectLiner
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(937, 571);
+ ClientSize = new Size(937, 612);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -344,5 +368,7 @@ namespace ProjectLiner
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
+ private Button buttonSortByColor;
+ private Button buttonSortByType;
}
}
\ No newline at end of file
diff --git a/ProjectLiner/ProjectLiner/FormShipCollection.cs b/ProjectLiner/ProjectLiner/FormShipCollection.cs
index 040f3b8..e52eb06 100644
--- a/ProjectLiner/ProjectLiner/FormShipCollection.cs
+++ b/ProjectLiner/ProjectLiner/FormShipCollection.cs
@@ -215,7 +215,7 @@ public partial class FormShipCollection : 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);
@@ -302,4 +302,38 @@ public partial class FormShipCollection : Form
RefreshListBoxItems();
}
}
+
+ ///
+ /// Сортировка по типу
+ ///
+ ///
+ ///
+ private void ButtonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareShips(new DrawningShipCompareByType());
+ }
+
+ ///
+ /// Сортировка по цвету
+ ///
+ ///
+ ///
+ private void ButtonSortByColor_Click(object sender, EventArgs e)
+ {
+ CompareShips(new DrawningShipCompareByColor());
+ }
+
+ ///
+ /// Сортировка по сравнителю
+ ///
+ /// Сравнитель объектов
+ private void CompareShips(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}
\ No newline at end of file