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

#pragma hdrstop

#include "CDSCctvCtlrF.h"
#include "AppGlobalF.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"
           "  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();

#if 0
                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 명칭
                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")->AsInteger;         //	N	NUMBER(5)	    Y			CCTV 제어기 지역번호
                pObj->STRM_STOR_ADDR      = pADO->FieldByName("STRM_STOR_ADDR")->AsString.Trim();       //	N	VARCHAR2(200)	Y			스트리밍 저장 주소
                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_SBST_DSPL_YN   = pADO->FieldByName("CCTV_SBST_DSPL_YN")->AsString.Trim();    //	N	CHAR(1)	        Y	'N'		CCTV 대체 표출 여부
                pObj->SYOP_CNTL_YN        = pADO->FieldByName("SYOP_CNTL_YN")->AsString.Trim();         //	N	CHAR(1)	        Y	'N'		운영자 제어 여부
                pObj->CCTV_IP             = pADO->FieldByName("CCTV_IP")->AsString.Trim();              //	N	VARCHAR2(20)	Y			목포 CCTV 제어 IP
                pObj->CCTV_PORT           = pADO->FieldByName("CCTV_PORT")->AsInteger;                  //	N	NUMBER(5)	    Y	1852		목포 CCTV 제어 PORT
                pObj->CCTV_ID             = pADO->FieldByName("CCTV_ID")->AsString.Trim();              //	N	VARCHAR2(20)	Y	'root'		목포 CCTV 제어 ID
                pObj->CCTV_PSWD           = pADO->FieldByName("CCTV_PSWD")->AsString.Trim();            //	N	VARCHAR2(20)	Y	'1234'		목포 CCTV 제어 PSWD
                pObj->CCTV_CHNL           = pADO->FieldByName("CCTV_CHNL")->AsInteger;                  //	N	NUMBER(5)	    Y	1		목포 CCTV 제어 CHANNEL
#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")->AsInteger;             //	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_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_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_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->CCTV_SBST_IMGN      = pADO->FieldByName("CCTV_SBST_IMGN")->AsString.Trim();       //	N	BLOB	        Y			CCTV 대체 영상

                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;

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

    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())
            {
                String CCTV_CTLR_NMBR = pADO->FieldByName("CCTV_CTLR_NMBR")->AsString;
                pObj = FLists.Find(CCTV_CTLR_NMBR);
                if (!pObj) continue;

                String UPDT_DT      = pADO->FieldByName("UPDT_DT")->AsString;
                String CONN_STTS_CD = pADO->FieldByName("CONN_STTS_CD")->AsString;
                if (CONN_STTS_CD != "CMS0")
                {
                    //통신장애
                    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;

    sQry = "UPDATE TB_CCTV_CTLR          \r\n"
           "   SET DEL_YN = 'Y'          \r\n"
           " WHERE CCTV_CTLR_NMBR = :p01 \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->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*/)
{
    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 CCTV_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.CCTV_PSWD          = M.CCTV_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"
           "           CCTV_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.CCTV_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->CCTV_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;
}
//---------------------------------------------------------------------------

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

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 CCTV_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.CCTV_PSWD          = M.CCTV_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"
           "           CCTV_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.CCTV_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->CCTV_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;
}
//---------------------------------------------------------------------------

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;

    sQry = "SELECT NVL(MAX(CCTV_CTLR_NMBR), 10000) + 1 AS NEWID FROM TB_CCTV_CTLR \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->Prepared = true;
			pADO->Open();
            ANmbr = pADO->FieldByName("NEWID")->AsInteger;
            AId = ANmbr / 10000;
            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;
                    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;
                    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();

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

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

			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;

    sQry = "DELETE FROM TB_CCTV_PSET WHERE CCTV_CTLR_NMBR = :p01 AND PSET_NMBR = :p02";

    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();

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

			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;
}
//---------------------------------------------------------------------------

