package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import wenrgise.common.bean.BaseHeaderBean;
import wenrgise.common.bean.LOVBean;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseMessageKeyException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.DateUtility;
import wenrgise.common.utility.EnrgiseUtil;
import wenrgise.common.utility.RecordMetaInfo;
import wenrgise.common.utility.UserInfo;
import wenrgise.common.vo.BaseDetailVO;
import wenrgise.common.vo.BaseHeaderVO;
import wenrgise.common.vo.LovQueryVO;
import wenrgise.common.vo.LovVO;
import wenrgise.ejb.common.helper.DBObject;
import wenrgise.ejb.common.helper.QueryRow;
import wenrgise.ejb.common.helper.QueryValue;
import wenrgise.ejb.common.utility.DBUtilitiesBean;
import wenrgise.hrms.bean.HrmSepClrTmplMstDtlBean;
import wenrgise.hrms.bean.HrmSepClrTmplMstHdrBean;
import wenrgise.hrms.vo.HrmSepClrTmplMstQVO;

public class HrmSepClrTmplMstBO extends HrmBaseBO {
  public HrmSepClrTmplMstBO() {}
  
  public HrmSepClrTmplMstBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmSepClrTmplMstHdrMetaInfo(HrmSepClrTmplMstQVO oHrmSepClrTmplMstQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmSepClrTmplMstQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmSepClrTmplMstQVO.getTmplDescId()));
    arylstParameters.add(new DBObject(3, 2, -5));
    arylstParameters.add(new DBObject(4, 2, 93));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_GetSepClrTmplMstHdrCount(?,?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmSepClrTmplMstHeaderInfo(HrmSepClrTmplMstQVO oHrmSepClrTmplMstQVO, long lStartPosition, long lLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    ArrayList arylstHeaderList = null;
    if (oHrmSepClrTmplMstQVO == null)
      oHrmSepClrTmplMstQVO = new HrmSepClrTmplMstQVO(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lStartPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmSepClrTmplMstQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmSepClrTmplMstQVO.getTmplDescId()));
    arylstParameters.add(new DBObject(5, 2, -10));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 12));
    arylstParameters.add(new DBObject(8, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_GetSepClrTmplMstHdr(?,?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmSepClrTmplMstHdrBean oHeaderBean = new HrmSepClrTmplMstHdrBean();
      oHeaderBean.setHeaderPrimaryKey(oRow.get("ID").getString());
      oHeaderBean.setTmplDescId(oRow.get("ID").getString());
      oHeaderBean.setTmplDesc(oRow.get("tmpl_description").getString());
      String sObsFlag = "on";
      if (oRow.get("obsolete_flag").getString().equals("N"))
        sObsFlag = "off"; 
      oHeaderBean.setObsoleteFlag(sObsFlag);
      arylstHeaderList.add(oHeaderBean);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmSepClrTmplMstDtlMetaInfo(String lPrimaryKey) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(2, 2, -5));
    arylstParameters.add(new DBObject(3, 2, 93));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_GetSepClrTmplMstDtlCount(?,?,?,?,?,?)");
    RecordMetaInfo oRecordMetaInfo = new RecordMetaInfo();
    DBObject oTotalRecord = arylstOutArray.get(0);
    oRecordMetaInfo.setRecordCount(((Long)oTotalRecord.getObject()).longValue());
    DBObject oTimeObject = arylstOutArray.get(1);
    oRecordMetaInfo.setOWhenPicked((Timestamp)oTimeObject.getObject());
    return oRecordMetaInfo;
  }
  
  public ArrayList getHrmSepClrTmplMstDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstDetailBean = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, -5, new Long(lDetailFirstPosition)));
    arylstParameters.add(new DBObject(2, 1, -5, new Long(lDetailLastPosition)));
    arylstParameters.add(new DBObject(3, 1, 12, lPrimaryKey));
    arylstParameters.add(new DBObject(4, 2, -10));
    arylstParameters.add(new DBObject(5, 2, 12));
    arylstParameters.add(new DBObject(6, 2, 12));
    arylstParameters.add(new DBObject(7, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_GetSepClrTmplMstDtl(?,?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    if (arylstList.size() == 0)
      throw new EnrgiseApplicationException("wenrgise.hrms.norecordfound", "M"); 
    QueryRow oRow = null;
    QueryValue oValue = null;
    HashMap oColumns = null;
    Iterator itrBean = arylstList.iterator();
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstDetailBean = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmSepClrTmplMstDtlBean oDetailBean = new HrmSepClrTmplMstDtlBean();
      oDetailBean.setDetailId(oRow.get("ID").getString());
      oDetailBean.setTxtClrDescId(oRow.get("clr_id").getString());
      oDetailBean.setTxtClrDesc(oRow.get("clrnc_description").getString());
      arylstDetailBean.add(oDetailBean);
    } 
    return arylstDetailBean;
  }
  
  public LovVO getHrmSepTmplLOV(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("ID");
    arylstHeaderList.add("hrm.HrmSepClrTmplMst.txtClrDesc");
    arylstHeaderList.add("hrm.HrmSepClrTmplMst.obsoleteFlag");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    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));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_GetTmplDescLOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("TMPL_DESCRIPTION").getString());
      oLOVBean.setDetailField3(oRow.get("OBSOLETE_FLAG").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public LovVO getHrmSepClrLOV(LovQueryVO oLovQueryVO) throws EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderList = new ArrayList();
    arylstHeaderList.add("Code ID");
    arylstHeaderList.add("hrm.HrmSepClrTmplMst.txtClrDesc");
    arylstHeaderList.add("hrm.HrmSepClrTmplMst.extIntFlag");
    oLovVO.setHeaderList(arylstHeaderList);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    if (oLovQueryVO.getSearchField2() != null)
      sQuerySearch2 = oLovQueryVO.getSearchField2(); 
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, sQuerySearch2));
    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));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_GetClrDescLOV(?,?,?,?,?,?)");
    DBObject oOutObject = arylstOutArray.get(0);
    ArrayList arylstList = (ArrayList)oOutObject.getObject();
    QueryRow oRow = null;
    Iterator iter = arylstList.iterator();
    while (iter.hasNext()) {
      if (count == 0)
        arylstList = new ArrayList(); 
      count++;
      oRow = iter.next();
      LOVBean oLOVBean = new LOVBean();
      oLOVBean.setDetailField1(oRow.get("ID").getString());
      oLOVBean.setDetailField2(oRow.get("CLRNC_DESCRIPTION").getString());
      oLOVBean.setDetailField3(oRow.get("EXT_INT_FLAG").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_SEP_TMPL_HDR";
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    String returnString = null;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    DateUtility d = new DateUtility();
    HrmSepClrTmplMstHdrBean oHrmSepClrTmplMstHdrBean = (HrmSepClrTmplMstHdrBean)oBaseHeaderBean;
    if (ScreenMode.equalsIgnoreCase("N")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "N"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmSepClrTmplMstHdrBean.getTmplDesc()));
      String sObsFlag = "N";
      if (oHrmSepClrTmplMstHdrBean.getObsoleteFlag().equals("on"))
        sObsFlag = "Y"; 
      arylstParameters.add(new DBObject(3, 1, 12, sObsFlag));
      arylstParameters.add(new DBObject(4, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getSiteId()));
      arylstParameters.add(new DBObject(6, 1, 12, null));
      arylstParameters.add(new DBObject(7, 2, 12));
      arylstParameters.add(new DBObject(8, 2, 12));
      arylstParameters.add(new DBObject(9, 2, 12));
      arylstParameters.add(new DBObject(10, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_UpsertSepClrTmplMstHdr(?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
      System.out.println(returnString);
    } else if (ScreenMode.equalsIgnoreCase("U")) {
      arylstParameters = new ArrayList();
      arylstParameters.add(new DBObject(1, 1, 12, "U"));
      arylstParameters.add(new DBObject(2, 1, 12, oHrmSepClrTmplMstHdrBean.getTmplDesc()));
      String sObsFlag = "N";
      if (oHrmSepClrTmplMstHdrBean.getObsoleteFlag().equals("on"))
        sObsFlag = "Y"; 
      arylstParameters.add(new DBObject(3, 1, 12, sObsFlag));
      arylstParameters.add(new DBObject(4, 1, 12, this.oUserInfo.getUserTypeId()));
      arylstParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getSiteId()));
      arylstParameters.add(new DBObject(6, 1, 12, oHrmSepClrTmplMstHdrBean.getHeaderPrimaryKey()));
      arylstParameters.add(new DBObject(7, 2, 12));
      arylstParameters.add(new DBObject(8, 2, 12));
      arylstParameters.add(new DBObject(9, 2, 12));
      arylstParameters.add(new DBObject(10, 2, 4));
      ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMSEPCLRTMPLMST.proc_UpsertSepClrTmplMstHdr(?,?,?,?,?,?,?,?,?,?)");
      DBObject oOutObject = arylstOutArray.get(0);
      returnString = (String)oOutObject.getObject();
    } 
    return returnString;
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmSepClrTmplMst"))
      saveHrmSepClrTmplMstDetail(sHeaderPrimaryKey, arylstDetailBeanArray); 
  }
  
  private void saveHrmSepClrTmplMstDetail(String sHeaderPrimaryKey, ArrayList arylstDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmSepClrTmplMstDtlBean oHrmSepClrTmplMstDtlBean = itrBean.next();
      System.out.println(oHrmSepClrTmplMstDtlBean.getStatus());
      if (oHrmSepClrTmplMstDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMSEPCLRTMPLMST.proc_UpsertSepClrTmplMstDtl(?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "N"));
        arylstParameters.add(new DBObject(2, 1, 12, null));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmSepClrTmplMstDtlBean.getTxtClrDescId()));
        arylstParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmSepClrTmplMstDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMSEPCLRTMPLMST.proc_UpsertSepClrTmplMstDtl(?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmSepClrTmplMstDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmSepClrTmplMstDtlBean.getTxtClrDescId()));
        arylstParameters.add(new DBObject(5, 1, 12, this.oUserInfo.getUserTypeId()));
        arylstParameters.add(new DBObject(6, 1, 12, this.oUserInfo.getSiteId()));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmSepClrTmplMstDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMSEPCLRTMPLMST.proc_DeleteSepClrTmplMstDtl(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmSepClrTmplMstDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {}
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return null;
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    if (bHeaderDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkMandatoryHeader((HrmSepClrTmplMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (sScreenName.equalsIgnoreCase("HrmSepClrTmplMst")) {
        Iterator itrBean1 = arylstDetailBeanArray.iterator();
        int iCount = 1;
        while (itrBean1.hasNext()) {
          HrmSepClrTmplMstDtlBean oHrmSepClrTmplMstDtlBean = itrBean1.next();
          if (!oHrmSepClrTmplMstDtlBean.getStatus().equalsIgnoreCase("D"))
            checkMandatory(oHrmSepClrTmplMstDtlBean, iCount, arylstErrorList); 
          iCount++;
        } 
      }  
    reportError(arylstErrorList);
  }
  
  private void checkMandatory(HrmSepClrTmplMstDtlBean oHrmSepClrTmplMstDtlBean, int iCount, ArrayList arylstErrorList) throws EnrgiseSystemException, EnrgiseApplicationException {}
  
  private void checkMandatoryHeader(HrmSepClrTmplMstHdrBean oHrmSepClrTmplMstHdrBean) throws EnrgiseSystemException, EnrgiseApplicationException {}
  
  public void additionalTimestampValidationImpl(BaseHeaderBean param1, Timestamp param2, String param3, String param4, boolean param5, ArrayList param6, boolean param7, Timestamp param8) {}
  
  public void additionalBusinessValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    HrmSepClrTmplMstHdrBean oHrmSepClrTmplMstHdrBean = (HrmSepClrTmplMstHdrBean)oBaseHeaderBean;
    if (bHeaderDataChanged)
      if (sScreenMode.equalsIgnoreCase("N"))
        checkUniqueHeader((HrmSepClrTmplMstHdrBean)oBaseHeaderBean);  
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmSepClrTmplMst"))
          EnrgiseUtil.checkDuplicate(arylstDetailBeanArray, "txtClrDescId", "hrm.HrmSepClrTmplMst.txtClrDesc", arylstErrorList, true);   
    reportError(arylstErrorList);
  }
  
  public void checkRefferenceKey(String sSkillHeaderId) throws EnrgiseApplicationException, EnrgiseSystemException {}
  
  private void checkUniqueHeader(HrmSepClrTmplMstHdrBean oHrmSepClrTmplMstHdrBean) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstList1 = new ArrayList();
    ArrayList arylstParam = new ArrayList();
    String sQuery = String.valueOf(String.valueOf(" Select TMPL_DESCRIPTION from HRM_SEP_TMPL_HDR where upper(TMPL_DESCRIPTION)='").concat(String.valueOf(oHrmSepClrTmplMstHdrBean.getTmplDesc().toUpperCase()))).concat(String.valueOf("'"));
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    ArrayList arylstList = oBean.executeQuery(sQuery);
    Iterator itrBean = arylstList.iterator();
    if (itrBean.hasNext()) {
      QueryRow oRow = itrBean.next();
      if (oRow.get("TMPL_DESCRIPTION").getString().equalsIgnoreCase(oHrmSepClrTmplMstHdrBean.getTmplDesc())) {
        arylstParam = new ArrayList();
        arylstParam.add("");
        arylstParam.add(new Integer(0));
        arylstList1.add(new EnrgiseMessageKeyException("wenrgise.common.uniqueConstraintViolated", arylstParam));
      } 
    } 
    reportError(arylstList1);
  }
}
