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

#pragma hdrstop

#include "CDSAtmpF.h"
#include "VMSOprMainLibF.h"

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

#pragma package(smart_init)

//---------------------------------------------------------------------------
void TCDSAtmp::Init()
{
    SUCCESS         = false;
    MSRM_DT         = "";
    MSRM_SYST_NM    = "";
    SO2_VAL         = "";
    CO_VAL          = "";
    NO2_VAL         = "";
    O3_VAL          = "";
    PM10_VAL        = "";
    PM10_24HH_VAL   = "";
    PM25_VAL        = "";
    PM25_24HH_VAL   = "";
    INTG_ATMP_VAL   = "";
    INTG_ATMP_GRAD  = "";
    SO2_GRAD        = "";
    CO_GRAD         = "";
    O3_GRAD         = "";
    NO2_GRAD        = "";
    PM10_24HH_GRAD  = "";
    PM25_24HH_GRAD  = "";
    PM10_1HH_GRAD   = "";
    PM25_1HH_GRAD   = "";
}
//---------------------------------------------------------------------------
TCDSAtmpManager *CDSAtmpManager = NULL;
//---------------------------------------------------------------------------

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

    sQry = "SELECT *                    \r\n"
           "  FROM TB_ATMP_PLTN_STTN    \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 ATMP_STTN_NMBR = pADO->FieldByName("ATMP_STTN_NMBR")->AsString.Trim();
				TCDSAtmp *pObj = FLists.Find(ATMP_STTN_NMBR);
                if (!pObj)
                {
                    pObj = new TCDSAtmp();

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

                pObj->ATMP_STTN_NM   = pADO->FieldByName("ATMP_STTN_NM")->AsString.Trim();
                pObj->VMS_DISP_NM    = pADO->FieldByName("VMS_DISP_NM")->AsString.Trim();
                pObj->ATMP_STTN_ADDR = pADO->FieldByName("ATMP_STTN_ADDR")->AsString.Trim();
                pObj->DEL_YN         = pADO->FieldByName("DEL_YN")->AsString.Trim();
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TCDSAtmpManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TCDSAtmpManager::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;
}
//---------------------------------------------------------------------------

