diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs
index 98858a8..598bdc8 100644
--- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs
@@ -55,7 +55,7 @@ public abstract class AbstractCompany
///
public static int operator +(AbstractCompany company, DrawingShip ship)
{
- return company._collection.Insert(ship);
+ return company._collection.Insert(ship, new DrawingShipEqutables());
}
///
/// Перегрузка оператора удаления для класса
@@ -93,6 +93,8 @@ public abstract class AbstractCompany
}
return bitmap;
}
+
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
///
/// Вывод заднего фона
///
diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..a8d1d5d
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLinkor.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/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs
index 2ee36f3..e86bb5b 100644
--- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,4 +1,5 @@
-using System;
+using ProjectLinkor.Drawnings;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -25,15 +26,17 @@ where T : class
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
+ /// Сравнение двух объеков
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
+ /// Сравнение двух объеков
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
///
@@ -56,4 +59,6 @@ where T : class
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+
+ void CollectionSort(IComparer comparer);
}
diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs
index 4425eca..b389ea6 100644
--- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,4 +1,5 @@
-using ProjectLinkor.Exceptions;
+using ProjectLinkor.Drawnings;
+using ProjectLinkor.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -48,16 +49,30 @@ public class ListGenericObjects : ICollectionGenericObjects
if (_collection[position] == null) throw new ObjectNotFoundException();
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)
+ {
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectAlreadyExistsException();
+ }
+ }
_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)
+ {
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectAlreadyExistsException(position);
+ }
+ }
_collection.Insert(position, obj);
return position;
@@ -77,4 +92,9 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs
index 38fe734..11ec030 100644
--- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,5 @@
-using ProjectLinkor.Exceptions;
+using ProjectLinkor.Drawnings;
+using ProjectLinkor.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -52,8 +53,18 @@ public class MassiveGenericObjects : ICollectionGenericObjects
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException();
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
+ if (comparer != null)
+ {
+ foreach (T? i in _collection)
+ {
+ if (comparer.Equals(i, obj))
+ {
+ throw new ObjectAlreadyExistsException(i);
+ }
+ }
+ }
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
@@ -64,12 +75,22 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
throw new CollectionOverflowException();
}
- 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();
}
+ if (comparer != null)
+ {
+ foreach (T? i in _collection)
+ {
+ if (comparer.Equals(i, obj))
+ {
+ throw new ObjectAlreadyExistsException(i);
+ }
+ }
+ }
if (_collection[position] == null)
{
_collection[position] = obj;
@@ -96,13 +117,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
--temp;
}
- return -1;
+ throw new CollectionOverflowException();
}
public T Remove(int position)
{
if (position >= Count || position < 0) throw new PositionOutOfCollectionException();
if (_collection[position] == null) throw new ObjectNotFoundException();
- T myObject = _collection[position];
+ T? myObject = _collection[position];
_collection[position] = null;
return myObject;
}
@@ -114,4 +135,9 @@ public class MassiveGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ Array.Sort(_collection, comparer);
+ }
}
diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs
index 87aa1d7..a8e215a 100644
--- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs
@@ -2,6 +2,7 @@
using ProjectLinkor.Exceptions;
using System;
using System.Collections.Generic;
+using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -17,11 +18,11 @@ public class StorageCollection
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> _storages;
+ readonly Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
///
/// Ключевое слово, с которого должен начинаться файл
@@ -41,7 +42,7 @@ public class StorageCollection
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
/// Добавление коллекции в хранилище
@@ -50,20 +51,20 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
- // TODO Прописать логику для добавления
- if (name == null || _storages.ContainsKey(name))
+ CollectionInfo collectionInfo = new(name, collectionType, string.Empty);
+ if (name == null || _storages.ContainsKey(collectionInfo))
return;
switch (collectionType)
{
case CollectionType.None:
return;
case CollectionType.Massive:
- _storages[name] = new MassiveGenericObjects();
+ _storages[collectionInfo] = new MassiveGenericObjects();
return;
case CollectionType.List:
- _storages[name] = new ListGenericObjects();
+ _storages[collectionInfo] = new ListGenericObjects();
return;
+ default: break;
}
}
@@ -73,9 +74,9 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- // TODO Прописать логику для удаления коллекции
- if (_storages.ContainsKey(name))
- _storages.Remove(name);
+ CollectionInfo collectionInfo = new(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ _storages.Remove(collectionInfo);
}
///
/// Доступ к коллекции
@@ -86,17 +87,18 @@ public class StorageCollection
{
get
{
- // TODO Продумать логику получения объекта
- if (name == null || !_storages.ContainsKey(name))
- return null;
- return _storages[name];
+ CollectionInfo collectionInfo = new(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ return _storages[collectionInfo];
+ return null;
}
}
public void SaveData(string filename)
{
if (_storages.Count == 0)
{
- throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
+ throw new InvalidDataException("В хранилище отсутствуют коллекции для сохранения");
+
}
if (File.Exists(filename))
{
@@ -105,7 +107,7 @@ public class StorageCollection
using (StreamWriter writer = new(filename))
{
writer.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
writer.Write(Environment.NewLine);
// не сохраняем пустые коллекции
@@ -115,8 +117,6 @@ public class StorageCollection
}
writer.Write(value.Key);
writer.Write(_separatorForKeyValue);
- writer.Write(value.Value.GetCollectionType);
- writer.Write(_separatorForKeyValue);
writer.Write(value.Value.MaxCount);
writer.Write(_separatorForKeyValue);
@@ -159,17 +159,20 @@ public class StorageCollection
{
string[] record = line.Split(_separatorForKeyValue,
StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 4)
+ if (record.Length != 3)
{
continue;
}
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new Exception("Не удалось определить информацию коллекции" + record[0]);
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ??
- throw new InvalidCastException("Не удалось определить тип коллекции:" + record[1]); ;
-
- collection.MaxCount = Convert.ToInt32(record[2]);
- string[] set = record[3].Split(_separatorItems,
- StringSplitOptions.RemoveEmptyEntries);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType);
+ if (collection == null)
+ {
+ throw new InvalidOperationException("Не удалось создать коллекцию");
+ }
+ collection.MaxCount = Convert.ToInt32(record[1]);
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawingShip() is T ship)
@@ -178,16 +181,16 @@ public class StorageCollection
{
if (collection.Insert(ship) == -1)
{
- throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
+ throw new ConstraintException("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowException ex)
{
- throw new CollectionOverflowException("Коллекция переполнена", ex);
+ throw new DataException("Коллекция переполнена", ex);
}
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
}
}
diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipCompareByColor.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipCompareByColor.cs
new file mode 100644
index 0000000..1659b5d
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipCompareByColor.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLinkor.Drawnings;
+
+public class DrawingShipCompareByColor : IComparer
+{
+ public int Compare(DrawingShip? x, DrawingShip? y)
+ {
+ if (x == null || x.EntityShip == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityShip == null)
+ {
+ return -1;
+ }
+ var bodycolorCompare = x.EntityShip.BodyColor.Name.CompareTo(y.EntityShip.BodyColor.Name);
+ if (bodycolorCompare != 0)
+ {
+ return bodycolorCompare;
+ }
+ var speedCompare = x.EntityShip.Speed.CompareTo(y.EntityShip.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityShip.Weight.CompareTo(y.EntityShip.Weight);
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipCompareByType.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipCompareByType.cs
new file mode 100644
index 0000000..79d83da
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipCompareByType.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLinkor.Drawnings;
+
+public class DrawingShipCompareByType : IComparer
+{
+ public int Compare(DrawingShip? x, DrawingShip? y)
+ {
+ 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);
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipEqutables.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipEqutables.cs
new file mode 100644
index 0000000..b7e89ea
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawingShipEqutables.cs
@@ -0,0 +1,64 @@
+using ProjectLinkor.Entities;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLinkor.Drawnings;
+
+public class DrawingShipEqutables : IEqualityComparer
+{
+ public bool Equals(DrawingShip? x, DrawingShip? 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 DrawingLinkor && y is DrawingLinkor)
+ {
+ // TODO доделать логику сравнения дополнительных параметров
+ EntityLinkor entityX = (EntityLinkor)x.EntityShip;
+ EntityLinkor entityY = (EntityLinkor)y.EntityShip;
+ if (entityX.Rocket != entityY.Rocket)
+ {
+ return false;
+ }
+ if (entityX.Gun != entityY.Gun)
+ {
+ return false;
+ }
+ if (entityX.AdditionalColor != entityY.AdditionalColor)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public int GetHashCode([DisallowNull] DrawingShip? obj)
+ {
+ return obj.GetHashCode();
+ }
+}
\ No newline at end of file
diff --git a/ProjectAirbus/ProjectAirbus/Exceptions/ObjectAlreadyExistsException.cs b/ProjectAirbus/ProjectAirbus/Exceptions/ObjectAlreadyExistsException.cs
new file mode 100644
index 0000000..eb0dd9a
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/Exceptions/ObjectAlreadyExistsException.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectLinkor.Exceptions;
+///
+/// Класс, описывающий ошибку, что в коллекции уже есть такой элемент
+///
+[Serializable]
+public class ObjectAlreadyExistsException : ApplicationException
+{
+ public ObjectAlreadyExistsException(object i) : base("В коллекции уже есть такой элемент " + i) { }
+ public ObjectAlreadyExistsException() : base() { }
+ public ObjectAlreadyExistsException(string message) : base(message) { }
+ public ObjectAlreadyExistsException(string message, Exception exception) : base(message, exception)
+ { }
+ protected ObjectAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
+}
diff --git a/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs
index 4793339..16625ac 100644
--- a/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs
+++ b/ProjectAirbus/ProjectAirbus/FormShipCollection.Designer.cs
@@ -52,6 +52,8 @@
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
+ buttonSortByColor = new Button();
+ buttonSortByType = new Button();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@@ -68,13 +70,15 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(752, 33);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(300, 854);
+ groupBoxTools.Size = new Size(300, 957);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
+ panelCompanyTools.Controls.Add(buttonSortByColor);
+ panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonAddShip);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
@@ -83,7 +87,7 @@
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Location = new Point(3, 479);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(294, 372);
+ panelCompanyTools.Size = new Size(294, 475);
panelCompanyTools.TabIndex = 8;
//
// buttonAddShip
@@ -98,7 +102,7 @@
//
// maskedTextBoxPosition
//
- maskedTextBoxPosition.Location = new Point(17, 125);
+ maskedTextBoxPosition.Location = new Point(13, 79);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(264, 31);
@@ -108,7 +112,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(17, 303);
+ buttonRefresh.Location = new Point(13, 257);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(264, 60);
buttonRefresh.TabIndex = 6;
@@ -119,7 +123,7 @@
// buttonRemoveShip
//
buttonRemoveShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveShip.Location = new Point(17, 171);
+ buttonRemoveShip.Location = new Point(13, 125);
buttonRemoveShip.Name = "buttonRemoveShip";
buttonRemoveShip.Size = new Size(264, 60);
buttonRemoveShip.TabIndex = 4;
@@ -130,7 +134,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(17, 237);
+ buttonGoToCheck.Location = new Point(13, 191);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(264, 60);
buttonGoToCheck.TabIndex = 5;
@@ -247,7 +251,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 33);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(752, 854);
+ pictureBox.Size = new Size(752, 957);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -292,11 +296,33 @@
//
openFileDialog.Filter = "txt file | *.txt";
//
+ // buttonSortByColor
+ //
+ buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByColor.Location = new Point(13, 389);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(264, 60);
+ 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(13, 323);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(264, 60);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += ButtonSortByType_Click;
+ //
// FormShipCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1052, 887);
+ ClientSize = new Size(1052, 990);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -341,5 +367,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/ProjectAirbus/ProjectAirbus/FormShipCollection.cs b/ProjectAirbus/ProjectAirbus/FormShipCollection.cs
index 6094f85..6f2c35e 100644
--- a/ProjectAirbus/ProjectAirbus/FormShipCollection.cs
+++ b/ProjectAirbus/ProjectAirbus/FormShipCollection.cs
@@ -74,6 +74,11 @@ public partial class FormShipCollection : Form
MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"Не удалось добавить объект: {ex.Message}");
}
+ catch (ObjectAlreadyExistsException)
+ {
+ MessageBox.Show("Такой объект уже существует");
+ _logger.LogError("Ошибка: такой объект уже существует {0}", ship);
+ }
}
private void ButtonRemoveShip_Click(object sender, EventArgs e)
@@ -223,7 +228,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);
@@ -308,4 +313,23 @@ public partial class FormShipCollection : Form
}
}
}
+
+ private void ButtonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareShips(new DrawingShipCompareByType());
+ }
+
+ private void ButtonSortByColor_Click(object sender, EventArgs e)
+ {
+ CompareShips(new DrawingShipCompareByColor());
+ }
+ private void CompareShips(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}