2023-10-25 02:19:13 +04:00
|
|
|
|
using Hydroplane.DrawningObjects;
|
|
|
|
|
using Hydroplane.Generics;
|
|
|
|
|
using Hydroplane.MovementStrategy;
|
|
|
|
|
using System;
|
2023-10-11 10:50:39 +04:00
|
|
|
|
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 Hydroplane
|
|
|
|
|
{
|
|
|
|
|
public partial class FormHydroplaneCollection : Form
|
|
|
|
|
{
|
2023-10-25 10:59:54 +04:00
|
|
|
|
private readonly PlanesGenericStorage _storage;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
2023-10-11 10:50:39 +04:00
|
|
|
|
public FormHydroplaneCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-10-25 10:59:54 +04:00
|
|
|
|
_storage = new PlanesGenericStorage(DrawPlane.Width, DrawPlane.Height);
|
2023-10-25 02:19:13 +04:00
|
|
|
|
}
|
2023-10-25 10:59:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Заполнение listBoxObjects
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = CollectionListBox.SelectedIndex;
|
|
|
|
|
CollectionListBox.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
CollectionListBox.Items.Add(_storage.Keys[i]);
|
|
|
|
|
}
|
|
|
|
|
if (CollectionListBox.Items.Count > 0 && (index == -1 || index
|
|
|
|
|
>= CollectionListBox.Items.Count))
|
|
|
|
|
{
|
|
|
|
|
CollectionListBox.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (CollectionListBox.Items.Count > 0 && index > -1 &&
|
|
|
|
|
index < CollectionListBox.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
CollectionListBox.SelectedIndex = index;
|
|
|
|
|
}
|
2023-10-25 02:19:13 +04:00
|
|
|
|
|
2023-10-25 10:59:54 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление набора в коллекцию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(SetTextBox.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_storage.AddSet(SetTextBox.Text);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
|
|
|
|
EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DrawPlane.Image =
|
|
|
|
|
_storage[CollectionListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show($"Удалить объект {CollectionListBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
_storage.DelSet(CollectionListBox.SelectedItem.ToString()
|
|
|
|
|
?? string.Empty);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление объекта в набор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
2023-10-25 10:59:54 +04:00
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormHydroplane form = new();
|
2023-10-25 02:19:13 +04:00
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2023-10-25 10:59:54 +04:00
|
|
|
|
if (obj + form.SelectedPlane)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2023-10-25 10:59:54 +04:00
|
|
|
|
DrawPlane.Image = obj.ShowPlanes();
|
2023-10-25 02:19:13 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-25 10:59:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление объекта из набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
2023-10-25 10:59:54 +04:00
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[CollectionListBox.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-25 10:59:54 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
2023-10-25 10:59:54 +04:00
|
|
|
|
return;
|
2023-10-25 02:19:13 +04:00
|
|
|
|
}
|
2023-10-25 10:59:54 +04:00
|
|
|
|
int pos = 0;
|
|
|
|
|
if (PlaneTextBox != null)
|
|
|
|
|
pos = Convert.ToInt32(PlaneTextBox.Text);
|
|
|
|
|
if (obj - pos != null)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-10-25 10:59:54 +04:00
|
|
|
|
DrawPlane.Image = obj.ShowPlanes();
|
2023-10-25 02:19:13 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-25 10:59:54 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновление рисунка по набору
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
|
|
|
|
e)
|
2023-10-25 02:19:13 +04:00
|
|
|
|
{
|
2023-10-25 10:59:54 +04:00
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[CollectionListBox.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DrawPlane.Image = obj.ShowPlanes();
|
2023-10-11 10:50:39 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|