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 gskproject; import java.awt.BorderLayout; import java.awt.Color; import java.sql.SQLException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; /** * * @author chamod */ public class Analyze extends javax.swing.JFrame { DBOperations dbOps = new DBOperations(); static Vector<String> PcolumnNames; //static Vector<Vector> personWiseObervation; static Vector<Vector> tableObservation; static Vector<Vector> tableDepartmentWise; static Vector<Vector> tablePersonWise; static Vector<Vector> tableAccidentTypeWise; static Vector<Vector> tableDepartmentAccident; static HashMap<String, Object> para; static HashMap<Object, Object[]> multiMap; static HashMap<Object, Object[]> depHashMap; static ArrayList<User> userList; static final String[] ACCIDENT_TYPE = { "First Aid", "LTI", "Near Miss" }; //public static int[][] dep; //public static int[][] accident; //public static int[][] depAccident; //static int nuOfAllCasesDepartmentVise; public Analyze() { initComponents(); loadFrame(); } /** * 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() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); btnFilter = new javax.swing.JButton(); dtDAFrom = new com.toedter.calendar.JDateChooser(); dtDATo = new com.toedter.calendar.JDateChooser(); jSeparator1 = new javax.swing.JSeparator(); jLabel23 = new javax.swing.JLabel(); jLabel24 = new javax.swing.JLabel(); ddDTimePeriod = new javax.swing.JComboBox(); jPanel3 = new javax.swing.JPanel(); ddDDepartment = new javax.swing.JComboBox(); jLabel20 = new javax.swing.JLabel(); jLabel21 = new javax.swing.JLabel(); ddDAccidentType = new javax.swing.JComboBox(); btnDAGraph = new javax.swing.JButton(); jLabel22 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); tblDepartmentAccident = new javax.swing.JTable(); jPanel4 = new javax.swing.JPanel(); jLabel17 = new javax.swing.JLabel(); jLabel18 = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); lblTotal = new javax.swing.JLabel(); lblOpen = new javax.swing.JLabel(); lblClosed = new javax.swing.JLabel(); lblTime = new javax.swing.JLabel(); btnReport = new javax.swing.JButton(); test2 = new javax.swing.JTextField(); dname = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jPanel6 = new javax.swing.JPanel(); dtPTo = new com.toedter.calendar.JDateChooser(); jLabel7 = new javax.swing.JLabel(); dtPFrom = new com.toedter.calendar.JDateChooser(); jLabel8 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); tblPersonVise = new javax.swing.JTable(); jLabel10 = new javax.swing.JLabel(); ddGraphPersonWise = new javax.swing.JComboBox(); jLabel11 = new javax.swing.JLabel(); ddDepartment = new javax.swing.JComboBox(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); lblPTotal = new javax.swing.JLabel(); lblPOpen = new javax.swing.JLabel(); lblPClosed = new javax.swing.JLabel(); btnPersonGraph = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Analyze"); jPanel2.setBorder(javax.swing.BorderFactory .createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Enter Duration")); jLabel15.setText("From"); jLabel16.setText("To"); btnFilter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/filter.png"))); // NOI18N btnFilter.setText("Filter"); btnFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFilterActionPerformed(evt); } }); dtDAFrom.setDateFormatString("d MMM yyyy"); dtDAFrom.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { dtDAFromPropertyChange(evt); } }); dtDAFrom.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { dtDAFromKeyPressed(evt); } }); dtDATo.setDateFormatString("d MMM yyyy"); dtDATo.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { dtDAToPropertyChange(evt); } }); dtDATo.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { dtDAToKeyPressed(evt); } }); jLabel23.setText("1 ."); jLabel24.setText("2 ."); ddDTimePeriod.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select Time Period", "Last Week", "Last Month", "Last Year", "This Week", "This Month", "This Year" })); ddDTimePeriod.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddDTimePeriodActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel23).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel15).addGap(9, 9, 9) .addComponent(dtDAFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26).addComponent(jLabel16) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(dtDATo, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(26, 26, 26).addComponent(btnFilter).addGap(21, 21, 21)) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jSeparator1) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel24) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ddDTimePeriod, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(btnFilter) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel15).addComponent(jLabel23)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(dtDATo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(dtDAFrom, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel24).addComponent(ddDTimePeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel3.setBorder(javax.swing.BorderFactory .createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Graph")); ddDDepartment.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { ddDDepartmentMouseClicked(evt); } }); ddDDepartment.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddDDepartmentActionPerformed(evt); } }); jLabel20.setText("1. Department : "); jLabel21.setText("Accident Type : "); ddDAccidentType.setModel( new javax.swing.DefaultComboBoxModel(new String[] { "All", "First Aid", "LTI", "Near Miss" })); ddDAccidentType.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddDAccidentTypeActionPerformed(evt); } }); btnDAGraph.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/chart-icon.png"))); // NOI18N btnDAGraph.setText("Graph"); btnDAGraph.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDAGraphActionPerformed(evt); } }); jLabel22.setText("2. "); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/piechart.png"))); // NOI18N jButton2.setText("Overrall All Accident Types Spread "); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel20) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(ddDDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(12, 12, 12).addComponent(jLabel21)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel22) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnDAGraph).addComponent(ddDAccidentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(91, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ddDDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel20).addComponent(jLabel21).addComponent(ddDAccidentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2).addComponent(jLabel22).addComponent(btnDAGraph)) .addContainerGap(38, Short.MAX_VALUE))); tblDepartmentAccident.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 } }, new String[] { "Department", "First Aid", "LTI", "Near Miss", "Open Cases", "Closed Cases", "Total" })); tblDepartmentAccident.setCellSelectionEnabled(false); tblDepartmentAccident.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); tblDepartmentAccident.setRowSelectionAllowed(true); jScrollPane1.setViewportView(tblDepartmentAccident); tblDepartmentAccident.getColumnModel().getSelectionModel() .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jPanel4.setBorder(javax.swing.BorderFactory .createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Summary")); jLabel17.setText("Number of Open Cases : "); jLabel18.setText("Total reported Cases : "); jLabel19.setText("Number of Closed Cases : "); lblTotal.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblOpen.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblOpen.setForeground(new java.awt.Color(255, 0, 0)); lblClosed.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblClosed.setForeground(new java.awt.Color(0, 204, 51)); lblTime.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(25, 25, 25) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel17).addComponent(jLabel18).addComponent(jLabel19)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblOpen, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblClosed, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel4Layout.createSequentialGroup().addGap(85, 85, 85).addComponent(lblTime, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(7, 7, 7) .addComponent(lblTime, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(lblTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel18)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel17).addComponent(lblOpen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblClosed, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel19)) .addContainerGap(14, Short.MAX_VALUE))); btnReport.setText("Generate Report"); btnReport.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnReportActionPerformed(evt); } }); dname.setText("jTextField1"); jButton1.setText("jButton1"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(22, 22, 22).addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 744, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel1Layout.createSequentialGroup().addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnReport).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(102, 102, 102) .addGroup(jPanel1Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(test2, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addComponent(dname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(9, 9, 9)))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1).addGap(178, 178, 178))))) .addContainerGap(36, Short.MAX_VALUE))); jPanel1Layout .setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addGap(25, 25, 25) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(btnReport) .addGap(18, 18, 18) .addComponent(test2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton1))) .addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(38, 38, 38)) .addGroup(jPanel1Layout.createSequentialGroup().addGap(31, 31, 31) .addComponent(dname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))); jTabbedPane1.addTab("Department-Accident Type Analysis", jPanel1); dtPTo.setDateFormatString("d MMM yyyy"); dtPTo.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { dtPToPropertyChange(evt); } }); dtPTo.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { dtPToKeyPressed(evt); } }); jLabel7.setText("To"); dtPFrom.setDateFormatString("d MMM yyyy"); dtPFrom.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent evt) { dtPFromPropertyChange(evt); } }); dtPFrom.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { dtPFromKeyPressed(evt); } }); jLabel8.setText("From"); tblPersonVise.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 } }, new String[] { "Person", "Total No: of Cases", "No:of Cases(Responsible Party)", "Open Cases(Responsible party)", "Open Cases Percentage(Resposible Party)", "No:of Cases(Observer)", "Open Cases(Observer)", "Open Cases Percentage(Observer)" })); jScrollPane2.setViewportView(tblPersonVise); jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/chart-icon.png"))); // NOI18N jLabel10.setText("Graph"); ddGraphPersonWise.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Spread of all Cases among Persons", "Percentage of Cases(As Resposible Parties)", "Percentage of opened cases out of No: of Cases(As Responsible Parties)", "Percentage of closed cases out of No: of Cases(As Responsible Parties)", "Percentage of Cases(As Observer)", "Percentage of opened cases out of No: of Cases(As Observer)", "Percentage of closed cases out of No: of Cases(As Observer)" })); ddGraphPersonWise.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddGraphPersonWiseActionPerformed(evt); } }); jLabel11.setText("Department"); ddDepartment .setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "EHS", "Engineering", "IT" })); ddDepartment.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ddDepartmentActionPerformed(evt); } }); jLabel12.setText("Total reported Cases : "); jLabel13.setText("Number of Open Cases : "); jLabel14.setText("Number of Closed Cases : "); btnPersonGraph.setText("Graph"); btnPersonGraph.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPersonGraphActionPerformed(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().addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel6Layout.createSequentialGroup().addContainerGap().addComponent(jScrollPane2)) .addGroup(jPanel6Layout.createSequentialGroup().addGap(22, 22, 22) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addComponent(jLabel8) .addGap(18, 18, 18) .addComponent(dtPFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( dtPTo, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel6Layout.createSequentialGroup().addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel13).addComponent(jLabel14) .addComponent(jLabel12)).addGap(41, 41, 41) .addGroup(jPanel6Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblPTotal).addComponent(lblPClosed) .addComponent(lblPOpen)))) .addGap(95, 95, 95) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addComponent(jLabel11) .addGap(18, 18, 18) .addComponent(ddDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE) .addComponent(jLabel10).addGap(18, 18, 18).addComponent( ddGraphPersonWise, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel6Layout.createSequentialGroup().addComponent(btnPersonGraph) .addGap(0, 0, Short.MAX_VALUE))))) .addContainerGap())); jPanel6Layout.setVerticalGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup() .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout.createSequentialGroup().addGap(24, 24, 24) .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel7).addComponent(jLabel8) .addComponent(dtPTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( dtPFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(30, 30, 30)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout .createSequentialGroup().addContainerGap() .addGroup(jPanel6Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel6Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10) .addComponent( ddGraphPersonWise, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel6Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ddDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel11))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel12).addComponent(lblPTotal)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13).addComponent(lblPOpen).addComponent(btnPersonGraph)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel14).addComponent(lblPClosed)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 449, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jTabbedPane1.addTab("Person wise Analysis", jPanel6); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1071, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); }// </editor-fold>//GEN-END:initComponents private void btnPersonGraphActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPersonGraphActionPerformed //System.out.println(); if (tblPersonVise.getSelectedRow() != -1) { String username = tablePersonWise.get(tblPersonVise.getSelectedRow()).get(0).toString(); int userID = dbOps.getUserID(username); java.sql.Date from; java.sql.Date to; if (dtPFrom.getDate() == null && dtPTo.getDate() == null) { from = null; to = null; } else if (dtPFrom.getDate() == null) { from = null; to = new java.sql.Date(dtPTo.getDate().getTime()); } else if (dtPTo.getDate() == null) { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = null; } else { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = new java.sql.Date(dtPTo.getDate().getTime()); } Vector<Vector> eachPersonDates = new Vector<Vector>(); eachPersonDates = dbOps.getEachPersonObservation(from, to, userID); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = null; Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); for (Vector<Object> row : eachPersonDates) { start.setTime((Date) row.get(1)); end.setTime((Date) row.get(2)); dataset.addValue(end.get(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR), "First Aid", row.get(0).toString()); } chart = ChartFactory.createLineChart("All Departments VS All Accident Types", "Observation ID", "Days", dataset, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame(username + " Chart", chart); frame.setSize(700, 500); frame.setVisible(true); } else { JOptionPane.showMessageDialog(this, "Please select a person using table!"); } }//GEN-LAST:event_btnPersonGraphActionPerformed private void ddDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddDepartmentActionPerformed Object obj = evt.getSource(); if (obj == ddDepartment) { personWiseTableload(); } }//GEN-LAST:event_ddDepartmentActionPerformed private void ddGraphPersonWiseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddGraphPersonWiseActionPerformed Object obj = evt.getSource(); if (obj == ddGraphPersonWise) { if (ddGraphPersonWise.getSelectedItem().toString().equals("Spread of all Cases among Persons")) { DefaultPieDataset pieDataSet = new DefaultPieDataset(); for (Vector row : tablePersonWise) { pieDataSet.setValue(row.get(0).toString(), Double.parseDouble(row.get(1).toString())); } JFreeChart chart = ChartFactory.createPieChart("Spread of all Cases among Persons", pieDataSet, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame frame = new ChartFrame("Pie Chart", chart); frame.setVisible(true); frame.setSize(700, 500); //System.out.println("aaa"); } else if (ddGraphPersonWise.getSelectedItem().toString() .equals("Percentage of Cases(As Resposible Parties)")) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); for (Vector row : tablePersonWise) {//select the personwise for analysing barDataSet.setValue((Double.parseDouble(row.get(2).toString()) / (int) row.get(1)) * 100, "Percentage of Cases(As Resposible Parties)", row.get(0).toString()); } JFreeChart chart = ChartFactory.createBarChart("Percentage of Cases(As Resposible Parties)", "Person", "Percentage of Cases(As Resposible Parties)", barDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } else if (ddGraphPersonWise.getSelectedItem().toString() .equals("Percentage of opened cases out of No: of Cases(As Responsible Parties)")) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); for (Vector row : tablePersonWise) { barDataSet.setValue((Double.parseDouble(row.get(3).toString()) / (int) row.get(2)) * 100, "Percentage of opened cases out of No: of Cases(As Responsible Parties)", row.get(0).toString()); } JFreeChart chart = ChartFactory.createBarChart( "Percentage of opened cases out of No: of Cases(As Responsible Parties)", "Person", "Percentage of opened cases out of No: of Cases(As Responsible Parties)", barDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } else if (ddGraphPersonWise.getSelectedItem().toString() .equals("Percentage of closed cases out of No: of Cases(As Responsible Parties)")) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); for (Vector row : tablePersonWise) { barDataSet.setValue( (Double.parseDouble(row.get(2).toString()) - (Double.parseDouble(row.get(3).toString())) / (int) row.get(2)) * 100, "Percentage of closed cases out of No: of Cases(As Responsible Parties)", row.get(0).toString()); } JFreeChart chart = ChartFactory.createBarChart( "Percentage of closed cases out of No: of Cases(As Responsible Parties)", "Person", "Percentage of closed cases out of No: of Cases(As Responsible Parties)", barDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } else if (ddGraphPersonWise.getSelectedItem().toString().equals("Percentage of Cases(As Observer)")) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); for (Vector row : tablePersonWise) { barDataSet.setValue((Double.parseDouble(row.get(5).toString()) / (int) row.get(1)) * 100, "Percentage of Cases(As Observer)", row.get(0).toString()); } JFreeChart chart = ChartFactory.createBarChart("Percentage of Cases(As Observer)", "Person", "Percentage of Cases(As Observer)", barDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } else if (ddGraphPersonWise.getSelectedItem().toString() .equals("Percentage of opened cases out of No: of Cases(As Observer)")) { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); for (Vector row : tablePersonWise) { barDataSet.setValue((Double.parseDouble(row.get(6).toString()) / (int) row.get(5)) * 100, "Percentage of Closed cases", row.get(0).toString()); } JFreeChart chart = ChartFactory.createBarChart( "Percentage of opened cases out of No: of Cases(As Observer)", "Person", "Percentage of opened cases out of No: of Cases(As Observer)", barDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } else { DefaultCategoryDataset barDataSet = new DefaultCategoryDataset(); for (Vector row : tablePersonWise) { barDataSet.setValue( ((Double.parseDouble(row.get(5).toString()) - (Double.parseDouble(row.get(6).toString()))) / (int) row.get(5)) * 100, "Percentage of closed cases out of No: of Cases(As Observer)", row.get(0).toString()); } JFreeChart chart = ChartFactory.createBarChart( "Percentage of closed cases out of No: of Cases(As Observer)", "Person", "Percentage of closed cases out of No: of Cases(As Observer)", barDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Bar Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } } }//GEN-LAST:event_ddGraphPersonWiseActionPerformed private void dtPFromKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtPFromKeyPressed //personWiseTableload(); }//GEN-LAST:event_dtPFromKeyPressed private void dtPFromPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dtPFromPropertyChange //personWiseTableload(); }//GEN-LAST:event_dtPFromPropertyChange private void dtPToKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtPToKeyPressed //personWiseTableload(); }//GEN-LAST:event_dtPToKeyPressed private void dtPToPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dtPToPropertyChange //personWiseTableload(); }//GEN-LAST:event_dtPToPropertyChange private void btnReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReportActionPerformed try { String accidentType1 = null, accidentType2 = null, accidentType3 = null, close_p_lti = null, close_p_firstaid = null, close_p_nearmiss = null; String duration_variable_from = null, duration_variable_to = null; //Calculate_Duration d =new Calculate_Duration(); if (ddDTimePeriod.getSelectedItem() == "ALL") { //duration_variable_from= "2005-01-01"; } else if (ddDTimePeriod.getSelectedItem() == "Last Week") { Date[] array = getLastWeek(); duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(array[0]); duration_variable_to = new SimpleDateFormat("yyyy-MM-dd").format(array[1]); } else if (ddDTimePeriod.getSelectedItem() == "Last Month") { Date[] array = getLastMonth(); duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(array[0]); duration_variable_to = new SimpleDateFormat("yyyy-MM-dd").format(array[1]); } else if (ddDTimePeriod.getSelectedItem() == "Last Year") { Date[] array = getLastYear(); duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(array[0]); duration_variable_to = new SimpleDateFormat("yyyy-MM-dd").format(array[1]); } //test2.setText(duration_variable_to); else if (ddDTimePeriod.getSelectedItem() == "This Week") { duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(getThisWeek()); duration_variable_to = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); } else if (ddDTimePeriod.getSelectedItem() == "This Month") { duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(getThisMonth()); duration_variable_to = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); } else if (ddDTimePeriod.getSelectedItem() == "This Year") { duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(getThisYear()); duration_variable_to = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); } else { // duration_variable=advanece_duration_variable; } System.out.println(duration_variable_from = new SimpleDateFormat("yyyy-MM-dd").format(getThisYear())); //departmentID =((Integer)department1.getSelectedIndex()).toString(); CAST(dates AS date) BETWEEN '1/1/2013' and '1/2/2013' //Integer.toString(department1.getSelectedIndex()+1); String departmentName = tableDepartmentAccident.get(tblDepartmentAccident.getSelectedRow()).get(0) .toString(); String departmentID = null; System.out.println(departmentName + "%%%%%%%%%%%%%%%%%%%%%%%%%"); //if(departmentName=="EHS") if ("EHS".equals(departmentName)) { departmentID = "1"; } else if ("IT".equals(departmentName)) { departmentID = "3"; } else if ("Engineering".equals(departmentName)) { departmentID = "2"; } //String query ="select observation.date, observation.departmentID, department.departmentName, observation.observationID, observation.responsiblePartyID, observation.accidentType, observation.zapStatus from observation INNER JOIN department ON (observation.departmentID=department.departmentID) where (observation.accidentType =" + "'" + accidentType1 + "'" + "or observation.accidentType = " + "'" + accidentType2 + "'" + "or observation.accidentType =" + "'" + accidentType3 + "'" + ") and (observation.departmentID =" + "'" + departmentID1+ "'" + "or observation.departmentID = " + "'" + departmentID2 + "'" + "or observation.departmentID =" + "'" + departmentID3 + "'" + ") order by departmentID"; String quary_total_LTI = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " )and (accidentType= " + "'" + "LTI" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_Open_LTI = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " ) and (accidentType= " + "'" + "LTI" + "'" + ") and (zapStatus = " + "'" + "Open" + "'" + ") and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_close_LTI = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " ) and (accidentType= " + "'" + "LTI" + "'" + ") and (zapStatus = " + "'" + "Close" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; //txt1.setText(quary_total_LTI); String quary_total_FirstAid = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " )and (accidentType= " + "'" + "First Aid" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_Open_FirstAid = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " ) and (accidentType= " + "'" + "First Aid" + "'" + ") and (zapStatus = " + "'" + "Open" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_close_FirstAid = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " ) and (accidentType= " + "'" + "First Aid" + "'" + ") and (zapStatus = " + "'" + "Close" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_total_NearMiss = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " )and (accidentType= " + "'" + "Near Miss" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_Open_NearMiss = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " ) and (accidentType= " + "'" + "Near Miss" + "'" + ") and (zapStatus = " + "'" + "Open" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; String quary_close_NearMiss = "select count(*) as x from observation where (observation.departmentID =" + "'" + departmentID + "'" + " ) and (accidentType= " + "'" + "Near Miss" + "'" + ") and (zapStatus = " + "'" + "Close" + "'" + ")and (observation.date between " + "'" + duration_variable_from + "'" + "and" + "'" + duration_variable_to + "'" + " )"; System.out.println("2"); test2.setText(quary_total_NearMiss); Case_Summary count1 = new Case_Summary(); String total_lti = count1.getData(quary_total_LTI); String open_lti = count1.getData(quary_Open_LTI); String close_lti = count1.getData(quary_close_LTI); if (Float.parseFloat(total_lti) == 0) { //float close_precentage_lti = (Float.parseFloat(close_lti)/1)*100; close_p_lti = "0.0 %";//Float.toString(close_precentage_lti).concat(" %"); } else { float close_precentage_lti = (Float.parseFloat(close_lti) / Float.parseFloat(total_lti)) * 100; close_p_lti = Float.toString(close_precentage_lti).concat(" %"); } //view.setText(total_lti); //view2.setText(close_lti); //view3.setText(close_p_lti); String total_firstaid = count1.getData(quary_total_FirstAid); String open_firstaid = count1.getData(quary_Open_FirstAid); String close_firstaid = count1.getData(quary_close_FirstAid); if (Float.parseFloat(total_firstaid) == 0) { //float close_precentage_lti = (Float.parseFloat(close_lti)/1)*100; close_p_firstaid = "0.0 %";//Float.toString(close_precentage_lti).concat(" %"); } else { float close_precentage_firstaid = (Float.parseFloat(close_firstaid) / Float.parseFloat(total_firstaid)) * 100; close_p_firstaid = Float.toString(close_precentage_firstaid).concat(" %"); } System.out.println("4"); String total_nearmiss = count1.getData(quary_total_NearMiss); String open_nearmiss = count1.getData(quary_Open_NearMiss); String close_nearmiss = count1.getData(quary_close_NearMiss); System.out.println("5"); if (Float.parseFloat(total_nearmiss) == 0) { //float close_precentage_lti = (Float.parseFloat(close_lti)/1)*100; close_p_nearmiss = "0.0 %";//Float.toString(close_precentage_lti).concat(" %"); } else { float close_precentage_nearmiss = (Float.parseFloat(close_nearmiss) / Float.parseFloat(total_nearmiss)) * 100; close_p_nearmiss = Float.toString(close_precentage_nearmiss).concat(" %"); } /*view2.setText(open); view3.setText(close); view.setText(quary_total);*/ departmentID = "3"; HashMap param = new HashMap(); param.put("total_nearmiss", total_nearmiss); param.put("open_nearmiss", open_nearmiss); param.put("close_nearmiss", close_nearmiss); param.put("close_p_nearmiss", close_p_nearmiss); param.put("total_lti", total_lti); param.put("open_lti", open_lti); param.put("close_lti", close_lti); param.put("close_p_lti", close_p_lti); param.put("total_firstaid", total_firstaid); param.put("open_firstaid", open_firstaid); param.put("close_firstaid", close_firstaid); param.put("close_p_firstaid", close_p_firstaid); param.put("departmentID", departmentID); param.put("departmentName", departmentName); param.put("duration_variable_from", duration_variable_from); param.put("duration_variable_to", duration_variable_to); Ireport_connection dep = new Ireport_connection( "C:\\Users\\chamod\\Documents\\NetBeansProjects\\GskProject\\src\\report\\Department_vice_Analyse.jasper", param); dep.setVisible(true); } catch (SQLException ex) { //Logger.getLogger(Department_Vice_Analyse.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_btnReportActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed if (tableDepartmentAccident != null) { DefaultPieDataset pieDataSet = new DefaultPieDataset(); Vector<Object> row = tableDepartmentAccident.get(tableDepartmentAccident.size() - 1); pieDataSet.setValue("First Aid", Double.parseDouble(row.get(1).toString())); pieDataSet.setValue("LTI", Double.parseDouble(row.get(2).toString())); pieDataSet.setValue("Near Miss", Double.parseDouble(row.get(3).toString())); JFreeChart chart = ChartFactory.createPieChart("Overrall All Accident Types Spread", pieDataSet, true, true, true); PiePlot p = (PiePlot) chart.getPlot(); ChartFrame frame = new ChartFrame("pie Chart", chart); frame.setVisible(true); frame.setSize(700, 500); } else { JOptionPane.showMessageDialog(this, "Please Filter Data!"); } }//GEN-LAST:event_jButton2ActionPerformed private void btnDAGraphActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDAGraphActionPerformed if (tableDepartmentAccident != null) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); JFreeChart chart = null; if (ddDDepartment.getSelectedIndex() == 0 && ddDAccidentType.getSelectedIndex() == 0) { for (int i = 0; i < tableDepartmentAccident.size() - 1; i++) { Vector<Object> row = tableDepartmentAccident.get(i); dataset.addValue(Double.parseDouble(row.get(1).toString()), "First Aid", row.get(0).toString()); dataset.addValue(Double.parseDouble(row.get(2).toString()), "LTI", row.get(0).toString()); dataset.addValue(Double.parseDouble(row.get(3).toString()), "Near Miss", row.get(0).toString()); } chart = ChartFactory.createBarChart3D("All Departments VS All Accident Types", "Departments", "Accident Types", dataset, PlotOrientation.VERTICAL, false, true, false); } else { String dep = ddDDepartment.getSelectedItem().toString(); String acc = ddDAccidentType.getSelectedItem().toString(); if (ddDDepartment.getSelectedIndex() == 0) { for (int i = 0; i < tableDepartmentAccident.size() - 1; i++) { Vector<Object> row = tableDepartmentAccident.get(i); dataset.addValue(Double.parseDouble(row.get(ddDAccidentType.getSelectedIndex()).toString()), acc, row.get(0).toString()); } chart = ChartFactory.createBarChart3D("All Departments VS " + acc, "Departments", acc, dataset, PlotOrientation.VERTICAL, false, true, false); } else if (ddDAccidentType.getSelectedIndex() == 0) { Vector row = tableDepartmentAccident.get(ddDDepartment.getSelectedIndex() - 1); dataset.addValue(Double.parseDouble(row.get(1).toString()), dep, "First Aid"); dataset.addValue(Double.parseDouble(row.get(2).toString()), dep, "LTI"); dataset.addValue(Double.parseDouble(row.get(3).toString()), dep, "Near Miss"); chart = ChartFactory.createBarChart3D(dep + " Department VS All Accident Types", "Accident Types", dep, dataset, PlotOrientation.VERTICAL, false, true, false); } } CategoryPlot p = chart.getCategoryPlot(); p.setRangeGridlinePaint(Color.BLACK); ChartFrame frame = new ChartFrame("Dual Axis Chart", chart); frame.setSize(700, 500); frame.setVisible(true); } else { JOptionPane.showMessageDialog(this, "Please Filter Data!"); } }//GEN-LAST:event_btnDAGraphActionPerformed private void ddDAccidentTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddDAccidentTypeActionPerformed if (ddDAccidentType.getSelectedIndex() != 0 && ddDDepartment.getSelectedIndex() != 0) { btnDAGraph.setEnabled(false); } else { btnDAGraph.setEnabled(true); } }//GEN-LAST:event_ddDAccidentTypeActionPerformed private void ddDDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddDDepartmentActionPerformed if (ddDAccidentType.getSelectedIndex() != 0 && ddDDepartment.getSelectedIndex() != 0) { btnDAGraph.setEnabled(false); } else { btnDAGraph.setEnabled(true); } }//GEN-LAST:event_ddDDepartmentActionPerformed private void ddDDepartmentMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ddDDepartmentMouseClicked }//GEN-LAST:event_ddDDepartmentMouseClicked private void ddDTimePeriodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ddDTimePeriodActionPerformed Object obj = evt.getSource(); if (obj == ddDTimePeriod) { if (ddDTimePeriod.getSelectedIndex() == 1) { Date[] array = getLastWeek(); if (departmentAccidentTableLoad(array[0], array[1])) { Calendar c = Calendar.getInstance(); c.setTime(array[0]); SimpleDateFormat f = new SimpleDateFormat("MMMMMMM"); lblTime.setText("For Last Week (Week-" + c.get(Calendar.WEEK_OF_MONTH) + " of " + f.format(array[0]) + ")"); dtDAFrom.setDate(null); dtDATo.setDate(null); } else { resetFields(); } } else if (ddDTimePeriod.getSelectedIndex() == 2) { Date[] array = getLastMonth(); if (departmentAccidentTableLoad(array[0], array[1])) { SimpleDateFormat f = new SimpleDateFormat("MMMMMMM"); lblTime.setText("For Last Month (" + f.format(array[0]) + ")"); dtDAFrom.setDate(null); dtDATo.setDate(null); } else { resetFields(); } } else if (ddDTimePeriod.getSelectedIndex() == 3) { Date[] array = getLastYear(); if (departmentAccidentTableLoad(array[0], array[1])) { SimpleDateFormat f = new SimpleDateFormat("yyyy"); lblTime.setText("For Last Year (" + f.format(array[0]) + ")"); dtDAFrom.setDate(null); dtDATo.setDate(null); } else { resetFields(); } } else if (ddDTimePeriod.getSelectedIndex() == 4) { Date from = getThisWeek(); System.out.println(from); Date to = new Date(); if (departmentAccidentTableLoad(from, to)) { Calendar c = Calendar.getInstance(); c.setTime(from); SimpleDateFormat f = new SimpleDateFormat("MMMMMMM"); lblTime.setText( "For This Week (Week-" + c.get(Calendar.WEEK_OF_MONTH) + " of " + f.format(from) + ")"); dtDAFrom.setDate(null); dtDATo.setDate(null); } else { resetFields(); } } else if (ddDTimePeriod.getSelectedIndex() == 5) { Date from = getThisMonth(); Date to = new Date(); if (departmentAccidentTableLoad(from, to)) { SimpleDateFormat f = new SimpleDateFormat("MMMMMMM"); lblTime.setText("For This Month (" + f.format(from) + ")"); dtDAFrom.setDate(null); dtDATo.setDate(null); } else { resetFields(); } } else if (ddDTimePeriod.getSelectedIndex() == 6) { Date from = getThisYear(); Date to = new Date(); if (departmentAccidentTableLoad(from, to)) { SimpleDateFormat f = new SimpleDateFormat("yyyy"); lblTime.setText("For This Year (" + f.format(from) + ")"); dtDAFrom.setDate(null); dtDATo.setDate(null); } else { resetFields(); } } } }//GEN-LAST:event_ddDTimePeriodActionPerformed private void dtDAToKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtDAToKeyPressed // TODO add your handling code here: }//GEN-LAST:event_dtDAToKeyPressed private void dtDAToPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dtDAToPropertyChange // TODO add your handling code here: }//GEN-LAST:event_dtDAToPropertyChange private void dtDAFromKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtDAFromKeyPressed // TODO add your handling code here: }//GEN-LAST:event_dtDAFromKeyPressed private void dtDAFromPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dtDAFromPropertyChange // TODO add your handling code here: }//GEN-LAST:event_dtDAFromPropertyChange private void btnFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFilterActionPerformed if (departmentAccidentTableLoad(dtDAFrom.getDate(), dtDATo.getDate())) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy"); if (dtDAFrom.getDate() == null && dtDATo.getDate() == null) { lblTime.setText("For full Time duration"); } else if (dtDAFrom.getDate() == null) { String t = dateFormat.format(dtDATo.getDate()); lblTime.setText("From Start day To " + t); } else if (dtDATo.getDate() == null) { String f = dateFormat.format(dtDAFrom.getDate()); lblTime.setText("From " + f + " To So far..."); } else { String f = dateFormat.format(dtDAFrom.getDate()); String t = dateFormat.format(dtDATo.getDate()); lblTime.setText(f + " - " + t); } ddDTimePeriod.setSelectedIndex(0); } else { resetFields(); } }//GEN-LAST:event_btnFilterActionPerformed public void resetFields() {//for reset the fields in the text area Vector<String> columnNames = new Vector<String>();// columnNames.add("Department"); columnNames.add("First Aid"); columnNames.add("LTI"); columnNames.add("Near Miss"); columnNames.add("Total"); tblDepartmentAccident.setModel(new DefaultTableModel(null, columnNames)); dtDAFrom.setDate(null); dtDATo.setDate(null); ddDTimePeriod.setSelectedIndex(0); lblOpen.setText(""); lblClosed.setText(""); lblTotal.setText(""); lblTime.setText(""); } public Date[] getLastWeek() {//get the last week start date and the end date //DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy"); Date today = new Date(); Calendar c = Calendar.getInstance(); c.setTime(today); Date start; Date end; if (c.get(Calendar.DAY_OF_WEEK) == 1) { c.add(Calendar.DATE, -7); end = c.getTime(); } else { c.add(Calendar.DATE, -1 * (c.get(Calendar.DAY_OF_WEEK) - 1)); end = c.getTime(); } c.setTime(end); c.add(Calendar.DATE, -6); start = c.getTime(); Date[] array = new Date[2]; array[0] = start; array[1] = end; return array; } public Date[] getLastMonth() {//get the last month start date and the end date Date today = new Date(); Calendar c = Calendar.getInstance(); c.setTime(today); c.add(Calendar.DATE, -1 * c.get(Calendar.DAY_OF_MONTH)); Date[] array = new Date[2]; array[1] = c.getTime(); c.add(Calendar.DATE, 1); c.add(Calendar.MONTH, -1); array[0] = c.getTime(); return array; } public Date[] getLastYear() {//get the last year start date and the end date Date today = new Date(); Calendar c = Calendar.getInstance(); c.setTime(today); c.add(Calendar.DATE, -1 * c.get(Calendar.DAY_OF_YEAR)); Date[] array = new Date[2]; array[1] = c.getTime(); c.add(Calendar.DATE, 1); c.add(Calendar.YEAR, -1); array[0] = c.getTime(); return array; } public Date getThisWeek() {//get the this week start date and today Date today = new Date(); Calendar c = Calendar.getInstance(); c.setTime(today); if (c.get(Calendar.DAY_OF_WEEK) == 1) { c.add(Calendar.DATE, -6); return c.getTime(); } else { c.add(Calendar.DATE, -1 * (c.get(Calendar.DAY_OF_WEEK) - 2)); return c.getTime(); } } public Date getThisMonth() {//get the this month start date and today Date today = new Date(); Calendar c = Calendar.getInstance(); c.setTime(today); c.add(Calendar.DATE, -1 * (c.get(Calendar.DAY_OF_MONTH) - 1)); return c.getTime(); } public Date getThisYear() {//get the this year start date and today Date today = new Date(); Calendar c = Calendar.getInstance(); c.setTime(today); c.add(Calendar.DATE, -1 * (c.get(Calendar.DAY_OF_YEAR) - 1)); return c.getTime(); } void loadFrame() {//load rhe frame in to ArrayList<String> depArray = dbOps.getDepartmentNames(); ddDDepartment.addItem("All"); for (String dep : depArray) { ddDDepartment.addItem(dep); } } public void personWiseTableload() { multiMap = new HashMap<Object, Object[]>(); userList = new ArrayList<User>(); if (ddDepartment.getSelectedIndex() == 0) { userList = dbOps.getUser(); } else { userList = dbOps.getUser(ddDepartment.getSelectedIndex()); } java.sql.Date from; java.sql.Date to; if (dtPFrom.getDate() == null && dtPTo.getDate() == null) { from = null; to = null; } else if (dtPFrom.getDate() == null) { from = null; to = new java.sql.Date(dtPTo.getDate().getTime()); } else if (dtPTo.getDate() == null) { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = null; } else { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = new java.sql.Date(dtPTo.getDate().getTime()); } Vector<String> columnNames = new Vector<String>(); columnNames.addElement("Person"); columnNames.addElement("Total No: of Cases"); columnNames.addElement("No:of Cases(Responsible Party)"); columnNames.addElement("Open Cases(Responsible party)"); columnNames.addElement("Open Cases Percentage(Resposible Party)"); columnNames.addElement("No:of Cases(Observer)"); columnNames.addElement("Open Cases(Observer)"); columnNames.addElement("Open Cases Percentage(Observer)"); if (from != null && to != null) { if (to.after(from)) { tableObservation = dbOps.getAnalyzeObservation(from, to); if (tableObservation.size() > 0) { for (User user : userList) { Object[] array = new Object[6]; array[0] = user.getUsername(); array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; array[5] = 0; multiMap.put(user.getUserID(), array); } for (Vector row : tableObservation) { Object[] arrayRes = multiMap.get(row.get(7)); if (arrayRes != null) { arrayRes[2] = (int) arrayRes[2] + 1; arrayRes[1] = (int) arrayRes[1] + 1; if (row.get(8).equals("Open")) { arrayRes[3] = (int) arrayRes[3] + 1; } } Object[] arrayOb = multiMap.get(row.get(6)); if (arrayOb != null) { arrayOb[4] = (int) arrayOb[4] + 1; arrayOb[1] = (int) arrayOb[1] + 1; if (row.get(8).equals("Open")) { arrayOb[5] = (int) arrayOb[5] + 1; } } } tablePersonWise = new Vector<Vector>(); for (int i = 0; i < multiMap.size(); i++) { Vector<Object> row = new Vector<Object>(); int userID = userList.get(i).getUserID(); row.addElement(multiMap.get(userID)[0]); row.addElement((int) multiMap.get(userID)[2] + (int) multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[2]); row.addElement(multiMap.get(userID)[3]); if ((int) multiMap.get(userID)[2] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[3].toString()) / (int) multiMap.get(userID)[2]) * 100) + "%"); } else { row.addElement(0); } row.addElement(multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[5]); if ((int) multiMap.get(userID)[4] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[5].toString()) / (int) multiMap.get(userID)[4]) * 100) + "%"); } else { row.addElement(0); } tablePersonWise.addElement(row); } tblPersonVise.setModel(new DefaultTableModel(tablePersonWise, columnNames)); } else { JOptionPane.showMessageDialog(this, "There are no observation between above days!"); dtPFrom.setDate(null); dtPTo.setDate(null); } } else { JOptionPane.showMessageDialog(this, "Wrong Date Entry (from date > to date)!"); dtPFrom.setDate(null); dtPTo.setDate(null); } } else { tableObservation = dbOps.getAnalyzeObservation(from, to); if (tableObservation.size() > 0) { for (User user : userList) { Object[] array = new Object[6]; array[0] = user.getUsername(); array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; array[5] = 0; multiMap.put(user.getUserID(), array); } for (Vector row : tableObservation) { Object[] arrayRes = multiMap.get(row.get(7)); if (arrayRes != null) { arrayRes[2] = (int) arrayRes[2] + 1; arrayRes[1] = (int) arrayRes[1] + 1; if (row.get(8).equals("Open")) { arrayRes[3] = (int) arrayRes[3] + 1; } } Object[] arrayOb = multiMap.get(row.get(6)); if (arrayOb != null) { arrayOb[4] = (int) arrayOb[4] + 1; arrayOb[1] = (int) arrayOb[1] + 1; if (row.get(8).equals("Open")) { arrayOb[5] = (int) arrayOb[5] + 1; } } } tablePersonWise = new Vector<Vector>(); for (int i = 0; i < multiMap.size(); i++) { Vector<Object> row = new Vector<Object>(); int userID = userList.get(i).getUserID(); row.addElement(multiMap.get(userID)[0]); row.addElement((int) multiMap.get(userID)[2] + (int) multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[2]); row.addElement(multiMap.get(userID)[3]); if ((int) multiMap.get(userID)[2] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[3].toString()) / (int) multiMap.get(userID)[2]) * 100) + "%"); } else { row.addElement(0); } row.addElement(multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[5]); if ((int) multiMap.get(userID)[4] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[5].toString()) / (int) multiMap.get(userID)[4]) * 100) + "%"); } else { row.addElement(0); } tablePersonWise.addElement(row); } tblPersonVise.setModel(new DefaultTableModel(tablePersonWise, columnNames)); } else { JOptionPane.showMessageDialog(this, "There are no observation between above days!"); dtPFrom.setDate(null); dtPTo.setDate(null); } } } public boolean departmentAccidentTableLoad(Date from1, Date to1) { depHashMap = new HashMap<Object, Object[]>(); ArrayList<Object[]> depNameID = dbOps.getDepartmentNameID(); java.sql.Date from; java.sql.Date to; if (from1 == null && to1 == null) { from = null; to = null; } else if (from1 == null) { from = null; to = new java.sql.Date(to1.getTime()); } else if (to1 == null) { from = new java.sql.Date(from1.getTime()); to = null; } else { from = new java.sql.Date(from1.getTime()); to = new java.sql.Date(to1.getTime()); } Vector<String> columnNames = new Vector<String>(); columnNames.add("Department"); columnNames.add("First Aid"); columnNames.add("LTI"); columnNames.add("Near Miss"); columnNames.add("Open Cases"); columnNames.add("Closed Cases"); columnNames.add("Total"); //int[][] depAccident=new int[3][3]; int DAOpen = 0; int DAClose = 0; int firstAidTotal = 0; int LTITotal = 0; int nearMissTotal = 0; //int openTotal=0; //int closeTotal=0; int totalTotal = 0; if (from != null && to != null) { if (to.after(from) || to.equals(from)) { tableObservation = dbOps.getAnalyzeObservation(from, to); if (tableObservation.size() > 0) { for (Object[] row : depNameID) { Object[] array = new Object[6]; array[0] = row[1]; array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; array[5] = 0; depHashMap.put(row[0], array); } for (Vector row : tableObservation) { Object[] array = depHashMap.get((int) row.get(5)); if (row.get(11).equals("First Aid")) { array[1] = (int) array[1] + 1; firstAidTotal++; } else if (row.get(11).equals("LTI")) { array[2] = (int) array[2] + 1; LTITotal++; } else { array[3] = (int) array[3] + 1; nearMissTotal++; } if (row.get(8).equals("Open")) { array[4] = (int) array[4] + 1; DAOpen++; } else { array[5] = (int) array[5] + 1; DAClose++; } } tableDepartmentAccident = new Vector<Vector>(); for (Object[] array : depNameID) { Vector<Object> row1 = new Vector<Object>(); row1.add(array[1]); row1.add((int) depHashMap.get(array[0])[1]); row1.add((int) depHashMap.get(array[0])[2]); row1.add((int) depHashMap.get(array[0])[3]); row1.add((int) depHashMap.get(array[0])[4]); row1.add((int) depHashMap.get(array[0])[5]); row1.add((int) depHashMap.get(array[0])[1] + (int) depHashMap.get(array[0])[2] + (int) depHashMap.get(array[0])[3]); tableDepartmentAccident.add(row1); } Vector<Object> row1 = new Vector<Object>(); row1.add("Total -->"); row1.add(firstAidTotal); row1.add(LTITotal); row1.add(nearMissTotal); row1.add(DAOpen); row1.add(DAClose); row1.add(firstAidTotal + LTITotal + nearMissTotal); tableDepartmentAccident.add(row1); tblDepartmentAccident.setModel(new DefaultTableModel(tableDepartmentAccident, columnNames)); lblTotal.setText(Integer.toString(DAClose + DAOpen)); lblOpen.setText(Integer.toString(DAOpen)); lblClosed.setText(Integer.toString(DAClose)); return true; } else { JOptionPane.showMessageDialog(this, "There are no observations!"); tableDepartmentAccident = null; return false; } } else { JOptionPane.showMessageDialog(this, "Wrong Date Entry (from date > to date)!"); tableDepartmentAccident = null; return false; } } else { tableObservation = dbOps.getAnalyzeObservation(from, to); if (tableObservation.size() > 0) { for (Object[] row : depNameID) { Object[] array = new Object[6]; array[0] = row[1]; array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; array[5] = 0; depHashMap.put(row[0], array); } for (Vector row : tableObservation) { Object[] array = depHashMap.get((int) row.get(5)); if (row.get(11).equals("First Aid")) { array[1] = (int) array[1] + 1; firstAidTotal++; } else if (row.get(11).equals("LTI")) { array[2] = (int) array[2] + 1; LTITotal++; } else { array[3] = (int) array[3] + 1; nearMissTotal++; } if (row.get(8).equals("Open")) { array[4] = (int) array[4] + 1; DAOpen++; } else { array[5] = (int) array[5] + 1; DAClose++; } } tableDepartmentAccident = new Vector<Vector>(); for (Object[] array : depNameID) { Vector<Object> row1 = new Vector<Object>(); row1.add(array[1]); row1.add((int) depHashMap.get(array[0])[1]); row1.add((int) depHashMap.get(array[0])[2]); row1.add((int) depHashMap.get(array[0])[3]); row1.add((int) depHashMap.get(array[0])[4]); row1.add((int) depHashMap.get(array[0])[5]); row1.add((int) depHashMap.get(array[0])[1] + (int) depHashMap.get(array[0])[2] + (int) depHashMap.get(array[0])[3]); tableDepartmentAccident.add(row1); } Vector<Object> row1 = new Vector<Object>(); row1.add("Total -->"); row1.add(firstAidTotal); row1.add(LTITotal); row1.add(nearMissTotal); row1.add(DAOpen); row1.add(DAClose); row1.add(firstAidTotal + LTITotal + nearMissTotal); tableDepartmentAccident.add(row1); tblDepartmentAccident.setModel(new DefaultTableModel(tableDepartmentAccident, columnNames)); lblTotal.setText(Integer.toString(DAClose + DAOpen)); lblOpen.setText(Integer.toString(DAOpen)); lblClosed.setText(Integer.toString(DAClose)); return true; } else { JOptionPane.showMessageDialog(this, "There are no observations!"); tableDepartmentAccident = null; return false; } } } /** * @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(Analyze.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Analyze.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Analyze.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Analyze.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 Analyze().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnDAGraph; private javax.swing.JButton btnFilter; private javax.swing.JButton btnPersonGraph; private javax.swing.JButton btnReport; private javax.swing.JComboBox ddDAccidentType; private javax.swing.JComboBox ddDDepartment; private javax.swing.JComboBox ddDTimePeriod; private javax.swing.JComboBox ddDepartment; private javax.swing.JComboBox ddGraphPersonWise; private javax.swing.JTextField dname; private com.toedter.calendar.JDateChooser dtDAFrom; private com.toedter.calendar.JDateChooser dtDATo; private com.toedter.calendar.JDateChooser dtPFrom; private com.toedter.calendar.JDateChooser dtPTo; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel23; private javax.swing.JLabel jLabel24; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel6; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JSeparator jSeparator1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JLabel lblClosed; private javax.swing.JLabel lblOpen; private javax.swing.JLabel lblPClosed; private javax.swing.JLabel lblPOpen; private javax.swing.JLabel lblPTotal; private javax.swing.JLabel lblTime; private javax.swing.JLabel lblTotal; private javax.swing.JTable tblDepartmentAccident; private javax.swing.JTable tblPersonVise; private javax.swing.JTextField test2; // End of variables declaration//GEN-END:variables }