private void addBtn_Click(object sender, EventArgs e) { String origin = "", destination = ""; for (int i = 0; i < gr.getNoOfAirports(); i++) { if (originBox.SelectedItem.ToString().Equals(gr.getAirport(i).name)) { origin = gr.getAirport(i).code; } if (destinationBox.SelectedItem.ToString().Equals(gr.getAirport(i).name)) { destination = gr.getAirport(i).code; } } String outboundRoute = "\n" + origin + "\t" + destination; String returnRoute = "\n" + destination + "\t" + origin; File.AppendAllText("routes.dat", outboundRoute); File.AppendAllText("routes.dat", returnRoute); Route R = new Route(); for (int i = 0; i < gr.getNoOfAirports(); i++) { if (originBox.SelectedItem.ToString().Equals(gr.getAirport(i).name)) { R.origin = gr.getAirport(i); } else if (destinationBox.SelectedItem.ToString().Equals(gr.getAirport(i).name)) { R.destination = gr.getAirport(i); } } gr.addRoute(R); this.Hide(); }
private void LoadData() { using (StreamReader myFile = new StreamReader("countries.dat")) { while (!myFile.EndOfStream) { Country C = new Country(); string[] lines = myFile.ReadLine().Split('\t'); C.countryCode = lines[1]; C.name = lines[2]; C.continent = lines[3]; gr.addCountry(C); } } using (StreamReader myFile = new StreamReader("airports.dat")) { while (!myFile.EndOfStream) { Airport A = new Airport(); string[] lines = myFile.ReadLine().Split('\t'); A.airportID = Int32.Parse(lines[0]); A.name = lines[1]; A.latitude = double.Parse(lines[2], CultureInfo.InvariantCulture); A.longitude = double.Parse(lines[3], CultureInfo.InvariantCulture); A.city = lines[5]; A.code = lines[6]; for (int i = 0; i < gr.getNoOfCountries(); i++) { if (lines[4].Equals(gr.getCountry(i).countryCode)) { A.country = gr.getCountry(i); } } gr.addAirport(A); } } using (StreamReader myFile = new StreamReader("routes.dat")) { while (!myFile.EndOfStream) { string[] lines = myFile.ReadLine().Split('\t'); Route R = new Route(); for (int i = 0; i < gr.getNoOfAirports(); i++) { if (lines[0].Equals(gr.getAirport(i).code)) { R.origin = gr.getAirport(i); } else if (lines[1].Equals(gr.getAirport(i).code)) { R.destination = gr.getAirport(i); } } gr.addRoute(R); } } gr.sortVectors(); gr.addNeighbours(); }