Правки по удалению и логированию.
This commit is contained in:
parent
e5194b35f7
commit
e6dc2035c8
@ -68,6 +68,7 @@ namespace Airbus
|
|||||||
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogInformation("При добавлении карты {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "Не была выбрана карта" : "Не была названа карта");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -75,6 +76,8 @@ namespace Airbus
|
|||||||
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogInformation("Отсутствует карта с названием {0}", textBoxNewMapName.Text);
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,13 +85,14 @@ namespace Airbus
|
|||||||
_mapsCollection.AddMap(textBoxNewMapName.Text,
|
_mapsCollection.AddMap(textBoxNewMapName.Text,
|
||||||
_mapsDict[comboBoxSelectorMap.Text]);
|
_mapsDict[comboBoxSelectorMap.Text]);
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
_logger.LogInformation($"Добавлена карта {textBoxNewMapName.Text}");
|
_logger.LogInformation("Добавлена карта {0}", textBoxNewMapName.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Выбор карты
|
//Выбор карты
|
||||||
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
_logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Удаление карты
|
// Удаление карты
|
||||||
@ -103,24 +107,40 @@ namespace Airbus
|
|||||||
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
|
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
|
_logger.LogInformation("Осуществлён переход на карту под названием {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//отрисовка добавленного объекта в хранилище
|
//отрисовка добавленного объекта в хранилище
|
||||||
private void AddPlane(DrawningAirbus plane)
|
private void AddPlane(DrawningAirbus plane)
|
||||||
{
|
{
|
||||||
if (listBoxMaps.SelectedIndex == -1)
|
try
|
||||||
{
|
{
|
||||||
return;
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectPlane(plane) != -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Объект добавлен");
|
||||||
|
_logger.LogInformation("Добавлен объект {@Airbus}", plane);
|
||||||
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
_logger.LogInformation("Не удалось добавить объект");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectPlane(plane) != -1)
|
catch (StorageOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
_logger.LogWarning("Ошибка, переполнение хранилища: {0}", ex.Message);
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
MessageBox.Show($"Ошибка, хранилище переполнено: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
else
|
catch (ArgumentException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
_logger.LogWarning("Ошибка добавления: {0}. Объект: {@Airbus}", ex.Message, plane);
|
||||||
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -136,7 +156,7 @@ namespace Airbus
|
|||||||
//удаление объекта
|
//удаление объекта
|
||||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -151,18 +171,23 @@ namespace Airbus
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] - pos != null)
|
var deletedPlane = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos;
|
||||||
|
|
||||||
|
if (deletedPlane != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удалён");
|
MessageBox.Show("Объект удалён");
|
||||||
|
_logger.LogInformation("Из текущей карты удалён объект {@Airbus}", deletedPlane);
|
||||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
|
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation("Не удалось удалить объект по позиции {0}. Объект равен null", pos);
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (PlaneNotFoundException ex)
|
catch (PlaneNotFoundException ex)
|
||||||
{
|
{
|
||||||
|
_logger.LogWarning("Неизвестная ошибка удаления: {0}", ex.Message);
|
||||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -230,17 +255,17 @@ namespace Airbus
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||||
|
_logger.LogInformation("Сохранение прошло успешно. Расположение файла: {0}", saveFileDialog.FileName);
|
||||||
|
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogInformation("Не удалось сохранить файл '{0}'. Текст ошибки: {1}", saveFileDialog.FileName, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,6 +278,7 @@ namespace Airbus
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||||
|
_logger.LogInformation("Загрузка данных из файла '{0}' прошла успешно", openFileDialog.FileName);
|
||||||
|
|
||||||
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
|
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
@ -261,6 +287,7 @@ namespace Airbus
|
|||||||
{
|
{
|
||||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogInformation("Не удалось загрузить файл '{0}'. Текст ошибки: {1}", openFileDialog.FileName, ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,11 @@ namespace Airbus
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return null;
|
throw new PlaneNotFoundException(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
//TODO проверка позиции???
|
|
||||||
//что-то типа throw new PlaneNotFoundException(position);
|
|
||||||
|
|
||||||
//получение объекта из набора по позиции
|
//получение объекта из набора по позиции
|
||||||
public T this[int position]
|
public T this[int position]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user