2024-03-14 14:26:53 +04:00
|
|
|
|
using ProjectElectricLocomotive.CollectionGenericObjects;
|
|
|
|
|
using ProjectElectricLocomotive.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 ProjectElectricLocomotive;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormLocomotiveCollection : Form
|
|
|
|
|
{
|
2024-03-28 09:57:08 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Хранилище коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StorageCollection<DrawningLocomotive> _storageCollection;
|
|
|
|
|
|
2024-03-14 14:26:53 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormLocomotiveCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-03-28 09:57:08 +04:00
|
|
|
|
_storageCollection = new();
|
2024-03-14 14:26:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-03-28 09:57:08 +04:00
|
|
|
|
panelCompanyTools.Enabled = false;
|
2024-03-14 14:26:53 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание объекта класса-перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
private void CreateObject(string type)
|
|
|
|
|
{
|
|
|
|
|
Random random = new();
|
|
|
|
|
DrawningLocomotive drawningLocomotive;
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case nameof(DrawningLocomotive):
|
|
|
|
|
drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
|
|
|
|
GetColor(random));
|
2024-03-28 09:57:08 +04:00
|
|
|
|
|
2024-03-14 14:26:53 +04:00
|
|
|
|
break;
|
|
|
|
|
case nameof(DrawningElectricLocomotive):
|
|
|
|
|
drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000),
|
|
|
|
|
GetColor(random), GetColor(random),
|
|
|
|
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
2024-03-28 09:57:08 +04:00
|
|
|
|
|
2024-03-14 14:26:53 +04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-28 08:25:13 +04:00
|
|
|
|
if (_company + drawningLocomotive != null)
|
2024-03-14 14:26:53 +04:00
|
|
|
|
{
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
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 buttonAddLocomotive_Click(object sender, EventArgs e) =>
|
|
|
|
|
CreateObject(nameof(DrawningLocomotive));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление электро локомотива
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonAddElectricLocomotive_Click(object sender, EventArgs e) =>
|
|
|
|
|
CreateObject(nameof(DrawningElectricLocomotive));
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonDelLocomotive_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company ==
|
|
|
|
|
null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-28 08:25:13 +04:00
|
|
|
|
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-03-14 14:26:53 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Перерисовка коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawningLocomotive? locomotive = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (locomotive == null)
|
|
|
|
|
{
|
|
|
|
|
locomotive = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (locomotive == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormlectricLocomotive form = new()
|
|
|
|
|
{
|
|
|
|
|
SetLocomotive = locomotive
|
|
|
|
|
};
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
}
|
2024-03-28 09:57:08 +04:00
|
|
|
|
/// <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<DrawningLocomotive>? collection =
|
|
|
|
|
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
2024-04-01 17:28:49 +04:00
|
|
|
|
case "Депо":
|
2024-03-28 09:57:08 +04:00
|
|
|
|
_company = new LocomotiveDepo(pictureBox.Width,
|
|
|
|
|
pictureBox.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 14:26:53 +04:00
|
|
|
|
|
2024-03-28 09:57:08 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-01 17:28:49 +04:00
|
|
|
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не выбрана");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
|
|
|
|
RerfreshListBoxItems();
|
2024-03-28 09:57:08 +04:00
|
|
|
|
// TODO прописать логику удаления элемента из коллекции
|
|
|
|
|
// нужно убедиться, что есть выбранная коллекция
|
|
|
|
|
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
|
|
|
|
// удалить и обновить ListBox
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
|
}
|
|
|
|
|
}
|