Изменил(а) на 'HoistingCrane/HoistingCrane/FormMapWithSetHoistingCrane.cs'

Signed-off-by: RomanovEgor <romanov17903@gmail.com>
This commit is contained in:
RomanovEgor 2022-12-25 10:42:46 +04:00 committed by 10Г Егор Романов
parent fadb91ff61
commit 755078a597

View File

@ -12,20 +12,57 @@ namespace HoistingCrane
{ {
public partial class FormMapWithSetHoistingCrane : Form public partial class FormMapWithSetHoistingCrane : Form
{ {
/// Словарь для выпадающего списка
/// </summary>
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Вторая карта", new SecondMap() },
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary>
private MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> _mapHoistingCraneCollectionGeneric; private MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> _mapHoistingCraneCollectionGeneric;
public FormMapWithSetHoistingCrane() public FormMapWithSetHoistingCrane()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
/// <summary>
/// Заполнение listBoxMaps
/// </summary>
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
} }
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{ {
AbstractMap map = null; AbstractMap map = null;
switch (comboBoxSelectorMap.Text) switch (comboBoxSelectorMap.Text)
{ {
case "Первая карта": case ростая карта":
map = new SimpleMap(); map = new SimpleMap();
break; break;
case "Вторая карта": case "Вторая карта":
@ -42,32 +79,74 @@ namespace HoistingCrane
_mapHoistingCraneCollectionGeneric = null; _mapHoistingCraneCollectionGeneric = null;
} }
} }
/// <summary>
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e) /// Добавление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddMap_Click_1(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null) if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
FormHoistingCrane form = new();
if (form.ShowDialog() == DialogResult.OK) if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
DrawingObjectHoistingCrane hoistingCrane = new(form.SelectedHoistingCrane); _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
if (_mapHoistingCraneCollectionGeneric + hoistingCrane == 1) ReloadMaps();
}
}
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
var formHoistingCraneConfig = new FormHoistingCraneConfig();
formHoistingCraneConfig.AddEvent(AddHoistingCrane);
formHoistingCraneConfig.Show();
}
private void AddHoistingCrane(DrawingHoistingCrane drawingHoistingCrane)
{
DrawingObjectHoistingCrane hoistingCrane = new DrawingObjectHoistingCrane(drawingHoistingCrane);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + hoistingCrane != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
}
private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e) private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -76,38 +155,35 @@ namespace HoistingCrane
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapHoistingCraneCollectionGeneric - pos == null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
MessageBox.Show("Не удалось удалить объект"); MessageBox.Show("Не удалось удалить объект");
} }
} }
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowOnMap(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -130,10 +206,5 @@ namespace HoistingCrane
} }
pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums); pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums);
} }
private void pictureBox_Click(object sender, EventArgs e)
{
}
} }
} }