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

#pragma hdrstop

#include "CDSFacilityF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

TItsRegFacility::TItsRegFacility()
{
    UnRegisterd = "N";
    GridIndex   = -1;
    Clear();
}
//---------------------------------------------------------------------------
TItsRegFacility::~TItsRegFacility()
{
}
//---------------------------------------------------------------------------
void TItsRegFacility::Clear()
{
#if 0
    Type        = "";
    Id          = "";
    Name        = "";
    DelYn       = ""
    UnRegisterd = "N";
#endif
}
//---------------------------------------------------------------------------


TItsFacility::TItsFacility()
{
    FCommStatus = "CMS2";     // 장비 통신상태값
    FDoorStatus = "CMS2";     // 장비 Door상태값
	GridIndex  = -1;         // 그리드 인덱스
    StatusGridIndex = -1;
    Deleted = "N";
    Clear();
}
//---------------------------------------------------------------------------
void TItsFacility::Clear()
{
#if 0
    FCLT_ID      = "";		// FCLT_ID VARCHAR(50 BYTE) NOT NULL,	'시설물 ID';
    RFID_ID      = "";		// RFID_ID VARCHAR(50 BYTE) NOT NULL,	'시설물 ID';
    FCLT_TYPE    = "";		// FCLT_TYPE VARCHAR(7 BYTE) NOT NULL, '시설물유형';
    FCLT_LCTN    = "";		// FCLT_LCTN VARCHAR(100 BYTE),        '시설물 위치';
    RSCE_YN      = "";		// RSCE_YN CHAR(1 BYTE) DEFAULT 'N',   '현장자산유무';
    MDL_NM       = "";     // MDL_NM VARCHAR(30 BYTE),            '모델명';
    USE_YEAR     = "";		// USE_YEAR NUMBER(3),                 '사용년수';
    INWR_DT      = "";		// INWR_DT VARCHAR(14 BYTE),           '입고일시';
    OTWR_DT      = "";		// OTWR_DT VARCHAR(14 BYTE),           '출고일시';
    ISTL_DT      = "";		// ISTL_DT VARCHAR(14 BYTE),           '설치일시';
    TAKT_DT      = "";		// TAKT_DT VARCHAR(14 BYTE),           '반출일시';
    TAKT_RESN    = "";		// TAKT_RESN VARCHAR(100 BYTE),        '반출사유';
    TAKN_DT      = "";		// TAKN_DT VARCHAR(14 BYTE),           '반입일시';
    ABDN_DT      = "";		// ABDN_DT VARCHAR(14 BYTE),           '폐기일시';
    ADTN_NM      = "";		// ADTN_NM VARCHAR(30 BYTE),           '추가자명';
    ADTN_DT      = "";		// ADTN_DT VARCHAR(14 BYTE),           '추가일시';
    CHNG_NM      = "";		// CHNG_NM VARCHAR(30 BYTE),           '변경자명';
    CHNG_DT      = "";		// CHNG_DT VARCHAR(14 BYTE),           '변경일시';
    AMT          = "";     // AMT NUMBER(15),                     '금액';
    DEL_YN       = "";     // DEL_YN CHAR(1 BYTE) DEFAULT 'N',    '삭제여부';
    ISTL_CMPY_ID = "";     // ISTL_CMPY_ID VARCHAR(30 BYTE),      '설치업체ID';
    MNFC_CMPY_ID = "";     // PRDC_CMPY_ID VARCHAR(30 BYTE)       '제조업체ID';
    ISTL_LCTN_ADDR = "";

    CommStatus = "CMS2";   // 장비 통신상태값
    DoorStatus = "CMS2";   // 장비 Door상태값

	GridIndex  = -1;	    // 메인폼에 뿌려지는 그리드 인덱스

#endif
}
//---------------------------------------------------------------------------
TItsFacility::~TItsFacility()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TItsFacilityManager *ItsFacilityManager = NULL;
//---------------------------------------------------------------------------

