компания
This commit is contained in:
parent
789d187fb7
commit
9048bc6077
@ -0,0 +1,126 @@
|
||||
using Microsoft.VisualBasic;
|
||||
using ProjectRoadTrain.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectroTrans.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 230;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 115;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция поездов
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningTrain>? _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<DrawningTrain> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="car">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningTrain trains)
|
||||
{
|
||||
return company._collection.Insert(trains);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningTrain? operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
public static bool operator <(AbstractCompany company1, AbstractCompany company2) => company1._collection.Count < company2._collection.Count;
|
||||
|
||||
public static bool operator >(AbstractCompany company1, AbstractCompany company2) => company1._collection.Count > company2._collection.Count;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningTrain? 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)
|
||||
{
|
||||
DrawningTrain? 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();
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using ProjectRoadTrain.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectElectroTrans.CollectionGenericObjects;
|
||||
|
||||
|
||||
public class AutoParkService : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public AutoParkService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrain> 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++)
|
||||
{
|
||||
DrawningTrain? drawningTrain = _collection?.Get(n);
|
||||
n++;
|
||||
if (drawningTrain != null)
|
||||
{
|
||||
drawningTrain.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
drawningTrain.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,9 +4,45 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectRoadTrain.CollectionGenericObjects
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
internal interface ICollectionGenericObjects
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// Количество объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
|
@ -30,16 +30,17 @@ public class DrawningRoadTrain : DrawningTrain
|
||||
Brush blackcolor = new SolidBrush(Color.Black);
|
||||
Brush bodycolor = new SolidBrush(roadTrain.BodyColor);
|
||||
|
||||
|
||||
if (roadTrain.WaterTank)
|
||||
{
|
||||
g.FillEllipse(bodytankcolor, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50);
|
||||
g.FillEllipse(bodytankcolor, _startPosX.Value + 10, _startPosY.Value + 15, 87, 24);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 15, 87, 24);
|
||||
}
|
||||
if (roadTrain.CleanBrush)
|
||||
{
|
||||
g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 70, 100, 2);
|
||||
g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 75, 100, 2);
|
||||
g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 65, 100, 2);
|
||||
g.FillRectangle(bodytankcolor, _startPosX.Value + 150, _startPosY.Value + 40, 55, 2);
|
||||
g.FillRectangle(bodytankcolor, _startPosX.Value + 150, _startPosY.Value + 46, 55, 2);
|
||||
g.FillRectangle(bodytankcolor, _startPosX.Value + 150, _startPosY.Value + 52, 55, 2);
|
||||
}
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
@ -19,9 +19,9 @@ public class DrawningTrain
|
||||
|
||||
protected int? _startPosY;
|
||||
|
||||
private readonly int _drawningTrainWidth = 170;
|
||||
private readonly int _drawningTrainWidth = 150;
|
||||
|
||||
private readonly int _drawningTrainHeight = 117;
|
||||
private readonly int _drawningTrainHeight = 98;
|
||||
|
||||
public int? GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
@ -161,15 +161,15 @@ public class DrawningTrain
|
||||
Brush bodycolor = new SolidBrush(EntityTrain.BodyColor);
|
||||
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 170, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value, 50, 60);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 40, 150, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 50, 60);
|
||||
// 120 высота
|
||||
// 270 ширина
|
||||
g.FillRectangle(blackcolor, _startPosX.Value, _startPosY.Value + 60, 170, 20);
|
||||
g.FillRectangle(bodycolor, _startPosX.Value + 120, _startPosY.Value, 50, 60);
|
||||
g.FillEllipse(blackcolor, _startPosX.Value + 120, _startPosY.Value + 77, 48, 40);
|
||||
g.FillEllipse(blackcolor, _startPosX.Value + 49, _startPosY.Value + 77, 48, 40);
|
||||
g.FillEllipse(blackcolor, _startPosX.Value, _startPosY.Value + 77, 48, 40);
|
||||
g.FillRectangle(blackcolor, _startPosX.Value, _startPosY.Value + 40, 150, 20);
|
||||
g.FillRectangle(bodycolor, _startPosX.Value + 100, _startPosY.Value, 50, 60);
|
||||
g.FillEllipse(blackcolor, _startPosX.Value + 100, _startPosY.Value + 59, 48, 38);
|
||||
g.FillEllipse(blackcolor, _startPosX.Value + 48, _startPosY.Value + 59, 48, 38);
|
||||
g.FillEllipse(blackcolor, _startPosX.Value, _startPosY.Value + 59, 48, 38);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,12 +29,10 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxRoadTrain = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateTrain = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxRoadTrain).BeginInit();
|
||||
@ -49,17 +47,6 @@
|
||||
pictureBoxRoadTrain.TabIndex = 0;
|
||||
pictureBoxRoadTrain.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 495);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(184, 29);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "создать моющий камаз";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += buttonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -108,17 +95,6 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateTrain
|
||||
//
|
||||
buttonCreateTrain.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateTrain.Location = new Point(215, 495);
|
||||
buttonCreateTrain.Name = "buttonCreateTrain";
|
||||
buttonCreateTrain.Size = new Size(122, 29);
|
||||
buttonCreateTrain.TabIndex = 6;
|
||||
buttonCreateTrain.Text = "создать камаз";
|
||||
buttonCreateTrain.UseVisualStyleBackColor = true;
|
||||
buttonCreateTrain.Click += buttonCreateTrain_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
@ -146,12 +122,10 @@
|
||||
ClientSize = new Size(923, 536);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateTrain);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxRoadTrain);
|
||||
Name = "FormRoadTrain";
|
||||
Text = "автопоезд";
|
||||
@ -162,12 +136,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxRoadTrain;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateTrain;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
|
@ -10,6 +10,18 @@ public partial class FormRoadTrain : Form
|
||||
{
|
||||
private DrawningTrain? _drawningTrain;
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
public DrawningTrain SetTrain
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningTrain = value;
|
||||
_drawningTrain.SetPictureSize(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
public FormRoadTrain()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -29,41 +41,7 @@ public partial class FormRoadTrain : Form
|
||||
_drawningTrain.DrawTransport(gr);
|
||||
pictureBoxRoadTrain.Image = bmp;
|
||||
}
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningTrain):
|
||||
_drawningTrain = new DrawningTrain(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(DrawningRoadTrain):
|
||||
_drawningTrain = new DrawningRoadTrain(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;
|
||||
}
|
||||
|
||||
_drawningTrain.SetPictureSize(pictureBoxRoadTrain.Width, pictureBoxRoadTrain.Height);
|
||||
_drawningTrain.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningRoadTrain));
|
||||
|
||||
}
|
||||
private void buttonCreateTrain_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningTrain));
|
||||
}
|
||||
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTrain == null)
|
||||
|
172
ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.Designer.cs
generated
Normal file
172
ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.Designer.cs
generated
Normal file
@ -0,0 +1,172 @@
|
||||
namespace ProjectRoadTrain
|
||||
{
|
||||
partial class FormTrainCollection
|
||||
{
|
||||
/// <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();
|
||||
buttonDelTrain = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddRoadTrain = new Button();
|
||||
buttonAddTrain = new Button();
|
||||
comboBoxSelectCompany = 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(buttonDelTrain);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddRoadTrain);
|
||||
groupBoxTools.Controls.Add(buttonAddTrain);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(816, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(218, 583);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(6, 470);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(206, 56);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(6, 358);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(206, 56);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||
//
|
||||
// buttonDelTrain
|
||||
//
|
||||
buttonDelTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonDelTrain.Location = new Point(6, 296);
|
||||
buttonDelTrain.Name = "buttonDelTrain";
|
||||
buttonDelTrain.Size = new Size(206, 56);
|
||||
buttonDelTrain.TabIndex = 4;
|
||||
buttonDelTrain.Text = "Удаление камаза";
|
||||
buttonDelTrain.UseVisualStyleBackColor = true;
|
||||
buttonDelTrain.Click += buttonDelTrain_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(6, 263);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(206, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddRoadTrain
|
||||
//
|
||||
buttonAddRoadTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddRoadTrain.Location = new Point(6, 156);
|
||||
buttonAddRoadTrain.Name = "buttonAddRoadTrain";
|
||||
buttonAddRoadTrain.Size = new Size(206, 56);
|
||||
buttonAddRoadTrain.TabIndex = 2;
|
||||
buttonAddRoadTrain.Text = "Добавление моющего камаза";
|
||||
buttonAddRoadTrain.UseVisualStyleBackColor = true;
|
||||
buttonAddRoadTrain.Click += buttonAddRoadTrain_Click;
|
||||
//
|
||||
// buttonAddTrain
|
||||
//
|
||||
buttonAddTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddTrain.Location = new Point(6, 94);
|
||||
buttonAddTrain.Name = "buttonAddTrain";
|
||||
buttonAddTrain.Size = new Size(206, 56);
|
||||
buttonAddTrain.TabIndex = 1;
|
||||
buttonAddTrain.Text = "Добавление камаза";
|
||||
buttonAddTrain.UseVisualStyleBackColor = true;
|
||||
buttonAddTrain.Click += buttonAddTrain_Click;
|
||||
//
|
||||
// comboBoxSelectCompany
|
||||
//
|
||||
comboBoxSelectCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectCompany.FormattingEnabled = true;
|
||||
comboBoxSelectCompany.Items.AddRange(new object[] { "хранилище" });
|
||||
comboBoxSelectCompany.Location = new Point(6, 26);
|
||||
comboBoxSelectCompany.Name = "comboBoxSelectCompany";
|
||||
comboBoxSelectCompany.Size = new Size(206, 28);
|
||||
comboBoxSelectCompany.TabIndex = 0;
|
||||
comboBoxSelectCompany.SelectedIndexChanged += comboBoxSelectCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(816, 583);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormTrainCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1034, 583);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormTrainCollection";
|
||||
Text = "Коллекция камазов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectCompany;
|
||||
private Button buttonAddRoadTrain;
|
||||
private Button buttonAddTrain;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonDelTrain;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
}
|
||||
}
|
208
ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.cs
Normal file
208
ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.cs
Normal file
@ -0,0 +1,208 @@
|
||||
using ProjectElectroTrans.CollectionGenericObjects;
|
||||
using ProjectRoadTrain.CollectionGenericObjects;
|
||||
using ProjectRoadTrain.Drawnings;
|
||||
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;
|
||||
|
||||
namespace ProjectRoadTrain
|
||||
{
|
||||
public partial class FormTrainCollection : Form
|
||||
{
|
||||
private AbstractCompany? _company = null;
|
||||
public FormTrainCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private void comboBoxSelectCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectCompany.Text)
|
||||
{
|
||||
case "хранилище":
|
||||
_company = new AutoParkService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTrain>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
private void buttonAddTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrain));
|
||||
|
||||
/// <summary>
|
||||
/// Добавление спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonAddRoadTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningRoadTrain));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="random">Генератор случайных чисел</param>
|
||||
/// <returns></returns>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTrans_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("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передача объекта в другую форму
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningTrain? train = null;
|
||||
int counter = 100;
|
||||
while (train == null)
|
||||
{
|
||||
train = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (train == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormRoadTrain form = new()
|
||||
{
|
||||
SetTrain = train
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перерисовка коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random random = new();
|
||||
DrawningTrain drawningTrain;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningTrain):
|
||||
drawningTrain = new DrawningTrain(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningRoadTrain):
|
||||
// вызов диалогового окна для выбора цвета
|
||||
drawningTrain = new DrawningRoadTrain(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 + drawningTrain != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = MessageBox.Show(drawningTrain.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 buttonDelTrain_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("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
120
ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.resx
Normal file
120
ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.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>
|
@ -11,7 +11,7 @@ namespace ProjectRoadTrain
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormRoadTrain());
|
||||
Application.Run(new FormTrainCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user