131 lines
4.7 KiB
C#
131 lines
4.7 KiB
C#
using ProjectLainer.DrawningObjects;
|
||
using ProjectLainer.Generics;
|
||
using ProjectLainer.MovementStrategy;
|
||
|
||
namespace ProjectLainer
|
||
{
|
||
public partial class FormLainerCollection : Form
|
||
{
|
||
private readonly LainersGenericStorage _storage;
|
||
public FormLainerCollection()
|
||
{
|
||
InitializeComponent();
|
||
_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();
|
||
}
|
||
}
|
||
private void ButtonAddLainer_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
LainerForm form = new();
|
||
if (form.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (obj + form.SelectedLainer)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBoxCollection.Image = obj.ShowLainers();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
private void ButtonRemove_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||
if (obj - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBoxCollection.Image = obj.ShowLainers();
|
||
}
|
||
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();
|
||
}
|
||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLainers();
|
||
}
|
||
}
|
||
}
|