Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT fechakm, unidad, conductor, kmentrada, kmsalida, kmrecorrido FROM kilometraje WHERE ( unidad = ? AND between fechakm = ? AND fechakm = ? )
- public void Reporte1(String unidad, String fecha1, String fecha2, Connection connection){
- Document documento = new Document();
- try {
- String ruta = System.getProperty("user.home");
- PdfWriter.getInstance(documento, new FileOutputStream(ruta + "/Desktop/ReporteKmRecorridoPorUnidad.pdf"));
- documento.open();
- PdfPTable tabla = new PdfPTable(6);
- tabla.addCell("Fecha");
- tabla.addCell("Unidad");
- tabla.addCell("Conductor");
- tabla.addCell("KmEntrada");
- tabla.addCell("KmSalida");
- tabla.addCell("KmRecorrido");
- try {
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbase", "USER","PASS");
- Conexion.GetDatabaseConnection();
- PreparedStatement pst = con.prepareStatement("SELECT fechakm, unidad, conductor, kmentrada, kmsalida, kmrecorrido FROM kilometraje WHERE ( unidad = ? AND between fechakm = ? AND fechakm = ? )");
- pst.setString(1, unidad);
- pst.setString(2, fecha1);
- pst.setString(3, fecha2);
- ResultSet rs = pst.executeQuery();
- if (rs.next()) {
- do {
- tabla.addCell(rs.getString(1));
- tabla.addCell(rs.getString(2));
- tabla.addCell(rs.getString(3));
- tabla.addCell(rs.getString(4));
- tabla.addCell(rs.getString(5));
- tabla.addCell(rs.getString(6));
- } while (rs.next());
- documento.add(tabla);
- }
- }catch(DocumentException | SQLException e) {
- } documento.close();
- Alert mensaje = new Alert(Alert.AlertType.CONFIRMATION);
- mensaje.setTitle("Tramesa");
- mensaje.setContentText("Reporte Generado Correctamente");
- mensaje.setHeaderText("Reporte");
- mensaje.show();
- } catch(DocumentException | FileNotFoundException e) {
- }
- }
- @FXML
- public void AccionReporteRecoPorUnidad() {
- try{
- if(cb_unidad.getSelectionModel().getSelectedIndex() == -1){
- Alert alerta1 = new Alert(Alert.AlertType.ERROR);
- alerta1.setTitle("Tramesa");
- alerta1.setHeaderText("Campo vacio");
- alerta1.setContentText("Debe seleccionar una Unidad");
- alerta1.showAndWait();
- }else if(dp_fechaUni1.getValue()==null){
- Alert alerta1 = new Alert(Alert.AlertType.ERROR);
- alerta1.setTitle("Tramesa");
- alerta1.setHeaderText("Campo vacio");
- alerta1.setContentText("Debe seleccionar una Fecha Inicial");
- alerta1.showAndWait();
- }else if(dp_fechaUni2.getValue()== null){
- Alert alerta1 = new Alert(Alert.AlertType.ERROR);
- alerta1.setTitle("Tramesa");
- alerta1.setHeaderText("Campo vacio");
- alerta1.setContentText("Debe seleccionar una Fecha Final");
- alerta1.showAndWait();
- }else{
- SimpleDateFormat formato = new SimpleDateFormat("dd-MM-yyyy");
- java.lang.String fechaInicio = formato.format(java.sql.Date.valueOf(dp_fechaUni1.getValue()));
- java.lang.String fechaFin = formato.format(java.sql.Date.valueOf(dp_fechaUni2.getValue()));
- Conexion.GetDatabaseConnection();
- Reporte1(cb_unidad.getSelectionModel().getSelectedItem().toString(), fechaInicio, fechaFin, Conexion.GetDatabaseConnection() );
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement