Beispiel #1
0
        public Seats Add(int index, Seats o)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index:" + index);
            }

            if (index > count)
            {
                index = count;
            }
            Node_Seats current = this.head;

            if (this.Empty || index == 0)
            {
                this.head = new Node_Seats(o, this.head);
            }
            else
            {
                for (int i = 0; i < index - 1; i++)
                {
                    current = current.Next;
                }

                current.Next = new Node_Seats(o, current.Next);
            }

            count++;
            return(o);
        }
Beispiel #2
0
        private void Button_Save_Click(object sender, EventArgs e)   // Adds the voyage to linked list
        /// Find the highest number in voyages
        {
            int highest_no = 0;

            if (list_voyages.Empty)
            {
                highest_no = 1000; //If there is not any voyage 1000 will be the default voyage number
            }
            else
            {
                for (int i = 0; i < list_voyages.Count; i++)
                {
                    if (list_voyages[i].number >= highest_no)
                    {
                        highest_no = list_voyages[i].number + 1;
                    }
                }
            }
            ///

            // Is any box empty ?
            if (Box_From.Text == "" ||
                Box_Destination.Text == "" ||
                Box_SeatCount.Value <= 0 ||
                Box_TicketPrice.Value <= 0 ||
                Box_Driver.Text == "" ||
                Box_PlateNumber.Text == "")
            {
                MessageBox.Show("You need to fill all boxes.");
            }
            else
            {
                Voyages newVoyage = new Voyages();
                newVoyage.number       = Convert.ToInt32(highest_no);
                newVoyage.from         = Box_From.Text;
                newVoyage.destination  = Box_Destination.Text;
                newVoyage.date         = Box_Date.Value.Date;
                newVoyage.time         = Box_Time.Value.TimeOfDay;
                newVoyage.seat_count   = (int)Box_SeatCount.Value;
                newVoyage.ticket_price = (int)Box_TicketPrice.Value;
                newVoyage.plate_number = Box_PlateNumber.Text;
                newVoyage.driver       = Box_Driver.Text;

                for (int i = 0; i < newVoyage.seat_count; i++)
                {
                    Seats newSeat = new Seats();
                    newSeat.number         = i + 1;
                    newSeat.passanger_name = null;
                    newSeat.gender         = null;
                    newSeat.status         = "Available";
                    newVoyage.LINKED_seats.Add(newSeat);
                }

                list_voyages.Add(newVoyage);
                Box_Driver.Text     = Box_From.Text = Box_Destination.Text = Box_PlateNumber.Text = "";
                Box_SeatCount.Value = Box_TicketPrice.Value = 0;
            }
        }
Beispiel #3
0
        public int indexOf(Seats o)
        {
            Node_Seats current = this.head;

            for (int i = 0; i < this.count; i++)
            {
                if (current.Data.Equals(o))
                {
                    return(i);
                }

                current = current.Next;
            }

            return(-1);
        }
Beispiel #4
0
        public Seats Remove(int index)
        {
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index:" + index);
            }

            if (this.Empty)
            {
                return(null);
            }

            if (index >= count)
            {
                index = count - 1;
            }

            Node_Seats current = this.head;
            Seats      result  = null;

            if (index == 0)
            {
                result    = current.Data;
                this.head = current.Next;
            }
            else
            {
                for (int i = 0; i < index - 1; i++)
                {
                    current = current.Next;
                }
                result = current.Next.Data;

                current.Next = current.Next.Next;
            }

            count--;
            return(result);
        }
Beispiel #5
0
        bool isBuyingTicket;                               // is user on ticket interface or not ?
        private LINKEDList voyages_scanner()               //This function scans all texts file and add to linked list called "list_voyages"
        {
            string        path;
            DirectoryInfo d = new DirectoryInfo("texts");

            FileInfo[] files = d.GetFiles("*.txt");

            foreach (FileInfo item in files)
            {
                path = "texts/" + item.Name;
                List <string> list        = File.ReadAllLines(path).ToList();
                int           row_counter = 0;

                foreach (var item2 in list)
                {
                    if (row_counter % 2 == 0)
                    {
                        object[] entries   = item2.Split(',');
                        Voyages  newVoyage = new Voyages();

                        newVoyage.number       = Convert.ToInt32(entries[0]);
                        newVoyage.from         = entries[1].ToString();
                        newVoyage.destination  = entries[2].ToString();
                        newVoyage.date         = DateTime.ParseExact(entries[3].ToString(), "dd-MM-yyyy", null);
                        newVoyage.time         = Convert.ToDateTime(entries[4]).TimeOfDay;
                        newVoyage.seat_count   = Convert.ToInt32(entries[5]);
                        newVoyage.ticket_price = Convert.ToInt32(entries[6]);
                        newVoyage.plate_number = entries[7].ToString();
                        newVoyage.driver       = entries[8].ToString();

                        for (int i = 0; i < newVoyage.seat_count; i++)
                        {
                            Seats newSeat = new Seats();
                            newSeat.number         = i + 1;
                            newSeat.passanger_name = null;
                            newSeat.gender         = null;
                            newSeat.status         = null;
                            newVoyage.LINKED_seats.Add(newSeat);
                        }

                        list_voyages.Add(newVoyage);
                    }
                    else
                    {
                        list_voyages[list_voyages.Count].LINKED_seats.Clear();
                        string[] entries = item2.Split(',');
                        for (int i = 0; i < list_voyages[list_voyages.Count].seat_count; i++)
                        {
                            object[] specific_entries = entries[i].Split('-');
                            Seats    newSeat          = new Seats();
                            newSeat.number         = i + 1;
                            newSeat.passanger_name = specific_entries[1].ToString();
                            newSeat.gender         = specific_entries[2].ToString();
                            newSeat.status         = specific_entries[3].ToString();
                            list_voyages[list_voyages.Count].LINKED_seats.Add(newSeat);
                        }
                    }

                    row_counter++;
                }
            }

            return(list_voyages);
        }
Beispiel #6
0
 public Node_Seats(Seats data, Node_Seats next)
 {
     this.data = data;
     this.next = next;
 }
Beispiel #7
0
 public Seats Add(Seats o)
 {
     return(this.Add(count, o));
 }
Beispiel #8
0
 public bool Contains(Seats o)
 {
     return(this.indexOf(o) >= 0);
 }