2023-10-04 12:52:06 +04:00
|
|
|
|
using Lab.DrawningObjects;
|
|
|
|
|
using Lab.Generics;
|
|
|
|
|
using Lab.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;
|
|
|
|
|
|
|
|
|
|
namespace Lab
|
|
|
|
|
{
|
|
|
|
|
public partial class CollectionsFrame : Form
|
|
|
|
|
{
|
2023-10-18 12:24:01 +04:00
|
|
|
|
private readonly CarsGenericStorage _storage;
|
2023-10-04 12:52:06 +04:00
|
|
|
|
public CollectionsFrame()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-10-18 12:24:01 +04:00
|
|
|
|
_storage = new CarsGenericStorage(DrawTank.Width, DrawTank.Height);
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
2023-10-18 12:24:01 +04:00
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = CollectionListBox.SelectedIndex;
|
|
|
|
|
CollectionListBox.Items.Clear();
|
|
|
|
|
foreach (var key in _storage.Keys)
|
|
|
|
|
{
|
|
|
|
|
CollectionListBox.Items.Add(key);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
2023-10-04 12:52:06 +04:00
|
|
|
|
{
|
2023-10-18 12:24:01 +04:00
|
|
|
|
if (string.IsNullOrEmpty(SetTextBox.Text))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_storage.AddSet(SetTextBox.Text);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
private void ListBoxObjects_SelectedIndexChanged(object sender,
|
|
|
|
|
EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DrawTank.Image =
|
|
|
|
|
_storage[CollectionListBox.SelectedItem?.ToString() ?? string.Empty]?.ShowCars();
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-15 10:25:49 +04:00
|
|
|
|
|
2023-11-14 23:39:34 +04:00
|
|
|
|
private void AddTanker(DrawTanker tanker)
|
2023-10-18 12:24:01 +04:00
|
|
|
|
{
|
2023-11-15 10:25:49 +04:00
|
|
|
|
|
2023-10-18 12:24:01 +04:00
|
|
|
|
var obj = _storage[CollectionListBox.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-14 23:39:34 +04:00
|
|
|
|
if (obj + tanker)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
DrawTank.Image = obj.ShowCars();
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-10-04 12:52:06 +04:00
|
|
|
|
{
|
2023-11-14 23:39:34 +04:00
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonAddCar_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
2023-11-14 23:39:34 +04:00
|
|
|
|
FormTankerConfig form = new FormTankerConfig();
|
|
|
|
|
form.Show();
|
|
|
|
|
form.AddEvent(AddTanker);
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-10-18 12:24:01 +04:00
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[CollectionListBox.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
2023-10-04 12:52:06 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-18 12:24:01 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
2023-10-04 12:52:06 +04:00
|
|
|
|
{
|
2023-10-18 12:24:01 +04:00
|
|
|
|
return;
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
2023-10-18 12:24:01 +04:00
|
|
|
|
int pos = Convert.ToInt32(CarTextBox.Text);
|
|
|
|
|
if (obj - pos != null)
|
2023-10-04 12:52:06 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-10-18 12:24:01 +04:00
|
|
|
|
DrawTank.Image = obj.ShowCars();
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-18 12:24:01 +04:00
|
|
|
|
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
|
|
|
|
e)
|
2023-10-04 12:52:06 +04:00
|
|
|
|
{
|
2023-10-18 12:24:01 +04:00
|
|
|
|
if (CollectionListBox.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[CollectionListBox.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DrawTank.Image = obj.ShowCars();
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
2023-11-15 10:25:49 +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();
|
|
|
|
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-04 12:52:06 +04:00
|
|
|
|
}
|
|
|
|
|
}
|