private void buttonAdd_Click(object sender, EventArgs e)
        {
            Flight newflight;
            string route;
            bool   parseInt;
            int    time, cost;
            int    x1, y1, x2, y2;

            x1 = y1 = x2 = y2 = 0;
            if (textBoxOrigin.Text != "")
            {
                if (textBoxOrigin.Text.Length == 1)
                {
                    if (textBoxDestination.Text != "")
                    {
                        if (textBoxDestination.Text.Length == 1)
                        {
                            if (textBoxDestination.Text != textBoxOrigin.Text)
                            {
                                if (textBoxTime.Text != "")
                                {
                                    parseInt = int.TryParse(textBoxTime.Text, out time);
                                    if (parseInt)
                                    {
                                        if (textBoxCost.Text != "")
                                        {
                                            parseInt = int.TryParse(textBoxCost.Text, out cost);
                                            if (parseInt)
                                            {
                                                route = "SK1" + textBoxOrigin.Text + textBoxDestination.Text;
                                                if (!flights.flightExistence(route))
                                                {
                                                    newflight = new Flight(textBoxOrigin.Text, textBoxDestination.Text, time, cost);
                                                    flights.Add(newflight);
                                                    GraphForm graphForm = new GraphForm(1, graph, flights);
                                                    if (!graph.excistenceCity(textBoxOrigin.Text))
                                                    {
                                                        MessageBox.Show("Ciudad Origen", "Informacion",
                                                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                        graphForm.ShowDialog();
                                                        x1 = graphForm.getX();
                                                        y1 = graphForm.getY();
                                                    }
                                                    if (!graph.excistenceCity(textBoxDestination.Text))
                                                    {
                                                        MessageBox.Show("Ciudad Destino", "Informacion",
                                                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                        graphForm.ShowDialog();
                                                        x2 = graphForm.getX();
                                                        y2 = graphForm.getY();
                                                    }
                                                    graph.addRoute(newflight, x1, y1, x2, y2);
                                                    MessageBox.Show("Vuelo agregado exitosamente", "Informacion",
                                                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                    textBoxOrigin.Text      = "";
                                                    textBoxDestination.Text = "";
                                                    textBoxTime.Text        = "";
                                                    textBoxCost.Text        = "";
                                                    viewsFlghtsUpdate(flights);
                                                }
                                                else
                                                {
                                                    MessageBox.Show("El vuelo ya existe", "Error",
                                                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                }
                                            }
                                            else
                                            {
                                                MessageBox.Show("Introduzca un costo valido", "Advertencia",
                                                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Introduzca el costo", "Advertencia",
                                                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Introduzca un timepo valido", "Advertencia",
                                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Introduzca el Tiempo", "Advertencia",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            else
                            {
                                MessageBox.Show("No se puede mismo origen y destino", "Advertencia",
                                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Destino no valido", "Advertencia",
                                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Introduzca un Destino", "Advertencia",
                                        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else
                {
                    MessageBox.Show("Origen no valido", "Advertencia",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Introduzca un Origen", "Advertencia",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void buttonGraph_Click(object sender, EventArgs e)
        {
            GraphForm graphForm = new GraphForm(2, graph, flights);

            graphForm.ShowDialog();
        }
示例#3
0
        private void aceptarMaterialFlatButton_Click(object sender, EventArgs e)
        {
            if (allReady() && (Convert.ToInt32(asientosLineTextField.Text) % 2 == 0) && routeFree() && !beSelf())
            {
                Vuelo v = new Vuelo(
                    origenLineTextField.Text.ToCharArray()[0],
                    destinoLineTextField.Text.ToCharArray()[0],
                    Convert.ToInt32(tiempoLineTextField.Text),
                    Convert.ToInt32(costoLineTextField.Text),
                    Convert.ToInt32(asientosLineTextField.Text)
                    );
                this.flyList.Add(v);
                // ************************************************************
                // Aqui es donde se hace el agregado para el nodo

                if (!graph.existVertex(v.getOrigen()))
                {
                    graph.addVertex(v.getOrigen());
                    GraphForm grafoVentana = new GraphForm(ref graph, 1);
                    this.Hide();
                    grafoVentana.ShowDialog();
                    this.Show();
                    int x = grafoVentana.getPosX();
                    int y = grafoVentana.getPosY();

                    if (x > -1 && y > -1)
                    {
                        graph.setCityPoints(v.getOrigen(), x, y);
                    }
                }
                if (!graph.existVertex(v.getDestino()))
                {
                    graph.addVertex(v.getDestino());
                    GraphForm grafoVentana = new GraphForm(ref graph, 1);
                    this.Hide();
                    grafoVentana.ShowDialog();
                    this.Show();
                    int x = grafoVentana.getPosX();
                    int y = grafoVentana.getPosY();
                    if (x > -1 && y > -1)
                    {
                        graph.setCityPoints(v.getDestino(), x, y);
                    }
                }
                graph.createAdy(v.getOrigen(), v.getDestino(), v.getCosto(), v.getTiempo());
                // *************************************************************

                this.Close();
            }
            else if (!routeFree())
            {
                MessageBox.Show("La ruta ya esta ocupada", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (beSelf())
            {
                MessageBox.Show("El origen y destino son el mismo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if ((Convert.ToInt32(asientosLineTextField.Text) % 2 != 0))
            {
                MessageBox.Show("El número de asientos debe ser par", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Algun dato esta erroneo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }