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

#pragma hdrstop

#include "CDSVmsObjTypeF.h"
#include "ITS_OPLibF.h"

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

#pragma package(smart_init)

//---------------------------------------------------------------------------
TVmsTypeManager *VmsTypeManager = NULL;
//---------------------------------------------------------------------------

TVmsTypeManager::TVmsTypeManager()
{
}
//---------------------------------------------------------------------------
TVmsTypeManager::~TVmsTypeManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------

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

    FLists.Lock();
    try
    {
        FLists.RemoveAll();
    }
    __finally
    {
        FLists.UnLock();
    }

    sQry = "SELECT A.*               \r\n"
           "  FROM TB_VMS_TYPE A     \r\n"
           " WHERE USE_YN = 'Y'      \r\n"
           " ORDER BY A.VMS_TYPE_CD  \r\n";

    FLists.Lock();
    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())
            {
#if 0
                String USE_YN = pADO->FieldByName("VMS_TYPE_CD")->AsString;
                if (USE_YN != "Y") continue;
#endif

				TVmsType *pObj = new TVmsType();
                if (!pObj)
                {
                    continue;
                }
                pObj->VMS_TYPE_CD  = pADO->FieldByName("VMS_TYPE_CD")->AsString.Trim(); //	N	VARCHAR2(5)	    N			VMS 유형 코드
                pObj->VMS_TYPE_NM  = pADO->FieldByName("VMS_TYPE_NM")->AsString.Trim(); //	N	VARCHAR2(40)	Y			VMS 유형 명
                pObj->VMS_WDTH     = pADO->FieldByName("VMS_WDTH")->AsInteger;          //	N	NUMBER(3)	    Y			VMS 너비
                pObj->VMS_HGHT     = pADO->FieldByName("VMS_HGHT")->AsInteger;          //	N	NUMBER(3)	    Y			VMS 높이
                pObj->ROW_NUM      = pADO->FieldByName("ROW_NUM")->AsInteger;           //	N	NUMBER(3)	    Y			행 개수
                pObj->COL_NUM      = pADO->FieldByName("COL_NUM")->AsInteger;           //	N	NUMBER(3)	    Y			열 개수
                pObj->MODL_ROW_NUM = pADO->FieldByName("MODL_ROW_NUM")->AsInteger;      //	N	NUMBER(3)	    Y			모듈 행 개수
                pObj->MODL_COL_NUM = pADO->FieldByName("MODL_COL_NUM")->AsInteger;      //	N	NUMBER(3)	    Y			모듈 열 개수
                pObj->POWR_ROW_NUM = pADO->FieldByName("POWR_ROW_NUM")->AsInteger;      //	N	NUMBER(3)	    Y			전원모듈 행 개수
                pObj->POWR_COL_NUM = pADO->FieldByName("POWR_COL_NUM")->AsInteger;      //	N	NUMBER(3)	    Y			전원모듈 열 개수
                pObj->USE_YN       = pADO->FieldByName("USE_YN")->AsString;             //	N	CHAR(1)	        Y	'N'		사용 여부

                FLists.Push(pObj->VMS_TYPE_CD, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TVmsTypeManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TVmsTypeManager::LoadFromDb", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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

TVmsObjUse::TVmsObjUse()
{
}
//---------------------------------------------------------------------------
TVmsObjUse::~TVmsObjUse()
{
    MODE = enUPDATE;
}
//---------------------------------------------------------------------------

TVmsObjUseManager::TVmsObjUseManager()
{
}
//---------------------------------------------------------------------------
TVmsObjUseManager::~TVmsObjUseManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------

bool TVmsObjUseManager::LoadFromDb(String AFormId, TADOConnection *ADbConn/*=NULL*/)
{
return true;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TVmsObjType::TVmsObjType()
{
}
//---------------------------------------------------------------------------
TVmsObjType::~TVmsObjType()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TVmsObjTypeManager *VmsObjTypeManager = NULL;
//---------------------------------------------------------------------------

TVmsObjTypeManager::TVmsObjTypeManager()
{
}
//---------------------------------------------------------------------------
TVmsObjTypeManager::~TVmsObjTypeManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------

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

    FLists.Lock();
    try
    {
        FLists.RemoveAll();
    }
    __finally
    {
        FLists.UnLock();
    }

    sQry = "SELECT VMS_FORM_TYPE_CD        AS TYPE, \r\n"
           "       VMS_FORM_OBJECT_TYPE_CD AS CD,   \r\n"
           "       VMS_FORM_OBJECT_TYPE_NM AS NM,   \r\n"
           "       USE_YN                           \r\n"
           "  FROM TB_VMS_FORM_OBJECT_TYPE          \r\n"
           " WHERE USE_YN = 'Y'                     \r\n"
           " ORDER BY TYPE, CD                      \r\n";

    FLists.Lock();
    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())
            {
                int nFormType = pADO->FieldByName("TYPE")->AsInteger;

				TVmsObjType *pObj = FLists.Find(nFormType);
                if (!pObj)
                {
                    pObj = new TVmsObjType();
                    FLists.Push(nFormType, pObj);
                }
                pObj->TYPE = nFormType;

                int nType = pADO->FieldByName("CD")->AsInteger;
                TFormObjType *pType = pObj->FLists.Find(nType);
                if (!pType)
                {
                    pType = new TFormObjType();
                    pObj->FLists.Push(nType, pType);
                }
                pType->TYPE    = pADO->FieldByName("CD")->AsInteger;
                pType->NAME    = pADO->FieldByName("NM")->AsString;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TVmsObjTypeManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TVmsObjTypeManager::LoadFromDb", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

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


