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

#pragma hdrstop

#include "CDSCctvCtlrF.h"

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

#pragma package(smart_init)


//---------------------------------------------------------------------------
TCctvCtlr::TCctvCtlr()
{
}
//---------------------------------------------------------------------------

TCctvCtlr::~TCctvCtlr()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TCctvCtlrManager *CctvCtlrManager = NULL;
//---------------------------------------------------------------------------

TCctvCtlrManager::TCctvCtlrManager()
{
    FImgStream = NULL;
}
//---------------------------------------------------------------------------
TCctvCtlrManager::~TCctvCtlrManager()
{
    FLists.RemoveAll();
    if (FImgStream) delete FImgStream;
    FImgStream = NULL;
}
//---------------------------------------------------------------------------
bool TCctvCtlrManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*,                                                                                                          \r\n"
           "       (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CLSF_CD = 'CTVT' AND CMMN_CD = A.CCTV_TYPE) AS CCTV_TYPE_NM \r\n"
           "  FROM TB_CCTV_CTLR A                                                                                                \r\n";
           " WHERE A.DEL_YN = 'N'                                                                                                \r\n";

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

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

#ifdef D_CCTV_HANTE
                pObj->CCTV_CTLR_NMBR      = pADO->FieldByName("CCTV_CTLR_NMBR")->AsString;             //	N	NUMBER(10)	    N			CCTV 제어기 번호
                pObj->CCTV_NM             = pADO->FieldByName("CCTV_NM")->AsString.Trim();              //	N	VARCHAR2(40)	Y			CCTV 명칭
#else
                pObj->CCTV_CTLR_NMBR      = pADO->FieldByName("CCTV_MNGM_NMBR")->AsString;             //	N	NUMBER(10)	    N			CCTV 제어기 번호
                pObj->CCTV_NM             = pADO->FieldByName("ISTL_LCTN_NM")->AsString.Trim();        //	N	VARCHAR2(40)	Y			CCTV 명칭
#endif

                pObj->CCTV_CTLR_ID        = pADO->FieldByName("CCTV_CTLR_ID")->AsString.Trim();         //	N	VARCHAR2(30)	Y			CCTV 제어기 ID
                pObj->CCTV_CTLR_IP        = pADO->FieldByName("CCTV_CTLR_IP")->AsString.Trim();         //	N	VARCHAR2(20)	Y			CCTV 제어기 아이피
                pObj->CCTV_CTLR_PORT      = pADO->FieldByName("CCTV_CTLR_PORT")->AsString.Trim().ToIntDef(0);             //	N	NUMBER(5)	    Y			CCTV 제어기 포트
                pObj->ISTL_LCTN_NM        = pADO->FieldByName("ISTL_LCTN_NM")->AsString.Trim();         //	N	VARCHAR2(40)	Y			설치 위치 명
                pObj->X_CRDN              = pADO->FieldByName("X_CRDN")->AsFloat;                       //	N	NUMBER(11,8)	Y			X 좌표
                pObj->Y_CRDN              = pADO->FieldByName("Y_CRDN")->AsFloat;                       //	N	NUMBER(10,8)	Y			Y 좌표
                pObj->DEL_YN              = pADO->FieldByName("DEL_YN")->AsString.Trim();               //	N	CHAR(1)	        Y	'N'		삭제 여부

                pObj->CCTV_TYPE_CD        = "CCTV";
