Final Commit

This commit is contained in:
shadowik 2022-12-11 21:44:32 +04:00
parent 0eb06f89e2
commit a20bad8336
6 changed files with 38 additions and 13 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -8,13 +9,22 @@ namespace DoubleDeckerBus
{
internal class DrawingObjectBus : IDrawingObject
{
private DrawingBus _bus = null;
public DrawingBus? _bus = null;
public DrawingObjectBus(DrawingBus bus)
{
_bus = bus;
}
public DrawingBus? Get_bus()
{
return _bus;
}
public DrawingBus getBus(DrawingBus? _bus) {
return _bus;
}
public float Step => _bus?.Bus?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
@ -22,7 +32,7 @@ namespace DoubleDeckerBus
return _bus?.GetCurrentPosition() ?? default;
}
public string GetInfo()
public string? GetInfo()
{
return _bus?.GetDataForSave();
}

View File

@ -60,7 +60,6 @@ namespace DoubleDeckerBus
var formBusConfig = new FormBusConfig();
formBusConfig.AddEvent(AddBus);
formBusConfig.Show();
}
private void AddBus(DrawingBus bus)
@ -69,17 +68,22 @@ namespace DoubleDeckerBus
{
return;
}
DrawingObjectBus boat = new(bus);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0)
try
{
DrawingObjectBus _bus = new(bus);
_ = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + _bus;
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_logger.LogInformation($"Объект добавлен");
}
else
catch (StorageOverflowException ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogInformation($"Объект не добаавлен");
MessageBox.Show($"Не удалось добавить объект {ex.Message}");
_logger.LogInformation($"Объект не добаавлен {ex.Message}");
}
catch (Exception ex) {
MessageBox.Show($"Не удалось добавить объект {ex.Message}");
_logger.LogInformation($"Объект не добаавлен {ex.Message}");
}
}

View File

@ -8,6 +8,7 @@ namespace DoubleDeckerBus
{
internal interface IDrawingObject
{
public DrawingBus getBus();
public float Step { get; }
void SetObject(int x, int y, int width, int height);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace DoubleDeckerBus
{
internal class SetBusesGeneric<T>
where T : class
where T : IDrawingObject
{
private readonly List<T> _places;
@ -29,6 +29,16 @@ namespace DoubleDeckerBus
public int Insert(T bus, int position)
{
try
{
if (bus.getBus(bus.Get_bus()) == null)
{
throw new NullReferenceException();
}
}
catch (NullReferenceException) {
MessageBox.Show("null");
}
if (BusyPlaces == _maxCount) {
throw new StorageOverflowException(BusyPlaces);
}
@ -57,7 +67,7 @@ namespace DoubleDeckerBus
public T this[int position] {
get {
if (position < 0 || position >= _maxCount) return null;
if (position < 0 || position >= _maxCount) return default(T);
return _places[position];
}
set {