diff --git a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs
index f60cb5b..f909dc6 100644
--- a/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/FormMapWithSetWarmlyShip.cs
@@ -155,15 +155,27 @@ namespace WarmlyShip
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ try
{
- MessageBox.Show("Объект удален");
- pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); ;
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox1.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); ;
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
}
- else
+ catch (WarmlyShipNotFoundException ex)
{
- MessageBox.Show("Не удалось удалить объект");
+ MessageBox.Show($"Ошибка удаления : {ex.Message}");
}
+ catch (Exception ex)
+ {
+ MessageBox.Show($"Неизвестная ошибка : {ex.Message}");
+ }
+
}
///
@@ -237,13 +249,15 @@ namespace WarmlyShip
{
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);
+
}
}
}
@@ -257,14 +271,16 @@ namespace WarmlyShip
// TODO продумать логику
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/WarmlyShip/WarmlyShip/MapsCollection.cs b/WarmlyShip/WarmlyShip/MapsCollection.cs
index b1e7e4c..670ce44 100644
--- a/WarmlyShip/WarmlyShip/MapsCollection.cs
+++ b/WarmlyShip/WarmlyShip/MapsCollection.cs
@@ -98,7 +98,7 @@ namespace WarmlyShip
///
/// Путь и имя файла
///
- public bool SaveData(string filename)
+ public void SaveData(string filename)
{
if (File.Exists(filename))
{
@@ -112,25 +112,24 @@ namespace WarmlyShip
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
}
}
- 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(filename))
{
if (!sr.ReadLine().Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
- return false;
+ throw new Exception("Формат данных в файле не правильный");
}
//очищаем записи
@@ -152,7 +151,6 @@ namespace WarmlyShip
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
}
- return true;
}
}
}
diff --git a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
index 9036562..3292cd8 100644
--- a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
+++ b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
@@ -51,6 +51,7 @@ namespace WarmlyShip
///
public int Insert(T ship, int position)
{
+ //
if (position < 0 || position > Count)
{
return -1;
@@ -69,6 +70,9 @@ namespace WarmlyShip
return null;
var result = _places[position];
_places.RemoveAt(position);
+
+ //throw new WarmlyShipNotFoundException(position);
+
return result;
}
diff --git a/WarmlyShip/WarmlyShip/StorageOverflowException.cs b/WarmlyShip/WarmlyShip/StorageOverflowException.cs
new file mode 100644
index 0000000..24f63c1
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/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 WarmlyShip
+{
+ [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) { }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/WarmlyShipNotFoundException.cs b/WarmlyShip/WarmlyShip/WarmlyShipNotFoundException.cs
new file mode 100644
index 0000000..eb6b165
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/WarmlyShipNotFoundException.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 WarmlyShip
+{
+ [Serializable]
+ internal class WarmlyShipNotFoundException : ApplicationException
+ {
+ public WarmlyShipNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
+ public WarmlyShipNotFoundException() : base() { }
+ public WarmlyShipNotFoundException(string message) : base(message) { }
+ public WarmlyShipNotFoundException(string message, Exception exception) : base(message, exception) { }
+ protected WarmlyShipNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
+ }
+}