2024-04-25 10:17:26 +04:00
|
|
|
|
using ProjectBus.MovementStrategy;
|
|
|
|
|
using ProjectBus.Drawnings;
|
|
|
|
|
using ProjectBus.CollectionGenericObject;
|
|
|
|
|
|
|
|
|
|
namespace ProjectBus;
|
|
|
|
|
|
|
|
|
|
public partial class FormSimpleBusCollection : Form
|
|
|
|
|
{
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Хранилише коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StorageCollection<DrawningSimpleBus> _storageCollection;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
2024-04-25 10:17:26 +04:00
|
|
|
|
private AbstractCompany? _company = null;
|
2024-05-20 14:22:37 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
2024-04-25 10:17:26 +04:00
|
|
|
|
public FormSimpleBusCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-20 14:22:37 +04:00
|
|
|
|
_storageCollection = new();
|
2024-04-25 10:17:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-04-25 10:17:26 +04:00
|
|
|
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "хранилище":
|
|
|
|
|
_company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningSimpleBus>());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// <summary>
|
2024-05-22 22:22:59 +04:00
|
|
|
|
/// Добавление автобуса
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-05-22 22:22:59 +04:00
|
|
|
|
private void ButtonAddSimpleBus_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FormSimpleBusConfig form = new();
|
|
|
|
|
form.Show();
|
|
|
|
|
form.AddEvent(SetSimpleBus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetSimpleBus(DrawningSimpleBus? drawningSimpleBus)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null || drawningSimpleBus == null) return;
|
|
|
|
|
drawningSimpleBus.SetPictureSize(pictureBox.Width, pictureBox.Height);
|
|
|
|
|
|
|
|
|
|
if (_company + drawningSimpleBus != -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект не удалось добавить");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-25 10:17:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание объекта класса-перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">Тип создаваемого объекта</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());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-20 14:22:37 +04:00
|
|
|
|
|
2024-05-22 22:22:59 +04:00
|
|
|
|
private Color GetColor(Random random)
|
2024-04-25 10:17:26 +04:00
|
|
|
|
{
|
2024-05-22 22:22:59 +04:00
|
|
|
|
throw new NotImplementedException();
|
2024-04-25 10:17:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 22:22:59 +04:00
|
|
|
|
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonDelBus_Click(object sender, EventArgs e)
|
2024-04-25 10:17:26 +04:00
|
|
|
|
{
|
|
|
|
|
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("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перерисовка коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
2024-04-25 10:17:26 +04:00
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 14:22:37 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача объекта в другую форму
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
2024-04-25 10:17:26 +04:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-20 14:22:37 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCollectionAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CollectionType collectionType = CollectionType.None;
|
|
|
|
|
if (radioButtonMassive.Checked)
|
|
|
|
|
{
|
|
|
|
|
collectionType = CollectionType.Massive;
|
|
|
|
|
}
|
|
|
|
|
else if (radioButtonList.Checked)
|
|
|
|
|
{
|
|
|
|
|
collectionType = CollectionType.List;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCollectionDel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не выбрана");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновление списка в listBoxCollection
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void RerfreshListBoxItems()
|
|
|
|
|
{
|
|
|
|
|
listBoxCollection.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
string? colName = _storageCollection.Keys?[i];
|
|
|
|
|
if (!string.IsNullOrEmpty(colName))
|
|
|
|
|
{
|
|
|
|
|
listBoxCollection.Items.Add(colName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCreateCompany_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не выбрана");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ICollectionGenericObjects<DrawningSimpleBus>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "хранилище":
|
|
|
|
|
_company = new BusStation(pictureBox.Width, pictureBox.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
}
|
2024-04-25 10:17:26 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 14:22:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|