private void eliminarBoton_Click(object sender, EventArgs e)
        {
            try
            {
                string nombrePasajero = ListViewPasajeros.SelectedItems[0].Text.ToString();

                List <Pasajero> lp = new List <Pasajero>();

                foreach (Universal v in listaVuelos)
                {
                    for (int i = 0; i < v.getPasajerosCount(); ++i)
                    {
                        Pasajero p = v.getPasajero(i);

                        if (nombrePasajero == p.getNombreYap())
                        {
                            int num_asiento;
                            num_asiento = p.getAsiento() - 1;
                            v.setAsientoOcupado(false, num_asiento);
                            v.setAsientosDisponibles(v.getAsientos() + 1);
                            v.eliminarPasajero(i);
                            ListViewPasajeros.Items.Clear();
                            actualizarListView();
                        }
                    }
                }
            }
            catch (ArgumentOutOfRangeException error)
            {
                Console.WriteLine(error);
                MessageBox.Show("Seleccione un elemento");
            }
        }
        private void aceptardatos_Click(object sender, EventArgs e)
        {
            if (nombre.Text != "" && apellido1.Text != "" && apellido2.Text != "" &&
                edad.Text != "" && v.confirmable)
            {
                name     = this.nombre.Text.ToString().ToUpper();
                lastname = this.apellido1.Text.ToString().ToUpper();
                age      = this.edad.Text.ToString();
                int ageint;
                ageint = Convert.ToInt32(age);
                asientoSeleccionado = v.getNumeroAsiento() + 1;
                vuelo = v.ToString(); //tostring sobrecargado

                Pasajero p = new Pasajero(name, lastname, ageint,
                                          asientoSeleccionado, vuelo);
                v.setPasajero(p);

                foreach (int num_asiento in v.AO)
                {
                    v.setAsientoOcupado(true, num_asiento);
                    v.setAsientosDisponibles(v.getAsientos() - 1);
                }
                v.confirmable = false;


                Close();
            }
            else
            {
                MessageBox.Show("COMPLETE TODOS LOS CAMPOS Y SELECCIONE UN ASIENTO");
            }
        }
        private void buscarPasajeros_TextChanged(object sender, EventArgs e)
        {
            ListViewPasajeros.Items.Clear();
            List <Pasajero> lp = new List <Pasajero>();

            if (comboFiltroPasajeros.Text.ToString() == "Nombre")
            {
                foreach (Universal v in listaVuelos)
                {
                    for (int i = 0; i < v.getPasajerosCount(); ++i)
                    {
                        Pasajero p        = v.getPasajero(i);
                        bool     iguales  = false;
                        string   nombre   = "";
                        string   buscable = "";

                        for (int j = 0; j < buscarPasajeros.Text.Length; ++j)
                        {
                            try
                            {
                                if (buscarPasajeros.Text.Length <= p.getNombreYap().Length)
                                {
                                    nombre   = nombre + p.getNombreYap()[j];
                                    buscable = buscable + buscarPasajeros.Text[j].ToString().ToUpper();
                                    if (buscable == nombre)
                                    {
                                        iguales = true;
                                    }
                                    else
                                    {
                                        iguales = false;
                                    }
                                }
                            }
                            catch (IndexOutOfRangeException)
                            {
                                MessageBox.Show("Cadena Demasiado Grande");
                                continue;
                            }
                        }
                        if (iguales)
                        {
                            lp.Add(p);
                        }
                    }
                }
                actualizarListView(ref lp);
            }
            else if (comboFiltroPasajeros.Text.ToString() == "Vuelo")
            {
                foreach (Universal v in listaVuelos)
                {
                    for (int i = 0; i < v.getPasajerosCount(); ++i)
                    {
                        Pasajero p        = v.getPasajero(i);
                        bool     iguales  = false;
                        string   vuelo    = "";
                        string   buscable = "";

                        for (int j = 0; j < buscarPasajeros.Text.Length; ++j)
                        {
                            try
                            {
                                if (buscarPasajeros.Text.Length <= p.getNombreYap().Length)
                                {
                                    vuelo    = vuelo + p.getRuta()[j];
                                    buscable = buscable + buscarPasajeros.Text[j].ToString().ToUpper();
                                    if (buscable == vuelo)
                                    {
                                        iguales = true;
                                    }
                                    else
                                    {
                                        iguales = false;
                                    }
                                }
                            }
                            catch (IndexOutOfRangeException)
                            {
                                MessageBox.Show("Cadena Demasiado Grande");
                                continue;
                            }
                        }
                        if (iguales)
                        {
                            lp.Add(p);
                        }
                    }
                }
                actualizarListView(ref lp);
            }
            else if (comboFiltroPasajeros.Text.ToString() == "Asiento")
            {
                foreach (Universal v in listaVuelos)
                {
                    for (int i = 0; i < v.getPasajerosCount(); ++i)
                    {
                        Pasajero p        = v.getPasajero(i);
                        bool     iguales  = false;
                        int      asiento  = 0;
                        int      buscable = 0;
                        try
                        {
                            buscable = Convert.ToInt32(buscarPasajeros.Text);
                        }
                        catch (FormatException)
                        {
                            continue;
                        }

                        asiento = p.getAsiento();
                        if (buscable == asiento)
                        {
                            iguales = true;
                        }
                        else
                        {
                            iguales = false;
                        }

                        if (iguales)
                        {
                            lp.Add(p);
                        }
                    }
                }
                actualizarListView(ref lp);
            }
            else
            {
                foreach (Universal v in listaVuelos)
                {
                    for (int i = 0; i < v.getPasajerosCount(); ++i)
                    {
                        Pasajero p        = v.getPasajero(i);
                        bool     iguales  = false;
                        string   nombre   = "";
                        string   buscable = "";

                        for (int j = 0; j < buscarPasajeros.Text.Length; ++j)
                        {
                            try
                            {
                                if (buscarPasajeros.Text.Length <= p.getNombreYap().Length)
                                {
                                    nombre   = nombre + p.getNombreYap()[j];
                                    buscable = buscable + buscarPasajeros.Text[j].ToString().ToUpper();
                                    if (buscable == nombre)
                                    {
                                        iguales = true;
                                    }
                                    else
                                    {
                                        iguales = false;
                                    }
                                }
                            }
                            catch (IndexOutOfRangeException)
                            {
                                MessageBox.Show("Cadena Demasiado Grande");
                                continue;
                            }
                        }
                        if (iguales)
                        {
                            lp.Add(p);
                        }
                    }
                }
                actualizarListView(ref lp);
            }

            if (buscarPasajeros.Text.ToString() == "")
            {
                actualizarListView();
            }
        }
Ejemplo n.º 4
0
 public void setPasajero(Pasajero p)
 {
     listaPasajeros.Add(p);
 }