PIbd-14 RachekA.C. LabWork3 Base #3
116
lab_0/CollectionGenericObject/AbstractCompany.cs
Normal file
116
lab_0/CollectionGenericObject/AbstractCompany.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using ProjectBus.Drawnings;
|
||||
|
||||
namespace ProjectBus.CollectionGenericObject;
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 400;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 80;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция автобусов
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningSimpleBus>? _collection = null;
|
||||
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="picHeight">Высота окна</param>
|
||||
/// <param name="collection">Коллекция поездов</param>
|
||||
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningSimpleBus> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="simplebus">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningSimpleBus simplebus)
|
||||
{
|
||||
return company._collection.Insert(simplebus);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningSimpleBus? operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningSimpleBus? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackgound(graphics);
|
||||
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningSimpleBus? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void DrawBackgound(Graphics g);
|
||||
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
|
56
lab_0/CollectionGenericObject/BusStation.cs
Normal file
56
lab_0/CollectionGenericObject/BusStation.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using ProjectBus.Drawnings;
|
||||
using ProjectBus.Entities;
|
||||
using System;
|
||||
|
||||
namespace ProjectBus.CollectionGenericObject;
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании - аренда поезда
|
||||
/// </summary>
|
||||
public class BusStation : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public BusStation(int picWidth, int picHeight, ICollectionGenericObjects<DrawningSimpleBus> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j));
|
||||
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1)));
|
||||
}
|
||||
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
int n = 0;
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
DrawningSimpleBus? drawningSimpleBus = _collection?.Get(n);
|
||||
n++;
|
||||
if (drawningSimpleBus != null)
|
||||
{
|
||||
drawningSimpleBus.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
drawningSimpleBus.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
28
lab_0/FormBus.Designer.cs
generated
28
lab_0/FormBus.Designer.cs
generated
@ -29,12 +29,10 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxBus = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonCreateSimpleBus = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit();
|
||||
@ -49,17 +47,6 @@
|
||||
pictureBoxBus.TabIndex = 7;
|
||||
pictureBoxBus.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 501);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(410, 46);
|
||||
buttonCreate.TabIndex = 2;
|
||||
buttonCreate.Text = "Создать автобус с доп.отсеком";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -108,17 +95,6 @@
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateSimpleBus
|
||||
//
|
||||
buttonCreateSimpleBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateSimpleBus.Location = new Point(428, 501);
|
||||
buttonCreateSimpleBus.Name = "buttonCreateSimpleBus";
|
||||
buttonCreateSimpleBus.Size = new Size(431, 46);
|
||||
buttonCreateSimpleBus.TabIndex = 8;
|
||||
buttonCreateSimpleBus.Text = "Создать обычный автобус";
|
||||
buttonCreateSimpleBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateSimpleBus.Click += buttonCreateSimpleBus_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
@ -146,12 +122,10 @@
|
||||
ClientSize = new Size(1155, 557);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateSimpleBus);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxBus);
|
||||
Name = "FormBus";
|
||||
Text = "Автобус";
|
||||
@ -161,12 +135,10 @@
|
||||
|
||||
#endregion
|
||||
private PictureBox pictureBoxBus;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateSimpleBus;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
|
@ -26,6 +26,22 @@ public partial class FormBus : Form
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта
|
||||
/// </summary>
|
||||
public DrawningSimpleBus SetSimpleBus
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningSimpleBus = value;
|
||||
_drawningSimpleBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
@ -52,51 +68,6 @@ public partial class FormBus : Form
|
||||
pictureBoxBus.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningSimpleBus):
|
||||
_drawningSimpleBus = new DrawningSimpleBus(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningBus):
|
||||
_drawningSimpleBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningSimpleBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height);
|
||||
_drawningSimpleBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать автобус с доп отсеком"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать обычный автобус"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus));
|
||||
|
||||
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
@ -179,3 +150,4 @@ public partial class FormBus : Form
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
174
lab_0/FormSimpleBusCollection.Designer.cs
generated
Normal file
174
lab_0/FormSimpleBusCollection.Designer.cs
generated
Normal file
@ -0,0 +1,174 @@
|
||||
namespace ProjectBus
|
||||
{
|
||||
partial class FormSimpleBusCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonDelBus = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddBus = new Button();
|
||||
buttonAddSimpleBus = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonDelBus);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddBus);
|
||||
groupBoxTools.Controls.Add(buttonAddSimpleBus);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(1063, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(333, 962);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(6, 731);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(315, 84);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click_1;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(6, 565);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(315, 84);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click_1;
|
||||
//
|
||||
// buttonDelBus
|
||||
//
|
||||
buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonDelBus.Location = new Point(6, 416);
|
||||
buttonDelBus.Name = "buttonDelBus";
|
||||
buttonDelBus.Size = new Size(315, 84);
|
||||
buttonDelBus.TabIndex = 5;
|
||||
buttonDelBus.Text = "Удалить автобус";
|
||||
buttonDelBus.UseVisualStyleBackColor = true;
|
||||
buttonDelBus.Click += ButtonDelBus_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(6, 355);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(315, 39);
|
||||
maskedTextBox.TabIndex = 4;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddBus
|
||||
//
|
||||
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddBus.Location = new Point(6, 225);
|
||||
buttonAddBus.Name = "buttonAddBus";
|
||||
buttonAddBus.Size = new Size(315, 84);
|
||||
buttonAddBus.TabIndex = 2;
|
||||
buttonAddBus.Text = "Добавление автобуса с доп. отсеком";
|
||||
buttonAddBus.UseVisualStyleBackColor = true;
|
||||
buttonAddBus.Click += ButtonAddBus_Click;
|
||||
//
|
||||
// buttonAddSimpleBus
|
||||
//
|
||||
buttonAddSimpleBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddSimpleBus.Location = new Point(6, 118);
|
||||
buttonAddSimpleBus.Name = "buttonAddSimpleBus";
|
||||
buttonAddSimpleBus.Size = new Size(315, 84);
|
||||
buttonAddSimpleBus.TabIndex = 1;
|
||||
buttonAddSimpleBus.Text = "Добавление автобуса";
|
||||
buttonAddSimpleBus.UseVisualStyleBackColor = true;
|
||||
buttonAddSimpleBus.Click += ButtonAddSimpleBus_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 47);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(315, 40);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(1063, 962);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormSimpleBusCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1396, 962);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormSimpleBusCollection";
|
||||
Text = "Коллекция автобусов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddBus;
|
||||
private Button buttonAddSimpleBus;
|
||||
private Button buttonDelBus;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
}
|
||||
}
|
182
lab_0/FormSimpleBusCollection.cs
Normal file
182
lab_0/FormSimpleBusCollection.cs
Normal file
@ -0,0 +1,182 @@
|
||||
using ProjectBus.MovementStrategy;
|
||||
using ProjectBus.Drawnings;
|
||||
using ProjectBus.CollectionGenericObject;
|
||||
|
||||
namespace ProjectBus;
|
||||
|
||||
public partial class FormSimpleBusCollection : Form
|
||||
{
|
||||
private AbstractCompany? _company = null;
|
||||
public FormSimpleBusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "хранилище":
|
||||
_company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningSimpleBus>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus));
|
||||
|
||||
/// <summary>
|
||||
/// Добавление спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="random">Генератор случайных чисел</param>
|
||||
/// <returns></returns>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Передача объекта в другую форму
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перерисовка коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random random = new();
|
||||
DrawningSimpleBus drawningSimpleBus;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningSimpleBus):
|
||||
drawningSimpleBus = new DrawningSimpleBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningBus):
|
||||
// вызов диалогового окна для выбора цвета
|
||||
drawningSimpleBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningSimpleBus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = MessageBox.Show(drawningSimpleBus.ToString());
|
||||
}
|
||||
}
|
||||
private static Color GetColor(Random random)
|
||||
{
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
||||
private void ButtonDelBus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRefresh_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
|
||||
}
|
||||
|
||||
private void ButtonGoToCheck_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningSimpleBus? simplebus = null;
|
||||
int counter = 100;
|
||||
while (simplebus == null)
|
||||
{
|
||||
simplebus = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (simplebus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormBus form = new()
|
||||
{
|
||||
SetSimpleBus = simplebus
|
||||
};
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
}
|
||||
|
120
lab_0/FormSimpleBusCollection.resx
Normal file
120
lab_0/FormSimpleBusCollection.resx
Normal 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>
|
@ -13,7 +13,7 @@ namespace lab_0
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBus());
|
||||
Application.Run(new FormSimpleBusCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user