diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..2d66485 --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,113 @@ +using WinFormsAppExcavator.Drawings; + +namespace WinFormsAppExcavator.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 90; + + /// + /// Ширина окна + /// + 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, DrawingExcavatorEmpty excavator) + { + return company._collection.Insert(excavator); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawingExcavatorEmpty operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawingExcavatorEmpty? 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) + { + DrawingExcavatorEmpty? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ExcavatorSharingServise.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ExcavatorSharingServise.cs new file mode 100644 index 0000000..e21a92d --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ExcavatorSharingServise.cs @@ -0,0 +1,63 @@ +using WinFormsAppExcavator.Drawings; + +namespace WinFormsAppExcavator.CollectionGenericObjects; +public class ExcavatorSharingServise : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public ExcavatorSharingServise(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + /// + /// прорисовка стоянки + /// + /// + protected override void DrawBackgound(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + Pen pen = new(Color.Black, 3); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 15, j * _placeSizeHeight); + } + } + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = width - 1; + int curHeight = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection.Get(i) != null) + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 2); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } + + } +} diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs index 5d2db32..dc9e69e 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -22,7 +22,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -30,14 +30,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/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/MassiveGenericObjects.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/MassiveGenericObjects.cs index bcab8ba..1a33a4b 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/MassiveGenericObjects.cs @@ -41,29 +41,73 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { // TODO проверка позиции + if (position >= _collection.Length || position < 0) + { return null; } return _collection[position]; } - public bool Insert(T obj) + public int Insert(T obj) { // TODO вставка в свободное место набора - return false; + int index = 0; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + + index++; + } + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то // ищется свободное место после этой позиции и идет вставка туда // если нет после, ищем до // TODO вставка - return false; + if (position >= _collection.Length || position < 0) + { return -1; } + + if (_collection[position]==null) + { + _collection[position] = obj; + return position; + } + int index; + + for (index=position+1; index<_collection.Length; ++index) + { + if (_collection[index]==null) + { + _collection[position] = obj; + return position; + } + } + + for (index = position-1; index>=0; --index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + return -1; } - public bool Remove(int position) + public T Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null - return true; + if (position >= _collection.Length || position < 0) + { return null; } + T obj = _collection[position]; + _collection[position] = null; + return obj; } } diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.Designer.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.Designer.cs index 9858944..56b778d 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.Designer.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.Designer.cs @@ -30,12 +30,10 @@ namespace WinFormsAppExcavator private void InitializeComponent() { pictureBoxExcavator = new PictureBox(); - buttonCreat = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonDown = new Button(); buttonUp = new Button(); - CreateExcavatorEmpty = new Button(); buttonStrategyStep = new Button(); comboBoxStrategy = new ComboBox(); ((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit(); @@ -50,17 +48,6 @@ namespace WinFormsAppExcavator pictureBoxExcavator.TabIndex = 0; pictureBoxExcavator.TabStop = false; // - // buttonCreat - // - buttonCreat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreat.Location = new Point(12, 288); - buttonCreat.Name = "buttonCreat"; - buttonCreat.Size = new Size(192, 29); - buttonCreat.TabIndex = 1; - buttonCreat.Text = "Создать Экскаватор"; - buttonCreat.UseVisualStyleBackColor = true; - buttonCreat.Click += ButtonCreat_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -109,17 +96,6 @@ namespace WinFormsAppExcavator buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // CreateExcavatorEmpty - // - CreateExcavatorEmpty.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - CreateExcavatorEmpty.Location = new Point(224, 288); - CreateExcavatorEmpty.Name = "CreateExcavatorEmpty"; - CreateExcavatorEmpty.Size = new Size(227, 29); - CreateExcavatorEmpty.TabIndex = 6; - CreateExcavatorEmpty.Text = "Создать Экскаватор простой"; - CreateExcavatorEmpty.UseVisualStyleBackColor = true; - CreateExcavatorEmpty.Click += CreateExcavatorEmpty_Click; - // // buttonStrategyStep // buttonStrategyStep.Location = new Point(792, 48); @@ -147,12 +123,10 @@ namespace WinFormsAppExcavator ClientSize = new Size(898, 329); Controls.Add(comboBoxStrategy); Controls.Add(buttonStrategyStep); - Controls.Add(CreateExcavatorEmpty); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreat); Controls.Add(pictureBoxExcavator); Name = "FormExcavator"; Text = "Экскаватор"; @@ -167,8 +141,6 @@ namespace WinFormsAppExcavator private Button buttonRight; private Button buttonDown; private Button buttonUp; - public Button buttonCreat; - public Button CreateExcavatorEmpty; private Button buttonStrategyStep; private ComboBox comboBoxStrategy; } diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.cs index 2ce12f8..14d66c7 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavator.cs @@ -1,5 +1,4 @@ -using System; -using WinFormsAppExcavator.Drawings; +using WinFormsAppExcavator.Drawings; using WinFormsAppExcavator.MovementStrategy; namespace WinFormsAppExcavator @@ -20,6 +19,21 @@ namespace WinFormsAppExcavator /// private AbstractStrategy? _strategy; + /// + /// получение объекта + /// + public DrawingExcavatorEmpty SetExcavator + { + set + { + _drawingExcavatorEmpty = value; + _drawingExcavatorEmpty.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -47,59 +61,6 @@ namespace WinFormsAppExcavator } - /// - ///создание объекта класса перемещения - /// - - private void CreateObject(String type) - { - Random random = new(); - switch (type) - { - case nameof(DrawingExcavatorEmpty): - _drawingExcavatorEmpty = new DrawingExcavatorEmpty(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(DrawingExcavator): - _drawingExcavatorEmpty = new DrawingExcavator(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)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - - _drawingExcavatorEmpty.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height); - _drawingExcavatorEmpty.SetPosition(random.Next(10, 100), random.Next(10, 100)); - - _strategy = null; - comboBoxStrategy.Enabled = true; - - Draw(); - } - - /// - /// обработка кнопки создать экскаватор - /// - /// - /// - private void ButtonCreat_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingExcavator)); - } - - - /// - /// обработка кнопки создать без дополнений - /// - /// - /// - private void CreateExcavatorEmpty_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingExcavatorEmpty)); - } - /// /// перемещение объекта /// diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs new file mode 100644 index 0000000..e9ed37f --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace WinFormsAppExcavator +{ + partial class FormExcavatorCollection + { + /// + /// 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(); + buttonRemoveExcavator = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddExcavator = new Button(); + buttonAddExcavatorEmpty = 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(buttonRemoveExcavator); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddExcavator); + groupBoxTools.Controls.Add(buttonAddExcavatorEmpty); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(722, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(220, 555); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 476); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(208, 53); + 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, 306); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(208, 53); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Отправление на тест"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveExcavator + // + buttonRemoveExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveExcavator.Location = new Point(6, 247); + buttonRemoveExcavator.Name = "buttonRemoveExcavator"; + buttonRemoveExcavator.Size = new Size(208, 53); + buttonRemoveExcavator.TabIndex = 4; + buttonRemoveExcavator.Text = "Удаление экскаватора"; + buttonRemoveExcavator.UseVisualStyleBackColor = true; + buttonRemoveExcavator.Click += ButtonRemoveExcavator_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(12, 203); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(208, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddExcavator + // + buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddExcavator.Location = new Point(6, 134); + buttonAddExcavator.Name = "buttonAddExcavator"; + buttonAddExcavator.Size = new Size(208, 53); + buttonAddExcavator.TabIndex = 2; + buttonAddExcavator.Text = "Добавление экскаватора"; + buttonAddExcavator.UseVisualStyleBackColor = true; + buttonAddExcavator.Click += ButtonAddExcavator_Click; + // + // buttonAddExcavatorEmpty + // + buttonAddExcavatorEmpty.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddExcavatorEmpty.Location = new Point(6, 75); + buttonAddExcavatorEmpty.Name = "buttonAddExcavatorEmpty"; + buttonAddExcavatorEmpty.Size = new Size(208, 53); + buttonAddExcavatorEmpty.TabIndex = 1; + buttonAddExcavatorEmpty.Text = "Добавление экскаватора простого"; + buttonAddExcavatorEmpty.UseVisualStyleBackColor = true; + buttonAddExcavatorEmpty.Click += ButtonAddExcavatorEmpty_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(208, 28); + 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(722, 555); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormExcavatorCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(942, 555); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormExcavatorCollection"; + Text = "Коллекция экскаваторов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddExcavator; + private Button buttonAddExcavatorEmpty; + private Button buttonRemoveExcavator; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs new file mode 100644 index 0000000..8d94319 --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs @@ -0,0 +1,175 @@ +using WinFormsAppExcavator.CollectionGenericObjects; +using WinFormsAppExcavator.Drawings; + +namespace WinFormsAppExcavator; + +public partial class FormExcavatorCollection : Form +{ + /// + /// компания + /// + AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormExcavatorCollection() + { + InitializeComponent(); + } + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new ExcavatorSharingServise(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Добавление обычного экскаватора + /// + /// + /// + private void ButtonAddExcavatorEmpty_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingExcavatorEmpty)); + + /// + /// Добавление полного экскаватора + /// + /// + /// + private void ButtonAddExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingExcavator)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawingExcavatorEmpty drawningExcavatorEmpty; + switch (type) + { + case nameof(DrawingExcavatorEmpty): + drawningExcavatorEmpty = new DrawingExcavatorEmpty(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawingExcavator): + // TODO вызов диалогового окна для выбора цвета + drawningExcavatorEmpty = new DrawingExcavator(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawningExcavatorEmpty != -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 ButtonRemoveExcavator_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; + } + + DrawingExcavatorEmpty? excavator = null; + int counter = 100; + while (excavator == null) + { + excavator = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (excavator == null) + { + return; + } + + FormExcavator form = new() + { + SetExcavator = excavator + }; + form.ShowDialog(); + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.resx b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.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/WinFormsAppExcavator/WinFormsAppExcavator/Program.cs b/WinFormsAppExcavator/WinFormsAppExcavator/Program.cs index 9552f97..5dfa1c0 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/Program.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/Program.cs @@ -11,7 +11,7 @@ // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormExcavator()); + Application.Run(new FormExcavatorCollection()); } } } \ No newline at end of file