Puka - Software for Detection of Breaths in Strain Gauge Recordings 1.0.0
(30,799 bytes)
/*
* AddSession.java
*
* Created on April 25, 2002, 10:33 AM
*/
package subjectData;
/**
*
* @author Joset A. Etzel
*/
import subjectData.*; import java.sql.*; import java.awt.event.*; import javax.swing.*; import java.io.File;
public class AddSession extends javax.swing.JInternalFrame {
Connection conData; Statement stmSQL;
private boolean bolAddingNew = false;
public AddSession() { /** Creates new form AddSession */
initComponents();
try { Class.forName("org.gjt.mm.mysql.Driver");
conData = SubjectData.getDatabaseConnection(); //gets connection to the correct database
} catch (Exception e) { e.printStackTrace(); }
FillComboBox(); //call sub to put the subject's names in the combo box
}
private void FillComboBox() {
//load the form after filling cboSubject & cboExperimenter
String strNames = ""; int intSubID = 0; String strTemp = "";
cboSubject.removeAllItems(); cboSubject.addItem("");
cboExperimenter.removeAllItems(); cboExperimenter.addItem("");
try {
stmSQL = conData.createStatement(); //stmSQL is global - have to get it ready
ResultSet rssSubjects = stmSQL.executeQuery("SELECT subID, PPG, firstName, middleInitial, lastName FROM subject ORDER BY lastName, PPG");
while(rssSubjects.next()) { //fill up cboSubject w/subject names & PPG numbers
strTemp = rssSubjects.getString("PPG");
if ( strTemp.equals("") == false ) { strNames = rssSubjects.getInt("subID") + ": " + strTemp; }
else { strNames = rssSubjects.getInt("subID") + ": " + rssSubjects.getString("lastName") + ", " + rssSubjects.getString("firstName") + " " + rssSubjects.getString("middleInitial") + "."; }
cboSubject.addItem(strNames); }
} catch(java.sql.SQLException e) { e.printStackTrace(); }
try { //load into cboExperimenter
stmSQL = conData.createStatement();
ResultSet rssSubjects = stmSQL.executeQuery("SELECT boxChoice FROM comboBoxes WHERE boxID = 'Experimenter' ORDER BY boxChoice");
while(rssSubjects.next()) { cboExperimenter.addItem(rssSubjects.getString("boxChoice")); }
} catch(java.sql.SQLException e) { e.printStackTrace(); }
try { //load into cboType
stmSQL = conData.createStatement();
ResultSet rssSubjects = stmSQL.executeQuery("SELECT boxChoice FROM comboBoxes WHERE boxID = 'ExperimentType' ORDER BY boxChoice");
while(rssSubjects.next()) { cboType.addItem(rssSubjects.getString("boxChoice")); }
} catch(java.sql.SQLException e) { e.printStackTrace(); }
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
java.awt.GridBagConstraints gridBagConstraints;
lblSubject = new javax.swing.JLabel();
cboSubject = new javax.swing.JComboBox();
jLabel17 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
txtComment = new javax.swing.JTextArea();
cmdOKClose = new javax.swing.JButton();
cboExperimenter = new javax.swing.JComboBox();
cmdAdd = new javax.swing.JButton();
cmdDelete = new javax.swing.JButton();
jSeparator3 = new javax.swing.JSeparator();
jLabel21 = new javax.swing.JLabel();
cmdClose2 = new javax.swing.JButton();
jScrollPane3 = new javax.swing.JScrollPane();
lstSessions = new javax.swing.JList();
lblType = new javax.swing.JLabel();
cboType = new javax.swing.JComboBox();
txtDate = new javax.swing.JTextField();
cmdEditData = new javax.swing.JButton();
getContentPane().setLayout(new java.awt.GridBagLayout());
setClosable(true);
setIconifiable(true);
setMaximizable(true);
setResizable(true);
setTitle("Work with experiment sessions");
setMinimumSize(new java.awt.Dimension(0, 0));
setPreferredSize(new java.awt.Dimension(800, 500));
lblSubject.setText("select subject:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.ipadx = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
getContentPane().add(lblSubject, gridBagConstraints);
cboSubject.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboSubjectItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.ipadx = 2;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
getContentPane().add(cboSubject, gridBagConstraints);
jLabel17.setText("session date:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(jLabel17, gridBagConstraints);
jLabel18.setFont(new java.awt.Font("Dialog", 3, 12));
jLabel18.setText("(yyyy-mm-dd format)");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.ipadx = 2;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(jLabel18, gridBagConstraints);
jLabel19.setText("experimenter:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(jLabel19, gridBagConstraints);
jLabel20.setText("comment:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 7;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
getContentPane().add(jLabel20, gridBagConstraints);
txtComment.setFont(new java.awt.Font("Dialog", 0, 10));
txtComment.setLineWrap(true);
txtComment.setRows(10);
txtComment.setWrapStyleWord(true);
txtComment.setBorder(new javax.swing.border.EtchedBorder());
txtComment.setMinimumSize(new java.awt.Dimension(400, 150));
txtComment.setPreferredSize(new java.awt.Dimension(400, 150));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 7;
gridBagConstraints.gridwidth = 4;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
getContentPane().add(txtComment, gridBagConstraints);
cmdOKClose.setMnemonic('S');
cmdOKClose.setText("Save");
cmdOKClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdOKCloseActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 8;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
getContentPane().add(cmdOKClose, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 5;
gridBagConstraints.ipady = 2;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(cboExperimenter, gridBagConstraints);
cmdAdd.setMnemonic('A');
cmdAdd.setText("Add New Session");
cmdAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdAddActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
getContentPane().add(cmdAdd, gridBagConstraints);
cmdDelete.setMnemonic('D');
cmdDelete.setText("Delete This Session");
cmdDelete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdDeleteActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(5, 4, 0, 0);
getContentPane().add(cmdDelete, gridBagConstraints);
jSeparator3.setMinimumSize(new java.awt.Dimension(500, 3));
jSeparator3.setPreferredSize(new java.awt.Dimension(500, 3));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 5;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 0);
getContentPane().add(jSeparator3, gridBagConstraints);
jLabel21.setText("sessions added for this subject:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.ipady = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(15, 0, 5, 0);
getContentPane().add(jLabel21, gridBagConstraints);
cmdClose2.setMnemonic('C');
cmdClose2.setText("Close");
cmdClose2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdClose2ActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 8;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
getContentPane().add(cmdClose2, gridBagConstraints);
jScrollPane3.setMinimumSize(new java.awt.Dimension(300, 100));
jScrollPane3.setPreferredSize(new java.awt.Dimension(300, 100));
lstSessions.setBorder(new javax.swing.border.EtchedBorder());
lstSessions.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "select a session" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
lstSessions.setMaximumSize(new java.awt.Dimension(200, 30));
lstSessions.setMinimumSize(new java.awt.Dimension(200, 30));
lstSessions.setPreferredSize(new java.awt.Dimension(200, 30));
lstSessions.setVisibleRowCount(5);
lstSessions.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
lstSessionsValueChanged(evt);
}
});
jScrollPane3.setViewportView(lstSessions);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.gridheight = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
getContentPane().add(jScrollPane3, gridBagConstraints);
lblType.setText("experiment type: ");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 5;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(lblType, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(cboType, gridBagConstraints);
txtDate.setMinimumSize(new java.awt.Dimension(130, 20));
txtDate.setPreferredSize(new java.awt.Dimension(130, 20));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 6;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 0, 0);
getContentPane().add(txtDate, gridBagConstraints);
cmdEditData.setMnemonic('V');
cmdEditData.setText("View/Edit Data for Session");
cmdEditData.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdEditDataActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(5, 4, 0, 0);
getContentPane().add(cmdEditData, gridBagConstraints);
pack();
}//GEN-END:initComponents
private void lstSessionsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstSessionsValueChanged
//show the selected session's information in the boxes on the screen
String strTemp = ""; String strSubID = ""; java.sql.Date dateTemp; String strSesID = "";
bolAddingNew = false; //switch flag - viewing, not adding
strTemp = (String)cboSubject.getSelectedItem(); //get selected subject and session IDs
if (strTemp.equals("") == true) { return; }
if (lstSessions.getSelectedIndex() == -1) { return; }
strSubID = strTemp.substring(0, strTemp.indexOf(":")); //ID is always the first part before the :
strTemp = (String)lstSessions.getSelectedValue();
strSesID = strTemp.substring(0, strTemp.indexOf(":")); //session ID is first also
try { //get all of the data from the database and put it up on the screen
ResultSet rssSubjects = stmSQL.executeQuery("SELECT * FROM session WHERE subID = " + strSubID + " AND sessionID = " + strSesID);
rssSubjects.next(); //move forward so can get the data out of the database
cboExperimenter.setSelectedItem(rssSubjects.getString("experimenter"));
txtComment.setText(rssSubjects.getString("environmentComment"));
txtDate.setText(rssSubjects.getString("expDate"));
cboType.setSelectedItem(rssSubjects.getString("expType"));
} catch(java.sql.SQLException e) { e.printStackTrace(); }
}//GEN-LAST:event_lstSessionsValueChanged
private void cmdEditDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEditDataActionPerformed
//load EricaData for an existing EricaData session
String strTemp = ""; String strType = ""; String strName = ""; String strSesID = "";
int intTemp = 0; String strSubID = "";
strTemp = (String)cboSubject.getSelectedItem(); //get and check sessionID and subjectID chosen
intTemp = lstSessions.getSelectedIndex();
if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the subject you want to edit from the box.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
if (intTemp == -1) { JOptionPane.showMessageDialog(null, "Please select the session you want to edit from the list.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
strSubID = strTemp.substring(0, strTemp.indexOf(":")); //ID is always the first part before the :
strName = strTemp.substring(strTemp.indexOf(":") + 2); //parse out subject name
strTemp = (String)lstSessions.getSelectedValue(); //chosen session
strSesID = strTemp.substring(0, strTemp.indexOf(":")); //session ID is first also
strType = strTemp.substring((strTemp.indexOf(",") + 2), (strTemp.indexOf("(") - 1)); //parse out the expType
if (strType.equals("Erica Sound Clips") == true) { //show EricaData
EricaData frmErica = new EricaData(strSubID, strName, strSesID);
JDesktopPane contentPane = this.getDesktopPane(); //get desktop pane that this internal frame is in
contentPane.add(frmErica, javax.swing.JLayeredPane.DEFAULT_LAYER); //add new frame to desktop frame
frmErica.setFrameIcon(new ImageIcon("ParasolSmall.gif"));
frmErica.setBounds(20, 20, 700, 580);
frmErica.show(); }
else { JOptionPane.showMessageDialog(null, "This button only works for EricaData sessions. '" + strType + "' is not 'Erica Sound Clips'", "Selection Error", JOptionPane.ERROR_MESSAGE); return; }
}//GEN-LAST:event_cmdEditDataActionPerformed
private void cmdClose2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdClose2ActionPerformed
try { this.setClosed(true); }
catch(java.beans.PropertyVetoException e) { e.printStackTrace(); }
}//GEN-LAST:event_cmdClose2ActionPerformed
private void cmdOKCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOKCloseActionPerformed
//adds or updates the database
String strSubID = ""; String strSesID = ""; String strTemp = ""; String strComment = ""; String strType = "";
String strExperimenter = ""; String strDate = ""; String strSQL = "";
//get the subject ID and session ID from the combo & list boxes
strTemp = (String)cboSubject.getSelectedItem();
if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the subject.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
strSubID = strTemp.substring(0, strTemp.indexOf(":")); //ID is always the first part before the :
if (bolAddingNew == false) { //updating the data in the database
strTemp = (String)lstSessions.getSelectedValue();
if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
strSesID = strTemp.substring(0, strTemp.indexOf(":")); }
//get the values from the user input and put into correct format
strExperimenter = (String)cboExperimenter.getSelectedItem(); strDate = txtDate.getText();
strComment = txtComment.getText(); strType = (String)cboType.getSelectedItem();
//check for errors in the text boxes; show message box and exit sub if errors
if (strExperimenter.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the experimenter for this session.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
if (strType.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the type of experiment the subject performed on this date.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
if (strDate.equals("0000-00-00") == true | strDate.equals("") == true) { JOptionPane.showMessageDialog(null, "Please enter the experiment date in the exact format yyyy-mm-dd.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
if (BackgroundNeuro.CheckDate(strDate, "the experiment date field") == false) { return; } //call fn to check date
strComment = SubjectData.AddEscapeChars(strComment); //call sub to add / before ', /, and "
//update or add data in the database as needed
if (bolAddingNew == false) { //updating the data in the database
strSQL = "UPDATE session SET experimenter = '" + strExperimenter + "', environmentComment = '" + strComment + "' WHERE subID = '" + strSubID + "' AND sessionID = '" + strSesID + "'"; }
else if (bolAddingNew == true) { //adding a new row
strSQL = "INSERT INTO session VALUES (" + strSubID + ", NULL, '" + strDate + "', '" + strExperimenter + "', '" + strComment + "', '" + strType +"')"; }
try { stmSQL = conData.createStatement(); stmSQL.executeUpdate(strSQL); }
catch(java.sql.SQLException e) { e.printStackTrace(); }
ClearScreen(); UpdateList(); //call subs to update screen
}//GEN-LAST:event_cmdOKCloseActionPerformed
private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDeleteActionPerformed
//delete the session highlighted in lstSessions
int intAnswer = 0; String strTemp = ""; String strSubID = ""; String strSesID = ""; String strTemp2 = "";
String strTime = ""; String strMovie = ""; boolean bolMade = true; String strHour = ""; String strSQL = "";
String strPath = "";
//check if a subject and session are selected and get the IDs
strTemp = (String)cboSubject.getSelectedItem(); strTemp2 = (String)lstSessions.getSelectedValue();
if (strTemp.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the subject you want to delete from the box.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
if (strTemp2.equals("") == true) { JOptionPane.showMessageDialog(null, "Please select the session you want to delete from the list.", "Missing Data Error", JOptionPane.ERROR_MESSAGE); return; }
strSubID = strTemp.substring(0, strTemp.indexOf(":")); //ID is always the first part before the :
strSesID = strTemp2.substring(0, strTemp2.indexOf(":")); //ID is always the first part before the :
//ask the user if they are sure they want to do the delete, exit if not
intAnswer = JOptionPane.showConfirmDialog(null, "The session " + strTemp2 + " will be deleted from the database.\nAll data and psychophysiology files for this session will also be lost.\nAre you sure that you want to delete this session?", "File Delete Confirm", JOptionPane.YES_NO_OPTION);
if (intAnswer == JOptionPane.NO_OPTION) { return; }
//get the type of experiment and set the sql statement to check for data
strSQL = "SELECT expType FROM session WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\"";
try {
stmSQL = conData.createStatement();
ResultSet rssSubjects = stmSQL.executeQuery(strSQL);
rssSubjects.next(); strTemp = rssSubjects.getString("expType");
} catch(java.sql.SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "There has been a serious database error.", "Serious Database Error", JOptionPane.ERROR_MESSAGE); return; }
if (strTemp.equals("Erica Sound Clips") == true) {
try {
ResultSet rssSubjects = stmSQL.executeQuery("SELECT dataFile FROM ericaData WHERE subID = '" + strSubID + "' AND sessionID = '" + strSesID + "'");
rssSubjects.next();
strPath = rssSubjects.getString("dataFile");
} catch(java.sql.SQLException e) { e.printStackTrace(); }
//delete the data archive from the hard drive
if ((strPath.equals("") == false) & (strPath.equals(null) == false)) { //check to make sure have a path
File fileZipPath = new File(strPath);
if (fileZipPath.exists() == true) { //file should already exist
bolMade = fileZipPath.delete(); //delete the existing file; bolMade shows if successful
if (bolMade == false) { JOptionPane.showMessageDialog(null, "There has been an error deleting the previous file. The old file was not deleted.", "Serious File Deletion Error", JOptionPane.ERROR_MESSAGE); return; }
}
}
try { //delete the entries from ericaData
stmSQL = conData.createStatement(); //stmSQL & conData are global
stmSQL.executeUpdate("DELETE FROM ericaData WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\"");
} catch(java.sql.SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "There has been an error deleting the ericaData table database entry.", "Database Deletion Error", JOptionPane.ERROR_MESSAGE); return; }
try { //delete the entries from ericaDataLikert
stmSQL = conData.createStatement(); //stmSQL & conData are global
stmSQL.executeUpdate("DELETE FROM ericaDataLikert WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\"");
} catch(java.sql.SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "There has been an error deleting the ericaDataLikert table database entry.", "Database Deletion Error", JOptionPane.ERROR_MESSAGE); return; }
}
try { //delete the existing record from the session table
stmSQL = conData.createStatement(); //stmSQL & conData are global
stmSQL.executeUpdate("DELETE FROM session WHERE subID = \"" + strSubID + "\" AND sessionID = \"" + strSesID + "\"");
} catch(java.sql.SQLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "There has been an error deleting the session table database entry.", "Database Deletion Error", JOptionPane.ERROR_MESSAGE); return; }
UpdateList(); //call sub to fill up the list of sessions for the current subject
ClearScreen(); //call sub to blank out the bottom of the screen
}//GEN-LAST:event_cmdDeleteActionPerformed
private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAddActionPerformed
ClearScreen();
bolAddingNew = true; //set flag for adding a new session
}//GEN-LAST:event_cmdAddActionPerformed
private void cboSubjectItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboSubjectItemStateChanged
//call sub to fill up the list of sessions for this subject
bolAddingNew = false; //switch flag - viewing, not adding
if ((String)cboSubject.getSelectedItem() != "") { //only want to do this if clicked, not if loading
if (evt.getStateChange() == ItemEvent.SELECTED) {
UpdateList(); //call sub to fill up the list of movies for the current subject and session
ClearScreen(); //clear the boxes in case were previously filled
}} //end the ifs
}//GEN-LAST:event_cboSubjectItemStateChanged
private void ClearScreen() {
// sub blanks out the controls on frmAdd
txtDate.setText(""); txtComment.setText(""); cboType.setSelectedIndex(0);
cboExperimenter.setSelectedIndex(0); lstSessions.removeAll();
}
private void UpdateList() {
//show the sessions in the list box for the current subject
String strSQL = ""; String strTemp = ""; String strID = ""; String strDate = ""; String strType = "";
String strSession = ""; int intID = 0; String strList[]; int intSize = 0; String strExperimenter = "";
strTemp = (String)cboSubject.getSelectedItem(); //get the date to parse out the parts
strID = strTemp.substring(0, strTemp.indexOf(":")); //ID is always the first part before the :
strSQL = "SELECT sessionID, expDate, experimenter, expType FROM session WHERE subID = \"" + strID + "\" ORDER BY expDate";
try {
ResultSet rssSubjects = stmSQL.executeQuery(strSQL); //make the resultset on the sql statement
while(rssSubjects.next()) { intSize = intSize + 1; } //count the number of rows in the resultset
rssSubjects.beforeFirst(); //move to the start of the resultset again
strList = new String[intSize]; //get the array ready to hold the data
intSize = 0;
while(rssSubjects.next()) { //get the data out of the database
intID = rssSubjects.getInt("sessionID"); strType = rssSubjects.getString("expType");
strDate = rssSubjects.getString("expDate"); strExperimenter = rssSubjects.getString("experimenter");
strList[intSize] = "" + intID + ": " + strDate + ", " + strType + " (" + strExperimenter + ")"; //store the list item
intSize = intSize + 1; //update count for next time
}
lstSessions.setListData(strList); //done with the result set, so add the data to the list
} catch(java.sql.SQLException e) { e.printStackTrace(); }
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox cboExperimenter;
private javax.swing.JComboBox cboSubject;
private javax.swing.JComboBox cboType;
private javax.swing.JButton cmdAdd;
private javax.swing.JButton cmdClose2;
private javax.swing.JButton cmdDelete;
private javax.swing.JButton cmdEditData;
private javax.swing.JButton cmdOKClose;
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.JScrollPane jScrollPane3;
private javax.swing.JSeparator jSeparator3;
private javax.swing.JLabel lblSubject;
private javax.swing.JLabel lblType;
private javax.swing.JList lstSessions;
private javax.swing.JTextArea txtComment;
private javax.swing.JTextField txtDate;
// End of variables declaration//GEN-END:variables
}