예제 #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Viaje       viaje       = ViajeFacade.buscarPorId(this.idViaje);
            ViajeDiario viajeDiario = new ViajeDiario();

            foreach (ViajeDiario vd in viaje.viajesDiarios)
            {
                if (vd.id == idDiario)
                {
                    viajeDiario = vd;
                }
            }
            foreach (Horario h in viaje.horarios)
            {
                if (h.parada.ciudad.nombre == viajeDiario.trayecto.origen.nombre)
                {
                    this.textoSalida.Text = h.salida;
                }
                if (h.parada.ciudad.nombre == viajeDiario.trayecto.destino.nombre)
                {
                    this.textoLlegada.Text = h.llegada;
                }
            }

            if (viajeDiario.id > -1)
            {
                int precio = viajeDiario.trayecto.precio;
                this.textoFecha.Text   = viajeDiario.fecha;
                this.textoOrigen.Text  = viajeDiario.trayecto.origen.nombre;
                this.textoDestino.Text = viajeDiario.trayecto.destino.nombre;
                this.textoTarifa.Text  = precio.ToString();
                this.textoTotal.Text   = precio.ToString();

                Button asiento;
                for (int i = 1; i <= viajeDiario.asientosDisponibles; i = i + 4)
                {
                    this.gridAsientos.RowDefinitions.Add(new RowDefinition());
                    this.gridAsientos.RowDefinitions[this.gridAsientos.RowDefinitions.Count - 1].Height = new System.Windows.GridLength(35);
                    for (int n = 0; n < 5; n++)
                    {
                        //ASIENTOS LADO CHOFER
                        if (n < 2)
                        {
                            string numero = (n + i).ToString();
                            if (Convert.ToInt32(numero) > viajeDiario.asientosDisponibles)
                            {
                                break;
                            }
                            asiento         = new Button();
                            asiento.Cursor  = Cursors.Hand;
                            asiento.Style   = Resources["BotonAzul"] as Style;
                            asiento.Content = numero;
                            asiento.Width   = 34;
                            asiento.Height  = 34;
                            asiento.Click  += new RoutedEventHandler(selecciona_Asiento);
                            asiento.Tag     = numero;
                            asiento.SetValue(Grid.ColumnProperty, n);
                            asiento.SetValue(Grid.RowProperty, this.gridAsientos.RowDefinitions.Count - 1);
                            this.gridAsientos.Children.Add(asiento);
                        }
                        else
                        {
                            //ASIENTOS OTRO LADO
                            if (n > 2)
                            {
                                string numero = (n - 1 + i).ToString();
                                if (Convert.ToInt32(numero) > viajeDiario.asientosDisponibles)
                                {
                                    break;
                                }
                                asiento         = new Button();
                                asiento.Cursor  = Cursors.Hand;
                                asiento.Style   = Resources["BotonAzul"] as Style;
                                asiento.Content = numero;
                                asiento.Width   = 34;
                                asiento.Height  = 34;
                                asiento.Click  += new RoutedEventHandler(selecciona_Asiento);
                                asiento.Tag     = numero;
                                asiento.SetValue(Grid.ColumnProperty, n);
                                asiento.SetValue(Grid.RowProperty, this.gridAsientos.RowDefinitions.Count - 1);
                                this.gridAsientos.Children.Add(asiento);
                            }
                        }
                    }
                }
            }
        }
        private void editar_Click(object sender, RoutedEventArgs e)
        {
            if (validarUpdate())
            {
                // UPDATE

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

                    if ((row == 0) && (col == 0 || col == 1 || col == 2))
                    {
                        Label label = (Label)ui;
                    }
                    else
                    {
                        TextBox txt        = (TextBox)ui;
                        string  textoCelda = txt.Text;
                        if (row > 0 && col < 2)
                        {
                            if (contador == 0)
                            {
                                listHorariosLlegadaUpdate.Add(textoCelda);
                                contador = 1;
                            }
                            else
                            {
                                listHorariosSalidaUpdate.Add(textoCelda);
                                contador = 0;
                            }
                        }
                    }
                }


                MySqlConnection con;

                for (int i = 0; i < (paradas.Count); i++)
                {
                    con = conexionDB.ObtenerConexion();
                    Viaje ciudad = ViajeFacade.buscarPorId(this.id_viaje);

                    Parada paradaCiudad = ParadaFacade.buscarPorRecorridoCiudad(ciudad.recorrido, this.paradas[i]);

                    string       updateString  = "UPDATE HORARIOS SET LLEGADA=?llegada, SALIDA=?salida WHERE VIAJE=?viaje AND PARADA=?parada";
                    MySqlCommand updateCommand = new MySqlCommand(updateString, con);
                    updateCommand.Parameters.Add("?llegada", listHorariosLlegadaUpdate[i]);
                    updateCommand.Parameters.Add("?salida", listHorariosSalidaUpdate[i]);
                    updateCommand.Parameters.Add("?viaje", this.id_viaje);
                    updateCommand.Parameters.Add("?parada", paradaCiudad.id);

                    updateCommand.ExecuteNonQuery();
                    con.Close();
                }

                MySqlConnection con2 = conexionDB.ObtenerConexion();
                string          updateDatosViajes  = "UPDATE VIAJES_DIARIOS SET BUS=?bus, AUXILIAR=?auxiliar,CHOFER=?chofer WHERE VIAJE=?viaje";
                MySqlCommand    updateDatosCommand = new MySqlCommand(updateDatosViajes, con2);
                updateDatosCommand.Parameters.Add("?bus", comboBus.Text);
                updateDatosCommand.Parameters.Add("?auxiliar", obtenerRutPersonaByNombre(comboAuxiliar.Text, "AUXILIAR"));
                updateDatosCommand.Parameters.Add("?chofer", obtenerRutPersonaByNombre(comboChofer.Text, "CHOFER"));
                updateDatosCommand.Parameters.Add("?viaje", this.id_viaje);

                updateDatosCommand.ExecuteNonQuery();
                con2.Close();

                nuevoViajeDiario = new nuevoViaje();
                nuevoViajeDiario.Show();
                nuevoViajeDiario.saludo.Text     = "Gracias por actualizar nuestros registros";
                nuevoViajeDiario.textBlock1.Text = "Se ha actualizado correctamente el viaje en el sistema";
            }
        }
        public paradasViaje(int idViaje, string origen, string destino)
        {
            InitializeComponent();
            Viaje viaje = ViajeFacade.buscarPorId(idViaje);

            if (viaje != null)
            {
                Label    valor;
                string[] itemsTabla = new string[3];
                bool     intermedio = false;
                foreach (Horario h in viaje.horarios)
                {
                    if (intermedio == false)
                    {
                        if (h.parada.ciudad.nombre == origen)
                        {
                            intermedio    = true;
                            itemsTabla[0] = h.parada.ciudad.nombre;
                            itemsTabla[1] = h.llegada;
                            itemsTabla[2] = h.salida;

                            this.tablaParadas.RowDefinitions.Add(new RowDefinition());
                            this.tablaParadas.RowDefinitions[this.tablaParadas.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.tablaParadas.RowDefinitions.Count - 1);
                                this.tablaParadas.Children.Add(valor);
                            }
                        }
                    }
                    else
                    {
                        if (h.parada.ciudad.nombre == destino)
                        {
                            itemsTabla[0] = h.parada.ciudad.nombre;
                            itemsTabla[1] = h.llegada;
                            itemsTabla[2] = h.salida;

                            this.tablaParadas.RowDefinitions.Add(new RowDefinition());
                            this.tablaParadas.RowDefinitions[this.tablaParadas.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.tablaParadas.RowDefinitions.Count - 1);
                                this.tablaParadas.Children.Add(valor);
                            }
                            break;
                        }
                        else
                        {
                            itemsTabla[0] = h.parada.ciudad.nombre;
                            itemsTabla[1] = h.llegada;
                            itemsTabla[2] = h.salida;

                            this.tablaParadas.RowDefinitions.Add(new RowDefinition());
                            this.tablaParadas.RowDefinitions[this.tablaParadas.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.tablaParadas.RowDefinitions.Count - 1);
                                this.tablaParadas.Children.Add(valor);
                            }
                        }
                    }
                }
            }
        }