From f31ccdc5933e612fe51c08a9e201d58539868b77 Mon Sep 17 00:00:00 2001 From: Yunusov_Niyaz Date: Fri, 17 Nov 2023 17:53:02 +0400 Subject: [PATCH] Lab5 Done --- Trolleybus/Trolleybus/BusDelegate.cs | 11 --- Trolleybus/Trolleybus/FormBusCollection.cs | 17 ++--- Trolleybus/Trolleybus/FormBusConfig.cs | 83 ++++++++++++---------- 3 files changed, 51 insertions(+), 60 deletions(-) delete mode 100644 Trolleybus/Trolleybus/BusDelegate.cs diff --git a/Trolleybus/Trolleybus/BusDelegate.cs b/Trolleybus/Trolleybus/BusDelegate.cs deleted file mode 100644 index c0eb1f3..0000000 --- a/Trolleybus/Trolleybus/BusDelegate.cs +++ /dev/null @@ -1,11 +0,0 @@ -using ProjectTrolleybus.DrawingObjects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectTrolleybus -{ - public delegate void BusDelegate(DrawingBus bus); -} diff --git a/Trolleybus/Trolleybus/FormBusCollection.cs b/Trolleybus/Trolleybus/FormBusCollection.cs index 0586524..5148483 100644 --- a/Trolleybus/Trolleybus/FormBusCollection.cs +++ b/Trolleybus/Trolleybus/FormBusCollection.cs @@ -64,8 +64,7 @@ namespace ProjectTrolleybus } if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _storage.DelSet(listBoxStorages.SelectedItem.ToString() - ?? string.Empty); + _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); } } @@ -75,17 +74,15 @@ namespace ProjectTrolleybus { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } FormBusConfig form = new FormBusConfig(pictureBoxCollection.Width, pictureBoxCollection.Height); form.Show(); - BusDelegate? busDelegate = new((m) => { - bool q = (obj + m); - if (q) + Action? busDelegate = new((bus) => { + if (obj + bus) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowBuses(); @@ -103,8 +100,7 @@ namespace ProjectTrolleybus { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; @@ -131,8 +127,7 @@ namespace ProjectTrolleybus { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; diff --git a/Trolleybus/Trolleybus/FormBusConfig.cs b/Trolleybus/Trolleybus/FormBusConfig.cs index b5f250e..76da4e4 100644 --- a/Trolleybus/Trolleybus/FormBusConfig.cs +++ b/Trolleybus/Trolleybus/FormBusConfig.cs @@ -14,12 +14,12 @@ namespace ProjectTrolleybus { public partial class FormBusConfig : Form { - private readonly int PictureWidth; - private readonly int PictureHeight; + private readonly int _pictureWidth; + private readonly int _pictureHeight; DrawingBus? _bus = null; - private event BusDelegate? EventAddBus; + Action? EventAddBus; public FormBusConfig(int Width, int Height) { @@ -33,18 +33,20 @@ namespace ProjectTrolleybus panelYellow.MouseDown += PanelColor_MouseDown; panelBlue.MouseDown += PanelColor_MouseDown; buttonCancel.Click += (s, e) => Close(); - PictureWidth = Width; - PictureHeight = Height; + _pictureWidth = Width; + _pictureHeight = Height; } private void DrawBus() { Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); Graphics gr = Graphics.FromImage(bmp); - _bus?.SetPosition(5, 5); _bus?.DrawTransport(gr); pictureBoxObject.Image = bmp; + _bus?.SetPosition(5, 5); + _bus?.DrawTransport(gr); + pictureBoxObject.Image = bmp; } - public void AddEvent(BusDelegate ev) + public void AddEvent(Action ev) { if (EventAddBus == null) { @@ -79,9 +81,14 @@ namespace ProjectTrolleybus switch (e.Data?.GetData(DataFormats.Text).ToString()) { case "labelSimple": - _bus = new DrawingBus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, PictureWidth, PictureHeight); break; + _bus = new DrawingBus((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, _pictureWidth, _pictureHeight); + break; case "labelAdvanced": - _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRoga.Checked, checkBoxBattery.Checked, PictureWidth, PictureHeight); break; + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxRoga.Checked, + checkBoxBattery.Checked, _pictureWidth, _pictureHeight); + break; } DrawBus(); } @@ -101,44 +108,21 @@ namespace ProjectTrolleybus Close(); } - private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(typeof(Color))) - { - e.Effect = DragDropEffects.Copy; - } - else - { - e.Effect = DragDropEffects.None; - } - } - - private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) - { - if (_bus == null || _bus.EntityBus == null || _bus is DrawingTrolleybus == false) - return; - Color colorAdditional = (Color)e.Data.GetData(typeof(Color)); - _bus = new DrawingTrolleybus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, - _bus.EntityBus.BodyColor, colorAdditional, ((EntityTrolleybus)_bus.EntityBus).Roga, - ((EntityTrolleybus)_bus.EntityBus).Battery, PictureWidth, PictureHeight); - DrawBus(); - } - private void labelColor_DragDrop(object sender, DragEventArgs e) { if (_bus == null || _bus.EntityBus == null) return; - Color color = (Color)e.Data.GetData(typeof(Color)); + Color colorBody = (Color)e.Data.GetData(typeof(Color)); if (_bus is DrawingTrolleybus == false) { - _bus = new DrawingBus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, - color, PictureWidth, PictureHeight); + _bus = new DrawingBus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + colorBody, _pictureWidth, _pictureHeight); } else { - _bus = new DrawingTrolleybus(_bus.EntityBus.Speed, _bus.EntityBus.Weight, - color, ((EntityTrolleybus)_bus.EntityBus).AdditionalColor, ((EntityTrolleybus)_bus.EntityBus).Roga, - ((EntityTrolleybus)_bus.EntityBus).Battery, PictureWidth, PictureHeight); + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + colorBody, ((EntityTrolleybus)_bus.EntityBus).AdditionalColor, checkBoxRoga.Checked, + checkBoxBattery.Checked, _pictureWidth, _pictureHeight); } DrawBus(); @@ -155,6 +139,29 @@ namespace ProjectTrolleybus e.Effect = DragDropEffects.None; } } + + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_bus == null || _bus.EntityBus == null || _bus is DrawingTrolleybus == false) + return; + Color colorAdditional = (Color)e.Data.GetData(typeof(Color)); + _bus = new DrawingTrolleybus((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, + _bus.EntityBus.BodyColor, colorAdditional, checkBoxRoga.Checked, + checkBoxBattery.Checked, _pictureWidth, _pictureHeight); + DrawBus(); + } + + private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } } }