diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..7799623 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Diesellocomotive.Drawnings; + + +namespace Diesellocomotive.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию Локомотив +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 80; + + /// + /// Ширина окна + /// + 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, DrawningLocomotive locomotive) + { + return company._collection.Insert(locomotive); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningLocomotive operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningLocomotive? 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) + { + DrawningLocomotive? 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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs index 1c54643..ec2dbfa 100644 --- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Diesellocomotive.CollectionGenericObjects; -public interface ICollectionGenericObjects +public interface ICollectionGenericObjects where T : class { /// @@ -24,7 +24,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -32,14 +32,14 @@ public interface ICollectionGenericObjects /// Добавляемый объект /// Позиция /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj, int position); + int Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - bool Remove(int position); + T Remove(int position); /// /// Получение объекта по позиции diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/LocomotiveSharingService.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/LocomotiveSharingService.cs new file mode 100644 index 0000000..d835bd3 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/LocomotiveSharingService.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Diesellocomotive.Drawnings; +namespace Diesellocomotive.CollectionGenericObjects; +public class LocomotiveSharingService : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public LocomotiveSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + /// + /// прорисовка стоянки + /// + /// + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black, 3); + int posX = 0; + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + int posY = 0; + g.DrawLine(pen, posX, posY, posX, posY + _placeSizeHeight * (_pictureHeight / _placeSizeHeight)); + for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++) + { + g.DrawLine(pen, posX, posY, posX + _placeSizeWidth - 30, posY); + posY += _placeSizeHeight; + } + posX += _placeSizeWidth; + + } + } + + protected override void SetObjectsPosition() + { + int posX = 0; + int posY = _pictureHeight / _placeSizeHeight - 1; + for (int i = 0; i < _collection?.Count; i++) + { + if (_collection.Get(i) != null) + { + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(posX * _placeSizeWidth + 3, posY * _placeSizeHeight + 3); + } + posY--; + if (posY < 0) + { + posY = _pictureHeight / _placeSizeHeight - 1; + posX++; + } + if (posX >= _pictureWidth / _placeSizeWidth) { return; } + } + + } +} \ No newline at end of file diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs index 0d6cad4..96662e3 100644 --- a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs @@ -117,4 +117,4 @@ public class MassiveGenericObjects : ICollectionGenericObjects _collection[position] = null; return obj; } -} \ No newline at end of file +} diff --git a/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.Designer.cs b/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.Designer.cs index c124560..d0ca53d 100644 --- a/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.Designer.cs +++ b/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBox1Diesellocomotive = new PictureBox(); - buttonCreateDiesellocomotive = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); - buttonCreateLocomotive = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBox1Diesellocomotive).BeginInit(); @@ -51,18 +49,6 @@ pictureBox1Diesellocomotive.TabStop = false; pictureBox1Diesellocomotive.Click += pictureBox1Diesellocomotive_Click; // - // buttonCreateDiesellocomotive - // - buttonCreateDiesellocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateDiesellocomotive.Location = new Point(14, 334); - buttonCreateDiesellocomotive.Margin = new Padding(3, 4, 3, 4); - buttonCreateDiesellocomotive.Name = "buttonCreateDiesellocomotive"; - buttonCreateDiesellocomotive.Size = new Size(221, 31); - buttonCreateDiesellocomotive.TabIndex = 1; - buttonCreateDiesellocomotive.Text = "Создать Тепловоз с трубой"; - buttonCreateDiesellocomotive.UseVisualStyleBackColor = true; - buttonCreateDiesellocomotive.Click += buttonCreateDiesellocomotive_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -115,18 +101,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += buttonMove_Click; // - // buttonCreateLocomotive - // - buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateLocomotive.Location = new Point(241, 334); - buttonCreateLocomotive.Margin = new Padding(3, 4, 3, 4); - buttonCreateLocomotive.Name = "buttonCreateLocomotive"; - buttonCreateLocomotive.Size = new Size(221, 31); - buttonCreateLocomotive.TabIndex = 6; - buttonCreateLocomotive.Text = "Создать Тепловоз "; - buttonCreateLocomotive.UseVisualStyleBackColor = true; - buttonCreateLocomotive.Click += buttonCreateLocomotive_Click; - // // comboBoxStrategy // comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -156,12 +130,10 @@ ClientSize = new Size(834, 380); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateLocomotive); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreateDiesellocomotive); Controls.Add(pictureBox1Diesellocomotive); Margin = new Padding(3, 4, 3, 4); Name = "FormDiesellocomotive"; @@ -174,12 +146,10 @@ #endregion private PictureBox pictureBox1Diesellocomotive; - private Button buttonCreateDiesellocomotive; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private Button buttonDown; - private Button buttonCreateLocomotive; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.cs b/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.cs index dde076f..3c1b460 100644 --- a/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.cs +++ b/ProjectSportCar/ProjectSportCar/FormDiesellocomotive.cs @@ -25,6 +25,23 @@ public partial class FormDiesellocomotive : Form /// /// private AbstractStrategy? _strategy; + + /// + /// Получение объекта + /// + public DrawningLocomotive SetLocomotive + { + set + { + _drawningLocomotive = value; + _drawningLocomotive.SetPictureSize(pictureBox1Diesellocomotive.Width, pictureBox1Diesellocomotive.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + + /// /// конструктор формы /// @@ -55,54 +72,6 @@ public partial class FormDiesellocomotive : Form } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - 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(DrawningDiesellocomotive): - _drawningLocomotive = new DrawningDiesellocomotive(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(pictureBox1Diesellocomotive.Width, pictureBox1Diesellocomotive.Height); - _drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - - /// - /// Обработка нажатия кнопки "Создать Тепловоз с трубой" - /// - /// - /// - - private void buttonCreateDiesellocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDiesellocomotive)); - - - /// - /// Обработка нажатия кнопки "Создать тепловоз" - /// - /// - /// - private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive)); - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.Designer.cs b/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.Designer.cs new file mode 100644 index 0000000..5c5975d --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.Designer.cs @@ -0,0 +1,172 @@ +namespace Diesellocomotive +{ + partial class FormLocomotiveCollection + { + /// + /// 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(); + buttonRemoveLocomotive = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddDiesellocomotive = new Button(); + buttonAddLocomotive = 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(buttonRemoveLocomotive); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddDiesellocomotive); + groupBoxTools.Controls.Add(buttonAddLocomotive); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(782, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(231, 622); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 517); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(219, 45); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 392); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(219, 45); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonRemoveLocomotive + // + buttonRemoveLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveLocomotive.Location = new Point(6, 278); + buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; + buttonRemoveLocomotive.Size = new Size(219, 45); + buttonRemoveLocomotive.TabIndex = 4; + buttonRemoveLocomotive.Text = "Удалить Локомотив"; + buttonRemoveLocomotive.UseVisualStyleBackColor = true; + buttonRemoveLocomotive.Click += buttonRemoveLocomotive_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 245); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(219, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddDiesellocomotive + // + buttonAddDiesellocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddDiesellocomotive.Location = new Point(6, 166); + buttonAddDiesellocomotive.Name = "buttonAddDiesellocomotive"; + buttonAddDiesellocomotive.Size = new Size(219, 45); + buttonAddDiesellocomotive.TabIndex = 2; + buttonAddDiesellocomotive.Text = "Добавление Тепловоза"; + buttonAddDiesellocomotive.UseVisualStyleBackColor = true; + buttonAddDiesellocomotive.Click += buttonAddDiesellocomotive_Click; + // + // buttonAddLocomotive + // + buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddLocomotive.Location = new Point(6, 116); + buttonAddLocomotive.Name = "buttonAddLocomotive"; + buttonAddLocomotive.Size = new Size(219, 44); + 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, 26); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(219, 28); + comboBoxSelectorCompany.TabIndex = 0; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(782, 622); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormLocomotiveCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1013, 622); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormLocomotiveCollection"; + Text = "Коллекция Локомотивов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddDiesellocomotive; + private Button buttonAddLocomotive; + private ComboBox comboBoxSelectorCompany; + private Button buttonRefresh; + private Button buttonGoToCheck; + private Button buttonRemoveLocomotive; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + } +} \ No newline at end of file diff --git a/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.cs b/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.cs new file mode 100644 index 0000000..388a6b1 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.cs @@ -0,0 +1,196 @@ +using Diesellocomotive.CollectionGenericObjects; +using Diesellocomotive.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 Diesellocomotive; + +/// +/// +/// +public partial class FormLocomotiveCollection : Form +{ + /// + /// + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormLocomotiveCollection() + { + InitializeComponent(); + } + + /// + /// + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new LocomotiveSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + // + /// Добавление Локомотива + /// + /// + /// + private void buttonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive)); + + /// + /// Добавление Монорельса + /// + /// + /// + private void buttonAddDiesellocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDiesellocomotive)); + + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + DrawningLocomotive drawningLocomotive; + Random random = new(); + switch (type) + { + case nameof(DrawningLocomotive): + drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningDiesellocomotive): + // TODO выбор цветов + drawningLocomotive = new DrawningDiesellocomotive(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 + drawningLocomotive != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + 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 buttonRemoveLocomotive_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; + } + + DrawningLocomotive? locomotive = null; + int counter = 100; + while (locomotive == null) + { + locomotive = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (locomotive == null) + { + return; + } + + FormDiesellocomotive form = new() + { + SetLocomotive = locomotive + }; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.resx b/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormLocomotiveCollection.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