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

#pragma hdrstop

#include "CDSColSysF.h"
#include "ITSDbF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

TItsColSys::TItsColSys()
{
	FCompleted = false;
    FEditMode  = DB_INIT;
	FGridIndex = -1;
	MEM_DEL    = "N";
    //Clear();
}
//---------------------------------------------------------------------------
void TItsColSys::Clear()
{
    CLCT_SYST_CD   = "";    //VARCHAR2(7)	N			수집 시스템 코드
    CLCT_SYST_NMBR = "";    //NUMBER(2)	Y			수집 시스템 번호
    CLCT_SYST_NM   = "";    //VARCHAR2(30)	N			수집 시스템 명
    CLCT_SYST_EXPL = "";    //VARCHAR2(100)	Y			수집 시스템 설명
    CLCT_MAX_NUM   = "";    //NUMBER(7)	Y	0		수집 최대 개수
    USE_YN         = "Y";   //CHAR(1)	Y	'N'		사용 여부
}
//---------------------------------------------------------------------------
TItsColSys::~TItsColSys()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TItsColSysManager *ItsColSysManager = NULL;
//---------------------------------------------------------------------------

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

    sQry = "SELECT CLCT_SYST_CD,     \r\n"
           "       CLCT_SYST_NMBR,   \r\n"
           "       CLCT_SYST_NM,     \r\n"
           "       CLCT_SYST_EXPL,   \r\n"
           "       CLCT_MAX_NUM,     \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->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsColSys *pObj = new TItsColSys();

                pObj->CLCT_SYST_CD   = pADO->FieldByName("CLCT_SYST_CD")->AsString;
                pObj->CLCT_SYST_NMBR = pADO->FieldByName("CLCT_SYST_NMBR")->AsString;
                pObj->CLCT_SYST_NM   = pADO->FieldByName("CLCT_SYST_NM")->AsString;
                pObj->CLCT_SYST_EXPL = pADO->FieldByName("CLCT_SYST_EXPL")->AsString;
                pObj->CLCT_MAX_NUM   = pADO->FieldByName("CLCT_MAX_NUM")->AsString;
                pObj->USE_YN         = pADO->FieldByName("USE_YN")->AsString;

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

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

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

