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


#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;

        FWebCamLists.Lock();
        FCctvLists.Lock();
        FVmsLists.Lock();
        FRseLists.Lock();

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

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

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

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

        FWebCamLists.RemoveAll();
        FCctvLists.RemoveAll();
        FVmsLists.RemoveAll();
        FRseLists.RemoveAll();

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

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

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

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

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

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

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

    LoadFacilityReg(ADbConn);
    LoadFacilityMaster(ADbConn);
    LoadFacilityWebCam(ADbConn);
    LoadFacilityCctv(ADbConn);
    LoadFacilityVms(ADbConn);
    LoadFacilityRse(ADbConn);

    LoadFacilityVds(ADbConn);

#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 '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"
#ifdef USE_WCAM
           "UNION                                                                             \r\n"
           "SELECT 'WCAM' AS FAC_TYPE, WEB_CMRA_ID AS FAC_ID, ISTL_LCTN_NM AS FAC_NM, DEL_YN  \r\n"
           "  FROM TB_WEB_CMRA                                                                \r\n"
           " WHERE DEL_YN = 'N'                                                               \r\n"
#endif
           "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"
#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

           "UNION                                                                             \r\n"
           "SELECT 'VDS' AS FAC_TYPE, VDS_CTLR_ID AS FAC_ID, LCTN AS FAC_N, DEL_YN            \r\n"
           "  FROM TB_VDS_CTLR                                                                \r\n"
           " WHERE DEL_YN = 'N'                                                               \r\n"
