From 4d472b3557438baa8f8576bd69fbc550c2307ea2 Mon Sep 17 00:00:00 2001 From: Victoria_Isaeva Date: Tue, 4 Jun 2024 16:09:19 +0400 Subject: [PATCH] =?UTF-8?q?8=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 5 +- .../CollectionInfo.cs | 59 ++++++++ .../ICollectionGenericObjects.cs | 24 +-- .../ListGenericObjects.cs | 29 ++-- .../MassiveGenericObjects.cs | 10 +- .../StorageCollection.cs | 62 ++++---- .../Exceptions/ObjectIsEqualException.cs | 13 ++ .../FormBusCollection.Designer.cs | 138 ++++++++++++------ .../ProjectAirbus/FormBusCollection.cs | 23 ++- .../ProjectAirbus/FormBusCollection.resx | 132 ----------------- 10 files changed, 256 insertions(+), 239 deletions(-) create mode 100644 ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs create mode 100644 ProjectAirbus/ProjectAirbus/Exceptions/ObjectIsEqualException.cs delete mode 100644 ProjectAirbus/ProjectAirbus/FormBusCollection.resx diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs index 4e454b8..1f3e02b 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs @@ -1,5 +1,6 @@ using ProjectAirbus.Drawnings; using ProjectAirbus.Exceptions; +using System.Numerics; namespace ProjectAirbus.CollectionGenericObjects; @@ -58,9 +59,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawningBus bus) + public static int? operator +(AbstractCompany company, DrawningBus bus) { - return company._collection?.Insert(bus, new DrawiningBusEqutables()) ?? false; + return company._collection?.Insert(bus, new DrawiningBusEqutables()); } /// diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs new file mode 100644 index 0000000..74f8a90 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionInfo.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirbus.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/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs index 8f16f5d..6a02469 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -12,15 +12,21 @@ public interface ICollectionGenericObjects where T : class { int Count { get; } - int MaxCount{get;set;} - int Insert(T obj, IEqualityComparer? comparer = null ); - int Insert(T obj, int position, IEqualityComparer? comparer = null); - T? Remove(int position); - T? Get(int position); - - CollectionType GetCollectionType { get; } - IEnumerable GetItems(); - void CollectionSort(IComparer comparer); + int MaxCount { set; get; } + + int Insert(T obj, IEqualityComparer? comparer = null); + + int Insert(T obj, int position, IEqualityComparer? comparer = null); + + T Remove(int position); + + T? Get(int position); + + CollectionType GetCollectionType { get; } + + IEnumerable GetItems(); + + void CollectionSort(IComparer comparer); } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs index e979ba2..9c83c90 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs @@ -1,9 +1,8 @@ using ProjectAirbus.CollectionGenericObjects; -using ProjectAirbus.Drawnings; using ProjectAirbus.Exceptions; using System.Linq; -namespace ProjectAirBus.CollectionGenericObjects; +namespace ProjectAirbus.CollectionGenericObjects; /// /// Параметризованный набор объектов @@ -24,11 +23,22 @@ public class ListGenericObjects : ICollectionGenericObjects public int Count => _collection.Count; - public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } - - public CollectionType GetCollectionType => CollectionType.List; + public int MaxCount + { + get + { + return Count; + } + set + { + if (value > 0) + { + _maxCount = value; + } + } + } - public int MaxCount { get; set; } + public CollectionType GetCollectionType => CollectionType.List; /// /// Конструктор @@ -45,7 +55,7 @@ public class ListGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj, IEqualityComparer? comparer = null) + public int Insert(T obj, IEqualityComparer? comparer = null) { // TODO выброс ошибки если переполнение if (comparer != null) @@ -61,7 +71,7 @@ public class ListGenericObjects : ICollectionGenericObjects return Count; } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) + public int Insert(T obj, int position, IEqualityComparer? comparer = null) { // TODO выброс ошибки если переполнение // TODO выброс ошибки если за границу @@ -95,9 +105,8 @@ public class ListGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } - public void CollectionSort(IComparer comparer) + void ICollectionGenericObjects.CollectionSort(IComparer comparer) { _collection.Sort(comparer); } - } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs index 16d6860..32cf9d3 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -6,8 +6,6 @@ namespace ProjectAirbus.CollectionGenericObjects; internal class MassiveGenericObjects : ICollectionGenericObjects where T : class { - - /// /// Массив объектов, которые храним /// @@ -56,14 +54,14 @@ internal class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj, IEqualityComparer? comparer = null) + public int Insert(T obj, IEqualityComparer? comparer = null) { // TODO выброс ошибки если переполнение if (comparer != null) { foreach (T? item in _collection) { - if ((comparer as IEqualityComparer).Equals(obj as DrawingBus, item as DrawingBus)) + if ((comparer as IEqualityComparer).Equals(obj as DrawningBus, item as DrawningBus)) throw new ObjectIsEqualException(); } } @@ -81,13 +79,13 @@ internal class MassiveGenericObjects : ICollectionGenericObjects throw new CollectionOverflowException(Count); } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) + 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 DrawingBus, item as DrawingBus)) + if ((comparer as IEqualityComparer).Equals(obj as DrawningBus, item as DrawningBus)) throw new ObjectIsEqualException(); } } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs index fe193ee..3c9fd88 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs @@ -1,22 +1,18 @@ - - -using ProjectAirbus.CollectionGenericObjects; +using ProjectAirbus.CollectionGenericObjects; using ProjectAirbus.Drawnings; using ProjectAirbus.Exceptions; using System.Text; - -namespace ProjectAirBus.CollectionGenericObjects; - +namespace ProjectAirbus.CollectionGenericObjects; public class StorageCollection where T : DrawningBus { - readonly Dictionary> _storages; + readonly Dictionary> _storages; - public List Keys => _storages.Keys.ToList(); + public List Keys => _storages.Keys.ToList(); private readonly string _collectionKey = "CollectionStorage"; @@ -26,7 +22,7 @@ public class StorageCollection public StorageCollection() { - _storages = new Dictionary>(); + _storages = new Dictionary>(); } @@ -34,27 +30,22 @@ public class StorageCollection { // TODO проверка, что name не пустой и нет в словаре записи с таким ключом // TODO Прописать логику для добавления - if (name == null || _storages.ContainsKey(name)) { return; } - switch (collectionType) - - { - case CollectionType.None: - return; - case CollectionType.Massive: - _storages[name] = new MassiveGenericObjects(); - return; - case CollectionType.List: - _storages[name] = new ListGenericObjects(); - 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[collectionInfo] = new MassiveGenericObjects(); + else if (collectionType == CollectionType.List) + _storages[collectionInfo] = new ListGenericObjects(); } 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,9 +53,10 @@ public class StorageCollection { get { - // TODO Продумать логику получения объекта - if (name == null || !_storages.ContainsKey(name)) { return null; } - return _storages[name]; + CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty); + if (_storages.ContainsKey(collectionInfo)) + return _storages[collectionInfo]; + return null; } } public void SaveData(string filename) @@ -81,7 +73,7 @@ public class StorageCollection StringBuilder sb = new(); sb.Append(_collectionKey); - foreach (KeyValuePair> value in _storages) + foreach (KeyValuePair> value in _storages) { sb.Append(Environment.NewLine); if (value.Value.Count == 0) @@ -145,17 +137,19 @@ public class StorageCollection foreach (string data in strs) { string[] record = data.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("Не удалось создать коллекцию"); + throw new Exception("Не удалось определить тип коллекции:" + record[1]); } - collection.MaxCount = Convert.ToInt32(record[2]); + collection.MaxCount = Convert.ToInt32(record[1]); string[] set = record[3].Split(_separatorItem, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) @@ -176,7 +170,7 @@ public class StorageCollection } } - _storages.Add(record[0], collection); + _storages.Add(collectionInfo, collection); } diff --git a/ProjectAirbus/ProjectAirbus/Exceptions/ObjectIsEqualException.cs b/ProjectAirbus/ProjectAirbus/Exceptions/ObjectIsEqualException.cs new file mode 100644 index 0000000..91ac934 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/Exceptions/ObjectIsEqualException.cs @@ -0,0 +1,13 @@ +using System.Runtime.Serialization; + +namespace ProjectAirbus.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/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs index 2dc9566..8fa878a 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs @@ -30,6 +30,8 @@ { groupBoxTools = new GroupBox(); panelCompanyTools = new Panel(); + buttonSortByColor = new Button(); + buttonSortByType = new Button(); buttonRefresh = new Button(); comboBoxSelectorCompany = new ComboBox(); buttonGoToChek = new Button(); @@ -64,34 +66,63 @@ groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(825, 28); + groupBoxTools.Location = new Point(722, 24); + groupBoxTools.Margin = new Padding(3, 2, 3, 2); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(303, 581); + groupBoxTools.Padding = new Padding(3, 2, 3, 2); + groupBoxTools.Size = new Size(265, 519); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // // panelCompanyTools // + panelCompanyTools.Controls.Add(buttonSortByColor); + panelCompanyTools.Controls.Add(buttonSortByType); panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(comboBoxSelectorCompany); panelCompanyTools.Controls.Add(buttonGoToChek); panelCompanyTools.Controls.Add(buttonAddBus); panelCompanyTools.Controls.Add(buttonDelBus); panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 343); + panelCompanyTools.Location = new Point(3, 301); + panelCompanyTools.Margin = new Padding(3, 2, 3, 2); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(297, 235); + panelCompanyTools.Size = new Size(259, 216); panelCompanyTools.TabIndex = 2; // + // buttonSortByColor + // + buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonSortByColor.Location = new Point(10, 182); + buttonSortByColor.Margin = new Padding(3, 2, 3, 2); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(240, 26); + 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(10, 152); + buttonSortByType.Margin = new Padding(3, 2, 3, 2); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(240, 26); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировать по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(10, 191); + buttonRefresh.Location = new Point(9, 122); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(275, 35); + buttonRefresh.Size = new Size(240, 26); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить "; buttonRefresh.UseVisualStyleBackColor = true; @@ -103,18 +134,20 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(11, 3); + comboBoxSelectorCompany.Location = new Point(12, 240); + comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(267, 28); + comboBoxSelectorCompany.Size = new Size(233, 23); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // // buttonGoToChek // buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(12, 150); + buttonGoToChek.Location = new Point(10, 91); + buttonGoToChek.Margin = new Padding(3, 2, 3, 2); buttonGoToChek.Name = "buttonGoToChek"; - buttonGoToChek.Size = new Size(273, 37); + buttonGoToChek.Size = new Size(238, 28); buttonGoToChek.TabIndex = 5; buttonGoToChek.Text = "Передать на тесты"; buttonGoToChek.UseVisualStyleBackColor = true; @@ -123,9 +156,10 @@ // buttonAddBus // buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBus.Location = new Point(11, 37); + buttonAddBus.Location = new Point(10, 7); + buttonAddBus.Margin = new Padding(3, 2, 3, 2); buttonAddBus.Name = "buttonAddBus"; - buttonAddBus.Size = new Size(270, 33); + buttonAddBus.Size = new Size(235, 25); buttonAddBus.TabIndex = 1; buttonAddBus.Text = "Добавление самолета"; buttonAddBus.UseVisualStyleBackColor = true; @@ -134,9 +168,10 @@ // buttonDelBus // buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelBus.Location = new Point(11, 109); + buttonDelBus.Location = new Point(10, 61); + buttonDelBus.Margin = new Padding(3, 2, 3, 2); buttonDelBus.Name = "buttonDelBus"; - buttonDelBus.Size = new Size(272, 35); + buttonDelBus.Size = new Size(237, 26); buttonDelBus.TabIndex = 4; buttonDelBus.Text = "Удалить самолет"; buttonDelBus.UseVisualStyleBackColor = true; @@ -144,10 +179,11 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(11, 76); + maskedTextBox.Location = new Point(10, 36); + maskedTextBox.Margin = new Padding(3, 2, 3, 2); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(276, 27); + maskedTextBox.Size = new Size(242, 23); maskedTextBox.TabIndex = 3; maskedTextBox.ValidatingType = typeof(int); // @@ -156,22 +192,25 @@ panelStorage.Controls.Add(buttonCreateCompany); panelStorage.Controls.Add(buttonCollectionDel); panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(comboBoxSelectorCompany); panelStorage.Controls.Add(buttonCollectionAdd); panelStorage.Controls.Add(radioButtonList); panelStorage.Controls.Add(radioButtonMassive); panelStorage.Controls.Add(textBoxCollectionName); panelStorage.Controls.Add(labelCollectionName); panelStorage.Dock = DockStyle.Top; - panelStorage.Location = new Point(3, 23); + panelStorage.Location = new Point(3, 18); + panelStorage.Margin = new Padding(3, 2, 3, 2); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(297, 317); + panelStorage.Size = new Size(259, 279); panelStorage.TabIndex = 2; // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(12, 288); + buttonCreateCompany.Location = new Point(11, 214); + buttonCreateCompany.Margin = new Padding(3, 2, 3, 2); buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(270, 29); + buttonCreateCompany.Size = new Size(236, 22); buttonCreateCompany.TabIndex = 7; buttonCreateCompany.Text = "Создать компанию "; buttonCreateCompany.UseVisualStyleBackColor = true; @@ -179,9 +218,10 @@ // // buttonCollectionDel // - buttonCollectionDel.Location = new Point(12, 251); + buttonCollectionDel.Location = new Point(10, 188); + buttonCollectionDel.Margin = new Padding(3, 2, 3, 2); buttonCollectionDel.Name = "buttonCollectionDel"; - buttonCollectionDel.Size = new Size(270, 29); + buttonCollectionDel.Size = new Size(236, 22); buttonCollectionDel.TabIndex = 6; buttonCollectionDel.Text = "Удалить коллекцию"; buttonCollectionDel.UseVisualStyleBackColor = true; @@ -190,16 +230,19 @@ // listBoxCollection // listBoxCollection.FormattingEnabled = true; - listBoxCollection.Location = new Point(12, 141); + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(10, 106); + listBoxCollection.Margin = new Padding(3, 2, 3, 2); listBoxCollection.Name = "listBoxCollection"; - listBoxCollection.Size = new Size(264, 104); + listBoxCollection.Size = new Size(232, 79); listBoxCollection.TabIndex = 5; // // buttonCollectionAdd // - buttonCollectionAdd.Location = new Point(12, 96); + buttonCollectionAdd.Location = new Point(10, 72); + buttonCollectionAdd.Margin = new Padding(3, 2, 3, 2); buttonCollectionAdd.Name = "buttonCollectionAdd"; - buttonCollectionAdd.Size = new Size(270, 29); + buttonCollectionAdd.Size = new Size(236, 22); buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.UseVisualStyleBackColor = true; @@ -208,9 +251,10 @@ // radioButtonList // radioButtonList.AutoSize = true; - radioButtonList.Location = new Point(202, 66); + radioButtonList.Location = new Point(177, 50); + radioButtonList.Margin = new Padding(3, 2, 3, 2); radioButtonList.Name = "radioButtonList"; - radioButtonList.Size = new Size(80, 24); + radioButtonList.Size = new Size(66, 19); radioButtonList.TabIndex = 3; radioButtonList.TabStop = true; radioButtonList.Text = "Список"; @@ -219,9 +263,10 @@ // radioButtonMassive // radioButtonMassive.AutoSize = true; - radioButtonMassive.Location = new Point(12, 66); + radioButtonMassive.Location = new Point(10, 50); + radioButtonMassive.Margin = new Padding(3, 2, 3, 2); radioButtonMassive.Name = "radioButtonMassive"; - radioButtonMassive.Size = new Size(82, 24); + radioButtonMassive.Size = new Size(67, 19); radioButtonMassive.TabIndex = 2; radioButtonMassive.TabStop = true; radioButtonMassive.Text = "Массив"; @@ -229,26 +274,28 @@ // // textBoxCollectionName // - textBoxCollectionName.Location = new Point(12, 33); + textBoxCollectionName.Location = new Point(10, 25); + textBoxCollectionName.Margin = new Padding(3, 2, 3, 2); textBoxCollectionName.Name = "textBoxCollectionName"; - textBoxCollectionName.Size = new Size(270, 27); + textBoxCollectionName.Size = new Size(237, 23); textBoxCollectionName.TabIndex = 1; // // labelCollectionName // labelCollectionName.AutoSize = true; - labelCollectionName.Location = new Point(12, 10); + labelCollectionName.Location = new Point(10, 8); labelCollectionName.Name = "labelCollectionName"; - labelCollectionName.Size = new Size(158, 20); + labelCollectionName.Size = new Size(125, 15); labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // // pictureBox1 // pictureBox1.Dock = DockStyle.Fill; - pictureBox1.Location = new Point(0, 28); + pictureBox1.Location = new Point(0, 24); + pictureBox1.Margin = new Padding(3, 2, 3, 2); pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(825, 581); + pictureBox1.Size = new Size(722, 519); pictureBox1.TabIndex = 1; pictureBox1.TabStop = false; // @@ -258,7 +305,8 @@ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1128, 28); + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(987, 24); menuStrip.TabIndex = 2; menuStrip.Text = "menuStrip1"; // @@ -266,14 +314,14 @@ // файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); файлToolStripMenuItem.Name = "файлToolStripMenuItem"; - файлToolStripMenuItem.Size = new Size(59, 24); + файлToolStripMenuItem.Size = new Size(48, 20); файлToolStripMenuItem.Text = "Файл"; // // saveToolStripMenuItem // saveToolStripMenuItem.Name = "saveToolStripMenuItem"; saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; - saveToolStripMenuItem.Size = new Size(231, 26); + saveToolStripMenuItem.Size = new Size(184, 22); saveToolStripMenuItem.Text = "Сохранение "; saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // @@ -281,7 +329,7 @@ // loadToolStripMenuItem.Name = "loadToolStripMenuItem"; loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; - loadToolStripMenuItem.Size = new Size(231, 26); + loadToolStripMenuItem.Size = new Size(184, 22); loadToolStripMenuItem.Text = "Загрузка"; loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; // @@ -295,14 +343,15 @@ // // FormBusCollection // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1128, 609); + ClientSize = new Size(987, 543); Controls.Add(pictureBox1); Controls.Add(groupBoxTools); Controls.Add(menuStrip); FormBorderStyle = FormBorderStyle.FixedSingle; MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); Name = "FormBusCollection"; Text = "Коллекция самолетов "; groupBoxTools.ResumeLayout(false); @@ -343,6 +392,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/FormBusCollection.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs index 3ca75db..f421133 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs @@ -2,7 +2,6 @@ using ProjectAirbus.CollectionGenericObjects; using ProjectAirbus.Drawnings; using ProjectAirbus.Exceptions; -using ProjectAirBus.CollectionGenericObjects; using System.Windows.Forms; namespace ProjectAirbus; @@ -214,7 +213,7 @@ public partial class FormBusCollection : 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); @@ -293,4 +292,24 @@ public partial class FormBusCollection : Form } } } + + private void buttonSortByType_Click(object sender, EventArgs e) + { + ComparePlane(new DrawningBusCompareByType()); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) + { + ComparePlane(new DrawningBusCompareByColor()); + } + + private void ComparePlane(IComparer comparer) + { + if (_company == null) + { + return; + } + _company.Sort(comparer); + pictureBox1.Image = _company.Show(); + } } diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.resx b/ProjectAirbus/ProjectAirbus/FormBusCollection.resx deleted file mode 100644 index a4f11d6..0000000 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.resx +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - 17, 17 - - - 145, 17 - - - 310, 17 - - - 25 - - \ No newline at end of file