2023-12-16 11:10:10 +04:00
|
|
|
|
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;
|
|
|
|
|
using ContainerShip.MovementStrategy;
|
|
|
|
|
using ContainerShip.DrawningObjects;
|
|
|
|
|
using ContainerShip.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ContainerShip
|
|
|
|
|
{
|
|
|
|
|
public partial class FormShipCollection : Form
|
|
|
|
|
{
|
2023-12-16 11:14:14 +04:00
|
|
|
|
private readonly ShipsGenericStorage _storage;
|
2023-12-16 11:10:10 +04:00
|
|
|
|
|
|
|
|
|
public FormShipCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-12-16 11:14:14 +04:00
|
|
|
|
_storage = new ShipsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|
|
|
|
}
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxStorages.SelectedIndex;
|
|
|
|
|
listBoxStorages.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.Items.Add(_storage.Keys[i]);
|
|
|
|
|
}
|
|
|
|
|
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]?.ShowShips();
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
2023-12-16 11:18:38 +04:00
|
|
|
|
|
2023-12-16 11:10:10 +04:00
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
2023-12-16 11:16:37 +04:00
|
|
|
|
{
|
|
|
|
|
var formShipConfig = new FormShipConfig();
|
|
|
|
|
formShipConfig.AddEvent(AddShip);
|
|
|
|
|
formShipConfig.Show();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddShip(DrawningShip selectedShip)
|
2023-12-16 11:10:10 +04:00
|
|
|
|
{
|
2023-12-16 11:14:14 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
2023-12-16 11:16:37 +04:00
|
|
|
|
MessageBox.Show("Не выбран набор");
|
2023-12-16 11:14:14 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-16 11:16:37 +04:00
|
|
|
|
selectedShip.ChangeBordersPicture(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
|
|
|
|
if (obj + selectedShip != -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowShips();
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-12-16 11:10:10 +04:00
|
|
|
|
{
|
2023-12-16 11:16:37 +04:00
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-16 11:18:38 +04:00
|
|
|
|
|
2023-12-16 11:10:10 +04:00
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-16 11:14:14 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
2023-12-16 11:10:10 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-16 11:14:14 +04:00
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
2023-12-16 11:10:10 +04:00
|
|
|
|
{
|
2023-12-16 11:14:14 +04:00
|
|
|
|
return;
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
2023-12-16 11:14:14 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2023-12-16 11:10:10 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-16 11:14:14 +04:00
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
|
|
|
|
if (obj - pos)
|
2023-12-16 11:10:10 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-12-16 11:14:14 +04:00
|
|
|
|
pictureBoxCollection.Image = obj.ShowShips();
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
2023-12-16 11:14:14 +04:00
|
|
|
|
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
|
|
|
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-16 11:14:14 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowShips();
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
2023-12-16 11:18:38 +04:00
|
|
|
|
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();
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowShips();
|
|
|
|
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-16 11:10:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|