Генерация ошибок
This commit is contained in:
parent
7636d8c378
commit
02efcdf8be
22
ArmoredCar/ArmoredCar/ArmoredCarNotFoundException.cs
Normal file
22
ArmoredCar/ArmoredCar/ArmoredCarNotFoundException.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredCar
|
||||
{
|
||||
[Serializable]
|
||||
internal class ArmoredCarNotFoundException : ApplicationException
|
||||
{
|
||||
public ArmoredCarNotFoundException(int i) : base($"Не найден объект по позиции{i}") { }
|
||||
public ArmoredCarNotFoundException() : base() { }
|
||||
public ArmoredCarNotFoundException(string message) : base(message) { }
|
||||
public ArmoredCarNotFoundException(string message, Exception exception) :
|
||||
base(message, exception)
|
||||
{ }
|
||||
protected ArmoredCarNotFoundException(SerializationInfo info, StreamingContext
|
||||
contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -229,14 +229,15 @@ namespace ArmoredCar
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат",
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
@ -250,15 +251,16 @@ namespace ArmoredCar
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadMaps();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат",
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace ArmoredCar
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns></returns>
|
||||
public bool SaveData(string filename)
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
@ -99,14 +99,13 @@ namespace ArmoredCar
|
||||
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))
|
||||
{
|
||||
@ -138,8 +137,7 @@ namespace ArmoredCar
|
||||
}
|
||||
_mapStorages.Add(elem[0], new MapWithSetArmoredCarsGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,8 @@ namespace ArmoredCar
|
||||
/// <param name="armoredCar">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T armoredCar)
|
||||
{
|
||||
if (Count < _maxCount)
|
||||
return Insert(armoredCar, 0);
|
||||
return -1;
|
||||
{
|
||||
return Insert(armoredCar, 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -46,6 +44,9 @@ namespace ArmoredCar
|
||||
/// <returns></returns>
|
||||
public int Insert(T armoredCar, int position)
|
||||
{
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException();
|
||||
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return -1;
|
||||
|
||||
@ -62,6 +63,8 @@ namespace ArmoredCar
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
T armoredCar = _places[position];
|
||||
if (armoredCar == null)
|
||||
throw new ArmoredCarNotFoundException();
|
||||
_places.RemoveAt(position);
|
||||
return armoredCar;
|
||||
}
|
||||
|
20
ArmoredCar/ArmoredCar/StorageOverflowException.cs
Normal file
20
ArmoredCar/ArmoredCar/StorageOverflowException.cs
Normal file
@ -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 ArmoredCar
|
||||
{
|
||||
|
||||
[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