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

#pragma hdrstop

#include "CDSPrkPlceF.h"
#include "ITS_OPLibF.h"

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

#pragma package(smart_init)

TPrkPlce::TPrkPlce()
{
    FOPR = new TPrkPlceOpr();
}
//---------------------------------------------------------------------------
TPrkPlce::~TPrkPlce()
{
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
TPrkPlceManager *PrkPlceManager = NULL;
//---------------------------------------------------------------------------

/*
* PrltPrk Manager
*/
TPrkPlceManager::TPrkPlceManager()
{
}
//---------------------------------------------------------------------------
TPrkPlceManager::~TPrkPlceManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------
bool TPrkPlceManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                \r\n"
           "  FROM TB_PRK_PLCE      \r\n"
           " WHERE pis_type != 'N'  \r\n"
           "   AND 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())
            {
				TPrkPlce *pObj = new TPrkPlce();

                pObj->CTLR_NMBR                   = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;
                pObj->CTLR_ID                     = pADO->FieldByName("PRK_PLCE_MANAGE_NO")->AsString;
                pObj->PRK_PLCE_STTUS_VER          = pADO->FieldByName("PRK_PLCE_STTUS_VER")->AsString;
                pObj->NAME                        = pADO->FieldByName("PRK_PLCE_NM")->AsString;
                pObj->ISTL_LCTN_NM                = pADO->FieldByName("PRK_PLCE_NM")->AsString;
                pObj->ISTL_LCTN_ADDR              = pADO->FieldByName("PRK_PLCE_ADRES")->AsString.Trim();
                pObj->VMS_DSPL_NM                 = pADO->FieldByName("VMS_DSPL_NM")->AsString;
                //pObj->PRK_PLCE_ADRES              = pADO->FieldByName("PRK_PLCE_ADRES")->AsString;
                pObj->PRK_PLCE_INSTL_DE           = pADO->FieldByName("PRK_PLCE_INSTL_DE")->AsString;
                pObj->PRK_PLCE_ABL_DE             = pADO->FieldByName("PRK_PLCE_ABL_DE")->AsString;
                pObj->PRK_PLCE_ENTRC_NM           = pADO->FieldByName("PRK_PLCE_ENTRC_NM")->AsString;
                //pObj->PRK_PLCE_ENTRC_LA           = pADO->FieldByName("PRK_PLCE_ENTRC_LA")->AsString;
                //pObj->PRK_PLCE_ENTRC_LO           = pADO->FieldByName("PRK_PLCE_ENTRC_LO")->AsString;
                pObj->PRK_PLCE_ENTRC_EXTTY        = pADO->FieldByName("PRK_PLCE_ENTRC_EXTTY")->AsInteger;
                pObj->PARKING_TY                  = pADO->FieldByName("PARKING_TY")->AsInteger;
                pObj->PARKING_US                  = pADO->FieldByName("PARKING_US")->AsInteger;
                pObj->AR_LEVEL_SE                 = pADO->FieldByName("AR_LEVEL_SE")->AsInteger;
                //pObj->PRK_PLCE_IMAGE_DATA         = pADO->FieldByName("PRK_PLCE_IMAGE_DATA")->AsString;
                pObj->PRK_PLCE_IMAGE_TYPE         = pADO->FieldByName("PRK_PLCE_IMAGE_TYPE")->AsInteger;
                pObj->PRK_PLCE_IMAGE_DC           = pADO->FieldByName("PRK_PLCE_IMAGE_DC")->AsString;
                pObj->SYS_NE                      = pADO->FieldByName("SYS_NE")->AsString;
                pObj->PARKING_CNTRL_SYS_INSTL_DE  = pADO->FieldByName("PARKING_CNTRL_SYS_INSTL_DE")->AsString;
                pObj->RELATION_LAW_AND_ORDINANCES = pADO->FieldByName("RELATION_LAW_AND_ORDINANCES")->AsString;
                pObj->PRK_AVAIL_CARTYPE           = pADO->FieldByName("PRK_AVAIL_CARTYPE")->AsString;
                pObj->PRK_CMPRT_CO                = pADO->FieldByName("PRK_CMPRT_CO")->AsInteger;
                pObj->COLCT_DEVICE_INSTL_AT       = pADO->FieldByName("COLCT_DEVICE_INSTL_AT")->AsInteger;
                pObj->MASTER_CONTROLLER           = pADO->FieldByName("MASTER_CONTROLLER")->AsInteger;
                pObj->SLAVE_CONTROLLER            = pADO->FieldByName("SLAVE_CONTROLLER")->AsInteger;
                pObj->COLCT_DEVICE_QTY            = pADO->FieldByName("COLCT_DEVICE_QTY")->AsInteger;
                pObj->COLCT_DEVICE_KND            = pADO->FieldByName("COLCT_DEVICE_KND")->AsString;
                //pObj->TYPE_IMGAGE                 = pADO->FieldByName("TYPE_IMGAGE")->AsInteger;
                //pObj->TYPE_GEOMAGNETIC            = pADO->FieldByName("TYPE_GEOMAGNETIC")->AsInteger;
                //pObj->TYPE_RADAR                  = pADO->FieldByName("TYPE_RADAR")->AsInteger;
                //pObj->TYPE_LOOP                   = pADO->FieldByName("TYPE_LOOP")->AsInteger;
                //pObj->TYPE_ULTRASONIC             = pADO->FieldByName("TYPE_ULTRASONIC")->AsInteger;
                //pObj->TYPE_ETC                    = pADO->FieldByName("TYPE_ETC")->AsInteger;
                pObj->COLCT_DEVICE_INSTL_DE       = pADO->FieldByName("COLCT_DEVICE_INSTL_DE")->AsString;
                pObj->CRM_PRV_CCTV_INSTL_AT       = pADO->FieldByName("CRM_PRV_CCTV_INSTL_AT")->AsInteger;
                pObj->CRM_PRV_CCTV_INSTL_CO       = pADO->FieldByName("CRM_PRV_CCTV_INSTL_CO")->AsInteger;
                pObj->INFO_CREATE_TIME            = pADO->FieldByName("INFO_CREATE_TIME")->AsString;
                //pObj->PIS_TYPE                    = pADO->FieldByName("PIS_TYPE")->AsString;
                pObj->DEL_YN                      = pADO->FieldByName("DEL_YN")->AsString;

                pObj->OPR_INFO  = pADO->FieldByName("OPR_INFO")->AsString;
                pObj->MIN30_FEE = pADO->FieldByName("MIN30_FEE")->AsInteger;
                pObj->MIN10_FEE = pADO->FieldByName("MIN10_FEE")->AsInteger;
                pObj->DAY_FEE   = pADO->FieldByName("DAY_FEE")->AsInteger;
                pObj->MON_FEE   = pADO->FieldByName("MON_FEE")->AsInteger;

                pObj->TYPE_CD        = pADO->FieldByName("PIS_TYPE")->AsString.Trim();
                pObj->X_CRDN         = pADO->FieldByName("PRK_PLCE_ENTRC_LO")->AsFloat;
                pObj->Y_CRDN         = pADO->FieldByName("PRK_PLCE_ENTRC_LA")->AsFloat;
                pObj->DEL_YN         = pADO->FieldByName("DEL_YN")->AsString.Trim();


				FLists.Push(pObj->CTLR_NMBR, pObj);

                pObj->Completed = true;
                pObj->MEM_DEL   = "N";
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TPrkPlceManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TPrkPlceManager::LoadFromDb", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

#if 0
    LoadFromDbOpr(ADbConn);
    LoadFromDbFlr(ADbConn);
#endif

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

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

    sQry = "SELECT *                                                                \r\n"
           "  FROM TB_PRK_PLCE_STTS A, TB_PRK_PLCE B                                \r\n"
           " WHERE B.pis_type != 'N'                                                \r\n"
           "   AND B.del_yn    = 'N'                                                \r\n"
           "   AND A.prk_plce_nmbr = B.prk_plce_nmbr                                \r\n"
           "   AND A.UPDT_DT       >= TO_CHAR(SYSDATE-10/1440, 'YYYYMMDDHH24MISS')   \r\n";

    FLists.Lock();
    try
    {
        TPrkPlce *pObj = NULL;

        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();
            //int nRows = pADO->RecordCount;
            for( ; !pADO->Eof; pADO->Next())
            {
                String sPrltNmbr = pADO->FieldByName("prk_plce_nmbr")->AsString;
                pObj = FLists.Find(sPrltNmbr);
                if (!pObj) continue;

                String UPDT_DT      = pADO->FieldByName("UPDT_DT")->AsString;
                String CONN_STTS_CD = pADO->FieldByName("CMNC_STTS_CD")->AsString;
                if (CONN_STTS_CD != "CMS0")
                {
                    pObj->STATE.Comm = park_comm_error;
                    //통신장애
                    continue;
                }
                pObj->STATE.Comm = park_comm_normal;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadStatusFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadStatusFromDb", 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 TPrkPlceManager::LoadFromDbOpr(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                    \r\n"
           "  FROM TB_PRK_PLCE_OPR A      \r\n"
           " WHERE A.prk_plce_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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                AObj->FOPR->PRK_PLCE_NMBR             = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;               //	N	NUMBER(10)	    N			주차장 관리 번호
                AObj->FOPR->PRK_PLCE_OPR_VER          = pADO->FieldByName("PRK_PLCE_OPR_VER")->AsString;            //	N	VARCHAR2(10)	Y			주차운영 정보버전
                AObj->FOPR->CMPT_INST_NM              = pADO->FieldByName("CMPT_INST_NM")->AsString;                //	N	VARCHAR2(32)	Y			관할기관명
                AObj->FOPR->OPER_DEPT_NM              = pADO->FieldByName("OPER_DEPT_NM")->AsString;                //	N	VARCHAR2(32)	Y			운영기관 정보 - 운영부서명
                AObj->FOPR->OPER_PERSON_NM            = pADO->FieldByName("OPER_PERSON_NM")->AsString;              //	N	VARCHAR2(10)	Y			운영기관 정보 - 운영기관 담당자
                AObj->FOPR->OPER_CTT_PC_TEL           = pADO->FieldByName("OPER_CTT_PC_TEL")->AsString;             //	N	VARCHAR2(13)	Y			운영기관 정보 - 운영담당자 전화번호
                AObj->FOPR->OPER_CTT_PC_EMAIL         = pADO->FieldByName("OPER_CTT_PC_EMAIL")->AsString;           //	N	VARCHAR2(50)	Y			운영기관 정보 - 운영담당자 이메일
                AObj->FOPR->NO_DRV_DAY_OPERTN_AT      = pADO->FieldByName("NO_DRV_DAY_OPERTN_AT")->AsInteger;       //	N	NUMBER(1)	    Y			주차 부제 시행여부 (0 : 미시행, 1 : 2부제, 2 : 5부제, 3 : 10부제, 4 : 승용차요일제, 9 : 기타)
                AObj->FOPR->OPERTN_BS_FREE_TIME       = pADO->FieldByName("OPERTN_BS_FREE_TIME")->AsString;         //	N	VARCHAR2(8)	    Y			기본무료 시간, 주차장 회차 (기본 무료) (00:30:00)
                AObj->FOPR->OPN_CODE                  = pADO->FieldByName("OPN_CODE")->AsInteger;                   //	N	NUMBER(1)	    Y			개방코드, 운영시간 외 무료 개방 (0 : 미개방, 1 : 개방)
                AObj->FOPR->PARKING_CHRGE_EXCCLC_MTHD = pADO->FieldByName("PARKING_CHRGE_EXCCLC_MTHD")->AsInteger;  //	N	NUMBER(1)	    Y			주차요금 정산 방식 (0 : 유인정산, 1 : 무인정산, 2 : 혼합정산, 9 : 기타)
                AObj->FOPR->PARKING_CHRGE_PYMNT_MN    = pADO->FieldByName("PARKING_CHRGE_PYMNT_MN")->AsString;      //	N	VARCHAR2(8)	    Y			주차요금 지불수단 - 아래 유형 조합해서 생성됌 - 예시) 현금/신용카드 혼합결제 시 (11000000), 핀테크 결제 시 (00000100), 1: 현금, 2: 신용카드, 3: 교통카드, 4: 전자지불(하이패스), 5: 휴대폰소액결제, 6: 핀테크(OO페이), 7: MaaS 통합결제, 9: 기타
                AObj->FOPR->PARKING_RESVE_OPERTN_AT   = pADO->FieldByName("PARKING_RESVE_OPERTN_AT")->AsInteger;    //	N	NUMBER(1)	    Y			주차예약 시행여부 (0 : 미시행, 1 : 시행-주차장, 2 : 시행-주차구역, 3 : 시행-주차면)
                AObj->FOPR->PARTCLR_MATTER            = pADO->FieldByName("PARTCLR_MATTER")->AsString;              //	N	VARCHAR2(128)	Y			특이사항
                AObj->FOPR->INFO_CREATE_TIME          = pADO->FieldByName("INFO_CREATE_TIME")->AsString;            //	N	VARCHAR2(14)    Y			주차정보를 입력하여 생성하는 시각, (YYYY-MM-DD hh:mm:ss)
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOpr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOpr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------

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

    sQry = "SELECT A.*                    \r\n"
           "  FROM TB_PRK_PLCE_OPR A      \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();

            for( ; !pADO->Eof; pADO->Next())
            {
                String PRK_PLCE_NMBR = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;
                TPrkPlce *AObj = FLists.Find(PRK_PLCE_NMBR);
                if (AObj == NULL) {
                    continue;
                }
                AObj->FOPR->PRK_PLCE_NMBR             = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;               //	N	NUMBER(10)	    N			주차장 관리 번호
                AObj->FOPR->PRK_PLCE_OPR_VER          = pADO->FieldByName("PRK_PLCE_OPR_VER")->AsString;            //	N	VARCHAR2(10)	Y			주차운영 정보버전
                AObj->FOPR->CMPT_INST_NM              = pADO->FieldByName("CMPT_INST_NM")->AsString;                //	N	VARCHAR2(32)	Y			관할기관명
                AObj->FOPR->OPER_DEPT_NM              = pADO->FieldByName("OPER_DEPT_NM")->AsString;                //	N	VARCHAR2(32)	Y			운영기관 정보 - 운영부서명
                AObj->FOPR->OPER_PERSON_NM            = pADO->FieldByName("OPER_PERSON_NM")->AsString;              //	N	VARCHAR2(10)	Y			운영기관 정보 - 운영기관 담당자
                AObj->FOPR->OPER_CTT_PC_TEL           = pADO->FieldByName("OPER_CTT_PC_TEL")->AsString;             //	N	VARCHAR2(13)	Y			운영기관 정보 - 운영담당자 전화번호
                AObj->FOPR->OPER_CTT_PC_EMAIL         = pADO->FieldByName("OPER_CTT_PC_EMAIL")->AsString;           //	N	VARCHAR2(50)	Y			운영기관 정보 - 운영담당자 이메일
                AObj->FOPR->NO_DRV_DAY_OPERTN_AT      = pADO->FieldByName("NO_DRV_DAY_OPERTN_AT")->AsInteger;       //	N	NUMBER(1)	    Y			주차 부제 시행여부 (0 : 미시행, 1 : 2부제, 2 : 5부제, 3 : 10부제, 4 : 승용차요일제, 9 : 기타)
                AObj->FOPR->OPERTN_BS_FREE_TIME       = pADO->FieldByName("OPERTN_BS_FREE_TIME")->AsString;         //	N	VARCHAR2(8)	    Y			기본무료 시간, 주차장 회차 (기본 무료) (00:30:00)
                AObj->FOPR->OPN_CODE                  = pADO->FieldByName("OPN_CODE")->AsInteger;                   //	N	NUMBER(1)	    Y			개방코드, 운영시간 외 무료 개방 (0 : 미개방, 1 : 개방)
                AObj->FOPR->PARKING_CHRGE_EXCCLC_MTHD = pADO->FieldByName("PARKING_CHRGE_EXCCLC_MTHD")->AsInteger;  //	N	NUMBER(1)	    Y			주차요금 정산 방식 (0 : 유인정산, 1 : 무인정산, 2 : 혼합정산, 9 : 기타)
                AObj->FOPR->PARKING_CHRGE_PYMNT_MN    = pADO->FieldByName("PARKING_CHRGE_PYMNT_MN")->AsString;      //	N	VARCHAR2(8)	    Y			주차요금 지불수단 - 아래 유형 조합해서 생성됌 - 예시) 현금/신용카드 혼합결제 시 (11000000), 핀테크 결제 시 (00000100), 1: 현금, 2: 신용카드, 3: 교통카드, 4: 전자지불(하이패스), 5: 휴대폰소액결제, 6: 핀테크(OO페이), 7: MaaS 통합결제, 9: 기타
                AObj->FOPR->PARKING_RESVE_OPERTN_AT   = pADO->FieldByName("PARKING_RESVE_OPERTN_AT")->AsInteger;    //	N	NUMBER(1)	    Y			주차예약 시행여부 (0 : 미시행, 1 : 시행-주차장, 2 : 시행-주차구역, 3 : 시행-주차면)
                AObj->FOPR->PARTCLR_MATTER            = pADO->FieldByName("PARTCLR_MATTER")->AsString;              //	N	VARCHAR2(128)	Y			특이사항
                AObj->FOPR->INFO_CREATE_TIME          = pADO->FieldByName("INFO_CREATE_TIME")->AsString;            //	N	VARCHAR2(14)    Y			주차정보를 입력하여 생성하는 시각, (YYYY-MM-DD hh:mm:ss)
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOpr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOpr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::LoadFromDbOprChrge(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                      \r\n"
           "  FROM TB_PRK_PLCE_OPR_CHRGE A  \r\n"
           " WHERE A.prk_plce_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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                int CHRGE = pADO->FieldByName("CHRGE")->AsInteger;
                TPrkPlceOprChrge *pChrge = AObj->FOPR->FChrges.Find(CHRGE);
                if (pChrge == NULL) {
                    pChrge = new TPrkPlceOprChrge();
                    pChrge->PRK_PLCE_NMBR = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;
                    pChrge->CHRGE = CHRGE;
                    AObj->FOPR->FChrges.Push(CHRGE, pChrge);
                }
                pChrge->PARKING_CHRGE_BS_TIME = pADO->FieldByName("PARKING_CHRGE_BS_TIME")->AsInteger;
                pChrge->PARKING_CHRGE_BS_CHRGE = pADO->FieldByName("PARKING_CHRGE_BS_CHRGE")->AsInteger;
                pChrge->PARKING_CHRGE_ADIT_UNIT_TIME = pADO->FieldByName("PARKING_CHRGE_ADIT_UNIT_TIME")->AsInteger;
                pChrge->PARKING_CHRGE_ADIT_UNIT_CHRGE = pADO->FieldByName("PARKING_CHRGE_ADIT_UNIT_CHRGE")->AsInteger;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOprChrge", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOprChrge", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------


bool TPrkPlceManager::LoadFromDbOprSched(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                      \r\n"
           "  FROM TB_PRK_PLCE_OPR_SCHED A  \r\n"
           " WHERE A.prk_plce_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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                int SCHED = pADO->FieldByName("SCHED")->AsInteger;
                TPrkPlceOprSched *pSched = AObj->FOPR->FScheds.Find(SCHED);
                if (pSched == NULL) {
                    pSched = new TPrkPlceOprSched();
                    pSched->PRK_PLCE_NMBR = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;
                    pSched->SCHED = SCHED;
                    AObj->FOPR->FScheds.Push(SCHED, pSched);
                }
                pSched->OPERTN_START_TIME = pADO->FieldByName("OPERTN_START_TIME")->AsString;
                pSched->OPERTN_END_TIME = pADO->FieldByName("OPERTN_END_TIME")->AsString;
                pSched->PARKING_CHRGE_LEVY_AT = pADO->FieldByName("PARKING_CHRGE_LEVY_AT")->AsInteger;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOprSched", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbOprSched", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::LoadFromDbFlr(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.PRK_PLCE_NMBR, A.FLR_NO,   \r\n"
           "       A.FLR_PRK_CMPRT_CO,          \r\n"
           "       A.FLR_REMNDR_PRK_CMPRT_CO,   \r\n"
           "       A.DATA_COLCT_TIME            \r\n"
           "  FROM TB_PRK_PLCE_FLR A            \r\n"
           " WHERE A.prk_plce_nmbr = :p01       \r\n";

    try
    {
        //AObj->FFlrs.Clear();
        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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                String PRK_PLCE_NMBR            = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;             //	N	NUMBER(10)	    N			주차장 관리 번호
                String FLR_NO                   = pADO->FieldByName("FLR_NO")->AsString;                    //	N	VARCHAR2(10)	N			층 번호
                int    FLR_PRK_CMPRT_CO         = pADO->FieldByName("FLR_PRK_CMPRT_CO")->AsInteger;         //	N	NUMBER(18)	    Y			층별 주차구획 수, 120(면), 시설정보+ 실시간정보
                int    FLR_REMNDR_PRK_CMPRT_CO  = pADO->FieldByName("FLR_REMNDR_PRK_CMPRT_CO")->AsInteger;  //	N	NUMBER(18)	    Y			층별 잔여 주차구획 수, 120(면), 실시간정보
                String DATA_COLCT_TIME          = pADO->FieldByName("DATA_COLCT_TIME")->AsString;           //	N	VARCHAR2(14)	Y			실시간 주차데이터 수집시간 (YYYY-MM-DD hh:mm:ss)

                TPrkPlceFlr *pFlr = AObj->FFlrs.Find(FLR_NO);
                if (pFlr == NULL) {
                    pFlr = new TPrkPlceFlr();
                    pFlr->PRK_PLCE_NMBR = PRK_PLCE_NMBR;
                    pFlr->FLR_NO        = FLR_NO;

                    AObj->FFlrs.Push(FLR_NO, pFlr);
                }
                pFlr->FLR_PRK_CMPRT_CO         = FLR_PRK_CMPRT_CO;
                pFlr->FLR_REMNDR_PRK_CMPRT_CO  = FLR_REMNDR_PRK_CMPRT_CO;
                pFlr->DATA_COLCT_TIME          = DATA_COLCT_TIME;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbFlr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbFlr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------
bool TPrkPlceManager::LoadFromDbFlr(TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.PRK_PLCE_NMBR, A.FLR_NO,   \r\n"
           "       A.FLR_PRK_CMPRT_CO,          \r\n"
           "       A.FLR_REMNDR_PRK_CMPRT_CO,   \r\n"
           "       A.DATA_COLCT_TIME            \r\n"
           "  FROM TB_PRK_PLCE_FLR A            \r\n";

    try
    {
        //AObj->FFlrs.Clear();
        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())
            {
                String PRK_PLCE_NMBR            = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;             //	N	NUMBER(10)	    N			주차장 관리 번호
                String FLR_NO                   = pADO->FieldByName("FLR_NO")->AsString;                    //	N	VARCHAR2(10)	N			층 번호
                int    FLR_PRK_CMPRT_CO         = pADO->FieldByName("FLR_PRK_CMPRT_CO")->AsInteger;         //	N	NUMBER(18)	    Y			층별 주차구획 수, 120(면), 시설정보+ 실시간정보
                int    FLR_REMNDR_PRK_CMPRT_CO  = pADO->FieldByName("FLR_REMNDR_PRK_CMPRT_CO")->AsInteger;  //	N	NUMBER(18)	    Y			층별 잔여 주차구획 수, 120(면), 실시간정보
                String DATA_COLCT_TIME          = pADO->FieldByName("DATA_COLCT_TIME")->AsString;           //	N	VARCHAR2(14)	Y			실시간 주차데이터 수집시간 (YYYY-MM-DD hh:mm:ss)

                TPrkPlce *AObj = FLists.Find(PRK_PLCE_NMBR);
                if (AObj == NULL) {
                    continue;
                }

                TPrkPlceFlr *pFlr = AObj->FFlrs.Find(FLR_NO);
                if (pFlr == NULL) {
                    pFlr = new TPrkPlceFlr();
                    pFlr->PRK_PLCE_NMBR = PRK_PLCE_NMBR;
                    pFlr->FLR_NO        = FLR_NO;

                    AObj->FFlrs.Push(FLR_NO, pFlr);
                }
                pFlr->FLR_PRK_CMPRT_CO         = FLR_PRK_CMPRT_CO;
                pFlr->FLR_REMNDR_PRK_CMPRT_CO  = FLR_REMNDR_PRK_CMPRT_CO;
                pFlr->DATA_COLCT_TIME          = DATA_COLCT_TIME;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbFlr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbFlr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::LoadFromDbFlrDev(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                                                  \r\n"
           "  FROM TB_PRK_PLCE_FLR_DEV A                                \r\n"
           " WHERE A.prk_plce_nmbr = :p01                               \r\n"
           " ORDER BY A.PRK_PLCE_NMBR, A.FLR_NO, TO_NUMBER(A.DEVICE_ID) \r\n";

    try
    {
        //AObj->FFlrs.Clear();
        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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                String PRK_PLCE_NMBR    = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;     //	N	NUMBER(10)	    N			주차장 관리 번호
                String FLR_NO           = pADO->FieldByName("FLR_NO")->AsString;            //	N	VARCHAR2(10)	N			층 번호
                int    DEVICE_ID        = pADO->FieldByName("DEVICE_ID")->AsInteger;        //	N	VARCHAR2(5)	    N			주차정보수집장치 ID
                int    X_POS            = pADO->FieldByName("X_POS")->AsInteger;            //	N	NUMBER(4)	    Y	0		이미지 좌표 X
                int    Y_POS            = pADO->FieldByName("Y_POS")->AsInteger;            //	N	NUMBER(4)	    Y	0		이미지 좌표 Y

                TPrkPlceFlr *pFlr = AObj->FFlrs.Find(FLR_NO);
                if (pFlr != NULL) {
                    // 무조건 주차장 층 정보가 존재해야 한다.
                    TPrkPlceFlrDev *pFlrDev = pFlr->FFlrDevs.Find(DEVICE_ID);
                    if (pFlrDev == NULL) {
                        pFlrDev = new TPrkPlceFlrDev();
                        pFlrDev->PRK_PLCE_NMBR = PRK_PLCE_NMBR;
                        pFlrDev->FLR_NO        = FLR_NO;
                        pFlrDev->DEVICE_ID     = DEVICE_ID;

                        pFlr->FFlrDevs.Push(DEVICE_ID, pFlrDev);
                    }
                    pFlrDev->X_POS = X_POS;
                    pFlrDev->Y_POS = Y_POS;
                }

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

bool TPrkPlceManager::LoadFromDbAr(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                    \r\n"
           "  FROM TB_PRK_PLCE_AR A       \r\n"
           " WHERE A.prk_plce_nmbr = :p01 \r\n";

    try
    {
        //FOR_STL(TPrkPlceFlr *, pFlr, AObj->FFlrs)
        //{
        //    pFlr->FArs.Clear();
        //}
        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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                String PRK_PLCE_NMBR          = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;           //	N	NUMBER(10)	    N			주차장 관리 번호
                String FLR_NO                 = pADO->FieldByName("FLR_NO")->AsString;                  //	N	VARCHAR2(10)	N			층 번호
                String AR_NO                  = pADO->FieldByName("AR_NO")->AsString;                   //	N	VARCHAR2(10)	N			구역 일련번호
                int    AR_PRK_CMPRT_CO        = pADO->FieldByName("AR_PRK_CMPRT_CO")->AsInteger;        //	N	NUMBER(18)	    Y			구역별 주차 구획 수, 120(면), 시설정보+실시간정보
                int    AR_REMNDR_PRK_CMPRT_CO = pADO->FieldByName("AR_REMNDR_PRK_CMPRT_CO")->AsInteger; //	N	NUMBER(18)	    Y			구역별 잔여 주차 구획 수, 120(면), 실시간정보

                TPrkPlceFlr *pFlr = AObj->FFlrs.Find(FLR_NO);
                if (pFlr) {
                    TPrkPlceAr *pAr = pFlr->FArs.Find(AR_NO);
                    if (pAr == NULL) {
                        pAr = new TPrkPlceAr();
                        pAr->PRK_PLCE_NMBR = PRK_PLCE_NMBR;
                        pAr->FLR_NO        = FLR_NO;
                        pAr->AR_NO         = AR_NO;

                        pFlr->FArs.Push(AR_NO, pAr);
                    }
                    pAr->AR_PRK_CMPRT_CO        = AR_PRK_CMPRT_CO;
                    pAr->AR_REMNDR_PRK_CMPRT_CO = AR_REMNDR_PRK_CMPRT_CO;
                }
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbAr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbAr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::LoadFromDbPrv(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                      \r\n"
           "  FROM TB_PRK_PLCE_PRV A        \r\n"
           " WHERE A.prk_plce_nmbr = :p01   \r\n";

    try
    {
        //AObj->FPrvs.Clear();
        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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                String PRK_PLCE_NMBR                = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;                 //	N	NUMBER(10)	    N			주차장 관리 번호
                int    VHCTY_AR_SE                  = pADO->FieldByName("VHCTY_AR_SE")->AsInteger;                  //	N	NUMBER(1)	    N			전용주차구역 구분 (0: 경차 전용, 1: 친환경차 (전기차), 2: 화물차 전용, 3: 긴급차량 전용, 4: 장애인 전용, 5: 어르신 전용, 6: 여성 전용, 9: 기타)
                int    VHCTY_AR_PRK_CMPRT_CO        = pADO->FieldByName("VHCTY_AR_PRK_CMPRT_CO")->AsInteger;        //	N	NUMBER(18)	    Y			전용주차구역별 주차 구획 수, 시설정보+실시간정보
                int    VHCTY_AR_REMNDR_PRK_CMPRT_CO = pADO->FieldByName("VHCTY_AR_REMNDR_PRK_CMPRT_CO")->AsInteger; //	N	NUMBER(18)	    Y			전용주차구역별 잔여 주차 구획 수, 실시간정보


                TPrkPlcePrv *pPrv = AObj->FPrvs.Find(VHCTY_AR_SE);
                if (pPrv == NULL) {
                    pPrv = new TPrkPlcePrv();
                    pPrv->PRK_PLCE_NMBR = PRK_PLCE_NMBR;
                    pPrv->VHCTY_AR_SE   = VHCTY_AR_SE;

                    AObj->FPrvs.Push(VHCTY_AR_SE, pPrv);
                }
                pPrv->VHCTY_AR_PRK_CMPRT_CO        = VHCTY_AR_PRK_CMPRT_CO;
                pPrv->VHCTY_AR_REMNDR_PRK_CMPRT_CO = VHCTY_AR_REMNDR_PRK_CMPRT_CO;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbPrv", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbPrv", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::LoadFromDbDev(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*                                          \r\n"
           "  FROM TB_PRK_PLCE_DEV A                            \r\n"
           " WHERE A.prk_plce_nmbr = :p01                       \r\n"
           " ORDER BY A.PRK_PLCE_NMBR, TO_NUMBER(A.DEVICE_ID)   \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->CTLR_NMBR;
            pADO->Prepared = true;
            pADO->Open();

            for( ; !pADO->Eof; pADO->Next())
            {
                String PRK_PLCE_NMBR        = pADO->FieldByName("PRK_PLCE_NMBR")->AsString;         //	N	NUMBER(10)	    N			주차장 관리 번호
                int    DEVICE_ID            = pADO->FieldByName("DEVICE_ID")->AsInteger;             //	N	VARCHAR2(5)	    N			주차정보수집장치 ID
                int    DEVICE_TYPE          = pADO->FieldByName("DEVICE_TYPE")->AsInteger;          //	N	NUMBER(1)	    Y			주차정보수집장치 종류 (0 : 영상식, 1 : 지자기, 2 : 레이더, 3 : 루프, 4 : 초음파, 9 : 기타)
                String PRK_UNIT_ID          = pADO->FieldByName("PRK_UNIT_ID")->AsString;           //	N	VARCHAR2(10)	Y			주차면 ID, 층번호+구역일련번호 예시) 1FA01 1층 A구역 01번 주차면
                int    TYPED_PARKING_LOTS   = pADO->FieldByName("TYPED_PARKING_LOTS")->AsInteger;   //	N	NUMBER(1)	    Y			주차면 유형 (0 : 일반, 1 : 경차 전용, 2 : 대형(화물)전용, 3 : 긴급차량전용, 4 : 장애인 전용, 5 : 여성 전용, 9 : 기타)
                int    OCCUPATION           = pADO->FieldByName("OCCUPATION")->AsInteger;           //	N	NUMBER(1)	    Y			주차면 점유여부 (0 : 주차가능 (주차면 비점유), 1 : 주차불가 (주차면 점유))
                int    CONNECTED            = pADO->FieldByName("CONNECTED")->AsInteger;            //	N	NUMBER(1)	    Y			통신상태 (0 : 불량, 1 : 정상)

                TPrkPlceDev *pDev = AObj->FDevs.Find(DEVICE_ID);
                if (pDev == NULL) {
                    pDev = new TPrkPlceDev();
                    pDev->PRK_PLCE_NMBR = PRK_PLCE_NMBR;
                    pDev->DEVICE_ID     = DEVICE_ID;
                    pDev->DEVICE_TYPE   = DEVICE_TYPE;
                    pDev->PRK_UNIT_ID   = PRK_UNIT_ID;

                    AObj->FDevs.Push(DEVICE_ID, pDev);
                }
                pDev->TYPED_PARKING_LOTS = TYPED_PARKING_LOTS;
                pDev->OCCUPATION         = OCCUPATION;
                pDev->CONNECTED          = CONNECTED;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbDev", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::LoadFromDbDev", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------


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

    sQry = "SELECT NVL(MAX(prk_plce_nmbr), 0) + 1 AS NEWID FROM TB_PRK_PLCE";

    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("TPrkPlceManager::GetNextPrkNmbr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORLOG("TPrkPlceManager::GetNextPrkNmbr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return false;
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::DeletePrkPlce(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "UPDATE TB_PRK_PLCE            \r\n"
           "   SET DEL_YN = 'Y'           \r\n"
           " WHERE prk_plce_nmbr = :p01   \r\n";

    try
    {
        FLists.Lock();
        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->CTLR_NMBR;
			pADO->ExecSQL();

        sQry = "DELETE TB_FCLT_INFR       \r\n"
               " WHERE FCLT_ID = :p01     \r\n";
               "   AND FCLT_TYPE = 'PARK' \r\n";

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

            return true;
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TPrkPlceManager::DeletePrkPlce", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TPrkPlceManager::DeletePrkPlce", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

bool TPrkPlceManager::InsertPrkPlce(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    return MergePrkPlce(AObj, ADbConn);
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::UpdatePrkPlce(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    return MergePrkPlce(AObj, ADbConn);
}
//---------------------------------------------------------------------------

bool TPrkPlceManager::MergePrkPlce(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "MERGE INTO TB_PRK_PLCE L                                                      \r\n"
           "USING (SELECT                                                                 \r\n"
           "              :p01 AS PRK_PLCE_NMBR,                                          \r\n"
           "              :p02 AS PRK_PLCE_MANAGE_NO,                                     \r\n"
           "              :p03 AS PRK_PLCE_STTUS_VER,                                     \r\n"
           "              :p04 AS PRK_PLCE_NM,                                            \r\n"
           "              :p44 AS VMS_DSPL_NM,                                            \r\n"
           "              :p05 AS PRK_PLCE_ADRES,                                         \r\n"
           "              :p06 AS PRK_PLCE_INSTL_DE,                                      \r\n"
           "              :p07 AS PRK_PLCE_ABL_DE,                                        \r\n"
           "              :p08 AS PRK_PLCE_ENTRC_NM,                                      \r\n"
           "              :p09 AS PRK_PLCE_ENTRC_LA,                                      \r\n"
           "              :p10 AS PRK_PLCE_ENTRC_LO,                                      \r\n"
           "              :p11 AS PRK_PLCE_ENTRC_EXTTY,                                   \r\n"
           "              :p12 AS PARKING_TY,                                             \r\n"
           "              :p13 AS PARKING_US,                                             \r\n"
           "              :p14 AS AR_LEVEL_SE,                                            \r\n"
           //"              :p15 AS PRK_PLCE_IMAGE_DATA,                                    \r\n"
           "              :p16 AS PRK_PLCE_IMAGE_TYPE,                                    \r\n"
           "              :p17 AS PRK_PLCE_IMAGE_DC,                                      \r\n"
           "              :p18 AS SYS_NE,                                                 \r\n"
           "              :p19 AS PARKING_CNTRL_SYS_INSTL_DE,                             \r\n"
           "              :p20 AS RELATION_LAW_AND_ORDINANCES,                            \r\n"
           "              :p21 AS PRK_AVAIL_CARTYPE,                                      \r\n"
           "              :p22 AS PRK_CMPRT_CO,                                           \r\n"
           "              :p23 AS COLCT_DEVICE_INSTL_AT,                                  \r\n"
           "              :p24 AS MASTER_CONTROLLER,                                      \r\n"
           "              :p25 AS SLAVE_CONTROLLER,                                       \r\n"
           "              :p26 AS COLCT_DEVICE_QTY,                                       \r\n"
           "              :p27 AS COLCT_DEVICE_KND,                                       \r\n"
           //"              :p28 AS TYPE_IMGAGE,                                            \r\n"
           //"              :p29 AS TYPE_GEOMAGNETIC,                                       \r\n"
           //"              :p30 AS TYPE_RADAR,                                             \r\n"
           //"              :p31 AS TYPE_LOOP,                                              \r\n"
           //"              :p32 AS TYPE_ULTRASONIC,                                        \r\n"
           //"              :p33 AS TYPE_ETC,                                               \r\n"
           "              :p34 AS COLCT_DEVICE_INSTL_DE,                                  \r\n"
           "              :p35 AS CRM_PRV_CCTV_INSTL_AT,                                  \r\n"
           "              :p36 AS CRM_PRV_CCTV_INSTL_CO,                                  \r\n"
           "              :p37 AS PIS_TYPE,                                               \r\n"
           "              :p38 AS INFO_CREATE_TIME,                                       \r\n"
           "              :p39 AS OPR_INFO,                                               \r\n"
           "              :p40 AS MIN30_FEE,                                              \r\n"
           "              :p41 AS MIN10_FEE,                                              \r\n"
           "              :p42 AS DAY_FEE,                                                \r\n"
           "              :p43 AS MON_FEE                                                 \r\n"
           "         FROM DUAL) M                                                         \r\n"
           "        ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR)                                \r\n"
           "WHEN MATCHED THEN                                                             \r\n"
           "   UPDATE SET                                                                 \r\n"
           "              L.PRK_PLCE_MANAGE_NO          = M.PRK_PLCE_MANAGE_NO,           \r\n"
           "              L.PRK_PLCE_STTUS_VER          = M.PRK_PLCE_STTUS_VER,           \r\n"
           "              L.PRK_PLCE_NM                 = M.PRK_PLCE_NM,                  \r\n"
           "              L.VMS_DSPL_NM                 = M.VMS_DSPL_NM,                  \r\n"
           "              L.PRK_PLCE_ADRES              = M.PRK_PLCE_ADRES,               \r\n"
           "              L.PRK_PLCE_INSTL_DE           = M.PRK_PLCE_INSTL_DE,            \r\n"
           "              L.PRK_PLCE_ABL_DE             = M.PRK_PLCE_ABL_DE,              \r\n"
           "              L.PRK_PLCE_ENTRC_NM           = M.PRK_PLCE_ENTRC_NM,            \r\n"
           "              L.PRK_PLCE_ENTRC_LA           = M.PRK_PLCE_ENTRC_LA,            \r\n"
           "              L.PRK_PLCE_ENTRC_LO           = M.PRK_PLCE_ENTRC_LO,            \r\n"
           "              L.PRK_PLCE_ENTRC_EXTTY        = M.PRK_PLCE_ENTRC_EXTTY,         \r\n"
           "              L.PARKING_TY                  = M.PARKING_TY,                   \r\n"
           "              L.PARKING_US                  = M.PARKING_US,                   \r\n"
           "              L.AR_LEVEL_SE                 = M.AR_LEVEL_SE,                  \r\n"
           //"              L.PRK_PLCE_IMAGE_DATA         = M.PRK_PLCE_IMAGE_DATA,          \r\n"
           "              L.PRK_PLCE_IMAGE_TYPE         = M.PRK_PLCE_IMAGE_TYPE,          \r\n"
           "              L.PRK_PLCE_IMAGE_DC           = M.PRK_PLCE_IMAGE_DC,            \r\n"
           "              L.SYS_NE                      = M.SYS_NE,                       \r\n"
           "              L.PARKING_CNTRL_SYS_INSTL_DE  = M.PARKING_CNTRL_SYS_INSTL_DE,   \r\n"
           "              L.RELATION_LAW_AND_ORDINANCES = M.RELATION_LAW_AND_ORDINANCES,  \r\n"
           "              L.PRK_AVAIL_CARTYPE           = M.PRK_AVAIL_CARTYPE,            \r\n"
           "              L.PRK_CMPRT_CO                = M.PRK_CMPRT_CO,                 \r\n"
           "              L.COLCT_DEVICE_INSTL_AT       = M.COLCT_DEVICE_INSTL_AT,        \r\n"
           "              L.MASTER_CONTROLLER           = M.MASTER_CONTROLLER,            \r\n"
           "              L.SLAVE_CONTROLLER            = M.SLAVE_CONTROLLER,             \r\n"
           "              L.COLCT_DEVICE_QTY            = M.COLCT_DEVICE_QTY,             \r\n"
           "              L.COLCT_DEVICE_KND            = M.COLCT_DEVICE_KND,             \r\n"
           //"              L.TYPE_IMGAGE                 = M.TYPE_IMGAGE,                  \r\n"
           //"              L.TYPE_GEOMAGNETIC            = M.TYPE_GEOMAGNETIC,             \r\n"
           //"              L.TYPE_RADAR                  = M.TYPE_RADAR,                   \r\n"
           //"              L.TYPE_LOOP                   = M.TYPE_LOOP,                    \r\n"
           //"              L.TYPE_ULTRASONIC             = M.TYPE_ULTRASONIC,              \r\n"
           //"              L.TYPE_ETC                    = M.TYPE_ETC,                     \r\n"
           "              L.COLCT_DEVICE_INSTL_DE       = M.COLCT_DEVICE_INSTL_DE,        \r\n"
           "              L.CRM_PRV_CCTV_INSTL_AT       = M.CRM_PRV_CCTV_INSTL_AT,        \r\n"
           "              L.CRM_PRV_CCTV_INSTL_CO       = M.CRM_PRV_CCTV_INSTL_CO,        \r\n"
           "              L.PIS_TYPE                    = M.PIS_TYPE,                     \r\n"
           "              L.INFO_CREATE_TIME            = M.INFO_CREATE_TIME,             \r\n"
           "              L.OPR_INFO                    = M.OPR_INFO,                     \r\n"
           "              L.MIN30_FEE                   = M.MIN30_FEE,                    \r\n"
           "              L.MIN10_FEE                   = M.MIN10_FEE,                    \r\n"
           "              L.DAY_FEE                     = M.DAY_FEE,                      \r\n"
           "              L.MON_FEE                     = M.MON_FEE                       \r\n"
           "WHEN NOT MATCHED THEN                                                         \r\n"
           "   INSERT (                                                                   \r\n"
           "           PRK_PLCE_NMBR,                                                     \r\n"
           "           PRK_PLCE_MANAGE_NO,                                                \r\n"
           "           PRK_PLCE_STTUS_VER,                                                \r\n"
           "           PRK_PLCE_NM,                                                       \r\n"
           "           VMS_DSPL_NM,                                                       \r\n"
           "           PRK_PLCE_ADRES,                                                    \r\n"
           "           PRK_PLCE_INSTL_DE,                                                 \r\n"
           "           PRK_PLCE_ABL_DE,                                                   \r\n"
           "           PRK_PLCE_ENTRC_NM,                                                 \r\n"
           "           PRK_PLCE_ENTRC_LA,                                                 \r\n"
           "           PRK_PLCE_ENTRC_LO,                                                 \r\n"
           "           PRK_PLCE_ENTRC_EXTTY,                                              \r\n"
           "           PARKING_TY,                                                        \r\n"
           "           PARKING_US,                                                        \r\n"
           "           AR_LEVEL_SE,                                                       \r\n"
           //"           PRK_PLCE_IMAGE_DATA,                                               \r\n"
           "           PRK_PLCE_IMAGE_TYPE,                                               \r\n"
           "           PRK_PLCE_IMAGE_DC,                                                 \r\n"
           "           SYS_NE,                                                            \r\n"
           "           PARKING_CNTRL_SYS_INSTL_DE,                                        \r\n"
           "           RELATION_LAW_AND_ORDINANCES,                                       \r\n"
           "           PRK_AVAIL_CARTYPE,                                                 \r\n"
           "           PRK_CMPRT_CO,                                                      \r\n"
           "           COLCT_DEVICE_INSTL_AT,                                             \r\n"
           "           MASTER_CONTROLLER,                                                 \r\n"
           "           SLAVE_CONTROLLER,                                                  \r\n"
           "           COLCT_DEVICE_QTY,                                                  \r\n"
           "           COLCT_DEVICE_KND,                                                  \r\n"
           //"           TYPE_IMGAGE,                                                       \r\n"
           //"           TYPE_GEOMAGNETIC,                                                  \r\n"
           //"           TYPE_RADAR,                                                        \r\n"
           //"           TYPE_LOOP,                                                         \r\n"
           //"           TYPE_ULTRASONIC,                                                   \r\n"
           //"           TYPE_ETC,                                                          \r\n"
           "           COLCT_DEVICE_INSTL_DE,                                             \r\n"
           "           CRM_PRV_CCTV_INSTL_AT,                                             \r\n"
           "           CRM_PRV_CCTV_INSTL_CO,                                             \r\n"
           "           PIS_TYPE,                                                          \r\n"
           "           INFO_CREATE_TIME,                                                  \r\n"
           "           OPR_INFO,                                                          \r\n"
           "           MIN30_FEE,                                                         \r\n"
           "           MIN10_FEE,                                                         \r\n"
           "           DAY_FEE,                                                           \r\n"
           "           MON_FEE )                                                          \r\n"
           "   VALUES (                                                                   \r\n"
           "           M.PRK_PLCE_NMBR,                                                   \r\n"
           "           M.PRK_PLCE_MANAGE_NO,                                              \r\n"
           "           M.PRK_PLCE_STTUS_VER,                                              \r\n"
           "           M.PRK_PLCE_NM,                                                     \r\n"
           "           M.VMS_DSPL_NM,                                                     \r\n"
           "           M.PRK_PLCE_ADRES,                                                  \r\n"
           "           M.PRK_PLCE_INSTL_DE,                                               \r\n"
           "           M.PRK_PLCE_ABL_DE,                                                 \r\n"
           "           M.PRK_PLCE_ENTRC_NM,                                               \r\n"
           "           M.PRK_PLCE_ENTRC_LA,                                               \r\n"
           "           M.PRK_PLCE_ENTRC_LO,                                               \r\n"
           "           M.PRK_PLCE_ENTRC_EXTTY,                                            \r\n"
           "           M.PARKING_TY,                                                      \r\n"
           "           M.PARKING_US,                                                      \r\n"
           "           M.AR_LEVEL_SE,                                                     \r\n"
           //"           M.PRK_PLCE_IMAGE_DATA,                                             \r\n"
           "           M.PRK_PLCE_IMAGE_TYPE,                                             \r\n"
           "           M.PRK_PLCE_IMAGE_DC,                                               \r\n"
           "           M.SYS_NE,                                                          \r\n"
           "           M.PARKING_CNTRL_SYS_INSTL_DE,                                      \r\n"
           "           M.RELATION_LAW_AND_ORDINANCES,                                     \r\n"
           "           M.PRK_AVAIL_CARTYPE,                                               \r\n"
           "           M.PRK_CMPRT_CO,                                                    \r\n"
           "           M.COLCT_DEVICE_INSTL_AT,                                           \r\n"
           "           M.MASTER_CONTROLLER,                                               \r\n"
           "           M.SLAVE_CONTROLLER,                                                \r\n"
           "           M.COLCT_DEVICE_QTY,                                                \r\n"
           "           M.COLCT_DEVICE_KND,                                                \r\n"
           //"           M.TYPE_IMGAGE,                                                     \r\n"
           //"           M.TYPE_GEOMAGNETIC,                                                \r\n"
           //"           M.TYPE_RADAR,                                                      \r\n"
           //"           M.TYPE_LOOP,                                                       \r\n"
           //"           M.TYPE_ULTRASONIC,                                                 \r\n"
           //"           M.TYPE_ETC,                                                        \r\n"
           "           M.COLCT_DEVICE_INSTL_DE,                                           \r\n"
           "           M.CRM_PRV_CCTV_INSTL_AT,                                           \r\n"
           "           M.CRM_PRV_CCTV_INSTL_CO,                                           \r\n"
           "           M.PIS_TYPE,                                                        \r\n"
           "           M.INFO_CREATE_TIME,                                                \r\n"
           "           M.OPR_INFO,                                                        \r\n"
           "           M.MIN30_FEE,                                                       \r\n"
           "           M.MIN10_FEE,                                                       \r\n"
           "           M.DAY_FEE,                                                         \r\n"
           "           M.MON_FEE )                                                        \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->CTLR_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->CTLR_ID;
            pADO->Parameters->ParamByName("p03")->Value = AObj->PRK_PLCE_STTUS_VER;
            pADO->Parameters->ParamByName("p04")->Value = AObj->NAME;
            pADO->Parameters->ParamByName("p44")->Value = AObj->VMS_DSPL_NM;
            pADO->Parameters->ParamByName("p05")->Value = AObj->ISTL_LCTN_ADDR;
            pADO->Parameters->ParamByName("p06")->Value = AObj->PRK_PLCE_INSTL_DE;
            pADO->Parameters->ParamByName("p07")->Value = AObj->PRK_PLCE_ABL_DE;
            pADO->Parameters->ParamByName("p08")->Value = AObj->PRK_PLCE_ENTRC_NM;
            pADO->Parameters->ParamByName("p09")->Value = AObj->Y_CRDN;
            pADO->Parameters->ParamByName("p10")->Value = AObj->X_CRDN;
            pADO->Parameters->ParamByName("p11")->Value = AObj->PRK_PLCE_ENTRC_EXTTY;
            pADO->Parameters->ParamByName("p12")->Value = AObj->PARKING_TY;
            pADO->Parameters->ParamByName("p13")->Value = AObj->PARKING_US;
            pADO->Parameters->ParamByName("p14")->Value = AObj->AR_LEVEL_SE;
            //pADO->Parameters->ParamByName("p15")->Value = AObj->PRK_PLCE_IMAGE_DATA;
            pADO->Parameters->ParamByName("p16")->Value = AObj->PRK_PLCE_IMAGE_TYPE;
            pADO->Parameters->ParamByName("p17")->Value = AObj->PRK_PLCE_IMAGE_DC;
            pADO->Parameters->ParamByName("p18")->Value = AObj->SYS_NE;
            pADO->Parameters->ParamByName("p19")->Value = AObj->PARKING_CNTRL_SYS_INSTL_DE;
            pADO->Parameters->ParamByName("p20")->Value = AObj->RELATION_LAW_AND_ORDINANCES;
            pADO->Parameters->ParamByName("p21")->Value = AObj->PRK_AVAIL_CARTYPE;
            pADO->Parameters->ParamByName("p22")->Value = AObj->PRK_CMPRT_CO;
            pADO->Parameters->ParamByName("p23")->Value = AObj->COLCT_DEVICE_INSTL_AT;
            pADO->Parameters->ParamByName("p24")->Value = AObj->MASTER_CONTROLLER;
            pADO->Parameters->ParamByName("p25")->Value = AObj->SLAVE_CONTROLLER;
            pADO->Parameters->ParamByName("p26")->Value = AObj->COLCT_DEVICE_QTY;
            pADO->Parameters->ParamByName("p27")->Value = AObj->COLCT_DEVICE_KND;
            //pADO->Parameters->ParamByName("p28")->Value = AObj->TYPE_IMGAGE;
            //pADO->Parameters->ParamByName("p29")->Value = AObj->TYPE_GEOMAGNETIC;
            //pADO->Parameters->ParamByName("p30")->Value = AObj->TYPE_RADAR;
            //pADO->Parameters->ParamByName("p31")->Value = AObj->TYPE_LOOP;
            //pADO->Parameters->ParamByName("p32")->Value = AObj->TYPE_ULTRASONIC;
            //pADO->Parameters->ParamByName("p33")->Value = AObj->TYPE_ETC;
            pADO->Parameters->ParamByName("p34")->Value = AObj->COLCT_DEVICE_INSTL_DE;
            pADO->Parameters->ParamByName("p35")->Value = AObj->CRM_PRV_CCTV_INSTL_AT;
            pADO->Parameters->ParamByName("p36")->Value = AObj->CRM_PRV_CCTV_INSTL_CO;
            pADO->Parameters->ParamByName("p37")->Value = AObj->TYPE_CD;
            pADO->Parameters->ParamByName("p38")->Value = AObj->INFO_CREATE_TIME;
            pADO->Parameters->ParamByName("p39")->Value = AObj->OPR_INFO;
            pADO->Parameters->ParamByName("p40")->Value = AObj->MIN30_FEE;
            pADO->Parameters->ParamByName("p41")->Value = AObj->MIN10_FEE;
            pADO->Parameters->ParamByName("p42")->Value = AObj->DAY_FEE;
            pADO->Parameters->ParamByName("p43")->Value = AObj->MON_FEE;

			pADO->ExecSQL();

            //MergePrkPlceOpr(AObj->FOPR, ADbConn);
            MergeFcltInfo(AObj, ADbConn);
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::MergePrkPlce", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::MergePrkPlce", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TPrkPlceManager::MergePrkPlceOpr(TPrkPlceOpr *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "MERGE INTO TB_PRK_PLCE_OPR L                                              \r\n"
           "USING (SELECT                                                             \r\n"
           "              :p01 AS PRK_PLCE_NMBR,                                      \r\n"
           "              :p02 AS PRK_PLCE_OPR_VER,                                   \r\n"
           "              :p03 AS CMPT_INST_NM,                                       \r\n"
           "              :p04 AS OPER_DEPT_NM,                                       \r\n"
           "              :p05 AS OPER_PERSON_NM,                                     \r\n"
           "              :p06 AS OPER_CTT_PC_TEL,                                    \r\n"
           "              :p07 AS OPER_CTT_PC_EMAIL,                                  \r\n"
           "              :p08 AS NO_DRV_DAY_OPERTN_AT,                               \r\n"
           "              :p09 AS OPERTN_BS_FREE_TIME,                                \r\n"
           "              :p10 AS OPN_CODE,                                           \r\n"
           "              :p11 AS PARKING_CHRGE_EXCCLC_MTHD,                          \r\n"
           "              :p12 AS PARKING_CHRGE_PYMNT_MN,                             \r\n"
           "              :p13 AS PARKING_RESVE_OPERTN_AT,                            \r\n"
           "              :p14 AS PARTCLR_MATTER,                                     \r\n"
           "              :p15 AS INFO_CREATE_TIME                                    \r\n"
           "         FROM DUAL) M                                                     \r\n"
           "        ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR)                            \r\n"
           "WHEN MATCHED THEN                                                         \r\n"
           "   UPDATE SET                                                             \r\n"
           "              L.PRK_PLCE_OPR_VER          = M.PRK_PLCE_OPR_VER,           \r\n"
           "              L.CMPT_INST_NM              = M.CMPT_INST_NM,               \r\n"
           "              L.OPER_DEPT_NM              = M.OPER_DEPT_NM,               \r\n"
           "              L.OPER_PERSON_NM            = M.OPER_PERSON_NM,             \r\n"
           "              L.OPER_CTT_PC_TEL           = M.OPER_CTT_PC_TEL,            \r\n"
           "              L.OPER_CTT_PC_EMAIL         = M.OPER_CTT_PC_EMAIL,          \r\n"
           "              L.NO_DRV_DAY_OPERTN_AT      = M.NO_DRV_DAY_OPERTN_AT,       \r\n"
           "              L.OPERTN_BS_FREE_TIME       = M.OPERTN_BS_FREE_TIME,        \r\n"
           "              L.OPN_CODE                  = M.OPN_CODE,                   \r\n"
           "              L.PARKING_CHRGE_EXCCLC_MTHD = M.PARKING_CHRGE_EXCCLC_MTHD,  \r\n"
           "              L.PARKING_CHRGE_PYMNT_MN    = M.PARKING_CHRGE_PYMNT_MN,     \r\n"
           "              L.PARKING_RESVE_OPERTN_AT   = M.PARKING_RESVE_OPERTN_AT,    \r\n"
           "              L.PARTCLR_MATTER            = M.PARTCLR_MATTER,             \r\n"
           "              L.INFO_CREATE_TIME          = M.INFO_CREATE_TIME            \r\n"
           "WHEN NOT MATCHED THEN                                                     \r\n"
           "   INSERT (                                                               \r\n"
           "           PRK_PLCE_NMBR,                                                 \r\n"
           "           PRK_PLCE_OPR_VER,                                              \r\n"
           "           CMPT_INST_NM,                                                  \r\n"
           "           OPER_DEPT_NM,                                                  \r\n"
           "           OPER_PERSON_NM,                                                \r\n"
           "           OPER_CTT_PC_TEL,                                               \r\n"
           "           OPER_CTT_PC_EMAIL,                                             \r\n"
           "           NO_DRV_DAY_OPERTN_AT,                                          \r\n"
           "           OPERTN_BS_FREE_TIME,                                           \r\n"
           "           OPN_CODE,                                                      \r\n"
           "           PARKING_CHRGE_EXCCLC_MTHD,                                     \r\n"
           "           PARKING_CHRGE_PYMNT_MN,                                        \r\n"
           "           PARKING_RESVE_OPERTN_AT,                                       \r\n"
           "           PARTCLR_MATTER,                                                \r\n"
           "           INFO_CREATE_TIME )                                             \r\n"
           "   VALUES (                                                               \r\n"
           "           M.PRK_PLCE_NMBR,                                               \r\n"
           "           M.PRK_PLCE_OPR_VER,                                            \r\n"
           "           M.CMPT_INST_NM,                                                \r\n"
           "           M.OPER_DEPT_NM,                                                \r\n"
           "           M.OPER_PERSON_NM,                                              \r\n"
           "           M.OPER_CTT_PC_TEL,                                             \r\n"
           "           M.OPER_CTT_PC_EMAIL,                                           \r\n"
           "           M.NO_DRV_DAY_OPERTN_AT,                                        \r\n"
           "           M.OPERTN_BS_FREE_TIME,                                         \r\n"
           "           M.OPN_CODE,                                                    \r\n"
           "           M.PARKING_CHRGE_EXCCLC_MTHD,                                   \r\n"
           "           M.PARKING_CHRGE_PYMNT_MN,                                      \r\n"
           "           M.PARKING_RESVE_OPERTN_AT,                                     \r\n"
           "           M.PARTCLR_MATTER,                                              \r\n"
           "           M.INFO_CREATE_TIME )                                           \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->PRK_PLCE_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->PRK_PLCE_OPR_VER;
            pADO->Parameters->ParamByName("p03")->Value = AObj->CMPT_INST_NM;
            pADO->Parameters->ParamByName("p04")->Value = AObj->OPER_DEPT_NM;
            pADO->Parameters->ParamByName("p05")->Value = AObj->OPER_PERSON_NM;
            pADO->Parameters->ParamByName("p06")->Value = AObj->OPER_CTT_PC_TEL;
            pADO->Parameters->ParamByName("p07")->Value = AObj->OPER_CTT_PC_EMAIL;
            pADO->Parameters->ParamByName("p08")->Value = AObj->NO_DRV_DAY_OPERTN_AT;
            pADO->Parameters->ParamByName("p09")->Value = AObj->OPERTN_BS_FREE_TIME;
            pADO->Parameters->ParamByName("p10")->Value = AObj->OPN_CODE;
            pADO->Parameters->ParamByName("p11")->Value = AObj->PARKING_CHRGE_EXCCLC_MTHD;
            pADO->Parameters->ParamByName("p12")->Value = AObj->PARKING_CHRGE_PYMNT_MN;
            pADO->Parameters->ParamByName("p13")->Value = AObj->PARKING_RESVE_OPERTN_AT;
            pADO->Parameters->ParamByName("p14")->Value = AObj->PARTCLR_MATTER;
            pADO->Parameters->ParamByName("p15")->Value = AObj->INFO_CREATE_TIME;

			pADO->ExecSQL();
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TPrkPlceManager::MergePrkPlceOpr", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TPrkPlceManager::MergePrkPlceOpr", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool TPrkPlceManager::MergePrkPlcePrv(TPrkPlce *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;
#if 0
    sQry = "MERGE INTO TB_PRK_PLCE_PRV L                                        \r\n"
           "USING (SELECT                                                       \r\n"
           "              :p01 AS PRK_PLCE_NMBR,                                \r\n"
           "              :p02 AS VHCTY_AR_SE,                                  \r\n"
           "              :p03 AS VHCTY_AR_PRK_CMPRT_CO,                        \r\n"
           "              0 AS VHCTY_AR_REMNDR_PRK_CMPRT_CO                     \r\n"
           "         FROM DUAL) M                                               \r\n"
           "        ON (L.PRK_PLCE_NMBR = M.PRK_PLCE_NMBR)                      \r\n"
           "WHEN MATCHED THEN                                                   \r\n"
           "   UPDATE SET                                                       \r\n"
           "              L.VHCTY_AR_SE           = M.VHCTY_AR_SE,              \r\n"
           "              L.VHCTY_AR_PRK_CMPRT_CO = M.VHCTY_AR_PRK_CMPRT_CO     \r\n"
           "WHEN NOT MATCHED THEN                                               \r\n"
           "   INSERT (                                                         \r\n"
           "           PRK_PLCE_NMBR,                                           \r\n"
           "           VHCTY_AR_SE,                                             \r\n"
           "           VHCTY_AR_PRK_CMPRT_CO,                                   \r\n"
           "           VHCTY_AR_REMNDR_PRK_CMPRT_CO )                           \r\n"
           "   VALUES (                                                         \r\n"
           "           M.PRK_PLCE_NMBR,                                         \r\n"
           "           M.VHCTY_AR_SE,                                           \r\n"
           "           M.VHCTY_AR_PRK_CMPRT_CO,                                 \r\n"
           "           M.VHCTY_AR_REMNDR_PRK_CMPRT_CO )                         \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->CTLR_ID;
			pADO->Parameters->ParamByName("p02")->Value = "PARK";
			pADO->Parameters->ParamByName("p03")->Value = AObj->NAME;
			pADO->ExecSQL();

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

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

bool TPrkPlceManager::MergeFcltInfo(TPrkPlce *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->CTLR_ID;
			pADO->Parameters->ParamByName("p02")->Value = "PARK";
			pADO->Parameters->ParamByName("p03")->Value = AObj->NAME;
			pADO->ExecSQL();

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

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

