private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.ciudades2 = CiudadFacade.buscarTodos();
            foreach (Ciudad c in this.ciudades2)
            {
                this.listCiudad.Items.Add((string)c.nombre);
                this.ciudades.Add(c.nombre, c.id);
            }

            MySqlConnection con = conexionDB.ObtenerConexion();

            try
            {
                string          sql  = "SELECT NOMBRE FROM REGION ORDER BY ID";
                MySqlCommand    cmd  = new MySqlCommand(sql, con);
                MySqlDataReader data = cmd.ExecuteReader();

                while (data.Read())
                {
                    ComboBoxItem r = new ComboBoxItem();
                    r.Content = data.GetString(0);
                    this.comboRegion.Items.Add(r);
                }
                data.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
        }
        private void comboOrigen_DropDownClosed(object sender, EventArgs e)
        {
            comboDestino.Items.Clear();
            // OBTENER ID CIUDAD ELEGIDA.

            List <int> recorridos = new List <int>();

            string ciudadOrigenElegida = this.comboOrigen.Text;
            Ciudad origen = CiudadFacade.buscarCiudadPorNombre(ciudadOrigenElegida);

            List <Parada> Origenes = ParadaFacade.buscarOrigenesGenerales();

            foreach (Parada ciudadesOrigenes in Origenes)
            {
                if (ciudadesOrigenes.ciudad.nombre.Equals(ciudadOrigenElegida))
                {
                    recorridos.Add(ciudadesOrigenes.recorrido);
                }
            }

            List <Parada> destinos = ParadaFacade.buscarDestinosGeneralesByCiudad(origen, recorridos);

            foreach (Parada ciudad in destinos)
            {
                Boolean validarCiudades = true;;

                for (int i = 0; i < this.comboDestino.Items.Count; i++)
                {
                    if (ciudad.ciudad.nombre.Equals(this.comboDestino.Items.GetItemAt(i)))
                    {
                        validarCiudades = false;
                    }
                }
                if (validarCiudades)
                {
                    this.comboDestino.Items.Add(ciudad.ciudad.nombre);
                }
            }
        }
