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

#pragma hdrstop

#include "CDSParkingF.h"
#include "ITSDbF.h"
#include "ITS_OPLibF.h"

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

#pragma package(smart_init)

TItsParking::TItsParking()
{
	FCompleted = false;
    FEditMode  = DB_INIT;
	FGridIndex = -1;
	MEM_DEL    = "N";
    DEL_YN     = "N";

    DEL_USER_ID  = "";
    DEL_DT       = "";
    DEL_YN       = "N";
    ADTN_USER_ID = "";
    ADTN_DT      = "";
    CHNG_USER_ID = "";
    CHNG_DT      = "";

    Floors = 0;
    FData1 = NULL;
    FData2 = NULL;
}
//---------------------------------------------------------------------------
void TItsParking::Clear()
{
}
//---------------------------------------------------------------------------
TItsParking::~TItsParking()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TItsParkingManager *ItsParkingManager = NULL;
//---------------------------------------------------------------------------

/*
* Parking Manager
*/
TItsParkingManager::TItsParkingManager()
{
}
//---------------------------------------------------------------------------
TItsParkingManager::~TItsParkingManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------
bool TItsParkingManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    return true;
}
//---------------------------------------------------------------------------

bool TItsParkingManager::GetNextParkingId(String &ANewId, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

#if 0
    sQry = "SELECT LPAD(NVL(MAX(SUBSTR(CTLR_MNGM_NMBR, -7)), '0000000') + 1, 7, '0') AS NEWID \r\n"
           "  FROM TB_PRLT_CTLR                                                               \r\n";
#else
    sQry = "SELECT NVL(MAX(CTLR_MNGM_NMBR)+1, 1) AS NEWID \r\n"
           "  FROM TB_PRLT_CTLR                           \r\n";
#endif

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

			pADO->Open();
            ANewId = pADO->FieldByName("NEWID")->AsString;
//            ANewId = "PAR" + pADO->FieldByName("NEWID")->AsString;
            return true;
        }
        catch(EDatabaseError &E)
        {
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return false;
}
//---------------------------------------------------------------------------

