Генерация ошибок
This commit is contained in:
parent
7a9c7c16a2
commit
fa9031723a
@ -131,24 +131,6 @@ namespace Trolleybus
|
||||
|
||||
formTrolleybusConfig.AddEvent(AddTrolleybus);
|
||||
formTrolleybusConfig.Show();
|
||||
/*if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Form1 form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawningObjectTrolleybus tractor = new(form.SelectedTrolleybus);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + tractor != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
@ -162,15 +144,26 @@ namespace Trolleybus
|
||||
{
|
||||
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();
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
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 (TrolleybusNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -235,13 +228,14 @@ namespace Trolleybus
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,10 @@ namespace Trolleybus
|
||||
// Добавление объекта в набор
|
||||
public int Insert(T trolleybus)
|
||||
{
|
||||
if (_places.Count > _maxCount)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// вставка в начало набора
|
||||
return Insert(trolleybus, 0);
|
||||
}
|
||||
|
19
Trolleybus/Trolleybus/StorageOverflowException.cs
Normal file
19
Trolleybus/Trolleybus/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;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Trolleybus
|
||||
{
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(int count) : base($"В наборе превышино количество: {count} элементов") { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -89,7 +89,9 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SetTrolleybusGeneric.cs" />
|
||||
<Compile Include="SimpleMap.cs" />
|
||||
<Compile Include="StorageOverflowException.cs" />
|
||||
<Compile Include="TrolleybusDelegate.cs" />
|
||||
<Compile Include="TrolleybusNotFoundException.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
18
Trolleybus/Trolleybus/TrolleybusNotFoundException.cs
Normal file
18
Trolleybus/Trolleybus/TrolleybusNotFoundException.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Trolleybus
|
||||
{
|
||||
internal class TrolleybusNotFoundException : ApplicationException
|
||||
{
|
||||
public TrolleybusNotFoundException() : base() { }
|
||||
public TrolleybusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public TrolleybusNotFoundException(string message) : base(message) { }
|
||||
public TrolleybusNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected TrolleybusNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user