コード例 #1
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            String newEntry = ("\n" + (gr.getNoOfAirports() + 1) + "\t" + nameTxt.Text + "\t" + latitudeTxt.Text + "\t" + longitudeTxt.Text
                               + "\t" + gr.getCountryCode(countryBox.SelectedItem.ToString()) + "\t" + cityTxt.Text + "\t" + airportCodeTxt.Text);

            File.AppendAllText("airports.dat", newEntry);

            Airport A = new Airport();

            A.airportID = gr.getNoOfAirports() + 1;
            A.name      = nameTxt.Text;
            A.latitude  = double.Parse(latitudeTxt.Text);
            A.longitude = double.Parse(longitudeTxt.Text);

            for (int i = 0; i < gr.getNoOfCountries(); i++)
            {
                if (countryBox.SelectedItem.ToString().Equals(gr.getCountry(i).name))
                {
                    A.country = gr.getCountry(i);
                }
            }

            A.city = cityTxt.Text;
            A.code = airportCodeTxt.Text;

            gr.addAirport(A);

            this.Hide();
        }
コード例 #2
0
        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();
        }