2023-12-19 18:53:18 +04:00
|
|
|
|
using ProjectLainer.DrawningObjects;
|
2023-12-08 21:10:19 +04:00
|
|
|
|
using ProjectLainer.Generics;
|
|
|
|
|
using ProjectLainer.MovementStrategy;
|
|
|
|
|
|
|
|
|
|
namespace ProjectLainer
|
|
|
|
|
{
|
|
|
|
|
public partial class FormLainerCollection : Form
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
private readonly LainersGenericStorage _storage;
|
2023-12-08 21:10:19 +04:00
|
|
|
|
public FormLainerCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-12-19 18:48:02 +04:00
|
|
|
|
_storage = new LainersGenericStorage(pictureBoxCollection.Width,
|
|
|
|
|
pictureBoxCollection.Height);
|
|
|
|
|
}
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxStorages.SelectedIndex;
|
|
|
|
|
listBoxStorages.Items.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (string key in _storage.Keys)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.Items.Add(key);
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
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-12-08 21:10:19 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonAddLainer_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-08 21:10:19 +04:00
|
|
|
|
LainerForm form = new();
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
if (obj + form.SelectedLainer)
|
2023-12-08 21:10:19 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2023-12-19 18:48:02 +04:00
|
|
|
|
pictureBoxCollection.Image = obj.ShowLainers();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonRemove_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-08 21:10:19 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-19 18:48:02 +04:00
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
|
|
|
|
if (obj - pos != null)
|
2023-12-08 21:10:19 +04:00
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowLainers();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
2023-12-19 18:48:02 +04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowLainers();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
2023-12-19 18:48:02 +04:00
|
|
|
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
2023-12-08 21:10:19 +04:00
|
|
|
|
{
|
2023-12-19 18:48:02 +04:00
|
|
|
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLainers();
|
2023-12-08 21:10:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|