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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "AppGlobalF.h"
#include "CDSVmsIfscF.h"
#include "ITSLangTransF.h"
#include "CDSFontF.h"
#pragma hdrstop

#include "VMSM610MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalendar"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxDropDownEdit"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxMaskEdit"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxTextEdit"
#pragma link "cxTimeEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#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 "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxRadioGroup"
#pragma link "cxClasses"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxDBData"
#pragma link "cxFilter"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridDBTableView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxStyles"
#pragma link "cxCheckBox"
#pragma link "cxImage"
#pragma link "cxButtonEdit"
#pragma link "cxBlobEdit"
#pragma link "VmsDesignerF"
#pragma link "cxColorComboBox"
#pragma link "cxCalc"
#pragma resource "*.dfm"

TVMSM610M *VMSM610M = NULL;
//---------------------------------------------------------------------------

__fastcall TVMSM610M::TVMSM610M(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    //CMM_LoadForm(g_sFormsDir, this);

    FSelected = false;
    FUpdate= false;
    FTitle = Caption;//"VMS 교통상황 폼 관리";
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::CommClose()
{
    try
    {
        if (m_pEdtDesigner)
        {
            delete m_pEdtDesigner;
            m_pEdtDesigner = NULL;
        }

        //CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::FormCreate(TObject *Sender)
{
    m_pEdtDesigner = new TVmsFormDesigner(PnlEditForm);
    FOR_STL(TCDSFontColor*, pObj, CDSFontManager->FColors)
    {
        m_pEdtDesigner->InitFontColor(pObj->VMS_FONT_COLR_CD, (TColor)pObj->VMS_FONT_COLR_VAL);
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::FormShow(TObject *Sender)
{
    Refresh();

    FormInit();

    PnlEdtBack->Width = FVmsWidth+4;
    PnlEdtBack->Height= FVmsHeight+4;

    LoadVmsIfsc(FVmsNmbr);

    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::FormInit()
{
    //TvObjList->OptionsView->NoDataToDisplayInfoText = "<등록되어 있는 객체 정보가 없습니다>";

    m_pEdtDesigner->ApplicationHandle = (long)Handle;

    FNewDb = false;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::LoadVmsIfsc(String AVmsNmbr)
{
    CMM_ClearGridTableView(TvAxis);

    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT C.VMS_CTLR_NMBR, C.VMS_CTLR_ID, C.VMS_NM,     \r\n"
           "       A.VMS_IFSC_ID, A.VMS_IFSC_NM,                 \r\n"
           "       A.DSPL_STRT_NODE_NM, A.DSPL_END_NODE_NM,      \r\n"
           "       A.AXIS_YN                                     \r\n"
           "  FROM TB_VMS_IFSC      A,                           \r\n"
           "       TB_VMS_RLTN_IFSC B,                           \r\n"
           "       (SELECT VMS_CTLR_NMBR,                        \r\n"
           "               VMS_CTLR_ID,                          \r\n"
           "               VMS_NM                                \r\n"
           "          FROM TB_VMS_CTLR                           \r\n"
           "         WHERE VMS_CTLR_NMBR = :p01) C               \r\n"
           " WHERE A.USE_YN        = 'Y'                         \r\n"
           "   AND A.VMS_IFSC_ID   = B.VMS_IFSC_ID               \r\n"
           "   AND B.VMS_CTLR_NMBR = C.VMS_CTLR_NMBR             \r\n";

    try
    {
        int nRow;
        TcxDataController *pGDC = TvAxis->DataController;
        TvAxis->BeginUpdate();
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

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

            for( ; !pADO->Eof; pADO->Next())
            {
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][Col00->Index] = pADO->FieldByName("VMS_CTLR_ID")->AsString;
                pGDC->Values[nRow][Col01->Index] = pADO->FieldByName("VMS_IFSC_ID")->AsString;
                pGDC->Values[nRow][Col02->Index] = pADO->FieldByName("VMS_IFSC_NM")->AsString;
                pGDC->Values[nRow][Col03->Index] = pADO->FieldByName("DSPL_STRT_NODE_NM")->AsString;
                pGDC->Values[nRow][Col04->Index] = pADO->FieldByName("DSPL_END_NODE_NM")->AsString;
                pGDC->Values[nRow][Col05->Index] = pADO->FieldByName("AXIS_YN")->AsString;
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("VMS Sect Query", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            DBERRORMSG("VMS Sect Query", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        TvAxis->EndUpdate();
        CMM_ExpandCollapseChk(TvAxis, true);
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
    BtnSearchClick(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::BtnSearchClick(TObject *Sender)
{
    RefreshData();

    EdFocus->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::RefreshData()
{
    // 검색조건에 의한 링크 데이터 조회
    FormClear();

    m_pEdtDesigner->Clear();
    m_pEdtDesigner->SizeType = FVmsTypeCd;
    m_pEdtDesigner->SetSize(FVmsWidth, FVmsHeight);
    m_pEdtDesigner->SetPos(0, 0);
    m_pEdtDesigner->BkColorCode = FFormColor;

    m_pEdtDesigner->EditMode = true;
    m_pEdtDesigner->Show();

    InitObjectList();

    LoadFormObjectInfo(FFormId, m_pEdtDesigner);

    DispObjectListData();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::AddTrafficTypeObject(int ARow, String AIfscId)
{
    TVmsIfsc *pObj;
    TcxGridDataController *pGDC = TvObjList->DataController;

    pGDC->Values[ARow][ColIfscId->Index] = AIfscId;
    //pObj = VmsIfscManager->FLists.Find(FIfscId[0].ToIntDef(0));
    pObj = VmsIfscManager->FLists.Find(AIfscId.ToIntDef(0));
    if (!pObj) return;
    pGDC->Values[ARow][ColIfscNm->Index]  = pObj->VMS_IFSC_NM;
    pGDC->Values[ARow][ColIfscStr->Index] = pObj->DSPL_STRT_NODE_NM;
    pGDC->Values[ARow][ColIfscEnd->Index] = pObj->DSPL_END_NODE_NM;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::InitObjectList()
{
    CMM_ClearGridTableView(TvObjList);
    TcxGridDataController *pGDC = TvObjList->DataController;

    ColObj03->Visible = false;
    ColObj04->Visible = false;
    try
    {
        TvObjList->BeginUpdate();
        pGDC->BeginUpdate();

        int nRow;
        switch(FFormType)
        {
        case 11:// '	소통상황(1단)
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "11";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm11->Caption;//"1Row Traffic";//"1단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[0]);
            break;
        case 12:// '	소통상황(2단)
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "11";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm11->Caption;//"1Row Traffic";//"1단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[0]);
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "12";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm12->Caption;//"2Row Traffic";//"2단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[1]);
            break;
        case 13:// '	소통상황(3단)
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "11";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm11->Caption;//"1Row Traffic";//"1단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[0]);
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "12";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm12->Caption;//"2Row Traffic";//"2단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[1]);
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "13";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm13->Caption;//"3Row Traffic";//"3단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[2]);
            break;
        case 14:// '	소통상황(4단)
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "11";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm11->Caption;//"1Row Traffic";//"1단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[0]);
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "12";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm12->Caption;//"2Row Traffic";//"2단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[1]);
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "13";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm13->Caption;//""3Row Traffic";//"3단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[2]);
            nRow = pGDC->AppendRecord();
            pGDC->Values[nRow][ColObj01->Index] = "14";
            pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblForm14->Caption;//""4Row Traffic";//"4단 소통정보";
            pGDC->Values[nRow][ColObjType->Index] = "Form";
            AddTrafficTypeObject(nRow, FIfscId[2]);
            break;
        case 15:// '	소통상황(도형식)
            ColObj03->Visible = true;
            break;
        default:
            break;
        }
    }
    __finally
    {
        pGDC->EndUpdate();
        TvObjList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::DispObjectListData()
{
    TcxGridDataController *pGDC = TvObjList->DataController;
    int nRow;

    TVmsFormObject *pObj;
    int nObjCnt = m_pEdtDesigner->GetObjectCount();
    for(int ii = 0; ii < nObjCnt; ii++)
    {
        pObj = m_pEdtDesigner->GetObject(ii);
        if (pObj)
        {
            switch(pObj->ObjType.ToIntDef(0))
            {
            case 91: //@축통행시간(고정)
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = "15";
                pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblFill91->Caption;//"AxisTravelTime";//"축통행시간(고정)";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                AddTrafficTypeObject(nRow, pObj->Tag);
                break;
            case 92: //@축소통상황(고정)
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = "15";
                pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblFill92->Caption;//"Traffic(Fix)";//"소통상황(고정)";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                AddTrafficTypeObject(nRow, pObj->Tag);
                break;

#if 0
            case 17: //@소통정보이미지1
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = String(FFormType);//"17";
                pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblFill17->Caption;//"TrafficImage";//"소통정보이미지";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "17";
                AddTrafficTypeObject(nRow, FIfscId[4]);
                break;
            case 27: //@소통정보이미지2
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = String(FFormType);//"27";
                pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblFill27->Caption;//"TrafficImage2";//"소통정보이미지2";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "27";
                AddTrafficTypeObject(nRow, FIfscId[5]);
                break;
            case 37: //@소통정보이미지3
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = String(FFormType);//"37";
                pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblFill37->Caption;//"TrafficImage3";//"소통정보이미지3";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "37";
                AddTrafficTypeObject(nRow, FIfscId[6]);
                break;
            case 47: //@소통정보이미지4
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = String(FFormType);//"47";
                pGDC->Values[nRow][ColObj02->Index] = FrmLang->lblFill47->Caption;//"TrafficImage4";//"소통정보이미지4";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "47";
                AddTrafficTypeObject(nRow, FIfscId[7]);
                break;
#endif
            }
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::BtnClosexClick(TObject *Sender)
{
    FSelected = false;
    Close();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::FormClose(TObject *Sender, TCloseAction &Action)
{
    CommClose();
    VMSM610M = NULL;
    //Action = caFree;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::LoadFormObjectInfo(String AFormId, TVmsFormDesigner *ADesigner)
{
    ADesigner->Clear();

    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*,                                       \r\n"
           "       C.VMS_FONT_NAME_NM,                        \r\n"
           "       B.IMAG_DATA AS SYMB_IMG,                   \r\n"
           "       B.SYMB_EXPL AS SYMB_IMG_NM,                \r\n"
           "       D.VMS_FORM_TYPE_CD                         \r\n"
           "  FROM TB_VMS_FORM_OBJECT  A,                     \r\n"
           "       TB_VMS_SYMB_LIB     B,                     \r\n"
           "       TB_VMS_FONT_NAME    C,                     \r\n"
           "       TB_VMS_FORM         D                      \r\n"
           " WHERE D.VMS_FORM_ID      = :p01                  \r\n"
           "   AND D.VMS_FORM_ID      = A.VMS_FORM_ID         \r\n"
           "   AND A.SYMB_LIB_NMBR    = B.SYMB_LIB_NMBR(+)    \r\n"
           "   AND A.VMS_FONT_NAME_CD = C.VMS_FONT_NAME_CD(+) \r\n"
           " ORDER BY A.VMS_FORM_OBJECT_ID ASC                \r\n";

    int VMS_FORM_TYPE_CD = -1;

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

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

            int    nDrawType;
            String sObjKind;
            for( ; !pADO->Eof; pADO->Next())
            {
                VMS_FORM_TYPE_CD = pADO->FieldByName("VMS_FORM_TYPE_CD")->AsInteger;
                int nFormId = pADO->FieldByName("VMS_FORM_ID")->AsInteger;
                int nObjId  = pADO->FieldByName("VMS_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(2열)
                    nObjType ==  37 || //@소통정보이미지3(3열)
                    nObjType ==  47 || //@소통정보이미지4(3열)
                    nObjType == 200 || //동영상
                    nObjType == 300 || //스트리밍영상
                    nObjType == 406 || //@통합대기등급 이미지
                    nObjType == 407 || //@미세먼지등급 이미지
                    nObjType == 408 || //@초미세먼지등급 이미지
                    nObjType == 413    //@오존등급이미지
                    )
                {
                    if (nObjType == 1) sObjKind = OBJKIND_IMAGEID;    //Image Id
                    else               sObjKind = OBJKIND_IMAGE;      //Image

                    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    nDsplW    = pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger;
                int    nDsplH    = pADO->FieldByName("VMS_DSPL_HEIGHT")->AsInteger;

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

//11	, '	@구간명
//12	, '	@시점명
//13	, '	@종점명
//14	, '	@소통상황
//15	, '	@통행시간
//16	, '	@통행속도
//17	, '	@방향
                pObj->Text = pADO->FieldByName("VMS_DSPL_TXT")->AsString.Trim();
                pObj->RunText = pObj->Text;

                String sIfscId = "";
                if (nObjType >= 11 && nObjType < 17)
                    sIfscId = FIfscId[0];
                else
                if (nObjType >= 21 && nObjType < 27)
                    sIfscId = FIfscId[1];
                else
                if (nObjType >= 31 && nObjType < 37)
                    sIfscId = FIfscId[2];
                else
                if (nObjType >= 41 && nObjType < 47)
                    sIfscId = FIfscId[3];

                switch(nObjType)
                {
                case 17: sIfscId = FIfscId[4]; break;
                case 27: sIfscId = FIfscId[5]; break;
                case 37: sIfscId = FIfscId[6]; break;
                case 47: sIfscId = FIfscId[7]; break;
                }

                if (sIfscId != "")
                {
                    TVmsIfsc *pIfscObj;
                    pIfscObj = VmsIfscManager->FLists.Find(sIfscId.ToIntDef(0));
                    if (pIfscObj)
                    {
                        switch(nObjType)
                        {
                        case 11: case 21: case 31: case 41:
                            pObj->RunText = pIfscObj->VMS_IFSC_NM;
                            break;
                        case 12: case 22: case 32: case 42:
                            pObj->RunText = pIfscObj->DSPL_STRT_NODE_NM;
                            break;
                        case 13: case 23: case 33: case 43:
                            pObj->RunText = pIfscObj->DSPL_END_NODE_NM;
                            break;
                        }
                    }
                }

                if (nObjType == 200 || nObjType == 300)
                {
                    pObj->EditMode = false;
                }
                pObj->ObjSeq      = nObjId;
                pObj->ObjId       = nObjId;
                pObj->ObjKind     = sObjKind;
                pObj->Tag         = pADO->FieldByName("VMS_IFSC_ID")->AsString;
                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("SYMB_LIB_NMBR")->AsString;

                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->SetSize(pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger, pADO->FieldByName("VMS_DSPL_HEIGHT")->AsInteger);
                    //pObj->SetPos(nPosX, nPosY);
                    pObj->SetRuntimeText(pObj->RunText);

#if 0
                    Label1->AutoSize   = true;
                    Label1->Font->Name = pObj->FontName;
                    Label1->Font->Size = pObj->FontSize;
                    Label1->Caption    = pObj->RunText;

                    if (pObj->FontBold)
                        Label1->Font->Style = TFontStyles() << fsBold;
                    else
                        Label1->Font->Style = TFontStyles();

                    //int nWidth = pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger;
                    //nWidth = Lavel1->Width;

#if 0
                    switch(pObj->TextAlign)
                    {
                    case 0://text_align_left:
                        //좌측정력인 경우 위치조정 필요 없음.
                        break;
                    case 1://text_align_right:
                        //좌측에서 글자길이를 뺀다음 만약 음수이면 0으로 설정
                        //pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger
                        nPosX = (nPosX+pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger) - Label1->Width;
                        break;
                    case 2://text_align_center:
                        //원래 글자의 중앙값을 얻은 다음에 조정된 글자의 1/2 크기를 뺀다음 음수이면 0으로 설정
                        nPosX = (nPosX+(pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger/2)) - (Label1->Width/2);
                        break;
                    }
                    if (nPosX < 0) nPosX = 0;
                    //AVmsObj->TextWidth = pLabel->Width;
#endif

                    pObj->SetSize(Label1->Width, pADO->FieldByName("VMS_DSPL_HEIGHT")->AsInteger);
#endif
                }
                else //if (sObjKind == "1" || sObjKind == "2")    // 이미지(1), 이미지 ID(2)
                {
                    if (pObj->ObjKind == OBJKIND_IMAGEID)
                    {
                        pObj->Text = pADO->FieldByName("SYMB_LIB_NMBR")->AsString;
                    }

                    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);

                            pObj->GetImage()->AutoSize= false;
                            pObj->GetImage()->Stretch = true;
                            pObj->GetImage()->Width  = nDsplW;
                            pObj->GetImage()->Height = nDsplH;
                            pObj->SetSize(nDsplW, nDsplH);
                            pObj->SetPos(nPosX, nPosY);
                            //pObj->SetSize(Bitmap->Width, Bitmap->Height);
                        }
                    }
                    __finally
                    {
                        SAFE_DELETE(pStream);
                    }
                }

                //pObj->SetPos(nPosX, nPosY);
                pObj->Show();
                pObj->BringToFront();
            }

            if (VMS_FORM_TYPE_CD == eFormTp_traf_1)
            {
                TVmsFormObject *pArw = NULL;
                TVmsFormObject *pStr = NULL;
                TVmsFormObject *pEnd = NULL;
                int nObjCnt = ADesigner->GetObjectCount();

                for(int ii = 0; ii < nObjCnt; ii++)
                {
                    TVmsFormObject *pObj = ADesigner->GetObject(ii);
                    if (!pObj) continue;

                    int nObjType = pObj->ObjType.ToIntDef(0);
                    switch(nObjType)
                    {
                    case 12:    //	@시점명	            Y
                        pStr = pObj;
                        break;
                    case 13:    //	@종점명	            Y
                        pEnd = pObj;
                        break;
                    }
                }

                for(int ii = 0; ii < nObjCnt; ii++)
                {
                    TVmsFormObject *pObj = ADesigner->GetObject(ii);
                    if (!pObj) continue;

                    int nObjType = pObj->ObjType.ToIntDef(0);
                    switch(nObjType)
                    {
                    case  1:    //	@심볼	            Y
                    case  2:    //	@이미지	            Y
                    case 17:    //	@소통정보이미지      Y
                        //if (pFormObj->TRFC_FILL_CD == "T")
                        if (pStr && pObj->Top <= (pStr->Top+pStr->Height) )
                        {
                            pArw = pObj;
                        }
                        break;
                    }
                }

                if (pArw && pStr && pEnd)
                {
                    int nRange = pStr->Top + pStr->Height;
                    if (pArw->Top <= nRange && pEnd->Top <= nRange)
                    {
                        int ARRAWGAP =  5;
                        int nLeft = 0;
                        int nTotW = pStr->Width + ARRAWGAP +
                                    pArw->Width + ARRAWGAP +
                                    pEnd->Width;

                        if (nTotW < ADesigner->Width)
                        {
                            nLeft = (ADesigner->Width - nTotW) / 2;
                        }

                        nLeft = (ADesigner->Width - nTotW) / 2;

                        pStr->Left = nLeft;
                        pArw->Left = pStr->Left + pStr->Width + ARRAWGAP;
                        pEnd->Left = pArw->Left + pArw->Width + ARRAWGAP;
                    }
                }
            }

        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TVMSM610M::LoadFormObjectInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            DBERRORMSG("TVMSM610M::LoadFormObjectInfo", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::FormClear()
{
    FSelIdx = -1;

    EdFormId->Clear();
    EdObjId->Clear();

    FNewDb = false;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::TvObjListFocusedRecordChanged(TcxCustomGridTableView *Sender,
          TcxCustomGridRecord *APrevFocusedRecord, TcxCustomGridRecord *AFocusedRecord,
          bool ANewItemRecordFocusingChanged)
{
    if (TvObjList->ViewData->RecordCount <= 0) return;
    if (TvObjList->DataController->FocusedRowIndex < 0) return;

    m_pEdtDesigner->SelectedObjectAll(false);

    TcxDataController *pGDC = TvObjList->DataController;
    int nIndex = pGDC->FocusedRecordIndex;

    String sObjType  = pGDC->Values[nIndex][ColObjType->Index];
    String sFormType = pGDC->Values[nIndex][ColObj01->Index];
    int    nFormType = sFormType.ToIntDef(0);
    if (nFormType == 11 || nFormType == 12 || nFormType == 13 || nFormType == 14)
    {
        BtnListAdd->Enabled = true;
        BtnListDelete->Enabled = true;
    }
    else
    {
        BtnListAdd->Enabled = true;
        BtnListDelete->Enabled = true;
    }
    if (nFormType == 15)    //도형식 배경소통정보 폼
    {
        int nObjSeq = VarToStr(pGDC->Values[nIndex][ColObj03->Index]).ToIntDef(0);
        m_pEdtDesigner->SelectObject(nObjSeq);
        return;
    }

    TVmsFormObject *pObj;
    int nObjCnt = m_pEdtDesigner->GetObjectCount();
    for(int ii = 0; ii < nObjCnt; ii++)
    {
        pObj = m_pEdtDesigner->GetObject(ii);
        if (!pObj) continue;

        int nObjType = pObj->ObjType.ToIntDef(0);
/*
        switch(sObjType.ToIntDef(-1))
        {
        case 17:
        case 27:
        case 37:
        case 47:
            if (sObjType.ToIntDef(-1) == nObjType)
            {
                m_pEdtDesigner->SelectObject(pObj->ObjSeq, true);
            }
            break;
        default:
*/
            switch(nFormType)
            {
            case 11:// '	소통상황(1단)
                //@구간명, @시점명, @종점명
                if (nObjType >= 11 && nObjType <= 17)
                {
                    m_pEdtDesigner->SelectObject(pObj->ObjSeq, true);
                }
                break;
            case 12:// '	소통상황(2단)
                if (nObjType >= 21 && nObjType <= 27)
                {
                    m_pEdtDesigner->SelectObject(pObj->ObjSeq, true);
                }
                break;
            case 13:// '	소통상황(3단)
                if (nObjType >= 31 && nObjType <= 37)
                {
                    m_pEdtDesigner->SelectObject(pObj->ObjSeq, true);
                }
                break;
            case 14:// '	소통상황(4단)
                if (nObjType >= 41 && nObjType <= 47)
                {
                    m_pEdtDesigner->SelectObject(pObj->ObjSeq, true);
                }
                break;
            default:
                break;
            }
/*
        }
*/
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::BtnListAddClick(TObject *Sender)
{
    int nCellIdx = CMM_GetRecordIndex(TvObjList);
    if (nCellIdx < 0) return;

    int nIfscIdx = CMM_GetRecordIndex(TvAxis);
    if (nIfscIdx < 0) return;

    TcxGridDataController *pDcCell = TvObjList->DataController;
    TcxGridDataController *pDcIfsc = TvAxis->DataController;

    pDcCell->Values[nCellIdx][ColIfscId->Index]  = pDcIfsc->Values[nIfscIdx][Col01->Index];
    pDcCell->Values[nCellIdx][ColIfscNm->Index]  = pDcIfsc->Values[nIfscIdx][Col02->Index];
    pDcCell->Values[nCellIdx][ColIfscStr->Index] = pDcIfsc->Values[nIfscIdx][Col03->Index];
    pDcCell->Values[nCellIdx][ColIfscEnd->Index] = pDcIfsc->Values[nIfscIdx][Col04->Index];

    TVmsFormObject *pObj;
    int nObjCnt = m_pEdtDesigner->GetObjectCount();
    for(int ii = 0; ii < nObjCnt; ii++)
    {
        pObj = m_pEdtDesigner->GetObject(ii);
        if (!pObj) continue;

        if (!pObj->Selected) continue;

        int nObjType = pObj->ObjType.ToIntDef(0);
        switch(nObjType)
        {
        case 11: case 21: case 31: case 41:
            pObj->RunText = VarToStr(pDcCell->Values[nCellIdx][ColIfscNm->Index]);
            pObj->SetRuntimeText(pObj->RunText);
            break;
        case 12: case 22: case 32: case 42:
            pObj->RunText = VarToStr(pDcCell->Values[nCellIdx][ColIfscStr->Index]);
            pObj->SetRuntimeText(pObj->RunText);
            break;
        case 13: case 23: case 33: case 43:
            pObj->RunText = VarToStr(pDcCell->Values[nCellIdx][ColIfscEnd->Index]);
            pObj->SetRuntimeText(pObj->RunText);
            break;
        }
    }

    if (FFormType == eFormTp_traf_1)
    {
        TVmsFormObject *pArw = NULL;
        TVmsFormObject *pStr = NULL;
        TVmsFormObject *pEnd = NULL;
        int nObjCnt = m_pEdtDesigner->GetObjectCount();

        for(int ii = 0; ii < nObjCnt; ii++)
        {
            TVmsFormObject *pObj = m_pEdtDesigner->GetObject(ii);
            if (!pObj) continue;

            int nObjType = pObj->ObjType.ToIntDef(0);
            switch(nObjType)
            {
            case 12:    //	@시점명	            Y
                pStr = pObj;
                break;
            case 13:    //	@종점명	            Y
                pEnd = pObj;
                break;
            }
        }

        for(int ii = 0; ii < nObjCnt; ii++)
        {
            TVmsFormObject *pObj = m_pEdtDesigner->GetObject(ii);
            if (!pObj) continue;

            int nObjType = pObj->ObjType.ToIntDef(0);
            switch(nObjType)
            {
            case  1:    //	@심볼	            Y
            case  2:    //	@이미지	            Y
            case 17:    //	@소통정보이미지      Y
                //if (pFormObj->TRFC_FILL_CD == "T")
                if (pStr && pObj->Top <= (pStr->Top+pStr->Height) )
                {
                    pArw = pObj;
                }
                break;
            }
        }

        if (pArw && pStr && pEnd)
        {
            int nRange = pStr->Top + pStr->Height;
            if (pArw->Top <= nRange && pEnd->Top <= nRange)
            {
                int ARRAWGAP =  5;
                int nLeft = 0;
                int nTotW = pStr->Width + ARRAWGAP +
                            pArw->Width + ARRAWGAP +
                            pEnd->Width;

                if (nTotW < m_pEdtDesigner->Width)
                {
                    nLeft = (m_pEdtDesigner->Width - nTotW) / 2;
                }

                nLeft = (m_pEdtDesigner->Width - nTotW) / 2;

                pStr->Left = nLeft;
                pArw->Left = pStr->Left + pStr->Width + ARRAWGAP;
                pEnd->Left = pArw->Left + pArw->Width + ARRAWGAP;
            }
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::BtnListDeleteClick(TObject *Sender)
{
    int nCellIdx = CMM_GetRecordIndex(TvObjList);
    if (nCellIdx < 0) return;

    TcxGridDataController *pDcCell = TvObjList->DataController;

    pDcCell->Values[nCellIdx][ColIfscId->Index]  = "";
    pDcCell->Values[nCellIdx][ColIfscNm->Index]  = "";
    pDcCell->Values[nCellIdx][ColIfscStr->Index] = "";
    pDcCell->Values[nCellIdx][ColIfscEnd->Index] = "";

    TVmsFormObject *pObj;
    int nObjCnt = m_pEdtDesigner->GetObjectCount();
    for(int ii = 0; ii < nObjCnt; ii++)
    {
        pObj = m_pEdtDesigner->GetObject(ii);
        if (!pObj) continue;

        if (!pObj->Selected) continue;

        int nObjType = pObj->ObjType.ToIntDef(0);
        switch(nObjType)
        {
        case 11: case 21: case 31: case 41:
            pObj->SetRuntimeText(pObj->Text);
            break;
        case 12: case 22: case 32: case 42:
            pObj->SetRuntimeText(pObj->Text);
            break;
        case 13: case 23: case 33: case 43:
            pObj->SetRuntimeText(pObj->Text);
            break;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::BtnSaveClick(TObject *Sender)
{
    TcxDataController *pGDC = TvObjList->DataController;

    try
    {
        TvObjList->BeginUpdate();
        pGDC->BeginUpdate();
        int nRows = pGDC->RecordCount;

        try
        {
            for (int ii = 0; ii < nRows; ii++)
            {
                int nObjType  = VarToStr(pGDC->Values[ii][ColObjType->Index]).ToIntDef(-1);
                int nFormType = VarToStr(pGDC->Values[ii][ColObj01->Index]).ToIntDef(0);

                String sIfscId = VarToStr(pGDC->Values[ii][ColIfscId->Index]);

/*
                switch(nObjType)
                {
                case 17: FIfscId[4] = sIfscId; break;
                case 27: FIfscId[5] = sIfscId; break;
                case 37: FIfscId[6] = sIfscId; break;
                case 47: FIfscId[7] = sIfscId; break;
                default:
*/
                    switch(nFormType)
                    {
                    case 11: FIfscId[0] = sIfscId; break; // '	소통상황(1단)
                    case 12: FIfscId[1] = sIfscId; break; // '	소통상황(2단)
                    case 13: FIfscId[2] = sIfscId; break; // '	소통상황(3단)
                    case 14: FIfscId[3] = sIfscId; break; // '	소통상황(4단)
                    }
                    //break;
/*
                }
*/
            }
        }
        catch(Exception &e)
        {
        }
    }
    __finally
    {
        pGDC->EndUpdate();
        TvObjList->EndUpdate();
    }

    m_pEdtDesigner->GetVmsFormImage(ImgForm);
    FSelected = true;
    Close();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM610M::Col05CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    int nRecordIdx = AViewInfo->GridRecord->RecordIndex;
    if (nRecordIdx < 0)
    {
        return;
    }

    try
    {
        int nItemIdx = AViewInfo->Item->Index;
    	if (VarIsNull(AViewInfo->GridRecord->DisplayTexts[nItemIdx])) return;

        String sData = AViewInfo->GridRecord->DisplayTexts[nItemIdx];
        if (sData == "Y")
        {
            ACanvas->Canvas->Brush->Color = clLime;
        }
    }
    catch(Exception &e)
    {
    }
}
//---------------------------------------------------------------------------

