196 lines
6.4 KiB
C#
196 lines
6.4 KiB
C#
using RPP.DrawningObjects;
|
||
using RPP.Generics;
|
||
using System.Windows.Forms;
|
||
|
||
|
||
namespace RPP
|
||
{
|
||
public partial class FormAirbusCollection : Form
|
||
{
|
||
private readonly AirbusGenericStorage _storage;
|
||
|
||
public FormAirbusCollection()
|
||
{
|
||
InitializeComponent();
|
||
_storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||
|
||
}
|
||
|
||
private void FormFlyAirbus_Load(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
private void AddAirbus(DrawningAirbus Airbus)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
if (obj + Airbus)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBoxCollection.Image = obj.ShowCars();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
|
||
}
|
||
private void AddAirbusButton_Click(object sender, EventArgs e)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
var formAirbusConfig = new FormAirbusConfig();
|
||
formAirbusConfig.Show();
|
||
formAirbusConfig.AddEvent(AddAirbus);
|
||
}
|
||
private void ReloadObjects()
|
||
{
|
||
int index = listBoxStorages.SelectedIndex;
|
||
listBoxStorages.Items.Clear();
|
||
foreach (var 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 ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowCars();
|
||
}
|
||
|
||
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 ButtonRemoveAirbus_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.ShowCars();
|
||
}
|
||
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.ShowCars();
|
||
}
|
||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (_storage.SaveData(saveFileDialog.FileName))
|
||
{
|
||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||
{
|
||
if (_storage.LoadData(openFileDialog.FileName))
|
||
{
|
||
ReloadObjects();
|
||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void panel2_Paint(object sender, PaintEventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void label2_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void panel1_Paint(object sender, PaintEventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|