TimeInOut2.java Source code

Java tutorial

Introduction

Here is the source code for TimeInOut2.java

Source

import java.awt.Color;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/*
 * 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 Kenneth
 */
public class TimeInOut2 extends javax.swing.JFrame {

    private String file;
    private int numberOfRows = 0;
    private SimpleDateFormat initFormat = new SimpleDateFormat("hh:mm a");
    private Connection connection;
    private String username = "root";
    private String password = "";

    /**
     * Creates new form TimeInOut2
     */
    public TimeInOut2() {
        initComponents();
        this.setIconImage(
                Toolkit.getDefaultToolkit().getImage(getClass().getResource("icons/Backup and Recovery.png")));
        insertPanel.setVisible(false);
        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost/181nprdb", username, password);
        } catch (ClassNotFoundException | SQLException ex) {
            //            Logger.getLogger(TimeInOut.class.getName()).log(Level.SEVERE, null, ex);
            new MessageDialog().error(this, ex.getMessage());
        }
    }

    /**
     * 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() {

        chooser = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        valid = new javax.swing.JPanel();
        fileName = new javax.swing.JTextField();
        choose = new javax.swing.JButton();
        checkup = new javax.swing.JButton();
        statusLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        logs = new javax.swing.JTextArea();
        insertPanel = new javax.swing.JPanel();
        insert = new javax.swing.JButton();
        date = new datechooser.beans.DateChooserCombo();
        statusBar = new javax.swing.JProgressBar();
        jButton1 = new javax.swing.JButton();

        chooser.setControlButtonsAreShown(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Rondalo", 1, 18)); // NOI18N
        jLabel1.setText("TIME IN/OUT");

        valid.setBackground(new java.awt.Color(255, 255, 255));
        valid.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Validate",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rondalo", 0, 12))); // NOI18N

        fileName.setEditable(false);
        fileName.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N
        fileName.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                fileNameCaretUpdate(evt);
            }
        });

        choose.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N
        choose.setText("Choose File");
        choose.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        choose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chooseActionPerformed(evt);
            }
        });

        checkup.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N
        checkup.setText("Start Checkup");
        checkup.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        checkup.setEnabled(false);
        checkup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkupActionPerformed(evt);
            }
        });

        logs.setEditable(false);
        logs.setColumns(20);
        logs.setLineWrap(true);
        logs.setRows(5);
        logs.setWrapStyleWord(true);
        logs.setBorder(javax.swing.BorderFactory.createTitledBorder(
                javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), "Logs",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rondalo", 0, 11))); // NOI18N
        jScrollPane1.setViewportView(logs);

        javax.swing.GroupLayout validLayout = new javax.swing.GroupLayout(valid);
        valid.setLayout(validLayout);
        validLayout.setHorizontalGroup(validLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(validLayout.createSequentialGroup().addContainerGap().addGroup(validLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1)
                        .addGroup(validLayout.createSequentialGroup()
                                .addGroup(validLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(validLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                                .addComponent(fileName, javax.swing.GroupLayout.PREFERRED_SIZE, 327,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(8, 8, 8)
                                .addGroup(validLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(checkup, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(choose, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addContainerGap()));
        validLayout.setVerticalGroup(validLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(validLayout.createSequentialGroup().addContainerGap()
                        .addGroup(validLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(fileName, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(choose))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(validLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(checkup, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(statusLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        insertPanel.setBackground(new java.awt.Color(255, 255, 255));
        insertPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Insert",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Rondalo", 0, 12))); // NOI18N

        insert.setFont(new java.awt.Font("Rondalo", 0, 12)); // NOI18N
        insert.setText("Start Inserting");
        insert.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        insert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertActionPerformed(evt);
            }
        });

        date.setCurrentView(new datechooser.view.appearance.AppearancesList("Light",
                new datechooser.view.appearance.ViewAppearance("custom",
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0),
                                new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0),
                                new java.awt.Color(0, 0, 255), true, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 255),
                                new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11),
                                new java.awt.Color(128, 128, 128), new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.LabelPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0),
                                new java.awt.Color(0, 0, 255), false, true,
                                new datechooser.view.appearance.swing.LabelPainter()),
                        new datechooser.view.appearance.swing.SwingCellAppearance(
                                new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 11), new java.awt.Color(0, 0, 0),
                                new java.awt.Color(255, 0, 0), false, false,
                                new datechooser.view.appearance.swing.ButtonPainter()),
                        (datechooser.view.BackRenderer) null, false, true)));
        date.setNothingAllowed(false);
        date.setFormat(2);
        date.setBehavior(datechooser.model.multiple.MultyModelBehavior.SELECT_SINGLE);

        statusBar.setStringPainted(true);

        javax.swing.GroupLayout insertPanelLayout = new javax.swing.GroupLayout(insertPanel);
        insertPanel.setLayout(insertPanelLayout);
        insertPanelLayout.setHorizontalGroup(insertPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, insertPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(statusBar, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(insertPanelLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                        .addComponent(date, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(insert)))
                        .addContainerGap()));
        insertPanelLayout.setVerticalGroup(insertPanelLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(insertPanelLayout.createSequentialGroup().addContainerGap()
                        .addComponent(statusBar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(insertPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(insert).addComponent(date, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Back.png"))); // NOI18N
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton1))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(valid, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(insertPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addContainerGap()))));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabel1))
                                .addComponent(jButton1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(valid, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(insertPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE));

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        new Home().setVisible(true);
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void chooseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseActionPerformed
        // TODO add your handling code here:
        FileFilter filter = new FileNameExtensionFilter("Excel files", "xls", "xlsx");
        chooser.setFileFilter(filter);
        chooser.showOpenDialog(null);
        if (chooser.getSelectedFile() != null) {
            fileName.setText(chooser.getSelectedFile().getAbsolutePath() + " ");
            if (file != null && !file.equals(chooser.getSelectedFile())) {
                logs.setText("");
                insertPanel.setVisible(false);
            }
            file = chooser.getSelectedFile().toString();
        }
    }//GEN-LAST:event_chooseActionPerformed

    private void fileNameCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_fileNameCaretUpdate
        // TODO add your handling code here:
        if (fileName.getText().trim().isEmpty()) {
            checkup.setEnabled(false);
        } else {
            checkup.setEnabled(true);
        }
    }//GEN-LAST:event_fileNameCaretUpdate

    private void checkupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkupActionPerformed
        // TODO add your handling code here:
        numberOfRows = 0;
        checkFile();
    }//GEN-LAST:event_checkupActionPerformed

    private void insertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertActionPerformed
        // TODO add your handling code here:
        PreparedStatement preparedStatement;

        try {

            FileInputStream fis = new FileInputStream(new File(file));
            XSSFWorkbook workbook = new XSSFWorkbook(fis);
            XSSFSheet sheet = workbook.getSheetAt(0);

            Iterator<Row> rowIterator = sheet.iterator();
            boolean isSuccessful = true;
            while (rowIterator.hasNext()) {

                statusBar.setValue(statusBar.getValue() + (int) (100 / numberOfRows));
                statusBar.update(statusBar.getGraphics());
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    Logger.getLogger(TimeInOut2.class.getName()).log(Level.SEVERE, null, ex);
                }

                Row row = rowIterator.next();
                Iterator<Cell> cellIterator = row.cellIterator();
                preparedStatement = connection.prepareStatement(
                        "INSERT INTO logs (logsDate,logsTime,logsStatus,residentIdnum) VALUES (?,?,?,?)");

                java.util.Date utilDate = date.getDateFormat().parse(date.getText());
                String formattedDate = new SimpleDateFormat("yyyy-MM-dd").format(utilDate);
                java.sql.Date sqlDate = new java.sql.Date(
                        new SimpleDateFormat("yyyy-MM-dd").parse(formattedDate).getTime());
                preparedStatement.setDate(1, sqlDate);

                preparedStatement.setInt(4, (int) cellIterator.next().getNumericCellValue());

                java.util.Date utilTime = cellIterator.next().getDateCellValue();
                String formattedTime = new SimpleDateFormat("HH:mm:ss").format(utilTime);
                java.sql.Time sqlTime = new java.sql.Time(
                        new SimpleDateFormat("HH:mm:ss").parse(formattedTime).getTime());
                preparedStatement.setTime(2, sqlTime);

                preparedStatement.setString(3, cellIterator.next().getStringCellValue());

                if (preparedStatement.execute()) {
                    isSuccessful = false;
                    break;
                }
            }
            statusBar.setValue(100);
            statusBar.update(statusBar.getGraphics());

            fis.close();
            if (isSuccessful) {
                new MessageDialog().successful(this);
                insert.setEnabled(false);
            } else {
                new MessageDialog().unsuccessful(this);
            }
        } catch (FileNotFoundException ex) {
            //            Logger.getLogger(TimeInOut2.class.getName()).log(Level.SEVERE, null, ex);
            new MessageDialog().error(this, ex.getMessage());
        } catch (IOException ex) {
            //            Logger.getLogger(TimeInOut2.class.getName()).log(Level.SEVERE, null, ex);
            new MessageDialog().error(this, ex.getMessage());
        } catch (SQLException | ParseException ex) {
            //            Logger.getLogger(TimeInOut2.class.getName()).log(Level.SEVERE, null, ex);
            new MessageDialog().error(this, ex.getMessage());
        }
    }//GEN-LAST:event_insertActionPerformed

    private void checkFile() {
        try {

            FileInputStream fis = new FileInputStream(new File(file));
            XSSFWorkbook workbook = new XSSFWorkbook(fis);
            XSSFSheet sheet = workbook.getSheetAt(0);

            boolean readyToSave = true;
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) {
                numberOfRows++;
                Row row = rowIterator.next();
                Iterator<Cell> cellIterator = row.cellIterator();
                if (!idValidator(cellIterator.next(), numberOfRows)
                        | !timeValidator(cellIterator.next(), numberOfRows)
                        | !statusValidator(cellIterator.next(), numberOfRows)) {
                    readyToSave = false;
                    logs.append("Problem(s) encountered at row " + numberOfRows + ".\n");
                }
            }
            if (readyToSave) {
                insertPanel.setVisible(readyToSave);
                logs.append("File ready to be inserted/saved.");
            } else {
                logs.append("Please fix the problems(s) first to proceed.");
            }
            //                statusLabel.setText("Finished");
            fis.close();
        } catch (FileNotFoundException ex) {
            //            Logger.getLogger(TimeInOut2.class.getName()).log(Level.SEVERE, null, ex);
            new MessageDialog().error(this, ex.getMessage());
        } catch (IOException ex) {
            //            Logger.getLogger(TimeInOut2.class.getName()).log(Level.SEVERE, null, ex);
            new MessageDialog().error(this, ex.getMessage());
        }
    }

    private boolean idValidator(Cell id, int currentRow) {
        try {
            id.getNumericCellValue();
        } catch (IllegalStateException ex) {
            logs.append("ID at row " + currentRow + " is not Valid.\n");
            return false;
        }
        return true;
    }

    private boolean timeValidator(Cell time, int currentRow) {
        try {
            initFormat.format(time.getDateCellValue());
        } catch (Exception ex) {
            logs.append("Time format at row " + currentRow + " is not Valid.\n");
            return false;
        }
        return true;
    }

    private boolean statusValidator(Cell status, int currentRow) {
        try {
            if (status.getStringCellValue().equals("IN") || status.getStringCellValue().equals("OUT")) {
                return true;
            } else {
                logs.append("Status at row " + currentRow + " is not Valid.\n");
                return false;
            }
        } catch (Exception ex) {
            logs.append("Status at row " + currentRow + " is not Valid.\n");
            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(TimeInOut2.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TimeInOut2.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TimeInOut2.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TimeInOut2.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 TimeInOut2().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton checkup;
    private javax.swing.JButton choose;
    private javax.swing.JFileChooser chooser;
    private datechooser.beans.DateChooserCombo date;
    private javax.swing.JTextField fileName;
    private javax.swing.JButton insert;
    private javax.swing.JPanel insertPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea logs;
    private javax.swing.JProgressBar statusBar;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JPanel valid;
    // End of variables declaration//GEN-END:variables
}