Lab5 Done

This commit is contained in:
Yunusov_Niyaz 2023-11-17 17:53:02 +04:00
parent de631fcdf5
commit f31ccdc593
3 changed files with 51 additions and 60 deletions

View File

@ -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);
}

View File

@ -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<DrawingBus>? 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;

View File

@ -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<DrawingBus>? 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<DrawingBus> 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;
}
}
}
}