This commit is contained in:
Вячеслав Иванов 2023-10-16 08:53:46 +04:00
parent f80ead5cf8
commit f57b0374f4
3 changed files with 32 additions and 37 deletions

View File

@ -43,7 +43,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
FormDoubleDeckerBus form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_theBuses + form.SelectedBus)
if (_theBuses + form.SelectedBus != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _theBuses.ShowTheBuses();
@ -62,13 +62,14 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
/// <param name="e"></param>
private void ButtonDeleteBus_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_theBuses - pos != null)
if (_theBuses - pos != true)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _theBuses.ShowTheBuses();

View File

@ -37,13 +37,8 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <returns></returns>
public bool Insert(T bus)
public int Insert(T bus)
{
if (_places[Count - 1] != null)
{
return false;
}
return Insert(bus, 0);
}
@ -53,35 +48,36 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <param name="bus">Добавляемый автобус</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T bus, int position)
public int Insert(T bus, int position)
{
if (position < 0 || position >= _places.Length)
int nullIndex = -1, i;
if (position < 0 || position >= Count)
{
return false;
return -1;
}
if (_places[position] != null)
for (i = position; i < Count; i++)
{
int ind = position;
while (ind < Count && _places[ind] != null)
if (_places[i] == null)
{
ind++;
nullIndex = i;
break;
}
}
if (ind == Count)
{
return false;
}
if (nullIndex < 0)
{
return -1;
}
for (int i = ind - 1; i >= position; i--)
{
_places[i + 1] = _places[i];
}
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = bus;
return true;
return position;
}
/// <summary>
@ -91,7 +87,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <returns></returns>
public bool Remove(int position)
{
if (position < 0 || position >= _places.Length || _places[position] == null)
if (position < 0 || position >= Count)
{
return false;
}
@ -107,7 +103,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <returns></returns>
public T? Get(int position)
{
if (position < 0 || position >= _places.Length)
if (position < 0 || position >= Count)
{
return null;
}

View File

@ -63,14 +63,13 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(TheBusesGenericCollection<T, U> collect, T?
obj)
public static int operator +(TheBusesGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return false;
return -1;
}
return collect?._collection.Insert(obj) ?? false;
return collect._collection.Insert(obj);
}
/// <summary>
@ -79,7 +78,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T? operator -(TheBusesGenericCollection<T, U> collect, int
public static bool operator -(TheBusesGenericCollection<T, U> collect, int
pos)
{
T? obj = collect._collection.Get(pos);
@ -87,7 +86,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
{
collect._collection.Remove(pos);
}
return obj;
return false;
}
/// <summary>
@ -145,8 +144,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
if (bus != null)
{
int inRow = _pictureWidth / _placeSizeWidth;
bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth,
i / inRow * _placeSizeHeight);
bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
bus.DrawTransport(g);
}
}