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

#pragma hdrstop

#include "CDSParkF.h"
#include "VMSOprMainLibF.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 PRK_PLCE_NMBR, PRK_PLCE_MANAGE_NO,   \r\n"
           "       PRK_PLCE_NM, VMS_DSPL_NM, DEL_YN     \r\n"
           "  FROM TB_PRK_PLCE                          \r\n"
           " WHERE DEL_YN    = 'N'                      \r\n"
           "   AND PIS_TYPE != 'N'                      \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 PRK_PLCE_NMBR = pADO->FieldByName("PRK_PLCE_NMBR")->AsString.Trim();
				TCDSPark *pObj = FLists.Find(PRK_PLCE_NMBR);
                if (!pObj)
                {
                    pObj = new TCDSPark();

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

                pObj->PRK_PLCE_MANAGE_NO = pADO->FieldByName("PRK_PLCE_MANAGE_NO")->AsString.Trim();
                pObj->PRK_PLCE_NM        = pADO->FieldByName("PRK_PLCE_NM")->AsString.Trim();
                pObj->VMS_DSPL_NM        = pADO->FieldByName("VMS_DSPL_NM")->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;
}
//---------------------------------------------------------------------------

