169 lines
5.6 KiB
C#
169 lines
5.6 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 ProjectGasolineTanker.Generic;
|
||
using ProjectGasolineTanker.Drawings;
|
||
using ProjectGasolineTanker.MovementStratg;
|
||
using ProjectGasolineTanker;
|
||
|
||
namespace ProjectGasolineTanker
|
||
{
|
||
public partial class FormTruckCollection : Form
|
||
{
|
||
// Набор объектов
|
||
private readonly TruckGenericStorage _storage;
|
||
|
||
public FormTruckCollection()
|
||
{
|
||
InitializeComponent();
|
||
_storage = new TruckGenericStorage(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;
|
||
}
|
||
|
||
}
|
||
|
||
// добавить набор в коллекцию
|
||
private void buttonAddStorage_Click(object sender, EventArgs e)
|
||
{
|
||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||
{
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
_storage.AddSet(textBoxStorageName.Text);
|
||
ReloadObjects();
|
||
}
|
||
|
||
// выбрать набор
|
||
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||
{
|
||
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTruck();
|
||
}
|
||
|
||
// удалить набор
|
||
private void buttonDeleteStorage_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)
|
||
{
|
||
|
||
var formTruckConfig = new FormTruckConfig();
|
||
|
||
formTruckConfig.AddEvent(AddTruck);
|
||
formTruckConfig.Show();
|
||
}
|
||
|
||
private void AddTruck(DrawingTruck selectedTruck)
|
||
{
|
||
if (listBoxStorages.SelectedIndex == -1)
|
||
{
|
||
MessageBox.Show("Не выбран набор");
|
||
return;
|
||
}
|
||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||
if (obj == null)
|
||
{
|
||
return;
|
||
}
|
||
selectedTruck.ChangePictureSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||
if (obj + selectedTruck != -1)
|
||
{
|
||
MessageBox.Show("Объект добавлен");
|
||
pictureBoxCollection.Image = obj.ShowTruck();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось добавить объект");
|
||
}
|
||
}
|
||
|
||
|
||
private void buttonDeleteTruck_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 = 0;
|
||
try
|
||
{
|
||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||
}
|
||
catch
|
||
{
|
||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
if (obj - pos)
|
||
{
|
||
MessageBox.Show("Объект удален");
|
||
pictureBoxCollection.Image = obj.ShowTruck();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Не удалось удалить объект");
|
||
}
|
||
}
|
||
|
||
// обновить рисунок по набору
|
||
private void buttonUpdate_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.ShowTruck();
|
||
}
|
||
|
||
|
||
}
|
||
}
|