示例#1
0
        // Сортувати вагони за типом і відобразити інформацію
        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();
        }
示例#2
0
        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;
            }
        }
示例#3
0
        /// <summary>
        /// Метод додає новий елемент в стек
        /// </summary>
        public void Add()
        {
            if (Count != 0)
            {
                Carriage next = new Carriage {
                    Previous = Last
                };

                next.SetNumber(Last.GetNumber() + 1);

                Last = next;
                Count++;
            }
            else
            {
                FormList();
            }
        }
示例#4
0
        // Оновити інформацію про вагони в головному потязі
        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();
        }