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

#pragma hdrstop

#include "CDSColtSysF.h"
#include "ITSDbF.h"

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

#pragma package(smart_init)

TItsColtSys::TItsColtSys()
{
	FCompleted = false;
    FEditMode  = DB_INIT;
	FGridIndex = -1;
	MEM_DEL    = "N";
    //Clear();
}
//---------------------------------------------------------------------------
void TItsColtSys::Clear()
{
    ColtSys_ID      = "";  //VARCHAR2(20)	N			사용자ID
    PWD          = "";  //VARCHAR2(64)	Y			암호
    NAME         = "";  //VARCHAR2(30)	Y			성명
    COMP         = "";  //VARCHAR2(50)	Y			회사
    TEL          = "";  //VARCHAR2(128)	Y			전화번호
    ADDR         = "";  //VARCHAR2(200)	Y			주소
    RESD_NMBR    = "";  //VARCHAR2(14)	Y			주민번호
    MOBILE       = "";  //VARCHAR2(128)	Y			이동전화
    EMAL         = "";  //VARCHAR2(128)	Y			이메일
    DEL_YN       = "";  //CHAR(1)	Y	'N'		삭제 여부
    RGSTYMD      = "";  //VARCHAR2(14)	Y			등록일자
    CRCTYMD      = "";  //VARCHAR2(14)	Y			수정일자
    HINT_QUES    = "";  //VARCHAR2(7)	Y			힌트질문
    HINT_ANS     = "";  //VARCHAR2(100)	Y			힌트질문답
    GROP_ID      = "";  //VARCHAR2(30)	Y			그룹ID
    OPER_SYST_ID = "";  //VARCHAR2(30)	Y			운영시스템ID
}
//---------------------------------------------------------------------------
TItsColtSys::~TItsColtSys()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TItsColtSysManager *ItsColtSysManager = NULL;
//---------------------------------------------------------------------------

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

    sQry = "SELECT ROWNUM AS ORDSEQ, \r\n"
           "       CLCT_SYST_CD,     \r\n"
           "       CLCT_SYST_NM,     \r\n"
           "       USE_YN            \r\n"
           "  FROM TB_CLCT_SYST_STUP \r\n"
           " WHERE USE_YN = 'Y'      \r\n";
    try
    {
        FLists.Lock();
        FLists.RemoveAll();
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

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

                pObj->ORDSEQ        = pADO->FieldByName("ORDSEQ")->AsString;
                pObj->CLCT_SYST_CD  = pADO->FieldByName("CLCT_SYST_CD")->AsString;
                pObj->CLCT_SYST_NM  = pADO->FieldByName("CLCT_SYST_NM")->AsString;
                pObj->USE_YN        = pADO->FieldByName("USE_YN")->AsString;

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

                pObj->Completed = true;
                pObj->MEM_DEL   = "N";
            }
        }
        catch(EDatabaseError &E)
        {
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
        catch(...)
        {
            throw Exception("[ItsColtSysManager] 알수없는 DB 오류가 발생하였습니다.");
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

