package wenrgise.hrms.ejb.business;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
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.ejb.business.HrmCommonBO;
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.MessageKey;
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.HrmTrngFacTrngDtlBean;
import wenrgise.hrms.bean.HrmTrngFacTrngHdrBean;
import wenrgise.hrms.vo.HrmTrngFacTrngQVO;

public class HrmTrngFacTrngBO extends HrmBaseBO {
  public HrmTrngFacTrngBO() {}
  
  public HrmTrngFacTrngBO(UserInfo oUserInfo) {
    super(oUserInfo);
  }
  
  public RecordMetaInfo getHrmFacTrngHdrMetaInfo(HrmTrngFacTrngQVO oHrmTrngFacTrngQVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    Timestamp oWhenPicked = null;
    int count = 0;
    BaseHeaderVO oBaseHeaderVO = new BaseHeaderVO();
    DateUtility d = new DateUtility();
    String oStr = oHrmTrngFacTrngQVO.getStartDate();
    String oStr1 = oHrmTrngFacTrngQVO.getEndDate();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, oHrmTrngFacTrngQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(2, 1, 12, oHrmTrngFacTrngQVO.getCalId()));
    arylstParameters.add(new DBObject(3, 1, 12, oHrmTrngFacTrngQVO.getCourseId()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngFacTrngQVO.getSiteId()));
    arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oStr)));
    arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oStr1)));
    arylstParameters.add(new DBObject(7, 2, -5));
    arylstParameters.add(new DBObject(8, 2, 93));
    arylstParameters.add(new DBObject(9, 2, 12));
    arylstParameters.add(new DBObject(10, 2, 12));
    arylstParameters.add(new DBObject(11, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMFACTRNGDTL.proc_HrFacTrngHdrCount(?,?,?,?,?,?,?,?,?,?,?)");
    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 getHrmFacTrngHeaderInfo(HrmTrngFacTrngQVO oHrmTrngFacTrngQVO, 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 (oHrmTrngFacTrngQVO == null)
      oHrmTrngFacTrngQVO = new HrmTrngFacTrngQVO(); 
    DateUtility d = new DateUtility();
    String oStr = oHrmTrngFacTrngQVO.getStartDate();
    String oStr1 = oHrmTrngFacTrngQVO.getEndDate();
    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, oHrmTrngFacTrngQVO.getHeaderPrimaryKey()));
    arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngFacTrngQVO.getCalId()));
    arylstParameters.add(new DBObject(5, 1, 12, oHrmTrngFacTrngQVO.getCourseId()));
    arylstParameters.add(new DBObject(6, 1, 12, oHrmTrngFacTrngQVO.getSiteId()));
    arylstParameters.add(new DBObject(7, 1, 93, EnrgiseUtil.convertToSqlDate(oStr)));
    arylstParameters.add(new DBObject(8, 1, 93, EnrgiseUtil.convertToSqlDate(oStr1)));
    arylstParameters.add(new DBObject(9, 2, -10));
    arylstParameters.add(new DBObject(10, 2, 12));
    arylstParameters.add(new DBObject(11, 2, 12));
    arylstParameters.add(new DBObject(12, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMFACTRNGDTL.proc_GetHrFacTrngHdr(?,?,?,?,?,?,?,?,?,?,?,?)");
    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();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHeaderList = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngFacTrngHdrBean oFacTrngHeader = new HrmTrngFacTrngHdrBean();
      oFacTrngHeader.setHeaderPrimaryKey(oRow.get("ID").getString());
      oFacTrngHeader.setCourseStatus(oRow.get("STATUS_FLAG").getString());
      oFacTrngHeader.setStartDate(EnrgiseUtil.convertToString(oRow.get("START_DATE").getDate()));
      oFacTrngHeader.setEndDate(EnrgiseUtil.convertToString(oRow.get("END_DATE").getDate()));
      oFacTrngHeader.setInstId(oRow.get("INSTID").getString());
      oFacTrngHeader.setInstitutionName(oRow.get("INST_NAME").getString());
      oFacTrngHeader.setCourseId(oRow.get("COURSEID").getString());
      oFacTrngHeader.setCourseName(oRow.get("CRS_NAME").getString());
      oFacTrngHeader.setCalId(oRow.get("CALID").getString());
      oFacTrngHeader.setCalendarName(oRow.get("CAL_NAME").getString());
      oFacTrngHeader.setSiteId(oRow.get("SITE_ID").getString());
      oFacTrngHeader.setSite(oRow.get("SITE_CODE").getString());
      oFacTrngHeader.setSiteName(oRow.get("SITE_NAME").getString());
      arylstHeaderList.add(oFacTrngHeader);
    } 
    return arylstHeaderList;
  }
  
  public RecordMetaInfo getHrmFacTrngDtlMetaInfo(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, "HRMFACTRNGDTL.proc_HrFacTrngDtlCount(?,?,?,?,?,?)");
    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 getHrmFacTrngDetailInfo(String lPrimaryKey, long lDetailFirstPosition, long lDetailLastPosition) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmFacTrngDetail = 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, "HRMFACTRNGDTL.proc_GetHrFacTrngDtl(?,?,?,?,?,?,?)");
    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();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmFacTrngDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngFacTrngDtlBean oFacTrngDetailBean = new HrmTrngFacTrngDtlBean();
      oFacTrngDetailBean.setDetailId(oRow.get("SRL_NO").getString());
      oFacTrngDetailBean.setTxtFromDate(EnrgiseUtil.convertToString(oRow.get("FROM_DATE").getDate()));
      oFacTrngDetailBean.setFacultyId(oRow.get("hrm_facm_id").getString());
      oFacTrngDetailBean.setDisabbutFaculty("false");
      oFacTrngDetailBean.setTxtToDate(EnrgiseUtil.convertToString(oRow.get("TO_DATE").getDate()));
      oFacTrngDetailBean.setDisabbutTxtFromDate("false");
      oFacTrngDetailBean.setTxtStartTime(oRow.get("START_TIME").getString());
      oFacTrngDetailBean.setDisabbutTxtToDate("false");
      oFacTrngDetailBean.setTxtEndTime(oRow.get("END_TIME").getString());
      oFacTrngDetailBean.setTxtAverageRating(oRow.get("AVERAGE_RATING").getString());
      oFacTrngDetailBean.setTxtNameOfFaculty(oRow.get("FACULTY_NAME").getString());
      oFacTrngDetailBean.setTxtSkillArea(oRow.get("SKILL_AREA").getString());
      arylstHrmFacTrngDetail.add(oFacTrngDetailBean);
    } 
    return arylstHrmFacTrngDetail;
  }
  
  public ArrayList getHrFacTrngDetailByFacId(String sId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmFacTrngDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sId));
    arylstParameters.add(new DBObject(2, 2, -10));
    arylstParameters.add(new DBObject(3, 2, 12));
    arylstParameters.add(new DBObject(4, 2, 12));
    arylstParameters.add(new DBObject(5, 2, 4));
    ArrayList arylstOutArray = oBean.callProc(arylstParameters, "HRMFACTRNGDTL.proc_GetFacTrngByFacId(?,?,?,?,?)");
    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();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmFacTrngDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngFacTrngDtlBean oFacTrngDetailBean = new HrmTrngFacTrngDtlBean();
      oFacTrngDetailBean.setDetailId(oRow.get("SRL_NO").getString());
      String datenewformat = formatter.format(oRow.get("FROM_DATE").getDate());
      oFacTrngDetailBean.setTxtFromDate(datenewformat);
      String datenewformat1 = formatter.format(oRow.get("TO_DATE").getDate());
      oFacTrngDetailBean.setTxtToDate(datenewformat1);
      oFacTrngDetailBean.setTxtStartTime(oRow.get("START_TIME").getString());
      oFacTrngDetailBean.setTxtEndTime(oRow.get("END_TIME").getString());
      oFacTrngDetailBean.setTxtAverageRating(oRow.get("AVERAGE_RATING").getString());
      oFacTrngDetailBean.setTxtNameOfFaculty(oRow.get("FACULTY_FIRST_NAME").getString());
      oFacTrngDetailBean.setTxtSkillArea(oRow.get("SKILL_AREA").getString());
      arylstHrmFacTrngDetail.add(oFacTrngDetailBean);
    } 
    return arylstHrmFacTrngDetail;
  }
  
  public ArrayList getHrFacTrngDetailByFacIdCalId(String sId, String sFacId) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    int count = 0;
    BaseDetailVO oBaseDetailVO = null;
    ArrayList arylstHrmFacTrngDetail = null;
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sId));
    arylstParameters.add(new DBObject(2, 1, 12, sFacId));
    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, "HRMFACTRNGDTL.proc_GetFacTrngByCalFacId(?,?,?,?,?,?)");
    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();
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    while (itrBean.hasNext()) {
      if (count == 0)
        arylstHrmFacTrngDetail = new ArrayList(); 
      count++;
      oRow = itrBean.next();
      HrmTrngFacTrngDtlBean oFacTrngDetailBean = new HrmTrngFacTrngDtlBean();
      oFacTrngDetailBean.setDetailId(oRow.get("SRL_NO").getString());
      String datenewformat = formatter.format(oRow.get("FROM_DATE").getDate());
      oFacTrngDetailBean.setTxtFromDate(datenewformat);
      String datenewformat1 = formatter.format(oRow.get("TO_DATE").getDate());
      oFacTrngDetailBean.setTxtToDate(datenewformat1);
      oFacTrngDetailBean.setTxtStartTime(oRow.get("START_TIME").getString());
      oFacTrngDetailBean.setTxtEndTime(oRow.get("END_TIME").getString());
      oFacTrngDetailBean.setTxtAverageRating(oRow.get("AVERAGE_RATING").getString());
      oFacTrngDetailBean.setTxtNameOfFaculty(oRow.get("FACULTY_FIRST_NAME").getString());
      oFacTrngDetailBean.setTxtSkillArea(oRow.get("SKILL_AREA").getString());
      arylstHrmFacTrngDetail.add(oFacTrngDetailBean);
    } 
    return arylstHrmFacTrngDetail;
  }
  
  public LovVO getHrmTrngFacultyLOVdata(LovQueryVO oLovQueryVO) throws EnrgiseApplicationException, EnrgiseSystemException {
    LovVO oLovVO = new LovVO();
    ArrayList arylstHeaderNames = new ArrayList();
    arylstHeaderNames.add("Course Id");
    arylstHeaderNames.add("hrm.HrmFacTrngDtl.nameOfFaculty");
    oLovVO.setHeaderList(arylstHeaderNames);
    ArrayList arylstVisibility = new ArrayList();
    arylstVisibility.add("H");
    arylstVisibility.add("V");
    oLovVO.setVisibilityList(arylstVisibility);
    int count = 0;
    ArrayList arylstParameters = new ArrayList();
    String instId = null;
    String sId = null;
    String sQuerySearch1 = new String();
    String sQuerySearch2 = new String();
    if (oLovQueryVO.getSearchField1() != null)
      sQuerySearch1 = oLovQueryVO.getSearchField1(); 
    DBUtilitiesBean oBean = new DBUtilitiesBean();
    arylstParameters = new ArrayList();
    arylstParameters.add(new DBObject(1, 1, 12, sQuerySearch1));
    arylstParameters.add(new DBObject(2, 1, 12, instId));
    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, "HRMTRNGLOV.proc_GetTrngFacultyLOV(?,?,?,?,?,?)");
    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("FACULTY_NAME").getString());
      arylstList.add(oLOVBean);
    } 
    oLovVO.setDetailList(arylstList);
    return oLovVO;
  }
  
  public void initializeBOImpl() {
    this.headerTable = "HRM_TRNG_FAC_DTL";
  }
  
  public void saveDetailImpl(String sHeaderPrimaryKey, String sScreenName, ArrayList arylstoDetailBeanArray) throws EnrgiseSystemException {
    if (sScreenName.equalsIgnoreCase("HrmTrngFacTrngDtl"))
      saveHrmFacTrngDetail(sHeaderPrimaryKey, arylstoDetailBeanArray); 
  }
  
  private void saveHrmFacTrngDetail(String sHeaderPrimaryKey, ArrayList arylstoDetailBeanArray) throws EnrgiseSystemException {
    boolean bInsert = false;
    boolean bUpdate = false;
    boolean bDelete = false;
    ArrayList arylstParameters = new ArrayList();
    DBUtilitiesBean oBean = null;
    DBUtilitiesBean oBean1 = null;
    Iterator itrBean = arylstoDetailBeanArray.iterator();
    while (itrBean.hasNext()) {
      HrmTrngFacTrngDtlBean oHrmTrngFacTrngDtlBean = itrBean.next();
      if (oHrmTrngFacTrngDtlBean.getStatus().equals("N")) {
        if (!bInsert) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMFACTRNGDTL.proc_UpsertHrFacTrngDtl(?,?,?,?,?,?,?,?,?,?,?)");
          bInsert = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "I"));
        arylstParameters.add(new DBObject(2, 1, 12, null));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngFacTrngDtlBean.getFacultyId()));
        arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngFacTrngDtlBean.getTxtFromDate())));
        arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngFacTrngDtlBean.getTxtToDate())));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmTrngFacTrngDtlBean.getTxtStartTime()));
        arylstParameters.add(new DBObject(8, 1, 12, oHrmTrngFacTrngDtlBean.getTxtEndTime()));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmTrngFacTrngDtlBean.getTxtSkillArea()));
        arylstParameters.add(new DBObject(10, 1, 12, "100"));
        arylstParameters.add(new DBObject(11, 1, 12, "100"));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmTrngFacTrngDtlBean.getStatus().equals("U")) {
        if (!bUpdate) {
          oBean = new DBUtilitiesBean();
          oBean.createBatch("HRMFACTRNGDTL.proc_UpsertHrFacTrngDtl(?,?,?,?,?,?,?,?,?,?,?)");
          bUpdate = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, "U"));
        arylstParameters.add(new DBObject(2, 1, 12, oHrmTrngFacTrngDtlBean.getDetailId()));
        arylstParameters.add(new DBObject(3, 1, 12, sHeaderPrimaryKey));
        arylstParameters.add(new DBObject(4, 1, 12, oHrmTrngFacTrngDtlBean.getFacultyId()));
        arylstParameters.add(new DBObject(5, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngFacTrngDtlBean.getTxtFromDate())));
        arylstParameters.add(new DBObject(6, 1, 93, EnrgiseUtil.convertToSqlDate(oHrmTrngFacTrngDtlBean.getTxtToDate())));
        arylstParameters.add(new DBObject(7, 1, 12, oHrmTrngFacTrngDtlBean.getTxtStartTime()));
        arylstParameters.add(new DBObject(8, 1, 12, oHrmTrngFacTrngDtlBean.getTxtEndTime()));
        arylstParameters.add(new DBObject(9, 1, 12, oHrmTrngFacTrngDtlBean.getTxtSkillArea()));
        arylstParameters.add(new DBObject(10, 1, 12, "100"));
        arylstParameters.add(new DBObject(11, 1, 12, "100"));
        oBean.addToBatch(arylstParameters);
        continue;
      } 
      if (oHrmTrngFacTrngDtlBean.getStatus().equals("D")) {
        if (!bDelete) {
          oBean1 = new DBUtilitiesBean();
          oBean1.createBatch("HRMFACTRNGDTL.proc_DeleteFacTrngDtl(?)");
          bDelete = true;
        } 
        arylstParameters = new ArrayList();
        arylstParameters.add(new DBObject(1, 1, 12, oHrmTrngFacTrngDtlBean.getDetailId()));
        oBean1.addToBatch(arylstParameters);
      } 
    } 
    if (bInsert)
      oBean.executeBatch(); 
    if (bUpdate)
      oBean.executeBatch(); 
    if (bDelete)
      oBean1.executeBatch(); 
  }
  
  public void updateHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    System.out.println("Update ille!");
  }
  
  public String saveNewHeaderImpl(BaseHeaderBean oBaseHeaderBean) throws EnrgiseSystemException {
    return "saveNewHeaderImpl ille!";
  }
  
  public void additionalFieldValidationImpl(BaseHeaderBean oBaseHeaderBean, Timestamp oWhenPicked, String sScreenName, String sScreenMode, boolean bHeaderDataChanged, ArrayList arylstoDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstList = new ArrayList();
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        if (sScreenName.equalsIgnoreCase("HrmTrngFacTrngDtl")) {
          Iterator itrBean1 = arylstoDetailBeanArray.iterator();
          int rowCount = 1;
          while (itrBean1.hasNext()) {
            HrmTrngFacTrngDtlBean oHrmTrngFacTrngDtlBean = itrBean1.next();
            if (!oHrmTrngFacTrngDtlBean.getStatus().equalsIgnoreCase("D"))
              checkMandatoryDtls(oHrmTrngFacTrngDtlBean, rowCount); 
          } 
          rowCount++;
        }   
  }
  
  private void checkMandatoryDtls(HrmTrngFacTrngDtlBean oHrmTrngFacTrngDtlBean, int rowCount) throws EnrgiseSystemException, EnrgiseApplicationException {
    ArrayList oErrorList = new ArrayList();
    ArrayList oParams = new ArrayList();
    if (!EnrgiseUtil.checkString(oHrmTrngFacTrngDtlBean.getTxtNameOfFaculty())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmFacTrngDtl.nameOfFaculty");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngFacTrngDtlBean.getTxtFromDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmFacTrngDtl.fromDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngFacTrngDtlBean.getTxtToDate())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmFacTrngDtl.toDate");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngFacTrngDtlBean.getTxtStartTime())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmFacTrngDtl.startTime");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngFacTrngDtlBean.getTxtEndTime())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmFacTrngDtl.endTime");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    if (!EnrgiseUtil.checkString(oHrmTrngFacTrngDtlBean.getTxtSkillArea())) {
      MessageKey oMessageKey = new MessageKey("hrm.HrmFacTrngDtl.skillArea");
      oParams = new ArrayList();
      oParams.add(oMessageKey);
      oParams.add(String.valueOf(rowCount));
      oErrorList.add(new EnrgiseMessageKeyException("wenrgise.common.detail.mandatoryFieldMissing", oParams, "E"));
    } 
    reportError(oErrorList);
  }
  
  public String saveHeaderImpl(BaseHeaderBean oBaseHeaderBean, String ScreenMode) throws EnrgiseSystemException {
    return "save";
  }
  
  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 arylstoDetailBeanArray, boolean bDetailDataChanged, Timestamp oDetailPicked) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList arylstErrorList = new ArrayList();
    HrmTrngFacTrngHdrBean oHrmTrngFacTrngHdrBean = (HrmTrngFacTrngHdrBean)oBaseHeaderBean;
    if (bDetailDataChanged)
      if (!sScreenMode.equalsIgnoreCase("D"))
        checkDatesConstraintForDtl(oHrmTrngFacTrngHdrBean, arylstoDetailBeanArray, arylstErrorList);  
    reportError(arylstErrorList);
  }
  
  private void checkDatesConstraintForDtl(HrmTrngFacTrngHdrBean oHrmTrngFacTrngHdrBean, ArrayList arylstoDetailBeanArray, ArrayList arylstErrorList) throws EnrgiseApplicationException, EnrgiseSystemException {
    int n = arylstoDetailBeanArray.size();
    Iterator itrBean1 = arylstoDetailBeanArray.iterator();
    int rowCount = 1;
    while (itrBean1.hasNext()) {
      HrmTrngFacTrngDtlBean oHrmTrngFacTrngDtlBean = itrBean1.next();
      DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
      checkTime(oHrmTrngFacTrngDtlBean, rowCount);
      int dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngFacTrngDtlBean.getTxtFromDate(), oHrmTrngFacTrngHdrBean.getStartDate());
      if (dateFlag == -1 && dateFlag != -2)
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.fromCrsDate.dateConstraintViolated")); 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngFacTrngDtlBean.getTxtFromDate(), oHrmTrngFacTrngHdrBean.getEndDate());
      if (dateFlag == 1 && dateFlag != -2)
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.fromCrsDate.dateConstraintViolated")); 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngFacTrngDtlBean.getTxtToDate(), oHrmTrngFacTrngHdrBean.getStartDate());
      if (dateFlag == -1 && dateFlag != -2)
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.toCrsDate.dateConstraintViolated")); 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngFacTrngDtlBean.getTxtToDate(), oHrmTrngFacTrngHdrBean.getEndDate());
      if (dateFlag == 1 && dateFlag != -2)
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.toCrsDate.dateConstraintViolated")); 
      dateFlag = EnrgiseUtil.compareDates(dateFormat, oHrmTrngFacTrngDtlBean.getTxtToDate(), oHrmTrngFacTrngDtlBean.getTxtFromDate());
      if (dateFlag == -1 && dateFlag != -2)
        arylstErrorList.add(new EnrgiseApplicationException("wenrgise.toFromDate.dateConstraintViolated")); 
      rowCount++;
    } 
    reportError(arylstErrorList);
  }
  
  public void checkTime(HrmTrngFacTrngDtlBean oHrmTrngFacTrngDtlBean, int rowCount) throws EnrgiseApplicationException, EnrgiseSystemException {
    ArrayList oList = new ArrayList();
    HrmCommonBO oHrmCommonBO = new HrmCommonBO();
    if (!oHrmCommonBO.checkTimeFormat(oHrmTrngFacTrngDtlBean.getTxtStartTime())) {
      ArrayList oParams = new ArrayList();
      oParams.add(new Integer(rowCount));
      throw new EnrgiseApplicationException("hrm.common.incorrectTimeFormat", oParams, "E");
    } 
    if (!oHrmCommonBO.checkTimeFormat(oHrmTrngFacTrngDtlBean.getTxtEndTime())) {
      ArrayList oParams = new ArrayList();
      oParams.add(new Integer(rowCount));
      throw new EnrgiseApplicationException("hrm.common.incorrectTimeFormat", oParams, "E");
    } 
    if (!oHrmCommonBO.checkTimeValue(oHrmTrngFacTrngDtlBean.getTxtStartTime())) {
      ArrayList oParams = new ArrayList();
      oParams.add(new Integer(rowCount));
      throw new EnrgiseApplicationException("hrm.common.incorrectTimeFormatHour", oParams, "E");
    } 
    if (!oHrmCommonBO.checkTimeValue(oHrmTrngFacTrngDtlBean.getTxtEndTime())) {
      ArrayList oParams = new ArrayList();
      oParams.add(new Integer(rowCount));
      throw new EnrgiseApplicationException("hrm.common.incorrectTimeFormatHour", oParams, "E");
    } 
    reportError(oList);
  }
}
