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

View File

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

View File

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