Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. SELECT fechakm, unidad, conductor, kmentrada, kmsalida, kmrecorrido FROM kilometraje WHERE ( unidad = ? AND between fechakm = ? AND fechakm = ? )
  2.  
  3. public void Reporte1(String unidad, String fecha1, String fecha2, Connection connection){
  4. Document documento = new Document();
  5. try {
  6. String ruta = System.getProperty("user.home");
  7. PdfWriter.getInstance(documento, new FileOutputStream(ruta + "/Desktop/ReporteKmRecorridoPorUnidad.pdf"));
  8. documento.open();
  9.  
  10. PdfPTable tabla = new PdfPTable(6);
  11. tabla.addCell("Fecha");
  12. tabla.addCell("Unidad");
  13. tabla.addCell("Conductor");
  14. tabla.addCell("KmEntrada");
  15. tabla.addCell("KmSalida");
  16. tabla.addCell("KmRecorrido");
  17.  
  18. try {
  19. Connection con = DriverManager.getConnection("jdbc:mysql://localhost/dbase", "USER","PASS");
  20. Conexion.GetDatabaseConnection();
  21. PreparedStatement pst = con.prepareStatement("SELECT fechakm, unidad, conductor, kmentrada, kmsalida, kmrecorrido FROM kilometraje WHERE ( unidad = ? AND between fechakm = ? AND fechakm = ? )");
  22. pst.setString(1, unidad);
  23. pst.setString(2, fecha1);
  24. pst.setString(3, fecha2);
  25.  
  26. ResultSet rs = pst.executeQuery();
  27. if (rs.next()) {
  28. do {
  29. tabla.addCell(rs.getString(1));
  30. tabla.addCell(rs.getString(2));
  31. tabla.addCell(rs.getString(3));
  32. tabla.addCell(rs.getString(4));
  33. tabla.addCell(rs.getString(5));
  34. tabla.addCell(rs.getString(6));
  35. } while (rs.next());
  36. documento.add(tabla);
  37. }
  38.  
  39. }catch(DocumentException | SQLException e) {
  40.  
  41. } documento.close();
  42. Alert mensaje = new Alert(Alert.AlertType.CONFIRMATION);
  43. mensaje.setTitle("Tramesa");
  44. mensaje.setContentText("Reporte Generado Correctamente");
  45. mensaje.setHeaderText("Reporte");
  46. mensaje.show();
  47. } catch(DocumentException | FileNotFoundException e) {
  48.  
  49. }
  50. }
  51.  
  52. @FXML
  53. public void AccionReporteRecoPorUnidad() {
  54. try{
  55. if(cb_unidad.getSelectionModel().getSelectedIndex() == -1){
  56. Alert alerta1 = new Alert(Alert.AlertType.ERROR);
  57. alerta1.setTitle("Tramesa");
  58. alerta1.setHeaderText("Campo vacio");
  59. alerta1.setContentText("Debe seleccionar una Unidad");
  60. alerta1.showAndWait();
  61. }else if(dp_fechaUni1.getValue()==null){
  62. Alert alerta1 = new Alert(Alert.AlertType.ERROR);
  63. alerta1.setTitle("Tramesa");
  64. alerta1.setHeaderText("Campo vacio");
  65. alerta1.setContentText("Debe seleccionar una Fecha Inicial");
  66. alerta1.showAndWait();
  67. }else if(dp_fechaUni2.getValue()== null){
  68. Alert alerta1 = new Alert(Alert.AlertType.ERROR);
  69. alerta1.setTitle("Tramesa");
  70. alerta1.setHeaderText("Campo vacio");
  71. alerta1.setContentText("Debe seleccionar una Fecha Final");
  72. alerta1.showAndWait();
  73. }else{
  74. SimpleDateFormat formato = new SimpleDateFormat("dd-MM-yyyy");
  75. java.lang.String fechaInicio = formato.format(java.sql.Date.valueOf(dp_fechaUni1.getValue()));
  76. java.lang.String fechaFin = formato.format(java.sql.Date.valueOf(dp_fechaUni2.getValue()));
  77. Conexion.GetDatabaseConnection();
  78. Reporte1(cb_unidad.getSelectionModel().getSelectedItem().toString(), fechaInicio, fechaFin, Conexion.GetDatabaseConnection() );
  79.  
  80. }
  81.  
  82.  
  83. }catch(Exception e){
  84. e.printStackTrace();
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement