diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs
index ae6c62f..e0377ca 100644
--- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs
@@ -54,7 +54,7 @@ public abstract class AbstractCompany
///
public static int operator +(AbstractCompany company, DrawningPlane plane)
{
- return company._collection.Insert(plane);
+ return company._collection.Insert(plane, new DrawningPlaneEqutables());
}
///
/// Перегрузка оператора удаления для класса
@@ -105,4 +105,9 @@ public abstract class AbstractCompany
/// Расстановка объектов
///
protected abstract void SetObjectsPosition();
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
}
\ No newline at end of file
diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/CollectionInfo.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..b296add
--- /dev/null
+++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirPlane.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;
+ }
+ ///
+ /// Создание объекта из строки
+ ///
+ ///
+ ///
+ 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/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs
index 901e1cc..8818901 100644
--- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ProjectAirPlane.Drawnings;
namespace ProjectAirPlane.CollectionGenericObjects;
@@ -10,37 +11,34 @@ public interface ICollectionGenericObjects
where T : class
{
///
- /// Количество объектов в коллекции
- ///
- int Count { get; }
-
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
///
/// Установка максимального количества элементов
///
int MaxCount { set; get; }
-
///
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
- /// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
-
+ /// /// Cравнение двух объектов
+ /// true - вставка прошла удачно, false - вставка неудалась
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
- /// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
-
+ /// Cравнение двух объектов
+ /// true - вставка прошла удачно, false - вставка неудалась
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
- /// true - удаление прошло удачно, false - удаление не удалось
- T? Remove(int position);
-
+ /// true - удаление прошло удачно, false - удаление неудалось
+ T Remove(int position);
///
/// Получение объекта по позиции
///
@@ -56,4 +54,9 @@ public interface ICollectionGenericObjects
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+ ///
+ /// Сортировка коллекции
+ ///
+ /// Сравнитель объектов
+ void CollectionSort(IComparer comparer);
}
diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ListGenericObjects.cs
index d983574..9c949a8 100644
--- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ListGenericObjects.cs
@@ -12,18 +12,17 @@ public class ListGenericObjects : ICollectionGenericObjects
where T : class
{
///
- /// Список объектов, которые храним
- ///
- private readonly List _collection;
+ /// Список объектов, которые храним
+ ///
+ private readonly List _collection;
public CollectionType GetCollectionType => CollectionType.List;
///
/// Максимально допустимое число объектов в списке
///
private int _maxCount;
-
public int Count => _collection.Count;
-
- public int MaxCount {
+ public int MaxCount
+ {
get
{
return Count;
@@ -36,8 +35,6 @@ public class ListGenericObjects : ICollectionGenericObjects
}
}
}
-
-
///
/// Конструктор
///
@@ -45,44 +42,45 @@ public class ListGenericObjects : ICollectionGenericObjects
{
_collection = new();
}
-
public T? Get(int position)
{
- // TODO проверка позиции
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
return _collection[position];
}
-
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO вставка в конец набора
+ if (comparer != null)
+ {
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectIsEqualException();
+ }
+ }
if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj);
return Count;
}
-
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
- // TODO проверка, что не превышено максимальное количество элементов
- // TODO проверка позиции
- // TODO вставка по позиции
+ if (comparer != null)
+ {
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectIsEqualException();
+ }
+ }
if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
_collection.Insert(position, obj);
return position;
}
-
public T Remove(int position)
{
- // TODO проверка позиции
- // TODO удаление объекта из списка
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
-
public IEnumerable GetItems()
{
for (int i = 0; i < Count; ++i)
@@ -90,4 +88,8 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+ void ICollectionGenericObjects.CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs
index 38a1ead..7677689 100644
--- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ProjectAirPlane.Drawnings;
using ProjectAirPlane.Exceptions;
namespace ProjectAirPlane.CollectionGenericObjects;
@@ -57,9 +58,16 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- // TODO вставка в свободное место набора
+ if (comparer != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningPlane, item as DrawningPlane))
+ throw new ObjectIsEqualException();
+ }
+ }
int index = 0;
while (index < _collection.Length)
{
@@ -73,15 +81,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)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
+ if (comparer != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningPlane, item as DrawningPlane))
+ throw new ObjectIsEqualException();
+ }
+ }
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
-
if (_collection[position] == null)
{
_collection[position] = obj;
@@ -130,4 +145,9 @@ public class MassiveGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ void ICollectionGenericObjects.CollectionSort(IComparer comparer)
+ {
+ Array.Sort(_collection, comparer);
+ }
}
diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/StorageCollection.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/StorageCollection.cs
index 0348da0..29a03a0 100644
--- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/StorageCollection.cs
@@ -14,17 +14,17 @@ 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>();
}
///
/// Добавление коллекции в хранилище
@@ -33,12 +33,13 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (_storages.ContainsKey(name)) return;
+ CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
+ if (_storages.ContainsKey(collectionInfo)) return;
if (collectionType == CollectionType.None) return;
else if (collectionType == CollectionType.Massive)
- _storages[name] = new MassiveGenericObjects();
+ _storages[collectionInfo] = new MassiveGenericObjects();
else if (collectionType == CollectionType.List)
- _storages[name] = new ListGenericObjects();
+ _storages[collectionInfo] = new ListGenericObjects();
}
///
/// Удаление коллекции
@@ -46,8 +47,9 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- if (_storages.ContainsKey(name))
- _storages.Remove(name);
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ _storages.Remove(collectionInfo);
}
///
/// Доступ к коллекции
@@ -58,8 +60,9 @@ public class StorageCollection
{
get
{
- if (_storages.ContainsKey(name))
- return _storages[name];
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ return _storages[collectionInfo];
return null;
}
}
@@ -92,7 +95,7 @@ public class StorageCollection
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
writer.Write(Environment.NewLine);
if (value.Value.Count == 0)
@@ -101,8 +104,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);
foreach (T? item in value.Value.GetItems())
@@ -144,18 +145,20 @@ 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);
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ??
+ throw new Exception("Не удалось создать коллекцию");
if (collection == null)
{
throw new Exception("Не удалось создать коллекцию");
}
- collection.MaxCount = Convert.ToInt32(record[2]);
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ collection.MaxCount = Convert.ToInt32(record[1]);
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningPlane() is T plane)
@@ -173,7 +176,7 @@ public class StorageCollection
}
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
}
}
@@ -187,8 +190,7 @@ public class StorageCollection
return collectionType switch
{
CollectionType.Massive => new MassiveGenericObjects(),
- CollectionType.List => new ListGenericObjects(),
- _ => null,
+ CollectionType.List => new ListGenericObjects(),_ => null,
};
}
diff --git a/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneCompareByColor.cs b/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneCompareByColor.cs
new file mode 100644
index 0000000..bcfc85f
--- /dev/null
+++ b/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneCompareByColor.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirPlane.Drawnings;
+///
+/// Сравнение по цвету, скорости, весу
+///
+public class DrawningPlaneCompareByColor : IComparer
+{
+ public int Compare(DrawningPlane? x, DrawningPlane? y)
+ {
+ if (x == null || x.EntityPlane == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityPlane == null)
+ {
+ return -1;
+ }
+ var bodycolorCompare = x.EntityPlane.BodyColor.Name.CompareTo(y.EntityPlane.BodyColor.Name);
+ if (bodycolorCompare != 0)
+ {
+ return bodycolorCompare;
+ }
+ var speedCompare = x.EntityPlane.Speed.CompareTo(y.EntityPlane.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityPlane.Weight.CompareTo(y.EntityPlane.Weight);
+ }
+}
diff --git a/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneCompareByType.cs b/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneCompareByType.cs
new file mode 100644
index 0000000..0ee7416
--- /dev/null
+++ b/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneCompareByType.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirPlane.Drawnings;
+///
+/// Сравнение по типу, скорости, весу
+///
+public class DrawningPlaneCompareByType : IComparer
+{
+ public int Compare(DrawningPlane? x, DrawningPlane? y)
+ {
+ if (x == null || x.EntityPlane == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityPlane == null)
+ {
+ return -1;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return x.GetType().Name.CompareTo(y.GetType().Name);
+ }
+
+ var speedCompare = x.EntityPlane.Speed.CompareTo(y.EntityPlane.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityPlane.Weight.CompareTo(y.EntityPlane.Weight);
+ }
+}
diff --git a/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneEqutables.cs b/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneEqutables.cs
new file mode 100644
index 0000000..eb21062
--- /dev/null
+++ b/ProjectAirPlane/ProjectAirPlane/Drawnings/DrawningPlaneEqutables.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectAirPlane.Entites;
+
+namespace ProjectAirPlane.Drawnings;
+
+///
+/// Реализация сравнения двух объектов класса-прорисовки
+///
+public class DrawningPlaneEqutables: IEqualityComparer
+{
+ public bool Equals(DrawningPlane? x, DrawningPlane? y)
+ {
+ if (x == null || x.EntityPlane == null)
+ {
+ return false;
+ }
+ if (y == null || y.EntityPlane == null)
+ {
+ return false;
+ }
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return false;
+ }
+ if (x.EntityPlane.Speed != y.EntityPlane.Speed)
+ {
+ return false;
+ }
+ if (x.EntityPlane.Weight != y.EntityPlane.Weight)
+ {
+ return false;
+ }
+ if (x.EntityPlane.BodyColor != y.EntityPlane.BodyColor)
+ {
+ return false;
+ }
+ if (x is DrawningAirPlane && y is DrawningAirPlane)
+ {
+ EntityAirPlane _x = (EntityAirPlane)x.EntityPlane;
+ EntityAirPlane _y = (EntityAirPlane)x.EntityPlane;
+ if (_x.AdditionalColor != _y.AdditionalColor)
+ {
+ return false;
+ }
+ if (_x.DopBak != _y.DopBak)
+ {
+ return false;
+ }
+ if (_x.Radar != _y.Radar)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ public int GetHashCode([DisallowNull] DrawningPlane obj)
+ {
+ return obj.GetHashCode();
+ }
+}
diff --git a/ProjectAirPlane/ProjectAirPlane/Exceptions/ObjectIsEqualException.cs b/ProjectAirPlane/ProjectAirPlane/Exceptions/ObjectIsEqualException.cs
new file mode 100644
index 0000000..86ed457
--- /dev/null
+++ b/ProjectAirPlane/ProjectAirPlane/Exceptions/ObjectIsEqualException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+///
+/// Класс, описывающий ошибку переполнения коллекции
+///
+[Serializable]
+public class ObjectIsEqualException : ApplicationException
+{
+ public ObjectIsEqualException(int count) : base("В коллекции содержится равный элемент: " + count) { }
+ public ObjectIsEqualException() : base() { }
+ public ObjectIsEqualException(string message) : base(message) { }
+ public ObjectIsEqualException(string message, Exception exception) : base(message, exception) { }
+ protected ObjectIsEqualException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+}
diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs
index b3b42ee..7ecb26e 100644
--- a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs
+++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs
@@ -52,6 +52,8 @@
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
+ buttonSortByType = new Button();
+ buttonSortByColor = new Button();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@@ -61,6 +63,7 @@
//
// groupBoxTools
//
+ groupBoxTools.Controls.Add(buttonAddPlane);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(panelStorage);
@@ -68,31 +71,32 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(686, 24);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(195, 534);
+ groupBoxTools.Size = new Size(195, 611);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
- panelCompanyTools.Controls.Add(buttonAddPlane);
+ panelCompanyTools.Controls.Add(buttonSortByColor);
+ panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemovePlane);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
- panelCompanyTools.Location = new Point(3, 343);
+ panelCompanyTools.Location = new Point(3, 377);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(189, 188);
+ panelCompanyTools.Size = new Size(189, 231);
panelCompanyTools.TabIndex = 8;
//
// buttonAddPlane
//
buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddPlane.Location = new Point(3, 13);
+ buttonAddPlane.Location = new Point(6, 343);
buttonAddPlane.Name = "buttonAddPlane";
- buttonAddPlane.Size = new Size(166, 28);
+ buttonAddPlane.Size = new Size(177, 28);
buttonAddPlane.TabIndex = 1;
buttonAddPlane.Text = "Добавление самолёта";
buttonAddPlane.UseVisualStyleBackColor = true;
@@ -100,10 +104,10 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(6, 57);
+ maskedTextBox.Location = new Point(3, 0);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
- maskedTextBox.Size = new Size(166, 23);
+ maskedTextBox.Size = new Size(177, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
maskedTextBox.MaskInputRejected += MaskedTextBox_MaskInputRejected;
@@ -111,9 +115,9 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(6, 156);
+ buttonRefresh.Location = new Point(3, 99);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(166, 25);
+ buttonRefresh.Size = new Size(177, 25);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -122,9 +126,9 @@
// buttonRemovePlane
//
buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemovePlane.Location = new Point(7, 86);
+ buttonRemovePlane.Location = new Point(4, 29);
buttonRemovePlane.Name = "buttonRemovePlane";
- buttonRemovePlane.Size = new Size(166, 24);
+ buttonRemovePlane.Size = new Size(176, 24);
buttonRemovePlane.TabIndex = 4;
buttonRemovePlane.Text = "Удалить самолёт";
buttonRemovePlane.UseVisualStyleBackColor = true;
@@ -133,9 +137,9 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(6, 125);
+ buttonGoToCheck.Location = new Point(3, 68);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(166, 25);
+ buttonGoToCheck.Size = new Size(177, 25);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -250,7 +254,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(686, 534);
+ pictureBox.Size = new Size(686, 611);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -294,11 +298,33 @@
//
openFileDialog.Filter = "txt file | *.txt";
//
+ // buttonSortByType
+ //
+ buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByType.Location = new Point(4, 130);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(177, 42);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += ButtonSortByType_Click;
+ //
+ // buttonSortByColor
+ //
+ buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByColor.Location = new Point(4, 178);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(177, 35);
+ buttonSortByColor.TabIndex = 8;
+ buttonSortByColor.Text = "Сортирова по цвету";
+ buttonSortByColor.UseVisualStyleBackColor = true;
+ buttonSortByColor.Click += ButtonSortByColor_Click;
+ //
// FormPlaneCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(881, 558);
+ ClientSize = new Size(881, 635);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -343,5 +369,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/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs
index 6fbce15..e9977c9 100644
--- a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs
+++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs
@@ -87,7 +87,12 @@ public partial class FormPlaneCollection : Form
catch (CollectionOverflowException ex)
{
MessageBox.Show("Не удалось добавить объект");
- _logger.LogError("Ошибка : {Messsage}", ex.Message);
+ _logger.LogError("Ошибка: {Message}", ex.Message);
+ }
+ catch (ObjectIsEqualException ex)
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ _logger.LogError("Ошибка: {Message}", ex.Message);
}
}
@@ -218,7 +223,7 @@ public partial class FormPlaneCollection : 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);
@@ -333,5 +338,25 @@ public partial class FormPlaneCollection : Form
}
}
}
+
+ private void ButtonSortByType_Click(object sender, EventArgs e)
+ {
+ ComparePlane(new DrawningPlaneCompareByType());
+ }
+
+ private void ButtonSortByColor_Click(object sender, EventArgs e)
+ {
+ ComparePlane(new DrawningPlaneCompareByColor());
+ }
+
+ private void ComparePlane(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}