2024-10-03 01:19:45 +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 ProjectGasolineTanker.Generic;
|
2024-10-03 01:21:27 +04:00
|
|
|
|
using ProjectGasolineTanker.Drawings;
|
2024-10-03 01:19:45 +04:00
|
|
|
|
using ProjectGasolineTanker.MovementStratg;
|
2024-10-03 01:21:27 +04:00
|
|
|
|
using ProjectGasolineTanker;
|
2024-10-03 01:19:45 +04:00
|
|
|
|
|
|
|
|
|
namespace ProjectGasolineTanker
|
|
|
|
|
{
|
|
|
|
|
public partial class FormTruckCollection : Form
|
|
|
|
|
{
|
|
|
|
|
|
2024-10-03 01:21:27 +04:00
|
|
|
|
private readonly TruckGenericStorage _storage;
|
2024-10-03 01:19:45 +04:00
|
|
|
|
|
|
|
|
|
public FormTruckCollection()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-10-03 01:21:27 +04:00
|
|
|
|
_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;
|
|
|
|
|
}
|
2024-10-03 01:19:45 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 01:21:27 +04:00
|
|
|
|
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)
|
2024-10-03 01:19:45 +04:00
|
|
|
|
{
|
2024-10-03 01:21:27 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не выбран набор");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-03 01:19:45 +04:00
|
|
|
|
FormGasolineTanker form = new();
|
2024-10-03 01:21:27 +04:00
|
|
|
|
|
2024-10-03 01:19:45 +04:00
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
2024-10-03 01:21:27 +04:00
|
|
|
|
if (obj + form.SelectedTruck != -1)
|
2024-10-03 01:19:45 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект добавлен");
|
2024-10-03 01:21:27 +04:00
|
|
|
|
pictureBoxCollection.Image = obj.ShowTruck();
|
2024-10-03 01:19:45 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 01:21:27 +04:00
|
|
|
|
private void buttonDeleteTruck_Click(object sender, EventArgs e)
|
2024-10-03 01:19:45 +04:00
|
|
|
|
{
|
2024-10-03 01:21:27 +04:00
|
|
|
|
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)
|
2024-10-03 01:19:45 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-10-03 01:21:27 +04:00
|
|
|
|
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
2024-10-03 01:19:45 +04:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2024-10-03 01:21:27 +04:00
|
|
|
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2024-10-03 01:19:45 +04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2024-10-03 01:21:27 +04:00
|
|
|
|
if (obj - pos)
|
2024-10-03 01:19:45 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2024-10-03 01:21:27 +04:00
|
|
|
|
pictureBoxCollection.Image = obj.ShowTruck();
|
2024-10-03 01:19:45 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 01:21:27 +04:00
|
|
|
|
|
|
|
|
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
2024-10-03 01:19:45 +04:00
|
|
|
|
{
|
2024-10-03 01:21:27 +04:00
|
|
|
|
if (listBoxStorages.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
|
|
|
|
string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollection.Image = obj.ShowTruck();
|
2024-10-03 01:19:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|