Пример #1
0
        private void btnagregarbus_Click(object sender, RoutedEventArgs e)
        {
            if (panelUsuario.validar1(txtModelo.Text, lbModelo.Text, comboMarca.Text, lbMarca.Text, cbxEstado.Text, lblEstado.Text, fechaPermiso.Text, label2.Text, año.Text, label5.Text, comboCiudad.Text, label6.Text) && validapatente1(txtPatente.Text))
            {
                string rbSeleccionado = "";

                if (rbSi.IsChecked == true)
                {
                    rbSeleccionado = "SI";
                }
                else
                {
                    rbSeleccionado = "NO";
                }


                try
                {
                    // Validar antes de esto, al comienzo....
                    //if (this.txtbRuta.Text.Equals("Ruta"))
                    //    MessageBox.Show("No ha seleccionado ruta");
                    //else if (patente.Equals("") || modelo.Equals(""))
                    //    MessageBox.Show("Falta llenar un campo");
                    //else
                    //{
                    MySqlConnection con = conexionDB.ObtenerConexion();
                    MySqlCommand    cmd;

                    string path = System.IO.Directory.GetCurrentDirectory();
                    path = path.Substring(0, path.Length - 9);
                    path = path + "Images/fotosBuses/";
                    string filePath = path + System.IO.Path.GetFileName(nameImagen);


                    System.IO.File.Copy(nameImagen, filePath, true);

                    string sqlID_CIUDAD = "SELECT ID FROM CIUDAD WHERE NOMBRE = '" + comboCiudad.Text + "'";
                    cmd = new MySqlCommand(sqlID_CIUDAD, con);

                    MySqlDataReader dr = cmd.ExecuteReader();

                    int numeroCiudad = 0;
                    while (dr.Read())
                    {
                        numeroCiudad = dr.GetInt32(0);
                    }
                    con.Close();

                    con.Open();
                    string       insertString  = "INSERT INTO BUS (patente,modelo,marca,year,vigencia_permiso,fecha_permiso,estado,imagen,ubicacion) VALUES (?patente,?modelo,?marca,?year,?vigencia,?fecha,?estado,?imagen,?ciudad)";
                    MySqlCommand insertCommand = new MySqlCommand(insertString, con);
                    insertCommand.Parameters.Add("?patente", txtPatente.Text);
                    insertCommand.Parameters.Add("?modelo", txtModelo.Text);
                    insertCommand.Parameters.Add("?marca", comboMarca.Text);
                    insertCommand.Parameters.Add("?year", año.Text);
                    insertCommand.Parameters.Add("?vigencia", rbSeleccionado);
                    insertCommand.Parameters.Add("?fecha", fechaPermiso.Text);
                    insertCommand.Parameters.Add("?estado", cbxEstado.Text);
                    insertCommand.Parameters.Add("?imagen", filePath.ToString());
                    insertCommand.Parameters.Add("?ciudad", numeroCiudad);


                    insertCommand.ExecuteNonQuery();

                    nuevoBus busNuevo = new nuevoBus();

                    busNuevo.Show();

                    this.txtModelo.Text           = "";
                    this.comboMarca.SelectedIndex = -1;
                    this.txtPatente.Text          = "";
                    this.cbxEstado.SelectedIndex  = -1;

                    this.rbSi.IsChecked            = false;
                    this.rbNo.IsChecked            = false;
                    this.fechaPermiso.Text         = "";
                    this.año.Text                  = "";
                    this.comboCiudad.SelectedIndex = -1;

                    string pathImagen = System.IO.Directory.GetCurrentDirectory();


                    pathImagen = pathImagen.Substring(0, pathImagen.Length - 9);

                    pathImagen = pathImagen + "Images/bus generico gris.jpg";

                    var uri    = new Uri(pathImagen);
                    var bitmap = new BitmapImage(uri);
                    this.examinarBus.Source = bitmap;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Пример #2
0
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (txtModelo.IsReadOnly == false)
            {
                if (validarUpdate())
                {
                    try
                    {
                        MySqlConnection con = conexionDB.ObtenerConexion();

                        string       sqlID_CIUDAD = "SELECT ID FROM CIUDAD WHERE NOMBRE = '" + ciudad.Text + "'";
                        MySqlCommand cmd          = new MySqlCommand(sqlID_CIUDAD, con);

                        MySqlDataReader dr = cmd.ExecuteReader();

                        int numeroCiudad = 0;
                        while (dr.Read())
                        {
                            numeroCiudad = dr.GetInt32(0);
                        }
                        con.Close();
                        // UPDATE

                        string vigencia = "";
                        if (rbSi.IsChecked == true)
                        {
                            vigencia = "SI";
                        }
                        else
                        {
                            vigencia = "NO";
                        }

                        con.Open();
                        string       updateString  = "UPDATE BUS SET modelo=?modelo,marca=?marca,year=?year,fecha_permiso=?fecha_permiso,vigencia_permiso=?vigencia_permiso,estado=?estado,ubicacion=?ubicacion WHERE patente='" + txtPatente.Text + "'";
                        MySqlCommand updateCommand = new MySqlCommand(updateString, con);
                        updateCommand.Parameters.Add("?modelo", txtModelo.Text);
                        updateCommand.Parameters.Add("?marca", txtMarca.Text);
                        updateCommand.Parameters.Add("?year", año.Text);
                        updateCommand.Parameters.Add("?fecha_permiso", fechaPermiso.Text);
                        updateCommand.Parameters.Add("?vigencia_permiso", vigencia);
                        updateCommand.Parameters.Add("?estado", comboEstado.Text);
                        updateCommand.Parameters.Add("?ubicacion", numeroCiudad);
                        updateCommand.ExecuteNonQuery();
                        con.Close();

                        nuevoBus busNuevo = new nuevoBus();
                        busNuevo.textBlock1.Text = "Se ha actualizado correctamente el bus en el sistema";
                        busNuevo.saludo.Text     = "Gracias por actualizar nuestros registros";
                        busNuevo.show("");
                    }
                    catch (Exception ex)
                    {
                        validar ventana = new validar();
                        ventana.show(ex.Message);
                    }
                }
            }
            else
            {
                validar error = new validar();
                error.show("Seleccione el boton para editar el regitro");
            }
        }
Пример #3
0
        private void button4_Click(object sender, RoutedEventArgs e)
        {
            if (txtModelo.IsReadOnly == false)
            {
                if (validarUpdate())
                {
                    try
                    {
                        MySqlConnection con = conexionDB.ObtenerConexion();

                        string sqlID_CIUDAD = "SELECT ID FROM CIUDAD WHERE NOMBRE = '" + ciudad.Text + "'";
                        MySqlCommand cmd = new MySqlCommand(sqlID_CIUDAD, con);

                        MySqlDataReader dr = cmd.ExecuteReader();

                        int numeroCiudad = 0;
                        while (dr.Read())
                        {
                            numeroCiudad = dr.GetInt32(0);
                        }
                        con.Close();
                        // UPDATE

                        string vigencia = "";
                        if (rbSi.IsChecked == true){
                        vigencia="SI";
                        }
                        else
                         {
                            vigencia="NO";
                         }

                        con.Open();
                        string updateString = "UPDATE BUS SET modelo=?modelo,marca=?marca,year=?year,fecha_permiso=?fecha_permiso,vigencia_permiso=?vigencia_permiso,estado=?estado,ubicacion=?ubicacion WHERE patente='" + txtPatente.Text + "'";
                        MySqlCommand updateCommand = new MySqlCommand(updateString, con);
                        updateCommand.Parameters.Add("?modelo", txtModelo.Text);
                        updateCommand.Parameters.Add("?marca", txtMarca.Text);
                        updateCommand.Parameters.Add("?year", año.Text);
                        updateCommand.Parameters.Add("?fecha_permiso", fechaPermiso.Text);
                        updateCommand.Parameters.Add("?vigencia_permiso", vigencia);
                        updateCommand.Parameters.Add("?estado", comboEstado.Text);
                        updateCommand.Parameters.Add("?ubicacion", numeroCiudad);
                        updateCommand.ExecuteNonQuery();
                        con.Close();

                        nuevoBus busNuevo = new nuevoBus();
                        busNuevo.textBlock1.Text = "Se ha actualizado correctamente el bus en el sistema";
                        busNuevo.saludo.Text = "Gracias por actualizar nuestros registros";
                        busNuevo.show("");

                    }
                    catch (Exception ex)
                    {
                        validar ventana = new validar();
                        ventana.show(ex.Message);
                    }

                }

            }
            else
            {
                validar error = new validar();
                error.show("Seleccione el boton para editar el regitro");
            }
        }