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

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

#include "VMSM640MF.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"

TVMSM640M *VMSM640M = NULL;
//---------------------------------------------------------------------------

__fastcall TVMSM640M::TVMSM640M(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 TVMSM640M::CommClose()
{
    try
    {
        if (m_pEdtDesigner)
        {
            delete m_pEdtDesigner;
            m_pEdtDesigner = NULL;
        }

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

void __fastcall TVMSM640M::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 TVMSM640M::FormShow(TObject *Sender)
{
    Refresh();

    FormInit();

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

    LoadAtmpInfo();

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

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

    m_pEdtDesigner->ApplicationHandle = (long)Handle;

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

void __fastcall TVMSM640M::LoadAtmpInfo()
{
    CMM_ClearGridTableView(TvAxis);

    try
    {
        int nRow;
        TcxDataController *pGDC = TvAxis->DataController;
        TvAxis->BeginUpdate();
        try
        {
            FOR_STL(TCDSAtmp*, pObj, CDSAtmpManager->FLists)
            {
                if (pObj->DEL_YN != "N") continue;

                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][Col01->Index] = pObj->ATMP_STTN_NMBR;
                pGDC->Values[nRow][Col02->Index] = pObj->ATMP_STTN_NM;
                pGDC->Values[nRow][Col03->Index] = pObj->VMS_DISP_NM;
                pGDC->Values[nRow][Col04->Index] = pObj->ATMP_STTN_ADDR;
            }
        }
        catch(Exception &e)
        {
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        TvAxis->EndUpdate();
        CMM_ExpandCollapseChk(TvAxis, true);
    }
}
//---------------------------------------------------------------------------

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

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

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

void __fastcall TVMSM640M::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 TVMSM640M::AddTrafficTypeObject(int ARow, String AIfscId)
{
    TcxGridDataController *pGDC = TvObjList->DataController;

    pGDC->Values[ARow][ColIfscId->Index] = AIfscId;

    TCDSAtmp *pObj = CDSAtmpManager->FLists.Find(AIfscId);
    if (!pObj) return;

    pGDC->Values[ARow][ColIfscNm->Index]  = pObj->VMS_DISP_NM;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM640M::InitObjectList()
{
    CMM_ClearGridTableView(TvObjList);
}
//---------------------------------------------------------------------------

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

    String sAtmpId = FIfscId[0];
    String sAtmpNm = "";

    TCDSAtmp *pAtmpObj = CDSAtmpManager->FLists.Find(sAtmpId);
    if (pAtmpObj)
    {
        sAtmpNm = pAtmpObj->VMS_DISP_NM;
    }

    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 401: //	@관측장소	Y	AAAe5oAAHAAASmcAAA
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@관측장소";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "401";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 402: //	@PM10	Y	AAAe5oAAHAAASmcAAB
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@M10";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 403: //	@PM2.5	Y	AAAe5oAAHAAASmcAAC
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@PM2.5";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 404: //	@PM10등급	Y	AAAe5oAAHAAASmcAAD
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@PM10등급";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 405: //	@PM2.5등급	Y	AAAe5oAAHAAASmcAAE
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@PM2.5등급";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 406: //	@통합대기등급 이미지	Y
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@통합대기등급 이미지";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                break;
            case 407: //	@미세먼지등급 이미지	Y
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@미세먼지등급 이미지";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 408: //	@초미세먼지등급 이미지	Y
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@초미세먼지등급 이미지";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 413: //	@오존등급 이미지	Y
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@오존등급 이미지";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 409: // @통합대기등급
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@통합대기등급";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 410: // @통합대기
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@통합대기";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 411: // @오존
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@오존";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            case 412: // @오존등급
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColObj01->Index] = pObj->ObjType;
                pGDC->Values[nRow][ColObj02->Index] = "@오존등급";
                pGDC->Values[nRow][ColObj03->Index] = String(pObj->ObjSeq);
                pGDC->Values[nRow][ColObjType->Index] = "x";
                pGDC->Values[nRow][ColIfscId->Index] = sAtmpId;
                pGDC->Values[nRow][ColIfscNm->Index] = sAtmpNm;
                break;
            }
        }
    }
}
//---------------------------------------------------------------------------

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

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