bool TItsParkingManager::DeleteParking(TItsParking *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "UPDATE TB_PRLT_CTLR          \r\n"
           "   SET DEL_YN      = 'Y',    \r\n"
           "       DEL_USER_ID = :p02,   \r\n"
           "       DEL_DT      = :p03    \r\n"
           " WHERE CTLR_MNGM_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_MNGM_NMBR;
			pADO->Parameters->ParamByName("p02")->Value = AObj->DEL_USER_ID;
			pADO->Parameters->ParamByName("p03")->Value = AObj->DEL_DT;
			pADO->ExecSQL();

    sQry = "DELETE TB_PRLT_OPER_INFR          \r\n"
           " WHERE CTLR_MNGM_NMBR = :p01 \r\n";

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


#if 0
    sQry = "DELETE TB_PRLT_FLOR          \r\n"
           " WHERE CTLR_MNGM_NMBR = :p01 \r\n";

			pADO->SQL->Text = sQry;
			pADO->Parameters->ParamByName("p01")->Value = AObj->CTLR_MNGM_NMBR;
			pADO->ExecSQL();
#endif

        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_MNGM_NMBR;
			pADO->ExecSQL();
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("주차장정보삭제", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            //DBERRORMSG("주차장정보삭제", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        //FLists.UnLock();
    }

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

bool TItsParkingManager::UpdateParking(TItsParking *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;


    sQry = "UPDATE TB_PRLT_CTLR                \r\n"
           "   SET PRLT_OPER_DVSN_CD = :p02,   \r\n"
           "       PRLT_TYPE_DVSN_CD = :p03,   \r\n"
           "       VALD_YN           = :p04,   \r\n"
           "       X_CRDN            = :p05,   \r\n"
           "       Y_CRDN            = :p06,   \r\n"
           "       ISTL_LCTN_ADDR    = :p07,   \r\n"
           "       TRMN_IP           = :p08,   \r\n"
           "       TRMN_PORT         = :p09,   \r\n"
           "       CTLR_CLCT_CYCL    = :p10,   \r\n"
           "       CTLR_STTS_CYCL    = :p11,   \r\n"
           "       WHOL_NPLS         = :p12,   \r\n"
           "       DEL_USER_ID       = :p13,   \r\n"
           "       DEL_DT            = :p14,   \r\n"
           "       DEL_YN            = :p15,   \r\n"
           "       ADTN_USER_ID      = :p16,   \r\n"
           "       ADTN_DT           = :p17,   \r\n"
           "       CHNG_USER_ID      = :p18,   \r\n"
           "       CHNG_DT           = :p19,   \r\n"
#ifdef USE_PARK_REAL
           "       CTLR_MNGM_NM      = :p20,   \r\n"
           "       REAL_DATA_YN      = :p21    \r\n"
#else
           "       CTLR_MNGM_NM      = :p20   \r\n"
#endif
           " WHERE CTLR_MNGM_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_MNGM_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->PRLT_OPER_DVSN_CD;
            pADO->Parameters->ParamByName("p03")->Value = AObj->PRLT_TYPE_DVSN_CD;
            pADO->Parameters->ParamByName("p04")->Value = AObj->VALD_YN;
            pADO->Parameters->ParamByName("p05")->Value = AObj->X_CRDN;
            pADO->Parameters->ParamByName("p06")->Value = AObj->Y_CRDN;
            pADO->Parameters->ParamByName("p07")->Value = AObj->ISTL_LCTN_ADDR;
            pADO->Parameters->ParamByName("p08")->Value = AObj->TRMN_IP;
            pADO->Parameters->ParamByName("p09")->Value = AObj->TRMN_PORT;
            pADO->Parameters->ParamByName("p10")->Value = AObj->CTLR_CLCT_CYCL;
            pADO->Parameters->ParamByName("p11")->Value = AObj->CTLR_STTS_CYCL;
            pADO->Parameters->ParamByName("p12")->Value = AObj->WHOL_NPLS;
            pADO->Parameters->ParamByName("p13")->Value = AObj->DEL_USER_ID;
            pADO->Parameters->ParamByName("p14")->Value = AObj->DEL_DT;
            pADO->Parameters->ParamByName("p15")->Value = AObj->DEL_YN;
            pADO->Parameters->ParamByName("p16")->Value = AObj->ADTN_USER_ID;
            pADO->Parameters->ParamByName("p17")->Value = AObj->ADTN_DT;
            pADO->Parameters->ParamByName("p18")->Value = AObj->CHNG_USER_ID;
            pADO->Parameters->ParamByName("p19")->Value = AObj->CHNG_DT;
            pADO->Parameters->ParamByName("p20")->Value = AObj->CTLR_MNGM_NM;
#ifdef USE_PARK_REAL
            pADO->Parameters->ParamByName("p21")->Value = AObj->REAL_DATA_YN;
#endif

			pADO->ExecSQL();

            InsertParkingOper(AObj, ADbConn);
            InsertParkingFloors(AObj, ADbConn);

        sQry = "UPDATE TB_FCLT_INFR       \r\n"
               "   SET FCLT_LCTN  = :p02  \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_MNGM_NMBR;
			pADO->Parameters->ParamByName("p02")->Value = AObj->CTLR_MNGM_NM;
			pADO->ExecSQL();

            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("주차장정보업데이트", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            //DBERRORMSG("주차장정보업데이트", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        //FLists.UnLock();
    }

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

bool TItsParkingManager::InsertParking(TItsParking *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "INSERT INTO TB_PRLT_CTLR(                              \r\n"
           "         CTLR_MNGM_NMBR,                               \r\n"
           "         PRLT_OPER_DVSN_CD,                            \r\n"
           "         PRLT_TYPE_DVSN_CD,                            \r\n"
           "         VALD_YN,                                      \r\n"
           "         X_CRDN,                                       \r\n"
           "         Y_CRDN,                                       \r\n"
           "         ISTL_LCTN_ADDR,                               \r\n"
           "         TRMN_IP,                                      \r\n"
           "         TRMN_PORT,                                    \r\n"
           "         CTLR_CLCT_CYCL,                               \r\n"
           "         CTLR_STTS_CYCL,                               \r\n"
           "         WHOL_NPLS,                                    \r\n"
           "         DEL_USER_ID,                                  \r\n"
           "         DEL_DT,                                       \r\n"
           "         DEL_YN,                                       \r\n"
           "         ADTN_USER_ID,                                 \r\n"
           "         ADTN_DT,                                      \r\n"
           "         CHNG_USER_ID,                                 \r\n"
           "         CHNG_DT,                                      \r\n"
#ifdef USE_PARK_REAL
           "         CTLR_MNGM_NM,                                 \r\n"
           "         REAL_DATA_YN                                  \r\n"
#else
           "         CTLR_MNGM_NM                                  \r\n"
#endif
           "                        )                              \r\n"
           "                 VALUES(:p01, :p02, :p03, :p04, :p05,  \r\n"
           "                        :p06, :p07, :p08, :p09, :p10,  \r\n"
           "                        :p11, :p12, :p13, :p14, :p15,  \r\n"
#ifdef USE_PARK_REAL
           "                        :p16, :p17, :p18, :p19, :p20,  \r\n"
           "                        :p21 )                         \r\n";
#else
           "                        :p16, :p17, :p18, :p19, :p20 ) \r\n";
#endif
    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_MNGM_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->PRLT_OPER_DVSN_CD;
            pADO->Parameters->ParamByName("p03")->Value = AObj->PRLT_TYPE_DVSN_CD;
            pADO->Parameters->ParamByName("p04")->Value = AObj->VALD_YN;
            pADO->Parameters->ParamByName("p05")->Value = AObj->X_CRDN;
            pADO->Parameters->ParamByName("p06")->Value = AObj->Y_CRDN;
            pADO->Parameters->ParamByName("p07")->Value = AObj->ISTL_LCTN_ADDR;
            pADO->Parameters->ParamByName("p08")->Value = AObj->TRMN_IP;
            pADO->Parameters->ParamByName("p09")->Value = AObj->TRMN_PORT;
            pADO->Parameters->ParamByName("p10")->Value = AObj->CTLR_CLCT_CYCL;
            pADO->Parameters->ParamByName("p11")->Value = AObj->CTLR_STTS_CYCL;
            pADO->Parameters->ParamByName("p12")->Value = AObj->WHOL_NPLS;
            pADO->Parameters->ParamByName("p13")->Value = AObj->DEL_USER_ID;
            pADO->Parameters->ParamByName("p14")->Value = AObj->DEL_DT;
            pADO->Parameters->ParamByName("p15")->Value = AObj->DEL_YN;
            pADO->Parameters->ParamByName("p16")->Value = AObj->ADTN_USER_ID;
            pADO->Parameters->ParamByName("p17")->Value = AObj->ADTN_DT;
            pADO->Parameters->ParamByName("p18")->Value = AObj->CHNG_USER_ID;
            pADO->Parameters->ParamByName("p19")->Value = AObj->CHNG_DT;
            pADO->Parameters->ParamByName("p20")->Value = AObj->CTLR_MNGM_NM;
#ifdef USE_PARK_REAL
            pADO->Parameters->ParamByName("p21")->Value = AObj->REAL_DATA_YN;
#endif

			pADO->ExecSQL();

            InsertParkingOper(AObj, ADbConn);
            InsertParkingFloors(AObj, ADbConn);

        sQry = "INSERT INTO TB_FCLT_INFR(FCLT_ID, FCLT_TYPE, FCLT_LCTN, RSCE_YN, DEL_YN, USE_YEAR, AMT) \r\n"
               "                  VALUES(:p01,    'PARK',     :p03,      'N',     'N',    '0',      '0') \r\n";

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

            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("주차장정보입력", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            //DBERRORMSG("주차장정보입력", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        //FLists.UnLock();
    }

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

bool TItsParkingManager::InsertParkingOper(TItsParking *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

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


    sQry = "DELETE TB_PRLT_OPER_INFR          \r\n"
           " WHERE CTLR_MNGM_NMBR = :p01 \r\n";

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

    sQry = "INSERT INTO TB_PRLT_OPER_INFR(                         \r\n"
           "         CTLR_MNGM_NMBR,                               \r\n"
           "         PRLT_MNGM_INTN_NM,                            \r\n"
           "         PRLT_MNGM_INTN_TEL,                           \r\n"
           "         PARK_NDSY_CD,                                 \r\n"
           "         PARK_OPER_DAY_CD,                             \r\n"
           "         PARK_WKDY_STRT_HH,                            \r\n"
           "         PARK_WKDY_END_HH,                             \r\n"
           "         PARK_LHDY_STRT_HH,                            \r\n"
           "         PARK_LHDY_END_HH,                             \r\n"
           "         PARK_OPDR_CD,                                 \r\n"
           "         PARK_FARE_IMPS_CD,                            \r\n"
           "         PARK_APNT_OFFR_YN                             \r\n"
           "                        )                              \r\n"
           "                 VALUES(:p01, :p02, :p03, :p04, :p05,  \r\n"
           "                        :p06, :p07, :p08, :p09, :p10,  \r\n"
           "                        :p11, :p12            )        \r\n";

			pADO->SQL->Text = sQry;

            pADO->Parameters->ParamByName("p01")->Value = AObj->CTLR_MNGM_NMBR;
            pADO->Parameters->ParamByName("p02")->Value = AObj->PRLT_MNGM_INTN_NM;
            pADO->Parameters->ParamByName("p03")->Value = AObj->PRLT_MNGM_INTN_TEL;
            pADO->Parameters->ParamByName("p04")->Value = AObj->PARK_NDSY_CD;
            pADO->Parameters->ParamByName("p05")->Value = AObj->PARK_OPER_DAY_CD;
            pADO->Parameters->ParamByName("p06")->Value = AObj->PARK_WKDY_STRT_HH;
            pADO->Parameters->ParamByName("p07")->Value = AObj->PARK_WKDY_END_HH;
            pADO->Parameters->ParamByName("p08")->Value = AObj->PARK_LHDY_STRT_HH;
            pADO->Parameters->ParamByName("p09")->Value = AObj->PARK_LHDY_END_HH;
            pADO->Parameters->ParamByName("p10")->Value = AObj->PARK_OPDR_CD;
            pADO->Parameters->ParamByName("p11")->Value = AObj->PARK_FARE_IMPS_CD;
            pADO->Parameters->ParamByName("p12")->Value = AObj->PARK_APNT_OFFR_YN;
			pADO->ExecSQL();

            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("주차장정보입력", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            //DBERRORMSG("주차장정보입력", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        //FLists.UnLock();
    }

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

bool TItsParkingManager::InsertParkingFloors(TItsParking *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

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


#if 0
    sQry = "DELETE TB_PRLT_FLOR          \r\n"
           " WHERE CTLR_MNGM_NMBR = :p01 \r\n";

			pADO->SQL->Text = sQry;
			pADO->Parameters->ParamByName("p01")->Value = AObj->CTLR_MNGM_NMBR;
			pADO->ExecSQL();
#endif

#if 0
    sQry = "INSERT INTO TB_PRLT_FLOR( CTLR_MNGM_NMBR, FLOR_NMBR, FLOR_NM ) \r\n"
           "                 VALUES(:p01, :p02, :p03   )                   \r\n";
#else
    sQry = "UPDATE TB_PRLT_FLOR          \r\n"
           "   SET FLOR_NM = :p03        \r\n"
           " WHERE CTLR_MNGM_NMBR = :p01 \r\n"
           "   AND FLOR_NMBR      = :p02 \r\n";
#endif

			pADO->SQL->Text = sQry;

            for (int ii = 0; ii < AObj->Floors; ii++)
            {
                pADO->Parameters->ParamByName("p01")->Value = AObj->CTLR_MNGM_NMBR;
                pADO->Parameters->ParamByName("p02")->Value = AObj->FLOR_NMBR[ii];
                pADO->Parameters->ParamByName("p03")->Value = AObj->FLOR_NM[ii];
                pADO->ExecSQL();
            }
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("주차장정보입력", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            //DBERRORMSG("주차장정보입력", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        //FLists.UnLock();
    }

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

bool TItsParkingManager::SelParkingFloors(TItsParking *AObj, TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT * FROM TB_PRLT_FLOR   \r\n"
           " WHERE CTLR_MNGM_NMBR = :p01 \r\n"
           " ORDER BY FLOR_NMBR          \r\n";

    AObj->Floors = 0;

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

			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
                AObj->FLOR_NMBR[AObj->Floors] = pADO->FieldByName("FLOR_NMBR")->AsString;
                AObj->FLOR_NM[AObj->Floors]   = pADO->FieldByName("FLOR_NM")->AsString;
                AObj->Floors++;
                if (AObj->Floors >= MAX_PARKING_FLOOR)
                {
                    break;
                }
            }
            return true;
        }
        catch(EDatabaseError &E)
        {
            //DBERRORMSG("주차장정보입력", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            //DBERRORMSG("주차장정보입력", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

