2024-03-21 10:52:11 +04:00
|
|
|
|
using ProjectCruiser.CollectionGenericObjects;
|
|
|
|
|
using ProjectCruiser.Drawnings;
|
2024-04-17 23:37:09 +04:00
|
|
|
|
using System.Windows.Forms;
|
2024-03-21 10:52:11 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectCruiser
|
|
|
|
|
{
|
|
|
|
|
public partial class FormCruisersCollection : Form
|
|
|
|
|
{
|
2024-04-04 11:05:33 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Хранилише коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StorageCollection<DrawningCruiser> _storageCollection;
|
|
|
|
|
|
2024-03-21 10:52:11 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
2024-04-04 11:05:33 +04:00
|
|
|
|
|
2024-03-21 10:52:11 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormCruisersCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-04-04 11:05:33 +04:00
|
|
|
|
_storageCollection = new();
|
2024-03-21 10:52:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-04 11:05:33 +04:00
|
|
|
|
panelCompanyTools.Enabled = false;
|
2024-03-21 10:52:11 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-17 23:37:09 +04:00
|
|
|
|
private void ButtonAddCruiser_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
FormCruiserConfing form = new();
|
|
|
|
|
// TODO передать метод
|
|
|
|
|
|
|
|
|
|
form.Show();
|
|
|
|
|
form.AddEvent(SetCruiser);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 10:52:11 +04:00
|
|
|
|
/// <summary>
|
2024-04-17 23:37:09 +04:00
|
|
|
|
/// Добавление крейсера в коллекцию
|
2024-03-21 10:52:11 +04:00
|
|
|
|
/// </summary>
|
2024-04-17 23:37:09 +04:00
|
|
|
|
/// <param name="cruiser"></param>
|
|
|
|
|
private void SetCruiser(DrawningCruiser cruiser)
|
2024-03-21 10:52:11 +04:00
|
|
|
|
{
|
2024-04-17 23:37:09 +04:00
|
|
|
|
if (_company == null || cruiser == null)
|
2024-03-21 10:52:11 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-17 23:37:09 +04:00
|
|
|
|
|
|
|
|
|
if (_company + cruiser != -1)
|
2024-03-21 10:52:11 +04:00
|
|
|
|
{
|
2024-04-04 11:05:33 +04:00
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2024-03-21 10:52:11 +04:00
|
|
|
|
pictureBoxCruiser.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-04-04 11:05:33 +04:00
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
2024-03-21 10:52:11 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-04-17 23:37:09 +04:00
|
|
|
|
/// Удаление объекта
|
2024-03-21 10:52:11 +04:00
|
|
|
|
/// </summary>
|
2024-04-17 23:37:09 +04:00
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2024-03-21 10:52:11 +04:00
|
|
|
|
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("удалить объект?", "удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxPosision.Text);
|
|
|
|
|
if (_company - pos != null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("объект удален");
|
|
|
|
|
pictureBoxCruiser.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonGetToTest_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawningCruiser? cruiser = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (cruiser == null)
|
|
|
|
|
{
|
|
|
|
|
cruiser = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter <= 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (cruiser == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormCruiser form = new()
|
|
|
|
|
{
|
|
|
|
|
SetCruiser = cruiser
|
|
|
|
|
};
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pictureBoxCruiser.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-04 11:05:33 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonCollecctionAdd_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.No)
|
|
|
|
|
{
|
|
|
|
|
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<DrawningCruiser>? collection =
|
|
|
|
|
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new CruiserDockingService(pictureBoxCruiser.Width, pictureBoxCruiser.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 10:52:11 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|