153 lines
4.9 KiB
C#
153 lines
4.9 KiB
C#
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 Catamaran
|
||
{
|
||
public partial class FormCatamaranCollection : Form
|
||
{
|
||
private readonly CatamaransGenericStorage _storage;
|
||
|
||
public FormCatamaranCollection()
|
||
{
|
||
InitializeComponent();
|
||
_storage = new CatamaransGenericStorage(pictureBoxCollection.Width,
|
||
pictureBoxCollection.Height);
|
||
}
|
||
|
||
private void ReloadObjects()
|
||
{
|
||
int index = SetslistBox.SelectedIndex;
|
||
SetslistBox.Items.Clear();
|
||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||
{
|
||
SetslistBox.Items.Add(_storage.Keys[i]);
|
||
}
|
||
if (SetslistBox.Items.Count > 0 && (index == -1 || index
|
||
>= SetslistBox.Items.Count))
|
||
{
|
||
SetslistBox.SelectedIndex = 0;
|
||
}
|
||
else if (SetslistBox.Items.Count > 0 && index > -1 &&
|
||
index < SetslistBox.Items.Count)
|
||
{
|
||
SetslistBox.SelectedIndex = index;
|
||
}
|
||
}
|
||
//
|
||
private void ButtonAddStorage_Click(object sender, EventArgs e)
|
||
{
|
||
string storname = setAddBox.Text;
|
||
if (string.IsNullOrEmpty(setAddBox.Text) || _storage.Keys.Contains(storname))
|
||
{
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
_storage.AddSet(setAddBox.Text);
|
||
ReloadObjects();
|
||
}
|
||
|
||
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
pictureBoxCollection.Image =
|
||
_storage[SetslistBox.SelectedItem?.ToString() ?? string.Empty]?.ShowCats();
|
||
}
|
||
|
||
private void ButtonDeleteStorage_Click(object sender, EventArgs e)
|
||
{
|
||
if (SetslistBox.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show($"Удалить набор { SetslistBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
_storage.DelSet(SetslistBox.SelectedItem.ToString()
|
||
?? string.Empty);
|
||
ReloadObjects();
|
||
}
|
||
}
|
||
|
||
private void ButtonAddCatamaran_Click(object sender, EventArgs e)
|
||
{
|
||
if (SetslistBox.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[SetslistBox.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
FormCatamaranConfig form = new();
|
||
form.Show();
|
||
Action<DrawningCatamaran>? catamaranDelegate = new((c) => {
|
||
bool q = (obj + c);
|
||
if (q)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
c.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||
pictureBoxCollection.Image = obj.ShowCats();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
});
|
||
form.AddEvent(catamaranDelegate);
|
||
|
||
}
|
||
|
||
private void ButtonRemoveCatamaran_Click(object sender, EventArgs e)
|
||
{
|
||
if (SetslistBox.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[SetslistBox.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||
{
|
||
return;
|
||
}
|
||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||
if (obj - pos != null)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBoxCollection.Image = obj.ShowCats();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||
{
|
||
if (SetslistBox.SelectedIndex == -1)
|
||
{
|
||
return;
|
||
}
|
||
var obj = _storage[SetslistBox.SelectedItem.ToString() ??
|
||
string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
pictureBoxCollection.Image = obj.ShowCats();
|
||
}
|
||
|
||
}
|
||
}
|