2023-11-04 16:22:00 +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 DumpTruck.Generics;
|
|
|
|
|
using DumpTruck.DrawingObjects;
|
|
|
|
|
using DumpTruck.MovementStrategy;
|
|
|
|
|
|
|
|
|
|
namespace DumpTruck
|
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Форма для работы с набором объектов класса DrawingTruck
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class FormTruckCollection : Form
|
|
|
|
|
{
|
2023-11-04 16:22:00 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Набор объектов
|
|
|
|
|
/// </summary>
|
2023-11-04 16:38:42 +04:00
|
|
|
|
private readonly TrucksGenericStorage _storage;
|
|
|
|
|
|
2023-11-04 16:22:00 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public FormTruckCollection()
|
2023-11-04 16:38:42 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_storage = new TrucksGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
2023-11-04 16:22:00 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 16:38:42 +04:00
|
|
|
|
private void ReloadObjects()
|
2023-11-04 16:22:00 +04:00
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
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))
|
2023-11-04 16:22:00 +04:00
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
listBoxStorages.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
|
|
|
|
index < listBoxStorages.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorages.SelectedIndex = index;
|
2023-11-04 16:22:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-04 16:38:42 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавление набора в коллекцию
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonAddObject_Click(object sender, EventArgs e)
|
2023-11-04 16:22:00 +04:00
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
2023-11-04 16:22:00 +04:00
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2023-11-04 16:22:00 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-04 16:38:42 +04:00
|
|
|
|
_storage.AddSet(textBoxStorageName.Text);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Выбор набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTrucks();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаление набора
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void buttonDelObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
2023-11-04 16:22:00 +04:00
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
return;
|
2023-11-04 16:22:00 +04:00
|
|
|
|
}
|
2023-11-04 16:38:42 +04:00
|
|
|
|
if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
|
2023-11-04 16:22:00 +04:00
|
|
|
|
{
|
2023-11-04 16:38:42 +04:00
|
|
|
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
|
|
|
|
ReloadObjects();
|
2023-11-04 16:22:00 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 16:38:42 +04:00
|
|
|
|
private void buttonAddTruck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FormDumpTruck form = new();
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (obj + form.SelectedTruck != -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowTrucks();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-04 16:22:00 +04:00
|
|
|
|
|
2023-11-04 16:38:42 +04:00
|
|
|
|
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление",
|
|
|
|
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
|
|
|
|
if (obj - pos != null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowTrucks();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowTrucks();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-04 16:22:00 +04:00
|
|
|
|
|
|
|
|
|
}
|