예제 #1
0
        void addStations()
        {
            Console.WriteLine();
            Console.WriteLine("ADDING STATIONS...");

            try
            {
                // public Station(string address, string id, Double latitude, Double longitude)
                Station s = new Station("addres1", "st1", 1.01, 1.01);
                service.registerStation(s);
                s = new Station("addres2", "st2", 2.02, 2.02);
                service.registerStation(s);
                s = new Station("addres3", "st3", 3.03, 3.03);
                service.registerStation(s);
                s = new Station("addres4", "st4", 4.04, 4.04);
                service.registerStation(s);
                s = new Station("addres5", "st5", 5.05, 5.05);
                service.registerStation(s);
                s = new Station("addres6", "st1", 6.06, 6.06);
                service.registerStation(s);
            }
            catch (Exception e)
            {
                printError(e);
            }

            foreach (Station s in service.getAllStations())
            {
                Console.WriteLine(stationToString(s));
            }
        }
        private void btn_registrar_Click(object sender, EventArgs e)
        {
            Boolean err  = false;
            string  mens = "";
            string  dir  = "";
            string  id   = "";
            double  lat  = 0.0;
            double  lon  = 0.0;

            if (txt_direccion.TextLength == 0)
            {
                err   = true;
                mens += "El campo Direccion es obligatorio \n";
            }
            else
            {
                dir = txt_direccion.Text;
            }
            if (txt_identificador.TextLength == 0)
            {
                err   = true;
                mens += "El campo Id es obligatorio \n";
            }
            else
            {
                id = txt_identificador.Text;
            }
            try
            {
                lat = double.Parse(txt_latitud.Text);
                if (lat < -90.0 || lat > 90.0)
                {
                    mens += "El valor de latitud tiene que estar entre 90 y -90 \n";
                }
            }
            catch (FormatException a)
            {
                err   = true;
                mens += "El campo Latitud es obligatorio \n";
            }
            try
            {
                lon = double.Parse(txt_longitud.Text);
                if (lon < -18 - .0 || lat > 180.0)
                {
                    mens += "El valor de longitud tiene que estar entre 180 y -180 \n";
                }
            }
            catch (FormatException a)
            {
                err   = true;
                mens += "El campo Longitud es obligatorio \n";
            }
            if (!err)
            {
                DialogResult answer = MessageBox.Show(this,
                                                      "Estacion agregada \n",
                                                      "Well done",
                                                      MessageBoxButtons.OK,
                                                      MessageBoxIcon.Information);
                if (answer == DialogResult.OK)
                {
                    Station st = new Station(dir, id, lat, lon);
                    service.registerStation(st);
                    service.saveChanges();
                    this.Close();
                }
            }
            else
            {
                DialogResult answer = MessageBox.Show(this,
                                                      "Revise los datos introducidos \n" + mens,
                                                      "Error",
                                                      MessageBoxButtons.OK,
                                                      MessageBoxIcon.Error);
            }
        }