From 0db70e3020486b9643ccf124160cc8638a8570af Mon Sep 17 00:00:00 2001 From: sardq Date: Sat, 2 Dec 2023 23:02:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HoistingCrane/CranesGenericCollection.cs | 16 ++++++++-------- .../HoistingCrane/FormCraneCollection.cs | 2 +- HoistingCrane/HoistingCrane/SetGeneric.cs | 6 ++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/HoistingCrane/HoistingCrane/CranesGenericCollection.cs b/HoistingCrane/HoistingCrane/CranesGenericCollection.cs index bd24e44..71988fa 100644 --- a/HoistingCrane/HoistingCrane/CranesGenericCollection.cs +++ b/HoistingCrane/HoistingCrane/CranesGenericCollection.cs @@ -81,18 +81,18 @@ namespace HoistingCrane.Generics int k = _pictureHeight/_placeSizeHeight-1; foreach (var crane in _collection.GetCranes()) { - if (crane != null) + if (j < 0) + { + j += _pictureWidth / _placeSizeWidth; + k--; + } + obj = crane; + if (obj != null) { - if (j < 0) - { - j += _pictureWidth / _placeSizeWidth; - k--; - } - obj = crane; obj.SetPosition(_placeSizeWidth * j, _placeSizeHeight * k); obj.DrawTransport(g); - j--; } + j--; } } } diff --git a/HoistingCrane/HoistingCrane/FormCraneCollection.cs b/HoistingCrane/HoistingCrane/FormCraneCollection.cs index 3770d11..b58efc4 100644 --- a/HoistingCrane/HoistingCrane/FormCraneCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCraneCollection.cs @@ -72,7 +72,7 @@ namespace HoistingCrane var obj = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]; if (obj != null) { - if (obj + crane != 1) + if (obj + crane != -1) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowCars(); diff --git a/HoistingCrane/HoistingCrane/SetGeneric.cs b/HoistingCrane/HoistingCrane/SetGeneric.cs index df483fb..c55f728 100644 --- a/HoistingCrane/HoistingCrane/SetGeneric.cs +++ b/HoistingCrane/HoistingCrane/SetGeneric.cs @@ -20,6 +20,8 @@ /// Добавление объекта в набор public int Insert(T crane) { + if(crane==null) + return -1; _places.Insert(0, crane); return 0; } @@ -33,8 +35,8 @@ /// Удаление объекта из набора с конкретной позиции public bool Remove(int position) { - if ((position < 0) || (position > _maxCount)) return false; - _places.RemoveAt(position); + if ((position < 0) || (position > _maxCount)|| (_places[position] == null)) return false; + _places[position] = null; return true; } /// Получение объекта из набора по позиции