private void comboDestinoReco_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     this.listRecorridos.Items.Clear();
     try
     {
         this.recorridos = RecorridoFacade.buscarPorOrigenDestino(this.comboOrigenReco.SelectedItem.ToString(), this.comboDestinoReco.SelectedItem.ToString());
         if (this.recorridos.Count > 0)
         {
             foreach (Recorrido rec in this.recorridos)
             {
                 Parada p = rec.parada;
                 while (p.id != -1)
                 {
                     if (p.siguiente.id == -1)
                     {
                         break;
                     }
                     else
                     {
                         p = p.siguiente;
                     }
                 }
                 this.listRecorridos.Items.Add(rec.id + ". " + rec.parada.ciudad.nombre + " - " + p.ciudad.nombre);
             }
         }
         else
         {
             validar alert = new validar();
             alert.show("No hay recorridos asociados");
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("comboDestinoReco_SelectionChanged: " + ex.Message);
     }
 }
Esempio n. 2
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 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++;
                }
            }
        }
        private void tabEditarViajeDiario_Selected(object sender, RoutedEventArgs e)
        {
            formatoTablaViaje();
            List <Viaje>  allViajes          = ViajeFacade.buscarAllViajes();
            List <string> listHorarioSalida  = new List <string>();
            List <string> listHorarioLlegada = new List <string>();
            int           largo = allViajes.Count;

            for (int z = 0; z < largo; z++)
            {
                this.ListadoViajes.RowDefinitions.Add(new RowDefinition());

                this.ListadoViajes.RowDefinitions[z].Height = new System.Windows.GridLength(40);
            }
            this.ListadoViajes.RowDefinitions[0].Height = new System.Windows.GridLength(25);
            this.ListadoViajes.RowDefinitions[ListadoViajes.RowDefinitions.Count - 1].Height = new System.Windows.GridLength(40);


            List <string> nombreIntermedios = new List <string>();

            foreach (Viaje viaje in allViajes)
            {
                List <Recorrido> listado = RecorridoFacade.OrigenDestinoByRecorrido(viaje.reco);
                foreach (Recorrido ciudad in listado)
                {
                    // TENGO LOS ORIGENES Y DESTINOS DE LOS VIAJES
                    nombreIntermedios.Add(ciudad.origen.nombre + " - " + ciudad.destino.nombre);
                }
            }

            if (allViajes.Count > -1)
            {
                // Obtener HORARIO DE SALIDA Y LLEGADA
                for (int i = 0; i < allViajes.Count; i++)
                {
                    MySqlConnection con = conexionDB.ObtenerConexion();
                    string          sql = "SELECT SALIDA FROM HORARIOS WHERE LLEGADA = '-' AND VIAJE =" + allViajes[i].id;
                    MySqlCommand    cmd = new MySqlCommand(sql, con);

                    MySqlDataReader dr = cmd.ExecuteReader();

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

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

                    MySqlCommand cmd2 = new MySqlCommand(sqlHoraLlegada, con);

                    MySqlDataReader dr2 = cmd2.ExecuteReader();

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


                TextBox celda;
                int     contador = 0;
                for (int row = 1; row < this.ListadoViajes.RowDefinitions.Count; row++)
                {
                    for (int col = 0; col < this.ListadoViajes.ColumnDefinitions.Count; col++)
                    {
                        if (col == 0)
                        {
                            celda       = new TextBox();
                            celda.Style = Resources["ItemTablaGuion"] as Style;
                            celda.Text  = nombreIntermedios[contador];
                            celda.SetValue(Grid.ColumnProperty, col);
                            celda.SetValue(Grid.RowProperty, row);
                            celda.IsReadOnly = true;
                            this.ListadoViajes.Children.Add(celda);
                        }
                        if (col == 1)
                        {
                            celda       = new TextBox();
                            celda.Style = Resources["ItemTablaGuion"] as Style;
                            celda.Text  = listHorarioSalida[contador] + " - " + listHorarioLlegada[contador];
                            celda.SetValue(Grid.ColumnProperty, col);
                            celda.SetValue(Grid.RowProperty, row);
                            celda.IsReadOnly = true;
                            this.ListadoViajes.Children.Add(celda);
                        }
                        if (col == 2)
                        {
                            celda       = new TextBox();
                            celda.Style = Resources["ItemTablaGuion"] as Style;
                            celda.Text  = allViajes[contador].identificador;
                            celda.SetValue(Grid.ColumnProperty, col);
                            celda.SetValue(Grid.RowProperty, row);
                            celda.IsReadOnly = true;
                            this.ListadoViajes.Children.Add(celda);
                        }
                        if (col == 3)
                        {
                            celda       = new TextBox();
                            celda.Style = Resources["ItemTablaGuion"] as Style;

                            celda.Text = allViajes[contador].fechaDesde;
                            celda.SetValue(Grid.ColumnProperty, col);
                            celda.SetValue(Grid.RowProperty, row);
                            celda.IsReadOnly = true;
                            this.ListadoViajes.Children.Add(celda);
                        }
                        if (col == 4)
                        {
                            celda       = new TextBox();
                            celda.Style = Resources["ItemTablaGuion"] as Style;

                            celda.Text = allViajes[contador].fechaHasta;
                            celda.SetValue(Grid.ColumnProperty, col);
                            celda.SetValue(Grid.RowProperty, row);
                            celda.IsReadOnly = true;
                            this.ListadoViajes.Children.Add(celda);
                        }
                        if (col == 5)
                        {
                            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 buttonNewViaje = new Button();
                            buttonNewViaje.Click += new RoutedEventHandler(buttonNewViaje_Click);

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

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


                            this.ListadoViajes.Children.Add(buttonNewViaje);
                        }
                    }
                    contador++;
                }
            }
        } // Fin metodo