/******************************************************************************
Function Name  :  RepositionSubEntity
Input(s)       :  CBaseEntityTA* pouRefSubEntity
                  CBaseEntityTA* pouCurrSubEntity
Output         :  HRESULT - returns the New Entity ID
Functionality  :  Reposition pouRefSubEntity after pouCurrSubEntity
Member of      :  CTestCaseEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
Codetag        :  CS021
******************************************************************************/
HRESULT CTestCaseEntity::RepositionSubEntity(CBaseEntityTA* pouRefSubEntity, CBaseEntityTA* pouCurrSubEntity)
{
    //DESIGN:: First Take copy of Data and delete it from current position and add at required place 
    UINT unCount = (UINT)m_ouData.m_odTAEntityList.GetCount();
    for(UINT i=0; i<unCount; i++)
    {
        POSITION pos = m_ouData.m_odTAEntityList.FindIndex(i);
        CBaseEntityTA* pEntity = m_ouData.m_odTAEntityList.GetAt(pos);
        if(pEntity->GetID() == pouRefSubEntity->GetID())
        {
            m_ouData.m_odTAEntityList.RemoveAt(pos);
            break;
        }
    }
    if(pouCurrSubEntity == NULL)        //Insert At First Index;
    {
        m_ouData.m_odTAEntityList.AddHead(pouRefSubEntity);
    }
    
    else
    {
        for(UINT i=0; i<unCount; i++)
        {
            POSITION pos = m_ouData.m_odTAEntityList.FindIndex(i);
            CBaseEntityTA* pEntity = m_ouData.m_odTAEntityList.GetAt(pos);
            if(pEntity->GetID() == pouCurrSubEntity->GetID())
            {
                m_ouData.m_odTAEntityList.InsertAfter(pos, pouRefSubEntity);
                break;
            }
        }
    }
    return pouRefSubEntity->GetID();
}
/******************************************************************************
Function Name  :  bParseTestSetup
Input(s)       :  INT nIndex
Output         :  BOOL
Functionality  :  Loads The
Member of      :  CTSExecutorChildFrame
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  07/04/2011
Modifications  :
Code Tag       :
******************************************************************************/
BOOL CTSExecutorChildFrame::bParseTestSetup(INT nIndex)
{
    BOOL bResult = FALSE;
    STestSetupInfo sTSInfo;

    if( m_ouTSExecutor.GetTestSetupInfo(nIndex, sTSInfo) == S_OK)
    {
        HTREEITEM hTSItem = m_odTreeView->InsertTreeItem(m_hParentTreeItem, sTSInfo.m_omstrName, NULL, def_INDEX_TESTSETUPIMAGE,
                            def_INDEX_TESTSETUPIMAGE, sTSInfo.m_dwID);
        m_odTreeView->GetTreeCtrl().SetCheck(hTSItem, sTSInfo.m_bEnable);

        for(INT i = 0; i < sTSInfo.m_nTCCount; i++)
        {
            CBaseEntityTA* pouTCData;
            CTestCaseData ouTCData;

            if(m_ouTSExecutor.GetTestCaseInfo(sTSInfo.m_dwID, i, &pouTCData) == S_OK)
            {
                pouTCData->GetEntityData(TEST_CASE, &ouTCData);
                HTREEITEM hTCItem =  m_odTreeView->InsertTreeItem(hTSItem, ouTCData.m_omTitle, NULL, def_INDEX_TESTCASEIMAGE,
                                     def_INDEX_TESTCASEIMAGE, pouTCData->GetID());
                m_odTreeView->GetTreeCtrl().SetCheck(hTCItem, pouTCData->bGetEnableStatus());
            }
        }

        bResult = TRUE;
    }

    return bResult;
}
/******************************************************************************
Function Name  :  DeleteSubEntry
Input(s)       :  CBaseEntityTA* pouSubEntryObj
Output         :  HRESULT
Functionality  :  Deletes a Subentry 
Member of      :  CTestCaseEntity
Friend of      :  -
Author(s)      :  Venkatanarayana Makam
Date Created   :  06/04/2011
Modifications  :  
Codetag        :  CS018
******************************************************************************/
HRESULT CTestCaseEntity::DeleteSubEntry(CBaseEntityTA* pouSubEntryObj)
{
    HRESULT hResult  = S_FALSE;
    INT nCount = (INT)m_ouData.m_odTAEntityList.GetCount();
    for(int i = 0; i < nCount; i++)
    {
        POSITION pos = m_ouData.m_odTAEntityList.FindIndex(i);
        CBaseEntityTA *pEntity = m_ouData.m_odTAEntityList.GetAt(pos);
        if(pEntity->GetID() == pouSubEntryObj->GetID())
        {
            m_ouData.m_odTAEntityList.RemoveAt(pos);
            hResult = S_OK;
            break;
        }
    }
    return hResult;
}