Java tutorial
/* * 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 appArriendos; import static appArriendos.frmReservaEquipo.txtCelular; import static appArriendos.frmReservaEquipo.txtEmail; import static appArriendos.frmReservaEquipo.txtNombre; import static appArriendos.frmReservaEquipo.txtRut; import static appArriendos.frmReservaEquipo.txtTelefono; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.Image; import com.itextpdf.text.pdf.Barcode; import com.itextpdf.text.pdf.Barcode39; import com.itextpdf.text.pdf.PdfContentByte; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.FileOutputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel; import net.sourceforge.barbecue.BarcodeException; /** * * @author Phobos */ public class frmVistaReserva extends javax.swing.JInternalFrame { /** * Creates new form frmVistaReserva */ public frmVistaReserva() { initComponents(); DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel(); modelo.addColumn("NUM"); modelo.addColumn("CODIGO"); modelo.addColumn("DESCRIPCION"); } /** * 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">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); txtFolio = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); txtFecha = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtFechaEntrega = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); txtHora = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); txtHoraEntrega = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); txtNombre = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); txtRut = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jButton10 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); txtEmail = new javax.swing.JTextField(); jLabel9 = new javax.swing.JLabel(); txtCelular = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); txtTelefono = new javax.swing.JTextField(); jScrollPane2 = new javax.swing.JScrollPane(); txtObservacion = new javax.swing.JTextArea(); jLabel11 = new javax.swing.JLabel(); lblEstado = new javax.swing.JLabel(); jButton9 = new javax.swing.JButton(); setClosable(true); setIconifiable(true); setMaximizable(true); setResizable(true); setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/imagen/png32/clock.png"))); // NOI18N addInternalFrameListener(new javax.swing.event.InternalFrameListener() { public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) { } public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) { } public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) { } public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) { } public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) { } public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) { } public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) { formInternalFrameOpened(evt); } }); jLabel1.setText("FOLIO"); txtFolio.setEnabled(false); jLabel2.setText("FECHA"); txtFecha.setEnabled(false); jLabel3.setText("FECHA ENTREGA"); txtFechaEntrega.setEditable(false); jLabel4.setText("HORA"); txtHora.setEnabled(false); jLabel5.setText("HORA ENTREGA"); txtHoraEntrega.setEnabled(false); jLabel6.setText("NOMBRE"); txtNombre.setEnabled(false); jLabel7.setText("RUT"); txtRut.setEnabled(false); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] { }, new String[] { })); jScrollPane1.setViewportView(jTable1); jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagen/png32/symbol.png"))); // NOI18N jButton10.setText("EXPORTAR A PDF"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagen/png32/icon-45874.png"))); // NOI18N jButton1.setText("CERRAR TAREA"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel8.setText("E-MAIL"); txtEmail.setEnabled(false); jLabel9.setText("CELULAR"); txtCelular.setEnabled(false); jLabel10.setText("TELEFONO"); txtTelefono.setEnabled(false); txtObservacion.setColumns(20); txtObservacion.setRows(5); txtObservacion.setEnabled(false); jScrollPane2.setViewportView(txtObservacion); jLabel11.setText("OBSERVACION"); lblEstado.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N lblEstado.setText("NUEVO"); jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagen/png32/icon-108504.png"))); // NOI18N jButton9.setText("ANULAR"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(29, 29, 29).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel11).addComponent(jLabel8).addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jButton1) .addGap(2, 2, 2).addComponent(jButton9) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(lblEstado) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton10)) .addComponent(jScrollPane1) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup().addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( txtFolio, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1).addComponent( jLabel6) .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel7) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(layout.createSequentialGroup() .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addComponent( txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent( txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent( txtHoraEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel3) .addComponent( txtFechaEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(txtRut, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel10) .addComponent( txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel9) .addComponent( txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))))))) .addGap(37, 37, 37))))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(22, 22, 22) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtFechaEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtFolio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup().addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtHoraEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(jLabel7)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtRut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jLabel8) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup().addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jLabel10) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel11).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton10).addComponent(jButton1).addComponent(lblEstado) .addComponent(jButton9)) .addGap(28, 28, 28))); pack(); }// </editor-fold>//GEN-END:initComponents // public ImageIcon barcode(String campotexto){ // Barcode barcode =null; // // try { // barcode= BarcodeFactory.createCodabar(campotexto); // } catch (BarcodeException e) { // // } // barcode.setDrawingText(true); // barcode.setBarHeight(60); // barcode.setBarWidth(2); // // // crear una imagen en memoria de 300x100 pixeles que contendra el codigo de barras; // BufferedImage image= new BufferedImage(300,100,BufferedImage.TYPE_INT_ARGB); // //Comenzar a difujar con graphiis // Graphics2D g = (Graphics2D) image.getGraphics(); // //dibujar codigo de barras en la posicion 5,20 // // try { // barcode.draw(g, 5, 20); // } catch (Exception e) { // } // return new ImageIcon(image); // // // } private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed // TODO add your handling code here: try { Connection miConexion = (Connection) Conexion.GetConnection(); Statement statement = (Statement) miConexion.createStatement(); String folio = txtFolio.getText(); ResultSet rs = statement .executeQuery("SELECT COUNT(*) AS num FROM tb_reserva WHERE num ='" + folio + "' "); int rows = 0; if (rs.next()) { rows = rs.getInt("num"); } if (rows > 0) { JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("Documento Pdf", "pdf"); chooser.setFileFilter(filter); chooser.setDialogTitle("Guardar archivo"); chooser.setMultiSelectionEnabled(false); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().toString().concat(".pdf"); FileOutputStream archivo = new FileOutputStream(file); Document documento = new Document(); PdfWriter pdfw = PdfWriter.getInstance(documento, archivo); documento.open(); PdfContentByte cb = pdfw.getDirectContent(); Barcode39 codeEAN = new Barcode39(); codeEAN.setCodeType(Barcode.UPCA); codeEAN.setCode(folio); documento.add(codeEAN.createImageWithBarcode(cb, null, null)); documento.add(new Paragraph("DOCUMENTO RESERVA", new Font(Font.FontFamily.HELVETICA, 16))); documento.add(new Paragraph("")); documento.add(new Paragraph("Nmero de folio : " + folio)); documento.add(new Paragraph("")); rs = statement.executeQuery("SELECT * FROM tb_reserva WHERE num ='" + folio + "' "); while (rs.next()) { documento.add(new Paragraph("Nmero de folio : " + folio)); documento.add(new Paragraph("Pedido Para Dia : " + rs.getString("fecha") + " A Las : " + rs.getString("hora") + " Horas")); documento.add( new Paragraph("Devolucion De Pedido Para El Dia : " + rs.getString("fecha_entrega") + " A Las : " + rs.getString("hora_entrega") + " Horas")); documento.add(new Paragraph("Solicit : " + rs.getString("rut"))); documento.add(new Paragraph("Fue Atendido Por : " + rs.getString("cod_admin"))); documento.add(new Paragraph("Sera Instalado Por : " + rs.getString("cod_instalador"))); int estado = rs.getInt("estado"); switch (estado) { case 1: documento.add(new Paragraph("EMITIDO")); break; case 2: documento.add(new Paragraph("ANULADO")); break; case 3: documento.add(new Paragraph("EJECUTADO")); break; } } PdfPTable table = new PdfPTable(3); rs = statement.executeQuery("SELECT * FROM tb_reserva_detalle WHERE folio ='" + folio + "' "); table.addCell("LINEA"); table.addCell("CODIGO"); table.addCell("DESCRIPCION"); while (rs.next()) { table.addCell(rs.getString("num")); table.addCell(rs.getString("codigo")); table.addCell(rs.getString("descripcion")); } documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(table); documento.close(); } // fin saveshowdialog } else { JOptionPane.showMessageDialog(this, "Numero de folio ingresado no se encuentra en sistema"); } } // fin trycatch catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error " + ex.getMessage()); } }//GEN-LAST:event_jButton10ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: Connection miConexion = (Connection) Conexion.GetConnection(); try { int fila = jTable1.getRowCount(); if (txtFolio.getText().trim().isEmpty()) { JOptionPane.showMessageDialog(this, "DEBE SELECCIONAR DOCUMENTO RESERVA"); } else { Statement statement = (Statement) miConexion.createStatement(); int folio = Integer.parseInt(txtFolio.getText()); statement.execute("UPDATE tb_reserva SET estado = 3 WHERE num = '" + folio + "'"); for (int i = 0; i < jTable1.getRowCount(); i++) { String codigo = (String) jTable1.getValueAt(i, 1); statement.execute("update tb_articulo set disponible = 0 where codigo = '" + codigo + "' "); } JOptionPane.showMessageDialog(this, "Datos ingresados correctamente"); statement.close(); miConexion.close(); } this.dispose(); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error " + ex.getMessage()); } }//GEN-LAST:event_jButton1ActionPerformed private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened // TODO add your handling code here: Connection miConexion = (Connection) Conexion.GetConnection(); txtFolio.setText(frmReservaBusqueda.txtFolio.getText()); try { if (txtFolio.getText().trim().isEmpty()) { JOptionPane.showMessageDialog(this, "Debe ingresar campo numero de folio"); } else { Statement statement = (Statement) miConexion.createStatement(); String folio = txtFolio.getText(); ResultSet rs = statement .executeQuery("SELECT COUNT(*) AS num FROM tb_reserva WHERE num ='" + folio + "' "); int rows = 0; if (rs.next()) { rows = rs.getInt("num"); } if (rows > 0) { rs = statement.executeQuery("SELECT * FROM tb_reserva WHERE num ='" + folio + "' "); while (rs.next()) { txtObservacion.setText(rs.getString("observacion")); txtRut.setText(rs.getString("rut")); ObtenerRegistroCliente(rs.getString("rut")); txtFecha.setText(rs.getString("fecha")); txtFechaEntrega.setText(rs.getString("fecha_entrega")); txtHora.setText(rs.getString("hora")); txtHoraEntrega.setText(rs.getString("hora_entrega")); int estado = rs.getInt("estado"); switch (estado) { case 1: lblEstado.setText("EMITIDO"); break; case 2: lblEstado.setText("ANULADO"); break; case 3: lblEstado.setText("EJECUTADO"); break; } rs = statement .executeQuery("SELECT * FROM tb_reserva_detalle WHERE folio ='" + folio + "' "); while (rs.next()) { DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel(); modelo.addRow(new Object[] { rs.getString("num"), rs.getString("codigo"), rs.getString("descripcion") }); } } rs.close(); statement.close(); miConexion.close(); } else { JOptionPane.showMessageDialog(this, "Numero de folio ingresado no se encuentra en sistema"); } } } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error " + ex.getMessage()); } }//GEN-LAST:event_formInternalFrameOpened private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed // TODO add your handling code here: Connection miConexion = (Connection) Conexion.GetConnection(); try { int dialogButton = JOptionPane.YES_NO_OPTION; int dialogResult = JOptionPane.showConfirmDialog(this, " DESEA ANULAR DOCUMENTO ?", "RESERVAS", dialogButton); if (dialogResult == 0) { if (txtFolio.getText().trim().isEmpty()) { JOptionPane.showMessageDialog(this, "Debe ingresar campo numero de folio"); } else { Statement statement = (Statement) miConexion.createStatement(); String folio = txtFolio.getText(); ResultSet rs = statement .executeQuery("SELECT COUNT(*) AS num FROM tb_reserva WHERE num ='" + folio + "' "); int rows = 0; if (rs.next()) { rows = rs.getInt("num"); } if (rows > 0) { int cantidad = statement .executeUpdate("UPDATE tb_reserva SET estado = 2 WHERE num ='" + folio + "' "); if (cantidad > 0) { JOptionPane.showMessageDialog(this, "Registro ANULADO exitosamente"); this.dispose(); } else { JOptionPane.showMessageDialog(this, "Problema ANULANDO registro de sistema"); } } else { JOptionPane.showMessageDialog(this, "Numero de folio ingresado no se encuentra en sistema"); } } } } catch (Exception ex) { JOptionPane.showMessageDialog(this, "Error " + ex.getMessage()); } }//GEN-LAST:event_jButton9ActionPerformed private void ObtenerRegistroCliente(String rut) { try { ResultSet rs, rs2 = null; Connection miConexion = (Connection) Conexion.GetConnection(); Statement statement = (Statement) miConexion.createStatement(); rs = statement.executeQuery("SELECT * from tb_cliente where rut = '" + rut + "'"); while (rs.next()) { txtRut.setText(rs.getString("rut")); txtNombre.setText(rs.getString("nombre")); txtTelefono.setText(rs.getString("telefono")); txtCelular.setText(rs.getString("celular")); txtEmail.setText(rs.getString("email")); } miConexion.close(); } catch (Exception ex) { //JOptionPane.showMessageDialog(this, "Error "+ex.getMessage()); } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton10; private javax.swing.JButton jButton9; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable jTable1; private javax.swing.JLabel lblEstado; private javax.swing.JTextField txtCelular; private javax.swing.JTextField txtEmail; private javax.swing.JTextField txtFecha; private javax.swing.JTextField txtFechaEntrega; public javax.swing.JTextField txtFolio; private javax.swing.JTextField txtHora; private javax.swing.JTextField txtHoraEntrega; private javax.swing.JTextField txtNombre; private javax.swing.JTextArea txtObservacion; private javax.swing.JTextField txtRut; private javax.swing.JTextField txtTelefono; // End of variables declaration//GEN-END:variables }