Третья лабораторная работа

This commit is contained in:
10Г Егор Романов 2022-10-10 19:53:02 +03:00
parent 72344e2aa5
commit 446f363f01
2 changed files with 16 additions and 68 deletions

View File

@ -18,40 +18,14 @@ namespace HoistingCrane
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 "Первая карта":
map = new SimpleMap(); map = new SimpleMap();
break; break;
case "Вторая карта": case "Вторая карта":
@ -68,56 +42,21 @@ namespace HoistingCrane
_mapHoistingCraneCollectionGeneric = null; _mapHoistingCraneCollectionGeneric = null;
} }
} }
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonAddMap_Click_1(object sender, EventArgs e)
{
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;
}
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private void ButtonAddHoistingCrane_Click(object sender, EventArgs e) private void ButtonAddHoistingCrane_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null)
{ {
return; return;
} }
FormHoistingCrane form = new();
if (form.ShowDialog() == DialogResult.OK)
{ {
DrawingObjectHoistingCrane hoistingCrane = new(form.SelectedHoistingCrane);
if (_mapHoistingCraneCollectionGeneric + hoistingCrane == 1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet();
} }
else else
{ {
@ -128,6 +67,7 @@ namespace HoistingCrane
private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e) private void ButtonRemoveHoistingCrane_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
} }
@ -136,8 +76,10 @@ namespace HoistingCrane
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapHoistingCraneCollectionGeneric - pos == null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet();
} }
else else
{ {
@ -147,20 +89,25 @@ namespace HoistingCrane
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null)
{ {
return; return;
} }
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowSet();
} }
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null)
{ {
return; return;
} }
pictureBox.Image = _mapHoistingCraneCollectionGeneric.ShowOnMap();
} }
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapHoistingCraneCollectionGeneric == null)
{ {
return; return;
} }

View File

@ -107,6 +107,7 @@ namespace HoistingCrane
} }
} }
private void DrawBulldozers(Graphics gr)
{ {
int heightEl = _pictureHeight / _placeSizeHeight; int heightEl = _pictureHeight / _placeSizeHeight;
int widthEl = _pictureWidth / _placeSizeWidth; int widthEl = _pictureWidth / _placeSizeWidth;