Musoev D.T. LabWork07 #7
@ -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 AirplaneWithRadar
|
||||
{
|
||||
[Serializable]
|
||||
internal class AirplaneNotFoundException : ApplicationException
|
||||
{
|
||||
public AirplaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public AirplaneNotFoundException() : base() { }
|
||||
public AirplaneNotFoundException(string message) : base(message) { }
|
||||
public AirplaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected AirplaneNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
@ -85,20 +85,30 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
private void AddAirplane(DrawningAirplane airplane)
|
||||
{
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
try
|
||||
{
|
||||
return;
|
||||
if (ListBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectAirplane(airplane) != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObjectAirplane(airplane) != -1)
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
MessageBox.Show($"Ошибка хранилище переполнено: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
else
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта
|
||||
@ -131,15 +141,25 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
|
||||
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 (AirplaneNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизвестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -253,7 +273,7 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не сохранилось:{ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,20 +26,29 @@
|
||||
// Добавление объекта в набор на конкретную позицию
|
||||
public int Insert(T airplane, int position)
|
||||
{
|
||||
if (position >= _maxCount || position < 0) return -1;
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
if (position < 0 || position > _maxCount) return -1;
|
||||
_places.Insert(position, airplane);
|
||||
return position;
|
||||
}
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _maxCount || position < 0) return null;
|
||||
// удаление объекта из массива, присовив элементу массива значение null
|
||||
T temp = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return temp;
|
||||
}
|
||||
if (position < Count || position > 0)
|
||||
{
|
||||
if (_places.ElementAt(position) != null)
|
||||
{
|
||||
T ship = _places[position];
|
||||
_places.RemoveAt(position);
|
||||
return ship;
|
||||
}
|
||||
throw new AirplaneNotFoundException(position);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Получение объекта из набора по позиции
|
||||
public T this[int position]
|
||||
{
|
||||
|
@ -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 AirplaneWithRadar
|
||||
{
|
||||
[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 context) : base(info, context) { }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user