public class SearchActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
Socket socket = new Socket("localhost", 8000);
ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
ObjectInputStream fromServer = new ObjectInputStream(socket.getInputStream());
int utarID = Integer.parseInt(txtUtarID.getText());
String sql = "SEARCH * FROM member WHERE utarID = ?;";
ClubMember member = new ClubMember(utarID);
sqlToServer.writeUTF(sql);
toServer.writeObject(member);
sqlToServer.flush();
toServer.flush();
System.out.println("Search command sent.");
ClubMember member1 = (ClubMember)fromServer.readObject();
txtName.setText(member1.name);
if(member1.gender.equals("M")){
rbMale.setSelected(true);
}
else if(member1.gender.equals("F")){
rbFemale.setSelected(true);
}
txtAddress.setText(member1.address);
txtPostcode.setText("" + member1.postcode);
txtCity.setText(member1.city);
cbState.setSelectedItem(member1.state);
txtEmail.setText(member1.email);
txtPhoneNumber.setText(member1.phoneNumber);
cbCourse.setSelectedItem(member1.course);
cbYearIntake.setSelectedItem(member1.yearIntake);
txtYear.setText("" + member1.year);
txtTrimester.setText("" + member1.trimester);
cbPosition.setSelectedItem(member1.position);
}
catch(Exception ex){
}
}
}
public class CreateActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
Socket socket = new Socket("localhost", 8000);
ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
int utarID = Integer.parseInt(txtUtarID.getText());
String name = txtName.getText();
String gender;
if(rbMale.isSelected())
gender = rbMale.getText();
else
gender = rbFemale.getText();
String address = txtAddress.getText();
int postcode = Integer.parseInt(txtPostcode.getText());
String city = txtCity.getText();
String state = "" + cbState.getSelectedItem();
String email = txtEmail.getText();
String phoneNumber = txtPhoneNumber.getText();
String course = "" + cbCourse.getSelectedItem();
int yearIntake = Integer.parseInt(cbYearIntake.getSelectedItem().toString());
int year = Integer.parseInt(txtYear.getText());
int trimester = Integer.parseInt(txtTrimester.getText());
String yearTrimester = "" + year + "/" + trimester;
String position = "" + cbPosition.getSelectedItem();
java.util.Date date = new java.util.Date();
java.sql.Date joinedDate = new java.sql.Date(date.getDate());
String sql = "INSERT INTO member VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
ClubMember member = new ClubMember(utarID, name, gender, address, postcode,
city, state, email, phoneNumber, course, yearIntake, year,
trimester, position, joinedDate);
String create = "Utar ID: "+utarID+"\nName: "+name+"\nGender: "+gender+"\nAddress: "+address+"\nPostcode: "+postcode+
"\nCity: "+city+"\nState: "+state+"\nEmail: "+email+"\nPhoneNumber: "+phoneNumber+
"\nCourse: "+course+"\nYear Intake: "+yearIntake+"\nYear/Trimester: "+yearTrimester+"\nPosition: "+position+
"\n\nDo you want to register this member?";
int response = JOptionPane.showConfirmDialog(null, create, "Create Confirm", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(response == JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null, "Member :" + name + " has been created.", "Created", JOptionPane.INFORMATION_MESSAGE);
System.out.println("Sending now.");
sqlToServer.writeUTF(sql);
toServer.writeObject(member);
sqlToServer.flush();
toServer.flush();
System.out.println("Object member sent.");
}
}
catch(Exception ex){
}
}
}
public class UpdateActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
Socket socket = new Socket("localhost", 8000);
ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
int utarID = Integer.parseInt(txtUtarID.getText());
String name = txtName.getText();
String gender;
if(rbMale.isSelected())
gender = rbMale.getText();
else
gender = rbFemale.getText();
String address = txtAddress.getText();
int postcode = Integer.parseInt(txtPostcode.getText());
String city = txtCity.getText();
String state = "" + cbState.getSelectedItem();
String email = txtEmail.getText();
String phoneNumber = txtPhoneNumber.getText();
String course = "" + cbCourse.getSelectedItem();
int yearIntake = Integer.parseInt(cbYearIntake.getSelectedItem().toString());
int year = Integer.parseInt(txtYear.getText());
int trimester = Integer.parseInt(txtTrimester.getText());
String yearTrimester = "" + year + "/" + trimester;
String position = "" + cbPosition.getSelectedItem();
java.util.Date date = new java.util.Date();
java.sql.Date joinedDate = new java.sql.Date(date.getDate());
String sql = "UPDATE member SET utarID=?, name=?, gender=?, address=?, postcode=?, "
+ "city=?, stateOfCountry=?, email=?, phoneNumber=?, course=?, yearIntake=?, "
+ "yearOfTrimester=?, trimester=?, currentPosition=?, joinedDate=? WHERE "
+ "utarID=?;";
ClubMember member = new ClubMember(utarID, name, gender, address, postcode,
city, state, email, phoneNumber, course, yearIntake, year,
trimester, position, joinedDate);
String update = "Utar ID: "+utarID+"\nName: "+name+"\nGender: "+gender+"\nAddress: "+address+"\nPostcode: "+postcode+
"\nCity: "+city+"\nState: "+state+"\nEmail: "+email+"\nPhoneNumber: "+phoneNumber+
"\nCourse: "+course+"\nYear Intake: "+yearIntake+"\nYear/Trimester: "+yearTrimester+"\nPosition: "+position+
"\n\nDo you want to update this member's information?";
int response = JOptionPane.showConfirmDialog(null, update, "Update Confirm", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(response == JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null, "Member :" + name + " has been Updated.", "Updated", JOptionPane.INFORMATION_MESSAGE);
sqlToServer.writeUTF(sql);
toServer.writeObject(member);
sqlToServer.flush();
toServer.flush();
System.out.println("Object member sent.");
}
}
catch(Exception ex){
}
}
}
public class DeleteActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
Socket socket = new Socket("localhost", 8000);
ObjectOutputStream toServer = new ObjectOutputStream(socket.getOutputStream());
DataOutputStream sqlToServer = new DataOutputStream(socket.getOutputStream());
int utarID = Integer.parseInt(txtUtarID.getText());
String name = txtName.getText();
String delete = "Do you want to delete member: " + name +"?";
String sql = "DELETE FROM member WHERE utarID=?;";
ClubMember member = new ClubMember(utarID);
int response = JOptionPane.showConfirmDialog(null, delete, "Delete Confirm", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(response == JOptionPane.YES_OPTION){
JOptionPane.showMessageDialog(null, "Member :" + name + " has been deleted.", "Deleted", JOptionPane.INFORMATION_MESSAGE);
sqlToServer.writeUTF(sql);
toServer.writeObject(member);
sqlToServer.flush();
toServer.flush();
System.out.println("Delete statement sent.");
txtUtarID.setText(null);
txtName.setText(null);
buttonGroup.clearSelection();
txtAddress.setText(null);
txtPostcode.setText(null);
cbState.setSelectedIndex(0);
txtCity.setText(null);
txtEmail.setText(null);
txtPhoneNumber.setText(null);
cbCourse.setSelectedIndex(0);
cbYearIntake.setSelectedIndex(0);
txtYear.setText(null);
txtTrimester.setText(null);
cbPosition.setSelectedIndex(0);
}
}
catch(Exception ex){
}
}
}