diff --git a/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/AbstractCompany.cs b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..ba86553
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/AbstractCompany.cs
@@ -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;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 230;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 115;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция поездов
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция поездов
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static int operator +(AbstractCompany company, DrawningTrain trains)
+ {
+ return company._collection.Insert(trains);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ 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;
+
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTrain? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ 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;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/AutoParkService.cs b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/AutoParkService.cs
new file mode 100644
index 0000000..62cd451
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/AutoParkService.cs
@@ -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
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public AutoParkService(int picWidth, int picHeight, ICollectionGenericObjects 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);
+ }
+ }
+ }
+ }
+}
diff --git a/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..4e9086c
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,48 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ T? Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+}
diff --git a/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..a6559b1
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,121 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectRoadTrain.CollectionGenericObjects;
+
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (_collection.Length > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
+
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)
+ {
+ if (position >= 0 && position < Count)
+ {
+ return _collection[position];
+ }
+
+ return null;
+ }
+
+ public int Insert(T obj)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ if (_collection[position] != null)
+ {
+ bool pushed = false;
+ for (int index = position + 1; index < Count; index++)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+
+ if (!pushed)
+ {
+ for (int index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+ }
+
+ if (!pushed)
+ {
+ return position;
+ }
+ }
+
+ _collection[position] = obj;
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ if (_collection[position] == null) return null;
+
+ T? temp = _collection[position];
+ _collection[position] = null;
+ return temp;
+ }
+}
\ No newline at end of file
diff --git a/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs
index 93ba94b..f5efda3 100644
--- a/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs
+++ b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningRoadTrain.cs
@@ -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);
diff --git a/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs
index 5030265..e2af3cf 100644
--- a/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs
+++ b/ProjectRoadTrain/ProjectRoadTrain/Drawnings/DrawningTrain.cs
@@ -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;
///
@@ -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);
}
}
diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs
index 552d7a9..f4c6769 100644
--- a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs
+++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.Designer.cs
@@ -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;
}
diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs
index 1c9152c..2152370 100644
--- a/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs
+++ b/ProjectRoadTrain/ProjectRoadTrain/FormRoadTrain.cs
@@ -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)
diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.Designer.cs b/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.Designer.cs
new file mode 100644
index 0000000..ed2bbb7
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.Designer.cs
@@ -0,0 +1,172 @@
+namespace ProjectRoadTrain
+{
+ partial class FormTrainCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.cs b/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.cs
new file mode 100644
index 0000000..4ed2e17
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.cs
@@ -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());
+ break;
+ }
+ }
+ private void buttonAddTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrain));
+
+ ///
+ /// Добавление спортивного автомобиля
+ ///
+ ///
+ ///
+ private void buttonAddRoadTrain_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningRoadTrain));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ 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("Не удалось удалить объект");
+ }
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ 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();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ 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("Не удалось удалить объект");
+ }
+ }
+
+ }
+}
+
diff --git a/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.resx b/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectRoadTrain/ProjectRoadTrain/FormTrainCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectRoadTrain/ProjectRoadTrain/Program.cs b/ProjectRoadTrain/ProjectRoadTrain/Program.cs
index d87a77e..2ccde8f 100644
--- a/ProjectRoadTrain/ProjectRoadTrain/Program.cs
+++ b/ProjectRoadTrain/ProjectRoadTrain/Program.cs
@@ -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());
}
}
}
\ No newline at end of file