import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; import java.sql.*; import java.lang.* ; public class duration extends Frame implements ActionListener { public Toolkit tk; public Image img; public TextField tf_date; public Panel Panel1; public Label lbl_durationcode1; public TextField tf_durationcode1; public Button but_retrieve; public Panel Panel2; public Label lbl_durationcode; public TextField tf_durationcode; public Label lbl_fromdate; public TextField tf_fromdate; public Label lbl_todate; public TextField tf_todate; public Button but_first; public Button but_previous; public Button but_next; public Button but_last; public Label lbl_message; public TextArea ta_message; public Button but_reset; public Button but_add; public Button but_delete; public Button but_update; public Button but_help; public Button but_exit; // public Connection con; public String s1,s2,s3,sqlstmt; public int i,ret; public duration(Connection c) { con = c; setResizable(false); setForeground(Color.black); //setBackground(Color.lightGray); setBackground(new Color(255,255,210)); setTitle("Duration Information"); setLayout(null); tk = getToolkit(); img = tk.getImage("air.gif"); tf_date = new TextField(""); Panel1 = new Panel(); Panel1.setLayout(null); Panel1.setForeground(Color.black); Panel1.setBackground(Color.gray); lbl_durationcode1 = new Label("Duration Code",Label.LEFT); tf_durationcode1 = new TextField(""); but_retrieve = new Button("Retrieve"); Panel2 = new Panel(); Panel2.setLayout(null); Panel2.setForeground(Color.black); Panel2.setBackground(Color.gray); lbl_durationcode = new Label("Duration Code",Label.LEFT); tf_durationcode = new TextField(""); lbl_fromdate = new Label("From Date",Label.LEFT); tf_fromdate = new TextField(""); lbl_todate = new Label("To Date",Label.LEFT); tf_todate = new TextField(""); but_first = new Button("First"); but_previous = new Button("Previous"); but_next = new Button("Next"); but_last = new Button("Last"); but_reset = new Button("Reset"); but_add = new Button("Add"); but_delete = new Button("Delete"); but_update = new Button("Update"); but_help = new Button("Help"); but_exit = new Button("Exit"); lbl_message = new Label("MESSAGE / ACTION / ERROR",Label.LEFT); ta_message = new TextArea(""); // set date & time tf_date.setText(Validate.getDate()); // Add()s add(tf_date); add(Panel1); Panel1.add(lbl_durationcode1); Panel1.add(tf_durationcode1); Panel1.add(but_retrieve); add(Panel2); Panel2.add(lbl_durationcode); Panel2.add(tf_durationcode); Panel2.add(lbl_fromdate); Panel2.add(tf_fromdate); Panel2.add(tf_todate); Panel2.add(lbl_todate); add(but_first); add(but_previous); add(but_next); add(but_last); add(lbl_message); add(ta_message); add(but_reset); add(but_add); add(but_delete); add(but_update); add(but_help); add(but_exit); // Events add but_retrieve. addActionListener(this); but_first. addActionListener(this); but_previous. addActionListener(this); but_next. addActionListener(this); but_last. addActionListener(this); but_reset. addActionListener(this); but_add. addActionListener(this); but_delete. addActionListener(this); but_update. addActionListener(this); but_help. addActionListener(this); but_exit. addActionListener(this); // InitialPosition setBounds(0,0,800,600); tf_date.setBounds (580,100,215,25); Panel1.setBounds (148,141,506,72); lbl_durationcode1.setBounds (102,27,119,19); tf_durationcode1.setBounds (221,21,70,27); but_retrieve.setBounds (332,25,75,25); Panel2.setBounds (148,239,504,115); lbl_durationcode.setBounds (129,12,106,19); tf_durationcode.setBounds (257,12,60,27); lbl_fromdate.setBounds (154,46,93,19); tf_fromdate.setBounds (257,46,121,27); lbl_todate.setBounds (171,80,79,19); tf_todate.setBounds (257,80,121,27); but_first.setBounds (90,392,75,25); but_previous.setBounds (90,418,75,25); but_next.setBounds (90,444,75,25); but_last.setBounds (90,470,75,25); ta_message.setBounds (210,395,384,101); lbl_message.setBounds (210,371,198,19); but_reset.setBounds (643,395,75,25); but_add.setBounds (643,421,75,25); but_delete.setBounds (643,447,75,25); but_update.setBounds (643,473,75,25); but_help.setBounds (320,507,75,25); but_exit.setBounds (401,507,75,25); // enable/disable buttons but_help.setVisible(false); tf_date.setEnabled(false); but_delete.setEnabled(false); ta_message.setEditable(false); // focus this.requestFocus(); } //end of constructor public void paint(Graphics g) { g.drawImage(img,0,45,this); } // end of paint public void actionPerformed(ActionEvent e) { if(e.getSource()==but_exit) { this.dispose(); } // end of exit if(e.getSource()==but_retrieve) { try { ta_message.setText("ACTION: Retrieving record ..."); i = Validate.stringToInt( tf_durationcode1.getText() ); CallableStatement cstmt = con.prepareCall( "{call retrieve_duration(?,?,?,?)}" ); cstmt.registerOutParameter(2,4); // integer cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.setInt(1,i); cstmt.executeUpdate(); i = cstmt.getInt(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s2 = Validate.stringSQLDateToString(s2); s3 = Validate.stringSQLDateToString(s3); tf_durationcode.setText( new Integer(i).toString() ); tf_fromdate .setText(s2); tf_todate .setText(s3); tf_durationcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Record does not exist / Incorrect data entered / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); tf_durationcode.setEnabled(true); return; } }// end of but_retrieve if(e.getSource()==but_add) { try { ta_message.setText("ACTION: Adding new record ..."); getInput(); CallableStatement cstmt = con.prepareCall( "{call insert_duration(?,?,?)}" ); cstmt.setInt(1,i); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.executeUpdate(); ta_message.setText("ACTION: Record added."); } catch(Exception er) { ta_message.setText ("ERROR: Incorrect data entered / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } } // end of but_add if(e.getSource()==but_update) { try { ta_message.setText("ACTION: Updating record..."); getInput(); CallableStatement cstmt = con.prepareCall( "{call update_duration(?,?,?)}"); cstmt.setInt(1,i); cstmt.setString(2,s2); cstmt.setString(3,s3); cstmt.executeUpdate(); ta_message.setText("ACTION: Record updated."); } catch(Exception er) { ta_message.setText ("ERROR: Incorrect data entered / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); } }// end of but_update if(e.getSource()==but_reset) { tf_durationcode.setEnabled(true); tf_durationcode1.setText(""); tf_durationcode.setText(""); tf_fromdate.setText(""); tf_todate.setText(""); ta_message.setText(""); tf_durationcode.requestFocus(); } // end of reset if(e.getSource()==but_first) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call first_duration(?,?,?)}" ); cstmt.registerOutParameter(1,4); // integer cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); i = cstmt.getInt(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); s2 = Validate.stringSQLDateToString(s2); s3 = Validate.stringSQLDateToString(s3); tf_durationcode1.setText( new Integer(i).toString() ); tf_durationcode .setText( new Integer(i).toString() ); tf_fromdate .setText(s2); tf_todate .setText(s3); tf_durationcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Record does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_first if(e.getSource()==but_last) { try { ta_message.setText("ACTION: Retrieving record ..."); CallableStatement cstmt = con.prepareCall( "{call last_duration(?,?,?)}" ); cstmt.registerOutParameter(1,4); // integer cstmt.registerOutParameter(2,12); // string cstmt.registerOutParameter(3,12); // string cstmt.executeUpdate(); i = cstmt.getInt(1); s2 = cstmt.getString(2); s3 = cstmt.getString(3); s2 = Validate.stringSQLDateToString(s2); s3 = Validate.stringSQLDateToString(s3); tf_durationcode1.setText( new Integer(i).toString() ); tf_durationcode.setText( new Integer(i).toString() ); tf_fromdate .setText(s2); tf_todate .setText(s3); tf_durationcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Record does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_last if(e.getSource()==but_previous) { try { ta_message.setText("ACTION: Retrieving record ..."); i = Validate.stringToInt( tf_durationcode.getText() ); CallableStatement cstmt = con.prepareCall( "{call previous_duration(?,?,?,?)}" ); cstmt.registerOutParameter(2,4); // integer cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.setInt(1,i); cstmt.executeUpdate(); i = cstmt.getInt(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s2 = Validate.stringSQLDateToString(s2); s3 = Validate.stringSQLDateToString(s3); tf_durationcode1.setText( new Integer(i).toString() ); tf_durationcode.setText( new Integer(i).toString() ); tf_fromdate .setText(s2); tf_todate .setText(s3); tf_durationcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Record does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_previous if(e.getSource()==but_next) { try { ta_message.setText("ACTION: Retrieving record ..."); i = Validate.stringToInt( tf_durationcode.getText() ); CallableStatement cstmt = con.prepareCall( "{call next_duration(?,?,?,?)}" ); cstmt.registerOutParameter(2,4); // integer cstmt.registerOutParameter(3,12); // string cstmt.registerOutParameter(4,12); // string cstmt.setInt(1,i); cstmt.executeUpdate(); i = cstmt.getInt(2); s2 = cstmt.getString(3); s3 = cstmt.getString(4); s2 = Validate.stringSQLDateToString(s2); s3 = Validate.stringSQLDateToString(s3); tf_durationcode1.setText( new Integer(i).toString() ); tf_durationcode.setText( new Integer(i).toString() ); tf_fromdate .setText(s2); tf_todate .setText(s3); tf_durationcode.setEnabled(false); ta_message.setText("ACTION: Record retrieved."); } catch(Exception er) { ta_message.setText ("ERROR: Record does not exist / Database error \n"); ta_message.append ("EXCEPTION:" + "[" + er + "]" + "\n"); ta_message.append ("SOLUTION: " + "For more details kindly refer Help "); return; } }// end of but_next }// action performed public static void main(String args[]) { } // end main public boolean getInput() throws Exception { s1 = tf_durationcode.getText(); s2 = tf_fromdate.getText(); s3 = tf_todate.getText(); if ( (s1 == "") | (s2 == "") | (s3 == "") ) { return false; } else { i = Validate.stringToInt(s1); s2 = Validate.stringToSQLDateString(s2); s3 = Validate.stringToSQLDateString(s3); return true; } }// end of getInput } // end class