2024-04-10 11:50:51 +04:00
|
|
|
|
using ProjectStormtrooper.CollectionGenericObjects;
|
|
|
|
|
using ProjectStormtrooper.Drawnings;
|
|
|
|
|
|
|
|
|
|
namespace ProjectStormtrooper;
|
|
|
|
|
|
2024-05-07 01:50:39 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
2024-04-10 11:50:51 +04:00
|
|
|
|
public partial class FormAirplaneCollection : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
|
2024-05-08 11:48:23 +04:00
|
|
|
|
private readonly StorageCollection<DrawningAirplane> _storageCollection;
|
|
|
|
|
|
2024-04-10 11:50:51 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormAirplaneCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-08 11:48:23 +04:00
|
|
|
|
_storageCollection = new();
|
2024-04-10 11:50:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-05-08 11:48:23 +04:00
|
|
|
|
panelCompanyTools.Enabled = false;
|
2024-04-10 11:50:51 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 01:31:59 +04:00
|
|
|
|
private void buttonAddAirplane_Click(object sender, EventArgs e)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
2024-06-13 01:31:59 +04:00
|
|
|
|
FormAirplaneConfig form = new();
|
|
|
|
|
form.Show();
|
|
|
|
|
form.AddEvent(SetAirplane);
|
|
|
|
|
}
|
|
|
|
|
private void SetAirplane(DrawningAirplane? airplane)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null || airplane == null)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-13 01:31:59 +04:00
|
|
|
|
if (_company + airplane != -1)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-13 01:31:59 +04:00
|
|
|
|
|
2024-05-07 01:50:39 +04:00
|
|
|
|
private void buttonRemoveAirplane_Click(object sender, EventArgs e)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
|
|
|
|
if (_company - pos != null)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
2024-04-10 11:50:51 +04:00
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DrawningAirplane? airplane = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (airplane == null)
|
|
|
|
|
{
|
|
|
|
|
airplane = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (airplane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormStormtrooper form = new()
|
|
|
|
|
{
|
|
|
|
|
SetAirplane = airplane
|
|
|
|
|
};
|
|
|
|
|
form.ShowDialog();
|
2024-04-10 11:50:51 +04:00
|
|
|
|
}
|
2024-05-07 01:50:39 +04:00
|
|
|
|
private void buttonRefresh_Click(object sender, EventArgs e)
|
2024-04-11 09:34:16 +04:00
|
|
|
|
{
|
2024-05-07 01:50:39 +04:00
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBox.Image = _company.Show();
|
2024-04-11 09:34:16 +04:00
|
|
|
|
}
|
2024-05-08 11:48:23 +04:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// TODO прописать логику удаления элемента из коллекции
|
|
|
|
|
// нужно убедиться, что есть выбранная коллекция
|
|
|
|
|
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
|
|
|
|
// удалить и обновить ListBox
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не выбрана");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ICollectionGenericObjects<DrawningAirplane>? collection =
|
|
|
|
|
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new AirplaneSharingService(pictureBox.Width, pictureBox.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
}
|
2024-04-10 11:50:51 +04:00
|
|
|
|
}
|