//---------------------------------------------------------------------------


#pragma hdrstop

#include "CDSParkF.h"
#include "AppGlobalF.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

//---------------------------------------------------------------------------
void TCDSPark::Init()
{
}
//---------------------------------------------------------------------------
TCDSParkManager *CDSParkManager = NULL;
//---------------------------------------------------------------------------

/*
* Manager
*/
TCDSParkManager::TCDSParkManager()
{
}
//---------------------------------------------------------------------------
TCDSParkManager::~TCDSParkManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------
void TCDSParkManager::Init()
{
    FOR_STL(TCDSPark*, pObj, FLists)
    {
        pObj->Init();
    }
}
//---------------------------------------------------------------------------
bool TCDSParkManager::LoadFromDb(TADOConnection *ADbConn)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                    \r\n"
           "  FROM TB_PRLT_CTLR         \r\n"
           " WHERE DEL_YN       = 'N'   \r\n"
           "   AND REAL_DATA_YN = 'Y'   \r\n";

    FLists.Lock();
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
                String PRLT_CTLR_NMBR = pADO->FieldByName("PRLT_CTLR_NMBR")->AsString.Trim();
				TCDSPark *pObj = FLists.Find(PRLT_CTLR_NMBR);
                if (!pObj)
                {
                    pObj = new TCDSPark();

                    pObj->PRLT_CTLR_NMBR = PRLT_CTLR_NMBR;
                    FLists.Push(pObj->PRLT_CTLR_NMBR, pObj);
                }

                pObj->PRLT_CTLR_ID = pADO->FieldByName("PRLT_CTLR_ID")->AsString.Trim();
                pObj->PRLT_NM      = pADO->FieldByName("PRLT_NM")->AsString.Trim();
                pObj->REAL_DATA_YN = pADO->FieldByName("REAL_DATA_YN")->AsString.Trim();
                pObj->DEL_YN       = pADO->FieldByName("DEL_YN")->AsString.Trim();
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TCDSParkManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TCDSParkManager::LoadFromDb", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

    return true;
}
//---------------------------------------------------------------------------

