Пятая лабораторная работа

This commit is contained in:
allllen4a 2023-11-07 13:43:16 +03:00
parent 620117e636
commit be244e3736
10 changed files with 774 additions and 78 deletions

View File

@ -54,17 +54,18 @@ namespace projectDoubleDeckerBus
/// <returns></returns>
///
//преобразовали bool в int
public static bool operator +(BusesGenericCollection<T, U> collect, T?
obj)
public static int operator +(BusesGenericCollection<T, U> collect, T obj)
{
if (obj == null)
{
return false;
return -1;
}
return (bool)collect?._collection.Insert(obj);
return collect?._collection.Insert(obj) ?? -1;
}
public static T? operator -(BusesGenericCollection<T, U> collect, int
pos)
/// Перегрузка оператора вычитания
public static T? operator -(BusesGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
@ -73,6 +74,8 @@ namespace projectDoubleDeckerBus
}
return obj;
}
// получение объекта imoveableObj
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;

View File

@ -296,6 +296,9 @@ namespace projectDoubleDeckerBus.Drawings
g.FillEllipse(brBlue, _startPosX + 145, _startPosY + 50, windowSize, windowSize);
}
public void setColor(Color color)
{
EntityBus.setColor(color);
}
}
}

View File

@ -79,5 +79,13 @@ namespace projectDoubleDeckerBus.Drawings
}
base.DrawTransport(g);
}
public void setAddColor(Color color)
{
if (EntityBus is EntityDoubleDeckerBus doubledeckerbus)
{
doubledeckerbus.setAddColor(color);
}
}
}
}

View File

@ -38,5 +38,9 @@ namespace projectDoubleDeckerBus.Entity
Weight = weight;
BodyColor = bodyColor;
}
public void setColor(Color color)
{
BodyColor = color;
}
}
}

View File

@ -42,5 +42,9 @@ namespace projectDoubleDeckerBus.Entity
Floor = floor;
Tailpipe = tailpipe;
}
public void setAddColor(Color color)
{
AdditionalColor = color;
}
}
}

View File

@ -16,7 +16,13 @@ namespace projectDoubleDeckerBus
{
public partial class FormBusCollection : Form
{
/// <summary>
/// Набор объектов
/// </summary>
private readonly BusesGenericStorage _storage;
/// <summary>
/// Конструктор
/// </summary>
public FormBusCollection()
{
InitializeComponent();
@ -24,6 +30,9 @@ namespace projectDoubleDeckerBus
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
ReloadObjects();
}
/// <summary>
/// Заполнение listBoxObjects
/// </summary>
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
@ -32,105 +41,86 @@ namespace projectDoubleDeckerBus
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
private void AddBus(DrawningBus bus)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void buttonUpdateCollection_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
DrawBus.Image = obj.ShowBuses();
}
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
DrawBus.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBuses();
if ((obj + bus) != -1)
{
MessageBox.Show("Объект добавлен");
DrawBus.Image = obj.ShowBuses();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBus_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormDoubleDeckerBus form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedBus)
{
MessageBox.Show("Объект добавлен");
DrawBus.Image = obj.ShowBuses();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
FormBusConfig form = new FormBusConfig();
form.Show();
form.AddEvent(AddBus);
}
/// <summary>
/// Удаление объекта из набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveBus_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
foreach (var it in maskedTextBoxNumber.Text)
if (it < '0' || it > '9')
{
MessageBox.Show("Не удалось удалить объект");
return;
}
if (maskedTextBoxNumber.Text.Length == 0)
{
MessageBox.Show("Не удалось удалить объект");
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
@ -141,6 +131,65 @@ namespace projectDoubleDeckerBus
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Обновление рисунка по набору
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonUpdateCollection_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
DrawBus.Image = obj.ShowBuses();
}
/// <summary>
/// Добавление набора в коллекцию
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
/// <summary>
/// Выбор набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
{
DrawBus.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBuses();
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
}
}
}

View File

