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

View File

@ -143,7 +143,7 @@ namespace DoubleDeckerBus
} }
private void ButtonAdd_Click(object sender, EventArgs e) private void ButtonAdd_Click(object sender, EventArgs e)
{ {
EventAddBus?.Invoke(_bus); EventAddBus?.Invoke(_bus);
Close(); Close();
} }

View File

@ -60,26 +60,30 @@ namespace DoubleDeckerBus
var formBusConfig = new FormBusConfig(); var formBusConfig = new FormBusConfig();
formBusConfig.AddEvent(AddBus); formBusConfig.AddEvent(AddBus);
formBusConfig.Show(); formBusConfig.Show();
} }
private void AddBus(DrawingBus bus) private void AddBus(DrawingBus bus)
{ {
if (listBoxMaps.SelectedIndex == -1) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
DrawingObjectBus boat = new(bus); try
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + boat >= 0)
{ {
DrawingObjectBus _bus = new(bus);
_ = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + _bus;
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_logger.LogInformation($"Объект добавлен"); _logger.LogInformation($"Объект добавлен");
} }
else catch (StorageOverflowException ex)
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show($"Не удалось добавить объект {ex.Message}");
_logger.LogInformation($"Объект не добаавлен"); _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 internal interface IDrawingObject
{ {
public DrawingBus getBus();
public float Step { get; } public float Step { get; }
void SetObject(int x, int y, int width, int height); void SetObject(int x, int y, int width, int height);

View File

@ -29,7 +29,7 @@ namespace DoubleDeckerBus
} }
public static int operator +(MapWithSetBusesGeneric<T, U> map, T bus) public static int operator +(MapWithSetBusesGeneric<T, U> map, T bus)
{ {
return map._setBuses.Insert(bus); return map._setBuses.Insert(bus);
} }

View File

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