From dc01587054cbf262acab4191584e399af66b4d25 Mon Sep 17 00:00:00 2001 From: Danila Date: Mon, 1 Apr 2024 14:05:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 9 ++++---- .../CollectionGenericObjects/Garage.cs | 3 --- .../ICollectionGenericObjects.cs | 7 +++--- .../MassivGenericObjects.cs | 22 +++++++++---------- .../HoistingCrane/FormCarCollection.cs | 14 ++---------- 5 files changed, 20 insertions(+), 35 deletions(-) diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs index be9be73..b7dbbee 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs @@ -1,5 +1,4 @@ using HoistingCrane.Drawning; -using System; namespace HoistingCrane.CollectionGenericObjects { public abstract class AbstractCompany @@ -42,13 +41,13 @@ namespace HoistingCrane.CollectionGenericObjects arr.SetMaxCount = GetMaxCount; } - public static bool operator +(AbstractCompany company, DrawningTrackedVehicle car) + public static int operator +(AbstractCompany company, DrawningTrackedVehicle car) { - return company.arr?.Insert(car) ?? false; + return company.arr?.Insert(car) ?? 0; } - public static bool operator -(AbstractCompany company, int position) + public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) { - return company.arr?.Remove(position) ?? false; + return company.arr?.Remove(position); } public DrawningTrackedVehicle? GetRandomObject() diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs index e2da629..3aedcb2 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs @@ -1,7 +1,4 @@ using HoistingCrane.Drawning; -using System; -using System.Collections.Specialized; - namespace HoistingCrane.CollectionGenericObjects { public class Garage : AbstractCompany diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs index 6187862..5182f15 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,5 +1,4 @@ -using System; -namespace HoistingCrane.CollectionGenericObjects +namespace HoistingCrane.CollectionGenericObjects { public interface ICollectionGenericObjects where T: class @@ -17,7 +16,7 @@ namespace HoistingCrane.CollectionGenericObjects /// /// /// - bool Insert(T obj); + int Insert(T obj); /// /// Добавление элемента в коллекцию на определенную позицию /// @@ -30,7 +29,7 @@ namespace HoistingCrane.CollectionGenericObjects /// /// /// - bool Remove(int position); + T? Remove(int position); T? Get(int position); } } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs index 81b86a9..ac0d22a 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs @@ -1,5 +1,4 @@ -using System; -namespace HoistingCrane.CollectionGenericObjects +namespace HoistingCrane.CollectionGenericObjects { public class MassivGenericObjects : ICollectionGenericObjects where T : class { @@ -31,16 +30,16 @@ namespace HoistingCrane.CollectionGenericObjects return null; } - public bool Insert(T obj) + public int Insert(T obj) { for(int i = 0; i < Count; i++) { if (arr[i] == null) { - arr[i] = obj; - return true; + Insert(obj,i); + return 1; } } - return false; + return 0; } public bool Insert(T obj, int position) @@ -81,14 +80,15 @@ namespace HoistingCrane.CollectionGenericObjects return false; } - public bool Remove(int position) + public T? Remove(int position) { - if(position < 0 || position >= arr.Length || arr[position] == null) + if(position >= 0 && position < Count) { - return false; + arr[position] = null; + return arr[position]; } - arr[position] = null; - return true; + return arr[position]; } + } } diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 7175e29..6c6c042 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -1,15 +1,5 @@ using HoistingCrane.CollectionGenericObjects; using HoistingCrane.Drawning; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - namespace HoistingCrane { public partial class FormCarCollection : Form @@ -49,7 +39,7 @@ namespace HoistingCrane default: return; } - if (_company + drawning) + if ((_company + drawning) == 1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -91,7 +81,7 @@ namespace HoistingCrane return; } int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos) + if ((_company - pos) == null) { MessageBox.Show("Объект удален!"); pictureBox.Image = _company.Show();