#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

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

			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("등록시설물정보조회", 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("등록시설물정보조회", 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";
//           " ORDER BY FCLT_TYPE, FCLT_ID \r\n";
    try
    {
        TFacilityStatus *pStatus;
        FListStatus.RemoveAll();

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

			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;

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

                pStatus = FListStatus.Find(pFacility->FCLT_TYPE);
                if (!pStatus)
                {
                    pStatus = new TFacilityStatus();
                    pStatus->Type   = pFacility->FCLT_TYPE;
                    pStatus->Total  = 0;
                    pStatus->Normal = 0;
                    pStatus->Error  = 0;
                    pStatus->Module = 0;
                    pStatus->Collect= 0;

                    FListStatus.Push(pFacility->FCLT_TYPE, pStatus);
                }
                pStatus->Total++;   /* 전체 갯수를 증가 시킴 */
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("시설물마스터정보조회", 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("시설물마스터정보조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

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

    sQry = "SELECT A.WEB_CMRA_NMBR,                     \r\n"
           "       A.WEB_CMRA_ID,                       \r\n"
           "       A.CMRA_IP,                           \r\n"
           "       A.CMRA_PORT,                         \r\n"
           "       A.STRM_SVR_IP,                       \r\n"
           "       A.STRM_SVR_PORT,                     \r\n"
           "       A.STRM_SESN_NM,                      \r\n"
           "       A.X_CRDN,                            \r\n"
           "       A.Y_CRDN,                            \r\n"
           "       A.ISTL_LCTN_NM,                      \r\n"
           "       A.ISTL_LCTN_ADDR,                    \r\n"
           "       A.EQPM_KIND,                         \r\n"
           "       A.DEL_YN,                            \r\n"
           "       A.LINK_ID,                           \r\n"
           "       B.STRM_RTSP_ADDR,                    \r\n"
           "       B.STRM_RTMP_ADDR,                    \r\n"
           "       B.STRM_HTTP_ADDR,                    \r\n"
           "       B.STRM_STOR_ADDR                     \r\n"
           "  FROM TB_WEB_CMRA A,                       \r\n"
           "       TB_WEB_CMRA_STRM B                   \r\n"
           " WHERE DEL_YN = 'N'                         \r\n"
           "   AND A.WEB_CMRA_NMBR = B.WEB_CMRA_NMBR(+) \r\n";
           //" ORDER BY A.WEB_CMRA_NMBR  \r\n";
#if 0
    sQry = "SELECT A.WEB_CMRA_NMBR,     \r\n"
           "       A.WEB_CMRA_ID,       \r\n"
           "       A.CMRA_IP,           \r\n"
           "       A.CMRA_PORT,         \r\n"
           "       A.STRM_SVR_IP,       \r\n"
           "       A.STRM_SVR_PORT,     \r\n"
           "       A.STRM_SESN_NM,      \r\n"
           "       A.X_CRDN,            \r\n"
           "       A.Y_CRDN,            \r\n"
           "       A.ISTL_LCTN_NM,      \r\n"
           "       A.ISTL_LCTN_ADDR,    \r\n"
           "       A.EQPM_KIND,         \r\n"
           "       A.DEL_YN,            \r\n"
           "       A.LINK_ID,           \r\n"
           "       B.STRM_RTSP_ADDR,    \r\n"
           "       B.STRM_RTMP_ADDR,    \r\n"
           "       B.STRM_HTTP_ADDR,    \r\n"
           "       B.STRM_STOR_ADDR     \r\n"
           "  FROM TB_WEB_CMRA A,       \r\n"
           "       TB_WEB_CMRA_STRM B   \r\n"
           " WHERE DEL_YN = 'N'         \r\n"
           "   AND A.WEB_CMRA_NMBR = B.WEB_CMRA_NMBR(+) \r\n";
           //" ORDER BY A.WEB_CMRA_NMBR  \r\n";
#endif
    try
    {
        FWebCamLists.Lock();
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

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

                pObj->WEB_CMRA_NMBR     = pADO->FieldByName("WEB_CMRA_NMBR")->AsString;
                pObj->WEB_CMRA_ID       = pADO->FieldByName("WEB_CMRA_ID")->AsString;
                pObj->CMRA_IP           = pADO->FieldByName("CMRA_IP")->AsString;
                pObj->CMRA_PORT         = pADO->FieldByName("CMRA_PORT")->AsString;
                pObj->STRM_SVR_IP       = pADO->FieldByName("STRM_SVR_IP")->AsString;
                pObj->STRM_SVR_PORT     = pADO->FieldByName("STRM_SVR_PORT")->AsString;
                pObj->STRM_SESN_NM      = pADO->FieldByName("STRM_SESN_NM")->AsString;
                pObj->X_CRDN            = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN            = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->ISTL_LCTN_NM      = pADO->FieldByName("ISTL_LCTN_NM")->AsString;
                pObj->ISTL_LCTN_ADDR    = pADO->FieldByName("ISTL_LCTN_ADDR")->AsString;
                pObj->EQPM_KIND         = pADO->FieldByName("EQPM_KIND")->AsString;
                pObj->DEL_YN            = pADO->FieldByName("DEL_YN")->AsString;
                pObj->LINK_ID           = pADO->FieldByName("LINK_ID")->AsString;
                pObj->STRM_RTSP_ADDR    = pADO->FieldByName("STRM_RTSP_ADDR")->AsString;
                pObj->STRM_RTMP_ADDR    = pADO->FieldByName("STRM_RTMP_ADDR")->AsString;
                pObj->STRM_HTTP_ADDR    = pADO->FieldByName("STRM_HTTP_ADDR")->AsString;
                pObj->STRM_STOR_ADDR    = pADO->FieldByName("STRM_STOR_ADDR")->AsString;

                pObj->ID                = "admin";
                pObj->PSWD              = "4321";

                pObj->FData1            = NULL;
                pObj->FData2            = NULL;

				FWebCamLists.Push(pObj->WEB_CMRA_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("웹카메라정보조회", 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("웹카메라정보조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FWebCamLists.UnLock();
    }

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

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

    sQry = "SELECT CCTV_MNGM_NMBR,         \r\n"
           "       CCTV_CTLR_ID,           \r\n"
           "       CCTV_CTLR_IP,           \r\n"
           "       CCTV_CTLR_PORT,         \r\n"
           "       CCTV_CAPT_IP,           \r\n"
           "       CCTV_CAPT_PORT,         \r\n"
           "       CCTV_FIBR_IP,           \r\n"
           "       CCTV_ENCD_IP,           \r\n"
           "       STRM_SVR_IP,            \r\n"
           "       STRM_SVR_PORT,          \r\n"
           "       STRM_SESN_NM,           \r\n"
           "       NVL(X_CRDN, 0) X_CRDN,  \r\n"
           "       NVL(Y_CRDN, 0) Y_CRDN,  \r\n"
           "       ISTL_LCTN_NM,           \r\n"
           "       ISTL_LCTN_ADDR,         \r\n"
           "       CCTV_CHNL,              \r\n"
           "       DEL_YN,                 \r\n"
           "       FRST_REGR_NMBR,         \r\n"
           "       FRST_RGST_DT,           \r\n"
           "       LAST_CRPR_NMBR,         \r\n"
           "       LAST_CRCT_DT,           \r\n"
           "       LINK_ID,                \r\n"
           "       CCTV_ID,                \r\n"
           "       RELY_PORT,              \r\n"
           "       STRM_RTSP_ADDR,         \r\n"
           "       STRM_RTMP_ADDR,         \r\n"
           "       STRM_HTTP_ADDR,         \r\n"
           "       CCTV_TYPE               \r\n"
           "  FROM TB_CCTV_CTLR            \r\n"
           " WHERE DEL_YN = 'N'            \r\n";
           //" ORDER BY CCTV_CTLR_ID         \r\n";
    try
    {
        FLocalCctvCnt = 0;
        FCctvLists.Lock();
        //FCctvLists.RemoveAll();
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

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

                pObj->CCTV_MNGM_NMBR    = pADO->FieldByName("CCTV_MNGM_NMBR")->AsString;
                pObj->CCTV_CTLR_ID      = pADO->FieldByName("CCTV_CTLR_ID")->AsString;
                pObj->CCTV_CTLR_IP      = pADO->FieldByName("CCTV_CTLR_IP")->AsString;
                pObj->CCTV_CTLR_PORT    = pADO->FieldByName("CCTV_CTLR_PORT")->AsString;
                pObj->CCTV_CAPT_IP      = pADO->FieldByName("CCTV_CAPT_IP")->AsString;
                pObj->CCTV_CAPT_PORT    = pADO->FieldByName("CCTV_CAPT_PORT")->AsString;
                pObj->CCTV_FIBR_IP      = pADO->FieldByName("CCTV_FIBR_IP")->AsString;
                pObj->CCTV_ENCD_IP      = pADO->FieldByName("CCTV_ENCD_IP")->AsString;
                pObj->STRM_SVR_IP       = pADO->FieldByName("STRM_SVR_IP")->AsString;
                pObj->STRM_SVR_PORT     = pADO->FieldByName("STRM_SVR_PORT")->AsString;
                pObj->STRM_SESN_NM      = pADO->FieldByName("STRM_SESN_NM")->AsString;
                pObj->X_CRDN            = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN            = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->ISTL_LCTN_NM      = pADO->FieldByName("ISTL_LCTN_NM")->AsString;
                pObj->ISTL_LCTN_ADDR    = pADO->FieldByName("ISTL_LCTN_ADDR")->AsString;
                pObj->CCTV_CHNL         = pADO->FieldByName("CCTV_CHNL")->AsString;
                pObj->DEL_YN            = pADO->FieldByName("DEL_YN")->AsString;
                pObj->FRST_REGR_NMBR    = pADO->FieldByName("FRST_REGR_NMBR")->AsString;
                pObj->FRST_RGST_DT      = pADO->FieldByName("FRST_RGST_DT")->AsString;
                pObj->LAST_CRPR_NMBR    = pADO->FieldByName("LAST_CRPR_NMBR")->AsString;
                pObj->LAST_CRCT_DT      = pADO->FieldByName("LAST_CRCT_DT")->AsString;
                pObj->LINK_ID           = pADO->FieldByName("LINK_ID")->AsString;
                pObj->CCTV_ID           = pADO->FieldByName("CCTV_ID")->AsString;
                pObj->RELY_PORT         = pADO->FieldByName("RELY_PORT")->AsString;
                pObj->STRM_RTSP_ADDR    = pADO->FieldByName("STRM_RTSP_ADDR")->AsString;
                pObj->STRM_RTMP_ADDR    = pADO->FieldByName("STRM_RTMP_ADDR")->AsString;
                pObj->STRM_HTTP_ADDR    = pADO->FieldByName("STRM_HTTP_ADDR")->AsString;
                pObj->CCTV_TYPE         = pADO->FieldByName("CCTV_TYPE")->AsString;

                pObj->FData1            = NULL;
                pObj->FData2            = NULL;

				FCctvLists.Push(pObj->CCTV_CTLR_ID, pObj);

                if (pObj->CCTV_CTLR_ID.Pos(CenterId)) 
                {
                    pObj->LOCAL_YN = "Y";
                    FLocalCctvCnt++;
                }
                else
                {
                    pObj->LOCAL_YN = "N";
                }
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("CCTV정보조회", 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("CCTV정보조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FCctvLists.UnLock();
    }

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

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

#if 0
    sQry = "SELECT VMS_CTLR_NMBR,              \r\n"
           "       VMS_ID,                     \r\n"
           "       VMS_CTLR_ID,                \r\n"
           "       VMS_NM,                     \r\n"
           "       VMS_CTLR_IP,                \r\n"
           "       VMS_USAG_TYPE_CD,           \r\n"
           "       VMS_FRM_TYPE_CD,            \r\n"
           "       VMS_TYPE_CD,                \r\n"
           "       VMS_MODL_TYPE_CD,           \r\n"
           "       VMS_CMNC_PORT,              \r\n"
           "       OPER_MODE,                  \r\n"
           "       VMS_CMNC_ERR_BASS_VAL,      \r\n"
           "       VMS_NGHT_BRGH_STEP,         \r\n"
           "       VMS_WEEK_BRGH_STEP,         \r\n"
           "       VMS_PHSE_CHNG_CYCL,         \r\n"
           "       VMS_MODL_ERR_RATE,          \r\n"
           "       CMNCFAIL_SLOT_NMBR,         \r\n"
           "       PWER_FAIL_SLOT_NMBR,        \r\n"
           "       DEL_YN,                     \r\n"
           "       CMTRINFR_CNCT_YN,           \r\n"
           "       WTHRINFR_CNCT_YN,           \r\n"
           "       ENVRINFR_CNCT_YN,           \r\n"
           "       VMS_MAX_PHSE_NUM,           \r\n"
           "       FRST_REGR_NMBR,             \r\n"
           "       FRST_RGST_DT,               \r\n"
           "       LAST_CRPR_NMBR,             \r\n"
           "       LAST_CRCT_DT,               \r\n"
           "       PANL_ON_TIME,               \r\n"
           "       PANL_OFF_TIME,              \r\n"
           "       PANL_PWER_MODE,             \r\n"
           "       BRGH_MODE,                  \r\n"
           "       WEB_CMRA_IP,                \r\n"
           "       NVL(X_CRDN, 0) X_CRDN,      \r\n"
           "       NVL(Y_CRDN, 0) Y_CRDN,      \r\n"
           "       ISTL_LCTN_NM,               \r\n"
           "       TRFC_STRG_USE_YN,           \r\n"
           "       VMS_LOC_IFSC_ID,            \r\n"
           "       WEB_CMRA_PORT,              \r\n"
           "       WEB_CMRA_ID,                \r\n"
           "       scp.dec_b64('DAMO','SCP','ARIA_256.SCPS', WEB_CMRA_PWD) AS WEB_CMRA_PWD,               \r\n"
           "       STRM_SESN_NM                \r\n"
           "  FROM TB_VMS_CTLR                 \r\n"
           " WHERE DEL_YN = 'N'                \r\n";
           //" ORDER BY VMS_CTLR_NMBR            \r\n";
#else
    sQry = "SELECT A.*,                                        \r\n"
           "       (SELECT NVL(ATRB1, '320')                   \r\n"
           "          FROM TB_CMMN_CD                          \r\n"
           "         WHERE CMMN_CLSF_CD = 'VMP'                \r\n"
           "           AND CMMN_CD = A.VMS_TYPE_CD) AS FORMW,  \r\n"
           "       (SELECT NVL(ATRB2,  '64')                   \r\n"
           "          FROM TB_CMMN_CD                          \r\n"
           "         WHERE CMMN_CLSF_CD = 'VMP'                \r\n"
           "           AND CMMN_CD = A.VMS_TYPE_CD) AS FORMH   \r\n"
           "  FROM TB_VMS_CTLR A                               \r\n";
           " WHERE DEL_YN = 'N'                                \r\n";
#endif
    try
    {
        FVmsLists.Lock();
        //FVmsLists.RemoveAll();
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

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

                pObj->VMS_CTLR_NMBR         = pADO->FieldByName("VMS_CTLR_NMBR")->AsString;
                pObj->VMS_ID                = pADO->FieldByName("VMS_ID")->AsString;
                pObj->VMS_CTLR_ID           = pADO->FieldByName("VMS_CTLR_ID")->AsString;
                pObj->VMS_NM                = pADO->FieldByName("VMS_NM")->AsString;
                pObj->VMS_CTLR_IP           = pADO->FieldByName("VMS_CTLR_IP")->AsString;
                pObj->VMS_USAG_TYPE_CD      = pADO->FieldByName("VMS_USAG_TYPE_CD")->AsString;
                pObj->VMS_FRM_TYPE_CD       = pADO->FieldByName("VMS_FRM_TYPE_CD")->AsString;
                pObj->VMS_TYPE_CD           = pADO->FieldByName("VMS_TYPE_CD")->AsString;
                pObj->VMS_MODL_TYPE_CD      = pADO->FieldByName("VMS_MODL_TYPE_CD")->AsString;
                pObj->VMS_CMNC_PORT         = pADO->FieldByName("VMS_CMNC_PORT")->AsString;
                pObj->OPER_MODE             = pADO->FieldByName("OPER_MODE")->AsString;
                pObj->VMS_CMNC_ERR_BASS_VAL = pADO->FieldByName("VMS_CMNC_ERR_BASS_VAL")->AsString;
                pObj->VMS_NGHT_BRGH_STEP    = pADO->FieldByName("VMS_NGHT_BRGH_STEP")->AsString;
                pObj->VMS_WEEK_BRGH_STEP    = pADO->FieldByName("VMS_WEEK_BRGH_STEP")->AsString;
                pObj->VMS_PHSE_CHNG_CYCL    = pADO->FieldByName("VMS_PHSE_CHNG_CYCL")->AsString;
                pObj->VMS_MODL_ERR_RATE     = pADO->FieldByName("VMS_MODL_ERR_RATE")->AsString;
                pObj->CMNCFAIL_SLOT_NMBR    = pADO->FieldByName("CMNCFAIL_SLOT_NMBR")->AsString;
                pObj->PWER_FAIL_SLOT_NMBR   = pADO->FieldByName("PWER_FAIL_SLOT_NMBR")->AsString;
                pObj->DEL_YN                = pADO->FieldByName("DEL_YN")->AsString;
                pObj->CMTRINFR_CNCT_YN      = pADO->FieldByName("CMTRINFR_CNCT_YN")->AsString;
                pObj->WTHRINFR_CNCT_YN      = pADO->FieldByName("WTHRINFR_CNCT_YN")->AsString;
                pObj->ENVRINFR_CNCT_YN      = pADO->FieldByName("ENVRINFR_CNCT_YN")->AsString;
                pObj->VMS_MAX_PHSE_NUM      = pADO->FieldByName("VMS_MAX_PHSE_NUM")->AsString;
                pObj->FRST_REGR_NMBR        = pADO->FieldByName("FRST_REGR_NMBR")->AsString;
                pObj->FRST_RGST_DT          = pADO->FieldByName("FRST_RGST_DT")->AsString;
                pObj->LAST_CRPR_NMBR        = pADO->FieldByName("LAST_CRPR_NMBR")->AsString;
                pObj->LAST_CRCT_DT          = pADO->FieldByName("LAST_CRCT_DT")->AsString;
                pObj->PANL_ON_TIME          = pADO->FieldByName("PANL_ON_TIME")->AsString;
                pObj->PANL_OFF_TIME         = pADO->FieldByName("PANL_OFF_TIME")->AsString;
                pObj->PANL_PWER_MODE        = pADO->FieldByName("PANL_PWER_MODE")->AsString;
                pObj->BRGH_MODE             = pADO->FieldByName("BRGH_MODE")->AsString;
                pObj->WEB_CMRA_IP           = pADO->FieldByName("WEB_CMRA_IP")->AsString;
                pObj->X_CRDN                = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN                = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->ISTL_LCTN_NM          = pADO->FieldByName("ISTL_LCTN_NM")->AsString;
                pObj->TRFC_STRG_USE_YN      = pADO->FieldByName("TRFC_STRG_USE_YN")->AsString;

                pObj->WEB_CMRA_PORT = pADO->FieldByName("WEB_CMRA_PORT")->AsString.Trim();
                pObj->WEB_CMRA_ID   = pADO->FieldByName("WEB_CMRA_ID")->AsString.Trim();
                pObj->WEB_CMRA_PSWD = pADO->FieldByName("WEB_CMRA_PWD")->AsString.Trim();
                pObj->STRM_SESN_NM  = pADO->FieldByName("STRM_SESN_NM")->AsString.Trim();

                pObj->WIDTH                 = pADO->FieldByName("FORMW")->AsString.Trim().ToIntDef(380);
                pObj->HEIGHT                = pADO->FieldByName("FORMH")->AsString.Trim().ToIntDef(64);

                pObj->ModVerCnt = 2;
                pObj->ModHorCnt = 12;
                if (pObj->VMS_TYPE_CD == "VMP0")
                {
                    pObj->ModVerCnt = 2;
                    pObj->ModHorCnt = 10;
                }
                else
                if (pObj->VMS_TYPE_CD == "VMP1")
                {
                    pObj->ModVerCnt = 10;
                    pObj->ModHorCnt = 18;
                }
                else
                if (pObj->VMS_TYPE_CD == "VMP2")
                {
                    pObj->ModVerCnt = 2*2;
                    pObj->ModHorCnt = 12*2;
                }
                else
                if (pObj->VMS_TYPE_CD == "VMP3")
                {
                    pObj->ModVerCnt = 1;
                    pObj->ModHorCnt = 6;
                }

                pObj->FData1            = NULL;
                pObj->FData2            = NULL;


				//FVmsLists.Push(pObj->VMS_CTLR_NMBR, pObj);
				FVmsLists.Push(pObj->VMS_CTLR_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("VMS정보조회", 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("VMS정보조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FVmsLists.UnLock();
    }

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

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

#ifdef USE_RSE
    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";
#else
    return true;
#endif

    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->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("RSE정보조회", 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("RSE정보조회", 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::LoadFacilityVds(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT CTLR_MNGM_NMBR,   \r\n"
           "       CTLR_TYPE_CD,     \r\n"
           "       VALD_YN,          \r\n"
           "       X_CRDN,           \r\n"
           "       Y_CRDN,           \r\n"
           "       LCTN,             \r\n"
           "       TRMN_IP,          \r\n"
           "       TRMN_PORT,        \r\n"
           "       CTLR_CLCT_CYCL,   \r\n"
           "       CTLR_STTS_CYCL,   \r\n"
           "       LOOP_BORD_NUM,    \r\n"
           "       DLTR_NMBR,        \r\n"
           "       DEL_DT,           \r\n"
           "       DEL_YN,           \r\n"
           "       FRST_REGR_NMBR,   \r\n"
           "       FRST_RGST_DT,     \r\n"
           "       LAST_CRPR_NMBR,   \r\n"
           "       LAST_CRCT__DT,    \r\n"
           "       VDS_CTLR_ID       \r\n"
           "  FROM TB_VDS_CTLR       \r\n";
           //" ORDER BY CTLR_MNGM_NMBR \r\n";

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

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

                pObj->CTLR_MNGM_NMBR    = pADO->FieldByName("CTLR_MNGM_NMBR")->AsString;
                pObj->CTLR_TYPE_CD      = pADO->FieldByName("CTLR_TYPE_CD")->AsString;
                pObj->VALD_YN           = pADO->FieldByName("VALD_YN")->AsString;
                pObj->X_CRDN            = pADO->FieldByName("X_CRDN")->AsString;
                pObj->Y_CRDN            = pADO->FieldByName("Y_CRDN")->AsString;
                pObj->LCTN              = pADO->FieldByName("LCTN")->AsString;
                pObj->TRMN_IP           = pADO->FieldByName("TRMN_IP")->AsString;
                pObj->TRMN_PORT         = pADO->FieldByName("TRMN_PORT")->AsString;
                pObj->CTLR_CLCT_CYCL    = pADO->FieldByName("CTLR_CLCT_CYCL")->AsString;
                pObj->CTLR_STTS_CYCL    = pADO->FieldByName("CTLR_STTS_CYCL")->AsString;
                pObj->LOOP_BORD_NUM     = pADO->FieldByName("LOOP_BORD_NUM")->AsString;
                pObj->DLTR_NMBR         = pADO->FieldByName("DLTR_NMBR")->AsString;
                pObj->DEL_DT            = pADO->FieldByName("DEL_DT")->AsString;
                pObj->DEL_YN            = pADO->FieldByName("DEL_YN")->AsString;
                pObj->FRST_REGR_NMBR    = pADO->FieldByName("FRST_REGR_NMBR")->AsString;
                pObj->FRST_RGST_DT      = pADO->FieldByName("FRST_RGST_DT")->AsString;
                pObj->LAST_CRPR_NMBR    = pADO->FieldByName("LAST_CRPR_NMBR")->AsString;
                pObj->LAST_CRCT__DT     = pADO->FieldByName("LAST_CRCT__DT")->AsString;
                pObj->VDS_CTLR_ID       = pADO->FieldByName("VDS_CTLR_ID")->AsString;

				//FVdsLists.Push(pObj->CTLR_MNGM_NMBR, pObj);
				FVdsLists.Push(pObj->VDS_CTLR_ID, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("VDS정보조회", 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("VDS정보조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FVdsLists.UnLock();
    }

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

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

    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"
           "       FRST_REGR_NMBR,       \r\n"
           "       FRST_RGST_DT,         \r\n"
           "       LAST_CRPR_NMBR,       \r\n"
           "       LAST_CRCT_DT          \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->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;              
                pObj->FRST_REGR_NMBR    = pADO->FieldByName("FRST_REGR_NMBR")->AsString;      
                pObj->FRST_RGST_DT      = pADO->FieldByName("FRST_RGST_DT")->AsString;        
                pObj->LAST_CRPR_NMBR    = pADO->FieldByName("LAST_CRPR_NMBR")->AsString;      
                pObj->LAST_CRCT_DT      = pADO->FieldByName("LAST_CRCT_DT")->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("AVI정보조회", 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("AVI정보조회", 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;

    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->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("DSRC정보조회", 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("DSRC정보조회", 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;

#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->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("BIT정보조회", 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("BIT정보조회", 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;

    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->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("SIG정보조회", 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("SIG정보조회", 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;

return true;
    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->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("SIGDET정보조회", 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("SIGDET정보조회", 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;

    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->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("PIS정보조회", 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("PIS정보조회", 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;

    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->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("PCS정보조회", 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("PCS정보조회", 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::LoadFacilityStatusFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    bool bResult = true;
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "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', '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_CCTV_STTS A, TB_CCTV_CTLR B                                            \r\n"
           " WHERE A.CCTV_MNGM_NMBR = B.CCTV_MNGM_NMBR                                       \r\n"
           "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
           "UNION                                                                            \r\n"
#ifdef USE_WCAM
           "SELECT 'WCAM' AS FAC_TYPE, B.WEB_CMRA_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_WEB_CMRA_STTS A, TB_WEB_CMRA B                                         \r\n"
           " WHERE A.WEB_CMRA_NMBR = B.WEB_CMRA_NMBR                                         \r\n"
           "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                  \r\n"
           "UNION                                                                            \r\n"
#endif
           "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"
           "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.CTLR_MNGM_NMBR = B.CTLR_MNGM_NMBR                                       \r\n"

#ifdef USE_AVI
           "UNION                                                                            \r\n"
           "SELECT 'AVI' AS FAC_TYPE, B.AVI_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_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"
           "       A.COLLDT 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

           ;

    try
    {
        TItsFacility *pFacility = NULL;

        FLists.Lock();

        FOR_STL(TItsFacility*, pObj, ItsFacilityManager->FLists)
        {
            pObj->FCollCntBase = 0;
            pObj->FCollCntCurr = 0;
            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->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->FCommStatus == "CMS0") pFacility->FComm = "1";
                //else if (pFacility->FCommStatus == "CMS1") pFacility->FComm = "0";
                //else if (pFacility->FCommStatus == "CMS2") pFacility->FComm = "0";

                //if (pFacility->FDoorStatus == "CDS1") pFacility->FDoor = "1";
                //else if (pFacility->FDoorStatus == "CMS1") pFacility->FComm = "0";
                //else if (pFacility->FDoorStatus == "CMS2") pFacility->FComm = "0";

                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
                }

                TFacilityStatus *pStatus = ItsFacilityManager->FListStatus.Find(pFacility->FCLT_TYPE);
                if (pStatus)
                {
                    if (pFacility->FComm == state_error)
                    {
                        pStatus->Error++;
                    }
                    else
                    if (pFacility->FComm == state_module)
                    {
                        //pStatus->Module++;
                    }
                }
            }

            //수집데이터를 처리하구 수집오류=false로 설정함
            //LoadDsrcCollectStatusFromDb(ADbConn);
            LoadVdsCollectStatusFromDb(ADbConn);
#ifdef USE_AVI
            LoadAviCollectStatusFromDb(ADbConn);
#endif
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORLOG("시설물상태정보조회", 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("시설물상태정보조회", String(exception.ClassName()), exception.Message, sQry);
            return false;
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        // 최종 모듈이상을 체크한다.
        FOR_STL(TItsFacility*, pTmpObj, ItsFacilityManager->FLists)
        {
            if (pTmpObj->FComm != state_error)
            {
                //통신이 정상인 경우에만(모듈이상이나 통신이상인 경우에는 이미처리가 되어있는거임...
                if (pTmpObj->FCollError)
                {
                    //수집이상이 발생한 경우임. ==> 모듈이상으로 처리하고 모듈오류갯수 증가시킴
                    TFacilityStatus *pStatus = ItsFacilityManager->FListStatus.Find(pTmpObj->FCLT_TYPE);
                    if (pStatus)
                    {
                        //pStatus->Module++;
                        pStatus->Collect++;
                    }
                }
            }
        }

        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

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

    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->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("DSRC수집상태정보조회", 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("DSRC수집상태정보조회", 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;

#if 1
    sQry = "SELECT A.CTLR_MNGM_NMBR, A.VDS_CTLR_ID, NVL(B.COLCNT, 0) AS COLCNT                \r\n"
           "  FROM TB_VDS_CTLR A,                                                             \r\n"
           "       (SELECT A.CTLR_MNGM_NMBR, MAX(B.OCRR_DT) AS OCRR_DT, COUNT(1) AS COLCNT    \r\n"
           "          FROM TB_VDS_DTCT_MSTR A, TB_VDS_DTCT_RAW_PNST B                         \r\n"
           "         WHERE A.DTCT_NMBR = B.DTCT_NMBR                                          \r\n"
           "           AND B.OCRR_DT >= TO_CHAR(SYSDATE-10/1440, 'YYYYMMDDHH24MISS')          \r\n"
           "         GROUP BY A.CTLR_MNGM_NMBR ) B                                            \r\n"
           " WHERE A.DEL_YN = 'N'                                                             \r\n"
           "   AND A.CTLR_MNGM_NMBR = B.CTLR_MNGM_NMBR(+)                                     \r\n";
#else
    sQry = "SELECT CTLR_NMBR AS CTLR_MNGM_NMBR, CTLR_ID AS VDS_CTLR_ID, COLCNT                                \r\n"
           "  FROM (SELECT A.CTLR_MNGM_NMBR AS CTLR_NMBR, A.VDS_CTLR_ID AS CTLR_ID, A.LCTN AS CTLR_NM,        \r\n"
           "               NVL(C.UPDT_DT, '-') AS UPDT_DT, NVL(C.CMNC_STTS_CD, 'CMS1') AS COMM_CD,            \r\n"
           "               NVL(C.COLCNT, 0) AS COLCNT, NVL(B.COMMERRCNT, 0) AS COMMERRCNT                     \r\n"
           "          FROM TB_VDS_CTLR A,                                                                     \r\n"
           "               (SELECT CTLR_MNGM_NMBR, COUNT(1) AS COMMERRCNT                                     \r\n"
           "                  FROM TB_VDS_CTLR_STTS_RAW                                                       \r\n"
           "                 WHERE 1=1                                                                        \r\n"
           "                   AND CMNC_STTS_CD <> 'CMS0'                                                     \r\n"
           "                   AND OCRR_DT >= TO_CHAR(TRUNC(SYSDATE), 'YYYYMMDD') || '000000'                 \r\n"
           "                 GROUP BY CTLR_MNGM_NMBR                                                          \r\n"
           "               ) B,                                                                               \r\n"
           "               (SELECT X.CTLR_MNGM_NMBR, X.UPDT_DT, X.CMNC_STTS_CD, NVL(Y.COLCNT, 0) AS COLCNT    \r\n"
           "                  FROM TB_VDS_CTLR_STTS X,                                                        \r\n"
           "                       (SELECT A.CTLR_MNGM_NMBR, COUNT(1) AS COLCNT                               \r\n"
           "                          FROM TB_VDS_DTCT_MSTR A, TB_VDS_DTCT_RAW_PNST B                         \r\n"
           "                         WHERE 1=1                                                                \r\n"
           "                           AND A.DTCT_NMBR = B.DTCT_NMBR                                          \r\n"
           "                           AND B.OCRR_DT >= TO_CHAR(SYSDATE-10/1440, 'YYYYMMDDHH24MISS')          \r\n"
           "                         GROUP BY A.CTLR_MNGM_NMBR ) Y                                            \r\n"
           "                 WHERE 1=1                                                                        \r\n"
           "                   AND X.UPDT_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS')                   \r\n"
           "                   AND X.CTLR_MNGM_NMBR = Y.CTLR_MNGM_NMBR(+)                                     \r\n"
           "               ) C                                                                                \r\n"
           "         WHERE 1=1                                                                                \r\n"
           "           AND A.DEL_YN = 'N'                                                                     \r\n"
           "           AND A.CTLR_MNGM_NMBR = B.CTLR_MNGM_NMBR(+)                                             \r\n"
           "           AND A.CTLR_MNGM_NMBR = C.CTLR_MNGM_NMBR(+)                                             \r\n"
           "       )                                                                                          \r\n"
           " WHERE 1=1                                                                                        \r\n"
           "   AND (COMM_CD = 'CMS0' AND COLCNT = 0)                                                          \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->Open();
            pADO->First();

            String sVdsId;
            int    nColCnt;
            for( ; !pADO->Eof; pADO->Next())
            {
                sVdsId = pADO->FieldByName("VDS_CTLR_ID")->AsString;
                pFacility = ItsFacilityManager->FLists.Find(sVdsId);
                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("VDS수집상태정보조회", 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("VDS수집상태정보조회", 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;

    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->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("AVI수집상태정보조회", 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("AVI수집상태정보조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

