diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs
index 0b45261..f12345e 100644
--- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs
@@ -28,7 +28,7 @@ public abstract class AbstractCompany
///
/// Вычисление максимального количества элементов, который можно разместитьв окне
///
- private int GetMaxCount => (_pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight))-1;
+ private int GetMaxCount => (_pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight)) - 1;
///
/// Конструктор
///
@@ -51,7 +51,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());
}
///
/// Перегрузка оператора удаления для класса
@@ -103,4 +103,10 @@ 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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/CollectionInfo.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..dff8764
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAiroplane.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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs
index 423488b..fbb5519 100644
--- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,4 +1,5 @@
namespace ProjectAiroplane.CollectionGenericObjects;
+
///
/// Интерфейс описания действий для набора хранимых объектов
///
@@ -24,14 +25,14 @@ where T : class
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? compaper = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? compaper = null);
///
/// Удаление объекта из коллекции с конкретной позиции
///
@@ -54,4 +55,5 @@ where T : class
///
///
IEnumerable GetItems();
+ void CollectionSort(IComparer comparer);
}
diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs
index 3b856da..e5a1b0a 100644
--- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs
@@ -45,20 +45,37 @@ public class ListGenericObjects : ICollectionGenericObjects
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? compaper = null)
{
+ if (compaper != null)
+ {
+ if (_collection.Contains(obj, compaper))
+ {
+ throw new ObjectIsEqualException();
+ }
+ }
+
if (Count == _maxCount) throw new CollectionOverflowException();
_collection.Add(obj);
return Count;
}
- public int Insert(T obj, int position)
+
+ public int Insert(T obj, int position, IEqualityComparer? compaper = null)
{
+ if (compaper != null)
+ {
+ if (_collection.Contains(obj, compaper))
+ {
+ 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 проверка позиции
@@ -76,4 +93,9 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs
index cd89687..83fd4ba 100644
--- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,5 @@
-using ProjectAiroplane.Exceptions;
+using ProjectAiroplane.Drawnings;
+using ProjectAiroplane.Exceptions;
namespace ProjectAiroplane.CollectionGenericObjects;
@@ -47,6 +48,7 @@ where T : class
{
_collection = Array.Empty();
}
+
public T? Get(int position)
{
// TODO проверка позиции
@@ -56,8 +58,17 @@ where T : class
if (_collection[position] == null) throw new ObjectNotFoundException(position);
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? compaper = null)
{
+ if (compaper != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((compaper as IEqualityComparer).Equals(obj as Drawningplane, item as Drawningplane))
+ throw new ObjectIsEqualException();
+ }
+ }
+
// TODO вставка в свободное место набора
int index = 0;
while (index < _collection.Length)
@@ -72,8 +83,17 @@ where T : class
}
throw new CollectionOverflowException(Count);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? compaper = null)
{
+ if (compaper != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((compaper as IEqualityComparer).Equals(obj as Drawningplane, item as Drawningplane))
+ throw new ObjectIsEqualException();
+ }
+ }
+
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
@@ -119,7 +139,7 @@ where T : class
{
throw new PositionOutOfCollectionException(position);
}
- if (_collection[position] == null) throw new ObjectNotFoundException(position);//выброс1
+ if (_collection[position] == null) throw new ObjectNotFoundException(position);
T obj = _collection[position];
_collection[position] = null;
return obj;
@@ -133,4 +153,9 @@ where T : class
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ Array.Sort(_collection, comparer);
+ }
}
\ No newline at end of file
diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs
index fb5a3c1..d08e8d7 100644
--- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs
@@ -13,17 +13,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>();
}
///
/// Добавление коллекции в хранилище
@@ -35,12 +35,13 @@ public class StorageCollection
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
- 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();
}
///
/// Удаление коллекции
@@ -48,9 +49,9 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- // TODO Прописать логику для удаления коллекции
- if (_storages.ContainsKey(name))
- _storages.Remove(name);
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ _storages.Remove(collectionInfo);
}
///
@@ -62,10 +63,13 @@ public class StorageCollection
{
get
{
- // TODO Продумать логику получения объекта
- 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;
+
}
}
@@ -104,7 +108,7 @@ public class StorageCollection
{
writer.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
StringBuilder sb = new();
@@ -117,8 +121,6 @@ public class StorageCollection
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
- sb.Append(value.Value.GetCollectionType);
- sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
@@ -159,57 +161,58 @@ public class StorageCollection
{
throw new Exception("В файле неверные данные");
}
-
+
_storages.Clear();
string strs = "";
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);//////////////////CreateCollection
-
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
+
+ ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType);
+
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 airoplane)//////////////////////////////////////////////////////////////////CreateDrawningplane()
-
+
{
try
-
+
{
if (collection.Insert(airoplane) == -1)
-
+
{
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowException ex)
-
- {
- throw new Exception("Коллекция переполнена", ex);
+
+ {
+ throw new Exception("Коллекция переполнена", ex);
}
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
diff --git a/ProjectSportCar/ProjectSportCar/Drawnings/DrawningPlaneEqutables.cs b/ProjectSportCar/ProjectSportCar/Drawnings/DrawningPlaneEqutables.cs
new file mode 100644
index 0000000..72dc52b
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/Drawnings/DrawningPlaneEqutables.cs
@@ -0,0 +1,72 @@
+namespace ProjectAiroplane.Drawnings;
+using ProjectAiroplane.Entities;
+using System.Diagnostics.CodeAnalysis;
+
+
+///
+/// Реализация сравнения двух объектов класса-прорисовки
+///
+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 EntityAiroplane && y is EntityAiroplane)
+ {
+ // TODO доделать логику сравнения дополнительных параметров
+ EntityAiroplane _x = (EntityAiroplane)x.Entityplane ;
+
+ EntityAiroplane _y = (EntityAiroplane)x.Entityplane;
+
+ if (_x.AdditionalColor != _y.AdditionalColor)
+ {
+ return false;
+ }
+
+ if (_x.Toplivbak != _y.Toplivbak)
+ {
+ return false;
+ }
+
+ if (_x.Radar != _y.Radar)
+ {
+ return false;
+ }
+
+ }
+ return true;
+ }
+ public int GetHashCode([DisallowNull] Drawningplane? obj)
+ {
+ return obj.GetHashCode();
+ }
+}
diff --git a/ProjectSportCar/ProjectSportCar/Drawnings/PlaneCompareByColor.cs b/ProjectSportCar/ProjectSportCar/Drawnings/PlaneCompareByColor.cs
new file mode 100644
index 0000000..d7957c3
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/Drawnings/PlaneCompareByColor.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAiroplane.Drawnings;
+
+internal class PlaneCompareByColor : 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/ProjectSportCar/ProjectSportCar/Drawnings/PlaneCompareByType.cs b/ProjectSportCar/ProjectSportCar/Drawnings/PlaneCompareByType.cs
new file mode 100644
index 0000000..d73d578
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/Drawnings/PlaneCompareByType.cs
@@ -0,0 +1,41 @@
+using ProjectAiroplane.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAiroplane.CollectionGenericObjects;
+
+///
+/// Сравнение по типу, скорости, весу
+///
+public class PlaneCompareByType : 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/ProjectSportCar/ProjectSportCar/Exceptions/ObjectIsEqualException.cs b/ProjectSportCar/ProjectSportCar/Exceptions/ObjectIsEqualException.cs
new file mode 100644
index 0000000..bba2fbb
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/Exceptions/ObjectIsEqualException.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 ProjectAiroplane.Exceptions;
+
+///
+/// Класс, описывающий ошибку переполнения коллекции
+///
+[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/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs
index e5493fb..263849a 100644
--- a/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs
+++ b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs
@@ -52,6 +52,8 @@
loadToolStripMenuItem = new ToolStripMenuItem();
openFileDialog = new OpenFileDialog();
saveFileDialog = new SaveFileDialog();
+ buttonSortByType = new Button();
+ buttonSortByColor = new Button();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@@ -68,27 +70,29 @@
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(859, 28);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(277, 652);
+ groupBoxTools.Size = new Size(277, 689);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
+ panelCompanyTools.Controls.Add(buttonSortByType);
+ panelCompanyTools.Controls.Add(buttonSortByColor);
panelCompanyTools.Controls.Add(buttonAddPlane);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonDelPlane);
panelCompanyTools.Controls.Add(maskedTextBox1);
panelCompanyTools.Controls.Add(buttonReFresh);
panelCompanyTools.Enabled = false;
- panelCompanyTools.Location = new Point(9, 380);
+ panelCompanyTools.Location = new Point(9, 364);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(268, 322);
+ panelCompanyTools.Size = new Size(268, 338);
panelCompanyTools.TabIndex = 9;
//
// buttonAddPlane
//
- buttonAddPlane.Location = new Point(7, 14);
+ buttonAddPlane.Location = new Point(4, 3);
buttonAddPlane.Name = "buttonAddPlane";
buttonAddPlane.Size = new Size(252, 40);
buttonAddPlane.TabIndex = 1;
@@ -98,7 +102,7 @@
//
// buttonGoToCheck
//
- buttonGoToCheck.Location = new Point(4, 168);
+ buttonGoToCheck.Location = new Point(4, 131);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(254, 42);
buttonGoToCheck.TabIndex = 5;
@@ -108,7 +112,7 @@
//
// buttonDelPlane
//
- buttonDelPlane.Location = new Point(4, 119);
+ buttonDelPlane.Location = new Point(4, 82);
buttonDelPlane.Name = "buttonDelPlane";
buttonDelPlane.Size = new Size(254, 43);
buttonDelPlane.TabIndex = 4;
@@ -118,7 +122,7 @@
//
// maskedTextBox1
//
- maskedTextBox1.Location = new Point(7, 74);
+ maskedTextBox1.Location = new Point(6, 49);
maskedTextBox1.Mask = "00";
maskedTextBox1.Name = "maskedTextBox1";
maskedTextBox1.Size = new Size(252, 27);
@@ -127,7 +131,7 @@
//
// buttonReFresh
//
- buttonReFresh.Location = new Point(4, 220);
+ buttonReFresh.Location = new Point(4, 179);
buttonReFresh.Name = "buttonReFresh";
buttonReFresh.Size = new Size(252, 40);
buttonReFresh.TabIndex = 6;
@@ -137,7 +141,7 @@
//
// buttonCreateCompany
//
- buttonCreateCompany.Location = new Point(13, 346);
+ buttonCreateCompany.Location = new Point(13, 330);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(252, 28);
buttonCreateCompany.TabIndex = 8;
@@ -157,7 +161,7 @@
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 23);
panelStorage.Name = "panelStorage";
- panelStorage.Size = new Size(271, 283);
+ panelStorage.Size = new Size(271, 270);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
@@ -233,7 +237,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(13, 312);
+ comboBoxSelectorCompany.Location = new Point(13, 296);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(252, 28);
comboBoxSelectorCompany.TabIndex = 0;
@@ -244,7 +248,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(859, 652);
+ pictureBox.Size = new Size(859, 689);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -289,11 +293,31 @@
//
saveFileDialog.Filter = "txt file | *.txt";
//
+ // buttonSortByType
+ //
+ buttonSortByType.Location = new Point(4, 225);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(254, 42);
+ buttonSortByType.TabIndex = 7;
+ buttonSortByType.Text = "Сортировать по Типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += buttonSortByType_Click;
+ //
+ // buttonSortByColor
+ //
+ buttonSortByColor.Location = new Point(4, 273);
+ buttonSortByColor.Name = "buttonSortByColor";
+ buttonSortByColor.Size = new Size(252, 40);
+ buttonSortByColor.TabIndex = 8;
+ buttonSortByColor.Text = "Сортировать по Цвету";
+ buttonSortByColor.UseVisualStyleBackColor = true;
+ buttonSortByColor.Click += buttonSortByColor_Click;
+ //
// FormPlaneCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1136, 680);
+ ClientSize = new Size(1136, 717);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip1);
@@ -338,5 +362,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
+ private Button buttonSortByType;
+ private Button buttonSortByColor;
}
}
\ No newline at end of file
diff --git a/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs
index 5949fca..3cc73f0 100644
--- a/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs
+++ b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs
@@ -77,18 +77,15 @@ public partial class FormPlaneCollection : Form
}
}
- catch (ObjectNotFoundException) { MessageBox.Show("Не удалось добавить объект");//ловлю ошибку1
-
- }
-
+ catch (ObjectNotFoundException) { }
catch (CollectionOverflowException ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
- catch (PositionOutOfCollectionException ex)
+ catch (ObjectIsEqualException ex)
{
- MessageBox.Show("Выход за границы коллекции");
+ MessageBox.Show("Не удалось добавить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
@@ -111,7 +108,7 @@ public partial class FormPlaneCollection : Form
}
int pos = Convert.ToInt32(maskedTextBox1.Text);
-
+
try
{
@@ -125,7 +122,7 @@ public partial class FormPlaneCollection : Form
catch (Exception ex)
{
MessageBox.Show("Не удалось удалить объект");
- _logger.LogError("Ошибка: {Message}", ex.Message);
+ _logger.LogError("Ошибка: {Message}", ex.Message);//отсюда идут в ткс2
}
}
///
@@ -248,7 +245,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);
@@ -325,4 +322,28 @@ public partial class FormPlaneCollection : Form
}
}
}
+
+ private void buttonSortByType_Click(object sender, EventArgs e)
+ {
+ ComparePlane(new PlaneCompareByType());
+ }
+
+ private void buttonSortByColor_Click(object sender, EventArgs e)
+ {
+ ComparePlane(new PlaneCompareByColor());
+ }
+
+ ///
+ /// Сортировка по сравнителю
+ ///
+ /// Сравнитель объектов
+ private void ComparePlane(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}