package wenrgise.hrms.businessdelegate;

import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.CreateException;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.vo.BaseQueryVO;
import wenrgise.common.vo.ThisPageVO;
import wenrgise.ejb.common.utility.ServiceLocator;
import wenrgise.hrms.bean.HrmGenEligRuleHdrBean;
import wenrgise.hrms.bean.HrmOrgCntryMstHdrBean;
import wenrgise.hrms.ejb.facade.HrmSecondFacade;
import wenrgise.hrms.ejb.facade.HrmSecondFacadeHome;

public class HrmGenEligRuleBD extends HrmBaseBD {
  ArrayList arylstHdr;
  
  public HashMap getEligClassInfo() throws EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      return oHrmSecondFacade.getEligClassInfo();
    } catch (RemoteException oRe) {
      throw new EnrgiseSystemException(oRe);
    } catch (CreateException oCrt) {
      throw new EnrgiseSystemException(oCrt);
    } 
  }
  
  public boolean updateHeaderRecordImpl(BaseHeaderBean oBaseHeaderBean) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return true;
  }
  
  public String saveImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    try {
      HrmSecondFacadeHome oHome = (HrmSecondFacadeHome)ServiceLocator.getLocator().getService("HrmSecondFacade");
      HrmSecondFacade oHrmSecondFacade = oHome.create();
      String s = oHrmSecondFacade.saveData((HrmGenEligRuleHdrBean)oBaseHeaderBean, oWhenPicked, sScreenName, sScreenMode, bHeaderDataChanged, oDetailBeanArray, bDetailDataChanged, oDetailPicked, this.oUserInfo);
      return s;
    } catch (CreateException oCrtExcep) {
      throw new EnrgiseSystemException(oCrtExcep);
    } 
  }
  
  public String getInsertDataImpl(BaseQueryVO oQueryVO) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return "Only Implementation";
  }
  
  public ArrayList getDetailRecordImpl(String lPrimaryKey, String sScreenName, long lAbsoluteStart, long lAbsoluteEnd) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  public RecordMetaInfo getTotalDetailRecordCountImpl(String lPrimaryKey, String sScreenName) throws EnrgiseApplicationException, EnrgiseSystemException {
    return null;
  }
  
  public RecordMetaInfo getHeaderMetaImpl(BaseQueryVO oQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    RecordMetaInfo oRecInfo = new RecordMetaInfo();
    oRecInfo.setRecordCount(1L);
    oRecInfo.setOWhenPicked(null);
    return oRecInfo;
  }
  
  public ArrayList getHeaderRecordImpl(BaseQueryVO oQueryVO, long lStartPosition, long lLastPosition) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstDummy = new ArrayList();
    arylstDummy.add(new HrmOrgCntryMstHdrBean());
    return arylstDummy;
  }
  
  public static void main(String[] ss) throws EnrgiseSystemException, EnrgiseApplicationException {
    HrmGenEligRuleBD o = new HrmGenEligRuleBD();
    System.out.println(o.getEligClassInfo());
  }
  
  public Map getDisabledFieldsImpl(ThisPageVO oThisPageVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    HashMap oHashMap = new HashMap();
    ArrayList arylstEnab = new ArrayList();
    ArrayList arylstDisab = new ArrayList();
    arylstDisab.add("butPrevHeader");
    arylstDisab.add("butNextHeader");
    HrmGenEligRuleHdrBean oHdrBean = (HrmGenEligRuleHdrBean)oThisPageVO.getOHeaderBean();
    if (oHdrBean.getDocumentType().equals("")) {
      arylstDisab.add("butDocumentCode");
      oHdrBean.setDocumentCode("");
      oHdrBean.setHidDocumentCodeId("");
    } else {
      arylstEnab.add("butDocumentCode");
    } 
    if (oHdrBean.getHidAction().equals("Refresh")) {
      arylstEnab.add("operator");
      arylstEnab.add("butValues");
      arylstEnab.add("documentType");
      arylstEnab.add("butDocumentCode");
      arylstEnab.add("butAnd");
      arylstEnab.add("butOr");
      arylstEnab.add("butShowFormula");
    } 
    oThisPageVO.setOHeaderBean((BaseHeaderBean)oHdrBean);
    oHashMap.put("E", arylstEnab);
    oHashMap.put("D", arylstDisab);
    return oHashMap;
  }
  
  public void onLoadAction(ThisPageVO oThisPageVO) {
    HrmGenEligRuleHdrBean oHdrBean = (HrmGenEligRuleHdrBean)oThisPageVO.getOHeaderBean();
    if (oHdrBean.getHidAction().equals("Refresh")) {
      oHdrBean.setDocumentCode("");
      oHdrBean.setHidDocumentCodeId("");
      oHdrBean.setDocumentType("");
      oHdrBean.setFormula("");
      oHdrBean.setEligSql("");
      oHdrBean.setHidAction("");
    } 
  }
  
  public String submitImpl(String sButtonName, BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList oDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws RemoteException, EnrgiseApplicationException, EnrgiseSystemException {
    return new String("");
  }
}
