/*
* LoginEntryClass.java
*
* Created on 2006��9��11��, ����10:36
*
* RealCix2.0
*/
package realcix20.classes;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import realcix20.classes.basic.BaseClass;
import realcix20.classes.basic.Cell;
import realcix20.classes.basic.Row;
import realcix20.utils.DAO;
/**
*
* @author JerryChen
*/
public class LoginEntryClass extends BaseClass {
private final String VALIDATE_LOGIN_ENTRY_SQL = "SELECT * FROM RUSER WHERE RUSER=? AND PASSWORD=?";
private final String VALIDATE_USER_NAME_SQL = "SELECT * FROM LOGINENTRY WHERE RUSER=?";
private final String VALIDATE_USER_PASSWORD_SQL = "SELECT * FROM LOGINENTRY WHERE RUSER=? AND PASSWORD=?";
private DAO dao;
public LoginEntryClass(int clsId) {
super(clsId);
dao = DAO.getInstance();
}
public boolean validateUserPassword(String name, String password) {
boolean flag = false;
dao.query(VALIDATE_USER_PASSWORD_SQL);
dao.setObject(1, name);
dao.setObject(2, password);
ResultSet rs = dao.executeQuery();
try {
if (rs.next()) {
flag = true;
}
}
catch (SQLException sqle) {
// System.err.println("LoginEntryClass :: public boolean validateUserPassword(String name, String password) Error! Code = " + sqle.toString());
}
return flag;
}
public boolean validateUserName(String userName) {
boolean flag = true;
dao.query(VALIDATE_USER_NAME_SQL);
dao.setObject(1, userName);
ResultSet rs = dao.executeQuery();
try {
if (rs.next()) {
flag = false;
}
}
catch (SQLException sqle) {
// System.err.println("LoginEntryClass :: public boolean validateUserName(String userName) Error! Code = " + sqle.toString());
}
return flag;
}
public boolean login(Row selectedRow) {
boolean flag = false;
dao.query(VALIDATE_LOGIN_ENTRY_SQL);
Iterator cellIter = selectedRow.getNewCells().iterator();
while (cellIter.hasNext()) {
Cell cell = (Cell)cellIter.next();
if (cell.getColumnName().equals("RUSER")) {
dao.setObject(1, cell.getColumnValue());
} else if (cell.getColumnName().equals("PASSWORD")) {
dao.setObject(2, cell.getColumnValue());
break;
}
}
ResultSet rs = dao.executeQuery();
try {
if (rs.next()) {
flag = true;
}
}
catch (SQLException sqle) {
// System.err.println("LoginEntryClass :: public boolean login(Row selectedRow) Error! Code = " + sqle.toString());
}
return flag;
}
}