From ea6a49ba00b4c4cbb9ba95cbe639819af2f1d37e Mon Sep 17 00:00:00 2001 From: Vladislav_396ntk Date: Mon, 15 Apr 2024 11:28:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ListGenericObjects.cs | 26 +++++++------------ .../StorageCollection.cs | 1 - .../HoistingCrane/FormCarCollection.cs | 24 +++++++++++++++-- HoistingCrane/HoistingCrane/FormCarConfig.cs | 9 +++---- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs index de49ee1..48bb52d 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -20,16 +20,16 @@ namespace HoistingCrane.CollectionGenericObjects /// Максимально допустимое число объектов в списке /// private int _maxCount; - public int Count + public int Count { get { return list.Count; } } - public int SetMaxCount + public int SetMaxCount { set { - if(value > 0) + if (value > 0) { _maxCount = value; } @@ -39,11 +39,8 @@ namespace HoistingCrane.CollectionGenericObjects public T? Get(int position) { // TODO проверка позиции - if(position >= 0 && position < _maxCount) - { - return list[position]; - } - return null; + if (position >= Count || position < 0) return null; + return list[position]; } @@ -51,9 +48,9 @@ namespace HoistingCrane.CollectionGenericObjects { // TODO проверка, что не превышено максимальное количество элементов // TODO вставка в конец набора - if (Count == _maxCount) - { - return -1; + if (Count == _maxCount) + { + return -1; } list.Add(obj); return Count; @@ -70,21 +67,18 @@ namespace HoistingCrane.CollectionGenericObjects } list.Insert(position, obj); return position; - - } - public T? Remove(int position) { // TODO проверка позиции // TODO удаление объекта из списка - if(position >= 0 && position < list.Count) + if (position >= 0 && position < list.Count) { T? temp = list[position]; list.RemoveAt(position); return temp; } return null; - } + } } } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs index 0765bd3..d1e5183 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs @@ -60,5 +60,4 @@ namespace HoistingCrane.CollectionGenericObjects } } } - } diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 7e10c97..bd42830 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -64,9 +64,29 @@ namespace HoistingCrane } return color; } - private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningHoistingCrane)); + private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) + { + FormCarConfig form = new(); + form.Show(); + form.AddEvent(SetCar); + } + private void SetCar(DrawningTrackedVehicle drawningTrackedVehicle) + { + if (_company == null || drawningTrackedVehicle == null) + { + return; + } - private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); + if (_company + drawningTrackedVehicle != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } private void buttonDeleteCar_Click(object sender, EventArgs e) { diff --git a/HoistingCrane/HoistingCrane/FormCarConfig.cs b/HoistingCrane/HoistingCrane/FormCarConfig.cs index 3135eb7..9105a92 100644 --- a/HoistingCrane/HoistingCrane/FormCarConfig.cs +++ b/HoistingCrane/HoistingCrane/FormCarConfig.cs @@ -117,11 +117,10 @@ namespace HoistingCrane /// private void labelBodyColor_DragDrop(object sender, DragEventArgs e) { - if (car != null) - { - car.EntityTrackedVehicle?.SetBodyColor((Color)e.Data.GetData(typeof(Color))); - DrawObject(); - } + if (car == null) + return; + car.EntityTrackedVehicle?.SetBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); } /// /// Передача основного цвета