From f57b0374f49514b33ed316b99f94851ad598ecba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Mon, 16 Oct 2023 08:53:46 +0400 Subject: [PATCH] fix --- .../FormBusCollection.cs | 9 ++-- .../Generics/SetGeneric.cs | 46 +++++++++---------- .../Generics/TheBusesGenericCollection.cs | 14 +++--- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs index b6e8277..5cfbb8e 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs @@ -43,7 +43,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base FormDoubleDeckerBus form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_theBuses + form.SelectedBus) + if (_theBuses + form.SelectedBus != -1) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = _theBuses.ShowTheBuses(); @@ -62,13 +62,14 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base /// private void ButtonDeleteBus_Click(object sender, EventArgs e) { - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_theBuses - pos != null) + + if (_theBuses - pos != true) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = _theBuses.ShowTheBuses(); diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs index c041aca..d8ee52f 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs @@ -37,13 +37,8 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics /// /// Добавляемый автобус /// - public bool Insert(T bus) + public int Insert(T bus) { - if (_places[Count - 1] != null) - { - return false; - } - return Insert(bus, 0); } @@ -53,35 +48,36 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics /// Добавляемый автобус /// Позиция /// - public bool Insert(T bus, int position) + public int Insert(T bus, int position) { - if (position < 0 || position >= _places.Length) + int nullIndex = -1, i; + + if (position < 0 || position >= Count) { - return false; + return -1; } - if (_places[position] != null) + for (i = position; i < Count; i++) { - int ind = position; - - while (ind < Count && _places[ind] != null) + if (_places[i] == null) { - ind++; + nullIndex = i; + break; } + } - if (ind == Count) - { - return false; - } + if (nullIndex < 0) + { + return -1; + } - for (int i = ind - 1; i >= position; i--) - { - _places[i + 1] = _places[i]; - } + for (i = nullIndex; i > position; i--) + { + _places[i] = _places[i - 1]; } _places[position] = bus; - return true; + return position; } /// @@ -91,7 +87,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics /// public bool Remove(int position) { - if (position < 0 || position >= _places.Length || _places[position] == null) + if (position < 0 || position >= Count) { return false; } @@ -107,7 +103,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics /// public T? Get(int position) { - if (position < 0 || position >= _places.Length) + if (position < 0 || position >= Count) { return null; } diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs index 3eb9dea..16415d7 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs @@ -63,14 +63,13 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics /// /// /// - public static bool operator +(TheBusesGenericCollection collect, T? - obj) + public static int operator +(TheBusesGenericCollection collect, T? obj) { if (obj == null) { - return false; + return -1; } - return collect?._collection.Insert(obj) ?? false; + return collect._collection.Insert(obj); } /// @@ -79,7 +78,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics /// /// /// - public static T? operator -(TheBusesGenericCollection collect, int + public static bool operator -(TheBusesGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); @@ -87,7 +86,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics { collect._collection.Remove(pos); } - return obj; + return false; } /// @@ -145,8 +144,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics if (bus != null) { int inRow = _pictureWidth / _placeSizeWidth; - bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, - i / inRow * _placeSizeHeight); + bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight); bus.DrawTransport(g); } }