200 lines
5.6 KiB
C#
200 lines
5.6 KiB
C#
using ProjectHoistingCrane.CollectionGenericObjects;
|
||
using ProjectHoistingCrane.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 ProjectHoistingCrane;
|
||
|
||
/// <summary>
|
||
/// Форма работы с компанией и её коллекцией
|
||
/// </summary>
|
||
public partial class FormCraneCollection : Form
|
||
{
|
||
/// <summary>
|
||
/// Компания
|
||
/// </summary>
|
||
private AbstractCompany? _company = null;
|
||
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormCraneCollection()
|
||
{
|
||
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 CraneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningCrane>());
|
||
break;
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Добавление обычного крана
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonAddCrane_Click(object sender, EventArgs e)
|
||
{
|
||
CreateObject(nameof(DrawningCrane));
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Добавление подъёмного крана
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e)
|
||
{
|
||
CreateObject(nameof(DrawningHoistingCrane));
|
||
}
|
||
|
||
/// <summary>
|
||
/// Создание объекта класса-перемещения
|
||
/// </summary>
|
||
/// <param name="type">Тип создаваемого объекта</param>
|
||
private void CreateObject(string type)
|
||
{
|
||
if (_company == null)
|
||
{
|
||
return;
|
||
}
|
||
Random random = new();
|
||
DrawningCrane drawningCrane;
|
||
switch (type)
|
||
{
|
||
case nameof(DrawningCrane):
|
||
drawningCrane = new DrawningCrane(random.Next(100, 300),
|
||
random.Next(1000, 3000), GetColor(random));
|
||
break;
|
||
case nameof(DrawningHoistingCrane):
|
||
// TODO вызов диалогового окна для выбора цвета
|
||
drawningCrane = new DrawningHoistingCrane(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 + drawningCrane > -1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBox.Image = _company.Show();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
|
||
/// <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 ButtonRemoveCrane_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);
|
||
if (_company - pos != null)
|
||
{
|
||
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;
|
||
}
|
||
DrawningCrane? crane = null;
|
||
int counter = 100;
|
||
while (crane == null)
|
||
{
|
||
crane = _company.GetRandomObject();
|
||
counter--;
|
||
if (counter <= 0)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
if (crane == null)
|
||
{
|
||
return;
|
||
}
|
||
FormHoistingCrane form = new()
|
||
{
|
||
SetCar = crane
|
||
};
|
||
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();
|
||
}
|
||
}
|