ISE_22.Aparyan.Bulldozer.Base/ProjectBulldozer/FormBulldozerCollections.cs

120 lines
4.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Bulldozer;
using ProjectBulldozer.Generics;
namespace ProjectBulldozer
{
public partial class FormTractorCollections : Form
{
private readonly TractorGenericStorage _storage;
//private readonly TractorGenericCollection<DrawingTractor, DrawingObjectTractor> _Tractors;
public FormTractorCollections()
{
InitializeComponent();
_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();
}
}
private void ButtonAddTractor_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1) return;
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormBulldozer form = new();
if (form.ShowDialog() == DialogResult.OK)
{
//проверяем, удалось ли нам загрузить объект
if (obj + form.SelectedTractor > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollections.Image = obj.ShowTractors();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1) return;
var obj = _storage[listBoxStorage.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("Объект удален");
pictureBoxCollections.Image = obj.ShowTractors();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
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();
}
}
}