2024-04-02 08:53:49 +04:00
|
|
|
|
using ProjectStormtrooper.CollectionGenericObjects;
|
|
|
|
|
using ProjectStormtrooper.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 ProjectStormtrooper;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма работы с компанией и ее коллекцией
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
public partial class FormStormtrooperCollection : Form
|
|
|
|
|
{
|
2024-04-16 10:33:52 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Хранилище коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StorageCollection<DrawningStormtrooperBase> _storageCollection;
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
|
|
|
|
/// </summary>
|
2024-04-26 15:53:05 +04:00
|
|
|
|
private AbstractCompany? _company;
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormStormtrooperCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-04-16 10:33:52 +04:00
|
|
|
|
_storageCollection = new();
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор компании
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-04-16 10:33:52 +04:00
|
|
|
|
panelCompanyTools.Enabled = true;
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|
2024-04-30 11:26:54 +04:00
|
|
|
|
|
2024-04-26 15:53:05 +04:00
|
|
|
|
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// <summary>
|
2024-04-26 15:53:05 +04:00
|
|
|
|
/// Добавление базового штурмовика
|
2024-04-02 08:53:49 +04:00
|
|
|
|
/// </summary>
|
2024-04-26 15:53:05 +04:00
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddStormtrooperBase_Click(object sender, EventArgs e)
|
2024-04-02 08:53:49 +04:00
|
|
|
|
{
|
2024-04-26 15:53:05 +04:00
|
|
|
|
FormStormtrooperConfig form = new();
|
|
|
|
|
form.Show();
|
|
|
|
|
// TODO передать метод
|
|
|
|
|
form.AddEvent(SetStormtrooper);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление штурмовика в коллекцию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stormtrooper"></param>
|
|
|
|
|
private void SetStormtrooper(DrawningStormtrooperBase stormtrooper)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null || stormtrooper == null)
|
2024-04-02 08:53:49 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-26 15:53:05 +04:00
|
|
|
|
if (_company + stormtrooper != -1)
|
2024-04-02 08:53:49 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRemoveStormtrooper_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBox.Text);
|
|
|
|
|
if (_company - pos != null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Передача объекта в другую форму
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DrawningStormtrooperBase? stormtrooper = null;
|
|
|
|
|
int counter = 100;
|
|
|
|
|
while (stormtrooper == null)
|
|
|
|
|
{
|
|
|
|
|
stormtrooper = _company.GetRandomObject();
|
|
|
|
|
counter--;
|
|
|
|
|
if (counter < -0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (stormtrooper == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormStormtrooper form = new()
|
|
|
|
|
{
|
|
|
|
|
SetStormtrooper = stormtrooper
|
|
|
|
|
};
|
|
|
|
|
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-04-16 10:33:52 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></par
|
|
|
|
|
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>
|
|
|
|
|
/// Удаление коллекции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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.Yes)
|
|
|
|
|
{
|
|
|
|
|
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<DrawningStormtrooperBase>? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new StormtrooperSharingService(pictureBox.Width, pictureBox.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
|
|
|
|
|
}
|
2024-04-30 11:26:54 +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)
|
|
|
|
|
{
|
|
|
|
|
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Сохранение прошло успешно",
|
|
|
|
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не сохранилось", "Результат",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия "Загрузка"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// TODO продумать логику
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (_storageCollection.LoadData(openFileDialog.FileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Загрузка прошла успешно",
|
|
|
|
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Загрузка не удалась", "Результат",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-16 10:33:52 +04:00
|
|
|
|
|
2024-04-26 15:53:05 +04:00
|
|
|
|
|
2024-04-30 11:26:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-02 08:53:49 +04:00
|
|
|
|
}
|