#ifdef D_CCTV_HANTE
                pObj->CCTV_TYPE_CD        = pADO->FieldByName("CCTV_TYPE_CD")->AsString.Trim();         //	N	VARCHAR2(7)	    Y			CCTV 유형
                pObj->CCTV_CTLR_LOCAL_NO  = pADO->FieldByName("CCTV_CTLR_LOCAL_NO")->AsString.Trim().ToIntDef(0);         //	N	NUMBER(5)	    Y			CCTV 제어기 지역번호
                pObj->INTR_RTSP_ADDR      = pADO->FieldByName("INTR_RTSP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			내부 RTSP 주소
                pObj->INTR_RTMP_ADDR      = pADO->FieldByName("INTR_RTMP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			내부 RTMP 주소
                pObj->INTR_HTTP_ADDR      = pADO->FieldByName("INTR_HTTP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			내부 HTTP 주소
                pObj->CCTV_IP             = pADO->FieldByName("CCTV_IP")->AsString.Trim();              //	N	VARCHAR2(20)	Y			목포 CCTV 제어 IP
                pObj->CCTV_PORT           = pADO->FieldByName("CCTV_PORT")->AsString.Trim().ToIntDef(0);                  //	N	NUMBER(5)	    Y	1852		목포 CCTV 제어 PORT
                pObj->CMRA_PSWD           = pADO->FieldByName("CMRA_PSWD")->AsString.Trim();            //	N	VARCHAR2(20)	Y	'1234'		목포 CCTV 제어 PSWD
#endif

                pObj->LINK_ID             = pADO->FieldByName("LINK_ID")->AsString.Trim();
                pObj->NODE_ID             = pADO->FieldByName("NODE_ID")->AsString.Trim();
                pObj->CCTV_ID             = pADO->FieldByName("CCTV_ID")->AsString.Trim();
                pObj->RELY_PORT           = pADO->FieldByName("RELY_PORT")->AsString.Trim();
                pObj->AREA_CD             = pADO->FieldByName("AREA_CD")->AsString.Trim();              //	N	VARCHAR2(7)	    Y			지역 코드
                pObj->CCTV_TYPE           = pADO->FieldByName("CCTV_TYPE")->AsString.Trim();            //	N	VARCHAR2(10)	Y			CCTV 유형
                pObj->CCTV_TYPE_NM        = pADO->FieldByName("CCTV_TYPE_NM")->AsString.Trim();            //	N	VARCHAR2(10)	Y			CCTV 유형

                pObj->ISTL_LCTN_ADDR      = pADO->FieldByName("ISTL_LCTN_ADDR")->AsString.Trim();
                pObj->CCTV_CHNL           = pADO->FieldByName("CCTV_CHNL")->AsString.Trim().ToIntDef(0);                  //	N	NUMBER(5)	    Y	1		목포 CCTV 제어 CHANNEL
                pObj->CCTV_CAPT_IP        = pADO->FieldByName("CCTV_CAPT_IP")->AsString.Trim();         //	N	VARCHAR2(20)	Y			CCTV 자막기 아이피
                pObj->CCTV_CAPT_PORT      = pADO->FieldByName("CCTV_CAPT_PORT")->AsString.Trim();       //	N	VARCHAR2(5)	    Y			CCTV 자막기 포트
                pObj->CCTV_FIBR_IP        = pADO->FieldByName("CCTV_FIBR_IP")->AsString.Trim();         //	N	VARCHAR2(20)	Y			CCTV 광장비 아이피
                pObj->CCTV_ENCD_IP        = pADO->FieldByName("CCTV_ENCD_IP")->AsString.Trim();         //	N	VARCHAR2(20)	Y			CCTV 인코더 아이피
                pObj->STRM_RTSP_ADDR      = pADO->FieldByName("STRM_RTSP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			스트리밍 RTSP 주소
                pObj->STRM_RTMP_ADDR      = pADO->FieldByName("STRM_RTMP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			스트리밍 RTMP 주소
                pObj->STRM_HTTP_ADDR      = pADO->FieldByName("STRM_HTTP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			스트리밍 HTTP 주소
                pObj->STRM_STOR_ADDR      = pADO->FieldByName("STRM_STOR_ADDR")->AsString.Trim();

                //pObj->CCTV_AREA_DVSN      = pADO->FieldByName("CCTV_AREA_DVSN")->AsString.Trim();     //	N	VARCHAR2(7)	    Y			CCTV 지역 구분
                pObj->CCTV_AREA_DVSN      = pADO->FieldByName("CCTV_LC")->AsString.Trim();              //	N	VARCHAR2(10)	    Y			CCTV 지역 구분
                //pObj->INTR_RTMP_ADDR      = pADO->FieldByName("INTR_RTMP_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			스트리밍 내부 RTMP 주소
                //pObj->SYOP_CNTL_YN        = pADO->FieldByName("SYOP_CNTL_YN")->AsString.Trim();         //	N	CHAR(1)	        Y	'N'		운영자 제어 여부

                //pObj->STRM_SVR_IP         = pADO->FieldByName("STRM_SVR_IP")->AsString.Trim();          //	N	VARCHAR2(20)	Y			스트리밍 서버 아이피
                //pObj->STRM_SVR_PORT       = pADO->FieldByName("STRM_SVR_PORT")->AsString.Trim();        //	N	VARCHAR2(5)	    Y			스트리밍 서버 포트
                pObj->STRM_SESN_NM        = pADO->FieldByName("STRM_SESN_NM")->AsString.Trim();         //	N	VARCHAR2(200)	Y			스트리밍 세션 명
                //pObj->STRM_ADDR           = pObj->STRM_SESN_NM;
                //pObj->FULL_STRM_ADDR      = pADO->FieldByName("FULL_STRM_SESN_NM")->AsString.Trim();

                pObj->CCTV_SBST_DSPL_YN   = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString.Trim();    //	N	CHAR(1)	        Y	'N'		CCTV 대체 표출 여부
                pObj->CCTV_SBST_IMGN      = "";//pADO->FieldByName("CCTV_SBST_IMGN")->AsString.Trim();       //	N	BLOB	        Y			CCTV 대체 영상

                pObj->CMRA_ID = pADO->FieldByName("CMRA_ID")->AsString.Trim();
                pObj->CMRA_PSWD = pADO->FieldByName("CMRA_PSWD")->AsString.Trim();
                pObj->CMRA_CHNL = pADO->FieldByName("CMRA_CHNL")->AsString.Trim().ToIntDef(0);
                pObj->CMRA_PORT = pADO->FieldByName("CMRA_PORT")->AsString.Trim().ToIntDef(0);
                pObj->CMRA_MODL = pADO->FieldByName("CMRA_MODL")->AsString.Trim();
                pObj->FULL_STRM_SESN_NM = pADO->FieldByName("FULL_STRM_SESN_NM")->AsString.Trim();

                pObj->STATE.Comm = cctv_error;

				FLists.Push(pObj->CCTV_CTLR_NMBR, pObj);
                pObj->Completed  = true;
            }
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("TCctvCtlrManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORMSG("TCctvCtlrManager::LoadFromDb", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

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

#ifdef D_CCTV_HANTE
    sQry = "SELECT *                                                        \r\n"
           "  FROM TB_CCTV_CTLR_STTS A,                                     \r\n"
           "       TB_CCTV_CTLR      B                                      \r\n"
           " WHERE A.CCTV_CTLR_NMBR = B.CCTV_CTLR_NMBR                      \r\n"
           "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS') \r\n";
#else
    sQry = "SELECT *                                                        \r\n"
           "  FROM TB_CCTV_STTS A,                                          \r\n"
           "       TB_CCTV_CTLR B                                           \r\n"
           " WHERE A.CCTV_MNGM_NMBR = B.CCTV_MNGM_NMBR                      \r\n"
           "   AND A.UPDT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS') \r\n";
#endif

    FLists.Lock();
    try
    {
        TCctvCtlr *pObj = NULL;
        try
        {
            int nORD;

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

            pADO->Prepared = true;
            pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
#ifdef D_CCTV_HANTE
                String CCTV_CTLR_NMBR = pADO->FieldByName("CCTV_CTLR_NMBR")->AsString;
#else
                String CCTV_CTLR_NMBR = pADO->FieldByName("CCTV_MNGM_NMBR")->AsString;
#endif
                pObj = FLists.Find(CCTV_CTLR_NMBR);
                if (!pObj) continue;

                String UPDT_DT      = pADO->FieldByName("UPDT_DT")->AsString;
#ifdef D_CCTV_HANTE
                String CONN_STTS_CD = pADO->FieldByName("CONN_STTS_CD")->AsString;
#else
                String CONN_STTS_CD = pADO->FieldByName("CMNC_STTS_CD")->AsString;
#endif
                if (CONN_STTS_CD != "CMS0")
                {
                    //통신장애
                    pObj->STATE.Comm = cctv_error;
                    continue;
                }
                pObj->STATE.Comm = (CONN_STTS_CD == "CMS0") ? cctv_normal : cctv_error;
            }
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::LoadStatusFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::LoadStatusFromDb", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        FLists.UnLock();

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

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

bool TCctvCtlrManager::DeleteCctv(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

#ifdef D_CCTV_HANTE
    sQry = "UPDATE TB_CCTV_CTLR          \r\n"
           "   SET DEL_YN = 'Y'          \r\n"
           " WHERE CCTV_CTLR_NMBR = :p01 \r\n";
#else
    sQry = "UPDATE TB_CCTV_CTLR          \r\n"
           "   SET DEL_YN = 'Y'          \r\n"
           " WHERE CCTV_MNGM_NMBR = :p01 \r\n";
#endif
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;
			pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_NMBR;
			pADO->ExecSQL();

        sQry = "DELETE TB_FCLT_INFR      \r\n"
               " WHERE FCLT_ID = :p01    \r\n";

			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;
			pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_ID;
			pADO->ExecSQL();

            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::DeleteCctv", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::DeleteCctv", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TCctvCtlrManager::InsertCctv(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    if (MergeCctv(AObj, ADbConn))
    {
        return MergeFcltInfo(AObj, ADbConn);
    }
    return false;
#if 0
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "MERGE INTO TB_CCTV_CTLR L                   \r\n"
           "USING (SELECT                               \r\n"
           "              :p01 AS CCTV_CTLR_NMBR,       \r\n"
           "              :p02 AS CCTV_CTLR_ID,         \r\n"
           "              :p03 AS CCTV_NM,              \r\n"
           "              :p04 AS CCTV_CTLR_IP,         \r\n"
           "              :p05 AS CCTV_CTLR_PORT,       \r\n"
           "              :p06 AS CCTV_CTLR_LOCAL_NO,   \r\n"
           "              :p07 AS CCTV_TYPE_CD,         \r\n"
           "              :p08 AS ISTL_LCTN_NM,         \r\n"
           "              :p09 AS X_CRDN,               \r\n"
           "              :p10 AS Y_CRDN,               \r\n"
           "              :p11 AS DEL_YN,               \r\n"
           "              :p12 AS STRM_SVR_IP,          \r\n"
           "              :p13 AS STRM_SESN_NM,         \r\n"
           "              :p14 AS STRM_RTSP_ADDR,       \r\n"
           "              :p15 AS STRM_RTMP_ADDR,       \r\n"
           "              :p16 AS STRM_HTTP_ADDR,       \r\n"
           "              :p17 AS CCTV_IP,              \r\n"
           "              :p18 AS CCTV_PORT,            \r\n"
           "              :p19 AS CCTV_ID,              \r\n"
           "              :p20 AS CMRA_PSWD,            \r\n"
           "              :p21 AS CCTV_CHNL             \r\n"
           "         FROM DUAL) M                       \r\n"
           "        ON (L.CCTV_CTLR_NMBR = M.CCTV_CTLR_NMBR)            \r\n"
           "WHEN MATCHED THEN                                           \r\n"
           "   UPDATE SET L.CCTV_CTLR_ID       = M.CCTV_CTLR_ID,        \r\n"
           "              L.CCTV_NM            = M.CCTV_NM,             \r\n"
           "              L.CCTV_CTLR_IP       = M.CCTV_CTLR_IP,        \r\n"
           "              L.CCTV_CTLR_PORT     = M.CCTV_CTLR_PORT,      \r\n"
           "              L.CCTV_CTLR_LOCAL_NO = M.CCTV_CTLR_LOCAL_NO,  \r\n"
           "              L.CCTV_TYPE_CD       = M.CCTV_TYPE_CD,        \r\n"
           "              L.ISTL_LCTN_NM       = M.ISTL_LCTN_NM,        \r\n"
           "              L.X_CRDN             = M.X_CRDN,              \r\n"
           "              L.Y_CRDN             = M.Y_CRDN,              \r\n"
           "              L.DEL_YN             = M.DEL_YN,              \r\n"
           "              L.STRM_SVR_IP        = M.STRM_SVR_IP,         \r\n"
           "              L.STRM_SESN_NM       = M.STRM_SESN_NM,        \r\n"
           "              L.STRM_RTSP_ADDR     = M.STRM_RTSP_ADDR,      \r\n"
           "              L.STRM_RTMP_ADDR     = M.STRM_RTMP_ADDR,      \r\n"
           "              L.STRM_HTTP_ADDR     = M.STRM_HTTP_ADDR,      \r\n"
           "              L.CCTV_IP            = M.CCTV_IP,             \r\n"
           "              L.CCTV_PORT          = M.CCTV_PORT,           \r\n"
           "              L.CCTV_ID            = M.CCTV_ID,             \r\n"
           "              L.CMRA_PSWD          = M.CMRA_PSWD,           \r\n"
           "              L.CCTV_CHNL          = M.CCTV_CHNL            \r\n"
           "WHEN NOT MATCHED THEN               \r\n"
           "   INSERT (                         \r\n"
           "           CCTV_CTLR_NMBR,          \r\n"
           "           CCTV_CTLR_ID,            \r\n"
           "           CCTV_NM,                 \r\n"
           "           CCTV_CTLR_IP,            \r\n"
           "           CCTV_CTLR_PORT,          \r\n"
           "           CCTV_CTLR_LOCAL_NO,      \r\n"
           "           CCTV_TYPE_CD,            \r\n"
           "           ISTL_LCTN_NM,            \r\n"
           "           X_CRDN,                  \r\n"
           "           Y_CRDN,                  \r\n"
           "           DEL_YN,                  \r\n"
           "           STRM_SVR_IP,             \r\n"
           "           STRM_SESN_NM	,           \r\n"
           "           STRM_RTSP_ADDR,          \r\n"
           "           STRM_RTMP_ADDR,          \r\n"
           "           STRM_HTTP_ADDR,          \r\n"
           "           CCTV_IP,                 \r\n"
           "           CCTV_PORT,               \r\n"
           "           CCTV_ID,                 \r\n"
           "           CMRA_PSWD,               \r\n"
           "           CCTV_CHNL                \r\n"
           "           )                        \r\n"
           "   VALUES (                         \r\n"
           "           M.CCTV_CTLR_NMBR,        \r\n"
           "           M.CCTV_CTLR_ID,          \r\n"
           "           M.CCTV_NM,               \r\n"
           "           M.CCTV_CTLR_IP,          \r\n"
           "           M.CCTV_CTLR_PORT,        \r\n"
           "           M.CCTV_CTLR_LOCAL_NO,    \r\n"
           "           M.CCTV_TYPE_CD,          \r\n"
           "           M.ISTL_LCTN_NM,          \r\n"
           "           M.X_CRDN,                \r\n"
           "           M.Y_CRDN,                \r\n"
           "           M.DEL_YN,                \r\n"
           "           M.STRM_SVR_IP,           \r\n"
           "           M.STRM_SESN_NM	,       \r\n"
           "           M.STRM_RTSP_ADDR,        \r\n"
           "           M.STRM_RTMP_ADDR,        \r\n"
           "           M.STRM_HTTP_ADDR,        \r\n"
           "           M.CCTV_IP,               \r\n"
           "           M.CCTV_PORT,             \r\n"
           "           M.CCTV_ID,               \r\n"
           "           M.CMRA_PSWD,             \r\n"
           "           M.CCTV_CHNL              \r\n"
           "           )                        \r\n";

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

            pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->CCTV_CTLR_ID;
            pADO->Parameters->ParamByName("p03")->Value = AObj->CCTV_NM;
            pADO->Parameters->ParamByName("p04")->Value = AObj->CCTV_CTLR_IP;
            pADO->Parameters->ParamByName("p05")->Value = AObj->CCTV_CTLR_PORT;
            pADO->Parameters->ParamByName("p06")->Value = AObj->CCTV_CTLR_LOCAL_NO;
            pADO->Parameters->ParamByName("p07")->Value = AObj->CCTV_TYPE_CD;
            pADO->Parameters->ParamByName("p08")->Value = AObj->ISTL_LCTN_NM;
            pADO->Parameters->ParamByName("p09")->Value = AObj->X_CRDN;
            pADO->Parameters->ParamByName("p10")->Value = AObj->Y_CRDN;
            pADO->Parameters->ParamByName("p11")->Value = AObj->DEL_YN;
            pADO->Parameters->ParamByName("p12")->Value = AObj->STRM_SVR_IP;
            pADO->Parameters->ParamByName("p13")->Value = AObj->STRM_SESN_NM;
            pADO->Parameters->ParamByName("p14")->Value = AObj->STRM_RTSP_ADDR;
            pADO->Parameters->ParamByName("p15")->Value = AObj->STRM_RTMP_ADDR;
            pADO->Parameters->ParamByName("p16")->Value = AObj->STRM_HTTP_ADDR;
            pADO->Parameters->ParamByName("p17")->Value = AObj->CCTV_IP;
            pADO->Parameters->ParamByName("p18")->Value = AObj->CCTV_PORT;
            pADO->Parameters->ParamByName("p19")->Value = AObj->CCTV_ID;
            pADO->Parameters->ParamByName("p20")->Value = AObj->CMRA_PSWD;
            pADO->Parameters->ParamByName("p21")->Value = AObj->CCTV_CHNL;

			pADO->ExecSQL();

            return MergeFcltInfo(AObj, ADbConn);
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::InsertCctv", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::InsertCctv", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

    return true;
#endif
}
//---------------------------------------------------------------------------

bool TCctvCtlrManager::UpdateCctv(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    return MergeCctv(AObj, ADbConn);
}
//---------------------------------------------------------------------------

#ifdef D_CCTV_HANTE
bool TCctvCtlrManager::MergeCctv(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "MERGE INTO TB_CCTV_CTLR L                   \r\n"
           "USING (SELECT                               \r\n"
           "              :p01 AS CCTV_CTLR_NMBR,       \r\n"
           "              :p02 AS CCTV_CTLR_ID,         \r\n"
           "              :p03 AS CCTV_NM,              \r\n"
           "              :p04 AS CCTV_CTLR_IP,         \r\n"
           "              :p05 AS CCTV_CTLR_PORT,       \r\n"
           "              :p06 AS CCTV_CTLR_LOCAL_NO,   \r\n"
           "              :p07 AS CCTV_TYPE_CD,         \r\n"
           "              :p08 AS ISTL_LCTN_NM,         \r\n"
           "              :p09 AS X_CRDN,               \r\n"
           "              :p10 AS Y_CRDN,               \r\n"
           "              :p11 AS DEL_YN,               \r\n"
           "              :p12 AS STRM_SVR_IP,          \r\n"
           "              :p13 AS STRM_SESN_NM,         \r\n"
           "              :p14 AS STRM_RTSP_ADDR,       \r\n"
           "              :p15 AS STRM_RTMP_ADDR,       \r\n"
           "              :p16 AS STRM_HTTP_ADDR,       \r\n"
           "              :p17 AS CCTV_IP,              \r\n"
           "              :p18 AS CCTV_PORT,            \r\n"
           "              :p19 AS CCTV_ID,              \r\n"
           "              :p20 AS CMRA_PSWD,            \r\n"
           "              :p21 AS CCTV_CHNL             \r\n"
           "         FROM DUAL) M                       \r\n"
           "        ON (L.CCTV_CTLR_NMBR = M.CCTV_CTLR_NMBR)            \r\n"
           "WHEN MATCHED THEN                                           \r\n"
           "   UPDATE SET L.CCTV_CTLR_ID       = M.CCTV_CTLR_ID,        \r\n"
           "              L.CCTV_NM            = M.CCTV_NM,             \r\n"
           "              L.CCTV_CTLR_IP       = M.CCTV_CTLR_IP,        \r\n"
           "              L.CCTV_CTLR_PORT     = M.CCTV_CTLR_PORT,      \r\n"
           "              L.CCTV_CTLR_LOCAL_NO = M.CCTV_CTLR_LOCAL_NO,  \r\n"
           "              L.CCTV_TYPE_CD       = M.CCTV_TYPE_CD,        \r\n"
           "              L.ISTL_LCTN_NM       = M.ISTL_LCTN_NM,        \r\n"
           "              L.X_CRDN             = M.X_CRDN,              \r\n"
           "              L.Y_CRDN             = M.Y_CRDN,              \r\n"
           "              L.DEL_YN             = M.DEL_YN,              \r\n"
           "              L.STRM_SVR_IP        = M.STRM_SVR_IP,         \r\n"
           "              L.STRM_SESN_NM       = M.STRM_SESN_NM,        \r\n"
           "              L.STRM_RTSP_ADDR     = M.STRM_RTSP_ADDR,      \r\n"
           "              L.STRM_RTMP_ADDR     = M.STRM_RTMP_ADDR,      \r\n"
           "              L.STRM_HTTP_ADDR     = M.STRM_HTTP_ADDR,      \r\n"
           "              L.CCTV_IP            = M.CCTV_IP,             \r\n"
           "              L.CCTV_PORT          = M.CCTV_PORT,           \r\n"
           "              L.CCTV_ID            = M.CCTV_ID,             \r\n"
           "              L.CMRA_PSWD          = M.CMRA_PSWD,           \r\n"
           "              L.CCTV_CHNL          = M.CCTV_CHNL            \r\n"
           "WHEN NOT MATCHED THEN               \r\n"
           "   INSERT (                         \r\n"
           "           CCTV_CTLR_NMBR,          \r\n"
           "           CCTV_CTLR_ID,            \r\n"
           "           CCTV_NM,                 \r\n"
           "           CCTV_CTLR_IP,            \r\n"
           "           CCTV_CTLR_PORT,          \r\n"
           "           CCTV_CTLR_LOCAL_NO,      \r\n"
           "           CCTV_TYPE_CD,            \r\n"
           "           ISTL_LCTN_NM,            \r\n"
           "           X_CRDN,                  \r\n"
           "           Y_CRDN,                  \r\n"
           "           DEL_YN,                  \r\n"
           "           STRM_SVR_IP,             \r\n"
           "           STRM_SESN_NM	,           \r\n"
           "           STRM_RTSP_ADDR,          \r\n"
           "           STRM_RTMP_ADDR,          \r\n"
           "           STRM_HTTP_ADDR,          \r\n"
           "           CCTV_IP,                 \r\n"
           "           CCTV_PORT,               \r\n"
           "           CCTV_ID,                 \r\n"
           "           CMRA_PSWD,               \r\n"
           "           CCTV_CHNL                \r\n"
           "           )                        \r\n"
           "   VALUES (                         \r\n"
           "           M.CCTV_CTLR_NMBR,        \r\n"
           "           M.CCTV_CTLR_ID,          \r\n"
           "           M.CCTV_NM,               \r\n"
           "           M.CCTV_CTLR_IP,          \r\n"
           "           M.CCTV_CTLR_PORT,        \r\n"
           "           M.CCTV_CTLR_LOCAL_NO,    \r\n"
           "           M.CCTV_TYPE_CD,          \r\n"
           "           M.ISTL_LCTN_NM,          \r\n"
           "           M.X_CRDN,                \r\n"
           "           M.Y_CRDN,                \r\n"
           "           M.DEL_YN,                \r\n"
           "           M.STRM_SVR_IP,           \r\n"
           "           M.STRM_SESN_NM	,       \r\n"
           "           M.STRM_RTSP_ADDR,        \r\n"
           "           M.STRM_RTMP_ADDR,        \r\n"
           "           M.STRM_HTTP_ADDR,        \r\n"
           "           M.CCTV_IP,               \r\n"
           "           M.CCTV_PORT,             \r\n"
           "           M.CCTV_ID,               \r\n"
           "           M.CMRA_PSWD,             \r\n"
           "           M.CCTV_CHNL              \r\n"
           "           )                        \r\n";

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

            pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->CCTV_CTLR_ID;
            pADO->Parameters->ParamByName("p03")->Value = AObj->CCTV_NM;
            pADO->Parameters->ParamByName("p04")->Value = AObj->CCTV_CTLR_IP;
            pADO->Parameters->ParamByName("p05")->Value = AObj->CCTV_CTLR_PORT;
            pADO->Parameters->ParamByName("p06")->Value = AObj->CCTV_CTLR_LOCAL_NO;
            pADO->Parameters->ParamByName("p07")->Value = AObj->CCTV_TYPE_CD;
            pADO->Parameters->ParamByName("p08")->Value = AObj->ISTL_LCTN_NM;
            pADO->Parameters->ParamByName("p09")->Value = AObj->X_CRDN;
            pADO->Parameters->ParamByName("p10")->Value = AObj->Y_CRDN;
            pADO->Parameters->ParamByName("p11")->Value = AObj->DEL_YN;
            pADO->Parameters->ParamByName("p12")->Value = AObj->STRM_SVR_IP;
            pADO->Parameters->ParamByName("p13")->Value = AObj->STRM_SESN_NM;
            pADO->Parameters->ParamByName("p14")->Value = AObj->STRM_RTSP_ADDR;
            pADO->Parameters->ParamByName("p15")->Value = AObj->STRM_RTMP_ADDR;
            pADO->Parameters->ParamByName("p16")->Value = AObj->STRM_HTTP_ADDR;
            pADO->Parameters->ParamByName("p17")->Value = AObj->CCTV_IP;
            pADO->Parameters->ParamByName("p18")->Value = AObj->CCTV_PORT;
            pADO->Parameters->ParamByName("p19")->Value = AObj->CCTV_ID;
            pADO->Parameters->ParamByName("p20")->Value = AObj->CMRA_PSWD;
            pADO->Parameters->ParamByName("p21")->Value = AObj->CCTV_CHNL;

			pADO->ExecSQL();

            return MergeFcltInfo(AObj, ADbConn);
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::MergeCctv", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::MergeCctv", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

    return true;
}
#else
bool TCctvCtlrManager::MergeCctv(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "MERGE INTO TB_CCTV_CTLR L                                 \r\n"
           "USING (SELECT                                             \r\n"
           "              :p01 AS CCTV_MNGM_NMBR,                     \r\n"
           "              :p02 AS CCTV_CTLR_ID,                       \r\n"
           "              :p03 AS CCTV_CTLR_IP,                       \r\n"
           "              :p04 AS CCTV_CTLR_PORT,                     \r\n"
           "              :p05 AS CCTV_CAPT_IP,                       \r\n"
           "              :p06 AS CCTV_CAPT_PORT,                     \r\n"
           "              :p07 AS CCTV_FIBR_IP,                       \r\n"
           "              :p08 AS CCTV_ENCD_IP,                       \r\n"
           "              :p09 AS STRM_SVR_IP,                        \r\n"
           "              :p10 AS STRM_SVR_PORT,                      \r\n"
           "              :p11 AS STRM_SESN_NM,                       \r\n"
           "              :p12 AS X_CRDN,                             \r\n"
           "              :p13 AS Y_CRDN,                             \r\n"
           "              :p14 AS ISTL_LCTN_NM,                       \r\n"
           "              :p15 AS ISTL_LCTN_ADDR,                     \r\n"
           "              :p16 AS CCTV_CHNL,                          \r\n"
           "              :p17 AS DEL_YN,                             \r\n"
           "              :p18 AS LINK_ID,                            \r\n"
           "              :p19 AS NODE_ID,                            \r\n"
           "              :p20 AS CCTV_ID,                            \r\n"
           "              :p21 AS RELY_PORT,                          \r\n"
           "              :p22 AS STRM_RTSP_ADDR,                     \r\n"
           "              :p23 AS STRM_RTMP_ADDR,                     \r\n"
           "              :p24 AS STRM_HTTP_ADDR,                     \r\n"
           "              :p25 AS STRM_STOR_ADDR,                     \r\n"
           "              :p26 AS AREA_CD,                            \r\n"
           "              :p27 AS CCTV_TYPE,                          \r\n"
           "              :p28 AS CCTV_SBST_DSPL_YN,                  \r\n"
           "              :p29 AS CCTV_LC,                            \r\n"
//           "              :p30 AS INTR_RTMP_ADDR,                     \r\n"
//           "              :p31 AS SYOP_CNTL_YN,                       \r\n"
           "              :p32 AS CMRA_ID,                            \r\n"
           "              :p33 AS CMRA_PSWD,                          \r\n"
           "              :p34 AS CMRA_CHNL,                          \r\n"
           "              :p35 AS CMRA_PORT,                          \r\n"
           "              :p36 AS CMRA_MODL,                          \r\n"
           "              :p37 AS FULL_STRM_SESN_NM                   \r\n"
           "         FROM DUAL) M                                     \r\n"
           "        ON (L.CCTV_MNGM_NMBR = M.CCTV_MNGM_NMBR)          \r\n"
           "WHEN MATCHED THEN                                         \r\n"
           "   UPDATE SET                                             \r\n"
           "              L.CCTV_CTLR_ID      = M.CCTV_CTLR_ID,       \r\n"
           "              L.CCTV_CTLR_IP      = M.CCTV_CTLR_IP,       \r\n"
           "              L.CCTV_CTLR_PORT    = M.CCTV_CTLR_PORT,     \r\n"
           "              L.CCTV_CAPT_IP      = M.CCTV_CAPT_IP,       \r\n"
           "              L.CCTV_CAPT_PORT    = M.CCTV_CAPT_PORT,     \r\n"
           "              L.CCTV_FIBR_IP      = M.CCTV_FIBR_IP,       \r\n"
           "              L.CCTV_ENCD_IP      = M.CCTV_ENCD_IP,       \r\n"
           "              L.STRM_SVR_IP       = M.STRM_SVR_IP,        \r\n"
           "              L.STRM_SVR_PORT     = M.STRM_SVR_PORT,      \r\n"
           "              L.STRM_SESN_NM      = M.STRM_SESN_NM,       \r\n"
           "              L.X_CRDN            = M.X_CRDN,             \r\n"
           "              L.Y_CRDN            = M.Y_CRDN,             \r\n"
           "              L.ISTL_LCTN_NM      = M.ISTL_LCTN_NM,       \r\n"
           "              L.ISTL_LCTN_ADDR    = M.ISTL_LCTN_ADDR,     \r\n"
           "              L.CCTV_CHNL         = M.CCTV_CHNL,          \r\n"
           "              L.DEL_YN            = M.DEL_YN,             \r\n"
           "              L.LINK_ID           = M.LINK_ID,            \r\n"
           "              L.NODE_ID           = M.NODE_ID,            \r\n"
           "              L.CCTV_ID           = M.CCTV_ID,            \r\n"
           "              L.RELY_PORT         = M.RELY_PORT,          \r\n"
           "              L.STRM_RTSP_ADDR    = M.STRM_RTSP_ADDR,     \r\n"
           "              L.STRM_RTMP_ADDR    = M.STRM_RTMP_ADDR,     \r\n"
           "              L.STRM_HTTP_ADDR    = M.STRM_HTTP_ADDR,     \r\n"
           "              L.STRM_STOR_ADDR    = M.STRM_STOR_ADDR,     \r\n"
           "              L.AREA_CD           = M.AREA_CD,            \r\n"
           "              L.CCTV_TYPE         = M.CCTV_TYPE,          \r\n"
           "              L.CCTV_SBST_DSPL_YN = M.CCTV_SBST_DSPL_YN,  \r\n"
           "              L.CCTV_LC           = M.CCTV_LC,            \r\n"
//           "              L.INTR_RTMP_ADDR    = M.INTR_RTMP_ADDR,     \r\n"
//           "              L.SYOP_CNTL_YN      = M.SYOP_CNTL_YN,       \r\n"
           "              L.CMRA_ID           = M.CMRA_ID,            \r\n"
           "              L.CMRA_PSWD         = M.CMRA_PSWD,          \r\n"
           "              L.CMRA_CHNL         = M.CMRA_CHNL,          \r\n"
           "              L.CMRA_PORT         = M.CMRA_PORT,          \r\n"
           "              L.CMRA_MODL         = M.CMRA_MODL,          \r\n"
           "              L.FULL_STRM_SESN_NM = M.FULL_STRM_SESN_NM   \r\n"
           "WHEN NOT MATCHED THEN                                     \r\n"
           "   INSERT (                                               \r\n"
           "           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"
           "           X_CRDN,                                        \r\n"
           "           Y_CRDN,                                        \r\n"
           "           ISTL_LCTN_NM,                                  \r\n"
           "           ISTL_LCTN_ADDR,                                \r\n"
           "           CCTV_CHNL,                                     \r\n"
           "           DEL_YN,                                        \r\n"
           "           LINK_ID,                                       \r\n"
           "           NODE_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"
           "           STRM_STOR_ADDR,                                \r\n"
           "           AREA_CD,                                       \r\n"
           "           CCTV_TYPE,                                     \r\n"
           "           CCTV_SBST_DSPL_YN,                             \r\n"
           "           CCTV_LC,                                       \r\n"
//           "           INTR_RTMP_ADDR,                                \r\n"
//           "           SYOP_CNTL_YN,                                  \r\n"
           "           CMRA_ID,                                       \r\n"
           "           CMRA_PSWD,                                     \r\n"
           "           CMRA_CHNL,                                     \r\n"
           "           CMRA_PORT,                                     \r\n"
           "           CMRA_MODL,                                     \r\n"
           "           FULL_STRM_SESN_NM )                            \r\n"
           "   VALUES (                                               \r\n"
           "           M.CCTV_MNGM_NMBR,                              \r\n"
           "           M.CCTV_CTLR_ID,                                \r\n"
           "           M.CCTV_CTLR_IP,                                \r\n"
           "           M.CCTV_CTLR_PORT,                              \r\n"
           "           M.CCTV_CAPT_IP,                                \r\n"
           "           M.CCTV_CAPT_PORT,                              \r\n"
           "           M.CCTV_FIBR_IP,                                \r\n"
           "           M.CCTV_ENCD_IP,                                \r\n"
           "           M.STRM_SVR_IP,                                 \r\n"
           "           M.STRM_SVR_PORT,                               \r\n"
           "           M.STRM_SESN_NM,                                \r\n"
           "           M.X_CRDN,                                      \r\n"
           "           M.Y_CRDN,                                      \r\n"
           "           M.ISTL_LCTN_NM,                                \r\n"
           "           M.ISTL_LCTN_ADDR,                              \r\n"
           "           M.CCTV_CHNL,                                   \r\n"
           "           M.DEL_YN,                                      \r\n"
           "           M.LINK_ID,                                     \r\n"
           "           M.NODE_ID,                                     \r\n"
           "           M.CCTV_ID,                                     \r\n"
           "           M.RELY_PORT,                                   \r\n"
           "           M.STRM_RTSP_ADDR,                              \r\n"
           "           M.STRM_RTMP_ADDR,                              \r\n"
           "           M.STRM_HTTP_ADDR,                              \r\n"
           "           M.STRM_STOR_ADDR,                              \r\n"
           "           M.AREA_CD,                                     \r\n"
           "           M.CCTV_TYPE,                                   \r\n"
           "           M.CCTV_SBST_DSPL_YN,                           \r\n"
           "           M.CCTV_LC,                                     \r\n"
//           "           M.INTR_RTMP_ADDR,                              \r\n"
//           "           M.SYOP_CNTL_YN,                                \r\n"
           "           M.CMRA_ID,                                     \r\n"
           "           M.CMRA_PSWD,                                   \r\n"
           "           M.CMRA_CHNL,                                   \r\n"
           "           M.CMRA_PORT,                                   \r\n"
           "           M.CMRA_MODL,                                   \r\n"
           "           M.FULL_STRM_SESN_NM )                          \r\n";

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

            pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_NMBR;     //CCTV_MNGM_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->CCTV_CTLR_ID;
            pADO->Parameters->ParamByName("p03")->Value = AObj->CCTV_CTLR_IP;
            pADO->Parameters->ParamByName("p04")->Value = AObj->CCTV_CTLR_PORT;
            pADO->Parameters->ParamByName("p05")->Value = AObj->CCTV_CAPT_IP;
            pADO->Parameters->ParamByName("p06")->Value = AObj->CCTV_CAPT_PORT;
            pADO->Parameters->ParamByName("p07")->Value = AObj->CCTV_FIBR_IP;
            pADO->Parameters->ParamByName("p08")->Value = AObj->CCTV_ENCD_IP;
            pADO->Parameters->ParamByName("p09")->Value = AObj->STRM_SVR_IP;
            pADO->Parameters->ParamByName("p10")->Value = AObj->STRM_SVR_PORT;
            pADO->Parameters->ParamByName("p11")->Value = AObj->STRM_SESN_NM;
            pADO->Parameters->ParamByName("p12")->Value = AObj->X_CRDN;
            pADO->Parameters->ParamByName("p13")->Value = AObj->Y_CRDN;
            pADO->Parameters->ParamByName("p14")->Value = AObj->CCTV_NM;            //ISTL_LCTN_NM;
            pADO->Parameters->ParamByName("p15")->Value = AObj->ISTL_LCTN_ADDR;
            pADO->Parameters->ParamByName("p16")->Value = AObj->CCTV_CHNL;
            pADO->Parameters->ParamByName("p17")->Value = AObj->DEL_YN;
            pADO->Parameters->ParamByName("p18")->Value = AObj->LINK_ID;
            pADO->Parameters->ParamByName("p19")->Value = AObj->NODE_ID;
            pADO->Parameters->ParamByName("p20")->Value = AObj->CCTV_ID;
            pADO->Parameters->ParamByName("p21")->Value = AObj->RELY_PORT;
            pADO->Parameters->ParamByName("p22")->Value = AObj->STRM_RTSP_ADDR;
            pADO->Parameters->ParamByName("p23")->Value = AObj->STRM_RTMP_ADDR;
            pADO->Parameters->ParamByName("p24")->Value = AObj->STRM_HTTP_ADDR;
            pADO->Parameters->ParamByName("p25")->Value = AObj->STRM_STOR_ADDR;
            pADO->Parameters->ParamByName("p26")->Value = AObj->AREA_CD;
            pADO->Parameters->ParamByName("p27")->Value = AObj->CCTV_TYPE;
            pADO->Parameters->ParamByName("p28")->Value = AObj->CCTV_SBST_DSPL_YN;
            pADO->Parameters->ParamByName("p29")->Value = AObj->CCTV_AREA_DVSN;
            //pADO->Parameters->ParamByName("p30")->Value = AObj->INTR_RTMP_ADDR;
            //pADO->Parameters->ParamByName("p31")->Value = AObj->SYOP_CNTL_YN;
            pADO->Parameters->ParamByName("p32")->Value = AObj->CMRA_ID;
            pADO->Parameters->ParamByName("p33")->Value = AObj->CMRA_PSWD;
            pADO->Parameters->ParamByName("p34")->Value = AObj->CMRA_CHNL;
            pADO->Parameters->ParamByName("p35")->Value = AObj->CMRA_PORT;
            pADO->Parameters->ParamByName("p36")->Value = AObj->CMRA_MODL;
            pADO->Parameters->ParamByName("p37")->Value = AObj->FULL_STRM_ADDR;     //FULL_STRM_SESN_NM;

			pADO->ExecSQL();

            return MergeFcltInfo(AObj, ADbConn);
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::MergeCctv", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::MergeCctv", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

    return true;
}
#endif
//---------------------------------------------------------------------------

bool TCctvCtlrManager::MergeFcltInfo(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "MERGE INTO TB_FCLT_INFR L                                         \r\n"
           "USING (SELECT :p01 AS FCLT_ID,                                    \r\n"
           "              :p02 AS FCLT_TYPE,                                  \r\n"
           "              :p03 AS FCLT_LCTN                                   \r\n"
           "         FROM DUAL) M                                             \r\n"
           "        ON (L.FCLT_ID = M.FCLT_ID AND L.FCLT_TYPE = M.FCLT_TYPE)  \r\n"
           "WHEN MATCHED                                                      \r\n"
           "THEN                                                              \r\n"
           "   UPDATE SET L.FCLT_LCTN = M.FCLT_LCTN,                          \r\n"
           "              L.DEL_YN    = 'N'                                   \r\n"
           "WHEN NOT MATCHED                                                  \r\n"
           "THEN                                                              \r\n"
           "   INSERT (  FCLT_ID,   FCLT_TYPE,   FCLT_LCTN)                   \r\n"
           "   VALUES (M.FCLT_ID, M.FCLT_TYPE, M.FCLT_LCTN)                   \r\n";
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;
			pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_ID;
			pADO->Parameters->ParamByName("p02")->Value = "CCTV";
			pADO->Parameters->ParamByName("p03")->Value = AObj->CCTV_NM;
			pADO->ExecSQL();

            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::MergeFcltInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::MergeFcltInfo", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TCctvCtlrManager::GetNextCctvId(int &ANmbr, int &AId, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#ifdef D_CCTV_HANTE
    sQry = "SELECT NVL(MAX(CCTV_CTLR_NMBR), 10000) + 1 AS NEWID FROM TB_CCTV_CTLR \r\n";
#else
    sQry = "SELECT NVL(MAX(CCTV_MNGM_NMBR), 0) + 1 AS NEWID FROM TB_CCTV_CTLR \r\n";
#endif

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

            pADO->Prepared = true;
			pADO->Open();
            ANmbr = pADO->FieldByName("NEWID")->AsInteger;
#ifdef D_CCTV_HANTE
            AId = ANmbr / 10000;
#else
            AId = ANmbr;
#endif
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::GetNextCctvId", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::GetNextCctvId", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return false;
}
//---------------------------------------------------------------------------

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

    FLists.Lock();
    try
    {
        FOR_STL(TCctvCtlr*, pObj, FLists)
        {
            pObj->FLists.RemoveAll();
        }
    }
    __finally
    {
        FLists.UnLock();
    }

    sQry = "SELECT B.*                                 \r\n"
           "  FROM TB_CCTV_CTLR A,                     \r\n"
           "       TB_CCTV_PSET B                      \r\n"
           " WHERE A.CCTV_CTLR_NMBR = B.CCTV_CTLR_NMBR \r\n"
           " ORDER BY B.CCTV_CTLR_NMBR, B.PSET_NMBR    \r\n";
    try
    {
        String CCTV_CTLR_NMBR;

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

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
                CCTV_CTLR_NMBR = pADO->FieldByName("CCTV_CTLR_NMBR")->AsString;
				TCctvCtlr *pCctv = FLists.Find(String(CCTV_CTLR_NMBR));
                if (!pCctv) continue;

                TCctvPset *pObj = new TCctvPset();
                if (pObj)
                {
                    pObj->CCTV_CTLR_NMBR = CCTV_CTLR_NMBR;
                    pObj->PSET_NMBR     = pADO->FieldByName("PSET_NMBR")->AsInteger;
                    pObj->PSET_NM       = pADO->FieldByName("PSET_NM")->AsString;
#if 1
                    pObj->PAN           = pADO->FieldByName("PAN_VAL")->AsInteger;
                    pObj->TILT          = pADO->FieldByName("TILT_VAL")->AsInteger;
                    pObj->ZOOM          = pADO->FieldByName("ZOOM_VAL")->AsInteger;
                    pObj->FOCS          = pADO->FieldByName("FOCS_VAL")->AsInteger;
#else
                    pObj->PAN           = pADO->FieldByName("PAN")->AsInteger;
                    pObj->TILT          = pADO->FieldByName("TILT")->AsInteger;
                    pObj->ZOOM          = pADO->FieldByName("ZOOM")->AsInteger;
                    pObj->FOCS          = pADO->FieldByName("FOCS")->AsInteger;
                    pObj->ANGLE         = pADO->FieldByName("ANGLE")->AsInteger;
#endif
                    pObj->DFLT_YN       = pADO->FieldByName("DFLT_YN")->AsString;

                    pObj->DEL_YN         = "N";

                    pCctv->FLists.Push(pObj->PSET_NMBR, pObj);
                }
            }
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("TCctvCtlrManager::LoadPreSet", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORMSG("TCctvCtlrManager::LoadPreSet", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

bool TCctvCtlrManager::SavePreSet(TCctvCtlr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();

#if 1
sQry = "DELETE FROM TB_CCTV_PSET WHERE CCTV_MNGM_NMBR = :p01";
#else
sQry = "DELETE FROM TB_CCTV_PSET WHERE CCTV_CTLR_NMBR = :p01";
#endif
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;
			pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_NMBR;
			pADO->ExecSQL();

#if 1
sQry = "INSERT INTO TB_CCTV_PSET(                               \r\n"
       "        CCTV_MNGM_NMBR,                                 \r\n"
       "        PSET_NMBR,                                      \r\n"
       "        PSET_NM,                                        \r\n"
       "        PAN_VAL,                                        \r\n"
       "        TILT_VAL,                                       \r\n"
       "        ZOOM_VAL,                                       \r\n"
       "        FOCS_VAL,                                       \r\n"
       "        DFLT_YN )                                       \r\n"
       " VALUES(:p01, :p02, :p03, :p04, :p05, :p06, :p07, :p08) \r\n";
#else
sQry = "INSERT INTO TB_CCTV_PSET(                               \r\n"
       "        CCTV_CTLR_NMBR,                                 \r\n"
       "        PSET_NMBR,                                      \r\n"
       "        PSET_NM,                                        \r\n"
       "        PAN,                                            \r\n"
       "        TILT,                                           \r\n"
       "        ZOOM,                                           \r\n"
       "        FOCS,                                           \r\n"
       "        DFLT_YN )                                       \r\n"
       " VALUES(:p01, :p02, :p03, :p04, :p05, :p06, :p07, :p08) \r\n";
#endif

			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;
            FOR_STL(TCctvPset *, pObj, AObj->FLists)
            {
                if (pObj->DEL_YN != "N") continue;

                pADO->Parameters->ParamByName("p01")->Value = pObj->CCTV_CTLR_NMBR;
                pADO->Parameters->ParamByName("p02")->Value = pObj->PSET_NMBR;
                pADO->Parameters->ParamByName("p03")->Value = pObj->PSET_NM;
                pADO->Parameters->ParamByName("p04")->Value = pObj->PAN;
                pADO->Parameters->ParamByName("p05")->Value = pObj->TILT;
                pADO->Parameters->ParamByName("p06")->Value = pObj->ZOOM;
                pADO->Parameters->ParamByName("p07")->Value = pObj->FOCS;
                pADO->Parameters->ParamByName("p08")->Value = pObj->DFLT_YN;

    			pADO->ExecSQL();
            }
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::SavePreSet", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::SavePreSet", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TCctvCtlrManager::DeletePreSet(TCctvCtlr *AObj, int APsetNmbr, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    TCctvPset* pObj = AObj->FLists.Find(APsetNmbr);
    if (!pObj) return false;

#if 1
    sQry = "DELETE FROM TB_CCTV_PSET WHERE CCTV_MNGM_NMBR = :p01 AND PSET_NMBR = :p02";
#else
    sQry = "DELETE FROM TB_CCTV_PSET WHERE CCTV_CTLR_NMBR = :p01 AND PSET_NMBR = :p02";
#endif

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();

			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

			pADO->Parameters->ParamByName("p01")->Value = AObj->CCTV_CTLR_NMBR;
			pADO->Parameters->ParamByName("p02")->Value = APsetNmbr;

			pADO->ExecSQL();

            pObj->DEL_YN = "Y";

            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::DeletePreSet", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::DeletePreSet", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TCctvCtlrManager::MergePreSet(TCctvCtlr *AObj, TCctvPset* APset, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();

#if 1
    sQry = "MERGE INTO TB_CCTV_PSET L                       \r\n"
           "USING (SELECT                                   \r\n"
           "              :p01 AS CCTV_MNGM_NMBR,           \r\n"
           "              :p02 AS PSET_NMBR,                \r\n"
           "              :p03 AS PSET_NM,                  \r\n"
           "              :p04 AS PAN_VAL,                  \r\n"
           "              :p05 AS TILT_VAL,                 \r\n"
           "              :p06 AS ZOOM,                     \r\n"
           "              :p07 AS FOCS_VAL,                 \r\n"
           "              :p08 AS DFLT_YN                   \r\n"
           "         FROM DUAL) M                           \r\n"
           "        ON (L.CCTV_MNGM_NMBR = M.CCTV_MNGM_NMBR \r\n"
           "        AND L.PSET_NMBR      = M.PSET_NMBR )    \r\n"
           "WHEN MATCHED THEN                               \r\n"
           "   UPDATE SET L.PSET_NM = M.PSET_NM,            \r\n"
           "              L.PAN_VAL     = M.PAN_VAL,        \r\n"
           "              L.TILT_VAL    = M.TILT_VAL,       \r\n"
           "              L.ZOOM_VAL    = M.ZOOM_VAL,       \r\n"
           "              L.FOCS_VAL    = M.FOCS_VAL,       \r\n"
           "              L.DFLT_YN = M.DFLT_YN             \r\n"
           "WHEN NOT MATCHED THEN                           \r\n"
           "   INSERT (                                     \r\n"
           "        CCTV_MNGM_NMBR,                         \r\n"
           "        PSET_NMBR,                              \r\n"
           "        PSET_NM,                                \r\n"
           "        PAN_VAL,                                \r\n"
           "        TILT_VAL,                               \r\n"
           "        ZOOM_VAL,                               \r\n"
           "        FOCS_VAL,                               \r\n"
           "        DFLT_YN )                               \r\n"
           "   VALUES (                                     \r\n"
           "        M.CCTV_MNGM_NMBR,                       \r\n"
           "        M.PSET_NMBR,                            \r\n"
           "        M.PSET_NM,                              \r\n"
           "        M.PAN_VAL,                              \r\n"
           "        M.TILT_VAL,                             \r\n"
           "        M.ZOOM_VAL,                             \r\n"
           "        M.FOCS_VAL,                             \r\n"
           "        M.DFLT_YN )                             \r\n";
#else
    sQry = "MERGE INTO TB_CCTV_PSET L                       \r\n"
           "USING (SELECT                                   \r\n"
           "              :p01 AS CCTV_CTLR_NMBR,           \r\n"
           "              :p02 AS PSET_NMBR,                \r\n"
           "              :p03 AS PSET_NM,                  \r\n"
           "              :p04 AS PAN,                      \r\n"
           "              :p05 AS TILT,                     \r\n"
           "              :p06 AS ZOOM,                     \r\n"
           "              :p07 AS FOCS,                     \r\n"
           "              :p08 AS DFLT_YN                   \r\n"
           "         FROM DUAL) M                           \r\n"
           "        ON (L.CCTV_CTLR_NMBR = M.CCTV_CTLR_NMBR \r\n"
           "        AND L.PSET_NMBR      = M.PSET_NMBR )    \r\n"
           "WHEN MATCHED THEN                               \r\n"
           "   UPDATE SET L.PSET_NM = M.PSET_NM,            \r\n"
           "              L.PAN     = M.PAN,                \r\n"
           "              L.TILT    = M.TILT,               \r\n"
           "              L.ZOOM    = M.ZOOM,               \r\n"
           "              L.FOCS    = M.FOCS,               \r\n"
           "              L.DFLT_YN = M.DFLT_YN             \r\n"
           "WHEN NOT MATCHED THEN                           \r\n"
           "   INSERT (                                     \r\n"
           "        CCTV_CTLR_NMBR,                         \r\n"
           "        PSET_NMBR,                              \r\n"
           "        PSET_NM,                                \r\n"
           "        PAN,                                    \r\n"
           "        TILT,                                   \r\n"
           "        ZOOM,                                   \r\n"
           "        FOCS,                                   \r\n"
           "        DFLT_YN )                               \r\n"
           "   VALUES (                                     \r\n"
           "        M.CCTV_CTLR_NMBR,                       \r\n"
           "        M.PSET_NMBR,                            \r\n"
           "        M.PSET_NM,                              \r\n"
           "        M.PAN,                                  \r\n"
           "        M.TILT,                                 \r\n"
           "        M.ZOOM,                                 \r\n"
           "        M.FOCS,                                 \r\n"
           "        M.DFLT_YN )                             \r\n";
#endif

			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;
            FOR_STL(TCctvPset *, pObj, AObj->FLists)
            {
                if (pObj->DEL_YN != "N") continue;

                pADO->Parameters->ParamByName("p01")->Value = APset->CCTV_CTLR_NMBR;
                pADO->Parameters->ParamByName("p02")->Value = APset->PSET_NMBR;
                pADO->Parameters->ParamByName("p03")->Value = APset->PSET_NM;
                pADO->Parameters->ParamByName("p04")->Value = APset->PAN;
                pADO->Parameters->ParamByName("p05")->Value = APset->TILT;
                pADO->Parameters->ParamByName("p06")->Value = APset->ZOOM;
                pADO->Parameters->ParamByName("p07")->Value = APset->FOCS;
                pADO->Parameters->ParamByName("p08")->Value = APset->DFLT_YN;

    			pADO->ExecSQL();

                TCctvPset* pObj = AObj->FLists.Find(APset->PSET_NMBR);
                if (pObj)
                {
                    pObj->CCTV_CTLR_NMBR = APset->CCTV_CTLR_NMBR;
                    pObj->PSET_NMBR      = APset->PSET_NMBR;
                    pObj->PSET_NM        = APset->PSET_NM;
                    pObj->PAN            = APset->PAN;
                    pObj->TILT           = APset->TILT;
                    pObj->ZOOM           = APset->ZOOM;
                    pObj->FOCS           = APset->FOCS;
                    pObj->DFLT_YN        = APset->DFLT_YN;
                }
                else
                {
                    AObj->FLists.Push(APset->PSET_NMBR, APset);
                }
            }
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::SavePreSet", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::SavePreSet", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TCctvCtlrManager::InsCctvControlHs(String ACtlDt, String ACctvNmbr, String ACtlType, String ACtlVal, String ACtlRes, String AUserId, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "INSERT INTO TB_CCTV_CTRL_HS(               \r\n"
           "                          CTRL_DT,         \r\n"
           "                          CCTV_CTLR_NMBR,  \r\n"
           "                          CTRL_TYPE,       \r\n"
           "                          CTRL_VAL,        \r\n"
           "                          CTRL_RESULT,     \r\n"
           "                          USER_ID          \r\n"
           "                         )                 \r\n"
           "                   VALUES(                 \r\n"
           "                          :p01,            \r\n"
           "                          :p02,            \r\n"
           "                          :p03,            \r\n"
           "                          :p04,            \r\n"
           "                          :p05,            \r\n"
           "                          :p06             \r\n"
           "                         )                 \r\n";
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();

			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

            pADO->Parameters->ParamByName("p01")->Value = ACtlDt;
            pADO->Parameters->ParamByName("p02")->Value = ACctvNmbr;
            pADO->Parameters->ParamByName("p03")->Value = ACtlType;
            pADO->Parameters->ParamByName("p04")->Value = ACtlVal;
            pADO->Parameters->ParamByName("p05")->Value = ACtlRes;
            pADO->Parameters->ParamByName("p06")->Value = AUserId;
            pADO->ExecSQL();
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORLOG("TCctvCtlrManager::InsCctvControlHs", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            //DBERRORLOG("TCctvCtlrManager::InsCctvControlHs", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

