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

#include <vcl.h>
#include "ITSDbF.h"
#include "ITSLangTransF.h"
#include "CDSFontF.h"
#include "AppGlobalF.h"
#pragma hdrstop

#include "FrmResourceF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "cxButtons"
#pragma link "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "VmsDesignerF"
#pragma resource "*.dfm"
TFrmLang *FrmLang;
//---------------------------------------------------------------------------
__fastcall TFrmLang::TFrmLang(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    FFontInit = false;
    //Show();
}
//---------------------------------------------------------------------------
void TFrmLang::ITSSkin_ButtonClick(TcxButton *ASearch, TcxButton *AEdit, TcxButton *AAdd, TcxButton *ADel, TcxButton *AApply)
{
    if (!AEdit) return;

    if (AEdit->Down)
    {
        // 편집모드 시작
        AEdit->Glyph->Assign(BtnEdit2->Glyph);
        AEdit->Hint = lblEditHint1->Caption;//"데이터 편집 종료/취소";

        if (ASearch) ASearch->Enabled = false;
        if (AAdd)    AAdd->Enabled    = true;
        if (ADel)    ADel->Enabled    = true;
        if (AApply)  AApply->Enabled  = true;
    }
    else
    {
        // 편집모드 종료
        AEdit->Glyph->Assign(BtnEdit1->Glyph);
        AEdit->Hint = lblEditHint2->Caption;//"데이터 편집";

        if (ASearch) ASearch->Enabled = true;
        if (AAdd)    AAdd->Enabled    = false;
        if (ADel)    ADel->Enabled    = false;
        if (AApply)  AApply->Enabled  = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmLang::FormClose(TObject *Sender, TCloseAction &Action)
{
    try
    {
        if (m_pEdtDesigner)
        {
            delete m_pEdtDesigner;
            m_pEdtDesigner = NULL;
        }
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmLang::FormCreate(TObject *Sender)
{
    m_pEdtDesigner = new TVmsFormDesigner(PnlEditForm);
    m_pEdtDesigner->ApplicationHandle = (long)Handle;
}
//---------------------------------------------------------------------------
int __fastcall TFrmLang::CheckImageUseCount(String ASYMB_LIB_NMBR)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    int        nResult = 0;

    sQry = "SELECT COUNT(1) AS CNT      \r\n"
           "  FROM TB_VMS_FORM_OBJECT   \r\n"
           " WHERE SYMBLIB_NMBR = :p01  \r\n";

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

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ASYMB_LIB_NMBR);
            ITSDb_SQLOpen(pADO);
            nResult = pADO->FieldByName("CNT")->AsInteger;
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("CheckImageUseCount", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("CheckImageUseCount", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return nResult;
}
//---------------------------------------------------------------------------

bool __fastcall TFrmLang::DelVmsImage(String ASYMB_LIB_NMBR, bool ADelIfsc)
{
    String sQry;
    TADOQuery *pADO = NULL;

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

if (ADelIfsc)
{
    sQry = "DELETE TB_VMS_SYMB_IFSC      \r\n"
           " WHERE SYMBLIB_NMBR = :p01   \r\n";

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ASYMB_LIB_NMBR);
			pADO->ExecSQL();
}

#if 0
    sQry = "DELETE TB_VMS_SYMB_LIB      \r\n"
           " WHERE SYMBLIB_NMBR = :p01  \r\n";
#else
    sQry = "UPDATE TB_VMS_SYMB_LIB                                \r\n"
           "   SET DEL_YN  = 'Y',                                 \r\n"
           "       UPDT_DT = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') \r\n"
           " WHERE SYMBLIB_NMBR = :p01                            \r\n";
#endif


            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ASYMB_LIB_NMBR);
			pADO->ExecSQL();
            return true;
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("DelVmsImage", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("DelVmsImage", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return true;
}
//---------------------------------------------------------------------------
bool __fastcall TFrmLang::GetNextVmsImgeId(int &ANmbr, int AFromId, int AToId)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT NVL(MAX(SYMBLIB_NMBR), :p01)+1 AS NEWID FROM TB_VMS_SYMB_LIB WHERE SYMBLIB_NMBR BETWEEN :p02 AND :p03 \r\n";

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

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", AFromId-1);
            ITSDb_SQLBind(pADO, "p02", AFromId);
            ITSDb_SQLBind(pADO, "p03", AToId);
            ITSDb_SQLOpen(pADO);

			pADO->Open();
            ANmbr = pADO->FieldByName("NEWID")->AsInteger;
            return true;
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("GetNextVmsImgeId", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("GetNextVmsImgeId", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return false;
}
//---------------------------------------------------------------------------
bool __fastcall TFrmLang::UpdateVmsImage(String ASYMB_LIB_NMBR, String ASYMB_EXPL, TImage *AImage, String ASYMB_TYPE)
{
    bool   bResult = false;
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "UPDATE TB_VMS_SYMB_LIB                                    \r\n"
           "   SET RGST_DT   = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS'),  \r\n"
           "       SYMB_EXPL = :p02,                                  \r\n";

if (AImage != NULL)
{
    sQry+= "       IMAG_DATA = :p03,                                  \r\n";
}

if (ASYMB_TYPE != "")
{
    sQry+= "       SYMB_TYPE = :p04,                                  \r\n";
}

    sQry+= "       UPDT_DT   = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS')   \r\n"
           " WHERE SYMBLIB_NMBR = :p01                                \r\n";

	TMemoryStream *dataStream = NULL;
    if (AImage != NULL)
    {
        dataStream = new TMemoryStream();
   	    AImage->Picture->Bitmap->SaveToStream(dataStream);
    }

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

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ASYMB_LIB_NMBR);
            ITSDb_SQLBind(pADO, "p02", ASYMB_EXPL);
            if (AImage != NULL)
            {
        		pADO->Parameters->ParamByName("p03")->LoadFromStream(dataStream, ftBlob);
            }
            if (ASYMB_TYPE != "")
            {
                ITSDb_SQLBind(pADO, "p04", ASYMB_TYPE);
            }
			pADO->ExecSQL();
            bResult = true;
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("UpdateVmsImage", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("UpdateVmsImage", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        if (dataStream) delete dataStream;
        dataStream = NULL;
    }
    return bResult;
}
//---------------------------------------------------------------------------

void __fastcall TFrmLang::UpdateVmsFormImage(String ASYMB_LIB_NMBR, String AOldWidth, String AOldHeight, String ANewWidth, String ANewHeight)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT VMS_FORM_ID               \r\n"
           "  FROM TB_VMS_FORM_OBJECT        \r\n"
           " WHERE SYMBLIB_NMBR = :p01       \r\n"
           " GROUP BY VMS_FORM_ID            \r\n";

    LstVmsFormId->Items->Clear();
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ASYMB_LIB_NMBR);
            ITSDb_SQLOpen(pADO);

            for( ; !pADO->Eof; pADO->Next())
            {
                String VMS_FORM_ID = pADO->FieldByName("VMS_FORM_ID")->AsString;
                LstVmsFormId->Items->Add(VMS_FORM_ID);
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("UpdateVmsFormImage", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("UpdateVmsFormImage", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

    if (LstVmsFormId->Items->Count == 0) return;

    //폼객체 이미지 크기 조정
    UpdateVmsFormImageType(ASYMB_LIB_NMBR, AOldWidth, AOldHeight, ANewWidth, ANewHeight);

    //폼이미지 BLOB 업데이트
    for (int ii = 0; ii < LstVmsFormId->Items->Count; ii++)
    {
        UpdateVmsFormImageBlob(LstVmsFormId->Items->Strings[ii]);
    }
}
//---------------------------------------------------------------------------
void __fastcall TFrmLang::UpdateVmsFormImageType(String ASYMB_LIB_NMBR, String AOldWidth, String AOldHeight, String ANewWidth, String ANewHeight)
{
    if (AOldWidth == ANewWidth && AOldHeight == ANewHeight) return;

    String sQry;
    TADOQuery *pADO = NULL;

#if 0
UPDATE TB_VMS_FORM_OBJECT
   SET VMS_DSPL_WIDTH = 320,
	     VMS_DSPL_HEIGHT = 64
 WHERE (FORM_OBJECT_ID, VMS_FORM_ID)
    IN (SELECT FORM_OBJECT_ID, VMS_FORM_ID
	        FROM TB_VMS_FORM_OBJECT
         WHERE SYMBLIB_NMBR = 6014
           AND (VMS_DSPL_WIDTH <> 320 OR VMS_DSPL_HEIGHT <> 64) )
 #endif

    //기존에 이미지크기를 그래도 사용하는 폼객체인 경우에만 변경된 크기로 업데이트 해준다.
    //이미지 크기가 다르다는 것은 사용자가 이미지를 폼편집에서 수정한 것이라 사용자가 직접
    //수정하여야 한다.
    sQry = "UPDATE TB_VMS_FORM_OBJECT                       \r\n"
           "   SET VMS_DSPL_WIDTH  = :p04,                  \r\n"
           "       VMS_DSPL_HEIGHT = :p05                   \r\n"
           " WHERE (FORM_OBJECT_ID, VMS_FORM_ID)            \r\n"
           "    IN (SELECT FORM_OBJECT_ID, VMS_FORM_ID      \r\n"
           "            FROM TB_VMS_FORM_OBJECT             \r\n"
           "         WHERE SYMBLIB_NMBR    = :p01           \r\n"
           "           AND VMS_DSPL_WIDTH  = :p02           \r\n"
           "           AND VMS_DSPL_HEIGHT = :p03)          \r\n";

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

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", ASYMB_LIB_NMBR);
            ITSDb_SQLBind(pADO, "p02", AOldWidth);
            ITSDb_SQLBind(pADO, "p03", AOldHeight);
            ITSDb_SQLBind(pADO, "p04", ANewWidth);
            ITSDb_SQLBind(pADO, "p05", ANewHeight);
			ITSDb_SQLExec(pADO);

        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("UpdateVmsFormImageType", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("UpdateVmsFormImageType", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TFrmLang::UpdateVmsFormImageBlob(String AVMS_FORM_ID)
{
    if (GetVmsFormImage(ImgForm, AVMS_FORM_ID) == false)
    {
        return;
    }

    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "UPDATE TB_VMS_FORM              \r\n"
           "   SET VMS_FORM_IMAG = :p02     \r\n"
           " WHERE VMS_FORM_ID   = :p01     \r\n";

	TMemoryStream *dataStream = new TMemoryStream();
   	ImgForm->Picture->Bitmap->SaveToStream(dataStream);

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

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", AVMS_FORM_ID);
            pADO->Parameters->ParamByName("p02")->LoadFromStream(dataStream, ftBlob);
            pADO->ExecSQL();

        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("UpdateVmsFormImageBlob", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("UpdateVmsFormImageBlob", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        if (dataStream) delete dataStream;
        dataStream = NULL;
    }
}
//---------------------------------------------------------------------------

bool __fastcall TFrmLang::GetVmsFormImage(TImage *AImage, String AVMS_FORM_ID)
{
    if (FFontInit == false)
    {
        FOR_STL(TCDSFontColor*, pObj, CDSFontManager->FColors)
        {
            m_pEdtDesigner->InitFontColor(pObj->VMS_FONT_COLR_CD, (TColor)pObj->VMS_FONT_COLR_VAL);
        }
        FFontInit = true;
    }

    m_pEdtDesigner->Clear();
    m_pEdtDesigner->EditMode = false;
    m_pEdtDesigner->Hide();

    String sQry;
    TADOQuery *pADO = NULL;

    AImage->Picture->Bitmap->FreeImage();
    AImage->Picture->Bitmap = NULL;

    sQry = "SELECT A.VMS_TYPE_CD, A.VMS_FORM_COLR_CD,           \r\n"
           "       B.VMS_WDTH, B.VMS_HGHT,                      \r\n"
           "       C.*,                                         \r\n"
           "       E.VMS_FONT_NAME_NM,                          \r\n"
           "       D.IMAG_DATA AS SYMB_IMG,                     \r\n"
           "       D.SYMB_EXPL AS SYMB_IMG_NM                   \r\n"
           "  FROM TB_VMS_FORM         A,                       \r\n"
           "         TB_VMS_TYPE         B,                     \r\n"
           "             TB_VMS_FORM_OBJECT  C,                 \r\n"
           "       TB_VMS_SYMB_LIB     D,                       \r\n"
           "       TB_VMS_FONT_NAME    E                        \r\n"
           " WHERE A.VMS_FORM_ID      = :p01                    \r\n"
           "   AND A.VMS_TYPE_CD      = B.VMS_TYPE_CD           \r\n"
           "     AND A.VMS_FORM_ID    = C.VMS_FORM_ID           \r\n"
           "   AND C.SYMBLIB_NMBR     = D.SYMBLIB_NMBR(+)       \r\n"
           "   AND C.VMS_FONT_NAME_CD = E.VMS_FONT_NAME_CD(+)   \r\n"
           " ORDER BY C.FORM_OBJECT_ID ASC                      \r\n";

    int nRows = 0;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", AVMS_FORM_ID);
            ITSDb_SQLOpen(pADO);

            int    nDrawType;
            String sObjKind;
            for( ; !pADO->Eof; pADO->Next())
            {
                if (nRows == 0)
                {
                    m_pEdtDesigner->SizeType    = pADO->FieldByName("VMS_TYPE_CD")->AsString;
                    m_pEdtDesigner->BkColorCode = pADO->FieldByName("VMS_TYPE_CD")->AsString;
                    int nW = pADO->FieldByName("VMS_WDTH")->AsInteger;
                    int nH = pADO->FieldByName("VMS_HGHT")->AsInteger;
                    m_pEdtDesigner->SetSize(nW, nH);
                    m_pEdtDesigner->SetPos(0, 0);
                    AImage->Width = nW;
                    AImage->Height = nH;
                    AImage->Picture->Bitmap->Width = nW;
                    AImage->Picture->Bitmap->Height = nH;
                }
                nRows++;

                int nObjId  = pADO->FieldByName("FORM_OBJECT_ID")->AsInteger;

                int nObjType = pADO->FieldByName("VMS_FORM_OBJECT_TYPE_CD")->AsInteger;
                if (nObjType ==   1 || //이미지 심볼
                    nObjType ==   2 || //파일이미지
                    nObjType ==   3 || //소통정보이미지
                    nObjType ==  17 || //소통이미지1
                    nObjType ==  27 || //소통이미지2
                    nObjType ==  37 || //소통이미지3
                    nObjType ==  47 || //소통이미지4
                    nObjType == 200 || //동영상
                    nObjType == 300 || //스트리밍영상
                    nObjType == 406 || //@통합대기등급 이미지
                    nObjType == 407 || //@미세먼지등급 이미지
                    nObjType == 408 || //@초미세먼지등급 이미지
                    nObjType == 413    //@오존등급이미지
                    )
                {
                    if (nObjType == 3) sObjKind = OBJKIND_IMAGE;
                    else               sObjKind = OBJKIND_IMAGEID;

                    nDrawType = 1;  //이미지그리기
                }
                else
                {
                    sObjKind  = OBJKIND_TEXT;  //문자열
                    nDrawType = 0;  //문자열그리기
                }

                int    nBlinking = pADO->FieldByName("VMS_DSPL_BLINKING")->AsInteger;
                int    nPosX     = pADO->FieldByName("VMS_DSPL_XCRDN")->AsInteger;
                int    nPosY     = pADO->FieldByName("VMS_DSPL_YCRDN")->AsInteger;
                int    nWidth    = pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger;
                int    nHeight   = pADO->FieldByName("VMS_DSPL_HEIGHT")->AsInteger;

                TVmsFormObject *pObj = m_pEdtDesigner->AddObject((VmsObjectDrawType)nDrawType);
                if (!pObj) continue;

                if (nObjType == 200 || nObjType == 300)
                {
                    pObj->EditMode = false;
                }
                String sIfscId  = pADO->FieldByName("VMS_IFSC_ID")->AsString;
                String sFillCd  = pADO->FieldByName("TRFC_FILL_CD")->AsString;

                pObj->ObjSeq      = nObjId;
                pObj->ObjId       = nObjId;
                pObj->ObjKind     = sObjKind;

                pObj->ObjType     = pADO->FieldByName("VMS_FORM_OBJECT_TYPE_CD")->AsString;
                pObj->ObjSize     = pADO->FieldByName("VMS_DSPL_SIZE")->AsInteger;
                pObj->BkColorCode = pADO->FieldByName("VMS_DSPL_BKCOLOR")->AsString;
                pObj->Blink       = nBlinking == 1 ? true : false;

                pObj->ImageId     = pADO->FieldByName("SYMBLIB_NMBR")->AsString;
                pObj->Text        = pADO->FieldByName("VMS_DSPL_TXT")->AsString;
                pObj->RunText     = pObj->Text;

                pObj->SetPos(nPosX, nPosY);
                if (pObj->ObjKind == OBJKIND_TEXT)    // 문자열
                {
                    int nFontBold       = pADO->FieldByName("VMS_FONT_BOLD")->AsInteger;

                    pObj->FontName      = pADO->FieldByName("VMS_FONT_NAME_NM")->AsString;
                    pObj->FontNameCode  = pADO->FieldByName("VMS_FONT_NAME_CD")->AsString;
                    pObj->FontColorCode = pADO->FieldByName("VMS_FONT_COLR_CD")->AsString;
                    pObj->FontSize      = pADO->FieldByName("VMS_FONT_SIZE")->AsInteger;
                    pObj->FontBold      = nFontBold == 1 ? true : false;
                    pObj->TextAlign     = pADO->FieldByName("VMS_FONT_ALIGN")->AsInteger;
                    //pObj->SetPos(nPosX, nPosY);
                    //pObj->SetSize(pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger, pADO->FieldByName("VMS_DSPL_HEIGHT")->AsInteger);
                }
                else //if (sObjKind == "1" || sObjKind == "2")    // 이미지(1), 이미지 ID(2)
                {
                    if (pObj->ObjKind == OBJKIND_IMAGEID)
                    {
                        if (pObj->Text.Trim() == "")
                        {
                            pObj->Text = pObj->ImageId;
                        }
                    }

                    TStream *pStream = NULL;
                    pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_FIGR"), bmRead);

                    try
                    {
                        if (pStream && pStream->Size > 0)
                        {
                            Graphics::TBitmap *Bitmap = pObj->GetBitmap();
                            pStream->Position = 0;
                            Bitmap->LoadFromStream(pStream);

#ifdef IMAGE_RESIZE
#if 0
                            if (nObjType == 1 || nObjType == 2)
                            {
                                pObj->GetImage()->AutoSize= false;
                                pObj->GetImage()->Stretch = true;
                                pObj->GetImage()->Width  = nWidth;
                                pObj->GetImage()->Height = nHeight;
                                pObj->SetSize(nWidth, nHeight);
                                pObj->SetPos(nPosX, nPosY);
                            }
                            else
                            {
                                pObj->SetSize(Bitmap->Width, Bitmap->Height);
                            }
#else
                            switch(nObjType)
                            {
                            case   1: //심볼
                            case   2: //이미지
                            case   3: //소통정보배경이미지
                            case  17: //소통정보이미지1
                            case  27: //소통정보이미지2
                            case  37: //소통정보이미지3
                            case  47: //소통정보이미지4
                            case 167: //@우회소통정보이미지
                            case 200: //동영상이미지
                            case 300: //스트리밍영상이미지
                            case 406: //@통합대기등급 이미지
                            case 407: //@미세먼지등급 이미지
                            case 408: //@초미세먼지등급 이미지
                            case 413: //@오존등급이미지
                                pObj->GetImage()->AutoSize= false;
                                pObj->GetImage()->Stretch = true;
                                pObj->GetImage()->Width  = nWidth;
                                pObj->GetImage()->Height = nHeight;
                                pObj->SetSize(nWidth, nHeight);
                                pObj->SetPos(nPosX, nPosY);
                                break;
                            default:
                                pObj->SetSize(Bitmap->Width, Bitmap->Height);
                                pObj->SetPos(nPosX, nPosY); //TODO
                                break;
                            }
#endif
#else
                            pObj->SetSize(Bitmap->Width, Bitmap->Height);
                            pObj->SetPos(nPosX, nPosY);
#endif
                        }
                    }
                    __finally
                    {
                        SAFE_DELETE(pStream);
                    }
                }

                //pObj->SetPos(nPosX, nPosY);
                //if (pObj->Left < 0) pObj->Left = 0;
                //if (pObj->Top  < 0) pObj->Top  = 0;
                pObj->Show();
                pObj->BringToFront();
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("UpdateVmsFormImageBlob", String(E.ClassName()), E.Message, sQry);
            return false;
            //throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("UpdateVmsFormImageBlob", String(e.ClassName()), e.Message, sQry);
            return false;
            //throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    m_pEdtDesigner->GetVmsFormImage(AImage);

    return nRows > 0 ? true : false;
}
//---------------------------------------------------------------------------

