From 667584047e27dab426ef47ff0e85ef551fdd924e Mon Sep 17 00:00:00 2001 From: Anya Date: Thu, 18 Apr 2024 15:06:42 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICollectionGenericObjects.cs | 57 ++++++++ .../MassiveGenericObjects.cs | 135 ++++++++++++++++++ 2 files changed, 192 insertions(+) create mode 100644 lab_0/CollectionGenericObject/ICollectionGenericObjects.cs create mode 100644 lab_0/CollectionGenericObject/MassiveGenericObjects.cs diff --git a/lab_0/CollectionGenericObject/ICollectionGenericObjects.cs b/lab_0/CollectionGenericObject/ICollectionGenericObjects.cs new file mode 100644 index 0000000..1c57f2c --- /dev/null +++ b/lab_0/CollectionGenericObject/ICollectionGenericObjects.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBus.CollectionGenericObject; + + /// + /// Интерфейс описания действий для набора хранимых объектов + /// + /// Параметр: ограничение - ссылочный тип + public interface ICollectionGenericObjects + where T : class + { + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + T? Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); + } + + + diff --git a/lab_0/CollectionGenericObject/MassiveGenericObjects.cs b/lab_0/CollectionGenericObject/MassiveGenericObjects.cs new file mode 100644 index 0000000..23552a8 --- /dev/null +++ b/lab_0/CollectionGenericObject/MassiveGenericObjects.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBus.CollectionGenericObject; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип + public class MassiveGenericObjects : ICollectionGenericObjects + where T : class + { + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } + + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + + public T? Get(int position) + { + if (position >= 0 && position < Count) + { + return _collection[position]; + } + + return null; + } + + public int Insert(T obj) + { + // вставка в свободное место набора + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + + return -1; + } + + public int Insert(T obj, int position) + { + // проверка позиции + if (position < 0 || position >= Count) + { + return -1; + } + + // проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой позиции и идет вставка туда если нет после, ищем до + if (_collection[position] != null) + { + bool pushed = false; + for (int index = position + 1; index < Count; index++) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + + if (!pushed) + { + for (int index = position - 1; index >= 0; index--) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + } + + if (!pushed) + { + return position; + } + } + + // вставка + _collection[position] = obj; + return position; + } + + public T? Remove(int position) + { + // проверка позиции + if (position < 0 || position >= Count) + { + return null; + } + + if (_collection[position] == null) return null; + + T? temp = _collection[position]; + _collection[position] = null; + return temp; + } + } + -- 2.25.1 From 337e0ba5f6e4fc1ebfb7d16a6e443b80bdc67a4f Mon Sep 17 00:00:00 2001 From: Anya Date: Thu, 25 Apr 2024 10:17:26 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=BB=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=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 116 +++++++++++ lab_0/CollectionGenericObject/BusStation.cs | 56 ++++++ lab_0/FormBus.Designer.cs | 28 --- lab_0/FormBus.cs | 62 ++---- lab_0/FormSimpleBusCollection.Designer.cs | 174 +++++++++++++++++ lab_0/FormSimpleBusCollection.cs | 182 ++++++++++++++++++ lab_0/FormSimpleBusCollection.resx | 120 ++++++++++++ lab_0/Program.cs | 2 +- 8 files changed, 666 insertions(+), 74 deletions(-) create mode 100644 lab_0/CollectionGenericObject/AbstractCompany.cs create mode 100644 lab_0/CollectionGenericObject/BusStation.cs create mode 100644 lab_0/FormSimpleBusCollection.Designer.cs create mode 100644 lab_0/FormSimpleBusCollection.cs create mode 100644 lab_0/FormSimpleBusCollection.resx diff --git a/lab_0/CollectionGenericObject/AbstractCompany.cs b/lab_0/CollectionGenericObject/AbstractCompany.cs new file mode 100644 index 0000000..025fa32 --- /dev/null +++ b/lab_0/CollectionGenericObject/AbstractCompany.cs @@ -0,0 +1,116 @@ +using ProjectBus.Drawnings; + +namespace ProjectBus.CollectionGenericObject; +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 400; + + /// + /// Размер места (высота) + /// + 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, DrawningSimpleBus simplebus) + { + return company._collection.Insert(simplebus); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningSimpleBus? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningSimpleBus? 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) + { + DrawningSimpleBus? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} + diff --git a/lab_0/CollectionGenericObject/BusStation.cs b/lab_0/CollectionGenericObject/BusStation.cs new file mode 100644 index 0000000..ddc7084 --- /dev/null +++ b/lab_0/CollectionGenericObject/BusStation.cs @@ -0,0 +1,56 @@ +using ProjectBus.Drawnings; +using ProjectBus.Entities; +using System; + +namespace ProjectBus.CollectionGenericObject; +/// +/// Реализация абстрактной компании - аренда поезда +/// +public class BusStation : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public BusStation(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j)); + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1))); + } + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight))); + } + + + } + + protected override void SetObjectsPosition() + { + int n = 0; + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + DrawningSimpleBus? drawningSimpleBus = _collection?.Get(n); + n++; + if (drawningSimpleBus != null) + { + drawningSimpleBus.SetPictureSize(_pictureWidth, _pictureHeight); + drawningSimpleBus.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); + } + } + } + } +} + + diff --git a/lab_0/FormBus.Designer.cs b/lab_0/FormBus.Designer.cs index cdcb98c..d4e6261 100644 --- a/lab_0/FormBus.Designer.cs +++ b/lab_0/FormBus.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxBus = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); - buttonCreateSimpleBus = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBus).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxBus.TabIndex = 7; pictureBoxBus.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 501); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(410, 46); - buttonCreate.TabIndex = 2; - buttonCreate.Text = "Создать автобус с доп.отсеком"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonCreateSimpleBus - // - buttonCreateSimpleBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateSimpleBus.Location = new Point(428, 501); - buttonCreateSimpleBus.Name = "buttonCreateSimpleBus"; - buttonCreateSimpleBus.Size = new Size(431, 46); - buttonCreateSimpleBus.TabIndex = 8; - buttonCreateSimpleBus.Text = "Создать обычный автобус"; - buttonCreateSimpleBus.UseVisualStyleBackColor = true; - buttonCreateSimpleBus.Click += buttonCreateSimpleBus_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(1155, 557); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateSimpleBus); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxBus); Name = "FormBus"; Text = "Автобус"; @@ -161,12 +135,10 @@ #endregion private PictureBox pictureBoxBus; - private Button buttonCreate; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private Button buttonDown; - private Button buttonCreateSimpleBus; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/lab_0/FormBus.cs b/lab_0/FormBus.cs index f63567b..d2c49c5 100644 --- a/lab_0/FormBus.cs +++ b/lab_0/FormBus.cs @@ -26,6 +26,22 @@ public partial class FormBus : Form /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawningSimpleBus SetSimpleBus + { + set + { + _drawningSimpleBus = value; + _drawningSimpleBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + + /// /// конструктор формы @@ -52,51 +68,6 @@ public partial class FormBus : Form pictureBoxBus.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningSimpleBus): - _drawningSimpleBus = new DrawningSimpleBus(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(DrawningBus): - _drawningSimpleBus = new DrawningBus(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; - } - - _drawningSimpleBus.SetPictureSize(pictureBoxBus.Width, pictureBoxBus.Height); - _drawningSimpleBus.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(DrawningBus)); - - /// - /// Обработка нажатия кнопки "Создать обычный автобус" - /// - /// - /// - private void buttonCreateSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus)); - private void ButtonMove_Click(object sender, EventArgs e) @@ -179,3 +150,4 @@ public partial class FormBus : Form } + diff --git a/lab_0/FormSimpleBusCollection.Designer.cs b/lab_0/FormSimpleBusCollection.Designer.cs new file mode 100644 index 0000000..4d5aa9f --- /dev/null +++ b/lab_0/FormSimpleBusCollection.Designer.cs @@ -0,0 +1,174 @@ +namespace ProjectBus +{ + partial class FormSimpleBusCollection + { + /// + /// 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(); + buttonDelBus = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddBus = new Button(); + buttonAddSimpleBus = 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(buttonDelBus); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(buttonAddSimpleBus); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(1063, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(333, 962); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 731); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(315, 84); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click_1; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 565); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(315, 84); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click_1; + // + // buttonDelBus + // + buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBus.Location = new Point(6, 416); + buttonDelBus.Name = "buttonDelBus"; + buttonDelBus.Size = new Size(315, 84); + buttonDelBus.TabIndex = 5; + buttonDelBus.Text = "Удалить автобус"; + buttonDelBus.UseVisualStyleBackColor = true; + buttonDelBus.Click += ButtonDelBus_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 355); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(315, 39); + maskedTextBox.TabIndex = 4; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddBus + // + buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBus.Location = new Point(6, 225); + buttonAddBus.Name = "buttonAddBus"; + buttonAddBus.Size = new Size(315, 84); + buttonAddBus.TabIndex = 2; + buttonAddBus.Text = "Добавление автобуса с доп. отсеком"; + buttonAddBus.UseVisualStyleBackColor = true; + buttonAddBus.Click += ButtonAddBus_Click; + // + // buttonAddSimpleBus + // + buttonAddSimpleBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddSimpleBus.Location = new Point(6, 118); + buttonAddSimpleBus.Name = "buttonAddSimpleBus"; + buttonAddSimpleBus.Size = new Size(315, 84); + buttonAddSimpleBus.TabIndex = 1; + buttonAddSimpleBus.Text = "Добавление автобуса"; + buttonAddSimpleBus.UseVisualStyleBackColor = true; + buttonAddSimpleBus.Click += ButtonAddSimpleBus_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, 47); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(315, 40); + 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(1063, 962); + pictureBox.TabIndex = 3; + pictureBox.TabStop = false; + // + // FormSimpleBusCollection + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1396, 962); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormSimpleBusCollection"; + Text = "Коллекция автобусов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddBus; + private Button buttonAddSimpleBus; + private Button buttonDelBus; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/lab_0/FormSimpleBusCollection.cs b/lab_0/FormSimpleBusCollection.cs new file mode 100644 index 0000000..0c52296 --- /dev/null +++ b/lab_0/FormSimpleBusCollection.cs @@ -0,0 +1,182 @@ +using ProjectBus.MovementStrategy; +using ProjectBus.Drawnings; +using ProjectBus.CollectionGenericObject; + +namespace ProjectBus; + +public partial class FormSimpleBusCollection : Form +{ + private AbstractCompany? _company = null; + public FormSimpleBusCollection() + { + InitializeComponent(); + } + + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "хранилище": + _company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + private void ButtonAddSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus)); + + /// + /// Добавление спортивного автомобиля + /// + /// + /// + private void ButtonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + + + /// + /// Удаление объекта + /// + /// + /// + + + /// + /// Передача объекта в другую форму + /// + /// + /// + + + /// + /// Перерисовка коллекции + /// + /// + /// + + + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningSimpleBus drawningSimpleBus; + switch (type) + { + case nameof(DrawningSimpleBus): + drawningSimpleBus = new DrawningSimpleBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningBus): + // вызов диалогового окна для выбора цвета + drawningSimpleBus = new DrawningBus(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 + drawningSimpleBus != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + _ = MessageBox.Show(drawningSimpleBus.ToString()); + } + } + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + + private void ButtonDelBus_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 ButtonRefresh_Click_1(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + + } + + private void ButtonGoToCheck_Click_1(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningSimpleBus? simplebus = null; + int counter = 100; + while (simplebus == null) + { + simplebus = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (simplebus == null) + { + return; + } + + FormBus form = new() + { + SetSimpleBus = simplebus + }; + form.ShowDialog(); + + } +} + diff --git a/lab_0/FormSimpleBusCollection.resx b/lab_0/FormSimpleBusCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/lab_0/FormSimpleBusCollection.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/lab_0/Program.cs b/lab_0/Program.cs index 919414c..beb3124 100644 --- a/lab_0/Program.cs +++ b/lab_0/Program.cs @@ -13,7 +13,7 @@ namespace lab_0 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormBus()); + Application.Run(new FormSimpleBusCollection()); } } } \ No newline at end of file -- 2.25.1 From aae38b1efd5b123691e03a303964b72de5562c71 Mon Sep 17 00:00:00 2001 From: Anya Date: Thu, 25 Apr 2024 11:24:03 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=BB=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=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab_0/CollectionGenericObject/MassiveGenericObjects.cs | 1 + lab_0/FormSimpleBusCollection.Designer.cs | 2 +- lab_0/FormSimpleBusCollection.cs | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lab_0/CollectionGenericObject/MassiveGenericObjects.cs b/lab_0/CollectionGenericObject/MassiveGenericObjects.cs index 23552a8..9b4ee88 100644 --- a/lab_0/CollectionGenericObject/MassiveGenericObjects.cs +++ b/lab_0/CollectionGenericObject/MassiveGenericObjects.cs @@ -12,6 +12,7 @@ namespace ProjectBus.CollectionGenericObject; /// Параметр: ограничение - ссылочный тип public class MassiveGenericObjects : ICollectionGenericObjects where T : class + { /// /// Массив объектов, которые храним diff --git a/lab_0/FormSimpleBusCollection.Designer.cs b/lab_0/FormSimpleBusCollection.Designer.cs index 4d5aa9f..90730ea 100644 --- a/lab_0/FormSimpleBusCollection.Designer.cs +++ b/lab_0/FormSimpleBusCollection.Designer.cs @@ -89,7 +89,7 @@ buttonDelBus.TabIndex = 5; buttonDelBus.Text = "Удалить автобус"; buttonDelBus.UseVisualStyleBackColor = true; - buttonDelBus.Click += ButtonDelBus_Click; + // // maskedTextBox // diff --git a/lab_0/FormSimpleBusCollection.cs b/lab_0/FormSimpleBusCollection.cs index 0c52296..31552a4 100644 --- a/lab_0/FormSimpleBusCollection.cs +++ b/lab_0/FormSimpleBusCollection.cs @@ -111,7 +111,7 @@ public partial class FormSimpleBusCollection : Form } - private void ButtonDelBus_Click(object sender, EventArgs e) + private void ButtonDelBus_Click_1(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { -- 2.25.1