package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.UserInfo;
import wenrgise.ejb.common.business.BaseBO;
import wenrgise.ejb.common.helper.DBObject;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.helper.QueryValue;
import wenrgise.ejb.common.utility.DBUtilitiesBean;

public class HrmLoginBO extends BaseBO {
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) {
    return new String();
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) {}
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String screenMode) {
    return new String();
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList oDetailBeanArray) {}
  
  public void initializeBOImpl() {}
  
  public void additionalFieldValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public UserInfo getLoginUserInfo(String sEmpNo, String sSiteId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    ArrayList arylstOutArray = new ArrayList();
    UserInfo oUserInfo = null;
    QueryRow oRow = null;
    QueryValue oValue = null;
    ArrayList oList = null;
    oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sEmpNo));
    arylstParameters.add(new DBObject(2, 1, 12, sSiteId));
    arylstParameters.add(new DBObject(3, 2, -10));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    arylstOutArray = oBean.callProc(arylstParameters, "HRMUSERINFO.procGetUserInfo(?,?,?,?,?,?)");
    oList = (ArrayList)((DBObject)arylstOutArray.get(0)).getObject();
    if (oList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    Iterator oIt = oList.iterator();
    while (oIt.hasNext()) {
      oRow = oIt.next();
      oUserInfo = new UserInfo();
      System.out.println(oRow.get("CURRENT_YEAR").getString());
      oUserInfo.setCurrentYear(oRow.get("CURRENT_YEAR").getString());
      System.out.println(oRow.get("SITE_ID").getString());
      oUserInfo.setSiteId(oRow.get("SITE_ID").getString());
      oUserInfo.setSiteCode(oRow.get("SITE_CODE").getString());
      oUserInfo.setSiteName(oRow.get("SITE_NAME").getString());
      oUserInfo.setUserActiveFlag(oRow.get("USER_ACTIVE_FLAG").getString());
      oUserInfo.setUserId(oRow.get("USER_ID").getString());
      oUserInfo.setUserLocked(oRow.get("USER_LOCKED").getString());
      oUserInfo.setUserName(oRow.get("USER_NAME").getString());
      oUserInfo.setUserSystemId(oRow.get("USER_SYSTEM_ID").getString());
      oUserInfo.setUserType(oRow.get("USER_TYPE").getString());
      oUserInfo.setUserTypeId(oRow.get("USER_TYPE_ID").getString());
      oUserInfo.setGradeId(oRow.get("GRADE_ID").getString());
      oUserInfo.setGrade(oRow.get("GRADE").getString());
      oUserInfo.setDesignation(oRow.get("DESIGNATION").getString());
      oUserInfo.setDesigId(oRow.get("DESIG_ID").getString());
    } 
    return oUserInfo;
  }
}
