2024-03-13 19:49:07 +04:00
|
|
|
|
using ProjectElectroTrans.CollectionGenericObjects;
|
|
|
|
|
using ProjectElectroTrans.Drawnings;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ProjectElectroTrans;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormTransCollection : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormTransCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new TransDepoService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingTrans>());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление обычного автомобиля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTrans));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление спортивного автомобиля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddElectroTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingElectroTrans));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание объекта класса-перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">Тип создаваемого объекта</param>
|
|
|
|
|
private void CreateObject(string type)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Random random = new();
|
|
|
|
|
DrawingTrans drawingTrans;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(DrawingTrans):
|
|
|
|
|
drawingTrans = new DrawingTrans(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
|
|
|
|
break;
|
|
|
|
|
case nameof(DrawingElectroTrans):
|
2024-03-14 09:42:38 +04:00
|
|
|
|
// вызов диалогового окна для выбора цвета
|
2024-03-13 19:49:07 +04:00
|
|
|
|
drawingTrans = new DrawingElectroTrans(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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 09:42:38 +04:00
|
|
|
|
if (_company + drawingTrans != -1)
|
2024-03-13 19:49:07 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_ = MessageBox.Show(drawingTrans.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение цвета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="random">Генератор случайных чисел</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRemoveTrans_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
2024-03-14 09:42:38 +04:00
|
|
|
|
if (_company - pos != null)
|
2024-03-13 19:49:07 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача объекта в другую форму
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawingTrans? car = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (car == null)
|
|
|
|
|
{
|
|
|
|
|
car = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (car == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormElectroTrans form = new()
|
|
|
|
|
{
|
|
|
|
|
SetCar = car
|
|
|
|
|
};
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перерисовка коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|