From a20bad83366743b131c3f67e576096730ac9eb2e Mon Sep 17 00:00:00 2001 From: shadowik Date: Sun, 11 Dec 2022 21:44:32 +0400 Subject: [PATCH] Final Commit --- .../DoubleDeckerBus/DrawingObjectBus.cs | 14 ++++++++++++-- .../DoubleDeckerBus/FormBusConfig.cs | 2 +- .../DoubleDeckerBus/FormMapWithSetBuses.cs | 18 +++++++++++------- .../DoubleDeckerBus/IDrawingObject.cs | 1 + .../DoubleDeckerBus/MapWithSetBusesGeneric.cs | 2 +- .../DoubleDeckerBus/SetBusesGeneric.cs | 14 ++++++++++++-- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs index bd5e511..25c0020 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs @@ -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(); } diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBusConfig.cs b/DoubleDeckerBus/DoubleDeckerBus/FormBusConfig.cs index 2c4b4d3..63346bc 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormBusConfig.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormBusConfig.cs @@ -143,7 +143,7 @@ namespace DoubleDeckerBus } private void ButtonAdd_Click(object sender, EventArgs e) - { + { EventAddBus?.Invoke(_bus); Close(); } diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs index 779e742..35a549d 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs @@ -60,26 +60,30 @@ namespace DoubleDeckerBus var formBusConfig = new FormBusConfig(); formBusConfig.AddEvent(AddBus); formBusConfig.Show(); - } private void AddBus(DrawingBus bus) - { + { if (listBoxMaps.SelectedIndex == -1) { 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}"); } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs b/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs index 93c20a0..2e091e9 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/IDrawingObject.cs @@ -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); diff --git a/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs index d5513cf..66aed8b 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs @@ -29,7 +29,7 @@ namespace DoubleDeckerBus } public static int operator +(MapWithSetBusesGeneric map, T bus) - { + { return map._setBuses.Insert(bus); } diff --git a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs index eed9d3e..32625aa 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace DoubleDeckerBus { internal class SetBusesGeneric - where T : class + where T : IDrawingObject { private readonly List _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 {