Готовая 7 лаба

This commit is contained in:
platoff aeeee 2023-12-24 12:47:59 +04:00
parent 8fed0cc8c9
commit 4b3d7d9694
2 changed files with 17 additions and 17 deletions

View File

@ -1,11 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace Tank.Exceptions
namespace Tank
{ {
[Serializable] [Serializable]
internal class TankStorageOverflowException : ApplicationException internal class TankStorageOverflowException : ApplicationException

View File

@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -12,19 +11,19 @@ using Tank.DrawingObjects;
using Tank.MovementStrategy; using Tank.MovementStrategy;
using Tank.Generics; using Tank.Generics;
using Tank.Exceptions; using Tank.Exceptions;
using Microsoft.Extensions.Logging;
namespace Tank namespace Tank
{ {
public partial class FormArmoredCarCollection : Form public partial class FormArmoredCarCollection : Form
{ {
private readonly TanksGenericStorage _storage; private readonly TanksGenericStorage _storage;
// Логгер
private readonly ILogger _logger; private readonly ILogger _logger;
public FormArmoredCarCollection() public FormArmoredCarCollection(ILogger<FormArmoredCarCollection> logger)
{ {
InitializeComponent(); InitializeComponent();
_storage = new TanksGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); _storage = new TanksGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
_logger = logger;
} }
private void ReloadObjects() private void ReloadObjects()
@ -45,7 +44,6 @@ namespace Tank
} }
public void AddArmoredCar(DrawingArmoredCar tank) public void AddArmoredCar(DrawingArmoredCar tank)
{ {
if (listBoxStorages.SelectedIndex == -1) if (listBoxStorages.SelectedIndex == -1)
{ {
return; return;
@ -56,20 +54,21 @@ namespace Tank
_logger.LogWarning("Добавление пустого объекта"); _logger.LogWarning("Добавление пустого объекта");
return; return;
} }
try _logger.LogInformation("Начало попытки добавления объекта");
{
if ((obj + tank) != false) if ((obj + tank) != false)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowTanks(); pictureBoxCollection.Image = obj.ShowTanks();
_logger.LogInformation($"Добавлен объект {obj}"); _logger.LogInformation($"Добавлен объект {obj}");
} }
} else
catch (TankStorageOverflowException ex)
{ {
_logger.LogWarning($"{ex.Message} в {listBoxStorages.SelectedItem.ToString()}"); TankStorageOverflowException ex = new TankStorageOverflowException();
MessageBox.Show(ex.Message); MessageBox.Show(ex.Message);
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
} }
} }
private void ButtonAddArmoredCar_Click(object sender, EventArgs e) private void ButtonAddArmoredCar_Click(object sender, EventArgs e)