Esempio n. 1
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 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 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.");
            }
        }
        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++;
                }
            }
        }