Генерация ошибок.
This commit is contained in:
parent
14708bf7c6
commit
dfbed5bdd5
@ -122,6 +122,8 @@ namespace Airbus
|
|||||||
//добавление объекта
|
//добавление объекта
|
||||||
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
//ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ ВСТАВКИ
|
||||||
|
|
||||||
var formPlaneConfig = new FormPlaneConfig();
|
var formPlaneConfig = new FormPlaneConfig();
|
||||||
|
|
||||||
formPlaneConfig.AddEvent(AddPlane);
|
formPlaneConfig.AddEvent(AddPlane);
|
||||||
@ -130,6 +132,8 @@ namespace Airbus
|
|||||||
//удаление объекта
|
//удаление объекта
|
||||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
//ВСТАВИТЬ ПРОВЕРКУ НА ВОЗМОЖНОСТЬ УДАЛЕНИЯ
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -143,6 +147,8 @@ namespace Airbus
|
|||||||
|
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] - pos != null)
|
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удалён");
|
MessageBox.Show("Объект удалён");
|
||||||
@ -153,6 +159,15 @@ namespace Airbus
|
|||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (PlaneNotFoundException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//вывод набора
|
//вывод набора
|
||||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
@ -211,14 +226,18 @@ namespace Airbus
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||||
|
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не сохранилось", "Результат",
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,15 +248,16 @@ namespace Airbus
|
|||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_mapsCollection.LoadData(openFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
ReloadMaps();
|
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||||
|
|
||||||
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
|
MessageBox.Show("Загрузка данных прошла успешно", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Ошибка загрузки данных", "Результат",
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ namespace Airbus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// сохранение информации по автомобилям в хранилище в файл
|
// сохранение информации по самолётам в ангарах в файл
|
||||||
public bool SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
@ -71,16 +71,14 @@ namespace Airbus
|
|||||||
$"{Environment.NewLine}");
|
$"{Environment.NewLine}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// загрузка информации по автомобилям на парковках из файла
|
// загрузка информации по самолётам в ангарах из файла
|
||||||
public bool LoadData(string filename)
|
public void LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Файл не найден");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamReader sr = new(filename))
|
using (StreamReader sr = new(filename))
|
||||||
@ -90,7 +88,7 @@ namespace Airbus
|
|||||||
//если не содержит такую запись или пустой файл
|
//если не содержит такую запись или пустой файл
|
||||||
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
|
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Формат данных в файле неправильный");
|
||||||
}
|
}
|
||||||
|
|
||||||
_mapStorage.Clear();
|
_mapStorage.Clear();
|
||||||
@ -117,8 +115,6 @@ namespace Airbus
|
|||||||
_mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
_mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//доступ к аэродрому
|
//доступ к аэродрому
|
||||||
|
24
Airbus/Airbus/PlaneNotFoundException.cs
Normal file
24
Airbus/Airbus/PlaneNotFoundException.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
|
||||||
|
//класс собственных исключений
|
||||||
|
internal class PlaneNotFoundException: ApplicationException
|
||||||
|
{
|
||||||
|
public PlaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
|
||||||
|
public PlaneNotFoundException() : base() { }
|
||||||
|
|
||||||
|
public PlaneNotFoundException(string message) : base(message) { }
|
||||||
|
|
||||||
|
public PlaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
|
||||||
|
protected PlaneNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
@ -64,6 +64,8 @@ namespace Airbus
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
//TODO проверка позиции???
|
||||||
|
//что-то типа throw new PlaneNotFoundException(position);
|
||||||
|
|
||||||
//получение объекта из набора по позиции
|
//получение объекта из набора по позиции
|
||||||
public T this[int position]
|
public T this[int position]
|
||||||
|
24
Airbus/Airbus/StorageOverflowException.cs
Normal file
24
Airbus/Airbus/StorageOverflowException.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Airbus
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
|
||||||
|
//класс собственных исключений
|
||||||
|
internal class StorageOverflowException : ApplicationException
|
||||||
|
{
|
||||||
|
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||||
|
|
||||||
|
public StorageOverflowException() : base() { }
|
||||||
|
|
||||||
|
public StorageOverflowException(string message) : base(message) { }
|
||||||
|
|
||||||
|
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
|
||||||
|
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user