Генерация ошибок
This commit is contained in:
parent
f76229aecc
commit
a74bda99cf
@ -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 AntiAircraftGun
|
||||
{
|
||||
[Serializable]
|
||||
internal class AntiAircraftGunNotFoundException : ApplicationException
|
||||
{
|
||||
public AntiAircraftGunNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public AntiAircraftGunNotFoundException() : base() { }
|
||||
public AntiAircraftGunNotFoundException(string message) : base(message) { }
|
||||
public AntiAircraftGunNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected AntiAircraftGunNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -150,6 +150,8 @@ namespace AntiAircraftGun
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
try
|
||||
{
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
@ -160,6 +162,15 @@ namespace AntiAircraftGun
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
catch (AntiAircraftGunNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show($"Ошибка удаления {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод набора
|
||||
/// </summary>
|
||||
@ -226,13 +237,14 @@ namespace AntiAircraftGun
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не сохранилось {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,14 +257,15 @@ namespace AntiAircraftGun
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadMaps();
|
||||
}
|
||||
else
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не загрузилось {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ namespace AntiAircraftGun
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns></returns>
|
||||
public bool SaveData(string filename)
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
@ -92,18 +92,17 @@ namespace AntiAircraftGun
|
||||
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка нформации по орудиям на парковках из файла
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public bool LoadData(string filename)
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
@ -112,7 +111,7 @@ namespace AntiAircraftGun
|
||||
str = sr.ReadLine();
|
||||
if (!str.Contains("MapsCollection"))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Формат данных в файле неправильный");
|
||||
}
|
||||
while ((str = sr.ReadLine()) != null)
|
||||
{
|
||||
@ -130,7 +129,6 @@ namespace AntiAircraftGun
|
||||
_mapStorages.Add(elem[0], new MapWithSetAntiAircraftGunsGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ namespace AntiAircraftGun
|
||||
/// <returns></returns>
|
||||
public int Insert(T antiAircraftGun, int position)
|
||||
{
|
||||
//TODO проверка на _maxCount
|
||||
if (position < 0 || position >= _places.Count) return -1;
|
||||
_places.Insert(position, antiAircraftGun);
|
||||
return position;
|
||||
@ -67,6 +68,7 @@ namespace AntiAircraftGun
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
//TODO исключение
|
||||
if (position < 0 || position >= _places.Count) return null;
|
||||
if (_places[position] == null) return null;
|
||||
T removed = _places[position];
|
||||
|
19
AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs
Normal file
19
AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs
Normal file
@ -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 AntiAircraftGun
|
||||
{
|
||||
[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…
Reference in New Issue
Block a user