From 8e29980e9f95dc7f64d64353e2248aa4eedb4045 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Mon, 18 Dec 2023 16:27:42 +0300 Subject: [PATCH] =?UTF-8?q?=D1=87=D0=B5=D1=82=20=D0=BD=D0=B5=20=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormAirplanesCollection.Designer.cs | 27 +++++++++++++- .../FormAirplanesCollection.cs | 37 ++++++++++++++----- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs b/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs index 5e9ac67..f0834db 100644 --- a/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs +++ b/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.Designer.cs @@ -30,6 +30,8 @@ { pictureBoxAirplanesCollection = new PictureBox(); groupBoxAirplaneWithRadar = new GroupBox(); + buttonSortByColor = new Button(); + buttonSortByType = new Button(); groupBoxCollection = new GroupBox(); buttonRemoveObject = new Button(); listBoxStorages = new ListBox(); @@ -59,10 +61,11 @@ pictureBoxAirplanesCollection.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxAirplanesCollection.TabIndex = 0; pictureBoxAirplanesCollection.TabStop = false; - pictureBoxAirplanesCollection.Click += pictureBoxAirplanesCollection_Click; // // groupBoxAirplaneWithRadar // + groupBoxAirplaneWithRadar.Controls.Add(buttonSortByColor); + groupBoxAirplaneWithRadar.Controls.Add(buttonSortByType); groupBoxAirplaneWithRadar.Controls.Add(groupBoxCollection); groupBoxAirplaneWithRadar.Controls.Add(buttonUpdateCollection); groupBoxAirplaneWithRadar.Controls.Add(buttonDeleteAirplane); @@ -76,6 +79,26 @@ groupBoxAirplaneWithRadar.TabStop = false; groupBoxAirplaneWithRadar.Text = "Инструменты"; // + // buttonSortByColor + // + buttonSortByColor.Location = new Point(7, 487); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(238, 29); + buttonSortByColor.TabIndex = 6; + buttonSortByColor.Text = "Сортировка по цвету"; + buttonSortByColor.UseVisualStyleBackColor = true; + buttonSortByColor.Click += buttonSortByColor_Click; + // + // buttonSortByType + // + buttonSortByType.Location = new Point(6, 453); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(238, 29); + buttonSortByType.TabIndex = 5; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // // groupBoxCollection // groupBoxCollection.Controls.Add(buttonRemoveObject); @@ -238,5 +261,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button buttonSortByColor; + private Button buttonSortByType; } } \ No newline at end of file diff --git a/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.cs b/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.cs index 58a630c..048edf7 100644 --- a/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.cs +++ b/ProjectAirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplanesCollection.cs @@ -28,7 +28,7 @@ namespace ProjectAirplaneWithRadar listBoxStorages.Items.Clear(); for (int i = 0; i < _storage.Keys.Count; i++) { - listBoxStorages.Items.Add(_storage.Keys[i]); + listBoxStorages.Items.Add(_storage.Keys[i].Name); } if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count)) @@ -69,6 +69,11 @@ namespace ProjectAirplaneWithRadar Log.Warning($" {listBoxStorages.SelectedItem.ToString() ?? string.Empty} "); MessageBox.Show(ex.Message); } + catch (ArgumentException ex) + { + Log.Warning($" {listBoxStorages.SelectedItem.ToString() ?? string.Empty}"); + MessageBox.Show(" "); + } }); form.AddEvent(airplaneDelegate); } @@ -89,8 +94,6 @@ namespace ProjectAirplaneWithRadar { return; } - - try { int pos = Convert.ToInt32(maskedTextBoxNumber.Text); @@ -125,7 +128,6 @@ namespace ProjectAirplaneWithRadar } pictureBoxAirplanesCollection.Image = obj.ShowAirplanes(); } - private void buttonAddObject_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxStorageName.Text)) @@ -150,17 +152,11 @@ namespace ProjectAirplaneWithRadar ReloadObjects(); Log.Information($" : {name}"); } - } private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) { pictureBoxAirplanesCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowAirplanes(); } - - private void pictureBoxAirplanesCollection_Click(object sender, EventArgs e) - { - - } private void SaveToolStripMenuItem_Click_1(object sender, EventArgs e) { if (saveFileDialog.ShowDialog() == DialogResult.OK) @@ -202,5 +198,26 @@ namespace ProjectAirplaneWithRadar } } } + + private void buttonSortByType_Click(object sender, EventArgs e) => CompareAirplanes(new AirplaneCompareByType()); + + + private void CompareAirplanes(IComparer comparer) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + obj.Sort(comparer); + pictureBoxAirplanesCollection.Image = obj.ShowAirplanes(); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) => CompareAirplanes(new AirplaneCompareByColor()); + } } \ No newline at end of file