238 lines
6.5 KiB
C#
238 lines
6.5 KiB
C#
using ProjectAirFighter.CollectionGenericObject;
|
||
using ProjectAirFighter.CollectionGenericObjects;
|
||
using ProjectAirFighter.Drawning;
|
||
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 ProjectAirFighter;
|
||
|
||
public partial class FormWarPlaneCollection : Form
|
||
{
|
||
/// <summary>
|
||
/// Хранилище коолекций
|
||
/// </summary>
|
||
private readonly StorageCollection<DrawningWarPlane> _storageCollection;
|
||
|
||
/// <summary>
|
||
/// Компания
|
||
/// </summary>
|
||
private AbstractCompany? _company;
|
||
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormWarPlaneCollection()
|
||
{
|
||
InitializeComponent();
|
||
_storageCollection = new();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Выбор компании
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
panelCompanyTools.Enabled = false;
|
||
}
|
||
|
||
|
||
|
||
private void ButtonAddWarPlane_Click(object sender, EventArgs e){
|
||
|
||
FormWarPlaneConfig form = new();
|
||
form.Show();
|
||
form.AddEvent(SetWarPlane);
|
||
}
|
||
|
||
private void SetWarPlane(DrawningWarPlane warPlane)
|
||
{
|
||
if (_company == null || warPlane == null)
|
||
{
|
||
return;
|
||
}
|
||
if (_company + warPlane != -1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBox.Image = _company.Show();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||
|
||
if (_company - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBox.Image = _company.Show();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
|
||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||
{
|
||
if (_company == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
DrawningWarPlane? warPlane = null;
|
||
|
||
int counter = 100;
|
||
while (warPlane == null)
|
||
{
|
||
warPlane = _company.GetRandomObject();
|
||
counter--;
|
||
if (counter <= 0)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (warPlane == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
FormAirFighter form = new()
|
||
{
|
||
SetWarPlane = warPlane
|
||
};
|
||
form.ShowDialog();
|
||
}
|
||
|
||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||
{
|
||
if (_company == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
pictureBox.Image = _company.Show();
|
||
}
|
||
/// <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>
|
||
/// Обновление списка в 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 buttonCollectionRemove_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||
{
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||
RerfreshListBoxItems();
|
||
|
||
}
|
||
/// <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<DrawningWarPlane>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||
if (collection == null)
|
||
{
|
||
MessageBox.Show("Коллекция не проинициализирована");
|
||
return;
|
||
}
|
||
|
||
switch (comboBoxSelectorCompany.Text)
|
||
{
|
||
case "Хранилище":
|
||
_company = new WarPlaneBase(pictureBox.Width,
|
||
pictureBox.Height, collection);
|
||
break;
|
||
}
|
||
|
||
panelCompanyTools.Enabled = true;
|
||
RerfreshListBoxItems();
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|