2024-03-10 19:05:31 +04:00
|
|
|
|
using ProjectMonorail.Scripts.Monorail.CollectionGenericObjects;
|
|
|
|
|
using ProjectMonorail.Scripts.Monorail.Drawnings;
|
|
|
|
|
|
|
|
|
|
namespace ProjectMonorail
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormMonorailCollection : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-04-07 18:24:39 +04:00
|
|
|
|
/// Хранилище коллекций
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly StorageCollection<DrawingMonorail> _storageCollection;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Компания
|
2024-03-10 19:05:31 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private AbstractCompany? _company = null;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormMonorailCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-04-07 18:24:39 +04:00
|
|
|
|
_storageCollection = new StorageCollection<DrawingMonorail>();
|
2024-03-10 19:05:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
2024-03-11 15:22:10 +04:00
|
|
|
|
_company = new DepotSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingMonorail>());
|
2024-03-10 19:05:31 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 22:21:50 +04:00
|
|
|
|
private void ButtonAddMonorail_Click(object sender, EventArgs e)
|
2024-03-10 19:05:31 +04:00
|
|
|
|
{
|
2024-04-07 22:21:50 +04:00
|
|
|
|
FormMonorailConfig form = new FormMonorailConfig();
|
|
|
|
|
form.Show();
|
|
|
|
|
form.AddEventListener_Monorail(SetMonorail);
|
|
|
|
|
}
|
2024-03-10 19:05:31 +04:00
|
|
|
|
|
2024-04-07 22:21:50 +04:00
|
|
|
|
private void SetMonorail(DrawingMonorail monorail)
|
|
|
|
|
{
|
|
|
|
|
if (monorail == null || _company == null) return;
|
2024-03-10 19:05:31 +04:00
|
|
|
|
|
2024-04-07 22:21:50 +04:00
|
|
|
|
if (_company + monorail != -1)
|
2024-03-10 19:05:31 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonRemoveMonorail_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) return;
|
|
|
|
|
|
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
|
|
|
|
|
|
|
|
|
|
int position = Convert.ToInt32(maskedTextBox.Text);
|
|
|
|
|
|
2024-03-11 15:22:10 +04:00
|
|
|
|
if (_company - position != null)
|
2024-03-10 19:05:31 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null) return;
|
|
|
|
|
|
|
|
|
|
DrawingMonorail? monorail = null;
|
|
|
|
|
int coutner = 100;
|
|
|
|
|
|
|
|
|
|
while (monorail == null && coutner-- > 0)
|
|
|
|
|
{
|
|
|
|
|
monorail = _company.GetRandomObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (monorail == null) return;
|
|
|
|
|
|
|
|
|
|
FormMonorail form = new FormMonorail()
|
|
|
|
|
{
|
|
|
|
|
SetMonorail = monorail
|
|
|
|
|
};
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (_company == null) return;
|
|
|
|
|
pictureBox.Image = _company.Show();
|
|
|
|
|
}
|
2024-04-07 18:24:39 +04:00
|
|
|
|
|
|
|
|
|
/// <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 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 ButtonCollectionDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// TODO прописать логику удаления элемента из коллекции
|
|
|
|
|
// нужно убедиться, что есть выбранная коллекция
|
|
|
|
|
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
|
|
|
|
// удалить и обновить ListBox
|
|
|
|
|
if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция для удаления не выбрана");
|
|
|
|
|
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<DrawingMonorail>? collection =
|
|
|
|
|
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (collection == null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Коллекция не проинициализирована");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (comboBoxSelectorCompany.Text)
|
|
|
|
|
{
|
|
|
|
|
case "Хранилище":
|
|
|
|
|
_company = new DepotSharingService(pictureBox.Width,
|
|
|
|
|
pictureBox.Height, collection);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
panelCompanyTools.Enabled = true;
|
|
|
|
|
RerfreshListBoxItems();
|
|
|
|
|
}
|
2024-04-21 21:24:49 +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)
|
|
|
|
|
{
|
|
|
|
|
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-03-10 19:05:31 +04:00
|
|
|
|
}
|
|
|
|
|
}
|