Collections

This commit is contained in:
BoiledMilk123 2024-04-07 22:44:06 +04:00
parent 3f11f1c9b8
commit a917e654ef
10 changed files with 841 additions and 73 deletions

View File

@ -0,0 +1,116 @@
using ProjectElectricLocomotive.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 147;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 64;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция автомобилей
/// </summary>
protected ICollectionGenericObjects<DrawningLocomotive>? _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<DrawningLocomotive> 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, DrawningLocomotive truck)
{
return company._collection.Insert(truck);
}
// <summary>
// Перегрузка оператора удаления для класса
// </summary>
// <param name = "company" > Компания </ param >
// < param name="position">Номер удаляемого объекта</param>
// <returns></returns>
public static DrawningLocomotive operator -(AbstractCompany company, int position)
{
return company._collection.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningLocomotive? 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)
{
DrawningLocomotive? 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();
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public interface ICollectionGenericObjects<T>
where T : class
{
/// <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>
/// Добавление объекта в коллекцию на конкретную позицию
/// /// <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);
}

View File

@ -0,0 +1,74 @@
using ProjectElectricLocomotive.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
public class LocomotiveDepot : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth">Ширина</param>
/// <param name="picHeight">Высота</param>
/// <param name="collection">Коллекция</param>
public LocomotiveDepot(int picWidth, int picHeight, ICollectionGenericObjects<DrawningLocomotive> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
int count_width = _pictureWidth / _placeSizeWidth; // кол-во мест в ширину
int count_height = _pictureHeight / _placeSizeHeight; // кол-во мест в длинну
Pen pen = new(Color.Black, 3);
for (int i = 0; i < count_width; i++)
{
for (int j = 0; j < count_height + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int positionWidth = 0;
int positionHeight = height - 1;
if (_collection?.Count != null)
{
for (int i = 0; i < (_collection.Count); i++)
{
if (_collection.Get(i) != null)
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * positionWidth + 25, positionHeight * _placeSizeHeight + 10);
}
if (positionWidth < width - 1)
{
positionWidth++;
}
else
{
positionWidth = 0;
positionHeight--;
}
if (positionHeight < 0)
{
return;
}
}
}
}
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T?[] _collection;
public int Count => _collection.Length;
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
// проверка позиции
if (position >= Count || position < 0)
{
return null;
}
return _collection[position];
}
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 >= Count || position < 0)
{
return -1;
}
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
else
{
for (int i = 1; i < Count; ++i)
{
if (_collection[position + i] == null)
{
_collection[position + i] = obj;
return position + i;
}
for (i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
}
}
return -1;
}
public T? Remove(int position)
{
//// проверка позиции
//// удаление объекта из массива, присвоив элементу массива значение null
if (position >= Count || position < 0 || _collection[position] == null) return null;
T removedObject = _collection[position];
_collection[position] = null;
return removedObject;
}
}

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxElectricLocomotive = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonCreateLocomotive = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
@ -49,17 +47,6 @@
pictureBoxElectricLocomotive.TabIndex = 0;
pictureBoxElectricLocomotive.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 436);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(150, 31);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать электровоз";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -112,17 +99,6 @@
buttonUp.UseVisualStyleBackColor = false;
buttonUp.Click += ButtonMove_Click;
//
// buttonCreateLocomotive
//
buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateLocomotive.Location = new Point(187, 436);
buttonCreateLocomotive.Name = "buttonCreateLocomotive";
buttonCreateLocomotive.Size = new Size(150, 31);
buttonCreateLocomotive.TabIndex = 6;
buttonCreateLocomotive.Text = "Создать локомотив";
buttonCreateLocomotive.UseVisualStyleBackColor = true;
buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -150,12 +126,10 @@
ClientSize = new Size(866, 479);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateLocomotive);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxElectricLocomotive);
Name = "FormElectricLocomotive";
Text = "Электровоз";
@ -166,12 +140,10 @@
#endregion
private PictureBox pictureBoxElectricLocomotive;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateLocomotive;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -21,6 +21,22 @@ public partial class FormElectricLocomotive : Form
private AbstractStrategy? _strategy;
/// <summary>
/// Получение объекта
/// </summary>
public DrawningLocomotive SetLocomotive
{
set
{
_drawningLocomotive = value;
_drawningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы
/// </summary>
@ -46,50 +62,6 @@ public partial class FormElectricLocomotive : Form
pictureBoxElectricLocomotive.Image = bmp;
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningLocomotive):
_drawningLocomotive = new DrawningLocomotive(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(DrawningElectricLocomotive):
_drawningLocomotive = new DrawningElectricLocomotive(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;
}
_drawningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
_drawningLocomotive.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(DrawningElectricLocomotive));
/// <summary>
/// Обработка нажатия кнопки "Создать локомотив"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>

View File

@ -0,0 +1,171 @@
namespace ProjectElectricLocomotive
{
partial class FormLocomotiveCollection
{
/// <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();
buttonRemoveLocomotive = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddElectricLocomotiv = new Button();
buttonAddLocomotive = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
colorDialog1 = new ColorDialog();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveLocomotive);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddElectricLocomotiv);
groupBoxTools.Controls.Add(buttonAddLocomotive);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(600, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(200, 450);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Location = new Point(6, 336);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(188, 32);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(6, 265);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(188, 32);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Поставить на пути";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveLocomotive
//
buttonRemoveLocomotive.Location = new Point(6, 193);
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
buttonRemoveLocomotive.Size = new Size(188, 32);
buttonRemoveLocomotive.TabIndex = 4;
buttonRemoveLocomotive.Text = "Удалить локомотив";
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 164);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(188, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddElectricLocomotiv
//
buttonAddElectricLocomotiv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddElectricLocomotiv.Location = new Point(6, 104);
buttonAddElectricLocomotiv.Name = "buttonAddElectricLocomotiv";
buttonAddElectricLocomotiv.Size = new Size(188, 32);
buttonAddElectricLocomotiv.TabIndex = 2;
buttonAddElectricLocomotiv.Text = "Добавить электровоз";
buttonAddElectricLocomotiv.UseVisualStyleBackColor = true;
buttonAddElectricLocomotiv.Click += ButtonAddElectricLocomotive_Click;
//
// buttonAddLocomotive
//
buttonAddLocomotive.Location = new Point(6, 66);
buttonAddLocomotive.Name = "buttonAddLocomotive";
buttonAddLocomotive.Size = new Size(188, 32);
buttonAddLocomotive.TabIndex = 1;
buttonAddLocomotive.Text = "Добавить локомотив";
buttonAddLocomotive.UseVisualStyleBackColor = true;
buttonAddLocomotive.Click += ButtonAddLocomotive_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, 22);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(188, 23);
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(600, 450);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormLocomotiveCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormLocomotiveCollection";
Text = "FormLocomotiveCollection";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddLocomotive;
private Button buttonRemoveLocomotive;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddElectricLocomotiv;
private PictureBox pictureBox;
private Button buttonGoToCheck;
private Button buttonRefresh;
private ColorDialog colorDialog1;
}
}

View File

@ -0,0 +1,184 @@
using ProjectElectricLocomotive.CollectionGenericObjects;
using ProjectElectricLocomotive.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 ProjectElectricLocomotive;
public partial class FormLocomotiveCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormLocomotiveCollection()
{
InitializeComponent();
}
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new LocomotiveDepot(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningLocomotive>());
break;
}
}
/// <summary>
/// Добавление грузовика
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
/// <summary>
/// Добавление бензовоза
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddElectricLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectricLocomotive));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningLocomotive DrawningLocomotive;
switch (type)
{
case nameof(DrawningLocomotive):
DrawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningElectricLocomotive):
DrawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 5000), GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + DrawningLocomotive != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
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;
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.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 ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningLocomotive? locomotive = null;
int counter = 100;
while (locomotive == null)
{
locomotive = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (locomotive == null)
{
return;
}
FormElectricLocomotive form = new()
{
SetLocomotive = locomotive
};
form.ShowDialog();
}
}

View File

@ -0,0 +1,123 @@
<?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>
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -11,7 +11,7 @@ namespace ProjectElectricLocomotive
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormElectricLocomotive());
Application.Run(new FormLocomotiveCollection());
}
}
}