2023-11-11 21:26:13 +04:00
|
|
|
|
using WarmlyLocomotive.Generics;
|
2023-11-11 00:01:51 +04:00
|
|
|
|
using WarmlyLocomotive.MovementStrategy;
|
2023-11-11 21:26:13 +04:00
|
|
|
|
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;
|
2023-11-14 22:19:16 +04:00
|
|
|
|
using static System.Windows.Forms.DataFormats;
|
|
|
|
|
using WarmlyLocomotive.DrawningObjects;
|
|
|
|
|
|
2023-11-11 00:01:51 +04:00
|
|
|
|
namespace WarmlyLocomotive
|
|
|
|
|
{
|
|
|
|
|
public partial class FormWarmlyLocomotiveCollection : Form
|
|
|
|
|
{
|
2023-11-11 21:26:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Набор объектов
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly WarmlyLocomotivesGenericStorage _storage;
|
2023-11-11 00:01:51 +04:00
|
|
|
|
public FormWarmlyLocomotiveCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-11-11 21:26:13 +04:00
|
|
|
|
_storage = new WarmlyLocomotivesGenericStorage(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
|
2023-11-11 00:01:51 +04:00
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Заполнение listBoxObjects
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxStorages.SelectedIndex;
|
|
|
|
|
listBoxStorages.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.Items.Add(_storage.Keys[i]);
|
|
|
|
|
}
|
|
|
|
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
|
|
|
|
>= listBoxStorages.Items.Count))
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
|
|
|
|
index < listBoxStorages.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
pictureBoxCollectionWarmlyLocomotive.Image =
|
|
|
|
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowWarmlyLocomotives();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonDelObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?",
|
|
|
|
|
"Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
|
|
|
|
?? string.Empty);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-14 22:19:16 +04:00
|
|
|
|
|
2023-11-11 21:26:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление объекта в набор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2023-11-11 00:01:51 +04:00
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-11 21:26:13 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-14 22:19:16 +04:00
|
|
|
|
FormWarmlyLocomotiveConfig form = new FormWarmlyLocomotiveConfig(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
|
|
|
|
|
form.Show();
|
|
|
|
|
Action<DrawningWarmlyLocomotive>? warmlydelegate = new((m) => {
|
|
|
|
|
bool q = (obj + m);
|
|
|
|
|
if (q)
|
2023-11-11 00:01:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2023-11-11 21:26:13 +04:00
|
|
|
|
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
|
2023-11-11 00:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
2023-11-14 22:19:16 +04:00
|
|
|
|
});
|
|
|
|
|
form.AddEvent(warmlydelegate);
|
2023-11-11 00:01:51 +04:00
|
|
|
|
}
|
2023-11-14 22:19:16 +04:00
|
|
|
|
|
2023-11-11 21:26:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта из набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
2023-11-11 00:01:51 +04:00
|
|
|
|
private void buttonRemove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-11 21:26:13 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
2023-11-11 00:01:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
2023-11-11 00:01:51 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
|
|
|
|
if (obj - pos != null)
|
2023-11-11 00:01:51 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-11-11 21:26:13 +04:00
|
|
|
|
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
|
2023-11-11 00:01:51 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновление рисунка по набору
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonreFreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление набора в коллекцию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonAddObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_storage.AddSet(textBoxStorageName.Text);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
2023-11-11 00:01:51 +04:00
|
|
|
|
}
|
2023-11-11 21:26:13 +04:00
|
|
|
|
}
|