/**
** @author HansA AmarasekarA
*/
public class Login extends javax.swing.JFrame {
public Login() {
initComponents();
this.setLocationRelativeTo(null);
}
private void buttonLoginActionPerformed(java.awt.event.ActionEvent evt) {
String selectedPerson = null;
if(radioTransportOfficer.isSelected()){
selectedPerson = "TransportOfficer";
}else if(radioTravelGuide.isSelected()){
selectedPerson = "TravelGuide";
}
String userName = textUserName.getText();
String password = new String(textPassword.getPassword());
String recievedName=null;
String recievedPassword=null;
String fullName=null;
try{
ResultSet result = DB_Access.getData("select * from "+selectedPerson+" where username='"+userName+"' and password='"+password+"'");
if(result.next()){
recievedName = result.getString(1); //retrieve name of the person
recievedPassword = result.getString(2);
fullName = result.getString(3);
}else{
JOptionPane.showMessageDialog(this, "No User Found","Error",1);
}
if(radioTransportOfficer.isSelected() && recievedName.equals(userName) && recievedPassword.equals(password)){
Home_TO homeTO = new Home_TO(fullName);
homeTO.setVisible(true);
this.dispose();
}else if(radioTravelGuide.isSelected() && recievedName.equals(userName) && recievedPassword.equals(password)){
Home_TG homeTG = new Home_TG(fullName,userName);
homeTG.setVisible(true);
this.dispose();
}else{
JOptionPane.showMessageDialog(this, "Invalid User Name and Password","Error",0);
}
}catch (Exception e){
//JOptionPane.showMessageDialog(this, "No User Found Catch","Error",0);
}
} private void radioTransportOfficerActionPerformed(java.awt.event.ActionEvent evt) {
radioTravelGuide.setSelected(false);
textUserName.setEditable(true);
textPassword.setEditable(true);
}
private void radioTravelGuideActionPerformed(java.awt.event.ActionEvent evt) {
radioTransportOfficer.setSelected(false);
textUserName.setEditable(true);
textPassword.setEditable(true);
}
private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
}
No comments :
Post a Comment