Java tutorial
import com.lowagie.text.Document; import com.lowagie.text.PageSize; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfWriter; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.event.ItemEvent; import java.awt.event.KeyEvent; import java.io.FileOutputStream; import java.sql.ResultSet; import java.sql.SQLException; import javax.swing.ImageIcon; /* * 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 Dhananjaya */ public class PRCR_Checkroll_Summar extends javax.swing.JFrame { /** * Creates new form PRCR_Checkroll_Summar */ Date_Handler datehandler = new Date_Handler(); DateChooser_text datechooser = new DateChooser_text(); DatabaseManager dbm = DatabaseManager.getDbCon(); PRCR_Checkroll_Amalgamation_Report rep = new PRCR_Checkroll_Amalgamation_Report(); public PRCR_Checkroll_Summar() { initComponents(); try { this.setIconImage(new ImageIcon(getClass().getResource("Iconpng.png")).getImage()); } 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() { jPanel1 = new javax.swing.JPanel(); datepanel1 = new javax.swing.JPanel(); monthfield2 = new javax.swing.JTextField(); yearfield2 = new javax.swing.JTextField(); datePick2 = new com.michaelbaranov.microba.calendar.DatePicker(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); division_jc = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); datepanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); monthfield2.setText(datehandler.get_today_month()); monthfield2.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { monthfield2KeyPressed(evt); } }); yearfield2.setText(datehandler.get_today_year()); yearfield2.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { yearfield2KeyPressed(evt); } }); datePick2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { datePick2ActionPerformed(evt); } }); javax.swing.GroupLayout datepanel1Layout = new javax.swing.GroupLayout(datepanel1); datepanel1.setLayout(datepanel1Layout); datepanel1Layout .setHorizontalGroup(datepanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(datepanel1Layout.createSequentialGroup().addGap(23, 23, 23) .addComponent(monthfield2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(yearfield2, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(24, 24, 24) .addComponent(datePick2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); datepanel1Layout.setVerticalGroup(datepanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(datepanel1Layout.createSequentialGroup().addGap(0, 0, 0).addGroup(datepanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(datePick2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(datepanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(monthfield2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(yearfield2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jTable1.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 }, { 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 }, { 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 }, { null, null }, { null, null }, { null, null } }, new String[] { "", "Amount" }) { Class[] types = new Class[] { java.lang.Object.class, java.lang.Double.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); jTable1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); jTable1.setGridColor(new java.awt.Color(255, 255, 255)); jTable1.setRowHeight(13); jScrollPane1.setViewportView(jTable1); if (jTable1.getColumnModel().getColumnCount() > 0) { jTable1.getColumnModel().getColumn(0).setPreferredWidth(250); jTable1.getColumnModel().getColumn(1).setPreferredWidth(100); } jButton1.setText("View"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Print"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); division_jc.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); division_jc.setEditable(true); division_jc.setModel(new javax.swing.DefaultComboBoxModel(dbm.getStringArray("division_details", "code"))); division_jc.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { division_jcItemStateChanged(evt); } }); division_jc.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { division_jcKeyPressed(evt); } }); jLabel2.setText("Division"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(datepanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel1Layout.createSequentialGroup().addGap(26, 26, 26) .addComponent(jLabel2).addGap(34, 34, 34).addComponent(division_jc, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 81, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 514, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(87, 87, 87))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(20, 20, 20) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2).addComponent(division_jc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(41, 41, 41) .addComponent(datepanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26).addComponent(jButton1).addGap(18, 18, 18) .addComponent(jButton2)) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 612, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(54, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void monthfield2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_monthfield2KeyPressed if (monthfield2.getText().equals("Jan")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Dec"); int yr = Integer.parseInt(yearfield2.getText()); yearfield2.setText("" + (yr - 1)); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Feb"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Feb")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Jan"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Mar"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Mar")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Feb"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Apr"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Apr")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Mar"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("May"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("May")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Apr"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Jun"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Jun")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("May"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Jul"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Jul")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Jun"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Aug"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Aug")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Jul"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Sep"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Sep")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Aug"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Oct"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Oct")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Sep"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Nov"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Nov")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Oct"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Dec"); monthfield2.selectAll(); } } else if (monthfield2.getText().equals("Dec")) { if (evt.getKeyCode() == KeyEvent.VK_UP) { monthfield2.setText("Nov"); int yr = Integer.parseInt(yearfield2.getText()); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_DOWN) { monthfield2.setText("Jan"); int yr = Integer.parseInt(yearfield2.getText()); yearfield2.setText("" + (yr + 1)); monthfield2.selectAll(); } } if (evt.getKeyCode() == KeyEvent.VK_LEFT) { //dayfield2.requestFocus(); //dayfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_RIGHT) { yearfield2.requestFocus(); yearfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { ////// ChaNGE focus on enter//////////////// //category_code.requestFocus(); } }//GEN-LAST:event_monthfield2KeyPressed private void datePick2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_datePick2ActionPerformed java.sql.Date datef = new java.sql.Date(datePick2.getDate().getTime()); // dayfield2.setText(datehandler.get_day(datef)); monthfield2.setText(datehandler.get_month(datef)); yearfield2.setText(datehandler.get_year(datef)); // category_code.requestFocus(); }//GEN-LAST:event_datePick2ActionPerformed private void yearfield2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_yearfield2KeyPressed if (evt.getKeyCode() == KeyEvent.VK_DOWN) { yearfield2.setText("" + (Integer.parseInt(yearfield2.getText()) + 1)); yearfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_UP) { yearfield2.setText("" + (Integer.parseInt(yearfield2.getText()) - 1)); yearfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_LEFT) { monthfield2.requestFocus(); monthfield2.selectAll(); } if (evt.getKeyCode() == KeyEvent.VK_ENTER) { ////// ChaNGE focus on enter//////////////// // category_code.requestFocus(); } }//GEN-LAST:event_yearfield2KeyPressed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // createNewDatabaseTable_CheckrollSummaryReport(); // try { // double normaldayss= checknReturnIntTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "normal_days") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Normal days"+ "','" + normaldayss + "')"); // double sundayss= checknReturnIntTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "sundays") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Sundays"+ "','" + sundayss + "')"); // double normalpayy= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "normal_pay") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Normal day pay"+ "','" + normalpayy + "')"); // double sundaypayy= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "sunday_pay") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Sunday pay"+ "','" + sundaypayy + "')"); // double totalpayy= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "total_pay") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Total pay"+ "','" + totalpayy + "')"); // double otbrfhrs= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ot_before_hours") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"OT Before Hours"+ "','" + otbrfhrs+ "')"); // double otbframnt= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ot_before_amount") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"OT Before pay"+ "','" + otbframnt + "')"); // double otaftrhrs= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ot_after_hours") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"OT After hours"+ "','" + otaftrhrs + "')"); // double otaftramnt= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ot_after_amount") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"OT After Amount"+ "','" + otaftramnt + "')"); // double incentive1= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "incentive1") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Incentive 1"+ "','" + incentive1 + "')"); // double incentive2= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "incentive2") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Incentive 2"+ "','" + incentive2 + "')"); // double grosspay= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "gross_pay") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Gross pay"+ "','" + grosspay + "')"); // double tea= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "tea") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Tea"+ "','" + tea + "')"); // double salaryadv= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "salary_adv") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Salary Advance"+ "','" + salaryadv + "')"); // double festadv= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "fest_adv") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Festival Advance"+ "','" + festadv + "')"); // double food= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "food") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Food"+ "','" + food + "')"); // double loan= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "loan") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Loan"+ "','" + loan + "')"); // double epf10= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "epf10") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"EPF 10"+ "','" + epf10 + "')"); // double epf12= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "epf12") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"EPF 12"+ "','" + epf12 + "')"); // double totepf= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "total_epf") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Total EPF "+ "','" + totepf + "')"); // double etf= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "etf") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"ETF"+ "','" + etf + "')"); // double ceb= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ceb") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"CEB"+ "','" + ceb + "')"); // double teacher= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "teacher") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Teacher"+ "','" + teacher + "')"); // double chem= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "chemical") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"CHEMICAL"+ "','" + chem + "')"); // double payslip= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "pay_slip") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Pay slip"+ "','" + payslip + "')"); // double fine= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "fine") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Fines"+ "','" + fine + "')"); // double welf= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "welfare") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Welfare"+ "','" + welf + "')"); // double kovil= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "kovil") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Kovil"+ "','" + kovil + "')"); // double new_1= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "new_1") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"New 1"+ "','" + new_1 + "')"); // double new_2= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "new_2") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"New 2"+ "','" + new_2 + "')"); // double other1= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "other_ded1") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Other Deduction 1"+ "','" + other1 + "')"); // double meals= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "meals") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Meals"+ "','" + meals + "')"); // double other2= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "other_ded2") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Other Deduction 2"+ "','" + other2 + "')"); // double pension= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "pension") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Pension"+ "','" + pension + "')"); // double predebt= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "pre_debt") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Pre Debts"+ "','" + predebt + "')"); // double totalded= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "total_ded") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Total Deduction"+ "','" + totalded + "')"); // double fullsal= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "full_salary") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Full Salary"+ "','" + fullsal + "')"); // double coins= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "coins") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Coins"+ "','" + coins + "')"); // double paid= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "paid_amount") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Paid Amount"+ "','" + paid + "')"); // double nextmnth= checknReturnDoubleTotal("pr_workdata_"+getST(monthfield2.getText(),yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "next_month") ; // dbm.insert("INSERT INTO prcr_checkroll_summary_report(column_1,amount) VALUES('" +"Next Month"+ "','" + nextmnth+ "')"); // // // // // // // // } catch (SQLException ex) { // System.out.println("error-couldnt write data in to checkrollsummaryreport database table"); // } System.out.println("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText())); System.out.println(division_jc.getSelectedItem().toString()); jTable1.setValueAt(checknReturnIntTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "normal_days"), 0, 1); jTable1.setValueAt(" Normal Days", 0, 0); jTable1.setValueAt(checknReturnIntTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "sundays"), 1, 1); jTable1.setValueAt(" Sun Days", 1, 0); //Holiday ?? jTable1.setValueAt(" Holidays", 2, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "normal_pay"), 4, 1); jTable1.setValueAt(" Normal Day Pay", 4, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "sunday_pay"), 5, 1); jTable1.setValueAt(" Sunday Pay", 5, 0); //HolidayPay?? jTable1.setValueAt(" Holiday Pay", 6, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "total_pay"), 7, 1); jTable1.setValueAt(" Total Pay", 7, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ot_before_hours"), 9, 1); jTable1.setValueAt(" Over Time Hours - Day", 9, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "ot_after_hours"), 10, 1); jTable1.setValueAt(" Over Time Hours - Night", 10, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "incentive1"), 12, 1); jTable1.setValueAt(" Incentive - 1", 12, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "incentive2"), 13, 1); jTable1.setValueAt(" Incentive - 2", 13, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "extra_pay"), 15, 1); jTable1.setValueAt(" Extra Pay", 15, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "gross_pay"), 17, 1); jTable1.setValueAt(" Gross Pay", 17, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "tea"), 19, 1); jTable1.setValueAt(" Tea", 19, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "salary_adv"), 20, 1); jTable1.setValueAt(" Salary Advance", 20, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "fest_adv"), 21, 1); jTable1.setValueAt(" Festival Advance", 21, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "food"), 22, 1); jTable1.setValueAt(" Food Stuffs", 22, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "loan"), 23, 1); jTable1.setValueAt(" Loan", 23, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "EPF 10%"), 25, 1); jTable1.setValueAt(" epf10", 25, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText())//Add other deduction separately , "division", division_jc.getSelectedItem().toString(), "other_ded1"), 27, 1); jTable1.setValueAt(" Other Deduction - 1", 27, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "meals"), 28, 1); jTable1.setValueAt(" Meals", 28, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "pension"), 29, 1); jTable1.setValueAt(" Pension", 29, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "pre_debt"), 31, 1); jTable1.setValueAt(" Previous Debts", 31, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "total_ded"), 33, 1); jTable1.setValueAt(" Total Deduction", 33, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "full_salary"), 35, 1); jTable1.setValueAt(" Balance Pay", 35, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "coins"), 37, 1); jTable1.setValueAt(" Coins", 37, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "paid_amount"), 38, 1); jTable1.setValueAt(" Paid Amount", 38, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "next_month"), 39, 1); jTable1.setValueAt(" Next Month", 39, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "epf12"), 42, 1); jTable1.setValueAt(" EPF 12%", 42, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "total_epf"), 43, 1); jTable1.setValueAt(" Total EPF", 43, 0); jTable1.setValueAt( checknReturnDoubleTotal("pr_workdata_" + getST(monthfield2.getText(), yearfield2.getText()), "division", division_jc.getSelectedItem().toString(), "etf"), 44, 1); jTable1.setValueAt(" ETF", 44, 0); }//GEN-LAST:event_jButton1ActionPerformed // public void createNewDatabaseTable_CheckrollSummaryReport(){ // try { // dbm.DeleteTable("prcr_checkroll_summary_report"); // //use new_1 and new_2 if any other deduction type is needd to be added // dbm.insert("CREATE TABLE prcr_checkroll_summary_report(column_1 VARCHAR(60)," // + "amount DOUBLE);"); // } catch (SQLException ex) { // //Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex); // System.err.println(ex.getMessage()); // } // } // Division column is the column in your database which divisions are entered // String division is the division you want to check. Give division as a string // column_need_to_get_total is Either Day OT hour column or Night OT hour column.. All other parameters are similar to the above method public double checknReturnDoubleTotal(String table_name, String division_column, String division, String column_need_to_get_total) { DatabaseManager dbm = DatabaseManager.getDbCon(); double tot = 0; try { ResultSet query = dbm.query("SELECT * FROM " + table_name + ""); while (query.next()) { if (query.getString(division_column).equals(division)) { tot = tot + query.getDouble(column_need_to_get_total); } } return tot; } catch (SQLException ex) { System.out.println(ex.getMessage()); System.out.println("SQL error-Some Amounts may be null "); } return tot; } public double checknReturnIntTotal(String table_name, String division_column, String division, String column_need_to_get_total) { DatabaseManager dbm = DatabaseManager.getDbCon(); int tot = 0; try { ResultSet query = dbm.query("SELECT * FROM " + table_name + ""); while (query.next()) { if (query.getString(division_column).equals(division)) { System.out.println(tot); tot = tot + query.getInt(column_need_to_get_total); System.out.println(tot); } } return tot; } catch (SQLException ex) { System.out.println(ex.getMessage()); System.out.println("SQL error-Some Normal days may be null "); } return tot; } public String getST(String month, String year) { String st; if (datehandler.return_index(month) < 10) { st = year + "_0" + datehandler.return_index(month); } else { st = year + "_" + datehandler.return_index(month); } System.out.println(st); return st; } private void division_jcItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_division_jcItemStateChanged DatabaseManager dbma = DatabaseManager.getDbCon(); String Name = null; if (evt.getStateChange() == ItemEvent.SELECTED) { String item = evt.getItem().toString(); try { ResultSet query = dbma.query("SELECT * FROM division_details WHERE code =" + item + ""); while (query.next()) { Name = query.getString("division"); System.out.println(Name); } } catch (SQLException ex) { System.out.println("error"); } // division_lb.setText("" + Name); } //empCode_JC.requestFocus(); }//GEN-LAST:event_division_jcItemStateChanged private void division_jcKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_division_jcKeyPressed if (evt.getKeyCode() == KeyEvent.VK_ENTER) { ////// ChaNGE focus on enter//////////////// // empCode_JC.requestFocus(); } // TODO add your handling code here: }//GEN-LAST:event_division_jcKeyPressed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed rep.CreateReport(division_jc.getSelectedItem().toString(), getST(monthfield2.getText(), yearfield2.getText()), getST(monthfield2.getText(), yearfield2.getText())); }//GEN-LAST:event_jButton2ActionPerformed private void print() { Document document = new Document(PageSize.A4); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:/CheckrollSummary.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); Graphics2D g2 = cb.createGraphicsShapes(600, 750); Shape oldClip = g2.getClip(); g2.clipRect(0, 0, 600, 750); jTable1.print(g2); g2.setClip(oldClip); g2.dispose(); cb.restoreState(); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); } /** * @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(PRCR_Checkroll_Summar.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PRCR_Checkroll_Summar.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PRCR_Checkroll_Summar.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PRCR_Checkroll_Summar.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 PRCR_Checkroll_Summar().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private com.michaelbaranov.microba.calendar.DatePicker datePick2; private javax.swing.JPanel datepanel1; private javax.swing.JComboBox division_jc; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; private javax.swing.JTextField monthfield2; private javax.swing.JTextField yearfield2; // End of variables declaration//GEN-END:variables }