Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package vistas;
- import Conexion.MySQLConection;
- import java.awt.HeadlessException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.text.SimpleDateFormat;
- import javax.swing.table.DefaultTableModel;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Properties;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import javax.swing.JDialog;
- import javax.swing.JOptionPane;
- import net.sf.jasperreports.engine.JasperFillManager;
- import net.sf.jasperreports.engine.JasperPrint;
- import net.sf.jasperreports.engine.JasperReport;
- import net.sf.jasperreports.engine.util.JRLoader;
- import net.sf.jasperreports.view.JasperViewer;
- /**
- *
- * @author dario
- */
- public class frmReportes extends javax.swing.JDialog {
- /**
- * Creates new form frmReportes
- */
- public frmReportes(java.awt.Frame parent, boolean modal) {
- super(parent, modal);
- initComponents();
- this.setLocationRelativeTo(null);
- llenarTabla();
- btnReporte.setEnabled(false);
- jTRerporte.setEnabled(false);
- }
- //---------------- llenando la tabla de empleados--------------//
- private void llenarTabla() {
- try {
- DefaultTableModel model = new DefaultTableModel();
- jTEmpleados.setModel(model);
- jTEmpleados.setAutoCreateRowSorter(true);
- PreparedStatement ps = null;
- ResultSet rs = null;
- Connection conn = MySQLConection.getConnection();
- String sql = "SELECT numEmpleado,user FROM empleados where puesto='diseñador'";
- ps = conn.prepareStatement(sql);
- rs = ps.executeQuery();
- ResultSetMetaData rsMeta = rs.getMetaData();
- int columnas = rsMeta.getColumnCount();
- model.addColumn("ID");
- model.addColumn("Usuario");
- int[] anchos = {3, 50};
- for (int x = 0; x < columnas; x++) {
- jTEmpleados.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
- }
- while (rs.next()) {
- Object[] filas = new Object[columnas];
- for (int i = 0; i < columnas; i++) {
- filas[i] = rs.getObject(i + 1);
- }
- model.addRow(filas);
- }
- } catch (Exception e) {
- JOptionPane.showMessageDialog(null, "Error al actualizar" + e);
- }
- }
- //---------------------- haciendo la consulta-------------------//
- private void Consulta() {
- try {
- //----variables del metodo----//
- SimpleDateFormat dFormato = new SimpleDateFormat("yyyy-MM-dd");
- String intervaloInicio = dFormato.format(jDCInicial.getDate());
- String intervaloFinal = dFormato.format(jDCFechaFinal.getDate());
- int fila = jTEmpleados.getSelectedRow();
- String numEmpleado = jTEmpleados.getValueAt(fila, 0).toString();
- //----terminan variables ----//
- DefaultTableModel model = new DefaultTableModel();
- jTRerporte.setModel(model);
- PreparedStatement ps = null;
- ResultSet rs = null;
- Connection conn = MySQLConection.getConnection();
- String SQL = "SELECT empleados.numEmpleado, empleados.user, empleados.puntoDeVenta, "
- + "count(pedidosempleado.idPedidoEmpleado) As conteo, "
- + "sum(pedidosempleado.tiempoTotal) AS tiempo, "
- + "sum(pedidosempleado.comision1)AS comision, "
- + "empleados.comision from empleados inner join pedidosempleado on empleados.numEmpleado=pedidosempleado.numeroEmpleado"
- + " where pedidosempleado.fechaFin between '" + intervaloInicio + "' AND '" + intervaloFinal + "' and empleados.numEmpleado='" + numEmpleado + "'";
- ps = conn.prepareStatement(SQL);
- rs = ps.executeQuery();
- ResultSetMetaData rsm = rs.getMetaData();
- int columnas = rsm.getColumnCount();
- model.addColumn("idEmpleado");
- model.addColumn("Usuario");
- model.addColumn("Sucursal");
- model.addColumn("Trabajos Realizados");
- model.addColumn("Tiempo Trabajado");
- model.addColumn("Comisiones");
- model.addColumn("Comision");
- int[] anchos = {2, 10, 20, 5, 10, 10, 10};
- for (int x = 0; x < columnas; x++) {
- jTRerporte.getColumnModel().getColumn(x).setPreferredWidth(anchos[x]);
- }
- while (rs.next()) {
- Object[] filas = new Object[columnas];
- for (int i = 0; i < columnas; i++) {
- filas[i] = rs.getObject(i + 1);
- }
- model.addRow(filas);
- }
- } catch (Exception e) {
- }
- }
- //---------------- Creando el stream para generar el reporte en la ventana-----------//
- private void streamReporte() {
- try {
- int fila2 = jTRerporte.getSelectedRow();
- String id = jTRerporte.getValueAt(fila2, 0).toString();
- String usuario = jTRerporte.getValueAt(fila2, 1).toString();
- String sucursal = jTRerporte.getValueAt(fila2, 2).toString();
- String trabajos = jTRerporte.getValueAt(fila2, 3).toString();
- String tiempos = jTRerporte.getValueAt(fila2, 4).toString();
- String comisiones = jTRerporte.getValueAt(fila2, 5).toString();
- String bono = jTRerporte.getValueAt(fila2, 6).toString();
- //Creando el objeto bw de la clase BufferedWriter Y se le pasa como parametro la ruta donde se guardara el archivo
- BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\dario\\Documents\\NetBeansProjects\\floreria2\\src\\reportes.txt"));
- //se le pasa lo contenido en la caja de texto para que lo imprima en el archivo txt
- bw.write("REPORTE INDIVDUAL" + "\n");
- bw.write("Num. Empleado:" + id + "\n");
- bw.write("Usuario:" + usuario + "\n");
- bw.write("Sucursal:" + sucursal + "\n");
- bw.write("Trabajos realizados en el periodo: " + trabajos + "\n");
- bw.write("Tiempo Total:" + tiempos + "\n");
- bw.write("Commisiones totales durante el periodo:" + comisiones + "\n");
- bw.write("Bono Extra:" + bono + "\n");
- bw.close(); //se cierra el stream
- //JOptionPane.showMessageDialog(null, "Archivo creado con exito");
- } catch (HeadlessException | IOException e) {
- }
- }
- //------------------- recuperando el reporte creado --------------------------------------//
- private void leerReporte() {
- try {
- //creando el objeto de la clase FileReader y pasandole por paramentro el objeto de la clase file archivo
- FileReader fr = new FileReader("C:\\Users\\dario\\Documents\\NetBeansProjects\\floreria2\\src\\reportes.txt");
- //creando el objeto br de la clase BufferedReader para almacenar en el buffer el archivo seleccionado, que es pasado por paramentro
- BufferedReader br = new BufferedReader(fr);
- //creacion de variables que contendran el texto del archivo leeido
- String texto = "";
- String linea = "";
- //bucle para leer el archivo
- while (((linea = br.readLine()) != null)) { //mientras que lo devuelto por el buffer no sea vacio
- texto += linea + "\n"; //se le suma a la variable texto lo contendido en la variable linea
- }
- //escribiendo en el area de texto designada el contenido de el archivo
- txtaArchivo.setText(texto);
- //se muestra en pantalla el aviso de que el archivo fue cargado de manera exitosa
- //cerrando el stream fr
- fr.close();
- } catch (Exception e) {
- //mostrando la exepcion en caso de error
- JOptionPane.showMessageDialog(null, "Error al cargar archivo", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jLabel3 = new javax.swing.JLabel();
- btnStart1 = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- jTEmpleados = new javax.swing.JTable();
- jLabel1 = new javax.swing.JLabel();
- jDCInicial = new com.toedter.calendar.JDateChooser();
- jLabel2 = new javax.swing.JLabel();
- jDCFechaFinal = new com.toedter.calendar.JDateChooser();
- jLabel4 = new javax.swing.JLabel();
- jPanel2 = new javax.swing.JPanel();
- jScrollPane2 = new javax.swing.JScrollPane();
- jTRerporte = new javax.swing.JTable();
- jLabel5 = new javax.swing.JLabel();
- jLabel12 = new javax.swing.JLabel();
- jPanel3 = new javax.swing.JPanel();
- btnPDF = new javax.swing.JButton();
- btnMail = new javax.swing.JButton();
- btnConsultar = new javax.swing.JButton();
- jPanel4 = new javax.swing.JPanel();
- jScrollPane3 = new javax.swing.JScrollPane();
- txtaArchivo = new javax.swing.JTextArea();
- btnReporte = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setAutoRequestFocus(false);
- setUndecorated(true);
- jPanel1.setBackground(new java.awt.Color(255, 255, 255));
- jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(122, 14, 2), 2, true));
- jPanel1.setInheritsPopupMenu(true);
- jLabel3.setFont(new java.awt.Font("Montserrat SemiBold", 0, 14)); // NOI18N
- jLabel3.setForeground(new java.awt.Color(122, 14, 2));
- btnStart1.setBackground(new java.awt.Color(255, 255, 255));
- btnStart1.setFont(new java.awt.Font("Montserrat SemiBold", 1, 14)); // NOI18N
- btnStart1.setForeground(new java.awt.Color(122, 14, 2));
- btnStart1.setText("Salir");
- btnStart1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(122, 14, 2)));
- btnStart1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnStart1ActionPerformed(evt);
- }
- });
- jTEmpleados.setFont(new java.awt.Font("Montserrat", 0, 14)); // NOI18N
- jTEmpleados.setForeground(new java.awt.Color(114, 22, 2));
- jTEmpleados.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- },
- new String [] {
- "Num. Empleado", "Nombre Empleado"
- }
- ) {
- boolean[] canEdit = new boolean [] {
- false, false
- };
- public boolean isCellEditable(int rowIndex, int columnIndex) {
- return canEdit [columnIndex];
- }
- });
- jTEmpleados.setGridColor(new java.awt.Color(114, 12, 2));
- jScrollPane1.setViewportView(jTEmpleados);
- jLabel1.setFont(new java.awt.Font("Montserrat", 1, 24)); // NOI18N
- jLabel1.setForeground(new java.awt.Color(114, 22, 2));
- jLabel1.setText("MODULO DE REPORTES");
- jLabel2.setFont(new java.awt.Font("Montserrat Black", 1, 14)); // NOI18N
- jLabel2.setForeground(new java.awt.Color(114, 22, 2));
- jLabel2.setText("Fecha Inicial");
- jLabel4.setFont(new java.awt.Font("Montserrat Black", 1, 14)); // NOI18N
- jLabel4.setForeground(new java.awt.Color(114, 22, 2));
- jLabel4.setText("Fecha Final");
- jPanel2.setBackground(new java.awt.Color(255, 255, 255));
- jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
- jTRerporte.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7"
- }
- ));
- jTRerporte.setFocusable(false);
- jTRerporte.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- jTRerporteMouseClicked(evt);
- }
- });
- jScrollPane2.setViewportView(jTRerporte);
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 631, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(21, Short.MAX_VALUE))
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(23, 23, 23)
- .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(41, Short.MAX_VALUE))
- );
- jLabel5.setFont(new java.awt.Font("Montserrat", 1, 14)); // NOI18N
- jLabel5.setForeground(new java.awt.Color(114, 22, 2));
- jLabel5.setText("Escoga el empleado y el periodo a inspeccionar");
- jLabel12.setFont(new java.awt.Font("Montserrat Black", 1, 14)); // NOI18N
- jLabel12.setForeground(new java.awt.Color(114, 22, 2));
- jLabel12.setText("Enviar correo");
- jPanel3.setBackground(new java.awt.Color(255, 255, 255));
- 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
- btnPDF.setBackground(new java.awt.Color(255, 255, 255));
- btnPDF.setForeground(new java.awt.Color(114, 22, 2));
- btnPDF.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8_pdf_50px.png"))); // NOI18N
- btnPDF.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnPDFActionPerformed(evt);
- }
- });
- btnMail.setBackground(new java.awt.Color(255, 255, 255));
- btnMail.setForeground(new java.awt.Color(114, 22, 2));
- btnMail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/icons8_mail_50px.png"))); // NOI18N
- btnMail.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnMailActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
- jPanel3.setLayout(jPanel3Layout);
- jPanel3Layout.setHorizontalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(btnPDF)
- .addGap(18, 18, 18)
- .addComponent(btnMail)
- .addContainerGap(12, Short.MAX_VALUE))
- );
- jPanel3Layout.setVerticalGroup(
- jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel3Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(btnMail)
- .addComponent(btnPDF))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- btnConsultar.setBackground(new java.awt.Color(255, 255, 255));
- btnConsultar.setFont(new java.awt.Font("Montserrat SemiBold", 0, 14)); // NOI18N
- btnConsultar.setForeground(new java.awt.Color(114, 22, 2));
- btnConsultar.setText("Inspecionar");
- btnConsultar.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(114, 22, 2), 1, true));
- btnConsultar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnConsultarActionPerformed(evt);
- }
- });
- jPanel4.setBackground(new java.awt.Color(255, 255, 255));
- 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
- txtaArchivo.setColumns(20);
- txtaArchivo.setRows(5);
- jScrollPane3.setViewportView(txtaArchivo);
- btnReporte.setBackground(new java.awt.Color(255, 255, 255));
- btnReporte.setFont(new java.awt.Font("Montserrat SemiBold", 0, 14)); // NOI18N
- btnReporte.setForeground(new java.awt.Color(114, 22, 2));
- btnReporte.setText("Generar Reporte Completo");
- btnReporte.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(114, 22, 2), 1, true));
- btnReporte.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnReporteActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
- jPanel4.setLayout(jPanel4Layout);
- jPanel4Layout.setHorizontalGroup(
- jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 646, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(btnReporte, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- jPanel4Layout.setVerticalGroup(
- jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(btnReporte, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(28, 28, 28)
- .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
- .addContainerGap())
- );
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel5)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(21, 21, 21)
- .addComponent(btnStart1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(214, 214, 214)
- .addComponent(jLabel12)
- .addGap(18, 18, 18)
- .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(6, 6, 6)
- .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jDCFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jDCInicial, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(btnConsultar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(286, 286, 286)
- .addComponent(jLabel3))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
- .addContainerGap(12, Short.MAX_VALUE))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel1)
- .addGap(70, 70, 70))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(19, 19, 19)
- .addComponent(jLabel1)
- .addGap(28, 28, 28)
- .addComponent(jLabel5)
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(21, 21, 21)
- .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel2)
- .addComponent(jDCInicial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(40, 40, 40)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel4)
- .addComponent(jDCFechaFinal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(btnStart1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jLabel12)
- .addGap(74, 74, 74))))
- .addGap(0, 0, Short.MAX_VALUE)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jLabel3)
- .addGap(126, 126, 126))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 627, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- private void btnStart1ActionPerformed(java.awt.event.ActionEvent evt) {
- this.dispose();
- }
- private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {
- Consulta();
- jTRerporte.setEnabled(true);
- jTRerporte.setFocusable(true);
- }
- private void btnPDFActionPerformed(java.awt.event.ActionEvent evt) {
- try {
- SimpleDateFormat dFormato = new SimpleDateFormat("yyyy-MM-dd");
- String intervaloInicio = dFormato.format(jDCInicial.getDate());
- String intervaloFinal = dFormato.format(jDCFechaFinal.getDate());
- int fila = jTEmpleados.getSelectedRow();
- String numEmpleado = jTEmpleados.getValueAt(fila, 0).toString();
- Connection conn = MySQLConection.getConnection();
- JasperReport reporte = null;
- String path = "src\\reportes\\ReporteEmpelado.jasper";
- Map parametro = new HashMap();
- parametro.put("inicio", intervaloInicio);
- parametro.put("final", intervaloFinal);
- parametro.put("usuario", numEmpleado);
- reporte = (JasperReport) JRLoader.loadObjectFromFile(path);
- JasperPrint jPrint = JasperFillManager.fillReport(reporte, parametro, conn);
- JasperViewer view = new JasperViewer(jPrint, false);
- JDialog dialog = new JDialog(this);
- dialog.setContentPane(view.getContentPane());
- dialog.setSize(view.getSize());
- dialog.setTitle("Reporte");
- dialog.setVisible(true);
- view.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
- } catch (Exception ex) {
- Logger.getLogger(frmReportes.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void btnReporteActionPerformed(java.awt.event.ActionEvent evt) {
- streamReporte();
- leerReporte();
- }
- private void jTRerporteMouseClicked(java.awt.event.MouseEvent evt) {
- btnReporte.setEnabled(true);
- }
- //--------- clase para envio de correo electronico ------//
- private void email(){
- try {
- Properties props = new Properties();
- props.setProperty("mail.smtp.host","smtp.gmail.com");
- props.setProperty("mail.smtp.starttls.enable","true");
- props.setProperty("mail.smtp.port","587");
- props.setProperty("mail.smtp.auth","true");
- Session session = Session.getDefaultInstance(props);
- String remitente = "rdzjesus2016@gmail.com";
- String password= "bljp201280";
- String receptor="jesus1280rodriguez@gmail.com";
- String asunto="prueba";
- String mensaje= "Buen dia envio el reporte";
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress(receptor));
- message.addRecipient(Message.RecipientType.TO, new InternetAddress(receptor));
- message.setSubject(asunto);
- message.setText(mensaje);
- Transport t = session.getTransport("smtp");
- t.connect(remitente,password);
- t.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
- t.close();
- JOptionPane.showInternalMessageDialog(null,"el correo ha sido enviado con exito");
- } catch (MessagingException ex) {
- Logger.getLogger(frmReportes.class.getName()).log(Level.SEVERE, null, ex);
- JOptionPane.showInternalMessageDialog(null,"el correo ha sido enviado con exito"+ex);
- }
- }
- private void btnMailActionPerformed(java.awt.event.ActionEvent evt) {
- email();
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(frmReportes.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the dialog */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- frmReportes dialog = new frmReportes(new javax.swing.JFrame(), true);
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnConsultar;
- private javax.swing.JButton btnMail;
- private javax.swing.JButton btnPDF;
- private javax.swing.JButton btnReporte;
- private javax.swing.JButton btnStart1;
- private com.toedter.calendar.JDateChooser jDCFechaFinal;
- private com.toedter.calendar.JDateChooser jDCInicial;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel12;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private javax.swing.JPanel jPanel3;
- private javax.swing.JPanel jPanel4;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JScrollPane jScrollPane2;
- private javax.swing.JScrollPane jScrollPane3;
- public javax.swing.JTable jTEmpleados;
- private javax.swing.JTable jTRerporte;
- private javax.swing.JTextArea txtaArchivo;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement