From f4110d81aca24e3762ad98af54a1f1a5baa368ad Mon Sep 17 00:00:00 2001 From: Shtyrkin_Egor Date: Sat, 8 Jun 2024 08:48:04 +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=20=E2=84=968=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../StorageCollection.cs | 2 +- .../DrawningWarshipCompareByColor.cs | 2 +- .../Drawnings/DrawningWarshipCompareByType.cs | 2 +- .../Drawnings/DrawningWarshipEqutables.cs | 4 +- .../Exceptions/ObjectIsEqualException.cs | 12 +- .../FormWarshipCollection.Designer.cs | 136 ++++++++++++------ .../FormWarshipCollection.cs | 27 +++- 7 files changed, 135 insertions(+), 50 deletions(-) diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs index e5f53be..e9e2508 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/CollectionGenericObjects/StorageCollection.cs @@ -166,7 +166,7 @@ public class StorageCollection continue; } - CollectionInfo? collectionInfo = collectionInfo.GetCollectionInfo(record[0]) ?? + CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? throw new Exception("Не удалось определить информацию коллекции: " + record[0]); ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ?? throw new Exception("Не удалось создать коллекцию"); diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByColor.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByColor.cs index ff57024..0cf4dc4 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByColor.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByColor.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectAircraftCarrier.Drawnings; -public class DrawningShipCompareByColor : IComparer +public class DrawningWarshipCompareByColor : IComparer { public int Compare(DrawningWarship? x, DrawningWarship? y) { diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByType.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByType.cs index 0c77084..c08d140 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByType.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipCompareByType.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectAircraftCarrier.Drawnings; -public class DrawningShipCompareByType : IComparer +public class DrawningWarshipCompareByType : IComparer { public int Compare(DrawningWarship? x, DrawningWarship? y) { diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipEqutables.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipEqutables.cs index 1e62665..af40945 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipEqutables.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarshipEqutables.cs @@ -41,8 +41,8 @@ public class DrawningWarshipEqutables : IEqualityComparer } if (x is DrawningAircraftCarrier && y is DrawningAircraftCarrier) { - DrawningAircraftCarrier _x = (DrawningAircraftCarrier)x.EntityWarship; - DrawningAircraftCarrier _y = (DrawningAircraftCarrier)x.EntityWarship; + EntityAircraftCarrier _x = (EntityAircraftCarrier)x.EntityWarship; + EntityAircraftCarrier _y = (EntityAircraftCarrier)x.EntityWarship; if (_x.AdditionalColor != _y.AdditionalColor) { return false; diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Exceptions/ObjectIsEqualException.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Exceptions/ObjectIsEqualException.cs index 976d5e0..a6149be 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/Exceptions/ObjectIsEqualException.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Exceptions/ObjectIsEqualException.cs @@ -1,11 +1,21 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace ProjectAircraftCarrier.Exceptions; -internal class ObjectIsEqualException +/// +/// Класс, описывающий ошибку переполнения коллекции +/// +[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/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs index 70d0c73..549801c 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.Designer.cs @@ -52,6 +52,8 @@ loadToolStripMenuItem = new ToolStripMenuItem(); saveFileDialog = new SaveFileDialog(); openFileDialog = new OpenFileDialog(); + buttonSortByColor = new Button(); + buttonSortByType = new Button(); groupBoxTools.SuspendLayout(); panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); @@ -66,15 +68,19 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(916, 28); + groupBoxTools.Location = new Point(802, 24); + groupBoxTools.Margin = new Padding(3, 2, 3, 2); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(205, 731); + groupBoxTools.Padding = new Padding(3, 2, 3, 2); + groupBoxTools.Size = new Size(179, 640); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // // panelCompanyTools // + panelCompanyTools.Controls.Add(buttonSortByColor); + panelCompanyTools.Controls.Add(buttonSortByType); panelCompanyTools.Controls.Add(buttonAddWarship); panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Controls.Add(buttonRefresh); @@ -82,17 +88,19 @@ panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 400); + panelCompanyTools.Location = new Point(3, 345); + panelCompanyTools.Margin = new Padding(3, 2, 3, 2); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(199, 328); + panelCompanyTools.Size = new Size(173, 293); panelCompanyTools.TabIndex = 9; // // buttonAddWarship // buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddWarship.Location = new Point(3, 21); + buttonAddWarship.Location = new Point(3, 2); + buttonAddWarship.Margin = new Padding(3, 2, 3, 2); buttonAddWarship.Name = "buttonAddWarship"; - buttonAddWarship.Size = new Size(193, 52); + buttonAddWarship.Size = new Size(168, 39); buttonAddWarship.TabIndex = 1; buttonAddWarship.Text = "Добавление\r\nвоенного корабля"; buttonAddWarship.UseVisualStyleBackColor = true; @@ -100,19 +108,21 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(3, 119); + maskedTextBox.Location = new Point(3, 44); + maskedTextBox.Margin = new Padding(3, 2, 3, 2); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(193, 27); + maskedTextBox.Size = new Size(169, 23); maskedTextBox.TabIndex = 3; maskedTextBox.ValidatingType = typeof(int); // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(3, 268); + buttonRefresh.Location = new Point(3, 158); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(193, 52); + buttonRefresh.Size = new Size(168, 39); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -121,9 +131,10 @@ // buttonRemoveWarship // buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveWarship.Location = new Point(3, 152); + buttonRemoveWarship.Location = new Point(3, 71); + buttonRemoveWarship.Margin = new Padding(3, 2, 3, 2); buttonRemoveWarship.Name = "buttonRemoveWarship"; - buttonRemoveWarship.Size = new Size(193, 52); + buttonRemoveWarship.Size = new Size(168, 39); buttonRemoveWarship.TabIndex = 4; buttonRemoveWarship.Text = "Удалить \r\nвоенный корабль"; buttonRemoveWarship.UseVisualStyleBackColor = true; @@ -132,9 +143,10 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(3, 210); + buttonGoToCheck.Location = new Point(3, 115); + buttonGoToCheck.Margin = new Padding(3, 2, 3, 2); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(193, 52); + buttonGoToCheck.Size = new Size(168, 39); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -142,9 +154,10 @@ // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(6, 369); + buttonCreateCompany.Location = new Point(5, 277); + buttonCreateCompany.Margin = new Padding(3, 2, 3, 2); buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(193, 29); + buttonCreateCompany.Size = new Size(169, 22); buttonCreateCompany.TabIndex = 8; buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.UseVisualStyleBackColor = true; @@ -160,16 +173,18 @@ 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(199, 290); + panelStorage.Size = new Size(173, 218); panelStorage.TabIndex = 7; // // buttonCollectionDel // - buttonCollectionDel.Location = new Point(3, 241); + buttonCollectionDel.Location = new Point(3, 181); + buttonCollectionDel.Margin = new Padding(3, 2, 3, 2); buttonCollectionDel.Name = "buttonCollectionDel"; - buttonCollectionDel.Size = new Size(193, 29); + buttonCollectionDel.Size = new Size(169, 22); buttonCollectionDel.TabIndex = 6; buttonCollectionDel.Text = "Удалить коллекцию"; buttonCollectionDel.UseVisualStyleBackColor = true; @@ -178,17 +193,19 @@ // listBoxCollection // listBoxCollection.FormattingEnabled = true; - listBoxCollection.ItemHeight = 20; - listBoxCollection.Location = new Point(6, 131); + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(5, 98); + listBoxCollection.Margin = new Padding(3, 2, 3, 2); listBoxCollection.Name = "listBoxCollection"; - listBoxCollection.Size = new Size(193, 104); + listBoxCollection.Size = new Size(169, 79); listBoxCollection.TabIndex = 5; // // buttonCollectionAdd // - buttonCollectionAdd.Location = new Point(3, 96); + buttonCollectionAdd.Location = new Point(3, 72); + buttonCollectionAdd.Margin = new Padding(3, 2, 3, 2); buttonCollectionAdd.Name = "buttonCollectionAdd"; - buttonCollectionAdd.Size = new Size(193, 29); + buttonCollectionAdd.Size = new Size(169, 22); buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.UseVisualStyleBackColor = true; @@ -197,9 +214,10 @@ // radioButtonList // radioButtonList.AutoSize = true; - radioButtonList.Location = new Point(101, 66); + radioButtonList.Location = new Point(88, 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 = "Список"; @@ -208,9 +226,10 @@ // radioButtonMassive // radioButtonMassive.AutoSize = true; - radioButtonMassive.Location = new Point(13, 66); + radioButtonMassive.Location = new Point(11, 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 = "Массив"; @@ -218,17 +237,18 @@ // // textBoxCollectionName // - textBoxCollectionName.Location = new Point(3, 33); + textBoxCollectionName.Location = new Point(3, 25); + textBoxCollectionName.Margin = new Padding(3, 2, 3, 2); textBoxCollectionName.Name = "textBoxCollectionName"; - textBoxCollectionName.Size = new Size(193, 27); + textBoxCollectionName.Size = new Size(169, 23); textBoxCollectionName.TabIndex = 1; // // labelCollectionName // labelCollectionName.AutoSize = true; - labelCollectionName.Location = new Point(20, 10); + labelCollectionName.Location = new Point(18, 8); labelCollectionName.Name = "labelCollectionName"; - labelCollectionName.Size = new Size(158, 20); + labelCollectionName.Size = new Size(125, 15); labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // @@ -238,18 +258,20 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 335); + comboBoxSelectorCompany.Location = new Point(5, 251); + comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(193, 28); + comboBoxSelectorCompany.Size = new Size(169, 23); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 28); + pictureBox.Location = new Point(0, 24); + pictureBox.Margin = new Padding(3, 2, 3, 2); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(916, 731); + pictureBox.Size = new Size(802, 640); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -259,7 +281,8 @@ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1121, 28); + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(981, 24); menuStrip.TabIndex = 2; menuStrip.Text = "menuStrip"; // @@ -267,14 +290,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(227, 26); + saveToolStripMenuItem.Size = new Size(181, 22); saveToolStripMenuItem.Text = "Сохранение"; saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; // @@ -282,7 +305,7 @@ // loadToolStripMenuItem.Name = "loadToolStripMenuItem"; loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; - loadToolStripMenuItem.Size = new Size(227, 26); + loadToolStripMenuItem.Size = new Size(181, 22); loadToolStripMenuItem.Text = "Загрузка"; loadToolStripMenuItem.Click += loadToolStripMenuItem_Click; // @@ -294,15 +317,40 @@ // openFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByColor + // + buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonSortByColor.Location = new Point(2, 244); + buttonSortByColor.Margin = new Padding(3, 2, 3, 2); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(168, 39); + 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(2, 201); + buttonSortByType.Margin = new Padding(3, 2, 3, 2); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(168, 39); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += ButtonSortByType_Click; + // // FormWarshipCollection // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1121, 759); + ClientSize = new Size(981, 664); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); Name = "FormWarshipCollection"; Text = "Коллекция военных кораблей"; groupBoxTools.ResumeLayout(false); @@ -343,5 +391,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/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs index 044243a..bc5ef6a 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormWarshipCollection.cs @@ -78,6 +78,11 @@ public partial class FormWarshipCollection : Form MessageBox.Show("Не удалось добавить объект"); _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (ObjectIsEqualException ex) + { + MessageBox.Show("Такой объект уже есть в коллекции"); + _logger.LogError("Ошибка: {Message}", ex.Message); + } } private void ButtonRemoveWarship_Click(object sender, EventArgs e) @@ -153,7 +158,7 @@ public partial class FormWarshipCollection : 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); @@ -273,4 +278,24 @@ public partial class FormWarshipCollection : Form } } } + + private void ButtonSortByType_Click(object sender, EventArgs e) + { + CompareWarship(new DrawningWarshipCompareByType()); + } + + private void ButtonSortByColor_Click(object sender, EventArgs e) + { + CompareWarship(new DrawningWarshipCompareByColor()); + } + + private void CompareWarship(IComparer comparer) + { + if (_company == null) + { + return; + } + _company.Sort(comparer); + pictureBox.Image = _company.Show(); + } } \ No newline at end of file