From 83e8f8850ca6fba9599ed474890b2da57d0d25e2 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sat, 16 Dec 2023 23:33:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B2=20=D1=84=D0=BE=D1=80=D0=BC=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormPlaneCollection.Designer.cs | 26 +++++++++++++++++++ .../FormPlaneCollection.cs | 23 +++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.Designer.cs b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.Designer.cs index 1a511d4..4c1c5d1 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.Designer.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.Designer.cs @@ -29,6 +29,8 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonSortByType = new Button(); + buttonSortByColor = new Button(); groupBoxStorages = new GroupBox(); buttonRemoveStorage = new Button(); listBoxStorages = new ListBox(); @@ -53,6 +55,8 @@ // // groupBoxTools // + groupBoxTools.Controls.Add(buttonSortByType); + groupBoxTools.Controls.Add(buttonSortByColor); groupBoxTools.Controls.Add(groupBoxStorages); groupBoxTools.Controls.Add(maskedTextBoxNumber); groupBoxTools.Controls.Add(buttonRefreshCollection); @@ -66,6 +70,26 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonSortByType + // + buttonSortByType.Location = new Point(6, 273); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(218, 29); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // + // buttonSortByColor + // + buttonSortByColor.Location = new Point(6, 305); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(218, 29); + buttonSortByColor.TabIndex = 6; + buttonSortByColor.Text = "Сортировка по цвету"; + buttonSortByColor.UseVisualStyleBackColor = true; + buttonSortByColor.Click += buttonSortByColor_Click; + // // groupBoxStorages // groupBoxStorages.Controls.Add(buttonRemoveStorage); @@ -246,5 +270,7 @@ private ToolStripMenuItem загрузитьToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button buttonSortByType; + private Button buttonSortByColor; } } \ No newline at end of file diff --git a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs index 2884e68..764f543 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/FormPlaneCollection.cs @@ -142,7 +142,7 @@ namespace ProjectStormtrooper { MessageBox.Show(ex.Message); _logger.LogWarning("Ошибка добавления: " + ex.Message); - } + } } /// /// Удаление объекта из набора @@ -246,5 +246,26 @@ namespace ProjectStormtrooper } } } + /// + /// Сортировка по сравнителю + /// + /// + private void ComparePlanes(IComparer comparer) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + obj.Sort(comparer); + pictureBoxCollection.Image = obj.ShowPlanes(); + } + private void buttonSortByType_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByType()); + + private void buttonSortByColor_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByColor()); } }