// Сортувати вагони за типом і відобразити інформацію private void SortEvent(object sender, EventArgs e) { Carriage carriage = Train.GetLast(); First = new Stack(); Second = new Stack(); while (carriage != null) { if (carriage.GetTypeValue() == "Пасажирський") { First.Add(carriage.GetTypeValue()); First.GetLast().SetNumber(carriage.GetNumber()); } else if (carriage.GetTypeValue() == "Вантажний") { Second.Add(carriage.GetTypeValue()); Second.GetLast().SetNumber(carriage.GetNumber()); } carriage = carriage.Previous; } SortForm sort = new SortForm(); sort.UpdateList(First, Second); sort.ShowDialog(); sort.Dispose(); }
public void UpdateList(Stack first, Stack second) { listView1.Items.Clear(); listView2.Items.Clear(); Carriage carriage = first.GetLast(); while (carriage != null) { listView1.Items.Add(carriage.GetNumber() + " вагон").SubItems.AddRange(new[] { carriage.GetTypeValue() }); carriage = carriage.Previous; } carriage = second.GetLast(); while (carriage != null) { listView2.Items.Add(carriage.GetNumber() + " вагон").SubItems.AddRange(new[] { carriage.GetTypeValue() }); carriage = carriage.Previous; } }
/// <summary> /// Метод додає новий елемент в стек /// </summary> public void Add() { if (Count != 0) { Carriage next = new Carriage { Previous = Last }; next.SetNumber(Last.GetNumber() + 1); Last = next; Count++; } else { FormList(); } }
// Оновити інформацію про вагони в головному потязі private void UpdateList(Stack stack) { listView1.Items.Clear(); Carriage carriage = stack.GetLast(); while (carriage != null) { listView1.Items.Add(carriage.GetNumber() + " вагон").SubItems.AddRange(new[] { carriage.GetTypeValue() }); carriage = carriage.Previous; } txtType.Text = ""; txtCount.Text = stack.Count.ToString(); }