void __fastcall TVMSM640M::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"
           "  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.SYMBLIB_NMBR     = B.SYMBLIB_NMBR(+)     \r\n"
           "   AND A.VMS_FONT_NAME_CD = C.VMS_FONT_NAME_CD(+) \r\n"
           " ORDER BY A.FORM_OBJECT_ID ASC                   \r\n";

    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())
            {
                int nFormId = pADO->FieldByName("VMS_FORM_ID")->AsInteger;
                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(2열)
                    nObjType ==  37 || //@소통정보이미지3(3열)
                    nObjType ==  47 || //소통이미지4
                    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;

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

                pObj->Text = pADO->FieldByName("VMS_DSPL_TXT")->AsString.Trim();
                pObj->RunText = pObj->Text;

                String sIfscId = "";
                if (nObjType == 401)
                    sIfscId = FIfscId[0];

                if (sIfscId != "")
                {
                    TCDSAtmp *pAtmpObj = CDSAtmpManager->FLists.Find(sIfscId);
                    if (pAtmpObj)
                    {
                        switch(nObjType)
                        {
                        case 401:
                            pObj->RunText = pAtmpObj->VMS_DISP_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;
                if (nObjType == 401) pObj->Tag = FIfscId[0];

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

                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->SetRuntimeText(pObj->RunText);
                }
                else //if (sObjKind == "1" || sObjKind == "2")    // 이미지(1), 이미지 ID(2)
                {
                    if (pObj->ObjKind == OBJKIND_IMAGEID)
                    {
                        pObj->Text = pADO->FieldByName("SYMBLIB_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->SetSize(Bitmap->Width, Bitmap->Height);
                        }
                    }
                    __finally
                    {
                        SAFE_DELETE(pStream);
                    }
                }

                pObj->SetPos(nPosX, nPosY);
                pObj->Show();
                pObj->BringToFront();
            }
        }
        catch(EDatabaseError &E)
        {
            DBERRORMSG("TVMSM640M::LoadFormObjectInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            DBERRORMSG("TVMSM640M::LoadFormObjectInfo", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
}
//---------------------------------------------------------------------------

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

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

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

void __fastcall TVMSM640M::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 == 401)
    {
        BtnListAdd->Enabled = true;
        BtnListDelete->Enabled = true;
    }
    else
    {
        BtnListAdd->Enabled = true;
        BtnListDelete->Enabled = true;
    }

    int nObjSeq = VarToStr(pGDC->Values[nIndex][ColObj03->Index]).ToIntDef(0);
    m_pEdtDesigner->SelectObject(nObjSeq);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM640M::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;

    for (int ii = 0; ii < pDcCell->RecordCount; ii++)
    {
        pDcCell->Values[ii][ColIfscId->Index]  = pDcIfsc->Values[nIfscIdx][Col01->Index];
        pDcCell->Values[ii][ColIfscNm->Index]  = pDcIfsc->Values[nIfscIdx][Col02->Index];
        pDcCell->Values[ii][ColIfscStr->Index] = pDcIfsc->Values[nIfscIdx][Col03->Index];
        pDcCell->Values[ii][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 401:
            pObj->RunText = VarToStr(pDcCell->Values[nCellIdx][ColIfscNm->Index]);
            pObj->SetRuntimeText(pObj->RunText);
            break;
        }
    }
}
//---------------------------------------------------------------------------

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

    TcxGridDataController *pDcCell = TvObjList->DataController;

    for (int ii = 0; ii < pDcCell->RecordCount; ii++)
    {
        pDcCell->Values[ii][ColIfscId->Index]  = "";
        pDcCell->Values[ii][ColIfscNm->Index]  = "";
        pDcCell->Values[ii][ColIfscStr->Index] = "";
        pDcCell->Values[ii][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 401:
            pObj->SetRuntimeText(pObj->Text);
            break;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM640M::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]);
                FIfscId[0] = sIfscId;
#if 0
                switch(nObjType)
                {
                case 401: FIfscId[0] = sIfscId; break; // '	소통상황(1단)
                    break;
                }
#endif
            }
        }
        catch(Exception &e)
        {
        }
    }
    __finally
    {
        pGDC->EndUpdate();
        TvObjList->EndUpdate();
    }

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

