Исправления

This commit is contained in:
Роман Пермяков 2024-03-11 14:37:22 +04:00
parent 614fdf72e5
commit d3dfa6670f
4 changed files with 22 additions and 21 deletions

View File

@ -29,14 +29,14 @@ namespace AccordionBus.CollectionGenericObjects
_collection.SetMaxCount = GetMaxCount;
}
public static bool operator +(AbstractCompany company, DrawningBus bus)
public static int operator +(AbstractCompany company, DrawningBus bus)
{
return company._collection?.Insert(bus) ?? false;
return company._collection.Insert(bus);
}
public static bool operator -(AbstractCompany company, int position)
public static DrawningBus? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position) ?? false;
return company._collection.Remove(position);
}
public DrawningBus? GetRandomObject()

View File

@ -22,20 +22,20 @@ namespace AccordionBus.CollectionGenericObjects
/// </summary>
/// <param name="obj">добавляемый объект</param>
/// <returns></returns>
bool Insert(T obj);
int Insert(T obj);
/// <summary>
/// вставить по позиции
/// </summary>
/// <param name="obj">добавляемый объект</param>
/// <param name="position">индекс</param>
/// <returns></returns>
bool Insert(T obj, int position);
int Insert(T obj, int position);
/// <summary>
/// удаление
/// </summary>
/// <param name="position">индекс</param>
/// <returns></returns>
bool Remove(int position);
T? Remove(int position);
/// <summary>
/// получение объекта по позиции
/// </summary>

View File

@ -26,27 +26,27 @@ namespace AccordionBus.CollectionGenericObjects
return _collection[position];
}
public bool Insert(T obj)
public int Insert(T obj)
{
for (int i = 0; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
return i;
}
}
return false;
return -1;
}
public bool Insert(T obj, int position)
public int Insert(T obj, int position)
{
if (position < 0 || position >= _collection.Length) { return false; }
if (position < 0 || position >= _collection.Length) { return -1; }
if (_collection[position] == null)
{
_collection[position] = obj;
return true;
return position;
}
else
{
@ -55,7 +55,7 @@ namespace AccordionBus.CollectionGenericObjects
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
return i;
}
}
@ -64,19 +64,20 @@ namespace AccordionBus.CollectionGenericObjects
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
return i;
}
}
}
return false;
return -1;
}
public bool Remove(int position)
public T? Remove(int position)
{
if (position < 0 || position >= _collection.Length) { return false;}
if (position < 0 || position >= _collection.Length) { return null;}
T? obj = _collection[position];
_collection[position] = null;
return true;
return obj;
}
}
}

View File

@ -55,7 +55,7 @@ namespace AccordionBus
return;
}
if (_company + _drawningBus)
if (_company + _drawningBus != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@ -89,7 +89,7 @@ namespace AccordionBus
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos)
if (_company - pos is DrawningBus)
{
MessageBox.Show("Объект удалён");
pictureBox.Image = _company.Show();