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


#pragma hdrstop

#include "TCDSFontF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

//---------------------------------------------------------------------------
TCDSFontName::TCDSFontName()
{
}
//---------------------------------------------------------------------------

TCDSFontName::~TCDSFontName()
{
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
TCDSFontColor::TCDSFontColor()
{
}
//---------------------------------------------------------------------------

TCDSFontColor::~TCDSFontColor()
{
}
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
TCDSFontManager *CDSFontManager = NULL;
//---------------------------------------------------------------------------

TCDSFontManager::TCDSFontManager()
{
}
//---------------------------------------------------------------------------
TCDSFontManager::~TCDSFontManager()
{
    FNames.RemoveAll();
    FColors.RemoveAll();
}
//---------------------------------------------------------------------------
int TCDSFontManager::LoadFontInfo(TADOConnection *ADbConn)
{
    if(LoadFontNameInfo(ADbConn) < 0)
    {
        return -1;
    }

    return LoadFontColorInfo(ADbConn);
}
//---------------------------------------------------------------------------
int TCDSFontManager::LoadFontNameInfo(TADOConnection *ADbConn)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    int        nSelCnt = 0;

    DDBSTART;

    sQry = "SELECT A.*                  \r\n"
           "  FROM TB_VMS_FONT_NAME  A  \r\n";

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
            pADO->Connection = ADbConn;

			SQLText(pADO, sQry, true);

			SQLOpen(pADO);
            for( ; !pADO->Eof; pADO->Next())
            {
                int VMS_FONT_NAME_CD = pADO->FieldByName("VMS_FONT_NAME_CD")->AsInteger;

				TCDSFontName *pObj = FNames.Find(VMS_FONT_NAME_CD);
                if (!pObj)
                {
                    pObj = new TCDSFontName();
                    pObj->VMS_FONT_NAME_CD = VMS_FONT_NAME_CD;
                    FNames.Push(pObj->VMS_FONT_NAME_CD, pObj);
                }

                pObj->VMS_FONT_NAME_NM = pADO->FieldByName("VMS_FONT_NAME_NM")->AsString.Trim();
                pObj->USE_YN           = pADO->FieldByName("USE_YN")->AsString.Trim();
                nSelCnt++;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERROR(String(E.ClassName()), E.Message, sQry);
            return -1;
        }
        catch(Exception &e)
        {
            DBERROR(String(e.ClassName()), e.Message, sQry);
            return -1;
        }
    }
    __finally
    {
        SQLFree(pADO);
    }

    IDBSTOP(nSelCnt);
    return nSelCnt;
}
//---------------------------------------------------------------------------
int TCDSFontManager::LoadFontColorInfo(TADOConnection *ADbConn)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    int        nSelCnt = 0;

    DDBSTART;

    sQry = "SELECT A.*                  \r\n"
           "  FROM TB_VMS_FONT_COLR  A  \r\n";

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
            pADO->Connection = ADbConn;

			SQLText(pADO, sQry, true);

			SQLOpen(pADO);
            for( ; !pADO->Eof; pADO->Next())
            {
                int VMS_FONT_COLR_CD = pADO->FieldByName("VMS_FONT_COLR_CD")->AsInteger;

				TCDSFontColor *pObj = FColors.Find(VMS_FONT_COLR_CD);
                if (!pObj)
                {
                    pObj = new TCDSFontColor();
                    pObj->VMS_FONT_COLR_CD = VMS_FONT_COLR_CD;
                    FColors.Push(pObj->VMS_FONT_COLR_CD, pObj);
                }

                pObj->VMS_FONT_COLR_NM  = pADO->FieldByName("VMS_FONT_COLR_NM")->AsString.Trim();
                pObj->VMS_FONT_COLR_VAL = pADO->FieldByName("VMS_FONT_COLR_VAL")->AsInteger;
                pObj->USE_YN            = pADO->FieldByName("USE_YN")->AsString.Trim();
                nSelCnt++;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERROR(String(E.ClassName()), E.Message, sQry);
            return -1;
        }
        catch(Exception &e)
        {
            DBERROR(String(e.ClassName()), e.Message, sQry);
            return -1;
        }
    }
    __finally
    {
        SQLFree(pADO);
    }

    IDBSTOP(nSelCnt);
    return nSelCnt;
}
//---------------------------------------------------------------------------