/*
* Facility Manager
*/
TItsFacilityManager::TItsFacilityManager()
{
}
//---------------------------------------------------------------------------
TItsFacilityManager::~TItsFacilityManager()
{
    FRegLists.RemoveAll();
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------
void TItsFacilityManager::SetCenterId(String ACenterId)
{
    CenterId = ACenterId;
}
//---------------------------------------------------------------------------
bool TItsFacilityManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    try
    {
        FLocalCctvCnt = 0;

        FRseLists.Lock();

        FAviLists.Lock();
        FDsrcLists.Lock();

        FBitLists.Lock();
        FSigLists.Lock();
        FSigDetLists.Lock();

        FPisLists.Lock();
        FPcsLists.Lock();

        FRegLists.Lock();
        FLists.Lock();

        FRseLists.RemoveAll();

        FAviLists.RemoveAll();
        FDsrcLists.RemoveAll();

        FBitLists.RemoveAll();
        FSigLists.RemoveAll();
        FSigDetLists.RemoveAll();

        FPisLists.RemoveAll();
        FPcsLists.RemoveAll();

        FRegLists.RemoveAll();
        FLists.RemoveAll();
    }
    __finally
    {
        FRseLists.UnLock();

        FAviLists.UnLock();
        FDsrcLists.UnLock();

        FBitLists.UnLock();
        FSigLists.UnLock();
        FSigDetLists.UnLock();

        FPisLists.UnLock();
        FPcsLists.UnLock();

        FRegLists.UnLock();
        FLists.UnLock();
    }

    LoadFacilityReg(ADbConn);       // 시설물 개별 테이블 조회(ID, NAME 등)
    LoadFacilityMaster(ADbConn);    // TB_FCLT_INFR

    LoadFacilityVds(ADbConn);
    LoadFacilityCctv(ADbConn);
    LoadFacilityVms(ADbConn);

    LoadFacilityWebCam(ADbConn);
    LoadFacilityCrsCam(ADbConn);
    LoadFacilityPark(ADbConn);

#ifdef USE_RSE
    LoadFacilityRse(ADbConn);
#endif
#ifdef USE_AVI
    LoadFacilityAvi(ADbConn);
#endif
#ifdef USE_DSRC
    LoadFacilityDsrc(ADbConn);
#endif
#ifdef USE_BIT
    LoadFacilityBit(ADbConn);
#endif
#ifdef USE_SIG
    LoadFacilitySig(ADbConn);
#endif
#ifdef USE_SIGDET
    LoadFacilitySigDet(ADbConn);
#endif
#ifdef USE_PVMS
    LoadFacilityPvms(ADbConn);
#endif
#ifdef USE_PVDS
    LoadFacilityPvds(ADbConn);
#endif

    CheckFacility();

    return true;
}
//---------------------------------------------------------------------------
bool TItsFacilityManager::CheckFacility()
{
    try
    {
        FLists.Lock();
        FOR_STL(TItsFacility *, pFacility, FLists)
        {
            TItsRegFacility *pRegFacility = FRegLists.Find(pFacility->FCLT_TYPE + pFacility->FCLT_ID);
            if (!pRegFacility)
            {
                pFacility->Deleted = "Y";
            }
        }
    }
    __finally
    {
        FLists.UnLock();
    }

    try
    {
        FRegLists.Lock();
        FOR_STL(TItsRegFacility *, pRegFacility, FRegLists)
        {
            TItsFacility *pFacility = FLists.Find(pRegFacility->Id);
            if (!pFacility)
            {
                pRegFacility->UnRegisterd = "Y";
            }
        }
    }
    __finally
    {
        FRegLists.UnLock();
    }
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityReg(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT '' AS FAC_TYPE, '' AS FAC_ID, '' AS FAC_NM, '' AS DEL_YN                             \r\n"
           "  FROM DUAL                                                                                 \r\n"
           " WHERE 1 = 0                                                                                \r\n"
#ifdef USE_CCTV
#if 0
           "UNION                                                                                       \r\n"
           "SELECT 'CCTV' AS FAC_TYPE, CCTV_CTLR_ID AS FAC_ID, CCTV_NM AS FAC_NM, DEL_YN                \r\n"
           "  FROM TB_CCTV_CTLR                                                                         \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#else
           "UNION                                                                                       \r\n"
           "SELECT 'CCTV' AS FAC_TYPE, CCTV_CTLR_ID AS FAC_ID, ISTL_LCTN_NM AS FAC_NM, DEL_YN           \r\n"
           "  FROM TB_CCTV_CTLR                                                                         \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#endif
#ifdef USE_VDS
           "UNION                                                                                       \r\n"
           "SELECT 'VDS' AS FAC_TYPE, VDS_CTLR_ID AS FAC_ID, VDS_NM AS FAC_N, DEL_YN                    \r\n"
           "  FROM TB_VDS_CTLR                                                                          \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#ifdef USE_VMS
           "UNION                                                                                       \r\n"
           "SELECT 'VMS'  AS FAC_TYPE, VMS_CTLR_ID  AS FAC_ID, VMS_NM AS FAC_NM, DEL_YN                 \r\n"
           "  FROM TB_VMS_CTLR                                                                          \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#ifdef USE_WCAM
           "UNION                                                                                       \r\n"
           "SELECT 'WCAM' AS FAC_TYPE, WCAM_CTLR_ID AS FAC_ID, WCAM_NM AS FAC_NM, DEL_YN                \r\n"
           "  FROM TB_WCAM_CTLR                                                                         \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#ifdef USE_CCAM
           "UNION                                                                                       \r\n"
           "SELECT 'CCAM' AS FAC_TYPE, CCAM_CTLR_ID AS FAC_ID, CCAM_NM AS FAC_NM, DEL_YN                \r\n"
           "  FROM TB_CCAM_CTLR                                                                         \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#ifdef USE_AVI
           "UNION                                                                                       \r\n"
           "SELECT 'AVI' AS FAC_TYPE, AVI_ID AS FAC_ID, AVI_LCTN_NM AS FAC_NM, DEL_YN                   \r\n"
           "  FROM TB_AVI_CTLR                                                                          \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#ifdef USE_DSRC
           "UNION                                                                                       \r\n"
           "SELECT 'DSRC' AS FAC_TYPE, RSE_ID AS FAC_ID, ISTL_LCTN_NM AS FAC_NM, DEL_YN                 \r\n"
           "  FROM TB_RSE_MSTR                                                                          \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
#ifdef USE_BIT
           "UNION                                                                                       \r\n"
           "SELECT 'BIT' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID, FCLT_LCTN AS FAC_NM, 'N' AS DEL_YN    \r\n"
           "  FROM VW_BIT                                                                               \r\n"
#if 0
           "SELECT 'BIT' AS FAC_TYPE, TO_CHAR(A.BIT_ID) AS FAC_ID, B.STOP_NAME AS FAC_NM,               \r\n"
           "       'N' AS DEL_YN                                                                        \r\n"
           "  FROM BIT A, BUSSTOP B                                                                     \r\n"
           " WHERE 1=1                                                                                  \r\n"
           "   AND A.INSTALL_STOP_ID = B.STOP_ID                                                        \r\n"
           "   AND B.USE_FLAG = '1'                                                                     \r\n"
#endif
#endif
#ifdef USE_SIG
           "UNION                                                                                       \r\n"
           "SELECT 'SIG' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID, FCLT_LCTN AS FAC_NM, 'N' AS DEL_YN    \r\n"
           "  FROM VW_SIG_CTLR                                                                          \r\n"
#endif
#ifdef USE_PVMS
           "UNION                                                                                       \r\n"
           "SELECT 'PVMS' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID, FCLT_LCTN AS FAC_NM, 'N' AS DEL_YN   \r\n"
           "  FROM VW_PIS_VMS                                                                           \r\n"
#endif
#ifdef USE_PVDS
           "UNION                                                                                       \r\n"
           "SELECT 'PVDS' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID, FCLT_LCTN AS FAC_NM, 'N' AS DEL_YN   \r\n"
           "  FROM VW_PIS_CONT                                                                          \r\n"
#endif
#ifdef USE_SIGDET
           "UNION                                                                                       \r\n"
           "SELECT 'LVD' AS FAC_TYPE, FCLT_ID AS FAC_ID, FCLT_LCTN AS FAC_NM, 'N' AS DEL_YN             \r\n"
           "  FROM VW_SIG_LVDS                                                                          \r\n"
#endif
#ifdef USE_RSE
           "UNION                                                                                       \r\n"
           "SELECT 'RSE' AS FAC_TYPE, RSEID AS FAC_ID, LOCATION AS FAC_NM, 'N' AS DEL_YN                \r\n"
           "  FROM RSEMST                                                                               \r\n"
#endif
#ifdef USE_PARK
           "UNION                                                                                       \r\n"
           "SELECT 'PARK' AS FAC_TYPE, PRLT_CTLR_ID AS FAC_ID, PRLT_NM AS FAC_NM, DEL_YN                \r\n"
           "  FROM TB_PRLT_CTLR                                                                         \r\n"
           " WHERE DEL_YN = 'N'                                                                         \r\n"
#endif
            ;

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsRegFacility *pRegFacility = new TItsRegFacility();

                pRegFacility->Type  = pADO->FieldByName("FAC_TYPE")->AsString;
                pRegFacility->Id    = pADO->FieldByName("FAC_ID")->AsString;
                pRegFacility->Name  = pADO->FieldByName("FAC_NM")->AsString;
                pRegFacility->DelYn = pADO->FieldByName("DEL_YN")->AsString;

                pRegFacility->GridIndex = -1;

				FRegLists.Push(pRegFacility->Type + pRegFacility->Id, pRegFacility);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityReg", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityReg", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FRegLists.UnLock();
    }

    return true;
}
//---------------------------------------------------------------------------
bool TItsFacilityManager::LoadFacilityMaster(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                     \r\n"
           "  FROM TB_FCLT_INFR          \r\n"
           " WHERE DEL_YN = 'N'          \r\n";

    TFacilityStatus *pStatus;

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsFacility *pFacility = new TItsFacility();

                pFacility->FCLT_ID         = pADO->FieldByName("FCLT_ID")->AsString;
                pFacility->RFID_ID         = pADO->FieldByName("RFID_ID")->AsString;
                pFacility->FCLT_TYPE       = pADO->FieldByName("FCLT_TYPE")->AsString;
                pFacility->FCLT_LCTN       = pADO->FieldByName("FCLT_LCTN")->AsString;
                pFacility->RSCE_YN         = pADO->FieldByName("RSCE_YN")->AsString;
                pFacility->MDL_NM          = pADO->FieldByName("MDL_NM")->AsString;
                pFacility->USE_YEAR        = pADO->FieldByName("USE_YEAR")->AsString;
                if (pFacility->USE_YEAR == "") pFacility->USE_YEAR = "0";
                pFacility->INWR_DT         = pADO->FieldByName("INWR_DT")->AsString;
                pFacility->OTWR_DT         = pADO->FieldByName("OTWR_DT")->AsString;
                pFacility->ISTL_DT         = pADO->FieldByName("ISTL_DT")->AsString;
                pFacility->TAKT_DT         = pADO->FieldByName("TAKT_DT")->AsString;
                pFacility->TAKT_RESN       = pADO->FieldByName("TAKT_RESN")->AsString;
                pFacility->TAKN_DT         = pADO->FieldByName("TAKN_DT")->AsString;
                pFacility->ABDN_DT         = pADO->FieldByName("ABDN_DT")->AsString;
                pFacility->ADTN_NM         = pADO->FieldByName("ADTN_NM")->AsString;
                pFacility->ADTN_DT         = pADO->FieldByName("ADTN_DT")->AsString;
                pFacility->CHNG_NM         = pADO->FieldByName("CHNG_NM")->AsString;
                pFacility->CHNG_DT         = pADO->FieldByName("CHNG_DT")->AsString;
                pFacility->AMT             = pADO->FieldByName("AMT")->AsString;
                pFacility->DEL_YN          = pADO->FieldByName("DEL_YN")->AsString;
                pFacility->ISTL_CMPY_ID    = pADO->FieldByName("ISTL_CMPY_ID")->AsString;
                pFacility->MNFC_CMPY_ID    = pADO->FieldByName("MNFC_CMPY_ID")->AsString;

                pFacility->ISTL_LCTN_ADDR  = pADO->FieldByName("ISTL_LCTN_ADDR")->AsString;

                pFacility->Sts00 = "-";

                pFacility->GridIndex       = -1;	    // 메인폼에 뿌려지는 그리드 인덱스
                pFacility->StatusGridIndex = -1;

                pFacility->Object = NULL;

				FLists.Push(pFacility->FCLT_ID, pFacility);
                pFacility->Completed = true;

                String FCLT_TYPE = pFacility->FCLT_TYPE;
                if (FCLT_TYPE == "VDS" && pFacility->FCLT_ID.Pos("VDC"))
                {
                    FCLT_TYPE = "CRSSVR";
                }
                pStatus = FListStatus.Find(FCLT_TYPE);
                if (!pStatus)
                {
                    pStatus = new TFacilityStatus();
                    pStatus->Type   = FCLT_TYPE;
                    pStatus->Total  = 0;
                    pStatus->Normal = 0;
                    pStatus->Error  = 0;
                    pStatus->Module = 0;
                    pStatus->Collect= 0;

                    FListStatus.Push(FCLT_TYPE, pStatus);
                }
                pStatus->Total++;   /* 전체 갯수를 증가 시킴 */
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityMaster", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityMaster", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }

        FListStatus.UnLock();
        FLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityWebCam(TADOConnection *ADbConn/*=NULL*/)
{
    if (!WCamCtlrManager)
    {
        WCamCtlrManager = new TWCamCtlrManager();
    }

#ifdef USE_WCAM
    TItsFacility *pFacility;

    WCamCtlrManager->LoadFromDb();
    FOR_STL(TWCamCtlr*, pObj, WCamCtlrManager->FLists)
    {
        if (pObj->DEL_YN == "Y") continue;
        pFacility = FLists.Find(pObj->WCAM_CTLR_ID);
        if (!pFacility) continue;

        pFacility->Object = pObj;
    }
#endif
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityCrsCam(TADOConnection *ADbConn/*=NULL*/)
{
    if (!CCamCtlrManager)
    {
        CCamCtlrManager = new TCCamCtlrManager();
    }

#ifdef USE_CCAM
    TItsFacility *pFacility;

    CCamCtlrManager->LoadFromDb();
    FOR_STL(TCCamCtlr*, pObj, CCamCtlrManager->FLists)
    {
        if (pObj->DEL_YN == "Y") continue;
        pFacility = FLists.Find(pObj->CCAM_CTLR_ID);
        if (!pFacility) continue;

        pFacility->Object = pObj;
        pFacility->FCLT_KIND = pObj->TYPE_CD;
    }
#endif
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityCctv(TADOConnection *ADbConn/*=NULL*/)
{
    if (!CctvCtlrManager)
    {
        CctvCtlrManager = new TCctvCtlrManager();
    }

#ifdef USE_CCTV
    TItsFacility *pFacility;

    CctvCtlrManager->LoadFromDb();
    FOR_STL(TCctvCtlr*, pObj, CctvCtlrManager->FLists)
    {
        if (pObj->DEL_YN == "Y") continue;
        pFacility = FLists.Find(pObj->CCTV_CTLR_ID);
        if (!pFacility) continue;

        pFacility->Object = pObj;
        pFacility->FCLT_KIND = pObj->TYPE_CD;
    }
#endif
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityVms(TADOConnection *ADbConn/*=NULL*/)
{
    if (!VmsCtlrManager)
    {
        VmsCtlrManager = new TVmsCtlrManager();
    }

#ifdef USE_VMS
    TItsFacility *pFacility;

    VmsCtlrManager->LoadVmsSize();
    VmsCtlrManager->LoadFromDb();
    VmsCtlrManager->LoadVmsFormUsage();
    VmsCtlrManager->LoadIfscRltn();
    FOR_STL(TVmsCtlr*, pObj, VmsCtlrManager->FLists)
    {
        if (pObj->DEL_YN == "Y") continue;
        pFacility = FLists.Find(pObj->VMS_CTLR_ID);
        if (!pFacility) continue;

        pFacility->Object = pObj;
        pFacility->FCLT_KIND = pObj->TYPE_CD;
    }
#endif
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityVds(TADOConnection *ADbConn/*=NULL*/)
{
    if (!VdsCtlrManager)
    {
        VdsCtlrManager = new TVdsCtlrManager();
    }

#ifdef USE_VDS
    TItsFacility *pFacility;

    VdsCtlrManager->LoadFromDb();
    VdsCtlrManager->LoadFromDtctDb();
    FOR_STL(TVdsCtlr*, pObj, VdsCtlrManager->FLists)
    {
        if (pObj->DEL_YN == "Y") continue;
        pFacility = FLists.Find(pObj->VDS_CTLR_ID);
        if (!pFacility) continue;

        pFacility->Object = pObj;
        pFacility->FCLT_KIND = pObj->TYPE_CD;
    }
#endif
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityRse(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_RSE
    return true;
#endif
    sQry = "SELECT RSEID,                    \r\n"
           "       INSTDT,                   \r\n"
           "       CITYCD,                   \r\n"
           "       REGIONCD,                 \r\n"
           "       AREACD,                   \r\n"
           "       RSEIP,                    \r\n"
           "       (COORDX/10000000) COORDX, \r\n"
           "       (COORDY/10000000) COORDY, \r\n"
           "       RADIUS1,                  \r\n"
           "       RADIUS2,                  \r\n"
           "       COMPCD,                   \r\n"
           "       LOCATION,                 \r\n"
           "       RSECONFIGID,              \r\n"
           "       OBEPARAMID,               \r\n"
           "       PORT,                     \r\n"
           "       BRIDGE,                   \r\n"
           "       COMYN                     \r\n"
           "  FROM RSEMST                    \r\n";
           //" ORDER BY RSEID                  \r\n";

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsRse *pObj = new TItsRse();

                pObj->RSEID		    = pADO->FieldByName("RSEID")->AsString;
                //pObj->INSTDT		= pADO->FieldByName("INSTDT")->AsString;
                pObj->CITYCD		= pADO->FieldByName("CITYCD")->AsString;
                pObj->REGIONCD		= pADO->FieldByName("REGIONCD")->AsString;
                pObj->AREACD		= pADO->FieldByName("AREACD")->AsString;
                pObj->RSEIP		    = pADO->FieldByName("RSEIP")->AsString;
                pObj->COORDX		= pADO->FieldByName("COORDX")->AsString;
                pObj->COORDY		= pADO->FieldByName("COORDY")->AsString;
                pObj->RADIUS1		= pADO->FieldByName("RADIUS1")->AsString;
                pObj->RADIUS2		= pADO->FieldByName("RADIUS2")->AsString;
                //pObj->COMPCD		= pADO->FieldByName("COMPCD")->AsString;
                pObj->LOCATION		= pADO->FieldByName("LOCATION")->AsString;
                //pObj->RSECONFIGID	= pADO->FieldByName("RSECONFIGID")->AsString;
                //pObj->OBEPARAMID	= pADO->FieldByName("OBEPARAMID")->AsString;
                //pObj->PORT		    = pADO->FieldByName("PORT")->AsString;
                //pObj->BRIDGE		= pADO->FieldByName("BRIDGE")->AsString;
                pObj->COMYN		    = pADO->FieldByName("COMYN")->AsString;

				FRseLists.Push(pObj->RSEID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityRse", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityRse", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FRseLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityAvi(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_AVI
    return true;
#endif
    sQry = "SELECT AVI_CTLR_MNGM_NMBR,   \r\n"
           "       AVI_ID,               \r\n"
           "       LINK_ID,              \r\n"
           "       AVI_LCTN_NM,          \r\n"
           "       AVI_VALD_YN,          \r\n"
           "       AVI_CTLR_IP,          \r\n"
           "       AVI_CTLR_CMNC_PORT,   \r\n"
           "       AVI_MAIN_CTLR_YN,     \r\n"
           "       AVI_MNGM_LANE_NUM,    \r\n"
           "       AVI_CMRA_NUM,         \r\n"
           "       AVI_DTCT_NUM,         \r\n"
           "       AVI_DTCT_NM,          \r\n"
           "       AVI_CLCT_CYCL,        \r\n"
           "       AVI_LAMP_AUTO_YN,     \r\n"
           "       AVI_LAMP_ON_HMS,      \r\n"
           "       AVI_LAMP_OFF_HMS,     \r\n"
           "       AVI_LAMP_ON_YN,       \r\n"
           "       X_CRDN,               \r\n"
           "       Y_CRDN,               \r\n"
           "       RMRK,                 \r\n"
           "       DEL_YN                \r\n"
           "  FROM TB_AVI_CTLR           \r\n";
           //" ORDER BY AVI_CTLR_MNGM_NMBR \r\n";

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsAvi *pObj = new TItsAvi();

                pObj->AVI_CTLR_MNGM_NMBR= pADO->FieldByName("AVI_CTLR_MNGM_NMBR")->AsString;
                pObj->AVI_ID            = pADO->FieldByName("AVI_ID")->AsString;
                pObj->LINK_ID           = pADO->FieldByName("LINK_ID")->AsString;
                pObj->AVI_LCTN_NM       = pADO->FieldByName("AVI_LCTN_NM")->AsString;
                pObj->AVI_VALD_YN       = pADO->FieldByName("AVI_VALD_YN")->AsString;
                pObj->AVI_CTLR_IP       = pADO->FieldByName("AVI_CTLR_IP")->AsString;
                pObj->AVI_CTLR_CMNC_PORT= pADO->FieldByName("AVI_CTLR_CMNC_PORT")->AsString;
                pObj->AVI_MAIN_CTLR_YN  = pADO->FieldByName("AVI_MAIN_CTLR_YN")->AsString;
                pObj->AVI_MNGM_LANE_NUM = pADO->FieldByName("AVI_MNGM_LANE_NUM")->AsString;
                pObj->AVI_CMRA_NUM      = pADO->FieldByName("AVI_CMRA_NUM")->AsString;
                pObj->AVI_DTCT_NUM      = pADO->FieldByName("AVI_DTCT_NUM")->AsString;
                pObj->AVI_DTCT_NM       = pADO->FieldByName("AVI_DTCT_NM")->AsString;
                pObj->AVI_CLCT_CYCL     = pADO->FieldByName("AVI_CLCT_CYCL")->AsString;
                pObj->AVI_LAMP_AUTO_YN  = pADO->FieldByName("AVI_LAMP_AUTO_YN")->AsString;
                pObj->AVI_LAMP_ON_HMS   = pADO->FieldByName("AVI_LAMP_ON_HMS")->AsString;
                pObj->AVI_LAMP_OFF_HMS  = pADO->FieldByName("AVI_LAMP_OFF_HMS")->AsString;
                pObj->AVI_LAMP_ON_YN    = pADO->FieldByName("AVI_LAMP_ON_YN")->AsString;
                pObj->X_CRDN            = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN            = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->RMRK              = pADO->FieldByName("RMRK")->AsString;
                pObj->DEL_YN            = pADO->FieldByName("DEL_YN")->AsString;

				//FAviLists.Push(pObj->AVI_CTLR_MNGM_NMBR, pObj);
				FAviLists.Push(pObj->AVI_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityAvi", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityAvi", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FAviLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityDsrc(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_DSRC
    return true;
#endif
    sQry = "SELECT ID,              \r\n"
           "       RSE_ID,          \r\n"
           "       ROAD_SPOT_ID,    \r\n"
           "       LOG_CNNC_ID,     \r\n"
           "       LOG_CNNC_PW,     \r\n"
           "       ISTL_LCTN_NM,    \r\n"
           "       LCTN_X,          \r\n"
           "       LCTN_Y,          \r\n"
           "       IP,              \r\n"
           "       PORT,            \r\n"
           "       MNFC_CMPY_CD,    \r\n"
           "       DEL_YN,          \r\n"
           "       CLCT_ABNR_BASI   \r\n"
           "  FROM TB_RSE_MSTR      \r\n";
           //" ORDER BY ID            \r\n";

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsDsrc *pObj = new TItsDsrc();

                pObj->ID             = pADO->FieldByName("ID")->AsString;
                pObj->RSE_ID         = pADO->FieldByName("RSE_ID")->AsString;
                pObj->ROAD_SPOT_ID   = pADO->FieldByName("ROAD_SPOT_ID")->AsString;
                pObj->LOG_CNNC_ID    = pADO->FieldByName("LOG_CNNC_ID")->AsString;
                pObj->LOG_CNNC_PW    = pADO->FieldByName("LOG_CNNC_PW")->AsString;
                pObj->ISTL_LCTN_NM   = pADO->FieldByName("ISTL_LCTN_NM")->AsString;
                pObj->LCTN_X         = pADO->FieldByName("LCTN_X")->AsString;
                pObj->LCTN_Y         = pADO->FieldByName("LCTN_Y")->AsString;
                pObj->IP             = pADO->FieldByName("IP")->AsString;
                pObj->PORT           = pADO->FieldByName("PORT")->AsString;
                pObj->MNFC_CMPY_CD   = pADO->FieldByName("MNFC_CMPY_CD")->AsString;
                pObj->DEL_YN         = pADO->FieldByName("DEL_YN")->AsString;
                pObj->CLCT_ABNR_BASI = pADO->FieldByName("CLCT_ABNR_BASI")->AsInteger;

				//FDsrcLists.Push(pObj->ID, pObj);
				FDsrcLists.Push(pObj->RSE_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityDsrc", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityDsrc", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FDsrcLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityBit(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_BIT
    return true;
#endif
#if 0
    sQry = "SELECT A.BIT_ID,                      \r\n"
           "       A.BIT_TYPE,                    \r\n"
           "       A.FAN_MIN_TEMPERATURE,         \r\n"
           "       A.FAN_MAX_TEMPERATURE,         \r\n"
           "       A.HEATER_MIN_TEMPERATURE,      \r\n"
           "       A.HEATER_MAX_TEMPERATURE,      \r\n"
           "       A.INSTALL_STOP_ID,             \r\n"
           "       B.STOP_ID,                     \r\n"
           "       B.SERVICE_ID,                  \r\n"
           "       B.STOP_TYPE,                   \r\n"
           "       B.STOP_NAME,                   \r\n"
           "       B.STOP_SHORTNAME,              \r\n"
           "       B.STOP_EXPLAIN,                \r\n"
           "       B.LAT AS COORDY,               \r\n"
           "       B.LNG AS COORDX,               \r\n"
           "       B.LINK_ID,                     \r\n"
           "       B.USE_FLAG                     \r\n"
           "  FROM BIT A, BUSSTOP B               \r\n"
           " WHERE 1=1                            \r\n"
           "   AND A.INSTALL_STOP_ID = B.STOP_ID  \r\n"
           "   AND B.USE_FLAG        = '1'        \r\n";
#else
    sQry = "SELECT * FROM VW_BIT \r\n";
#endif


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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsBit *pObj = new TItsBit();

                pObj->FCLT_ID                = pADO->FieldByName("FCLT_ID")->AsString;
                pObj->FCLT_LCTN              = pADO->FieldByName("FCLT_LCTN")->AsString;
                pObj->BIT_ID                 = pADO->FieldByName("BIT_ID")->AsString;
                pObj->X_CRDN                 = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN                 = pADO->FieldByName("Y_CRDN")->AsString;

                pObj->STOP_ID                = pADO->FieldByName("STOP_ID")->AsString;
#if 0
                pObj->BIT_TYPE               = pADO->FieldByName("BIT_TYPE")->AsString;
                pObj->FAN_MIN_TEMPERATURE    = pADO->FieldByName("FAN_MIN_TEMPERATURE")->AsInteger;
                pObj->FAN_MAX_TEMPERATURE    = pADO->FieldByName("FAN_MAX_TEMPERATURE")->AsInteger;
                pObj->HEATER_MIN_TEMPERATURE = pADO->FieldByName("HEATER_MIN_TEMPERATURE")->AsInteger;
                pObj->HEATER_MAX_TEMPERATURE = pADO->FieldByName("HEATER_MAX_TEMPERATURE")->AsInteger;
                pObj->INSTALL_STOP_ID        = pADO->FieldByName("INSTALL_STOP_ID")->AsString;
                pObj->SERVICE_ID             = pADO->FieldByName("SERVICE_ID")->AsString;
                pObj->STOP_TYPE              = pADO->FieldByName("STOP_TYPE")->AsString;
                pObj->STOP_NAME              = pADO->FieldByName("STOP_NAME")->AsString;
                pObj->STOP_SHORTNAME         = pADO->FieldByName("STOP_SHORTNAME")->AsString;
#endif
                pObj->STOP_EXPLAIN           = pADO->FieldByName("REMARK")->AsString;
                pObj->LINK_ID                = pADO->FieldByName("LINK_ID")->AsString;

                pObj->DEL_YN  = "N";

				FBitLists.Push(pObj->FCLT_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityBit", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityBit", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FBitLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilitySig(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_SIG
    return true;
#endif
    sQry = "SELECT * FROM VW_SIG_CTLR      \r\n";

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsSig *pObj = new TItsSig();

                pObj->FCLT_ID       = pADO->FieldByName("FCLT_ID")->AsString;
                pObj->FCLT_LCTN     = pADO->FieldByName("FCLT_LCTN")->AsString;
                pObj->SIG_ID        = pADO->FieldByName("FACIL_ID")->AsString;
                pObj->X_CRDN        = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN        = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->MDL_NM        = pADO->FieldByName("MDL_NM")->AsString;

                pObj->DEL_YN  = "N";

				FSigLists.Push(pObj->FCLT_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilitySig", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilitySig", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FSigLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilitySigDet(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_SIGDET
    return true;
#endif
    sQry = "SELECT * FROM VW_SIG_LVDS      \r\n";

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsSigDet *pObj = new TItsSigDet();

                pObj->FCLT_ID       = pADO->FieldByName("FCLT_ID")->AsString;
                pObj->FCLT_LCTN     = pADO->FieldByName("FCLT_LCTN")->AsString;
                pObj->SDET_ID       = pADO->FieldByName("FACIL_ID")->AsString;
                pObj->X_CRDN        = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN        = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->MDL_NM        = pADO->FieldByName("MDL_NM")->AsString;
                pObj->SIG_ID        = pADO->FieldByName("ASSETS_CODE")->AsString;

                pObj->DEL_YN  = "N";

				FSigDetLists.Push(pObj->FCLT_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilitySigDet", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilitySigDet", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FSigDetLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityPvms(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_PVMS
    return true;
#endif
    sQry = "SELECT * FROM VW_PIS_VMS \r\n";


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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsPis *pObj = new TItsPis();

                pObj->FCLT_ID   = pADO->FieldByName("FCLT_ID")->AsString;
                pObj->FCLT_LCTN = pADO->FieldByName("FCLT_LCTN")->AsString;
                pObj->PIS_ID    = pADO->FieldByName("FACIL_ID")->AsString;
                pObj->X_CRDN    = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN    = pADO->FieldByName("Y_CRDN")->AsString;

                pObj->DEL_YN  = "N";

				FPisLists.Push(pObj->FCLT_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityPvms", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityPvms", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FPisLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityPvds(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_PVDS
    return true;
#endif
    sQry = "SELECT * FROM VW_PIS_CONT \r\n";


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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsPcs *pObj = new TItsPcs();

                pObj->FCLT_ID   = pADO->FieldByName("FCLT_ID")->AsString;
                pObj->FCLT_LCTN = pADO->FieldByName("FCLT_LCTN")->AsString;
                pObj->PCS_ID    = pADO->FieldByName("FACIL_ID")->AsString;
                pObj->X_CRDN    = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN    = pADO->FieldByName("Y_CRDN")->AsString;

                pObj->DEL_YN  = "N";

				FPcsLists.Push(pObj->FCLT_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityPvds", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsFacilityManager::LoadFacilityPvds", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FPisLists.UnLock();
    }

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

bool TItsFacilityManager::LoadFacilityPark(TADOConnection *ADbConn/*=NULL*/)
{
    if (!PrltCtlrManager)
    {
        PrltCtlrManager = new TPrltCtlrManager();
    }

#ifdef USE_PARK
    TItsFacility *pFacility;

    TFacilityStatus *pStatus = FListStatus.Find("PARK");
    if (pStatus)
    {
        pStatus->Total  = 0;
        pStatus->Normal = 0;
        pStatus->Error  = 0;
        pStatus->Module = 0;
        pStatus->Collect= 0;
    }

    PrltCtlrManager->LoadFromDb();
    FOR_STL(TPrltCtlr*, pObj, PrltCtlrManager->FLists)
    {
        if (pObj->DEL_YN == "Y") continue;
        pFacility = FLists.Find(pObj->PRLT_CTLR_ID);
        if (!pFacility) continue;

        pFacility->Object = pObj;
        pFacility->FCLT_KIND = pObj->REAL_DATA_YN;  //실시간주차정보제공여부

        //주차장중에 실시간정보를 수집하는 것만 상태정보 범례를 표출하자
        if (pObj->REAL_DATA_YN == "Y")
        {
            if (pStatus)
            {
                pStatus->Total++;   /* 전체 갯수를 증가 시킴 */
            }
        }
    }
#endif
    return true;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadFacilityStatusFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    bool bResult = true;
    String sQry;
    TADOQuery *pADO = NULL;

            sQry = "SELECT '' AS FAC_TYPE, '' AS FAC_ID,                                             \r\n"
                   "       '' AS STTS_CD,  '' AS DOOR_STTS_CD,                                       \r\n"
                   "       DECODE('', 'CMS0', '0', 'CMS1', '1', '2') AS COMM,                        \r\n"
                   "       DECODE('', 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,                        \r\n"
                   "       NVL(NULL, 0) AS CBOX_TMPR,                                                \r\n"
                   "       '' AS STS00,                                                              \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM DUAL                                                                      \r\n"
                   " WHERE 1 = 0                                                                     \r\n"
#ifdef USE_CCTV
#if 0
                   "UNION                                                                            \r\n"
                   "SELECT 'CCTV' AS FAC_TYPE, B.CCTV_CTLR_ID AS FAC_ID,                             \r\n"
                   "       CONN_STTS_CD AS STTS_CD, 'CDS0' AS DOOR_STTS_CD,                          \r\n"
                   "       DECODE(CONN_STTS_CD, 'CMS0', '0', 'CMS1', '1', '2') AS COMM,              \r\n"
                   "       '0' AS DOOR,                                                              \r\n"
                   "       0 AS CBOX_TMPR,                                                           \r\n"
                   "       A.UPDT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_CCTV_CTLR_STTS A, TB_CCTV_CTLR B                                       \r\n"
                   " WHERE A.CCTV_CTLR_NMBR = B.CCTV_CTLR_NMBR                                       \r\n"
                   "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
#else
                   "UNION                                                                            \r\n"
                   "SELECT 'CCTV' AS FAC_TYPE, B.CCTV_CTLR_ID AS FAC_ID,                             \r\n"
                   "       CMNC_STTS_CD AS STTS_CD, CBOX_DOOR_STTS_CD AS DOOR_STTS_CD,               \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', '1', 'CMS1', '0', '2') AS COMM,              \r\n"
                   "       DECODE(CBOX_DOOR_STTS_CD, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,         \r\n"
                   "       NVL(A.CBOX_TMPR, 0) AS CBOX_TMPR,                                         \r\n"
                   "       A.UPDT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_CCTV_STTS A, TB_CCTV_CTLR B                                            \r\n"
                   " WHERE A.CCTV_MNGM_NMBR = B.CCTV_MNGM_NMBR                                       \r\n"
                   "   AND UPDT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS')                    \r\n"
#endif
#endif
#ifdef USE_WCAM
                   "UNION                                                                            \r\n"
                   "SELECT 'WCAM' AS FAC_TYPE, B.WCAM_CTLR_ID AS FAC_ID,                             \r\n"
                   "       CMNC_STTS_CD AS STTS_CD, 'CDS0' AS DOOR_STTS_CD,                          \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', '0', 'CMS1', '1', '0') AS COMM,              \r\n"
                   "       '0' AS DOOR, 0 AS CBOX_TMPR,                                              \r\n"
                   "       A.UPDT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_WCAM_CTLR_STTS A, TB_WCAM_CTLR B                                       \r\n"
                   " WHERE A.WCAM_CTLR_NMBR = B.WCAM_CTLR_NMBR                                       \r\n"
                   "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
#endif
#ifdef USE_CCAM
                   "UNION                                                                         \r\n"
                   "SELECT 'CCAM' AS FAC_TYPE, B.CCAM_CTLR_ID AS FAC_ID,                          \r\n"
                   "       CMNC_STTS_CD AS STTS_CD, CBOX_DOOR_STTS_CD AS DOOR_STTS_CD,            \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', '0', 'CMS1', '1', '2') AS COMM,           \r\n"
                   "       DECODE(CBOX_DOOR_STTS_CD, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,      \r\n"
                   "       NVL(A.CBOX_TMPR, 0) AS CBOX_TMPR,                                      \r\n"
                   "       A.UPDT_DT AS STS00,                                                    \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,  \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10   \r\n"
                   "  FROM TB_CCAM_CTLR_STTS A, TB_CCAM_CTLR B                                    \r\n"
                   " WHERE A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')               \r\n"
                   "   AND A.CCAM_CTLR_NMBR = B.CCAM_CTLR_NMBR                                    \r\n"
#endif
#ifdef USE_VMS
#if 0
                   "UNION                                                                            \r\n"
                   "SELECT 'VMS' AS FAC_TYPE, B.VMS_CTLR_ID AS FAC_ID,                               \r\n"
                   "       CMNC_STTS_CD AS STTS_CD, CBOX_DOOR_STTS_CD AS DOOR_STTS_CD,               \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', '0', 'CMS1', '1', '2') AS COMM,              \r\n"
                   "       DECODE(CBOX_DOOR_STTS_CD, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,         \r\n"
                   "       NVL(A.CBOX_TMPR, 0) AS CBOX_TMPR,                                         \r\n"
                   "       A.UPDT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_VMS_CTLR_STTS A, TB_VMS_CTLR B                                         \r\n"
                   " WHERE A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR                                         \r\n"
                   "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
#else
                   "UNION                                                                            \r\n"
                   "SELECT 'VMS' AS FAC_TYPE, B.VMS_CTLR_ID AS FAC_ID,                               \r\n"
                   "       CONN_STTS_CD AS STTS_CD, CBOXDOOR_OPEN_STTS_CD AS DOOR_STTS_CD,           \r\n"
                   "       DECODE(CONN_STTS_CD, 'CMS0', '0', 'CMS1', '1', '2') AS COMM,              \r\n"
                   "       DECODE(CBOXDOOR_OPEN_STTS_CD, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,     \r\n"
                   "       NVL(A.CBOX_TMPR, 0) AS CBOX_TMPR,                                         \r\n"
                   "       A.RGST_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_VMS_STTS_PRST A, TB_VMS_CTLR B                                         \r\n"
                   " WHERE A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR                                         \r\n"
                   "   AND A.RGST_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
#endif
#endif
#ifdef USE_VDS
                   "UNION                                                                         \r\n"
                   "SELECT 'VDS' AS FAC_TYPE, B.VDS_CTLR_ID AS FAC_ID,                            \r\n"
                   "       CMNC_STTS_CD AS STTS_CD, CBOX_DOOR_STTS_CD AS DOOR_STTS_CD,            \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', '0', 'CMS1', '1', '2') AS COMM,           \r\n"
                   "       DECODE(CBOX_DOOR_STTS_CD, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,      \r\n"
                   "       NVL(A.CBOX_TMPR, 0) AS CBOX_TMPR,                                      \r\n"
                   "       A.UPDT_DT AS STS00,                                                    \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,  \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10   \r\n"
                   "  FROM TB_VDS_CTLR_STTS A, TB_VDS_CTLR B                                      \r\n"
                   " WHERE A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')               \r\n"
                   "   AND A.VDS_CTLR_NMBR = B.VDS_CTLR_NMBR                                      \r\n"
#endif
#ifdef USE_AVI
                   "UNION                                                                            \r\n"
                   "SELECT 'AVI' AS FAC_TYPE, B.AVI_ID AS FAC_ID,                                    \r\n"
                   "       CONN_STTS_CD AS STTS_CD, CBOX_DOOR_STTS_CD AS DOOR_STTS_CD,               \r\n"
                   "       DECODE(CONN_STTS_CD, 'CMS0', '0', 'CMS1', '1', '2') AS COMM,              \r\n"
                   "       DECODE(CBOX_DOOR_STTS_CD, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,         \r\n"
                   "       NVL(A.CBOX_TMPR, 0) AS CBOX_TMPR,                                         \r\n"
                   "       A.UPDT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_AVI_CTLR_STTS A, TB_AVI_CTLR B                                         \r\n"
                   " WHERE A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
                   "   AND A.AVI_CTLR_MNGM_NMBR = B.AVI_CTLR_MNGM_NMBR                               \r\n"
#endif
#ifdef USE_DSRC
                   "UNION                                                                            \r\n"
                   "SELECT 'DSRC' AS FAC_TYPE, B.RSE_ID AS FAC_ID,                                   \r\n"
                   "       DECODE(CMNC_STTS, '0', 'CMS0', 'CMS1') AS STTS_CD,                        \r\n"
                   "       DECODE(CNTL_DEVC_STTS, '0', 'CDS0', '4', 'CDS0', 'CDS1') AS DOOR_STTS_CD, \r\n"
                   "       DECODE(CMNC_STTS, '0', '0', '1') AS COMM,                                 \r\n"
                   "       '0' AS DOOR, 0 AS CBOX_TMPR,                                              \r\n"
                   "       A.CLCT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_RSE_STTS_PNST A, TB_RSE_MSTR B                                         \r\n"
                   " WHERE A.CLCT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
                   "   AND A.ID = B.ID                                                               \r\n"
#endif
#ifdef USE_RSE
                   "UNION                                                                            \r\n"
                   "SELECT 'RSE' AS FAC_TYPE, B.RSEID AS FAC_ID,                                     \r\n"
                   "       'CMS0' AS STTS_CD, 'CDS0' AS DOOR_STTS_CD,                                \r\n"
                   "       '0' AS COMM, '0' AS DOOR, 0 AS CBOX_TMPR,                                 \r\n"
                   "       TO_CHAR(A.COLLDT, 'YYYYMMDDHH24MISS') AS STS00,                           \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM RSEOPSTATE A, RSEMST B                                                    \r\n"
                   " WHERE B.RSEID = A.RSEID                                                         \r\n"
                   "   AND A.COLLDT > SYSDATE - 30/1440                                              \r\n"
#endif
#ifdef USE_BIT
                   "UNION                                                                            \r\n"
                   "SELECT 'BIT' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID,                            \r\n"
                   "       CONN_STATE AS STTS_CD, 'CDS0' AS DOOR_STTS_CD,                            \r\n"
                   "       DECODE(CONN_STATE, 'CMS0', '0', '1') AS COMM,                             \r\n"
                   "       '0' AS DOOR, 0 AS CBOX_TMPR,                                              \r\n"
                   "       UPDATE_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM VW_BIT_STATUS                                                             \r\n"
#endif
#ifdef USE_SIG
                   "UNION                                                                            \r\n"
                   "SELECT 'SIG' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID,                            \r\n"
                   "       CONN_STATE AS STTS_CD, DOOR_STATE AS DOOR_STTS_CD,                        \r\n"
                   "       DECODE(CONN_STATE, 'CMS0', '0', '1') AS COMM,                             \r\n"
                   "       DECODE(DOOR_STATE, 'CDS0', '0', 'CDS1', '1', '0') AS DOOR,                \r\n"
                   "       0 AS CBOX_TMPR,                                                           \r\n"
                   "       UPDATE_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM VW_SIG_CTLR_STATUS                                                        \r\n"
#endif
#ifdef USE_SIGDET
                   "UNION                                                                            \r\n"
                   "SELECT 'LVD' AS FAC_TYPE, FCLT_ID AS FAC_ID,                                     \r\n"
                   "       DECODE(DISCONN_STATE, 'STS0', 'CMS0', 'CMS1') AS STTS_CD,                 \r\n"
                   "       'CDS0' AS DOOR_STTS_CD,                                                   \r\n"
                   "       DECODE(DISCONN_STATE, 'STS0', '0', '1') AS COMM,                          \r\n"
                   "       '0' AS DOOR, 0 AS CBOX_TMPR                                               \r\n"
                   "  FROM VW_SIG_LVDS_STATUS                                                        \r\n"
#endif
#ifdef USE_PVMS
                   "UNION                                                                            \r\n"
                   "SELECT 'PVMS' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID,                           \r\n"
                   "       DECODE(COMM_STATE, 0, 'CMS0', 'CMS1') AS STTS_CD,                         \r\n"
                   "       DECODE(DOOR_STATE, 0, 'CDS0', 'CDS1') AS DOOR_STTS_CD,                    \r\n"
                   "       DECODE(COMM_STATE, 0, '0', '1') AS COMM, '0' AS DOOR,                     \r\n"
                   "       0 AS CBOX_TMPR,                                                           \r\n"
                   "       UPDATE_DT             AS STS00,                                           \r\n"
                   "       '0'                   AS STS01,                                           \r\n"
                   "       TO_CHAR(POWER_STATE)  AS STS02,                                           \r\n"
                   "       TO_CHAR(MODULE_STATE) AS STS03,                                           \r\n"
                   "       TO_CHAR(FAN_STATE)    AS STS04,                                           \r\n"
                   "       TO_CHAR(HEATER_STATE) AS STS05,                                           \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM VW_PIS_VMS_STATUS                                                         \r\n"
#endif
#ifdef USE_PVDS
                   "UNION                                                                            \r\n"
                   "SELECT 'PVMS' AS FAC_TYPE, TO_CHAR(FCLT_ID) AS FAC_ID,                           \r\n"
                   "       DECODE(COMM_STATE, '0', 'CMS0', 'CMS1') AS STTS_CD,                       \r\n"
                   "       'CDS0' AS DOOR_STTS_CD,                                                   \r\n"
                   "       DECODE(COMM_STATE, '0', '0', '1') AS COMM, '0' AS DOOR,                   \r\n"
                   "       0 AS CBOX_TMPR,                                                           \r\n"
                   "       UPDATE_DT           AS STS00,                                             \r\n"
                   "       TO_CHAR(CONT_STATE) AS STS01,                                             \r\n"
                   "       '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,                   \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM VW_PIS_CONT_STATUS                                                        \r\n"
#endif
#ifdef USE_PARK
                   "UNION                                                                            \r\n"
                   "SELECT 'PARK' AS FAC_TYPE, B.PRLT_CTLR_ID AS FAC_ID,                             \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', 'CMS0', 'CMS1') AS STTS_CD,                  \r\n"
                   "       'CDS0' AS DOOR_STTS_CD,                                                   \r\n"
                   "       DECODE(CMNC_STTS_CD, 'CMS0', '0', 'CMS1', '1', '0') AS COMM,              \r\n"
                   "      '0' AS DOOR,                                                               \r\n"
                   "       0 AS CBOX_TMPR,                                                           \r\n"
                   "       A.UPDT_DT AS STS00,                                                       \r\n"
                   "       '0' AS STS01, '0' AS STS02, '0' AS STS03, '0' AS STS04, '0' AS STS05,     \r\n"
                   "       '0' AS STS06, '0' AS STS07, '0' AS STS08, '0' AS STS09, '0' AS STS10      \r\n"
                   "  FROM TB_PRLT_CTLR_STTS A, TB_PRLT_CTLR B                                       \r\n"
                   " WHERE A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
                   "   AND A.PRLT_CTLR_NMBR = B.PRLT_CTLR_NMBR                                       \r\n"
#endif
           ;

    try
    {
        TItsFacility *pFacility = NULL;

        FLists.Lock();

        FOR_STL(TItsFacility*, pObj, ItsFacilityManager->FLists)
        {
            pObj->FCollCntBase = 0;
            pObj->FCollCntCurr = 0;

            //수집시간내에 조회되는것은 수집오류가 아니므로 초기에 수집오류로 설정
            if (pObj->FCLT_TYPE == "VDS" ||
                pObj->FCLT_TYPE == "AVI" ||
                pObj->FCLT_TYPE == "DSRC")
            {
                //pObj->FCollError   = true;
                pObj->FCollError   = false;
            }
            else
            {
                pObj->FCollError   = false;
            }

            pObj->FComm = state_error;
            pObj->FDoor = "0";
            pObj->FCommStatus = "CMS1";
            pObj->FDoorStatus = "CDS0";

            if (pObj->FCLT_TYPE == "CCTV" ||
                pObj->FCLT_TYPE == "VMS"  ||
                pObj->FCLT_TYPE == "VDS"  ||
                pObj->FCLT_TYPE == "AVI")
            {
                pObj->FCBoxTmpr = "?";
            }
            else
            {
                pObj->FCBoxTmpr = "-";
            }
        }

        //상태정보를 읽어오기전에 상태정보 통계데이터를 초기화한다.
        FOR_STL(TFacilityStatus*, pStatus, ItsFacilityManager->FListStatus)
        {
            //pStatus->Total  = 0; 전체 수량은 초기화하지 않는다.
            pStatus->Normal = 0;
            pStatus->Error  = 0;
            pStatus->Module = 0;
            pStatus->Collect= 0;
        }

        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
            pADO->SQL->Clear();
            pADO->SQL->Text = sQry;

            pADO->Prepared = true;
            pADO->Open();
            //int nRows = pADO->RecordCount;
            for( ; !pADO->Eof; pADO->Next())
            {
                String sId = pADO->FieldByName("FAC_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sId);
                if (!pFacility) continue;

                pFacility->FCommStatus = pADO->FieldByName("STTS_CD")->AsString;
                pFacility->FDoorStatus = pADO->FieldByName("DOOR_STTS_CD")->AsString;

                pFacility->FComm = pADO->FieldByName("COMM")->AsString;
                pFacility->FDoor = pADO->FieldByName("DOOR")->AsString;

                pFacility->Sts00 = pADO->FieldByName("STS00")->AsString;
                pFacility->Sts01 = pADO->FieldByName("STS01")->AsString;
                pFacility->Sts02 = pADO->FieldByName("STS02")->AsString;
                pFacility->Sts03 = pADO->FieldByName("STS03")->AsString;
                pFacility->Sts04 = pADO->FieldByName("STS04")->AsString;
                pFacility->Sts05 = pADO->FieldByName("STS05")->AsString;
                pFacility->Sts06 = pADO->FieldByName("STS06")->AsString;
                pFacility->Sts07 = pADO->FieldByName("STS07")->AsString;
                pFacility->Sts08 = pADO->FieldByName("STS08")->AsString;
                pFacility->Sts09 = pADO->FieldByName("STS09")->AsString;
                pFacility->Sts10 = pADO->FieldByName("STS10")->AsString;

                if (pFacility->FCLT_TYPE == "CCTV" ||
                    pFacility->FCLT_TYPE == "VMS" ||
                    pFacility->FCLT_TYPE == "VDS" ||
                    pFacility->FCLT_TYPE == "AVI")
                {
                    pFacility->FCBoxTmpr = pADO->FieldByName("CBOX_TMPR")->AsString;
                }

                if (pFacility->FComm == state_normal)
                {
                    //통신이 정상인데 함체문이 열려있으면 모듈이상으로 처리
#if 0
                    if (pFacility->FDoor == "1")
                        pFacility->FComm = state_module; //모듈이상(함체문 열림)
#endif
                }
            }

            //수집데이터를 처리하구 수집오류=false로 설정함
#ifdef USE_DSRC
            LoadDsrcCollectStatusFromDb(ADbConn);
#endif
#ifdef USE_VDS
            //LoadVdsCollectStatusFromDb(ADbConn);
#endif
#ifdef USE_AVI
            LoadAviCollectStatusFromDb(ADbConn);
#endif
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadFacilityStatusFromDb", String(E.ClassName()), E.Message, sQry);
            return false;
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadFacilityStatusFromDb", String(exception.ClassName()), exception.Message, sQry);
            return false;
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        // 상태정보를 최종 체크한다.
        TFacilityStatus *pStatus;
        FOR_STL(TItsFacility*, pTmpObj, ItsFacilityManager->FLists)
        {
            String FCLT_TYPE = pTmpObj->FCLT_TYPE;
            if (FCLT_TYPE == "VDS" && pTmpObj->FCLT_KIND == "C")
            {
                FCLT_TYPE = "CRSSVR";
            }
            pStatus = ItsFacilityManager->FListStatus.Find(FCLT_TYPE);
            if (!pStatus) continue;

            if (FCLT_TYPE == "PARK" && pTmpObj->FCLT_KIND == "N")
            {
                //주차장이면서 실시간정보를 제공하지않는경우 통신정상으로 설정
                pTmpObj->FComm = state_default;
                continue;
            }

            if      (pTmpObj->FComm == state_error)  pStatus->Error++;
            else if (pTmpObj->FComm == state_module) pStatus->Module++;

            if (pTmpObj->FComm != state_error)
            {
                //통신이상이 아닌 경우 수집이상인 경우 수집이상 갯수를 증가시킨다.
                if (pTmpObj->FCollError)
                {
                    pStatus->Collect++;
                    pTmpObj->FComm = state_collect;
                }
            }
        }

        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }

        //각각의 제어기에 대한 상태정보를 업데이트 한다.
        TItsFacility *pFacility;
        FOR_STL(TWCamCtlr*, pObj, WCamCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;
            pFacility = ItsFacilityManager->FLists.Find(pObj->WCAM_CTLR_ID);
            if (pFacility)
            {
                pObj->STATE.Comm = pFacility->FComm != state_error ? wcam_normal : wcam_error;
            }
        }

        FOR_STL(TCCamCtlr*, pObj, CCamCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;
            pFacility = ItsFacilityManager->FLists.Find(pObj->CCAM_CTLR_ID);
            if (pFacility)
            {
                pObj->STATE.Comm = pFacility->FComm != state_error ? ccam_normal : ccam_error;
            }
        }

        FOR_STL(TVdsCtlr*, pObj, VdsCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;
            pFacility = ItsFacilityManager->FLists.Find(pObj->VDS_CTLR_ID);
            if (pFacility)
            {
                pObj->STATE.Comm = pFacility->FComm != state_error ? vds_normal : vds_error;
            }
        }

        FOR_STL(TVmsCtlr*, pObj, VmsCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;
            pFacility = ItsFacilityManager->FLists.Find(pObj->VMS_CTLR_ID);
            if (pFacility)
            {
                pObj->STATE.Comm = pFacility->FComm != state_error ? vms_comm_normal : vms_comm_error;
            }
        }

        FOR_STL(TPrltCtlr*, pObj, PrltCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;
            pFacility = ItsFacilityManager->FLists.Find(pObj->PRLT_CTLR_ID);
            if (pFacility)
            {
                pObj->STATE.Comm = pFacility->FComm != state_error ? park_comm_normal : park_comm_error;
            }
        }

        FLists.UnLock();
    }

    return bResult;
}
//---------------------------------------------------------------------------

bool TItsFacilityManager::LoadDsrcCollectStatusFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_DSRC
    return true;
#endif
    sQry = "SELECT DISTINCT B.RSE_ID                                     \r\n"
           "  FROM TB_RSE_OBU_CLCT_PNST A,                               \r\n"
           "       TB_RSE_MSTR          B                                \r\n"
           " WHERE A.CLCT_DT > TO_CHAR(SYSDATE-1/24, 'YYYYMMDDHH24MISS') \r\n"
           "   AND A.ID = B.ID                                           \r\n";

    try
    {
        TItsFacility *pFacility = NULL;

        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            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 sRseId = pADO->FieldByName("RSE_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sRseId);
                if (!pFacility) continue;

                pFacility->FCollError = false;
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadDsrcCollectStatusFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadDsrcCollectStatusFromDb", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TItsFacilityManager::LoadVdsCollectStatusFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_VDS
    return true;
#endif

    sQry = "SELECT DISTINCT C.VDS_CTLR_ID AS VDS_CTLR_ID                    \r\n"
           "  FROM TB_VDS_DTCT_CLCT_PNST A,                                 \r\n"
           "       TB_VDS_DTCT           B,                                 \r\n"
           "       TB_VDS_CTLR           C                                  \r\n"
           " WHERE A.CLCT_DT > TO_CHAR(SYSDATE-1/24, 'YYYYMMDDHH24MISS')    \r\n"
           "   AND A.VDS_DTCT_NMBR = B.VDS_DTCT_NMBR                        \r\n"
           "   AND B.VDS_CTLR_NMBR = C.VDS_CTLR_NMBR                        \r\n";

    try
    {
        TItsFacility *pFacility = NULL;

        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
            pADO->SQL->Clear();
            pADO->SQL->Text = sQry;

            pADO->Prepared = true;
            pADO->Open();
            pADO->First();

            for( ; !pADO->Eof; pADO->Next())
            {
                String sVdsId = pADO->FieldByName("VDS_CTLR_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sVdsId);
                if (!pFacility) continue;

                pFacility->FCollError = false;
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadVdsCollectStatusFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadVdsCollectStatusFromDb", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TItsFacilityManager::LoadAviCollectStatusFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_AVI
    return true;
#endif

    sQry = "SELECT A.AVI_CTLR_MNGM_NMBR, B.AVI_ID                         \r\n"
           "  FROM TB_AVI_PASS_VHCL_PNST A,                               \r\n"
           "       TB_AVI_CTLR           B                                \r\n"
           " WHERE A.CRTN_DT > TO_CHAR(SYSDATE-1/24, 'YYYYMMDDHH24MISS')  \r\n"
           "   AND A.AVI_CTLR_MNGM_NMBR = B.AVI_CTLR_MNGM_NMBR            \r\n";

    try
    {
        TItsFacility *pFacility = NULL;

        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
            pADO->SQL->Clear();
            pADO->SQL->Text = sQry;

            pADO->Prepared = true;
            pADO->Open();
            pADO->First();

            for( ; !pADO->Eof; pADO->Next())
            {
                String sAviId = pADO->FieldByName("AVI_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sAviId);
                if (!pFacility) continue;

                pFacility->FCollError = false;
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadAviCollectStatusFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadAviCollectStatusFromDb", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TItsFacilityManager::LoadDsrcCollectStatusFromDb_OLD(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_DSRC
    return true;
#endif
    sQry = "SELECT X.ID, X.RSE_ID, X.CLCT_ABNR_BASI,                                 \r\n"
           "       Y.STAT_DT, NVL(Y.CLCT_NUM, 0) AS CLCT_NUM                         \r\n"
           "  FROM (SELECT M.ID, M.RSE_ID, M.CLCT_ABNR_BASI                          \r\n"
           "          FROM TB_RSE_MSTR M                                             \r\n"
           "         WHERE M.DEL_YN <> 'Y'                                           \r\n"
           "       ) X,                                                              \r\n"
           "       (SELECT P.ID, P.STAT_DT, P.CLCT_NUM                               \r\n"
           "          FROM TB_RSE_OBU_CLCT_HH_PNST P                                 \r\n"
           "         WHERE P.STAT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS')  \r\n"
           "       ) Y                                                               \r\n"
           " WHERE X.ID = Y.ID(+)                                                    \r\n";

#if 0
    sQry = "SELECT X.ID, X.RSE_ID, X.CLCT_ABNR_BASI,                                                         \r\n"
           "       Y.STAT_DT, NVL(Y.CLCT_NUM, 0) AS CLCT_NUM                                                 \r\n"
           "  FROM (SELECT M.ID, M.RSE_ID, M.CLCT_ABNR_BASI                                                  \r\n"
           "          FROM TB_RSE_MSTR M                                                                     \r\n"
           "         WHERE M.DEL_YN <> 'Y'                                                                   \r\n"
           "       ) X,                                                                                      \r\n"
           "       (SELECT ID, STAT_DT, CLCT_NUM                                                             \r\n"
           "          FROM TB_RSE_OBU_CLCT_HH_PNST                                                           \r\n"
           "         WHERE (ID, STAT_DT) IN (SELECT P.ID, MAX(P.STAT_DT)                                     \r\n"
           "                                  FROM TB_RSE_OBU_CLCT_HH_PNST P                                 \r\n"
           "                                 WHERE P.STAT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS')  \r\n"
           "                                 GROUP BY P.ID)                                                  \r\n"
           "       ) Y                                                                                       \r\n"
           " WHERE X.ID = Y.ID(+)                                                                            \r\n";
#endif
    try
    {
        TItsFacility *pFacility = NULL;

        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
            pADO->SQL->Clear();
            pADO->SQL->Text = sQry;

            pADO->Prepared = true;
            pADO->Open();
            //int nRows = pADO->RecordCount;
            for( ; !pADO->Eof; pADO->Next())
            {
                String sId = pADO->FieldByName("RSE_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sId);
                if (!pFacility) continue;

                pFacility->FCollCntBase = pADO->FieldByName("CLCT_ABNR_BASI")->AsInteger;
                pFacility->FCollCntCurr = pADO->FieldByName("CLCT_NUM")->AsInteger;
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadDsrcCollectStatusFromDb_OLD", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadDsrcCollectStatusFromDb_OLD", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TItsFacilityManager::LoadAviCollectStatusFromDb_OLD(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifndef USE_AVI
    return true;
#endif
    sQry = "SELECT A.AVI_CTLR_MNGM_NMBR, A.AVI_ID, NVL(B.COLCNT, 0) AS COLCNT                \r\n"
           "  FROM TB_AVI_CTLR A,                                                            \r\n"
           "       (SELECT AVI_CTLR_MNGM_NMBR, MAX(CRTN_DT) AS CRTN_DT, COUNT(1) AS COLCNT   \r\n"
           "          FROM TB_AVI_PASS_VHCL_PNST                                             \r\n"
           "         WHERE CRTN_DT >= TO_CHAR(SYSDATE-10/1440, 'YYYYMMDDHH24MISS')           \r\n"
           "         GROUP BY AVI_CTLR_MNGM_NMBR ) B                                         \r\n"
           " WHERE A.DEL_YN = 'N'                                                            \r\n"
           "   AND A.AVI_CTLR_MNGM_NMBR = B.AVI_CTLR_MNGM_NMBR(+)                            \r\n";

    try
    {
        TItsFacility *pFacility = NULL;

        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
            pADO->SQL->Clear();
            pADO->SQL->Text = sQry;

            pADO->Prepared = true;
            pADO->Open();
            pADO->First();

            String sAviId;
            int    nColCnt;

            for( ; !pADO->Eof; pADO->Next())
            {
                sAviId = pADO->FieldByName("AVI_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sAviId);
                if (!pFacility)
                {
                    continue;
                }

                nColCnt = pADO->FieldByName("COLCNT")->AsInteger;
                if (nColCnt == 0)
                {
                    if (pFacility->FComm != state_error)
                    {
                        pFacility->FCollError = true;
                    }
                }
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadAviCollectStatusFromDb_OLD", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("TItsFacilityManager::LoadAviCollectStatusFromDb_OLD", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

