2023-11-30 02:11:18 +04:00
|
|
|
|
using Bulldozer;
|
|
|
|
|
using ProjectBulldozer.Generics;
|
2023-12-13 17:38:05 +04:00
|
|
|
|
using ProjectBulldozer.Drawning;
|
2023-12-13 18:22:58 +04:00
|
|
|
|
using System.ComponentModel;
|
2023-12-13 17:38:05 +04:00
|
|
|
|
|
2023-11-30 02:11:18 +04:00
|
|
|
|
namespace ProjectBulldozer
|
|
|
|
|
{
|
|
|
|
|
public partial class FormTractorCollections : Form
|
|
|
|
|
{
|
2023-11-30 02:46:03 +04:00
|
|
|
|
private readonly TractorGenericStorage _storage;
|
2023-12-13 18:22:58 +04:00
|
|
|
|
private readonly TractorGenericCollection<DrawingTractor, DrawingObjectTractor> _tractors;
|
2023-12-13 17:38:05 +04:00
|
|
|
|
readonly int countPlace = 10;
|
2023-11-30 02:11:18 +04:00
|
|
|
|
public FormTractorCollections()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-11-30 02:46:03 +04:00
|
|
|
|
_storage = new TractorGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
|
|
|
|
|
}
|
|
|
|
|
private void ReloadObjects()
|
|
|
|
|
{
|
|
|
|
|
int index = listBoxStorage.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
listBoxStorage.Items.Clear();
|
|
|
|
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
|
|
|
|
}
|
|
|
|
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count))
|
|
|
|
|
{
|
|
|
|
|
listBoxStorage.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (listBoxStorage.Items.Count > 0 && index > -1 && index < listBoxStorage.Items.Count)
|
|
|
|
|
{
|
|
|
|
|
listBoxStorage.SelectedIndex = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
pictureBoxCollections.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowTractors();
|
|
|
|
|
}
|
|
|
|
|
private void ButtonRemoveObject_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorage.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
_storage.DelSet(listBoxStorage.SelectedItem.ToString() ?? string.Empty);
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
2023-11-30 02:11:18 +04:00
|
|
|
|
}
|
|
|
|
|
private void ButtonAddTractor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-12-13 18:22:58 +04:00
|
|
|
|
if (listBoxStorage.SelectedIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-13 17:38:05 +04:00
|
|
|
|
var formBulldozerConfig = new FormBulldozerConfig();
|
|
|
|
|
formBulldozerConfig.AddEvent(AddTractor);
|
|
|
|
|
formBulldozerConfig.Show();
|
|
|
|
|
}
|
|
|
|
|
private void AddTractor(DrawingTractor tractor)
|
|
|
|
|
{
|
|
|
|
|
tractor._pictureWidth = pictureBoxCollections.Width;
|
|
|
|
|
tractor._pictureHeight = pictureBoxCollections.Height;
|
2023-11-30 02:46:03 +04:00
|
|
|
|
|
|
|
|
|
if (listBoxStorage.SelectedIndex == -1) return;
|
|
|
|
|
|
|
|
|
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
2023-12-13 17:38:05 +04:00
|
|
|
|
|
2023-11-30 02:46:03 +04:00
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-13 17:38:05 +04:00
|
|
|
|
int addedIndex = obj + tractor;
|
|
|
|
|
if (addedIndex != -1 && addedIndex < countPlace)
|
2023-11-30 02:11:18 +04:00
|
|
|
|
{
|
2023-12-13 17:38:05 +04:00
|
|
|
|
MessageBox.Show("Объект добавлен");
|
|
|
|
|
pictureBoxCollections.Image = obj.ShowTractors();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось добавить объект");
|
|
|
|
|
|
|
|
|
|
|
2023-11-30 02:11:18 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2023-11-30 02:46:03 +04:00
|
|
|
|
if (listBoxStorage.SelectedIndex == -1) return;
|
|
|
|
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 02:11:18 +04:00
|
|
|
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
2023-11-30 02:46:03 +04:00
|
|
|
|
if (obj - pos != null)
|
2023-11-30 02:11:18 +04:00
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Объект удален");
|
2023-11-30 02:46:03 +04:00
|
|
|
|
pictureBoxCollections.Image = obj.ShowTractors();
|
2023-11-30 02:11:18 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не удалось удалить объект");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-13 18:22:58 +04:00
|
|
|
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (listBoxStorage.SelectedIndex == -1) return;
|
|
|
|
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pictureBoxCollections.Image = obj.ShowTractors();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 saveFileDialog_FileOk(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openFileDialog_FileOk(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void файлToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
if (_storage.LoadData(openFileDialog.FileName))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Загрузка прошло успешно",
|
|
|
|
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Не загрузилось", "Результат",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
ReloadObjects();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-30 02:11:18 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-13 18:22:58 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|