167 lines
5.2 KiB
C#
167 lines
5.2 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;
|
||
using DumpTruck.Generics;
|
||
using DumpTruck.DrawingObjects;
|
||
using DumpTruck.MovementStrategy;
|
||
|
||
namespace DumpTruck
|
||
{
|
||
/// <summary>
|
||
/// Форма для работы с набором объектов класса DrawingTruck
|
||
/// </summary>
|
||
public partial class FormTruckCollection : Form
|
||
{
|
||
/// <summary>
|
||
/// Набор объектов
|
||
/// </summary>
|
||
private readonly TrucksGenericStorage _storage;
|
||
|
||
/// <summary>
|
||
/// Конструктор
|
||
/// </summary>
|
||
public FormTruckCollection()
|
||
{
|
||
InitializeComponent();
|
||
_storage = new TrucksGenericStorage(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;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Добавление набора в коллекцию
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
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();
|
||
}
|
||
/// <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)
|
||
{
|
||
return;
|
||
}
|
||
if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
|
||
{
|
||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||
ReloadObjects();
|
||
}
|
||
}
|
||
|
||
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("Не удалось добавить объект");
|
||
}
|
||
}
|
||
}
|
||
|
||
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();
|
||
}
|
||
}
|
||
|
||
}
|