Генерация ошибок
This commit is contained in:
parent
7a9c7c16a2
commit
fa9031723a
@ -131,24 +131,6 @@ namespace Trolleybus
|
|||||||
|
|
||||||
formTrolleybusConfig.AddEvent(AddTrolleybus);
|
formTrolleybusConfig.AddEvent(AddTrolleybus);
|
||||||
formTrolleybusConfig.Show();
|
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>
|
/// <summary>
|
||||||
/// Удаление объекта
|
/// Удаление объекта
|
||||||
@ -162,15 +144,26 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
try
|
||||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
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 (TrolleybusNotFoundException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -235,13 +228,14 @@ namespace Trolleybus
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
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)
|
public int Insert(T trolleybus)
|
||||||
{
|
{
|
||||||
|
if (_places.Count > _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
// вставка в начало набора
|
// вставка в начало набора
|
||||||
return Insert(trolleybus, 0);
|
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="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="SetTrolleybusGeneric.cs" />
|
<Compile Include="SetTrolleybusGeneric.cs" />
|
||||||
<Compile Include="SimpleMap.cs" />
|
<Compile Include="SimpleMap.cs" />
|
||||||
|
<Compile Include="StorageOverflowException.cs" />
|
||||||
<Compile Include="TrolleybusDelegate.cs" />
|
<Compile Include="TrolleybusDelegate.cs" />
|
||||||
|
<Compile Include="TrolleybusNotFoundException.cs" />
|
||||||
<EmbeddedResource Include="Form1.resx">
|
<EmbeddedResource Include="Form1.resx">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</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…
x
Reference in New Issue
Block a user