diff --git a/AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs
new file mode 100644
index 0000000..5e75f45
--- /dev/null
+++ b/AntiAircraftGun/AntiAircraftGun/AntiAircraftGunNotFoundException.cs
@@ -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) { }
+ }
+}
diff --git a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs
index f8af888..428b465 100644
--- a/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs
+++ b/AntiAircraftGun/AntiAircraftGun/FormMapWithSetAntiAircraftGuns.cs
@@ -150,14 +150,25 @@ namespace AntiAircraftGun
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ try
{
- MessageBox.Show("Объект удален");
- pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
}
- else
+ catch (AntiAircraftGunNotFoundException ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show($"Ошибка удаления {ex.Message}");
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Неизвестная ошибка {ex.Message}");
}
}
///
@@ -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);
}
}
}
diff --git a/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs b/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs
index 02de5e8..8d88567 100644
--- a/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs
+++ b/AntiAircraftGun/AntiAircraftGun/MapsCollection.cs
@@ -78,7 +78,7 @@ namespace AntiAircraftGun
///
/// Путь и имя файла
///
- 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;
}
///
/// Загрузка нформации по орудиям на парковках из файла
///
///
///
- 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(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
- return true;
}
}
}
diff --git a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs
index 9807595..e512797 100644
--- a/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs
+++ b/AntiAircraftGun/AntiAircraftGun/SetAntiAircraftGunsGeneric.cs
@@ -56,6 +56,7 @@ namespace AntiAircraftGun
///
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
///
public T Remove(int position)
{
+ //TODO исключение
if (position < 0 || position >= _places.Count) return null;
if (_places[position] == null) return null;
T removed = _places[position];
diff --git a/AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs b/AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs
new file mode 100644
index 0000000..ebeb2d7
--- /dev/null
+++ b/AntiAircraftGun/AntiAircraftGun/StorageOverflowException.cs
@@ -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) { }
+ }
+}