2024-03-23 18:42:24 +04:00
|
|
|
|
using ProjectAirplaneWithRadar.CollectionGenericObjects;
|
|
|
|
|
using ProjectAirplaneWithRadar.Drawnings;
|
2024-04-20 10:04:26 +04:00
|
|
|
|
using ProjectAirplaneWithRadar.Exceptions;
|
2024-03-23 18:42:24 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectAirplaneWithRadar
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormAirplaneCollection : Form
|
|
|
|
|
{
|
2024-03-28 18:07:22 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Хранилише коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StorageCollection<DrawningAirplane> _storageCollection;
|
|
|
|
|
|
2024-03-23 18:42:24 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormAirplaneCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-03-28 18:07:22 +04:00
|
|
|
|
_storageCollection = new();
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-03-28 18:07:22 +04:00
|
|
|
|
panelCompanyTools.Enabled = false;
|
2024-04-14 13:10:36 +04:00
|
|
|
|
}
|
2024-04-13 16:42:07 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление самолета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FormAirplaneConfig form = new();
|
|
|
|
|
form.Show();
|
|
|
|
|
form.AddEvent(SetAirplane);
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-13 16:42:07 +04:00
|
|
|
|
/// Добавление самолета в коллекцию
|
2024-03-23 18:42:24 +04:00
|
|
|
|
/// </summary>
|
2024-04-13 16:42:07 +04:00
|
|
|
|
/// <param name="airplane"></param>
|
|
|
|
|
private void SetAirplane(DrawningAirplane airplane)
|
2024-03-23 18:42:24 +04:00
|
|
|
|
{
|
2024-04-13 16:42:07 +04:00
|
|
|
|
if (_company == null || airplane == null)
|
2024-03-23 18:42:24 +04:00
|
|
|
|
return;
|
|
|
|
|
|
2024-04-20 10:04:26 +04:00
|
|
|
|
try
|
2024-03-23 18:42:24 +04:00
|
|
|
|
{
|
2024-04-20 10:04:26 +04:00
|
|
|
|
if (_company + airplane != -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
2024-04-20 10:04:26 +04:00
|
|
|
|
catch (CollectionOverflowException ex)
|
2024-03-23 18:42:24 +04:00
|
|
|
|
{
|
2024-04-20 10:04:26 +04:00
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
catch (ObjectNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
}
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRemoveAirplane_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-04-20 10:04:26 +04:00
|
|
|
|
|
|
|
|
|
try
|
2024-03-23 18:42:24 +04:00
|
|
|
|
{
|
2024-04-20 10:04:26 +04:00
|
|
|
|
if (_company - pos != null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
} catch (PositionOutOfCollectionException ex)
|
2024-03-23 18:42:24 +04:00
|
|
|
|
{
|
2024-04-20 10:04:26 +04:00
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
} catch (ObjectNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message);
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача объекта в другую форму
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawningAirplane? plane = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (plane == null)
|
|
|
|
|
{
|
2024-04-20 10:04:26 +04:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
plane = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (PositionOutOfCollectionException ex)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
catch (ObjectNotFoundException ex)
|
2024-03-23 18:42:24 +04:00
|
|
|
|
{
|
2024-04-20 10:04:26 +04:00
|
|
|
|
MessageBox.Show(ex.Message);
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FormAirplaneWithRadar form = new()
|
|
|
|
|
{
|
|
|
|
|
SetAirplane = plane
|
|
|
|
|
};
|
|
|
|
|
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 18:07:22 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCollectionAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-14 13:10:36 +04:00
|
|
|
|
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
2024-03-28 18:07:22 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CollectionType collectionType = CollectionType.None;
|
2024-04-14 13:10:36 +04:00
|
|
|
|
if (radioButtonMassive.Checked)
|
2024-03-28 18:07:22 +04:00
|
|
|
|
collectionType = CollectionType.Massive;
|
|
|
|
|
else if (radioButtonList.Checked)
|
|
|
|
|
collectionType = CollectionType.List;
|
|
|
|
|
|
|
|
|
|
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
|
|
|
|
RefreshListBoxItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCollectionDel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-14 13:10:36 +04:00
|
|
|
|
if (listBoxCollection.SelectedItems == null || listBoxCollection.SelectedIndex < 0)
|
2024-03-28 18:07:22 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не выбрана");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
|
|
|
|
RefreshListBoxItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновление списка в listBoxCollection
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void RefreshListBoxItems()
|
|
|
|
|
{
|
|
|
|
|
listBoxCollection.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
string? colName = _storageCollection.Keys?[i];
|
2024-04-14 13:10:36 +04:00
|
|
|
|
if (!string.IsNullOrEmpty(colName))
|
2024-03-28 18:07:22 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
2024-04-14 13:10:36 +04:00
|
|
|
|
|
2024-03-28 18:07:22 +04:00
|
|
|
|
ICollectionGenericObjects<DrawningAirplane>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
RefreshListBoxItems();
|
|
|
|
|
}
|
2024-04-14 13:10:36 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия "Сохранение"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2024-04-18 18:14:42 +04:00
|
|
|
|
try
|
2024-04-14 13:10:36 +04:00
|
|
|
|
{
|
2024-04-18 18:14:42 +04:00
|
|
|
|
_storageCollection.SaveData(saveFileDialog.FileName);
|
2024-04-14 13:10:36 +04:00
|
|
|
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
2024-04-18 18:14:42 +04:00
|
|
|
|
catch(Exception ex)
|
2024-04-14 13:10:36 +04:00
|
|
|
|
{
|
2024-04-18 18:14:42 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
2024-04-14 13:10:36 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия "Загрузка"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2024-04-18 18:14:42 +04:00
|
|
|
|
try
|
2024-04-14 13:10:36 +04:00
|
|
|
|
{
|
2024-04-18 18:14:42 +04:00
|
|
|
|
_storageCollection.LoadData(openFileDialog.FileName);
|
2024-04-14 13:10:36 +04:00
|
|
|
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2024-04-18 20:43:19 +04:00
|
|
|
|
RefreshListBoxItems();
|
2024-04-14 13:10:36 +04:00
|
|
|
|
}
|
2024-04-18 18:14:42 +04:00
|
|
|
|
catch(Exception ex)
|
2024-04-14 13:10:36 +04:00
|
|
|
|
{
|
2024-04-18 18:14:42 +04:00
|
|
|
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-04-14 13:10:36 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-23 18:42:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|