Advertisement
Metziop

Untitled

Jun 15th, 2021
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 36.08 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package vistas;
  7.  
  8. import Conexion.MySQLConection;
  9. import java.awt.HeadlessException;
  10. import java.sql.Connection;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13. import java.sql.ResultSetMetaData;
  14. import java.text.SimpleDateFormat;
  15. import javax.swing.table.DefaultTableModel;
  16. import java.io.BufferedReader;
  17. import java.io.BufferedWriter;
  18. import java.io.FileReader;
  19. import java.io.FileWriter;
  20. import java.io.IOException;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import java.util.Properties;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import javax.mail.Message;
  27. import javax.mail.MessagingException;
  28. import javax.mail.Session;
  29. import javax.mail.Transport;
  30. import javax.mail.internet.InternetAddress;
  31. import javax.mail.internet.MimeMessage;
  32. import javax.swing.JDialog;
  33. import javax.swing.JOptionPane;
  34. import net.sf.jasperreports.engine.JasperFillManager;
  35. import net.sf.jasperreports.engine.JasperPrint;
  36. import net.sf.jasperreports.engine.JasperReport;
  37. import net.sf.jasperreports.engine.util.JRLoader;
  38. import net.sf.jasperreports.view.JasperViewer;
  39.  
  40. /**
  41.  *
  42.  * @author dario
  43.  */
  44. public class frmReportes extends javax.swing.JDialog {
  45.  
  46.     /**
  47.      * Creates new form frmReportes
  48.      */
  49.     public frmReportes(java.awt.Frame parent, boolean modal) {
  50.         super(parent, modal);
  51.         initComponents();
  52.         this.setLocationRelativeTo(null);
  53.         llenarTabla();
  54.         btnReporte.setEnabled(false);
  55.  
  56.         jTRerporte.setEnabled(false);
  57.     }
  58.  
  59.     //---------------- llenando la tabla de empleados--------------//
  60.     private void llenarTabla() {
  61.  
  62.         try {
  63.             DefaultTableModel model = new DefaultTableModel();
  64.  
  65.             jTEmpleados.setModel(model);
  66.             jTEmpleados.setAutoCreateRowSorter(true);
  67.             PreparedStatement ps = null;
  68.             ResultSet rs = null;
  69.  
  70.             Connection conn = MySQLConection.getConnection();
  71.             String sql = "SELECT numEmpleado,user FROM empleados where puesto='diseñador'";
  72.             ps = conn.prepareStatement(sql);
  73.             rs = ps.executeQuery();
  74.             ResultSetMetaData rsMeta = rs.getMetaData();
  75.             int columnas = rsMeta.getColumnCount();
  76.             model.addColumn("ID");
  77.             model.addColumn("Usuario");
  78.  
  79.             int[] anchos = {3, 50};
  80.             for (int x = 0; x < columnas; x++) {
  81.                 jTEmpleados.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
  82.             }
  83.             while (rs.next()) {
  84.                 Object[] filas = new Object[columnas];
  85.                 for (int i = 0; i < columnas; i++) {
  86.                     filas[i] = rs.getObject(i + 1);
  87.                 }
  88.                 model.addRow(filas);
  89.             }
  90.         } catch (Exception e) {
  91.             JOptionPane.showMessageDialog(null, "Error al actualizar" + e);
  92.         }
  93.  
  94.     }
  95.  
  96.     //---------------------- haciendo la consulta-------------------//
  97.     private void Consulta() {
  98.  
  99.         try {
  100.             //----variables del metodo----//
  101.  
  102.             SimpleDateFormat dFormato = new SimpleDateFormat("yyyy-MM-dd");
  103.             String intervaloInicio = dFormato.format(jDCInicial.getDate());
  104.             String intervaloFinal = dFormato.format(jDCFechaFinal.getDate());
  105.             int fila = jTEmpleados.getSelectedRow();
  106.             String numEmpleado = jTEmpleados.getValueAt(fila, 0).toString();
  107.             //----terminan variables ----//
  108.             DefaultTableModel model = new DefaultTableModel();
  109.             jTRerporte.setModel(model);
  110.             PreparedStatement ps = null;
  111.             ResultSet rs = null;
  112.             Connection conn = MySQLConection.getConnection();
  113.             String SQL = "SELECT empleados.numEmpleado, empleados.user, empleados.puntoDeVenta, "
  114.                     + "count(pedidosempleado.idPedidoEmpleado) As conteo, "
  115.                     + "sum(pedidosempleado.tiempoTotal) AS tiempo, "
  116.                     + "sum(pedidosempleado.comision1)AS comision, "
  117.                     + "empleados.comision from empleados inner join pedidosempleado on empleados.numEmpleado=pedidosempleado.numeroEmpleado"
  118.                     + " where pedidosempleado.fechaFin between '" + intervaloInicio + "' AND '" + intervaloFinal + "' and empleados.numEmpleado='" + numEmpleado + "'";
  119.             ps = conn.prepareStatement(SQL);
  120.             rs = ps.executeQuery();
  121.             ResultSetMetaData rsm = rs.getMetaData();
  122.             int columnas = rsm.getColumnCount();
  123.             model.addColumn("idEmpleado");
  124.             model.addColumn("Usuario");
  125.             model.addColumn("Sucursal");
  126.             model.addColumn("Trabajos Realizados");
  127.             model.addColumn("Tiempo Trabajado");
  128.             model.addColumn("Comisiones");
  129.             model.addColumn("Comision");
  130.             int[] anchos = {2, 10, 20, 5, 10, 10, 10};
  131.             for (int x = 0; x < columnas; x++) {
  132.                 jTRerporte.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
  133.             }
  134.             while (rs.next()) {
  135.                 Object[] filas = new Object[columnas];
  136.                 for (int i = 0; i < columnas; i++) {
  137.                     filas[i] = rs.getObject(i + 1);
  138.                 }
  139.                 model.addRow(filas);
  140.             }
  141.  
  142.         } catch (Exception e) {
  143.         }
  144.  
  145.     }
  146.  
  147.     //---------------- Creando el stream para generar el reporte en la ventana-----------//
  148.     private void streamReporte() {
  149.         try {
  150.             int fila2 = jTRerporte.getSelectedRow();
  151.             String id = jTRerporte.getValueAt(fila2, 0).toString();
  152.             String usuario = jTRerporte.getValueAt(fila2, 1).toString();
  153.             String sucursal = jTRerporte.getValueAt(fila2, 2).toString();
  154.             String trabajos = jTRerporte.getValueAt(fila2, 3).toString();
  155.             String tiempos = jTRerporte.getValueAt(fila2, 4).toString();
  156.             String comisiones = jTRerporte.getValueAt(fila2, 5).toString();
  157.             String bono = jTRerporte.getValueAt(fila2, 6).toString();
  158.             //Creando el objeto bw de la clase  BufferedWriter Y se le pasa como parametro la ruta donde se guardara el archivo
  159.             BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\dario\\Documents\\NetBeansProjects\\floreria2\\src\\reportes.txt"));
  160.             //se le pasa lo contenido en la caja de texto para que lo imprima en el archivo txt
  161.             bw.write("REPORTE INDIVDUAL" + "\n");
  162.             bw.write("Num. Empleado:" + id + "\n");
  163.             bw.write("Usuario:" + usuario + "\n");
  164.             bw.write("Sucursal:" + sucursal + "\n");
  165.             bw.write("Trabajos realizados en el periodo: " + trabajos + "\n");
  166.             bw.write("Tiempo Total:" + tiempos + "\n");
  167.             bw.write("Commisiones totales durante el periodo:" + comisiones + "\n");
  168.             bw.write("Bono Extra:" + bono + "\n");
  169.             bw.close(); //se cierra el stream
  170.  
  171.             //JOptionPane.showMessageDialog(null, "Archivo creado con exito");
  172.         } catch (HeadlessException | IOException e) {
  173.  
  174.         }
  175.  
  176.     }
  177.  
  178.     //------------------- recuperando el reporte creado --------------------------------------//
  179.     private void leerReporte() {
  180.  
  181.         try {
  182.  
  183.             //creando el objeto de la clase FileReader y pasandole por paramentro el objeto de la clase file archivo
  184.             FileReader fr = new FileReader("C:\\Users\\dario\\Documents\\NetBeansProjects\\floreria2\\src\\reportes.txt");
  185.             //creando el objeto br de la clase BufferedReader para almacenar en el buffer el archivo seleccionado, que es pasado por paramentro
  186.             BufferedReader br = new BufferedReader(fr);
  187.             //creacion de variables que contendran el texto del archivo leeido
  188.             String texto = "";
  189.             String linea = "";
  190.             //bucle para leer el archivo
  191.             while (((linea = br.readLine()) != null)) { //mientras que lo devuelto por el buffer no sea vacio
  192.                 texto += linea + "\n"; //se le suma a la variable texto lo contendido en la variable linea
  193.             }
  194.             //escribiendo en el area de texto designada el contenido de el archivo
  195.             txtaArchivo.setText(texto);
  196.             //se muestra en pantalla el aviso de que el archivo fue cargado de manera exitosa
  197.  
  198.             //cerrando el stream fr
  199.             fr.close();
  200.  
  201.         } catch (Exception e) {
  202.             //mostrando la exepcion en caso de error
  203.             JOptionPane.showMessageDialog(null, "Error al cargar archivo", "Error", JOptionPane.ERROR_MESSAGE);
  204.         }
  205.  
  206.     }
  207.  
  208.     /**
  209.      * This method is called from within the constructor to initialize the form.
  210.      * WARNING: Do NOT modify this code. The content of this method is always
  211.      * regenerated by the Form Editor.
  212.      */
  213.     @SuppressWarnings("unchecked")
  214.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  215.     private void initComponents() {
  216.  
  217.         jPanel1 = new javax.swing.JPanel();
  218.         jLabel3 = new javax.swing.JLabel();
  219.         btnStart1 = new javax.swing.JButton();
  220.         jScrollPane1 = new javax.swing.JScrollPane();
  221.         jTEmpleados = new javax.swing.JTable();
  222.         jLabel1 = new javax.swing.JLabel();
  223.         jDCInicial = new com.toedter.calendar.JDateChooser();
  224.         jLabel2 = new javax.swing.JLabel();
  225.         jDCFechaFinal = new com.toedter.calendar.JDateChooser();
  226.         jLabel4 = new javax.swing.JLabel();
  227.         jPanel2 = new javax.swing.JPanel();
  228.         jScrollPane2 = new javax.swing.JScrollPane();
  229.         jTRerporte = new javax.swing.JTable();
  230.         jLabel5 = new javax.swing.JLabel();
  231.         jLabel12 = new javax.swing.JLabel();
  232.         jPanel3 = new javax.swing.JPanel();
  233.         btnPDF = new javax.swing.JButton();
  234.         btnMail = new javax.swing.JButton();
  235.         btnConsultar = new javax.swing.JButton();
  236.         jPanel4 = new javax.swing.JPanel();
  237.         jScrollPane3 = new javax.swing.JScrollPane();
  238.         txtaArchivo = new javax.swing.JTextArea();
  239.         btnReporte = new javax.swing.JButton();
  240.  
  241.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  242.         setAutoRequestFocus(false);
  243.         setUndecorated(true);
  244.  
  245.         jPanel1.setBackground(new java.awt.Color(255, 255, 255));
  246.         jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(122, 14, 2), 2, true));
  247.         jPanel1.setInheritsPopupMenu(true);
  248.  
  249.         jLabel3.setFont(new java.awt.Font("Montserrat SemiBold", 0, 14)); // NOI18N
  250.         jLabel3.setForeground(new java.awt.Color(122, 14, 2));
  251.  
  252.         btnStart1.setBackground(new java.awt.Color(255, 255, 255));
  253.         btnStart1.setFont(new java.awt.Font("Montserrat SemiBold", 1, 14)); // NOI18N
  254.         btnStart1.setForeground(new java.awt.Color(122, 14, 2));
  255.         btnStart1.setText("Salir");
  256.         btnStart1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(122, 14, 2)));
  257.         btnStart1.addActionListener(new java.awt.event.ActionListener() {
  258.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  259.                 btnStart1ActionPerformed(evt);
  260.             }
  261.         });
  262.  
  263.         jTEmpleados.setFont(new java.awt.Font("Montserrat", 0, 14)); // NOI18N
  264.         jTEmpleados.setForeground(new java.awt.Color(114, 22, 2));
  265.         jTEmpleados.setModel(new javax.swing.table.DefaultTableModel(
  266.             new Object [][] {
  267.  
  268.             },
  269.             new String [] {
  270.                 "Num. Empleado", "Nombre Empleado"
  271.             }
  272.         ) {
  273.             boolean[] canEdit = new boolean [] {
  274.                 false, false
  275.             };
  276.  
  277.             public boolean isCellEditable(int rowIndex, int columnIndex) {
  278.                 return canEdit [columnIndex];
  279.             }
  280.         });
  281.         jTEmpleados.setGridColor(new java.awt.Color(114, 12, 2));
  282.         jScrollPane1.setViewportView(jTEmpleados);
  283.  
  284.         jLabel1.setFont(new java.awt.Font("Montserrat", 1, 24)); // NOI18N
  285.         jLabel1.setForeground(new java.awt.Color(114, 22, 2));
  286.         jLabel1.setText("MODULO DE REPORTES");
  287.  
  288.         jLabel2.setFont(new java.awt.Font("Montserrat Black", 1, 14)); // NOI18N
  289.         jLabel2.setForeground(new java.awt.Color(114, 22, 2));
  290.         jLabel2.setText("Fecha Inicial");
  291.  
  292.         jLabel4.setFont(new java.awt.Font("Montserrat Black", 1, 14)); // NOI18N
  293.         jLabel4.setForeground(new java.awt.Color(114, 22, 2));
  294.         jLabel4.setText("Fecha Final");
  295.  
  296.         jPanel2.setBackground(new java.awt.Color(255, 255, 255));
  297.         jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
  298.  
  299.         jTRerporte.setModel(new javax.swing.table.DefaultTableModel(
  300.             new Object [][] {
  301.                 {null, null, null, null, null, null, null}
  302.             },
  303.             new String [] {
  304.                 "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7"
  305.             }
  306.         ));
  307.         jTRerporte.setFocusable(false);
  308.         jTRerporte.addMouseListener(new java.awt.event.MouseAdapter() {
  309.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  310.                 jTRerporteMouseClicked(evt);
  311.             }
  312.         });
  313.         jScrollPane2.setViewportView(jTRerporte);
  314.  
  315.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  316.         jPanel2.setLayout(jPanel2Layout);
  317.         jPanel2Layout.setHorizontalGroup(
  318.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  319.             .addGroup(jPanel2Layout.createSequentialGroup()
  320.                 .addContainerGap()
  321.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 631, javax.swing.GroupLayout.PREFERRED_SIZE)
  322.                 .addContainerGap(21, Short.MAX_VALUE))
  323.         );
  324.         jPanel2Layout.setVerticalGroup(
  325.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  326.             .addGroup(jPanel2Layout.createSequentialGroup()
  327.                 .addGap(23, 23, 23)
  328.                 .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
  329.                 .addContainerGap(41, Short.MAX_VALUE))
  330.         );
  331.  
  332.         jLabel5.setFont(new java.awt.Font("Montserrat", 1, 14)); // NOI18N
  333.         jLabel5.setForeground(new java.awt.Color(114, 22, 2));
  334.         jLabel5.setText("Escoga el empleado y el periodo a inspeccionar");
  335.  
  336.         jLabel12.setFont(new java.awt.Font("Montserrat Black", 1, 14)); // NOI18N
  337.         jLabel12.setForeground(new java.awt.Color(114, 22, 2));
  338.         jLabel12.setText("Enviar correo");
  339.  
  340.         jPanel3.setBackground(new java.awt.Color(255, 255, 255));
  341.         jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Exportar Reporte", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Montserrat Light", 1, 12), new java.awt.Color(114, 22, 2))); // NOI18N
  342.  
  343.         btnPDF.setBackground(new java.awt.Color(255, 255, 255));
  344.         btnPDF.setForeground(new java.awt.Color(114, 22, 2));
  345.         btnPDF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8_pdf_50px.png"))); // NOI18N
  346.         btnPDF.addActionListener(new java.awt.event.ActionListener() {
  347.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  348.                 btnPDFActionPerformed(evt);
  349.             }
  350.         });
  351.  
  352.         btnMail.setBackground(new java.awt.Color(255, 255, 255));
  353.         btnMail.setForeground(new java.awt.Color(114, 22, 2));
  354.         btnMail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8_mail_50px.png"))); // NOI18N
  355.         btnMail.addActionListener(new java.awt.event.ActionListener() {
  356.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  357.                 btnMailActionPerformed(evt);
  358.             }
  359.         });
  360.  
  361.         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
  362.         jPanel3.setLayout(jPanel3Layout);
  363.         jPanel3Layout.setHorizontalGroup(
  364.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  365.             .addGroup(jPanel3Layout.createSequentialGroup()
  366.                 .addContainerGap()
  367.                 .addComponent(btnPDF)
  368.                 .addGap(18, 18, 18)
  369.                 .addComponent(btnMail)
  370.                 .addContainerGap(12, Short.MAX_VALUE))
  371.         );
  372.         jPanel3Layout.setVerticalGroup(
  373.             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  374.             .addGroup(jPanel3Layout.createSequentialGroup()
  375.                 .addContainerGap()
  376.                 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  377.                     .addComponent(btnMail)
  378.                     .addComponent(btnPDF))
  379.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  380.         );
  381.  
  382.         btnConsultar.setBackground(new java.awt.Color(255, 255, 255));
  383.         btnConsultar.setFont(new java.awt.Font("Montserrat SemiBold", 0, 14)); // NOI18N
  384.         btnConsultar.setForeground(new java.awt.Color(114, 22, 2));
  385.         btnConsultar.setText("Inspecionar");
  386.         btnConsultar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(114, 22, 2), 1, true));
  387.         btnConsultar.addActionListener(new java.awt.event.ActionListener() {
  388.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  389.                 btnConsultarActionPerformed(evt);
  390.             }
  391.         });
  392.  
  393.         jPanel4.setBackground(new java.awt.Color(255, 255, 255));
  394.         jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Reporte en modo texto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Montserrat Black", 1, 14), new java.awt.Color(114, 22, 2))); // NOI18N
  395.  
  396.         txtaArchivo.setColumns(20);
  397.         txtaArchivo.setRows(5);
  398.         jScrollPane3.setViewportView(txtaArchivo);
  399.  
  400.         btnReporte.setBackground(new java.awt.Color(255, 255, 255));
  401.         btnReporte.setFont(new java.awt.Font("Montserrat SemiBold", 0, 14)); // NOI18N
  402.         btnReporte.setForeground(new java.awt.Color(114, 22, 2));
  403.         btnReporte.setText("Generar Reporte Completo");
  404.         btnReporte.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(114, 22, 2), 1, true));
  405.         btnReporte.addActionListener(new java.awt.event.ActionListener() {
  406.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  407.                 btnReporteActionPerformed(evt);
  408.             }
  409.         });
  410.  
  411.         javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
  412.         jPanel4.setLayout(jPanel4Layout);
  413.         jPanel4Layout.setHorizontalGroup(
  414.             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  415.             .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
  416.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
  417.                 .addGap(0, 0, Short.MAX_VALUE)
  418.                 .addComponent(btnReporte, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
  419.         );
  420.         jPanel4Layout.setVerticalGroup(
  421.             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  422.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
  423.                 .addContainerGap()
  424.                 .addComponent(btnReporte, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
  425.                 .addGap(28, 28, 28)
  426.                 .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
  427.                 .addContainerGap())
  428.         );
  429.  
  430.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  431.         jPanel1.setLayout(jPanel1Layout);
  432.         jPanel1Layout.setHorizontalGroup(
  433.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  434.             .addGroup(jPanel1Layout.createSequentialGroup()
  435.                 .addContainerGap()
  436.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  437.                     .addComponent(jLabel5)
  438.                     .addGroup(jPanel1Layout.createSequentialGroup()
  439.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  440.                             .addGroup(jPanel1Layout.createSequentialGroup()
  441.                                 .addGap(21, 21, 21)
  442.                                 .addComponent(btnStart1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
  443.                                 .addGap(214, 214, 214)
  444.                                 .addComponent(jLabel12)
  445.                                 .addGap(18, 18, 18)
  446.                                 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  447.                             .addGroup(jPanel1Layout.createSequentialGroup()
  448.                                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
  449.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  450.                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  451.                                     .addGroup(jPanel1Layout.createSequentialGroup()
  452.                                         .addGap(6, 6, 6)
  453.                                         .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
  454.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  455.                                         .addComponent(jDCFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
  456.                                     .addGroup(jPanel1Layout.createSequentialGroup()
  457.                                         .addComponent(jLabel2)
  458.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  459.                                         .addComponent(jDCInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
  460.                                     .addComponent(btnConsultar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
  461.                             .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  462.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  463.                             .addGroup(jPanel1Layout.createSequentialGroup()
  464.                                 .addGap(286, 286, 286)
  465.                                 .addComponent(jLabel3))
  466.                             .addGroup(jPanel1Layout.createSequentialGroup()
  467.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  468.                                 .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
  469.                 .addContainerGap(12, Short.MAX_VALUE))
  470.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  471.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  472.                 .addComponent(jLabel1)
  473.                 .addGap(70, 70, 70))
  474.         );
  475.         jPanel1Layout.setVerticalGroup(
  476.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  477.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  478.                 .addGap(19, 19, 19)
  479.                 .addComponent(jLabel1)
  480.                 .addGap(28, 28, 28)
  481.                 .addComponent(jLabel5)
  482.                 .addGap(18, 18, 18)
  483.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  484.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  485.                         .addGap(0, 0, Short.MAX_VALUE)
  486.                         .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  487.                     .addGroup(jPanel1Layout.createSequentialGroup()
  488.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  489.                             .addGroup(jPanel1Layout.createSequentialGroup()
  490.                                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
  491.                                 .addGap(21, 21, 21)
  492.                                 .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
  493.                             .addGroup(jPanel1Layout.createSequentialGroup()
  494.                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  495.                                     .addComponent(jLabel2)
  496.                                     .addComponent(jDCInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  497.                                 .addGap(40, 40, 40)
  498.                                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  499.                                     .addComponent(jLabel4)
  500.                                     .addComponent(jDCFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
  501.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  502.                         .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  503.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  504.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  505.                             .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  506.                             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  507.                                 .addComponent(btnStart1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
  508.                                 .addGroup(jPanel1Layout.createSequentialGroup()
  509.                                     .addComponent(jLabel12)
  510.                                     .addGap(74, 74, 74))))
  511.                         .addGap(0, 0, Short.MAX_VALUE)))
  512.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  513.                 .addComponent(jLabel3)
  514.                 .addGap(126, 126, 126))
  515.         );
  516.  
  517.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  518.         getContentPane().setLayout(layout);
  519.         layout.setHorizontalGroup(
  520.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  521.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  522.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  523.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  524.                 .addContainerGap())
  525.         );
  526.         layout.setVerticalGroup(
  527.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  528.             .addGroup(layout.createSequentialGroup()
  529.                 .addContainerGap()
  530.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 627, javax.swing.GroupLayout.PREFERRED_SIZE)
  531.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  532.         );
  533.  
  534.         pack();
  535.     }// </editor-fold>                        
  536.  
  537.     private void btnStart1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  538.         this.dispose();
  539.     }                                        
  540.  
  541.     private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                            
  542.         Consulta();
  543.         jTRerporte.setEnabled(true);
  544.         jTRerporte.setFocusable(true);
  545.  
  546.     }                                            
  547.  
  548.     private void btnPDFActionPerformed(java.awt.event.ActionEvent evt) {                                      
  549.         try {
  550.             SimpleDateFormat dFormato = new SimpleDateFormat("yyyy-MM-dd");
  551.             String intervaloInicio = dFormato.format(jDCInicial.getDate());
  552.             String intervaloFinal = dFormato.format(jDCFechaFinal.getDate());
  553.             int fila = jTEmpleados.getSelectedRow();
  554.             String numEmpleado = jTEmpleados.getValueAt(fila, 0).toString();
  555.             Connection conn = MySQLConection.getConnection();
  556.             JasperReport reporte = null;
  557.             String path = "src\\reportes\\ReporteEmpelado.jasper";
  558.             Map parametro = new HashMap();
  559.             parametro.put("inicio", intervaloInicio);
  560.             parametro.put("final", intervaloFinal);
  561.             parametro.put("usuario", numEmpleado);
  562.             reporte = (JasperReport) JRLoader.loadObjectFromFile(path);
  563.             JasperPrint jPrint = JasperFillManager.fillReport(reporte, parametro, conn);
  564.             JasperViewer view = new JasperViewer(jPrint, false);
  565.             JDialog dialog = new JDialog(this);
  566.             dialog.setContentPane(view.getContentPane());
  567.             dialog.setSize(view.getSize());
  568.             dialog.setTitle("Reporte");
  569.             dialog.setVisible(true);
  570.             view.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  571.  
  572.         } catch (Exception ex) {
  573.             Logger.getLogger(frmReportes.class.getName()).log(Level.SEVERE, null, ex);
  574.         }
  575.     }                                      
  576.  
  577.  
  578.     private void btnReporteActionPerformed(java.awt.event.ActionEvent evt) {                                          
  579.         streamReporte();
  580.         leerReporte();
  581.  
  582.     }                                          
  583.  
  584.     private void jTRerporteMouseClicked(java.awt.event.MouseEvent evt) {                                        
  585.         btnReporte.setEnabled(true);
  586.  
  587.     }                                      
  588.     //--------- clase para envio de correo electronico  ------//
  589.     private void email(){
  590.         try {
  591.             Properties props = new Properties();
  592.             props.setProperty("mail.smtp.host","smtp.gmail.com");
  593.             props.setProperty("mail.smtp.starttls.enable","true");
  594.             props.setProperty("mail.smtp.port","587");
  595.             props.setProperty("mail.smtp.auth","true");
  596.            
  597.             Session session = Session.getDefaultInstance(props);
  598.             String remitente = "rdzjesus2016@gmail.com";
  599.             String password= "bljp201280";
  600.             String receptor="jesus1280rodriguez@gmail.com";
  601.             String asunto="prueba";
  602.             String mensaje= "Buen dia envio el reporte";
  603.            
  604.             MimeMessage message = new MimeMessage(session);
  605.             message.setFrom(new InternetAddress(receptor));
  606.             message.addRecipient(Message.RecipientType.TO, new InternetAddress(receptor));
  607.             message.setSubject(asunto);
  608.             message.setText(mensaje);
  609.             Transport t = session.getTransport("smtp");
  610.             t.connect(remitente,password);
  611.             t.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
  612.             t.close();
  613.             JOptionPane.showInternalMessageDialog(null,"el correo ha sido enviado con exito");
  614.            
  615.         } catch (MessagingException ex) {
  616.             Logger.getLogger(frmReportes.class.getName()).log(Level.SEVERE, null, ex);
  617.             JOptionPane.showInternalMessageDialog(null,"el correo ha sido enviado con exito"+ex);
  618.            
  619.         }
  620.        
  621.     }
  622.    
  623.     private void btnMailActionPerformed(java.awt.event.ActionEvent evt) {                                        
  624.        email();
  625.     }                                      
  626.  
  627.     /**
  628.      * @param args the command line arguments
  629.      */
  630.     public static void main(String args[]) {
  631.         /* Set the Nimbus look and feel */
  632.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  633.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  634.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  635.          */
  636.         try {
  637.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  638.                 if ("Nimbus".equals(info.getName())) {
  639.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  640.                     break;
  641.                 }
  642.             }
  643.         } catch (ClassNotFoundException ex) {
  644.             java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  645.         } catch (InstantiationException ex) {
  646.             java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  647.         } catch (IllegalAccessException ex) {
  648.             java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  649.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  650.             java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  651.         }
  652.         //</editor-fold>
  653.  
  654.         /* Create and display the dialog */
  655.         java.awt.EventQueue.invokeLater(new Runnable() {
  656.             public void run() {
  657.                 frmReportes dialog = new frmReportes(new javax.swing.JFrame(), true);
  658.                 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
  659.                     @Override
  660.                     public void windowClosing(java.awt.event.WindowEvent e) {
  661.                         System.exit(0);
  662.                     }
  663.                 });
  664.                 dialog.setVisible(true);
  665.             }
  666.         });
  667.     }
  668.  
  669.     // Variables declaration - do not modify                    
  670.     private javax.swing.JButton btnConsultar;
  671.     private javax.swing.JButton btnMail;
  672.     private javax.swing.JButton btnPDF;
  673.     private javax.swing.JButton btnReporte;
  674.     private javax.swing.JButton btnStart1;
  675.     private com.toedter.calendar.JDateChooser jDCFechaFinal;
  676.     private com.toedter.calendar.JDateChooser jDCInicial;
  677.     private javax.swing.JLabel jLabel1;
  678.     private javax.swing.JLabel jLabel12;
  679.     private javax.swing.JLabel jLabel2;
  680.     private javax.swing.JLabel jLabel3;
  681.     private javax.swing.JLabel jLabel4;
  682.     private javax.swing.JLabel jLabel5;
  683.     private javax.swing.JPanel jPanel1;
  684.     private javax.swing.JPanel jPanel2;
  685.     private javax.swing.JPanel jPanel3;
  686.     private javax.swing.JPanel jPanel4;
  687.     private javax.swing.JScrollPane jScrollPane1;
  688.     private javax.swing.JScrollPane jScrollPane2;
  689.     private javax.swing.JScrollPane jScrollPane3;
  690.     public javax.swing.JTable jTEmpleados;
  691.     private javax.swing.JTable jTRerporte;
  692.     private javax.swing.JTextArea txtaArchivo;
  693.     // End of variables declaration                  
  694. }
  695.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement