PIbd-14_Rachek_A.S._Base/lab_0/FormSimpleBusCollection.cs

183 lines
4.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<DrawningSimpleBus>());
break;
}
}
private void ButtonAddSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus));
/// <summary>
/// Добавление спортивного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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_1(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();
}
}