2023-12-01 21:10:50 +04:00
|
|
|
|
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;
|
2023-12-29 20:25:33 +04:00
|
|
|
|
using Airbus_Base.Exceptions;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using Serilog;
|
|
|
|
|
|
2023-12-01 21:10:50 +04:00
|
|
|
|
|
|
|
|
|
namespace Airbus_Base
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма для работы с набором объектов класса DrawningAirbus
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormAirplaneCollection : Form
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Набор объектов
|
|
|
|
|
/// </summary>
|
2023-12-02 00:24:08 +04:00
|
|
|
|
private readonly TheAirplaneGenericStorage _storage;
|
2023-12-01 21:10:50 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormAirplaneCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-12-02 00:24:08 +04:00
|
|
|
|
_storage = new TheAirplaneGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Заполнение listBoxObjects
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxObjects.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
listBoxObjects.Items.Clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
|
|
|
|
{
|
2023-12-29 21:27:30 +04:00
|
|
|
|
listBoxObjects.Items.Add(_storage.Keys[i].Name);
|
2023-12-02 00:24:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление набора в коллекцию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
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();
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Information($"Добавлен набор: {textBoxStorageName.Text}");
|
2023-12-02 00:24:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
pictureBoxCollection.Image = _storage[listBoxObjects.SelectedItem?.ToString() ?? string.Empty]?.ShowTheAirplanes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxObjects.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show($"Удалить объект{listBoxObjects.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
string name = (listBoxObjects.SelectedItem.ToString() ?? string.Empty);
|
|
|
|
|
_storage.DelSet(name);
|
2023-12-02 00:24:08 +04:00
|
|
|
|
ReloadObjects();
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Information($"Удален набор: {name}");
|
2023-12-02 00:24:08 +04:00
|
|
|
|
}
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление объекта в набор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-02 00:24:08 +04:00
|
|
|
|
if (listBoxObjects.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxObjects.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-15 22:22:18 +04:00
|
|
|
|
FormAirplaneConfig form = new();
|
|
|
|
|
form.Show();
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Action<DrawningAirplane>? airplaneDelegate = new((airplane) =>
|
2023-12-01 21:10:50 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
try
|
2023-12-01 21:10:50 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
bool isAdditionSuccessful = obj + airplane;
|
2023-12-01 21:10:50 +04:00
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2023-12-29 20:25:33 +04:00
|
|
|
|
airplane.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
2023-12-02 00:24:08 +04:00
|
|
|
|
pictureBoxCollection.Image = obj.ShowTheAirplanes();
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Information($"Добавлен объект в коллекцию {listBoxObjects.SelectedItem.ToString() ?? string.Empty}");
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
2023-12-29 21:27:30 +04:00
|
|
|
|
catch (ArgumentException ex)
|
2023-12-01 21:10:50 +04:00
|
|
|
|
{
|
2023-12-29 21:27:30 +04:00
|
|
|
|
Log.Warning($"Добавляемый объект уже существует в коллекции {listBoxObjects.SelectedItem.ToString() ?? string.Empty}");
|
|
|
|
|
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
2023-12-15 22:22:18 +04:00
|
|
|
|
});
|
|
|
|
|
form.AddEvent(airplaneDelegate);
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта из набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonDeleteAirplane_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-02 00:24:08 +04:00
|
|
|
|
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)
|
2023-12-01 21:10:50 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 20:25:33 +04:00
|
|
|
|
try
|
2023-12-01 21:10:50 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
|
|
|
|
var isAdditionSuccessful = obj - pos;
|
2023-12-01 21:10:50 +04:00
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Information($"Удален объект из коллекции {listBoxObjects.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
|
2023-12-02 00:24:08 +04:00
|
|
|
|
pictureBoxCollection.Image = obj.ShowTheAirplanes();
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
2023-12-29 20:25:33 +04:00
|
|
|
|
catch (AirplaneNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
Log.Warning($"Не получилось удалить объект из коллекции {listBoxObjects.SelectedItem.ToString() ?? string.Empty}");
|
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
catch (FormatException)
|
2023-12-01 21:10:50 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Warning($"Было введено не число");
|
|
|
|
|
MessageBox.Show("Введите число");
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновление рисунка по набору
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-02 00:24:08 +04:00
|
|
|
|
if (listBoxObjects.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxObjects.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowTheAirplanes();
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
2023-12-15 23:53:20 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия "Сохранение"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
try
|
2023-12-15 23:53:20 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
_storage.SaveData(saveFileDialog.FileName);
|
2023-12-15 23:53:20 +04:00
|
|
|
|
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Information($"Файл {saveFileDialog.FileName} успешно сохранен");
|
2023-12-15 23:53:20 +04:00
|
|
|
|
}
|
2023-12-29 20:25:33 +04:00
|
|
|
|
catch (Exception ex)
|
2023-12-15 23:53:20 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Warning("Не удалось сохранить");
|
|
|
|
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2023-12-15 23:53:20 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обработка нажатия "Загрузка"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
try
|
2023-12-15 23:53:20 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
_storage.LoadData(openFileDialog.FileName);
|
2023-12-15 23:53:20 +04:00
|
|
|
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Information($"Файл {openFileDialog.FileName} успешно загружен");
|
2023-12-15 23:53:20 +04:00
|
|
|
|
foreach (var collection in _storage.Keys)
|
|
|
|
|
{
|
|
|
|
|
listBoxObjects.Items.Add(collection);
|
|
|
|
|
}
|
2023-12-29 20:25:33 +04:00
|
|
|
|
ReloadObjects();
|
2023-12-15 23:53:20 +04:00
|
|
|
|
}
|
2023-12-29 20:25:33 +04:00
|
|
|
|
catch (Exception ex)
|
2023-12-15 23:53:20 +04:00
|
|
|
|
{
|
2023-12-29 20:25:33 +04:00
|
|
|
|
Log.Warning("Не удалось загрузить");
|
|
|
|
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2023-12-15 23:53:20 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-29 21:27:30 +04:00
|
|
|
|
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareAirplanes(new AirplaneCompareByType());
|
|
|
|
|
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareAirplanes(new AirplaneCompareByColor());
|
|
|
|
|
private void CompareAirplanes(IComparer<DrawningAirplane?> comparer)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxObjects.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxObjects.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
obj.Sort(comparer);
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowTheAirplanes();
|
|
|
|
|
}
|
2023-12-01 21:10:50 +04:00
|
|
|
|
}
|
|
|
|
|
}
|