111 lines
4.0 KiB
C#
111 lines
4.0 KiB
C#
namespace ElectricLocomotive;
|
||
|
||
public partial class FormLocomotivCollection : Form {
|
||
private readonly LocosGenericStorage _storage;
|
||
public FormLocomotivCollection() {
|
||
InitializeComponent();
|
||
_storage = new(collectionPictureBox.Width, collectionPictureBox.Height);
|
||
}
|
||
private void ReloadObjects() {
|
||
int index = storageListBox.SelectedIndex;
|
||
storageListBox.Items.Clear();
|
||
for (int i = 0; i < _storage.Keys.Count; i++) {
|
||
storageListBox.Items.Add(_storage.Keys[i]);
|
||
}
|
||
if (storageListBox.Items.Count > 0 && (index == -1 || index
|
||
>= storageListBox.Items.Count)) {
|
||
storageListBox.SelectedIndex = 0;
|
||
}
|
||
else if (storageListBox.Items.Count > 0 && index > -1 &&
|
||
index < storageListBox.Items.Count) {
|
||
storageListBox.SelectedIndex = index;
|
||
}
|
||
}
|
||
|
||
private void addLocomotiv_Click(object sender, EventArgs e) {
|
||
if (storageListBox.SelectedIndex == -1) {
|
||
return;
|
||
}
|
||
var obj = _storage[storageListBox.SelectedItem.ToString() ?? string.Empty];
|
||
if (obj == null) {
|
||
return;
|
||
}
|
||
FormLocoConfig form = new();
|
||
form.Show();
|
||
Action<DrawingLocomotiv>? monorailDelegate = new((m) => {
|
||
bool q = (obj + m);
|
||
if (q)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
m.ChangePictureBoxSize(collectionPictureBox.Width, collectionPictureBox.Height);
|
||
collectionPictureBox.Image = obj.ShowLocos();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
});
|
||
form.AddEvent(monorailDelegate);
|
||
}
|
||
private void deleteLoco_Click(object sender, EventArgs e) {
|
||
if (storageListBox.SelectedIndex == -1) {
|
||
return;
|
||
}
|
||
var obj = _storage[storageListBox.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null) {
|
||
return;
|
||
}
|
||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
|
||
return;
|
||
}
|
||
int pos = Convert.ToInt32(locoIndexInput.Text);
|
||
if (obj - pos != null) {
|
||
MessageBox.Show("Объект удален");
|
||
collectionPictureBox.Image = obj.ShowLocos();
|
||
}
|
||
else {
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
|
||
private void refreshCollection_Click(object sender, EventArgs e) {
|
||
if (storageListBox.SelectedIndex == -1) {
|
||
return;
|
||
}
|
||
var obj = _storage[storageListBox.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null) {
|
||
return;
|
||
}
|
||
collectionPictureBox.Image = obj.ShowLocos();
|
||
}
|
||
private void storagesListBox_SelectedIndexChanged(object sender, EventArgs e) {
|
||
collectionPictureBox.Image =
|
||
_storage[storageListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowLocos();
|
||
}
|
||
|
||
private void delStorageButton_Click(object sender, EventArgs e) {
|
||
if (storageListBox.SelectedIndex == -1) {
|
||
return;
|
||
}
|
||
if (MessageBox.Show($"Удалить объект{storageListBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||
MessageBoxIcon.Question) == DialogResult.Yes) {
|
||
_storage.DelSet(storageListBox.SelectedItem.ToString()
|
||
?? string.Empty);
|
||
ReloadObjects();
|
||
}
|
||
|
||
}
|
||
|
||
private void addStorageButton_Click(object sender, EventArgs e) {
|
||
if (string.IsNullOrEmpty(storageIndexInput.Text)) {
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
_storage.AddSet(storageIndexInput.Text);
|
||
ReloadObjects();
|
||
}
|
||
} |