/*
 * 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 proj;

import java.sql.*;
/**
 *
 * @author aaditya
 */
public class Analyze extends javax.swing.JFrame {

    /**
     * Creates new form Analyze
     */
    private static final String USERNAME="root";
    private static final String PASSWORD="1234";
    private static final String CONN_STRING="jdbc:mysql://localhost:3306/time_analyzer?autoReconnect=true&useSSL=false";
    public String emp_id_val;
    public Analyze() {
        initComponents();
    }
    private String[][] date_log_empid =new String[1000][2];
    /**
     * 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() {

        Start = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        most_eff_date = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Start.setText("Connect");
        Start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StartActionPerformed(evt);
            }
        });

        jLabel1.setText("Most Efficient Date");

        most_eff_date.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                most_eff_dateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(220, 220, 220)
                        .addComponent(Start))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel1)
                        .addGap(38, 38, 38)
                        .addComponent(most_eff_date, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(124, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(Start)
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(most_eff_date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(338, Short.MAX_VALUE))
        );

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

    private void StartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartActionPerformed
                // connect to date_log table for all purposes
        Connection conn = null;
        try{
            conn = DriverManager.getConnection(CONN_STRING,USERNAME,PASSWORD);
            Statement stmt =(Statement) conn.createStatement();
            String print_name;
            System.out.println("This"+emp_id_val);
            print_name = "SELECT date,hours_worked FROM date_log where emp_id='"+emp_id_val+"';";
            ResultSet rs = stmt.executeQuery(print_name);
            int i=0;
            while(rs.next()){
                date_log_empid[i][0]=(rs.getString("date"));
                date_log_empid[i][1]=(rs.getString("hours_worked"));
                i++;
            }
            
            for(int j=0;j<i;j++) 
                System.out.println(date_log_empid[j][0]+"  "+date_log_empid[j][1]);
            // array stored . Now lets do our things.
            most_eff_date.setText(most_eff_dt());
           
        }
            
        catch(SQLException e){
            System.out.println("Didnot happen"+e);
        }
    }//GEN-LAST:event_StartActionPerformed
    private String most_eff_dt(){
        int max=0;
        int index=0;
        for(int i=0;i<this.date_log_empid.length;i++){
            if(Integer.parseInt(date_log_empid[i][1])>max){
                max=Integer.parseInt(date_log_empid[i][1]);
                index=i;
            }
        }
        return date_log_empid[index][0];
    }
    private void most_eff_dateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_most_eff_dateActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_most_eff_dateActionPerformed

    /**
     * @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 Start;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField most_eff_date;
    // End of variables declaration//GEN-END:variables
}

@@ -4503,16 +4503,29 @@
 things.%0A
+            %0A
         
@@ -4562,16 +4562,17 @@
 _eff_dt(
+i
 ));%0A    
@@ -4768,16 +4768,23 @@
 _eff_dt(
+int len
 )%7B%0A     
@@ -4844,34 +4844,11 @@
 0;i%3C
-this.date_log_empid.length
+len
 ;i++

add new fucntionalities . will experiment now