Java tutorial
package pkgfinal; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.FontFactory; import com.itextpdf.text.Image; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import java.awt.event.KeyEvent; //import java.awt.Image; import java.io.FileOutputStream; import static java.lang.String.valueOf; import java.sql.Connection; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.text.MessageFormat; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.TableModel; import javax.swing.table.DefaultTableModel; //import javax.swing.text.Document; import net.proteanit.sql.DbUtils; /* * 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. */ /** * * @author Ali */ public class viewTable extends javax.swing.JFrame { Connection conn = null; ResultSet rs = null; PreparedStatement pst = null; public viewTable() { initComponents(); conn = conn2.DB(); combobox(); // Update_table(); } // methods m = new methods(); createTable ct = new createTable(); public void Update_table() { try { String sql = "select * from '" + jComboBox1.getSelectedItem() + "' order by ID"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); table.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { } } } private void combobox() { try { // String sql3 ="SELECT * FROM SalPur.sqlite_master WHERE type='table'"; String sql4 = "SELECT name FROM sqlite_master WHERE type='table'"; // String sql="select * from sys.tables"; // String sql5="select sys.table from sqlite_master"; pst = conn.prepareStatement(sql4); rs = pst.executeQuery(); while (rs.next()) { //String Name =rs.getString(sql4.toString()); jComboBox1.addItem(rs.getString(1)); // name.setText(valueOf(jComboBox1)); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "combox"); } finally { try { rs.close(); pst.close(); } catch (Exception e) { } } } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); jComboBox1 = new javax.swing.JComboBox(); jButton1 = new javax.swing.JButton(); name = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); date_tf = new com.toedter.calendar.JDateChooser(); jLabel6 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); BRname_tf = new javax.swing.JTextField(); purchase_tf = new javax.swing.JTextField(); id_tf = new javax.swing.JTextField(); MAname_tf = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); sale_tf = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); total = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); jLabel8 = new javax.swing.JLabel(); Add_Sub = new javax.swing.JTextField(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jPanel5 = new javax.swing.JPanel(); jLabel9 = new javax.swing.JLabel(); Sale_Add_Sub = new javax.swing.JTextField(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jPanel6 = new javax.swing.JPanel(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); Clear = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jPanel7 = new javax.swing.JPanel(); jButton12 = new javax.swing.JButton(); jLabel11 = new javax.swing.JLabel(); T_pur = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); T_sale = new javax.swing.JTextField(); T_Quantity = new javax.swing.JTextField(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jPanel8 = new javax.swing.JPanel(); search_tf = new javax.swing.JTextField(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); table.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null, null }, { null, null, null, null, null, null, null }, { null, null, null, null, null, null, null }, { null, null, null, null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4", "title ", "null", "Title 7" })); table.setToolTipText("Table"); table.setMinimumSize(new java.awt.Dimension(60, 120)); table.setRowHeight(30); table.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tableMouseClicked(evt); } }); table.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { tableKeyReleased(evt); } }); jScrollPane1.setViewportView(table); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Table Name" })); jComboBox1.addPopupMenuListener(new javax.swing.event.PopupMenuListener() { public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) { } public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) { jComboBox1PopupMenuWillBecomeInvisible(evt); } public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) { } }); jComboBox1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jComboBox1MouseClicked(evt); } }); jComboBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed(evt); } }); jButton1.setText("Back"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("show Table"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jPanel2.setBackground(new java.awt.Color(204, 204, 255)); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Purchase Data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(51, 51, 255))); // NOI18N jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel6.setText("Id"); jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel2.setText("Manufacture Name"); purchase_tf.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { purchase_tfActionPerformed(evt); } }); MAname_tf.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MAname_tfActionPerformed(evt); } }); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel3.setText("Purchase Quantity"); jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel7.setText("Date"); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel1.setText("Brand Name"); 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() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(purchase_tf, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2).addComponent(jLabel1).addComponent(jLabel7) .addComponent( jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(BRname_tf, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(MAname_tf, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(date_tf, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(id_tf, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(17, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(id_tf).addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(21, 21, 21) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel7).addComponent(date_tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(27, 27, 27) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(BRname_tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(20, 20, 20) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2).addComponent(MAname_tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(25, 25, 25) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(purchase_tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap())); jPanel1.setBackground(new java.awt.Color(204, 204, 255)); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Sale Detail", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(51, 51, 255))); // NOI18N jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel4.setText("Sale Quantity"); 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().addComponent(jLabel4) .addGap(27, 27, 27) .addComponent(sale_tf, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4).addComponent(sale_tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap())); jPanel3.setBackground(new java.awt.Color(204, 204, 255)); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total Detail", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(51, 51, 255))); // NOI18N jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jLabel5.setText("Total Quantity"); 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(jLabel5) .addGap(27, 27, 27) .addComponent(total, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(20, 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(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING).addComponent(total, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap())); jPanel4.setBackground(new java.awt.Color(204, 204, 255)); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Purchase", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(51, 51, 255))); // NOI18N jLabel8.setText("Purchase / Purchase Return"); jButton3.setText("Add"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setText("Sub"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addComponent(jLabel8) .addGap(44, 44, 44) .addComponent(Add_Sub, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(19, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3).addGap(18, 18, 18).addComponent(jButton4).addGap(23, 23, 23))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8).addComponent(Add_Sub, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3).addComponent(jButton4)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel5.setBackground(new java.awt.Color(204, 204, 255)); jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Sale Return", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12), new java.awt.Color(51, 51, 255))); // NOI18N jLabel9.setText("Sale Return"); Sale_Add_Sub.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { Sale_Add_SubActionPerformed(evt); } }); jButton5.setText("Add"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } }); jButton6.setText("Sub"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout .setHorizontalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap() .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(46, 46, 46) .addComponent(Sale_Add_Sub, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton5).addGap(18, 18, 18).addComponent(jButton6) .addGap(22, 22, 22))); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addGroup(jPanel5Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel9) .addComponent(Sale_Add_Sub, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE) .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton5).addComponent(jButton6)))); jPanel6.setBackground(new java.awt.Color(204, 204, 255)); jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Buttons", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 1, 12))); // NOI18N jButton7.setText("Save"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } }); jButton8.setText("Delete"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } }); Clear.setText("Clear"); Clear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearActionPerformed(evt); } }); jButton9.setText("Update"); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6); jPanel6.setLayout(jPanel6Layout); jPanel6Layout.setHorizontalGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addComponent(jButton9) .addGap(28, 28, 28).addComponent(Clear)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup().addComponent(jButton7) .addGap(28, 28, 28).addComponent(jButton8).addGap(6, 6, 6))) .addContainerGap())); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton7).addComponent(jButton8)) .addGap(18, 18, 18) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton9).addComponent(Clear)) .addContainerGap())); jPanel7.setBackground(new java.awt.Color(204, 204, 255)); jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Total Quantity", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), new java.awt.Color(255, 51, 102))); // NOI18N jButton12.setText("Total Quantities"); jButton12.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton12ActionPerformed(evt); } }); jLabel11.setText("Total Sale"); jLabel10.setText("Total Purchase"); jLabel12.setText("Total Quantity"); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addContainerGap().addGroup(jPanel7Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel7Layout.createSequentialGroup().addGap(114, 114, 114).addComponent(jButton12)) .addGroup(jPanel7Layout.createSequentialGroup().addComponent(jLabel10) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel12)) .addGroup(jPanel7Layout.createSequentialGroup() .addComponent(T_pur, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(T_sale, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(T_Quantity, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap())); jPanel7Layout.setVerticalGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup().addGap(25, 25, 25) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10).addComponent(jLabel11).addComponent(jLabel12)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(T_pur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(T_sale, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(T_Quantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton12).addContainerGap())); jButton10.setText("Print"); jButton10.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton10ActionPerformed(evt); } }); jButton11.setText("save Report"); jButton11.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton11ActionPerformed(evt); } }); jPanel8.setBackground(new java.awt.Color(204, 204, 255)); jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Search", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(51, 102, 255))); // NOI18N search_tf.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { search_tfKeyReleased(evt); } }); javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8); jPanel8.setLayout(jPanel8Layout); jPanel8Layout .setHorizontalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel8Layout.createSequentialGroup().addContainerGap() .addComponent(search_tf, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE) .addContainerGap())); jPanel8Layout.setVerticalGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel8Layout.createSequentialGroup().addContainerGap() .addComponent(search_tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.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(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(0, 43, Short.MAX_VALUE) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 817, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(22, 22, 22) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1) .addGroup(layout.createSequentialGroup().addComponent(jButton10) .addGap(18, 18, 18).addComponent(jButton11))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(35, 35, 35).addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addGap(42, 42, 42).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2)) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(143, 143, 143))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(22, 22, 22).addComponent( jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))) .addContainerGap(66, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(23, 23, 23).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(37, 37, 37) .addComponent(jButton1).addGap(18, 18, 18) .addGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton10).addComponent(jButton11))) .addGroup(layout.createSequentialGroup().addGap(28, 28, 28).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addGroup(layout.createSequentialGroup().addGap(31, 31, 31) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(31, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void jComboBox1PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBox1PopupMenuWillBecomeInvisible // comboxSelect(); // String temp =(String)jComboBox1.getSelectedItem(); // table.setModel(ct.tname).jComboBox1.getSelectedItem(); /* try{ int row = table.getSelectedRow(); String table_click =(table.getModel().getValueAt(row, 0).toString()); String sql ="select * from "+ct.tname+" where Id="+table_click+" "; String sql1 ="SELECT * FROM sqlite_master WHERE type='table'"; table.setModel().jComboBox1.getSelectedItem(); pst = conn.prepareStatement(sql1); pst.setString(1, temp); rs = pst.executeQuery(); if(rs.next()){ String val1 = rs.getString("Id"); Date val2 = rs.getDate("date"); String val3 = rs.getString("BrandName"); String val4 = rs.getString("ManufactureName"); String val5 = rs.getString("PurchaseQuantity"); String val6 = rs.getString("SaleQuantity"); String val7 = rs.getString("TotalQuantity"); } } catch(Exception e){ JOptionPane.showMessageDialog(null,"combox2"); } */ // String sql7 ="SELECT name FROM sqlite_master WHERE type='table'"; // String tempt =(String)jComboBox1.getSelectedItem(); /* try{ String sql7 ="SELECT name FROM sqlite_master WHERE type='table'"; String tempt =(String)jComboBox1.getSelectedItem(); pst = conn.prepareStatement(sql7); pst.setString(1, tempt); rs = pst.executeQuery(); if(rs.next()){ table.setModel((TableModel) rs); } } catch(Exception e){ JOptionPane.showMessageDialog(null,"combox3"); } */ }//GEN-LAST:event_jComboBox1PopupMenuWillBecomeInvisible private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed // try { String sql = " select * from '" + jComboBox1.getSelectedItem() + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); table.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { } } }//GEN-LAST:event_jComboBox1ActionPerformed private void tableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseClicked try { int row = table.getSelectedRow(); String table_clicked = (table.getModel().getValueAt(row, 0).toString()); String sql = "select * from '" + jComboBox1.getSelectedItem() + "' where ID= '" + table_clicked + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { String add1 = rs.getString("ID"); id_tf.setText(add1); /* String add2 = rs.getDate("Date").toString(); date_tf.setDateFormatString(add2); // date_tf.setToolTipText(add2); */ /* String add2 = rs.getString("Date"); // date_tf.setDateFormatString(add2); */ java.util.Date add2 = rs.getDate("Date"); date_tf.setDate(add2); String add3 = rs.getString("BrandName"); BRname_tf.setText(add3); String add4 = rs.getString("ManufactureName"); MAname_tf.setText(add4); String add5 = rs.getString("PurchaseQuantity"); purchase_tf.setText(add5); String add6 = rs.getString("SaleQuantity"); sale_tf.setText(add6); String add7 = rs.getString("TotalQuantity"); total.setText(add7); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); // Update_table(); } }//GEN-LAST:event_tableMouseClicked private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed dispose(); options op = new options(); op.setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed try { String sql = " select * from '" + name.getText() + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); table.setModel(DbUtils.resultSetToTableModel(rs)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { rs.close(); pst.close(); } catch (Exception e) { } } }//GEN-LAST:event_jButton2ActionPerformed private void jComboBox1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox1MouseClicked // try{ // String row= (String) jComboBox1.getSelectedItem(); // String Table_click = (table.getModel().toString()); // String sql = "select * from '"+row+"' where Id= '"+Table_click+"' "; // // pst = conn.prepareStatement(sql); // rs = pst.executeQuery(); // // if(rs.next()){ // // String add1 =rs.getString("Id"); // // EmployeeID_text.setText(add1); // Date add2 =rs.getDate("date"); // // Name_text.setText(add2); // String add3 =rs.getString("BrandName"); // // Surname_text.setText(add3); // String add4 =rs.getString("ManufactureName"); // // Age_text.setText(add4); // String add5 =rs.getString("PurchaseQuantity"); // String add6 =rs.getString("SaleQuantity"); // String add7 =rs.getString("TotalQuantity"); // } // // } // catch(Exception e){ // JOptionPane.showMessageDialog(null, e); // } }//GEN-LAST:event_jComboBox1MouseClicked private void purchase_tfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_purchase_tfActionPerformed // TODO add your handling code here: }//GEN-LAST:event_purchase_tfActionPerformed private void MAname_tfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MAname_tfActionPerformed // TODO add your handling code here: }//GEN-LAST:event_MAname_tfActionPerformed private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed try { String sql = "insert into '" + jComboBox1.getSelectedItem() + "'(ID, Date, BrandName, ManufactureName, PurchaseQuantity, SaleQuantity, TotalQuantity ) values(?,?,?,?,?,?,?)"; pst = conn.prepareStatement(sql); pst.setString(1, id_tf.getText()); pst.setString(2, ((JTextField) date_tf.getDateEditor().getUiComponent()).getText()); pst.setString(3, BRname_tf.getText()); pst.setString(4, MAname_tf.getText()); pst.setString(5, purchase_tf.getText()); pst.setString(6, sale_tf.getText()); double sub = Double.parseDouble(purchase_tf.getText()); double sub2 = Double.parseDouble(sale_tf.getText()); double v = sub - sub2; total.setText(String.valueOf(v)); pst.setString(7, total.getText()); /* String val = purchase_tf.getText(); String val2 = sale_tf.getText(); String Total = val-val2; */ // pst.setString(7, Total); if (sub >= sub2) { JOptionPane.showMessageDialog(null, "saved"); pst.execute(); } else { JOptionPane.showMessageDialog(null, "Purchase Quantity must be greater than Sale Quantity"); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } try { Update_table(); } finally { try { rs.close(); pst.close(); } catch (Exception e) { } } }//GEN-LAST:event_jButton7ActionPerformed private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed int p = JOptionPane.showConfirmDialog(null, "Do you Really want to Delete", "Deleted", JOptionPane.YES_NO_OPTION); if (p == 0) { try { String sql = "Delete from '" + jComboBox1.getSelectedItem() + "' where ID=?"; pst = conn.prepareStatement(sql); pst.setString(1, id_tf.getText()); pst.execute(); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } try { Update_table(); } finally { try { rs.close(); pst.close(); } catch (Exception e) { } } }//GEN-LAST:event_jButton8ActionPerformed private void ClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearActionPerformed id_tf.setText(""); date_tf.setDate(null); BRname_tf.setText(""); MAname_tf.setText(""); purchase_tf.setText(""); Add_Sub.setText(""); sale_tf.setText(""); Sale_Add_Sub.setText(""); total.setText(""); }//GEN-LAST:event_ClearActionPerformed private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed try { String val1 = id_tf.getText(); String val2 = (((JTextField) date_tf.getDateEditor().getUiComponent()).getText()); // String Val7 = val2.CURRENT_DATE(); String val3 = BRname_tf.getText(); String val4 = MAname_tf.getText(); String val5 = purchase_tf.getText(); String val6 = sale_tf.getText(); double sub = Double.parseDouble(purchase_tf.getText()); double sub2 = Double.parseDouble(sale_tf.getText()); double v = sub - sub2; total.setText(String.valueOf(v)); String val7 = total.getText(); String sql = "update '" + jComboBox1.getSelectedItem() + "' set ID='" + val1 + "' ,Date='" + val2 + "', BrandName='" + val3 + "' ,MAnufactureNAme='" + val4 + "' ,PurchaseQuantity='" + val5 + "' ,SaleQuantity='" + val6 + "',TotalQuantity='" + val7 + "' where ID='" + val1 + "'"; pst = conn.prepareStatement(sql); if (sub >= sub2) { pst.execute(); JOptionPane.showMessageDialog(null, "Updated"); } else { JOptionPane.showMessageDialog(null, "Purchase Quantity must be greater than Sale Quantity"); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } try { Update_table(); } finally { try { pst.close(); rs.close(); } catch (Exception e) { } } }//GEN-LAST:event_jButton9ActionPerformed private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed MessageFormat header = new MessageFormat(" '" + jComboBox1.getSelectedItem() + "' Report"); MessageFormat footer = new MessageFormat("Page{0,number,integer}"); try { table.print(JTable.PrintMode.NORMAL, header, footer); } catch (java.awt.print.PrinterException e) { System.err.format("Cannot print %s%n", e.getMessage()); } }//GEN-LAST:event_jButton10ActionPerformed private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(" " + jComboBox1.getSelectedItem() + ".pdf")); document.open(); // Image image = Image.getInstance("save.png"); // document.add(new Paragraph("image")); // document.add(image); document.add(new Paragraph("ECHO TRADERS", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.RED))); document.add(new Paragraph(" " + jComboBox1.getSelectedItem() + " Report ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.BLUE))); document.add(new Paragraph(new java.util.Date().toString())); document.add(new Paragraph("--------------------------------------------------------")); PdfPTable table = new PdfPTable(7); PdfPCell cell = new PdfPCell(new Paragraph("Purcahse_Sale Report")); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(BaseColor.GREEN); table.addCell(cell); String sql = "select * from '" + jComboBox1.getSelectedItem() + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { String v1 = rs.getString("ID"); String add = rs.getString("Date"); String v2 = rs.getString("BrandName"); String v3 = rs.getString("ManufactureName"); String v4 = rs.getString("PurchaseQuantity"); String v5 = rs.getString("SaleQuantity"); String v6 = rs.getString("TotalQuantity"); // table.addCell("ID"); table.addCell(v1); // table.addCell(v/*.date_tf.getDateFormatString()*/); table.addCell(add); // table.addCell("Brand name"); table.addCell(v2); // table.addCell("Manyfacture Name"); table.addCell(v3); // table.addCell("purchase Quantity"); table.addCell(v4); table.addCell(v5); table.addCell(v6); } document.add(table); com.itextpdf.text.List list = new com.itextpdf.text.List(true, 20); list.add("Printed Date:_____________"); list.add("Signature:_______________"); document.add(list); document.close(); JOptionPane.showMessageDialog(null, "Saved Report"); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } }//GEN-LAST:event_jButton11ActionPerformed private void Sale_Add_SubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Sale_Add_SubActionPerformed // TODO add your handling code here: }//GEN-LAST:event_Sale_Add_SubActionPerformed private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed try { String sql = "select sum(PurchaseQuantity), sum(SaleQuantity), sum(TotalQuantity) from '" + jComboBox1.getSelectedItem() + "'"; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { String sum1 = rs.getString("sum(PurchaseQuantity)"); T_pur.setText(sum1); String sum2 = rs.getString("sum(SaleQuantity)"); T_sale.setText(sum2); String sum3 = rs.getString("sum(TotalQuantity)"); T_Quantity.setText(sum3); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } Update_table(); }//GEN-LAST:event_jButton12ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed Double sub1 = Double.parseDouble(purchase_tf.getText()); Double sub2 = Double.parseDouble(Add_Sub.getText()); Double output = sub1 + sub2; purchase_tf.setText(String.valueOf(output)); }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed Double sub1 = Double.parseDouble(purchase_tf.getText()); Double sub2 = Double.parseDouble(Add_Sub.getText()); Double output = sub1 - sub2; purchase_tf.setText(String.valueOf(output)); }//GEN-LAST:event_jButton4ActionPerformed private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed Double SubSale = Double.parseDouble(sale_tf.getText()); Double SubSale2 = Double.parseDouble(Sale_Add_Sub.getText()); Double SaleSubOutput = SubSale + SubSale2; sale_tf.setText(String.valueOf(SaleSubOutput)); }//GEN-LAST:event_jButton5ActionPerformed private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed Double SubSale = Double.parseDouble(sale_tf.getText()); Double SubSale2 = Double.parseDouble(Sale_Add_Sub.getText()); Double SaleSubOutput = SubSale - SubSale2; sale_tf.setText(String.valueOf(SaleSubOutput)); }//GEN-LAST:event_jButton6ActionPerformed private void search_tfKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_search_tfKeyReleased try { String sql = "Select * from '" + jComboBox1.getSelectedItem() + "' where ID=?"; pst = conn.prepareStatement(sql); pst.setString(1, search_tf.getText()); rs = pst.executeQuery(); if (rs.next()) { String add1 = rs.getString("ID"); id_tf.setText(add1); java.util.Date add2 = rs.getDate("Date"); date_tf.setDate(add2); String add3 = rs.getString("BrandName"); BRname_tf.setText(add3); String add4 = rs.getString("ManufactureName"); MAname_tf.setText(add4); String add5 = rs.getString("PurchaseQuantity"); purchase_tf.setText(add5); String add6 = rs.getString("SaleQuantity"); sale_tf.setText(add6); String add7 = rs.getString("TotalQuantity"); total.setText(add7); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } // For BrandName try { String sql = "Select * from '" + jComboBox1.getSelectedItem() + "' where BrandName=?"; pst = conn.prepareStatement(sql); pst.setString(1, search_tf.getText().toUpperCase().toLowerCase()); rs = pst.executeQuery(); if (rs.next()) { String add1 = rs.getString("Id"); id_tf.setText(add1); java.util.Date add2 = rs.getDate("Date"); date_tf.setDate(add2); String add3 = rs.getString("BrandName"); BRname_tf.setText(add3); String add4 = rs.getString("ManufactureName"); MAname_tf.setText(add4); String add5 = rs.getString("PurchaseQuantity"); purchase_tf.setText(add5); String add6 = rs.getString("saleQuantity"); sale_tf.setText(add6); String add7 = rs.getString("TotalQuantity"); total.setText(add7); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } try { String sql = "Select * from '" + jComboBox1.getSelectedItem() + "' where ManufactureName=? "; pst = conn.prepareStatement(sql); pst.setString(1, search_tf.getText().toUpperCase().toLowerCase()); rs = pst.executeQuery(); if (rs.next()) { String add1 = rs.getString("ID"); id_tf.setText(add1); java.util.Date add2 = rs.getDate("Date"); date_tf.setDate(add2); String add3 = rs.getString("BrandName"); BRname_tf.setText(add3); String add4 = rs.getString("ManufactureName"); MAname_tf.setText(add4); String add5 = rs.getString("PurchaseQuantity"); purchase_tf.setText(add5); String add6 = rs.getString("SaleQuantity"); sale_tf.setText(add6); String add7 = rs.getString("TotalQuantity"); total.setText(add7); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } finally { try { pst.close(); rs.close(); } catch (Exception e) { } } Update_table(); }//GEN-LAST:event_search_tfKeyReleased private void tableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyReleased if (evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP) { try { int row = table.getSelectedRow(); String table_clicked = (table.getModel().getValueAt(row, 0).toString()); String sql = "select * from '" + jComboBox1.getSelectedItem() + "' where ID= '" + table_clicked + "' "; pst = conn.prepareStatement(sql); rs = pst.executeQuery(); if (rs.next()) { String add1 = rs.getString("ID"); id_tf.setText(add1); java.util.Date add2 = rs.getDate("Date"); date_tf.setDate(add2); String add3 = rs.getString("BrandName"); BRname_tf.setText(add3); String add4 = rs.getString("ManufactureName"); MAname_tf.setText(add4); String add5 = rs.getString("PurchaseQuantity"); purchase_tf.setText(add5); String add6 = rs.getString("SaleQuantity"); sale_tf.setText(add6); String add7 = rs.getString("TotalQuantity"); total.setText(add7); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } }//GEN-LAST:event_tableKeyReleased /** * @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(viewTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(viewTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(viewTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(viewTable.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new viewTable().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextField Add_Sub; private javax.swing.JTextField BRname_tf; private javax.swing.JButton Clear; private javax.swing.JTextField MAname_tf; private javax.swing.JTextField Sale_Add_Sub; private javax.swing.JTextField T_Quantity; private javax.swing.JTextField T_pur; private javax.swing.JTextField T_sale; private com.toedter.calendar.JDateChooser date_tf; private javax.swing.JTextField id_tf; private javax.swing.JButton jButton1; private javax.swing.JButton jButton10; private javax.swing.JButton jButton11; private javax.swing.JButton jButton12; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JButton jButton9; public javax.swing.JComboBox jComboBox1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; 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.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JPanel jPanel6; private javax.swing.JPanel jPanel7; private javax.swing.JPanel jPanel8; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField name; private javax.swing.JTextField purchase_tf; private javax.swing.JTextField sale_tf; private javax.swing.JTextField search_tf; public javax.swing.JTable table; private javax.swing.JTextField total; // End of variables declaration//GEN-END:variables //String tname = null; }