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; } /// Получение объекта из набора по позиции