예제 #1
0
        /// <summary>
        /// Parse the input file - fill the flights database
        /// </summary>
        /// <param name="filePath">The input file (get flights)</param>
        public void ParseTextFile(string filePath)
        {
            flights = new Flights();
            StreamReader reader = new StreamReader(filePath);
            string       line   = reader.ReadLine();

            // Read each line and create a new flight
            while (line != null)
            {
                // Create the flight
                Flight   flight  = new Flight();
                string[] members = line.Split(' ');
                flight.flightNumber = members[0];
                flight.src          = members[1];
                flight.dst          = members[2];
                flight.date         = DateTime.Parse(members[3]);
                flight.seats        = Convert.ToInt32(members[4]);
                flight.price        = Convert.ToInt32(members[5]);
                flights.Add(flight);
                line = reader.ReadLine();
            }
            // Close the file
            reader.Close();
        }