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


#pragma hdrstop

#include "CDSFontF.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::GetColorCode(int AColor)
{
    FOR_STL(TCDSFontColor*, pObj, FColors)
    {
        if (AColor == pObj->VMS_FONT_COLR_VAL) return pObj->VMS_FONT_COLR_CD;
    }
    return 0;
}
//---------------------------------------------------------------------------
int TCDSFontManager::GetColorCodeIndex(int ACode)
{
    int nIdx = 0;
    FOR_STL(TCDSFontColor*, pObj, FColors)
    {
        if (ACode == pObj->VMS_FONT_COLR_CD) return nIdx;
        nIdx++;
    }
    return 0;
}
//---------------------------------------------------------------------------
int TCDSFontManager::LoadFontInfo()
{
    if(LoadFontNameInfo() < 0)
    {
        return -1;
    }

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

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

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
            pADO->Connection = ADbConn;
			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 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)
        {
            DBERRORMSG("TCDSFontManager::LoadFontNameInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TCDSFontManager::LoadFontNameInfo", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return nSelCnt;
#endif
return 0;
}
//---------------------------------------------------------------------------
int TCDSFontManager::LoadFontColorInfo()
{
#if 0
    String     sQry;
    TADOQuery *pADO = NULL;
    int        nSelCnt = 0;

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

    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
            pADO->Connection = ADbConn;
			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 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)
        {
            DBERRORMSG("TCDSFontManager::LoadFontColorInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("TCDSFontManager::LoadFontColorInfo", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return nSelCnt;
#endif
return 0;
}
//---------------------------------------------------------------------------
