From 7ae96abc1b8355ab1c9418da5bfbfcfd57d1bfde Mon Sep 17 00:00:00 2001 From: mar-va Date: Wed, 20 Mar 2024 17:32:36 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=963?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 69 +++++++ .../BusSharingService.cs | 56 ++++++ .../ICollectionGenericObjects.cs | 54 ++++++ .../MassiveGenericObjects.cs | 104 +++++++++++ .../FormAccordionBus.Designer.cs | 29 --- .../ProjectAccordionBus/FormAccordionBus.cs | 52 ++---- .../FormBusCollection.Designer.cs | 174 ++++++++++++++++++ .../ProjectAccordionBus/FormBusCollection.cs | 169 +++++++++++++++++ .../FormBusCollection.resx | 120 ++++++++++++ .../ProjectAccordionBus/Program.cs | 2 +- 10 files changed, 758 insertions(+), 71 deletions(-) create mode 100644 ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/BusSharingService.cs create mode 100644 ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.Designer.cs create mode 100644 ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.cs create mode 100644 ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.resx diff --git a/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/AbstractCompany.cs b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..3ae1230 --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,69 @@ +using ProjectAccordionBus.Drawnings; +using ProjectAccordionBus.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAccordionBus.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + protected readonly int _placeSizeWidth = 240; + + protected readonly int _placeSizeHeight = 60; + + protected readonly int _pictureWidth; + + protected readonly int _pictureHeight; + + protected ICollectionGenericObjects _collection = null; + + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + + public AbstractCompany(int picWidth, int picHeigth, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeigth; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + public static int operator +(AbstractCompany company, DrawningBus bus) + { + return company._collection.Insert(bus); + } + + public static DrawningBus operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + + public DrawningBus? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + DrawningBus? obj = _collection?.Get(i); + SetObjectPosition(i, _collection?.Count ?? 0, obj); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + protected abstract void DrawBackground(Graphics g); + + protected abstract void SetObjectPosition(int position, int MaxPos, DrawningBus? bus); +} diff --git a/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/BusSharingService.cs b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/BusSharingService.cs new file mode 100644 index 0000000..2672f5e --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/BusSharingService.cs @@ -0,0 +1,56 @@ +using ProjectAccordionBus.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAccordionBus.CollectionGenericObjects; + +public class BusSharingService : AbstractCompany +{ + public BusSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + + protected override void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + + protected override void SetObjectPosition(int position, int MaxPos, DrawningBus? bus) + { + int n = 0; + int m = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection?.Get(i) != null) + { + int x = 5 + _placeSizeWidth * n; + int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m; + + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(x, y); + } + + if (n < _pictureWidth / _placeSizeWidth) + n++; + else + { + n = 0; + m++; + } + } + } +} + diff --git a/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..961e5ac --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAccordionBus.CollectionGenericObjects; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Кол-во объектов в коллекци + /// + int Count { get; } + + /// + /// Установка максимального кол-ва объектов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллецию + /// + /// + /// + 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/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..f116585 --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAccordionBus.CollectionGenericObjects; + +/// +/// Параметризированный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Массив объектов которые храним + /// + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + if (position >= _collection.Length || position < 0) + { + return null; + } + return _collection[position]; + } + + public int Insert(T obj) + { + int index = 0; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + index++; + } + return -1; + } + + public int Insert(T obj, int position) + { + + if (position >= _collection.Length || position < 0) + return -1; + + + if (_collection[position] != null) + { + // проверка, что после вставляемого элемента в массиве есть пустой элемент + int nullIndex = -1; + for (int i = position + 1; i < Count; i++) + { + if (_collection[i] == null) + { + nullIndex = i; + break; + } + } + // Если пустого элемента нет, то выходим + if (nullIndex < 0) + { + return -1; + } + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + int j = nullIndex - 1; + while (j >= position) + { + _collection[j + 1] = _collection[j]; + j--; + } + } + _collection[position] = obj; + return position; + } + + public T? Remove(int position) + { + if (position >= _collection.Length || position < 0) + { + return null; + } + T temp = _collection[position]; + _collection[position] = null; + return temp; + } +} + diff --git a/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.Designer.cs b/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.Designer.cs index de70f29..6a8ea48 100644 --- a/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.Designer.cs +++ b/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.Designer.cs @@ -30,12 +30,10 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAccordionBus)); pictureBoxAccordionBus = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonUp = new Button(); buttonRight = new Button(); - buttonCreateBus = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAccordionBus).BeginInit(); @@ -51,17 +49,6 @@ pictureBoxAccordionBus.TabStop = false; pictureBoxAccordionBus.Click += pictureBoxAccordionBus_Click; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 351); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(188, 23); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать автобус-гармошку"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -110,17 +97,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateBus - // - buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBus.Location = new Point(218, 351); - buttonCreateBus.Name = "buttonCreateBus"; - buttonCreateBus.Size = new Size(138, 23); - buttonCreateBus.TabIndex = 6; - buttonCreateBus.Text = "Создать автобус"; - buttonCreateBus.UseVisualStyleBackColor = true; - buttonCreateBus.Click += buttonCreateBus_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -130,7 +106,6 @@ comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(121, 23); comboBoxStrategy.TabIndex = 7; - comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged; // // buttonStrategyStep // @@ -149,12 +124,10 @@ ClientSize = new Size(728, 386); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateBus); Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxAccordionBus); Name = "FormAccordionBus"; Text = "Сочленённый автобус"; @@ -170,12 +143,10 @@ #endregion private PictureBox pictureBoxAccordionBus; - private Button buttonCreate; private Button buttonLeft; private Button buttonDown; private Button buttonUp; private Button buttonRight; - private Button buttonCreateBus; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.cs b/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.cs index 74a57e6..4201be8 100644 --- a/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.cs +++ b/ProjectAccordionBus/ProjectAccordionBus/FormAccordionBus.cs @@ -19,6 +19,17 @@ public partial class FormAccordionBus : Form private AbstractStrategy? _strategy; + public DrawningBus SetBus + { + set + { + _drawningBus = value; + _drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormAccordionBus() { @@ -39,42 +50,6 @@ public partial class FormAccordionBus : Form pictureBoxAccordionBus.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningBus): - _drawningBus = new DrawningBus(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(DrawningAccordionBus): - _drawningBus = new DrawningAccordionBus(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; - } - - _drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); - _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - private void ButtonCreate_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningAccordionBus)); - } - - private void buttonCreateBus_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningBus)); - } - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningBus == null) @@ -143,11 +118,6 @@ public partial class FormAccordionBus : Form _strategy = null; } } - - private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) - { - - } } diff --git a/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.Designer.cs b/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.Designer.cs new file mode 100644 index 0000000..28da4c0 --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.Designer.cs @@ -0,0 +1,174 @@ +namespace ProjectAccordionBus +{ + partial class FormBusCollection + { + /// + /// 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(); + buttonDeleteBus = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAccordionBus = new Button(); + buttonAddBus = 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(buttonDeleteBus); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddAccordionBus); + groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(625, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(175, 450); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 393); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(163, 33); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 327); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(163, 33); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonDeleteBus + // + buttonDeleteBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDeleteBus.Location = new Point(6, 269); + buttonDeleteBus.Name = "buttonDeleteBus"; + buttonDeleteBus.Size = new Size(163, 33); + buttonDeleteBus.TabIndex = 5; + buttonDeleteBus.Text = "Удаление автобуса"; + buttonDeleteBus.UseVisualStyleBackColor = true; + buttonDeleteBus.Click += buttonDeleteBus_Click; + // + // maskedTextBox + // + maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(6, 219); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(163, 23); + maskedTextBox.TabIndex = 5; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddAccordionBus + // + buttonAddAccordionBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAccordionBus.Location = new Point(6, 141); + buttonAddAccordionBus.Name = "buttonAddAccordionBus"; + buttonAddAccordionBus.Size = new Size(163, 45); + buttonAddAccordionBus.TabIndex = 3; + buttonAddAccordionBus.Text = "Добавление автобуса-гармошки"; + buttonAddAccordionBus.UseVisualStyleBackColor = true; + buttonAddAccordionBus.Click += buttonAddAccordionBus_Click; + // + // buttonAddBus + // + buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBus.Location = new Point(6, 90); + buttonAddBus.Name = "buttonAddBus"; + buttonAddBus.Size = new Size(163, 45); + buttonAddBus.TabIndex = 2; + buttonAddBus.Text = "Добавление автобуса"; + buttonAddBus.UseVisualStyleBackColor = true; + buttonAddBus.Click += buttonAddBus_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(163, 23); + comboBoxSelectorCompany.TabIndex = 1; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(625, 450); + pictureBox.TabIndex = 4; + pictureBox.TabStop = false; + // + // FormBusCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBusCollection"; + Text = "Коллекция автобусов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddAccordionBus; + private Button buttonAddBus; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + private Button buttonDeleteBus; + private MaskedTextBox maskedTextBox; + } +} \ No newline at end of file diff --git a/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.cs b/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.cs new file mode 100644 index 0000000..d37c077 --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.cs @@ -0,0 +1,169 @@ +using ProjectAccordionBus.CollectionGenericObjects; +using ProjectAccordionBus.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 ProjectAccordionBus; + +/// +/// +/// +public partial class FormBusCollection : Form +{ + /// + /// + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormBusCollection() + { + InitializeComponent(); + } + /// + /// Добавление улучшенного троллейбуса + /// + /// + /// + private void ButtonAddAccordionBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAccordionBus)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создания объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningBus drawningBus; + switch (type) + { + case nameof(DrawningBus): + drawningBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningAccordionBus): + drawningBus = new DrawningAccordionBus(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 + drawningBus != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// Выбор цвета + /// + /// + /// + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + private void buttonAddBus_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningBus)); + } + + private void buttonAddAccordionBus_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningAccordionBus)); + } + + private void buttonDeleteBus_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + 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; + + DrawningBus? bus = null; + int counter = 100; + while (bus == null || counter > 0) + { + bus = _company.GetRandomObject(); + counter--; + } + + if (bus == null) return; + + FormAccordionBus form = new() + { + SetBus = bus + }; + form.ShowDialog(); + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } + + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new BusSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + +} diff --git a/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.resx b/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAccordionBus/ProjectAccordionBus/FormBusCollection.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/ProjectAccordionBus/ProjectAccordionBus/Program.cs b/ProjectAccordionBus/ProjectAccordionBus/Program.cs index 2eae234..c0b1625 100644 --- a/ProjectAccordionBus/ProjectAccordionBus/Program.cs +++ b/ProjectAccordionBus/ProjectAccordionBus/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAccordionBus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAccordionBus()); + Application.Run(new FormBusCollection()); } } } \ No newline at end of file