Esempio n. 3
0
        private void Guardar_Click(object sender, RoutedEventArgs e)
        {
            if (this.lp.Count > 1)
            {
                bool            okPrecios = true;
                TextBox         txt;
                int             idParada  = -1;
                List <Trayecto> trayectos = new List <Trayecto>();
                string[,] precios = new string[this.lp.Count, this.lp.Count];

                foreach (UIElement ui in this.tabla.Children)
                {
                    int row = System.Windows.Controls.Grid.GetRow(ui);
                    int col = System.Windows.Controls.Grid.GetColumn(ui);

                    if (row != 0 && col != 0)
                    {
                        txt = (TextBox)ui;
                        precios[row - 1, col - 1] = txt.Text;
                    }
                }
                try
                {
                    idParada = ParadaFacade.obtenerProximoId();
                    idParada = idParada + lp.Count - 1;
                    Parada parada    = new Parada(idParada, CiudadFacade.buscarPorNombre(lp[lp.Count - 1]), new Parada());
                    Parada siguiente = parada;
                    Console.WriteLine("Ultima parada: " + parada.id + " siguiente: " + parada.siguiente.id);

                    //     Estructura las paradas
                    for (int i = lp.Count - 2; i > -1; i--)
                    {
                        idParada  = idParada - 1;
                        parada    = new Parada(idParada, CiudadFacade.buscarPorNombre(lp[i]), siguiente);
                        siguiente = parada;
                        Console.WriteLine("Parada: " + parada.id + " siguiente: " + parada.siguiente.id);
                    }
                    // estructura los trayectos
                    for (int i = 0; i < lp.Count; i++)
                    {
                        for (int j = i + 1; j < lp.Count; j++)
                        {
                            if (Convert.ToInt32(precios[i, j]) <= 0)
                            {
                                okPrecios = false;
                            }
                            trayectos.Add(new Trayecto(CiudadFacade.buscarPorNombre(lp[i]), CiudadFacade.buscarPorNombre(lp[j]), Convert.ToInt32(precios[i, j])));
                        }
                    }
                    Recorrido recorrido = new Recorrido(parada, trayectos);

                    try
                    {
                        if (okPrecios == true)
                        {
                            RecorridoFacade.guardar(recorrido);
                            okAlerta alert = new okAlerta();
                            alert.show("Recorrido Ingresado Correctamente");
                            this.DialogResult = true;
                            this.Close();
                        }
                        else
                        {
                            validar alert = new validar();
                            alert.show("La Tarifa del trayecto debe ser MAYOR que 0");
                        }
                    }
                    catch (Exception ex)
                    {
                        validar alert = new validar();
                        alert.show("No se pudo Guardar el Recorrido. Por favor verifique los datos");
                    }
                }
                catch (Exception ex)
                {
                    validar alert = new validar();
                    alert.show("Error al obtener datos. Verifique las paradas nuevamente.");
                }
            }
            else
            {
                validar alert = new validar();
                alert.show("El Recorrido debe tener como minimo dos Paradas");
            }
        }
        private void botonBuscar_Click(object sender, RoutedEventArgs e)
        {
            this.gridMuestraViajes.Visibility = Visibility.Hidden;
            this.tablaViajes.Children.Clear();
            this.tablaViajes.RowDefinitions.Clear();
            if (this.comboOrigen.SelectedIndex > -1 && this.comboDestino.SelectedIndex > -1)
            {
                if (this.buscarFecha.Text != "")
                {
                    bool     existen = false;
                    Label    valor;
                    Button   ver;
                    string[] itemsTabla = new string[4];
                    string   salida     = "";
                    string   llegada    = "";
                    string   fecha      = this.buscarFecha.Text;

                    Ciudad origen  = CiudadFacade.buscarPorNombre(this.comboOrigen.SelectedItem.ToString());
                    Ciudad destino = CiudadFacade.buscarPorNombre(this.comboDestino.SelectedItem.ToString());

                    try
                    {
                        List <Viaje> viajes = ViajeFacade.buscarPorOrigenDestino(origen.nombre, destino.nombre);
                        if (viajes.Count > 0)
                        {
                            foreach (Viaje viaje in viajes)
                            {
                                foreach (ViajeDiario vd in viaje.viajesDiarios)
                                {
                                    if (vd.fecha == fecha && vd.trayecto.origen.id == origen.id && vd.trayecto.destino.id == destino.id)
                                    {
                                        existen = true;
                                        foreach (Horario horario in viaje.horarios)
                                        {
                                            if (horario.parada.ciudad.id == origen.id)
                                            {
                                                salida = origen.nombre + " - " + horario.salida;
                                            }
                                            if (horario.parada.ciudad.id == destino.id)
                                            {
                                                llegada = destino.nombre + " - " + horario.llegada;
                                            }
                                        }

                                        itemsTabla[0] = salida;
                                        itemsTabla[1] = llegada;
                                        itemsTabla[2] = vd.trayecto.precio.ToString();
                                        itemsTabla[3] = viaje.identificador;

                                        this.tablaViajes.RowDefinitions.Add(new RowDefinition());
                                        this.tablaViajes.RowDefinitions[this.tablaViajes.RowDefinitions.Count - 1].Height = new System.Windows.GridLength(30);
                                        for (int n = 0; n < itemsTabla.Length; n++)
                                        {
                                            valor                     = new Label();
                                            valor.Style               = Resources["ItemViaje"] as Style;
                                            valor.Content             = itemsTabla[n];
                                            valor.HorizontalAlignment = HorizontalAlignment.Center;
                                            valor.SetValue(Grid.ColumnProperty, n);
                                            valor.SetValue(Grid.RowProperty, this.tablaViajes.RowDefinitions.Count - 1);
                                            this.tablaViajes.Children.Add(valor);
                                        }
                                        BitmapImage btm = new BitmapImage(new Uri("/SmarTravel_Final;component/Images/continue.png", UriKind.Relative));
                                        Image       img = new Image();
                                        img.Source  = btm;
                                        img.Stretch = Stretch.Uniform;

                                        ver         = new Button();
                                        ver.Cursor  = Cursors.Hand;
                                        ver.Style   = Resources["BotonSinBorde"] as Style;
                                        ver.Content = img;
                                        ver.Click  += new RoutedEventHandler(verViaje_Click);
                                        ver.Tag     = viaje.id.ToString() + "/" + vd.id.ToString();
                                        ver.SetValue(Grid.ColumnProperty, 4);
                                        ver.SetValue(Grid.RowProperty, this.tablaViajes.RowDefinitions.Count - 1);
                                        this.tablaViajes.Children.Add(ver);
                                    }
                                }
                            }
                            if (existen == true)
                            {
                                this.gridMuestraViajes.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                validar alert = new validar();
                                alert.show("No existen viajes disponibles para esta fecha.");
                            }
                        }
                        else
                        {
                            validar alert = new validar();
                            alert.show("No existen viajes disponibles.");
                        }
                    }
                    catch (Exception ex)
                    {
                        validar alert = new validar();
                        alert.show("No se pudo obtener los viajes disponibles.");
                    }
                }
                else
                {
                    validar alert = new validar();
                    alert.show("Seleccione una fecha de busqueda.");
                }
            }
            else
            {
                validar alert = new validar();
                alert.show("Debe seleccionar origen y destino.");
            }
        }
        public void crearTabla()
        {
            horarios.RowDefinitions.Clear();
            paradas.Clear();
            TextBox tHorarios;

            try
            {
                // ENCABEZADO 3 COLUMNAS EN LA PRIMERA FILA

                this.horarios.ColumnDefinitions.Add(new ColumnDefinition());
                this.horarios.ColumnDefinitions.Add(new ColumnDefinition());
                this.horarios.ColumnDefinitions.Add(new ColumnDefinition());
                this.horarios.RowDefinitions.Add(new RowDefinition());


                Label llegadaHeader = new Label();
                llegadaHeader.Content = "LLEGADA";
                llegadaHeader.Style   = Resources["HeaderTabla"] as Style;

                llegadaHeader.SetValue(Grid.ColumnProperty, 0);
                llegadaHeader.SetValue(Grid.RowProperty, 0);
                this.horarios.Children.Add(llegadaHeader);

                Label salidadHeader = new Label();
                salidadHeader.Content = "SALIDA";
                salidadHeader.Style   = Resources["HeaderTabla"] as Style;

                salidadHeader.SetValue(Grid.ColumnProperty, 1);
                salidadHeader.SetValue(Grid.RowProperty, 0);
                this.horarios.Children.Add(salidadHeader);

                Label intermediosHeader = new Label();
                intermediosHeader.Content = "INTERMEDIOS";
                intermediosHeader.Style   = Resources["HeaderTabla"] as Style;
                intermediosHeader.Width   = 200;
                intermediosHeader.SetValue(Grid.ColumnProperty, 2);
                intermediosHeader.SetValue(Grid.RowProperty, 0);
                this.horarios.Children.Add(intermediosHeader);


                MySqlConnection con = conexionDB.ObtenerConexion();
                string          sql = "SELECT LLEGADA,SALIDA,P.CIUDAD FROM HORARIOS AS H INNER JOIN PARADA AS P ON H.PARADA = P.ID WHERE VIAJE = " + this.id_viaje;

                MySqlCommand    cmd = new MySqlCommand(sql, con);
                MySqlDataReader dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    if (!dr.GetString(0).Equals("-"))
                    {
                        listHorarios.Add(dr.GetString(0));
                    }
                    if (!dr.GetString(1).Equals("-"))
                    {
                        listHorarios.Add(dr.GetString(1));
                    }

                    Ciudad parada = CiudadFacade.buscarPorId(dr.GetInt32(2));
                    paradas.Add(parada.nombre);
                }
                con.Close();


                this.horarios.ColumnDefinitions[0].Width = new System.Windows.GridLength(120);
                this.horarios.ColumnDefinitions[1].Width = new System.Windows.GridLength(120);
                this.horarios.ColumnDefinitions[2].Width = new System.Windows.GridLength(220);
                int largo = paradas.Count;
                for (int z = 0; z < largo; z++)
                {
                    //this.horarios.ColumnDefinitions.Add(new ColumnDefinition());
                    this.horarios.RowDefinitions.Add(new RowDefinition());

                    this.horarios.RowDefinitions[z].Height = new System.Windows.GridLength(50);
                }
                this.horarios.RowDefinitions[0].Height = new System.Windows.GridLength(30);
                this.horarios.RowDefinitions[horarios.RowDefinitions.Count - 1].Height = new System.Windows.GridLength(50);
                int contador        = 0;
                int registrohorario = 0;
                for (int row = 1; row < this.horarios.RowDefinitions.Count; row++)
                {
                    for (int col = 0; col < this.horarios.ColumnDefinitions.Count; col++)
                    {
                        if ((col == 0 && row == 1) || (col == 1 && row == horarios.RowDefinitions.Count - 1))
                        {
                            tHorarios       = new TextBox();
                            tHorarios.Style = Resources["ItemTablaGuion"] as Style;
                            tHorarios.Text  = "-";
                            tHorarios.SetValue(Grid.ColumnProperty, col);
                            tHorarios.SetValue(Grid.RowProperty, row);
                            tHorarios.IsReadOnly = true;
                            this.horarios.Children.Add(tHorarios);
                        }
                        else if (col == 2 && row != 0)
                        {
                            if (contador < paradas.Count)
                            {
                                tHorarios       = new TextBox();
                                tHorarios.Style = Resources["ItemTablaGuion"] as Style;
                                tHorarios.Text  = paradas[contador];
                                tHorarios.SetValue(Grid.ColumnProperty, col);
                                tHorarios.SetValue(Grid.RowProperty, row);
                                tHorarios.IsReadOnly = true;
                                this.horarios.Children.Add(tHorarios);
                            }
                        }
                        else
                        {
                            tHorarios            = new TextBox();
                            tHorarios.Style      = Resources["ItemTablaGuion"] as Style;
                            tHorarios.Text       = listHorarios[registrohorario];
                            tHorarios.MaxLength  = 5;
                            tHorarios.IsReadOnly = false;
                            tHorarios.SetValue(Grid.ColumnProperty, col);
                            tHorarios.SetValue(Grid.RowProperty, row);
                            this.horarios.Children.Add(tHorarios);
                            registrohorario++;
                        }
                    }
                    contador++;
                }
                //MessageBox.Show("Childe"+this.horarios.Children.Count);
                con.Open();
                sql = "SELECT BUS,CHOFER,AUXILIAR,DESDE,HASTA FROM VIAJES_DIARIOS AS VD INNER JOIN VIAJES AS V ON VD.VIAJE=V.ID WHERE VIAJE = " + this.id_viaje + " limit 1";
                cmd = new MySqlCommand(sql, con);
                dr  = cmd.ExecuteReader();

                while (dr.Read())
                {
                    this.comboBus.Text      = dr.GetString(0);
                    this.fechaDesde.Text    = dr.GetString(3);
                    this.fechaHasta.Text    = dr.GetString(4);
                    this.comboAuxiliar.Text = obtenerNombrePersonaByRut(dr.GetString(2), "AUXILIAR");
                    this.comboChofer.Text   = obtenerNombrePersonaByRut(dr.GetString(1), "CHOFER");
                }
                con.Close();
            }    // Fin TRY



            catch (Exception ex)
            {
                validar validarError = new validar();
                validarError.show(ex.Message);
            }
        }
        private void button5_Click(object sender, RoutedEventArgs e)
        {
            if (validarEditViajeDiario())
            {
                listadoRecorridos.RowDefinitions.Clear();
                listadoRecorridos.ColumnDefinitions.Clear();
                this.listadoRecorridos.Visibility = Visibility.Visible;

                List <string> listHorarioSalida  = new List <string>();
                List <string> listHorarioLlegada = new List <string>();

                Ciudad       origen  = CiudadFacade.buscarPorNombre(this.cOrigenEditar.Text);
                Ciudad       destino = CiudadFacade.buscarPorNombre(this.cDestinoEditar.Text);
                List <Viaje> allViajesByOrigenDestino = ViajeFacade.buscarViajePorOrigenAndDestino(origen, destino);
                try
                {
                    if (allViajesByOrigenDestino.Count > -1)
                    {
                        // Obtener HORARIO DE SALIDA Y LLEGADA
                        for (int i = 0; i < allViajesByOrigenDestino.Count; i++)
                        {
                            MySqlConnection con = conexionDB.ObtenerConexion();
                            string          sql = "SELECT SALIDA FROM HORARIOS WHERE LLEGADA = '-' AND VIAJE =" + allViajesByOrigenDestino[i].id;
                            MySqlCommand    cmd = new MySqlCommand(sql, con);

                            MySqlDataReader dr = cmd.ExecuteReader();

                            while (dr.Read())
                            {
                                listHorarioSalida.Add(dr.GetString(0));
                            }
                            con.Close();

                            con.Open();
                            string sqlHoraLlegada = "SELECT LLEGADA FROM HORARIOS WHERE SALIDA = '-' AND VIAJE =" + allViajesByOrigenDestino[i].id;

                            MySqlCommand cmd2 = new MySqlCommand(sqlHoraLlegada, con);

                            MySqlDataReader dr2 = cmd2.ExecuteReader();

                            while (dr2.Read())
                            {
                                listHorarioLlegada.Add(dr2.GetString(0));
                            }
                            con.Close();
                        }


                        darFormatoListadoRecorridos();

                        // CREAR FILAS SEGUN RESULTADO
                        int largo = allViajesByOrigenDestino.Count;
                        this.listadoRecorridos.ColumnDefinitions[0].Width = new System.Windows.GridLength(180);
                        this.listadoRecorridos.ColumnDefinitions[1].Width = new System.Windows.GridLength(185);
                        this.listadoRecorridos.ColumnDefinitions[2].Width = new System.Windows.GridLength(120);
                        this.listadoRecorridos.ColumnDefinitions[3].Width = new System.Windows.GridLength(60);

                        for (int z = 0; z < largo; z++)
                        {
                            this.listadoRecorridos.RowDefinitions.Add(new RowDefinition());
                            this.listadoRecorridos.RowDefinitions[z].Height = new System.Windows.GridLength(40);
                        }
                        this.listadoRecorridos.RowDefinitions[0].Height = new System.Windows.GridLength(30);
                        this.listadoRecorridos.RowDefinitions[listadoRecorridos.RowDefinitions.Count - 1].Height = new System.Windows.GridLength(40);


                        int     contador = 0;
                        TextBox tHorarios;
                        for (int row = 1; row < this.listadoRecorridos.RowDefinitions.Count; row++)
                        {
                            for (int col = 0; col < this.listadoRecorridos.ColumnDefinitions.Count; col++)
                            {
                                if (col == 0)
                                {
                                    tHorarios       = new TextBox();
                                    tHorarios.Style = Resources["ItemTablaGuion"] as Style;
                                    tHorarios.Text  = origen.nombre + "- " + destino.nombre;
                                    tHorarios.SetValue(Grid.ColumnProperty, col);
                                    tHorarios.SetValue(Grid.RowProperty, row);
                                    tHorarios.IsReadOnly = true;
                                    this.listadoRecorridos.Children.Add(tHorarios);
                                }
                                if (col == 1)
                                {
                                    tHorarios       = new TextBox();
                                    tHorarios.Style = Resources["ItemTablaGuion"] as Style;
                                    tHorarios.Text  = allViajesByOrigenDestino[contador].identificador;
                                    tHorarios.SetValue(Grid.ColumnProperty, col);
                                    tHorarios.SetValue(Grid.RowProperty, row);
                                    tHorarios.IsReadOnly = true;
                                    this.listadoRecorridos.Children.Add(tHorarios);
                                }
                                if (col == 2)
                                {
                                    tHorarios       = new TextBox();
                                    tHorarios.Style = Resources["ItemTablaGuion"] as Style;

                                    tHorarios.Text = listHorarioSalida[contador] + " - " + listHorarioLlegada[contador];
                                    tHorarios.SetValue(Grid.ColumnProperty, col);
                                    tHorarios.SetValue(Grid.RowProperty, row);
                                    tHorarios.IsReadOnly = true;
                                    this.listadoRecorridos.Children.Add(tHorarios);
                                }
                                if (col == 3)
                                {
                                    BitmapImage btm = new BitmapImage(new Uri("/SmarTravel_Final;component/Images/busquedaIcon.png", UriKind.Relative));
                                    Image       img = new Image();
                                    img.Source  = btm;
                                    img.Stretch = Stretch.Fill;
                                    img.Width   = 30;
                                    img.Height  = 30;
                                    Button b = new Button();
                                    b.Click += new RoutedEventHandler(b_Click);

                                    //b.Content = "VER"
                                    b.Content = img;

                                    b.Tag = Convert.ToString(allViajesByOrigenDestino[contador].id);
                                    b.SetValue(Grid.ColumnProperty, col);
                                    b.SetValue(Grid.RowProperty, row);


                                    this.listadoRecorridos.Children.Add(b);
                                }
                            } // Fin columnas
                            contador++;
                        }     // FIn tabla
                    }

                    else
                    {
                        validar v = new validar();
                        v.show("No hay viajes diarios creados");
                    }
                } // Fin try
                catch (Exception ex)
                {
                    validar v = new validar();
                    v.show(ex.Message);
                }
            } // Fin validar datos
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (validarIngresoViajeDiario())
            {
                //listadoId.Clear();
                cabecerasAgregarViajes();
                this.gridAgregarViajes.Visibility = Visibility.Visible;
                Ciudad origen  = CiudadFacade.buscarPorNombre(this.comboOrigen.SelectedItem.ToString());
                Ciudad destino = CiudadFacade.buscarPorNombre(this.comboDestino.SelectedItem.ToString());

                listadoId = RecorridoFacade.RecorridoByOrigenDestino(origen, destino);
                List <string> nombreIntermedios = new List <string>();

                for (int z = 0; z < listadoId.Count; z++)
                {
                    nombreIntermedios.Add(ParadaFacade.nombresIntermediosByRecorridos(listadoId[z].id));
                }

                int largo = listadoId.Count - 1;
                this.gridAgregarViajes.ColumnDefinitions[0].Width = new System.Windows.GridLength(500);
                this.gridAgregarViajes.ColumnDefinitions[1].Width = new System.Windows.GridLength(80);
                for (int z = 0; z <= largo; z++)
                {
                    this.gridAgregarViajes.RowDefinitions.Add(new RowDefinition());
                    this.gridAgregarViajes.RowDefinitions[z].Height = new System.Windows.GridLength(40);
                }
                this.gridAgregarViajes.RowDefinitions[gridAgregarViajes.RowDefinitions.Count - 1].Height = new System.Windows.GridLength(40);
                int     contador = 0;
                TextBox texto;
                for (int row = 1; row < this.gridAgregarViajes.RowDefinitions.Count; row++)
                {
                    for (int col = 0; col < this.gridAgregarViajes.ColumnDefinitions.Count; col++)
                    {
                        if (col == 0)
                        {
                            texto       = new TextBox();
                            texto.Style = Resources["ItemTablaGuion"] as Style;

                            texto.Text = nombreIntermedios[contador];
                            texto.SetValue(Grid.ColumnProperty, col);
                            texto.SetValue(Grid.RowProperty, row);
                            texto.IsReadOnly = true;
                            this.gridAgregarViajes.Children.Add(texto);
                        }

                        if (col == 1)
                        {
                            BitmapImage btm = new BitmapImage(new Uri("/SmarTravel_Final;component/Images/crear.png", UriKind.Relative));
                            Image       img = new Image();
                            img.Source  = btm;
                            img.Stretch = Stretch.Fill;
                            img.Width   = 50;
                            img.Height  = 30;
                            Button bIngreso = new Button();
                            bIngreso.Click  += new RoutedEventHandler(bIngreso_Click);
                            bIngreso.Content = img;
                            bIngreso.Tag     = Convert.ToString(contador);
                            bIngreso.SetValue(Grid.ColumnProperty, col);
                            bIngreso.SetValue(Grid.RowProperty, row);
                            this.gridAgregarViajes.Children.Add(bIngreso);
                        }
                    }
                    contador++;
                }
            }
        }