PIbd22_NikiforovaMV_Contain.../ContainerShip/FormShipCollection.cs
2023-12-16 11:10:10 +04:00

73 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
{
private readonly ShipsGenericCollection<DrawningShip, DrawingObjectShip> _ship;
public FormShipCollection()
{
InitializeComponent();
_ship = new ShipsGenericCollection<DrawningShip, DrawingObjectShip>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void buttonAdd_Click(object sender, EventArgs e)
{
FormShips form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_ship + form.SelectedShip != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _ship.ShowShips();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = 0;
try
{
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
}
catch
{
MessageBox.Show("Ошибка ввода данных");
return;
}
if (_ship - pos)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _ship.ShowShips();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _ship.ShowShips();
}
}
}