using Airbus_Base.DrawningObjects; using Airbus_Base.Generics; using Airbus_Base.MovementStrategy; 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; namespace Airbus_Base { /// /// Форма для работы с набором объектов класса DrawningAirbus /// public partial class FormAirplaneCollection : Form { /// /// Набор объектов /// private readonly TheAirplaneGenericStorage _storage; /// /// Конструктор /// public FormAirplaneCollection() { InitializeComponent(); _storage = new TheAirplaneGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); } /// /// Заполнение listBoxObjects /// private void ReloadObjects() { int index = listBoxObjects.SelectedIndex; listBoxObjects.Items.Clear(); for (int i = 0; i < _storage.Keys.Count; i++) { listBoxObjects.Items.Add(_storage.Keys[i]); } if (listBoxObjects.Items.Count > 0 && (index == -1 || index >= listBoxObjects.Items.Count)) { listBoxObjects.SelectedIndex = 0; } else if (listBoxObjects.Items.Count > 0 && index > -1 && index < listBoxObjects.Items.Count) { listBoxObjects.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[listBoxObjects.SelectedItem?.ToString() ?? string.Empty]?.ShowTheAirplanes(); } /// /// Удаление набора /// /// /// private void ButtonDelObject_Click(object sender, EventArgs e) { if (listBoxObjects.SelectedIndex == -1) { return; } if (MessageBox.Show($"Удалить объект{listBoxObjects.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _storage.DelSet(listBoxObjects.SelectedItem.ToString() ?? string.Empty); ReloadObjects(); } } /// /// Добавление объекта в набор /// /// /// private void ButtonAddAirplane_Click(object sender, EventArgs e) { if (listBoxObjects.SelectedIndex == -1) { return; } var obj = _storage[listBoxObjects.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } FormAirbus form = new(); if (form.ShowDialog() == DialogResult.OK) { if (obj + form.SelectedAirplane) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowTheAirplanes(); } else { MessageBox.Show("Не удалось добавить объект"); } } } /// /// Удаление объекта из набора /// /// /// private void ButtonDeleteAirplane_Click(object sender, EventArgs e) { if (listBoxObjects.SelectedIndex == -1) { return; } var obj = _storage[listBoxObjects.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.ShowTheAirplanes(); } else { MessageBox.Show("Не удалось удалить объект"); } } /// /// Обновление рисунка по набору /// /// /// private void ButtonRefreshCollection_Click(object sender, EventArgs e) { if (listBoxObjects.SelectedIndex == -1) { return; } var obj = _storage[listBoxObjects.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } pictureBoxCollection.Image = obj.ShowTheAirplanes(); } } }