Генерация ошибок
This commit is contained in:
parent
c050a5b51f
commit
3f9f13fd89
@ -120,6 +120,8 @@ namespace AirPlaneWithRadar
|
||||
}
|
||||
if (maskedTextBoxPosition.Text == null)
|
||||
return;
|
||||
try
|
||||
{
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null)
|
||||
{
|
||||
@ -130,6 +132,13 @@ namespace AirPlaneWithRadar
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}catch(PlainNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Wrong id");
|
||||
}catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error of delete");
|
||||
}
|
||||
}
|
||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -175,16 +184,18 @@ namespace AirPlaneWithRadar
|
||||
}
|
||||
private void SaveToolStrip_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
catch(Exception ex) {
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,17 +203,20 @@ namespace AirPlaneWithRadar
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.LoadData(openFileDialog.FileName) && _mapsCollection.Count != 0)
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось загрузить", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadMaps();
|
||||
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось загрузить", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ namespace AirPlaneWithRadar
|
||||
return _mapStorages[ind];
|
||||
}
|
||||
}
|
||||
public bool SaveData(string filename)
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
@ -69,22 +69,22 @@ namespace AirPlaneWithRadar
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool LoadData(string filename)
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("File not found");
|
||||
}
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
if (!sr.ReadLine().Equals("MapsCollection"))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Wrong file");
|
||||
}
|
||||
_mapStorages.Clear();
|
||||
string line = sr.ReadLine();
|
||||
@ -109,7 +109,7 @@ namespace AirPlaneWithRadar
|
||||
line = sr.ReadLine();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
[Serializable]
|
||||
internal class PlainNotFoundException : ApplicationException
|
||||
{
|
||||
public PlainNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public PlainNotFoundException() : base() { }
|
||||
public PlainNotFoundException(string message) : base(message) { }
|
||||
public PlainNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected PlainNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirPlaneWithRadar
|
||||
{
|
||||
[Serializable]
|
||||
internal class StorageOverFullException : ApplicationException
|
||||
{
|
||||
public StorageOverFullException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
|
||||
public StorageOverFullException() : base() { }
|
||||
public StorageOverFullException(string message) : base(message) { }
|
||||
public StorageOverFullException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverFullException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user