From cf95633ab626b22ac5f0ffc4de435ed4ab3a321a Mon Sep 17 00:00:00 2001 From: Evgehil Date: Mon, 13 May 2024 03:27:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 8 +- .../CollectionInfo.cs | 52 ++++++++ .../ICollectionGenericObjects.cs | 12 +- .../ListGenericObjects.cs | 25 +++- .../MassiveGenericObjects.cs | 30 ++++- .../StorageCollection.cs | 41 +++--- .../Drawings/DrawingAirplanCompareByColor.cs | 28 ++++ .../Drawings/DrawiningAirplanEqutables.cs | 58 +++++++++ .../Drawings/DrawningAirplanCompareByType.cs | 29 +++++ .../Exceptions/ObjectIsEqualException.cs | 13 ++ Project_airbus/Project_airbus/Form1.resx | 120 ++++++++++++++++++ .../FormAirplanCollection.Designer.cs | 42 ++++-- .../Project_airbus/FormAirplanCollection.cs | 28 +++- .../Project_airbus/FormAirplanCollection.resx | 3 + 14 files changed, 452 insertions(+), 37 deletions(-) create mode 100644 Project_airbus/Project_airbus/CollectionGenericObjects/CollectionInfo.cs create mode 100644 Project_airbus/Project_airbus/Drawings/DrawingAirplanCompareByColor.cs create mode 100644 Project_airbus/Project_airbus/Drawings/DrawiningAirplanEqutables.cs create mode 100644 Project_airbus/Project_airbus/Drawings/DrawningAirplanCompareByType.cs create mode 100644 Project_airbus/Project_airbus/Exceptions/ObjectIsEqualException.cs create mode 100644 Project_airbus/Project_airbus/Form1.resx diff --git a/Project_airbus/Project_airbus/CollectionGenericObjects/AbstractCompany.cs b/Project_airbus/Project_airbus/CollectionGenericObjects/AbstractCompany.cs index d6325e7..36013b7 100644 --- a/Project_airbus/Project_airbus/CollectionGenericObjects/AbstractCompany.cs +++ b/Project_airbus/Project_airbus/CollectionGenericObjects/AbstractCompany.cs @@ -55,7 +55,7 @@ public abstract class AbstractCompany /// public static int operator +(AbstractCompany company, DrawingAirplan airplan) { - return company._collection.Insert(airplan); + return company._collection.Insert(airplan, new DrawiningAirplanEqutables()); } /// @@ -113,5 +113,11 @@ public abstract class AbstractCompany /// Расстановка объектов /// protected abstract void SetObjectsPosition(); + + /// + /// Сортировка + /// + /// Сравнитель объектов + public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer); } diff --git a/Project_airbus/Project_airbus/CollectionGenericObjects/CollectionInfo.cs b/Project_airbus/Project_airbus/CollectionGenericObjects/CollectionInfo.cs new file mode 100644 index 0000000..ce02741 --- /dev/null +++ b/Project_airbus/Project_airbus/CollectionGenericObjects/CollectionInfo.cs @@ -0,0 +1,52 @@ +using Project_airbus.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/Project_airbus/Project_airbus/CollectionGenericObjects/ICollectionGenericObjects.cs b/Project_airbus/Project_airbus/CollectionGenericObjects/ICollectionGenericObjects.cs index 144d5a9..4c8527c 100644 --- a/Project_airbus/Project_airbus/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/Project_airbus/Project_airbus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -21,16 +21,18 @@ public interface ICollectionGenericObjects /// Добавление объекта в коллекцию /// /// Добавляемый объект + /// Сравнение двух объектов /// 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 +58,10 @@ public interface ICollectionGenericObjects /// /// Поэлементый вывод элементов коллекции IEnumerable GetItems(); + + /// + /// Сортировка коллекции + /// + /// Сравнитель объектов + void CollectionSort(IComparer comparer); } \ No newline at end of file diff --git a/Project_airbus/Project_airbus/CollectionGenericObjects/ListGenericObjects.cs b/Project_airbus/Project_airbus/CollectionGenericObjects/ListGenericObjects.cs index c052444..0e33618 100644 --- a/Project_airbus/Project_airbus/CollectionGenericObjects/ListGenericObjects.cs +++ b/Project_airbus/Project_airbus/CollectionGenericObjects/ListGenericObjects.cs @@ -52,15 +52,31 @@ public class ListGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) + public int Insert(T obj, IEqualityComparer? comparer = null) { + 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) { + 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); @@ -82,4 +98,9 @@ public class ListGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } + + void ICollectionGenericObjects.CollectionSort(IComparer comparer) + { + _collection.Sort(comparer); + } } diff --git a/Project_airbus/Project_airbus/CollectionGenericObjects/MassiveGenericObjects.cs b/Project_airbus/Project_airbus/CollectionGenericObjects/MassiveGenericObjects.cs index 0131950..a72e0ae 100644 --- a/Project_airbus/Project_airbus/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Project_airbus/Project_airbus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,4 +1,5 @@ -using Project_airbus.Exceptions; +using Project_airbus.Drawings; +using Project_airbus.Exceptions; namespace Project_airbus.CollectionGenericObjects; @@ -55,8 +56,17 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) + public int Insert(T obj, IEqualityComparer? comparer = null) { + if (comparer != null) + { + foreach (T? item in _collection) + { + if ((comparer as IEqualityComparer).Equals(obj as DrawingAirplan, item as DrawingAirplan)) + throw new ObjectIsEqualException(); + } + } + int index = 0; while (index < _collection.Length) { @@ -70,8 +80,17 @@ 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) { + if (comparer != null) + { + foreach (T? item in _collection) + { + if ((comparer as IEqualityComparer).Equals(obj as DrawingAirplan, item as DrawingAirplan)) + throw new ObjectIsEqualException(); + } + } + if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position); if (_collection[position] == null) @@ -118,4 +137,9 @@ public class MassiveGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } + + void ICollectionGenericObjects.CollectionSort(IComparer comparer) + { + Array.Sort(_collection, comparer); + } } diff --git a/Project_airbus/Project_airbus/CollectionGenericObjects/StorageCollection.cs b/Project_airbus/Project_airbus/CollectionGenericObjects/StorageCollection.cs index 6ce2ea4..5146168 100644 --- a/Project_airbus/Project_airbus/CollectionGenericObjects/StorageCollection.cs +++ b/Project_airbus/Project_airbus/CollectionGenericObjects/StorageCollection.cs @@ -14,12 +14,12 @@ public class StorageCollection /// /// Словарь (хранилище) с коллекциями /// - readonly Dictionary> _storages; + readonly Dictionary> _storages; /// /// Возвращение списка названий коллекций /// - public List Keys => _storages.Keys.ToList(); + public List Keys => _storages.Keys.ToList(); /// /// Ключевое слово, с которого должен начинаться файл @@ -41,7 +41,7 @@ public class StorageCollection /// public StorageCollection() { - _storages = new Dictionary>(); + _storages = new Dictionary>(); } /// @@ -52,12 +52,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(); } /// @@ -66,8 +67,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); } /// @@ -79,8 +81,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; } } @@ -102,7 +105,7 @@ public class StorageCollection using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(_collectionKey); - foreach (KeyValuePair> value in _storages) + foreach (KeyValuePair> value in _storages) { StringBuilder sb = new(); sb.Append(Environment.NewLine); @@ -113,8 +116,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,18 +160,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("Не удалось определить тип коллекции:" + record[1]); } - 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?.CreateDrawingAirplan() is T airplan) @@ -188,7 +191,7 @@ public class StorageCollection } } } - _storages.Add(record[0], collection); + _storages.Add(collectionInfo, collection); } } } diff --git a/Project_airbus/Project_airbus/Drawings/DrawingAirplanCompareByColor.cs b/Project_airbus/Project_airbus/Drawings/DrawingAirplanCompareByColor.cs new file mode 100644 index 0000000..89350ec --- /dev/null +++ b/Project_airbus/Project_airbus/Drawings/DrawingAirplanCompareByColor.cs @@ -0,0 +1,28 @@ +namespace Project_airbus.Drawings; + +public class DrawningAirplanCompareByColor : IComparer +{ + public int Compare(DrawingAirplan? x, DrawingAirplan? y) + { + if (x == null || x.EntityAirplan == null) + { + return 1; + } + + if (y == null || y.EntityAirplan == null) + { + return -1; + } + var bodycolorCompare = x.EntityAirplan.BodyAirbus.Name.CompareTo(y.EntityAirplan.BodyAirbus.Name); + if (bodycolorCompare != 0) + { + return bodycolorCompare; + } + var speedCompare = x.EntityAirplan.Speed.CompareTo(y.EntityAirplan.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityAirplan.Weight.CompareTo(y.EntityAirplan.Weight); + } +} \ No newline at end of file diff --git a/Project_airbus/Project_airbus/Drawings/DrawiningAirplanEqutables.cs b/Project_airbus/Project_airbus/Drawings/DrawiningAirplanEqutables.cs new file mode 100644 index 0000000..ba67b02 --- /dev/null +++ b/Project_airbus/Project_airbus/Drawings/DrawiningAirplanEqutables.cs @@ -0,0 +1,58 @@ +using Project_airbus.Entities; +using System.Diagnostics.CodeAnalysis; + +namespace Project_airbus.Drawings; + +public class DrawiningAirplanEqutables : IEqualityComparer +{ + public bool Equals(DrawingAirplan? x, DrawingAirplan? y) + { + if (x == null || x.EntityAirplan == null) + { + return false; + } + if (y == null || y.EntityAirplan == null) + { + return false; + } + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + if (x.EntityAirplan.Speed != y.EntityAirplan.Speed) + { + return false; + } + if (x.EntityAirplan.Weight != y.EntityAirplan.Weight) + { + return false; + } + if (x.EntityAirplan.BodyAirbus != y.EntityAirplan.BodyAirbus) + { + return false; + } + if (x is DrawingAirbus && y is DrawingAirbus) + { + EntityAirbus _x = (EntityAirbus)x.EntityAirplan; + EntityAirbus _y = (EntityAirbus)x.EntityAirplan; + if (_x.AdditionalColor != _y.AdditionalColor) + { + return false; + } + if (_x.BodySection != _y.BodySection) + { + return false; + } + if (_x.Motor != _y.Motor) + { + return false; + } + } + return true; + } + public int GetHashCode([DisallowNull] DrawingAirplan obj) + { + return obj.GetHashCode(); + } +} + diff --git a/Project_airbus/Project_airbus/Drawings/DrawningAirplanCompareByType.cs b/Project_airbus/Project_airbus/Drawings/DrawningAirplanCompareByType.cs new file mode 100644 index 0000000..a6c3ce0 --- /dev/null +++ b/Project_airbus/Project_airbus/Drawings/DrawningAirplanCompareByType.cs @@ -0,0 +1,29 @@ +using Project_airbus.Drawings; + +public class DrawningAirplanCompareByType : IComparer +{ + public int Compare(DrawingAirplan? x, DrawingAirplan? y) + { + if (x == null || x.EntityAirplan == null) + { + return 1; + } + + if (y == null || y.EntityAirplan == null) + { + return -1; + } + + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + + var speedCompare = x.EntityAirplan.Speed.CompareTo(y.EntityAirplan.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityAirplan.Weight.CompareTo(y.EntityAirplan.Weight); + } +} diff --git a/Project_airbus/Project_airbus/Exceptions/ObjectIsEqualException.cs b/Project_airbus/Project_airbus/Exceptions/ObjectIsEqualException.cs new file mode 100644 index 0000000..2876217 --- /dev/null +++ b/Project_airbus/Project_airbus/Exceptions/ObjectIsEqualException.cs @@ -0,0 +1,13 @@ +using System.Runtime.Serialization; +/// +/// Класс, описывающий ошибку переполнения коллекции +/// +[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/Project_airbus/Project_airbus/Form1.resx b/Project_airbus/Project_airbus/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Project_airbus/Project_airbus/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Project_airbus/Project_airbus/FormAirplanCollection.Designer.cs b/Project_airbus/Project_airbus/FormAirplanCollection.Designer.cs index 974a73b..4a59ae4 100644 --- a/Project_airbus/Project_airbus/FormAirplanCollection.Designer.cs +++ b/Project_airbus/Project_airbus/FormAirplanCollection.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(); @@ -68,13 +70,15 @@ groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(925, 28); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(210, 679); + groupBoxTools.Size = new Size(210, 777); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // // panelCompanyTools // + panelCompanyTools.Controls.Add(buttonSortByColor); + panelCompanyTools.Controls.Add(buttonSortByType); panelCompanyTools.Controls.Add(buttonAddAirplan); panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Controls.Add(buttonRefresh); @@ -83,7 +87,7 @@ panelCompanyTools.Enabled = false; panelCompanyTools.Location = new Point(3, 400); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(207, 307); + panelCompanyTools.Size = new Size(207, 377); panelCompanyTools.TabIndex = 9; // // buttonAddAirplan @@ -98,7 +102,7 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(3, 116); + maskedTextBox.Location = new Point(3, 63); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(192, 27); @@ -107,7 +111,7 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(3, 253); + buttonRefresh.Location = new Point(3, 200); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(195, 46); buttonRefresh.TabIndex = 6; @@ -117,7 +121,7 @@ // // ButtonDelAirplan // - ButtonDelAirplan.Location = new Point(3, 149); + ButtonDelAirplan.Location = new Point(3, 96); ButtonDelAirplan.Name = "ButtonDelAirplan"; ButtonDelAirplan.Size = new Size(195, 46); ButtonDelAirplan.TabIndex = 4; @@ -127,7 +131,7 @@ // // buttonGoToCheck // - buttonGoToCheck.Location = new Point(3, 201); + buttonGoToCheck.Location = new Point(3, 148); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(195, 46); buttonGoToCheck.TabIndex = 5; @@ -244,7 +248,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 28); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(925, 679); + pictureBox.Size = new Size(925, 777); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -289,11 +293,31 @@ // openFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByType + // + buttonSortByType.Location = new Point(3, 252); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(195, 51); + buttonSortByType.TabIndex = 8; + buttonSortByType.Text = "Сортировка по типу "; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // + // buttonSortByColor + // + buttonSortByColor.Location = new Point(3, 309); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(195, 51); + buttonSortByColor.TabIndex = 9; + buttonSortByColor.Text = "Сортировка по цвету"; + buttonSortByColor.UseVisualStyleBackColor = true; + buttonSortByColor.Click += buttonSortByColor_Click; + // // FormAirplanCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1135, 707); + ClientSize = new Size(1135, 805); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); @@ -338,5 +362,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/Project_airbus/Project_airbus/FormAirplanCollection.cs b/Project_airbus/Project_airbus/FormAirplanCollection.cs index 79dbe19..9cfda1f 100644 --- a/Project_airbus/Project_airbus/FormAirplanCollection.cs +++ b/Project_airbus/Project_airbus/FormAirplanCollection.cs @@ -83,6 +83,11 @@ public partial class FormAirplanCollection : Form MessageBox.Show("Не удалось добавить объект"); _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (ObjectIsEqualException ex) + { + MessageBox.Show("Не удалось добавить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); + } } /// @@ -163,7 +168,7 @@ public partial class FormAirplanCollection : 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); @@ -247,7 +252,6 @@ public partial class FormAirplanCollection : Form { _logger.LogError("Ошибка: {Message}", ex.Message); } - } /// @@ -327,4 +331,24 @@ public partial class FormAirplanCollection : Form } } } + + private void buttonSortByType_Click(object sender, EventArgs e) + { + CompareAirplan(new DrawningAirplanCompareByType()); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) + { + CompareAirplan(new DrawningAirplanCompareByColor()); + } + + private void CompareAirplan(IComparer comparer) + { + if (_company == null) + { + return; + } + _company.Sort(comparer); + pictureBox.Image = _company.Show(); + } } \ No newline at end of file diff --git a/Project_airbus/Project_airbus/FormAirplanCollection.resx b/Project_airbus/Project_airbus/FormAirplanCollection.resx index b2e8bcd..b65585f 100644 --- a/Project_airbus/Project_airbus/FormAirplanCollection.resx +++ b/Project_airbus/Project_airbus/FormAirplanCollection.resx @@ -126,4 +126,7 @@ 310, 17 + + 25 + \ No newline at end of file