Готово

This commit is contained in:
artur-kalimullin 2024-05-24 22:01:49 +04:00
parent 6f25644d0c
commit 43b355e7dd
4 changed files with 46 additions and 39 deletions

View File

@ -102,10 +102,11 @@ public abstract class AbstractCompany
DrawningAirCraft? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
catch (ObjectNotFoundException e){}
catch (PositionOutOfCollectionException e){}
}
catch (ObjectNotFoundException)
{
}
}
return bitmap;
}

View File

@ -58,8 +58,10 @@ public class AirCraftAngar : AbstractCompany
_collection.Get(currentIndex)?.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
}
}
catch (ObjectNotFoundException e){}
catch (PositionOutOfCollectionException e){}
catch (ObjectNotFoundException)
{
}
currentIndex++;
}
}

View File

@ -1,5 +1,6 @@
using ProjectAirFighter.Drawnings;
using ProjectAirFighter.Exceptions;
using System.Data;
using System.Text;
namespace ProjectAirFighter.CollectionGenericObjects;
@ -93,7 +94,7 @@ public class StorageCollection<T>
{
if (_storages.Count == 0)
{
throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
throw new InvalidDataException("В хранилище отсутствуют коллекции для сохранения");
}
if (File.Exists(filename))
@ -133,7 +134,6 @@ public class StorageCollection<T>
}
writer.Write(sb);
}
}
}
@ -145,7 +145,7 @@ public class StorageCollection<T>
{
if (!File.Exists(filename))
{
throw new FileNotFoundException("Файл не существует");
throw new FileNotFoundException($"{filename} не существует");
}
using (StreamReader fs = File.OpenText(filename))
@ -153,11 +153,11 @@ public class StorageCollection<T>
string str = fs.ReadLine();
if (str == null || str.Length == 0)
{
throw new ArgumentException("В файле нет данных");
throw new FileFormatException("Файл не подходит");
}
if (!str.StartsWith(_collectionKey))
{
throw new InvalidDataException("В файле неверные данные");
throw new IOException("В файле неверные данные");
}
_storages.Clear();
string strs = "";
@ -189,7 +189,7 @@ public class StorageCollection<T>
}
catch (CollectionOverflowException ex)
{
throw new CollectionOverflowException("Коллекция переполнена", ex);
throw new DataException("Коллекция переполнена", ex);
}
}
}

View File

@ -78,7 +78,7 @@ public partial class FormAirCraftCollection : Form
catch (CollectionOverflowException ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"Не удалось добавить объект: {ex.Message}");
_logger.LogError($"Не удалось добавить объект: {ex.Message}");
}
}
@ -91,7 +91,7 @@ public partial class FormAirCraftCollection : Form
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
_logger.LogWarning("Удаление объекта из несуществующей коллекции");
_logger.LogError("Удаление объекта из несуществующей коллекции");
return;
}
@ -105,18 +105,18 @@ public partial class FormAirCraftCollection : Form
{
object decrementObject = _company - pos;
MessageBox.Show("Объект удален");
_logger.LogInformation($"Удален по позиции {pos}");
_logger.LogInformation($"Удален объект по позиции {pos}");
pictureBox.Image = _company.Show();
}
catch (ObjectNotFoundException ex)
catch (ObjectNotFoundException)
{
MessageBox.Show("Объект не найден");
_logger.LogWarning($"Удаление не найденного объекта в позиции {pos} ");
_logger.LogError($"Удаление не найденного объекта в позиции {pos} ");
}
catch (PositionOutOfCollectionException ex)
catch (PositionOutOfCollectionException)
{
MessageBox.Show("Удаление вне рамках коллекции");
_logger.LogWarning($"Удаление объекта за пределами коллекции {pos} ");
_logger.LogError($"Удаление объекта за пределами коллекции {pos} ");
}
}
@ -131,29 +131,33 @@ public partial class FormAirCraftCollection : Form
{
return;
}
DrawningAirCraft? aircraft = null;
int counter = 100;
while (aircraft == null)
try
{
aircraft = _company.GetRandomObject();
counter--;
if (counter <= 0)
DrawningAirCraft? aircraft = null;
int counter = 100;
while (aircraft == null)
{
break;
aircraft = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (aircraft == null)
{
return;
}
FormAirFighter form = new()
{
SetAirCraft = aircraft
};
form.ShowDialog();
}
if (aircraft == null)
catch (ObjectNotFoundException)
{
return;
_logger.LogError("Ошибка при передаче объекта на FormAirFighter");
}
FormAirFighter form = new()
{
SetAirCraft = aircraft
};
form.ShowDialog();
}
/// <summary>
@ -181,7 +185,7 @@ public partial class FormAirCraftCollection : Form
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Не заполненная коллекция");
_logger.LogError("Не заполненная коллекция");
return;
}
@ -210,7 +214,7 @@ public partial class FormAirCraftCollection : Form
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
_logger.LogWarning("Удаление невыбранной коллекции");
_logger.LogError("Удаление невыбранной коллекции");
return;
}
string name = listBoxCollection.SelectedItem.ToString() ?? string.Empty;
@ -248,7 +252,7 @@ public partial class FormAirCraftCollection : Form
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
_logger.LogWarning("Создание компании невыбранной коллекции");
_logger.LogError("Создание компании невыбранной коллекции");
return;
}
@ -256,7 +260,7 @@ public partial class FormAirCraftCollection : Form
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
_logger.LogWarning("Не удалось инициализировать коллекцию");
_logger.LogError("Не удалось инициализировать коллекцию");
return;
}