@ -0,0 +1,360 @@
namespace projectDoubleDeckerBus
{
partial class FormBusConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBoxParametrs = new GroupBox();
labelModifiedObject = new Label();
labelSimpleObject = new Label();
numericUpDownWeight = new NumericUpDown();
groupBoxColors = new GroupBox();
panelWhite = new Panel();
panelGray = new Panel();
panelBlack = new Panel();
panelPurple = new Panel();
panelYellow = new Panel();
panelBlue = new Panel();
panelGreen = new Panel();
panelRed = new Panel();
numericUpDownSpeed = new NumericUpDown();
checkBoxTailpipe = new CheckBox();
checkBoxFloor = new CheckBox();
label2 = new Label();
label1 = new Label();
pictureBoxObject = new PictureBox();
LabelColor = new Label();
labelAddColor = new Label();
buttonCancel = new Button();
PanelObject = new Panel();
buttonAdd = new Button();
groupBoxParametrs.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
PanelObject.SuspendLayout();
SuspendLayout();
//
// groupBoxParametrs
//
groupBoxParametrs.Controls.Add(labelModifiedObject);
groupBoxParametrs.Controls.Add(labelSimpleObject);
groupBoxParametrs.Controls.Add(numericUpDownWeight);
groupBoxParametrs.Controls.Add(groupBoxColors);
groupBoxParametrs.Controls.Add(numericUpDownSpeed);
groupBoxParametrs.Controls.Add(checkBoxTailpipe);
groupBoxParametrs.Controls.Add(checkBoxFloor);
groupBoxParametrs.Controls.Add(label2);
groupBoxParametrs.Controls.Add(label1);
groupBoxParametrs.Location = new Point(12, 12);
groupBoxParametrs.Name = "groupBoxParametrs";
groupBoxParametrs.Size = new Size(411, 250);
groupBoxParametrs.TabIndex = 0;
groupBoxParametrs.TabStop = false;
groupBoxParametrs.Text = "Parametrs";
//
// labelModifiedObject
//
labelModifiedObject.AllowDrop = true;
labelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
labelModifiedObject.Location = new Point(312, 202);
labelModifiedObject.Name = "labelModifiedObject";
labelModifiedObject.Size = new Size(81, 32);
labelModifiedObject.TabIndex = 6;
labelModifiedObject.Text = "Modified";
labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
labelModifiedObject.MouseDown += LabelObject_MouseDown;
//
// labelSimpleObject
//
labelSimpleObject.AllowDrop = true;
labelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
labelSimpleObject.Location = new Point(174, 202);
labelSimpleObject.Name = "labelSimpleObject";
labelSimpleObject.Size = new Size(81, 32);
labelSimpleObject.TabIndex = 5;
labelSimpleObject.Text = "Simple";
labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
//
// numericUpDownWeight
//
numericUpDownWeight.Location = new Point(50, 72);
numericUpDownWeight.Name = "numericUpDownWeight";
numericUpDownWeight.Size = new Size(98, 23);
numericUpDownWeight.TabIndex = 2;
//
// groupBoxColors
//
groupBoxColors.Controls.Add(panelWhite);
groupBoxColors.Controls.Add(panelGray);
groupBoxColors.Controls.Add(panelBlack);
groupBoxColors.Controls.Add(panelPurple);
groupBoxColors.Controls.Add(panelYellow);
groupBoxColors.Controls.Add(panelBlue);
groupBoxColors.Controls.Add(panelGreen);
groupBoxColors.Controls.Add(panelRed);
groupBoxColors.Location = new Point(174, 22);
groupBoxColors.Name = "groupBoxColors";
groupBoxColors.Size = new Size(219, 159);
groupBoxColors.TabIndex = 4;
groupBoxColors.TabStop = false;
groupBoxColors.Text = "Colors";
//
// panelWhite
//
panelWhite.BackColor = Color.White;
panelWhite.Location = new Point(6, 87);
panelWhite.Name = "panelWhite";
panelWhite.Size = new Size(33, 30);
panelWhite.TabIndex = 7;
panelWhite.MouseDown += PanelColor_MouseDown;
//
// panelGray
//
panelGray.BackColor = Color.Silver;
panelGray.Location = new Point(54, 87);
panelGray.Name = "panelGray";
panelGray.Size = new Size(33, 30);
panelGray.TabIndex = 6;
panelGray.MouseDown += PanelColor_MouseDown;
//
// panelBlack
//
panelBlack.BackColor = Color.Black;
panelBlack.Location = new Point(103, 87);
panelBlack.Name = "panelBlack";
panelBlack.Size = new Size(33, 30);
panelBlack.TabIndex = 5;
panelBlack.MouseDown += PanelColor_MouseDown;
//
// panelPurple
//
panelPurple.BackColor = Color.Purple;
panelPurple.Location = new Point(162, 87);
panelPurple.Name = "panelPurple";
panelPurple.Size = new Size(33, 30);
panelPurple.TabIndex = 4;
panelPurple.MouseDown += PanelColor_MouseDown;
//
// panelYellow
//
panelYellow.BackColor = Color.Yellow;
panelYellow.Location = new Point(159, 22);
panelYellow.Name = "panelYellow";
panelYellow.Size = new Size(33, 30);
panelYellow.TabIndex = 3;
panelYellow.MouseDown += PanelColor_MouseDown;
//
// panelBlue
//
panelBlue.BackColor = Color.Blue;
panelBlue.Location = new Point(103, 22);
panelBlue.Name = "panelBlue";
panelBlue.Size = new Size(33, 30);
panelBlue.TabIndex = 2;
panelBlue.MouseDown += PanelColor_MouseDown;
//
// panelGreen
//
panelGreen.BackColor = Color.Lime;
panelGreen.Location = new Point(54, 22);
panelGreen.Name = "panelGreen";
panelGreen.Size = new Size(33, 30);
panelGreen.TabIndex = 1;
panelGreen.MouseDown += PanelColor_MouseDown;
//
// panelRed
//
panelRed.BackColor = Color.Red;
panelRed.Location = new Point(6, 22);
panelRed.Name = "panelRed";
panelRed.Size = new Size(33, 30);
panelRed.TabIndex = 0;
panelRed.MouseDown += PanelColor_MouseDown;
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location = new Point(50, 28);
numericUpDownSpeed.Name = "numericUpDownSpeed";
numericUpDownSpeed.Size = new Size(98, 23);
numericUpDownSpeed.TabIndex = 1;
//
// checkBoxTailpipe
//
checkBoxTailpipe.AutoSize = true;
checkBoxTailpipe.Location = new Point(6, 162);
checkBoxTailpipe.Name = "checkBoxTailpipe";
checkBoxTailpipe.Size = new Size(66, 19);
checkBoxTailpipe.TabIndex = 3;
checkBoxTailpipe.Text = "Tailpipe";
checkBoxTailpipe.UseVisualStyleBackColor = true;
//
// checkBoxFloor
//
checkBoxFloor.AutoSize = true;
checkBoxFloor.Location = new Point(6, 120);
checkBoxFloor.Name = "checkBoxFloor";
checkBoxFloor.Size = new Size(53, 19);
checkBoxFloor.TabIndex = 2;
checkBoxFloor.Text = "Floor";
checkBoxFloor.UseVisualStyleBackColor = true;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 74);
label2.Name = "label2";
label2.Size = new Size(45, 15);
label2.TabIndex = 1;
label2.Text = "Weight";
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 30);
label1.Name = "label1";
label1.Size = new Size(39, 15);
label1.TabIndex = 0;
label1.Text = "Speed";
//
// pictureBoxObject
//
pictureBoxObject.Location = new Point(3, 29);
pictureBoxObject.Name = "pictureBoxObject";
pictureBoxObject.Size = new Size(340, 212);
pictureBoxObject.TabIndex = 1;
pictureBoxObject.TabStop = false;
//
// LabelColor
//
LabelColor.AllowDrop = true;
LabelColor.BorderStyle = BorderStyle.FixedSingle;
LabelColor.Location = new Point(23, 4);
LabelColor.Name = "LabelColor";
LabelColor.Size = new Size(76, 22);
LabelColor.TabIndex = 2;
LabelColor.Text = "ColorBase";
LabelColor.TextAlign = ContentAlignment.MiddleCenter;
LabelColor.DragDrop += LabelColor_DragDrop;
LabelColor.DragEnter += LabelColor_DragEnter;
//
// labelAddColor
//
labelAddColor.AllowDrop = true;
labelAddColor.BorderStyle = BorderStyle.FixedSingle;
labelAddColor.Location = new Point(241, 4);
labelAddColor.Name = "labelAddColor";
labelAddColor.Size = new Size(76, 22);
labelAddColor.TabIndex = 3;
labelAddColor.Text = "AddColor";
labelAddColor.TextAlign = ContentAlignment.MiddleCenter;
labelAddColor.DragDrop += LabelAddColor_DragDrop;
labelAddColor.DragEnter += LabelColor_DragEnter;
//
// buttonCancel
//
buttonCancel.Location = new Point(659, 268);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(123, 39);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "cancel";
buttonCancel.UseVisualStyleBackColor = true;
//
// PanelObject
//
PanelObject.AllowDrop = true;
PanelObject.Controls.Add(LabelColor);
PanelObject.Controls.Add(labelAddColor);
PanelObject.Controls.Add(pictureBoxObject);
PanelObject.Location = new Point(434, 18);
PanelObject.Name = "PanelObject";
PanelObject.Size = new Size(348, 244);
PanelObject.TabIndex = 6;
PanelObject.DragDrop += PanelObject_DragDrop;
PanelObject.DragEnter += PanelObject_DragEnter;
//
// buttonAdd
//
buttonAdd.Location = new Point(434, 268);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(123, 39);
buttonAdd.TabIndex = 7;
buttonAdd.Text = "add";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += buttonAdd_Click;
//
// FormBusConfig
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(789, 323);
Controls.Add(buttonAdd);
Controls.Add(buttonCancel);
Controls.Add(groupBoxParametrs);
Controls.Add(PanelObject);
Name = "FormBusConfig";
Text = "FormBusConfig";
groupBoxParametrs.ResumeLayout(false);
groupBoxParametrs.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
PanelObject.ResumeLayout(false);
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParametrs;
private GroupBox groupBoxColors;
private CheckBox checkBoxTailpipe;
private CheckBox checkBoxFloor;
private Label label2;
private Label label1;
private NumericUpDown numericUpDownSpeed;
private NumericUpDown numericUpDownWeight;
private Panel panelWhite;
private Panel panelGray;
private Panel panelBlack;
private Panel panelPurple;
private Panel panelYellow;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelRed;
private PictureBox pictureBoxObject;
private Label labelModifiedObject;
private Label labelSimpleObject;
private Label LabelColor;
private Label labelAddColor;
private Button buttonCancel;
private Panel PanelObject;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using projectDoubleDeckerBus.Entity;
using projectDoubleDeckerBus.Drawings;
using projectDouble_Decker_Bus.MovementStrategy;
namespace projectDoubleDeckerBus
{
public partial class FormBusConfig : Form
{
DrawningBus? _bus = null;
private event Action<DrawningBus> EventAddBus;
public FormBusConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
private void DrawCar()
{
Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_bus?.SetPosition(5, 5);
if (_bus is DrawningBus)
(_bus as DrawningBus).DrawTransport(gr);
else
_bus?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
e.Effect = DragDropEffects.Copy;
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelColor_DragDrop(object sender, DragEventArgs e)
{
if (_bus is DrawningBus bus)
{
LabelColor.BackColor = (Color)e.Data.GetData(typeof(Color));
_bus.setColor((Color)e.Data.GetData(typeof(Color)));
}
DrawCar();
}
private void LabelAddColor_DragDrop(object sender, DragEventArgs e)
{
if (_bus is DrawningDoubleDeckerBus bus)
{
labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color));
bus.setAddColor((Color)e.Data.GetData(typeof(Color)));
}
DrawCar();
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_bus = new DrawningBus((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, 900,
500);
LabelColor.BackColor = Color.White;
labelAddColor.BackColor = Color.Transparent;
break;
case "labelModifiedObject":
_bus = new DrawningDoubleDeckerBus((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxFloor.Checked,
checkBoxTailpipe.Checked, 900,
500);
LabelColor.BackColor = Color.White;
labelAddColor.BackColor = Color.Black;
break;
}
DrawCar();
}
public void AddEvent(Action<DrawningBus> ev)
{
if (EventAddBus == null)
{
EventAddBus = ev;
}
else
{
EventAddBus += ev;
}
}
private void buttonAdd_Click(object sender, EventArgs e)
{
EventAddBus?.Invoke(_bus);
Close();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -35,42 +35,52 @@ namespace projectDoubleDeckerBus.Generics
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <returns></returns>
public bool Insert(T bus)
public int Insert(T bus)
{
return Insert(bus, 0);
if (_places.Count >= _maxCount)
return -1;
_places.Insert(0, bus);
return 0;
}
public bool Insert(T bus, int position)
{
if (position < 0 || position >= _maxCount)
if (_places.Count >= _maxCount)
return false;
if (Count >= _maxCount)
if (position < 0 || position > _places.Count)
return false;
_places.Insert(0, bus);
if (position == _places.Count)
_places.Add(bus);
else
_places.Insert(position, bus);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > _maxCount)
return false;
if (position >= Count)
if (position < 0 || position >= _places.Count)
return false;
_places.RemoveAt(position);
return true;
}
public T? this[int position]
public T Get(int position)
{
if (position < 0 || position >= _places.Count)
return null;
return _places[position];
}
public T this[int position]
{
get
{
if (position < 0 || position > _maxCount)
if (position < 0 || position >= _places.Count)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
_places[position] = value;
Insert(value, position);
}
}
public IEnumerable<T?> GetBuses(int? maxBuses = null)