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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "WindowMsgF.h"
#include "CDSFacilityF.h"
#include "CDSIncidentF.h"
#include "FrmMainF.h"
#include "ITSLangTransF.h"
#include "ITSMapF.h"
#include "CDSLayerF.h"
#include "CDSNodeF.h"
#include "CDSLinkF.h"
#include "CDSIfscF.h"
#include "CDSRoadF.h"

#include "FrmCctvImgF.h"
#include "FrmVmsMsgF.h"
#include "FrmLinkInfoF.h"
#include "FrmGisSearchF.h"
#include "FrmStreamPlayerF.h"
#include "FrmLinkInfoF.h"
#include "FrmParkMsgF.h"
#pragma hdrstop

#include "ITS0000MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FRAME_FacilityStatusListF"
#pragma link "FRAME_ProcessStatusListF"
#pragma link "FRAME_IncidentListF"
#pragma link "FRAME_RepeatCongestListF"
#pragma link "FRAME_TrafficMissLinkListF"
#pragma link "FRAME_IncidentAutoListF"
#pragma link "cxClasses"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxEdit"
#pragma link "cxFilter"
#pragma link "cxGraphics"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "FRAME_DatabaseStatusF"
#pragma link "FRAME_OpenMapF"
#pragma link "cxButtons"
#pragma link "cxCheckBox"
#pragma link "cxTextEdit"
#pragma link "cxProgressBar"
#pragma link "dxGDIPlusClasses"
#pragma link "FRAME_AtmpPltnListF"
#pragma link "FRAME_VilgFrcsListF"
#pragma link "FRAME_VilgShprListF"
#pragma resource "*.dfm"
TITS0000M *ITS0000M = NULL;
//---------------------------------------------------------------------------
TColor g_clrStatus[5] = {
clGreen,
clRed,
clYellow,
clBlack,//clSilver,
clBlack,//clSilver,
};
String g_strStatus[5] = {
    "", "", "", "", "",
};
String g_strIncident[6] = {
    "", "사고", "공사", "행사", "기상", "기타",
};

TColor g_clrTraffic[4] = {
    clGray,
    clLime,
    clYellow,
    clRed,
};
String g_strTraffic[4] = {
    "", "", "", "",
};
//---------------------------------------------------------------------------

String g_sTrafficSql[] = {

    "0*************************************************************************\r\n",

    "1*************************************************************************\r\n",

    "SELECT A.ROAD_ID AS LINKID,  NVL(B.SPED, 0) AS SPEED,                     \r\n"
    "       NVL(B.PRCN_DT, '19000101000000')     AS REGDATE,                   \r\n"
    "       NVL(B.DATA_NUM, 0) AS DATACNT,                                     \r\n"
    "       NVL(B.TRVL_HH, 0) AS TRVTM                                         \r\n"
    "  FROM TB_ROAD A,                                                         \r\n"
    "       (SELECT *                                                          \r\n"
    "          FROM TB_ROAD_TRAF                                               \r\n"
    "         WHERE PRCN_DT > TO_CHAR(SYSDATE -  5 / 1440, 'YYYYMMDDHH24MISS') \r\n"
    "           ) B                                                            \r\n"
    " WHERE A.ROAD_ID = B.ROAD_ID(+)                                           \r\n",

    "SELECT A.IFSC_ID AS LINKID,  NVL(B.SPED, 0) AS SPEED,                     \r\n"
    "       NVL(B.PRCN_DT, '19000101000000')     AS REGDATE,                   \r\n"
    "       NVL(B.DATA_NUM, 0) AS DATACNT,                                     \r\n"
    "       NVL(B.TRVL_HH, 0) AS TRVTM                                         \r\n"
    "  FROM TB_IFSC A,                                                         \r\n"
    "       (SELECT *                                                          \r\n"
    "          FROM TB_IFSC_TRAF                                               \r\n"
    "         WHERE PRCN_DT > TO_CHAR(SYSDATE -  5 / 1440, 'YYYYMMDDHH24MISS') \r\n"
    "       ) B                                                                \r\n"
    " WHERE A.IFSC_ID = B.IFSC_ID(+)                                           \r\n",

    "4************************************************************************\r\n",

    "SELECT A.LINK_ID AS LINKID,  NVL(B.SPED, 0) AS SPEED,                     \r\n"
    "       NVL(B.PRCN_DT, '19000101000000')     AS REGDATE,                   \r\n"
    "       NVL(B.DATA_NUM, 0) AS DATACNT,                                     \r\n"
    "       NVL(B.TRVL_HH, 0) AS TRVTM                                         \r\n"
    "  FROM TB_LINK A,                                                         \r\n"
    "       (SELECT *                                                          \r\n"
    "          FROM TB_LINK_TRAF                                               \r\n"
    "         WHERE PRCN_DT > TO_CHAR(SYSDATE -  5 / 1440, 'YYYYMMDDHH24MISS') \r\n"
    "       ) B                                                                \r\n"
    " WHERE A.LINK_ID = B.LINK_ID(+)                                           \r\n",

    "6************************************************************************\r\n",
};

void TITS0000M_MapCallback(TObject *ASender, const String AFunc, const String AArgs, const bool AFirst)
{
    try
    {
        if (!ITS0000M) return;
        ITS0000M->OpenMapCallback(ASender, AFunc, AArgs, AFirst);
    }
    catch(Exception &exception)
    {
    }
}
//---------------------------------------------------------------------------

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

    GrpSystem->Caption = lblSysTab->Caption + " - " + TsIncident->Caption;//"▶ 시스템 운영 정보 - " + TsIncident->Caption;

    FRAMEFacilityStatusList1->PnlBottom->Visible = false;
    FRAMETrafficMissLinkList1->Column18->Visible = false;

    //FrmMain->dxStatusBar->Panels->Items[isbGisPos]->Visible = true;

    //시스템자동돌발
    FRAMEIncidentAutoList1->Visible = false;
    TsIncidentAuto->TabVisible = false;
    TsIncidentAuto->Visible = false;

    //기상-초단기예보
    FRAMEVilgShprList1->Visible = false;
    TsVilgShpr->TabVisible = false;
    TsVilgShpr->Visible = false;

    //기상-동네예보
    FRAMEVilgFrcsList1->Visible = false;
    TsVilgFrcs->TabVisible = false;
    TsVilgFrcs->Visible = false;

    TabDebug->TabVisible = false;
    TabDebug->Visible = false;
    reMsg->Lines->Clear();

    PgSystem->Properties->ActivePage = TsIncident;
    PgSystemOpr->Properties->ActivePage = TsFacilityOpr;

    FRAMEOpenMap1->PnlToolbar->Visible = false;
    FRAMEOpenMap1->MapCallbackFunc = TITS0000M_MapCallback;

#ifdef USE_PARK
    ChkPark->Tag = LyrTp_Park;
    ChkPark->Visible  = true;
#else
    ChkPark->Visible  = false;
#endif
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::CommClose()
{
    try
    {
        if (FrmMain->dxStatusBar->Panels->Items[isbGisPos]->Visible)
            FrmMain->dxStatusBar->Panels->Items[isbGisPos]->Visible = false;

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

void __fastcall TITS0000M::FormCreate(TObject *Sender)
{
    //
}
//---------------------------------------------------------------------------

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

    FRAMEOpenMap1->OpenMap();

    Application->ProcessMessages();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::LoadLocalSkin()
{
#define     MAX_VIEW        12

    TcxGridTableView *pView[MAX_VIEW];
    TcxGrid *pGrid[MAX_VIEW];

    for (int ii = 0; ii < MAX_VIEW; ii++)
    {
        pGrid[ii] = NULL;
        pView[ii] = NULL;
    }

    pGrid[ 0] = FRAMEProcessStatusList1->CxList;    //프로세스상태
    pGrid[ 1] = FRAMEFacilityStatusList1->CxList;   //시설물상태
#if 0
    pGrid[ 2] = NULL;
    pGrid[ 3] = NULL;
#else
    pGrid[ 2] = FRAMEDatabaseStatus1->CxList;//FRAMEUtisStatusList1->CxUtisRun;    //UTIS현황-운영현황
    //pGrid[ 3] = FRAMEUtisStatusList1->CxUtisRse;     //UTIS현황-RSE상태현황
#endif
    pGrid[ 4] = FRAMEIncidentList1->CxList;         //돌발
    pGrid[ 5] = FRAMERepeatCongestList1->CxList;    //반복정체구간
    pGrid[ 6] = FRAMETrafficMissLinkList1->CxList;  //소통정보결측구간
    pGrid[ 7] = FRAMEIncidentAutoList1->CxList2;    //소통정보결측구간
    //pGrid[ 8] = FRAMEBlackBoxEventList1->CxList;    //블랙박스이벤트리스트
    pGrid[ 9] = FRAMEVilgFrcsList1->CxList;         //기상정보리스트
    pGrid[10] = FRAMEVilgShprList1->CxList;         //기상정보리스트(초단기예보)
    pGrid[11] = FRAMEAtmpPltnList1->CxList;         //환경정보(대기오염)

    pView[ 0] = FRAMEProcessStatusList1->TvList;
    pView[ 1] = FRAMEFacilityStatusList1->TvList;
#if 0
    pView[ 2] = NULL;
    pView[ 3] = NULL;
#else
    pView[ 2] = FRAMEDatabaseStatus1->TvList;//FRAMEUtisStatusList1->TvUtisRun;
    //pView[ 3] = FRAMEUtisStatusList1->TvUtisRse;
#endif
    pView[ 4] = FRAMEIncidentList1->TvList;
    pView[ 5] = FRAMERepeatCongestList1->TvList;
    pView[ 6] = FRAMETrafficMissLinkList1->TvList;
    pView[ 7] = FRAMEIncidentAutoList1->TvList2;
    //pView[ 8] = FRAMEBlackBoxEventList1->TvList;
    pView[ 9] = FRAMEVilgFrcsList1->TvList;
    pView[10] = FRAMEVilgShprList1->TvList;
    pView[11] = (TcxGridTableView*)FRAMEAtmpPltnList1->TvList;

    for (int ii = 0; ii < MAX_VIEW; ii++)
    {
        if (!pView[ii]) continue;

        //pGrid[ii]->LookAndFeel->SkinName = "McSkin";
        pView[ii]->Styles->Inactive   = NULL;
        pView[ii]->Styles->ContentOdd = NULL;
        pView[ii]->Styles->ContentEven= NULL;
        pView[ii]->Styles->Selection  = NULL;
        pView[ii]->OptionsSelection->CellSelect = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;

    // 상태바 표출
    PnlProgress->Left = (this->Width  - PnlProgress->Width)  / 2;
    PnlProgress->Top  = (this->Height - PnlProgress->Height) / 2;
    PnlProgress->Top -= 50;
    PnlProgress->Visible = true;

    PbLoadMap->Properties->Text = lblGisStep1->Caption;//"지도 로딩 중...";
    Application->ProcessMessages();
    PbLoadMap->Position = 30;

    // 리스트 항목을 초기화한다.
    InitListData();
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::InitListData()
{
    FIncidentCnt  = 0;
    FRrCongestCnt = 0;
    FMissLinkCnt  = 0;

    FRAMEFacilityStatusList1->UpdateList();
    UpdateFacilityStatusTotal();
    FRAMEProcessStatusList1->UpdateList();
    if (GrpBottomUtis->Visible)
    {
        FRAMEDatabaseStatus1->UpdateList();
        //FRAMEUtisStatusList1->UpdateList();
    }

    if (FRAMEIncidentList1->Visible) FRAMEIncidentList1->UpdateList();
    if (FRAMERepeatCongestList1->Visible) FRAMERepeatCongestList1->UpdateList();
    if (FRAMETrafficMissLinkList1->Visible) FRAMETrafficMissLinkList1->UpdateList();
    if (FRAMEIncidentAutoList1->Visible) FRAMEIncidentAutoList1->UpdateList();
    //FRAMEBlackBoxEventList1->UpdateList();
    if (FRAMEVilgFrcsList1->Visible) FRAMEVilgFrcsList1->UpdateList();
    if (FRAMEVilgShprList1->Visible) FRAMEVilgShprList1->UpdateList();
    if (FRAMEAtmpPltnList1->Visible) FRAMEAtmpPltnList1->UpdateList();

    UpdateAlarmStatus();
    UpdateClctSystStts();           // 수집/가공현황 업데이트
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::UpdateAlarmStatus()
{
    String sAlarmMsg = "";

    FIncidentCnt  = FRAMEIncidentList1->TvList->DataController->RecordCount;
    FRrCongestCnt = FRAMERepeatCongestList1->TvList->DataController->RecordCount;
    FMissLinkCnt  = FRAMETrafficMissLinkList1->TvList->DataController->RecordCount;
    FIncidentAutoCnt  = FRAMEIncidentAutoList1->TvList2->DataController->RecordCount;
    //FBlackBoxEventCnt = FRAMEBlackBoxEventList1->TvList->DataController->RecordCount;

    FVilgFrcsCnt1 = FRAMEVilgFrcsList1->GetAlarmCount1();
    FVilgFrcsCnt2 = FRAMEVilgFrcsList1->GetAlarmCount2();
    FVilgFrcsCnt3 = FRAMEVilgShprList1->GetAlarmCount();
    FAtmpPlntCnt  = FRAMEAtmpPltnList1->GetAlarmCount();

    if (TsIncidentAuto->TabVisible == false)
    {
        FIncidentAutoCnt = 0;
    }
    if (TsVilgShpr->TabVisible == false)
    {
        FVilgFrcsCnt3 = 0;
    }
    if (TsVilgFrcs->TabVisible == false)
    {
        FVilgFrcsCnt1 = 0;
        FVilgFrcsCnt2 = 0;
    }
    if (TsAtmpPltn->TabVisible == false)
    {
        FAtmpPlntCnt = 0;
    }

    if (FIncidentCnt > 0)
    {
        sAlarmMsg += TsIncident->Caption + "(" + String(FIncidentCnt) + ")  ";//"돌발상황(" + String(FIncidentCnt) + ")  ";
        TsIncident->ImageIndex = 1;
    }
    else
        TsIncident->ImageIndex = 2;

    if (FRrCongestCnt > 0)
    {
        sAlarmMsg += TsRrCongest->Caption + "(" + String(FRrCongestCnt) + ")  ";//"반복정체구간(" + String(FRrCongestCnt) + ")  ";
        TsRrCongest->ImageIndex = 1;
    }
    else
        TsRrCongest->ImageIndex = 2;

    if (FMissLinkCnt > 0)
    {
        sAlarmMsg += TsMissingLink->Caption + "(" + String(FMissLinkCnt) + ")  ";//"결측구간(" + String(FMissLinkCnt) + ")  ";
        TsMissingLink->ImageIndex = 1;
    }
    else
        TsMissingLink->ImageIndex = 2;

    if (FIncidentAutoCnt > 0)
    {
        sAlarmMsg += TsIncidentAuto->Caption + "(" + String(FIncidentAutoCnt) + ")  ";//"자동돌발(" + String(FIncidentAutoCnt) + ")  ";
        TsIncidentAuto->ImageIndex = 1;
    }
    else
        TsIncidentAuto->ImageIndex = 2;

    if ((FVilgFrcsCnt1 + FVilgFrcsCnt2) > 0)
    {
        //sAlarmMsg += TsVilgFrcs->Caption + "(" + String(FVilgFrcsCnt1 + FVilgFrcsCnt2) + ")  ";
        sAlarmMsg += TsVilgFrcs->Caption + "  ";
        TsVilgFrcs->ImageIndex = 1;
    }
    else
        TsVilgFrcs->ImageIndex = 2;

    if ((FVilgFrcsCnt3) > 0)
    {
        //sAlarmMsg += TsVilgShpr->Caption + "(" + String(FVilgFrcsCnt3) + ")  ";
        sAlarmMsg += TsVilgShpr->Caption + "  ";
        TsVilgShpr->ImageIndex = 1;
    }
    else
        TsVilgShpr->ImageIndex = 2;

    if ((FAtmpPlntCnt) > 0)
    {
        sAlarmMsg += TsAtmpPltn->Caption + "(" + String(FAtmpPlntCnt) + ")  ";
        TsAtmpPltn->ImageIndex = 1;
    }
    else
        TsAtmpPltn->ImageIndex = 2;

    LblAlarm->Caption = sAlarmMsg;
    if ((FIncidentCnt+FRrCongestCnt+FMissLinkCnt+FIncidentAutoCnt+FBlackBoxEventCnt+FVilgFrcsCnt1+FVilgFrcsCnt2+FVilgFrcsCnt3+FAtmpPlntCnt) > 0)
    {
        LblAlarm->Visible = true;
    }
    else
    {
        LblAlarm->Visible = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::PgSystemPageChanging(TObject *Sender, TcxTabSheet *NewPage, bool &AllowChange)
{
    GrpSystem->Caption = lblSysTab->Caption + " - " + NewPage->Caption;//"▶ 시스템 운영 정보 - " + NewPage->Caption;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FormClose(TObject *Sender, TCloseAction &Action)
{
    try {
        CommClose();

        ITS0000M = NULL;
        Action = caFree;
    } catch(...) {}
}
//---------------------------------------------------------------------------

/*
 * 메인폼에서 데이터를 수신시 발생하는 이벤트 핸들러
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TITS0000M::OnMainFormMessage(TMessage &Msg)
{
    switch(Msg.WParam)
    {
    case WP_DB_SELECT_OK:
        switch(Msg.LParam)
        {
        case LP_MSG_TRAFFIC:    //소통정보 조회 완료
            DebugMsg("교통정보 업데이트");
            UpdateTrafficMissLinkInfo();    // 결측구간
            UpdateTrafficRrCongestInfo();   // 반복정체구간
            UpdateGisTraffic();             // 지도 소통정보 업데이트
            if (BtnRefresh->Enabled == false)
            {
                BtnRefresh->Enabled = true;
            }
            UpdateClctSystStts();           // 수집/가공현황 업데이트
            break;

        case LP_MSG_PROCESS_STTS:   //프로세스 상태 조회 완료
            DebugMsg("프로세스 상태정보 업데이트");
            UpdateProcessStatusInfo();
            break;

        case LP_MSG_DATABASE_STTS:  //데이터베이스 상태
            DebugMsg("데이터베이스 상태정보 업데이트");
            UpdateDatabaseStatusInfo();
            break;

        case LP_MSG_FACILITY_STTS:  //시설물 상태 조회 완료
            DebugMsg("시설물 상태정보 업데이트");
            UpdateFacilityStatusInfo();
            break;

        case LP_MSG_INCIDENT:   //돌발정보 조회 완료
            DebugMsg("돌발정보 업데이트");
            UpdateIncidentInfo();
            break;

        case LP_MSG_16: DebugMsg("블랙박스정보 로딩");  UpdateBlackBoxEventInfo();             break;
        case LP_MSG_WEATHER: DebugMsg("기상정보 로딩"); UpdateVilgFrcsInfo();                  break;
        case LP_MSG_05: DebugMsg("UTIS 정보 로딩");     UpdateUtisStatusInfo();                break;
        case LP_MSG_14: DebugMsg("시설물정보 로딩");    UpdateFacilityInfo();                  break;
        case LP_MSG_09: DebugMsg("프로세스정보 로딩");  FRAMEProcessStatusList1->UpdateList(); break;

        case LP_MSG_VMS_DSPLMSG: DebugMsg("VMS 표출 스케쥴 로딩"); UpdateVmsMsg(1);           break;
        }
        break;
    case WP_MSG_01: //소통등급이 변경되었다.
        SetGisTrafficColor();
        break;
    case WP_MSG_02: //돌발정보를 현단말에서 취소/등록/해제 하였다.
        UpdateIncidentInfo();
        break;
    case WP_MSG_03: //시설물 기본정보가 변경됨
        UpdateFacilityInfo();
        break;
    case WP_DB_SELECT_ERROR:
    case WP_DB_SELECT_CANCEL:
        break;
    case WP_MSG_15:
        if (LP_MSG_15 == Msg.LParam)
        {
            RefreshGisLink();
        }
        break;
    }
    //TmrDebugHideTimer((TObject*)TmrDebugHide);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateTrafficMissLinkInfo()
{
    FMissLinkCnt  = 0;
    FRAMETrafficMissLinkList1->UpdateList();
    FRAMEIncidentAutoList1->UpdateList();
    UpdateAlarmStatus();
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateTrafficRrCongestInfo()
{
    FRrCongestCnt = 0;
    FRAMERepeatCongestList1->UpdateList();
    UpdateAlarmStatus();
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateIncidentInfo()
{
    FIncidentCnt  = 0;
    FRAMEIncidentList1->UpdateList();
    FRAMEIncidentAutoList1->UpdateList();
    UpdateAlarmStatus();
    UpdateGisIncident();
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateFacilityStatusInfo()
{
    //FRAMEFacilityStatusList1->UpdateList();
    FRAMEFacilityStatusList1->RefreshList();
    UpdateFacilityStatusTotal();
    UpdateAlarmStatus();
    UpdateGisFacility();
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateProcessStatusInfo()
{
    FRAMEProcessStatusList1->RefreshList();
    UpdateAlarmStatus();
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateUtisStatusInfo()
{
    if (GrpBottomUtis->Visible)
    {
        //FRAMEUtisStatusList1->RefreshList();
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateDatabaseStatusInfo()
{
    if (GrpBottomUtis->Visible)
    {
        FRAMEDatabaseStatus1->RefreshList();
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateFacilityInfo()
{
    FRAMEFacilityStatusList1->UpdateList();
    UpdateFacilityStatusTotal();
    UpdateAlarmStatus();
    UpdateGisFacility(); //지도 시설물 재로딩
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateBlackBoxEventInfo()
{
    FBlackBoxEventCnt  = 0;
    //FRAMEBlackBoxEventList1->UpdateList();
    UpdateAlarmStatus();
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::UpdateVilgFrcsInfo()
{
    FVilgFrcsCnt1  = 0;
    FVilgFrcsCnt2  = 0;
    FVilgFrcsCnt3  = 0;
    FAtmpPlntCnt   = 0;
    FRAMEVilgFrcsList1->RefreshList();
    FRAMEVilgShprList1->RefreshList();
    FRAMEAtmpPltnList1->RefreshList();
    UpdateAlarmStatus();
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMEIncidentList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    //돌발 클릭
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMEIncidentList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sId = VarToStr(pGDC->Values[nRow][FRAMEIncidentList1->Column01->Index]);
        String sDx = VarToStr(pGDC->Values[nRow][FRAMEIncidentList1->Column07->Index]);
        String sDy = VarToStr(pGDC->Values[nRow][FRAMEIncidentList1->Column08->Index]);
        SelectObjectByPos(StrToFloat(sDx), StrToFloat(sDy), true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMERepeatCongestList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    //반복정체구간 클릭
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMERepeatCongestList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sSvcLinkId = VarToStr(pGDC->Values[nRow][FRAMERepeatCongestList1->Column01->Index]);
        SelectLinkById(2, sSvcLinkId, true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMETrafficMissLinkList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    //소통정보 결측구간 클릭
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMETrafficMissLinkList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sLinkId = VarToStr(pGDC->Values[nRow][FRAMETrafficMissLinkList1->Column02->Index]);
        SelectLinkById(1, sLinkId, true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMEFacilityStatusList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    //시설물 위치이동
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMEFacilityStatusList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sType = VarToStr(pGDC->Values[nRow][FRAMEFacilityStatusList1->Column01->Index]);
        FSelId       = VarToStr(pGDC->Values[nRow][FRAMEFacilityStatusList1->Column02->Index]);
        if (sType == "CRSSVR") return;
        MoveGisFacility(sType, FSelId);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::MoveGisFacility(String AType, String AId)
{
    if (!FRAMEOpenMap1->MapStart) return;

    int nLayerIdx = ItsLayerManager->GetLayerIndex(AType);
    if (nLayerIdx < 0) return;

    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (pFacility)
    {
        if (pFacility->Object)
        {
            sJs.printf(L"selectLayerObject(%d, '%s', %d)", nLayerIdx, pFacility->Object->CTLR_NMBR.c_str(), FRAMEOpenMap1->MapZoom);
            FRAMEOpenMap1->ExecScript(sJs);
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMEFacilityStatusList1TvListCellClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
	if (AButton != mbRight) return;
    if (!ACellViewInfo) return;

    try {
        TcxDataController *pGDC = FRAMEFacilityStatusList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sType = VarToStr(pGDC->Values[nRow][FRAMEFacilityStatusList1->Column01->Index]);
        FSelId       = VarToStr(pGDC->Values[nRow][FRAMEFacilityStatusList1->Column02->Index]);
        if (sType == "CRSSVR") return;

        int nLayerIndex = ItsLayerManager->GetLayerIndex(sType);

        OnMapPopupMenu(nLayerIndex, FSelId, true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::pmuFacilityPopup(TObject *Sender)
{
    TPopupMenu *pPopup = (TPopupMenu*)Sender;

    FSelMenuTag = pPopup->Tag;

    String sLayerType = ItsLayerManager->GetLayerType(FSelMenuTag);
    if (sLayerType == "") return;

    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(FSelId);
    if (!pFacility) return;

    TCDSObject *pObj = pFacility->Object;
    if (!pObj) return;

    pPopup->Items->Items[0]->Caption = "[" + sLayerType + "] " + pObj->NAME;

#if 0
    switch(pPopup->Tag)
    {
    case LyrTp_Cctv:
        break;
    case LyrTp_Vms:
        break;
    case LyrTp_Vds:
        break;
    case LyrTp_VdsDet:
        break;
    case LyrTp_VdsR:
    case LyrTp_VdsRDet:
    case LyrTp_VdsC:
    case LyrTp_VdsCDet:
    case LyrTp_Avi:
    case LyrTp_Rse:
    case LyrTp_Dsrc:
    case LyrTp_Park:
    case LyrTp_PVms:
    case LyrTp_Bit:
    case LyrTp_Sig:
    case LyrTp_SigDet:
        break;
    case LyrTp_WCam:
        break;
    case LyrTp_CCam:
        break;
    case LyrTp_Event:
    case LyrTp_Wthr:
    case LyrTp_Atmp:
    case LyrTp_Incd:
        break;
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::mnuFacilityMoveClick(TObject *Sender)
{
    TMenuItem *pMenu = (TMenuItem*)Sender;
    Application->ProcessMessages();
    String sLayerType = ItsLayerManager->GetLayerType(FSelMenuTag);
    if (sLayerType != "")
    {
        MoveGisFacility(sLayerType, FSelId);
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::mnuFacilityPingClick(TObject *Sender)
{
    TMenuItem *pMenu = (TMenuItem*)Sender;
    Application->ProcessMessages();

    String sIp = "";

    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(FSelId);
    if (!pFacility) return;

    TCDSObject *pObj = pFacility->Object;
    if (!pObj) return;

    if (pMenu->Tag == 21) //제어기 핑 테스트
    {
        sIp = pObj->CTLR_IP;
    }
    else
    if (pMenu->Tag == 22 && FSelMenuTag == LyrTp_Vms)
    {
        TVmsCtlr *pObj = (TVmsCtlr*)pObj;
        sIp = pObj->WEB_CMRA_IP;
    }

    if (sIp.IsEmpty())
    {
        Application->MessageBox(Label2->Caption.c_str(),//L"IP Address 정보가 없습니다.\r\nIP Address 정보를 확인하세요.",
                                Label1->Caption.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }
    else
    {
        ITSUtil_NetworkPing(sIp);
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::mnuStopImageClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ScreenToClient(pt);
    ShowCctvStopImage(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowCctvStopImage(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TCctvCtlr *pObj = (TCctvCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmCctvImg *pForm = (TFrmCctvImg *)pObj->FData1;
            pForm->SetFocus();
            pForm->LoadStopImage();
        }
        else
        {
            TFrmCctvImg *pForm = new TFrmCctvImg(ITS0000M);
            pForm->Parent = ITS0000M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top + pt.y;
            pForm->FObj = pObj;
            pObj->FData2 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::mnuCctvCamClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS0000M->ScreenToClient(pt);
    ShowCctvCamera(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowCctvCamera(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TCctvCtlr *pObj = (TCctvCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmStreamPlayer *pForm = (TFrmStreamPlayer *)pObj->FData1;
            pForm->SetFocus();
        }
        else
        {
            TFrmStreamPlayer *pForm = new TFrmStreamPlayer(ITS0000M);
            pForm->FObj.IsCctv    = true;
            pForm->FObj.ID        = pObj->CCTV_CTLR_ID;
            pForm->FObj.NAME      = pObj->CCTV_NM;
            pForm->FObj.RTSP_ADDR = pObj->STRM_SESN_NM;
            pForm->FObj.Data      = (TCDSObject*)pObj;
            pForm->FObj.Installed = true;
            pForm->Parent = ITS0000M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;

            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::mnuVmsMsgClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS0000M->ScreenToClient(pt);
    ShowVmsMessage(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateVmsMsg(int AType)
{
    try
    {
        FOR_STL(TVmsCtlr*, pObj, VmsCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;
            if (pObj->FData2)
            {
                TFrmVmsMsg *pForm = (TFrmVmsMsg *)pObj->FData2;
                if (AType == 1)
                    pForm->VmsFormReload();
                else
                    pForm->VmsFormReload();
            }
        }
    }
    catch(Exception &e)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ShowVmsMessage(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TVmsCtlr *pObj = (TVmsCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData2)
        {
            TFrmVmsMsg *pForm = (TFrmVmsMsg *)pObj->FData2;
            pForm->SetFocus();
        }
        else
        {
            TFrmVmsMsg *pForm = new TFrmVmsMsg(ITS0000M, pObj);
            pForm->Parent = ITS0000M;

            int nHG = pForm->ClientHeight - pForm->PnlVmsMsgDisp->Height;
            int nWG = pForm->ClientWidth  - pForm->PnlVmsMsgDisp->Width;

#if 0
            pForm->ClientHeight = nHG + pObj->Height;
            pForm->ClientWidth  = nWG + pObj->Width;
#endif

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;

            pObj->FData2 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::mnuVmsCamClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS0000M->ScreenToClient(pt);
    ShowVmsCamera(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowVmsCamera(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TVmsCtlr *pObj = (TVmsCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmStreamPlayer *pForm = (TFrmStreamPlayer *)pObj->FData1;
            pForm->SetFocus();
        }
        else
        {
            TFrmStreamPlayer *pForm = new TFrmStreamPlayer(ITS0000M);
            pForm->FObj.IsCctv    = false;
            pForm->FObj.ID        = pObj->VMS_CTLR_ID;
            pForm->FObj.NAME      = pObj->VMS_NM;
            pForm->FObj.RTSP_ADDR = pObj->STRM_SESN_NM;
            pForm->FObj.Data      = (TCDSObject*)pObj;
            pForm->FObj.Installed = true;
            pForm->Parent = ITS0000M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;

            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::MnuWebCamClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS0000M->ScreenToClient(pt);
    ShowWebCamera(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowWebCamera(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TWCamCtlr *pObj = (TWCamCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmStreamPlayer *pForm = (TFrmStreamPlayer *)pObj->FData1;
            pForm->SetFocus();
        }
        else
        {
            TFrmStreamPlayer *pForm = new TFrmStreamPlayer(ITS0000M);
            pForm->FObj.IsCctv    = false;
            pForm->FObj.ID        = pObj->WCAM_CTLR_ID;
            pForm->FObj.NAME      = pObj->WCAM_NM;
            pForm->FObj.RTSP_ADDR = pObj->STRM_SESN_NM;
            pForm->FObj.Data      = (TCDSObject*)pObj;
            pForm->FObj.Installed = true;
            pForm->Parent = ITS0000M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;

            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::MnuCrsCamClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS0000M->ScreenToClient(pt);
    ShowCrsCamera(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowCrsCamera(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TCCamCtlr *pObj = (TCCamCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmStreamPlayer *pForm = (TFrmStreamPlayer *)pObj->FData1;
            pForm->SetFocus();
        }
        else
        {
            TFrmStreamPlayer *pForm = new TFrmStreamPlayer(ITS0000M);
            pForm->FObj.IsCctv    = false;
            pForm->FObj.ID        = pObj->CCAM_CTLR_ID;
            pForm->FObj.NAME      = pObj->CCAM_NM;
            pForm->FObj.RTSP_ADDR = pObj->STRM_SESN_NM;
            pForm->FObj.Data      = (TCDSObject*)pObj;
            pForm->FObj.Installed = true;
            pForm->Parent = ITS0000M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;

            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::FRAMEIncidentAutoList1TvList2CellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    //소통정보 결측구간 클릭
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMEIncidentAutoList1->TvList2->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sLinkId = VarToStr(pGDC->Values[nRow][FRAMEIncidentAutoList1->ColumnA01->Index]);
        SelectLinkById(1, sLinkId, true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::UpdateFacilityStatusTotal()
{
    int nRow = 0;
    try
    {
        CMM_ClearGridTableView(TvStatus);

        TcxDataController *pGDC = TvStatus->DataController;
        TvStatus->BeginUpdate();

        ItsFacilityManager->FListStatus.Lock();

        try
        {
            FOR_STL(TFacilityStatus*, pStatus, ItsFacilityManager->FListStatus)
            {
                nRow = pGDC->AppendRecord();

                if (pStatus->Type == "CCAM")
                    pGDC->Values[nRow][ColName->Index] = "교차로감시";
                else
                if (pStatus->Type == "WCAM")
                    pGDC->Values[nRow][ColName->Index] = "CCTV(웹카메라)";
                else
                if (pStatus->Type == "CRSSVR")
                {
                    pGDC->Values[nRow][ColName->Index] = "교차로분석서버";
                }
                else
                if (pStatus->Type == "PARK")
                {
                    pGDC->Values[nRow][ColName->Index] = "주차장";
                }
                else
                    pGDC->Values[nRow][ColName->Index] = pStatus->Type;

                pGDC->Values[nRow][ColTotal->Index]  = pStatus->Total;
                pGDC->Values[nRow][ColNormal->Index] = pStatus->Total - pStatus->Error;
                pGDC->Values[nRow][ColFail->Index]   = pStatus->Error;
                if (pStatus->Type == "VDS" || pStatus->Type == "AVI" || pStatus->Type == "DSRC")
                    pGDC->Values[nRow][ColModule->Index] = pStatus->Collect;//Module;
                else
                    pGDC->Values[nRow][ColModule->Index] = "-";
            }
        }
        catch(Exception &exception)
        {
        }
    }
    __finally
    {
        ItsFacilityManager->FListStatus.UnLock();
        TvStatus->EndUpdate();
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateClctSystStts()
{
    int nRow = 0;

    CMM_ClearGridTableView(TvClctStts);
    TcxDataController *pGDC = TvClctStts->DataController;

    TvClctStts->BeginUpdate();
    ItsLinkManager->FClctSystStts.Lock();
    try
    {
        try
        {
            FOR_STL(TClctSystStts*, pObj, ItsLinkManager->FClctSystStts)
            {
                nRow = pGDC->AppendRecord();

                pGDC->Values[nRow][Column1->Index] = pObj->CLCT_SYST_NM;
                pGDC->Values[nRow][Column2->Index] = ITSUtil_FormatStr(pObj->PRCN_DT, STR_DATETIME);
                if (pObj->IsCollected)
                {
                    pGDC->Values[nRow][Column3->Index] = FormatFloat("##,##0", pObj->CLCT_NUM);
                    pGDC->Values[nRow][Column4->Index] = FormatFloat("##,##0", pObj->FLTR_NUM);
                    pGDC->Values[nRow][Column5->Index] = FormatFloat("##,##0", pObj->FUSN_NUM);
                }
                else
                {
                    pGDC->Values[nRow][Column3->Index] = "-";
                    pGDC->Values[nRow][Column4->Index] = "-";
                    pGDC->Values[nRow][Column5->Index] = "-";
                }
            }
        }
        catch(Exception &exception)
        {
        }
    }
    __finally
    {
        ItsLinkManager->FClctSystStts.UnLock();
        TvClctStts->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ColNameCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
          TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
{
    // 장비명
    if (AViewInfo->GridRecord->RecordIndex < 0) return;
    ACanvas->Font->Style = TFontStyles() << fsBold;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ColTotalCustomDrawCell(TcxCustomGridTableView *Sender,
          TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    // 전체
    if (AViewInfo->GridRecord->RecordIndex < 0) return;
    ACanvas->Font->Style = TFontStyles() << fsBold;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ColNormalCustomDrawCell(TcxCustomGridTableView *Sender,
          TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    // 정상
    if (AViewInfo->GridRecord->RecordIndex < 0) return;
    ACanvas->Font->Style = TFontStyles() << fsBold;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ColFailCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
          TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
{
    // 이상
    if (AViewInfo->GridRecord->RecordIndex < 0) return;
    ACanvas->Font->Style = TFontStyles() << fsBold;
	if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[ColFail->Index]))
    {
        String sErr = AViewInfo->GridRecord->DisplayTexts[ColFail->Index];
        if (sErr != "0")
        {
            ACanvas->Font->Color = clRed;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ColModuleCustomDrawCell(TcxCustomGridTableView *Sender,
          TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    // 이상
    if (AViewInfo->GridRecord->RecordIndex < 0) return;
    ACanvas->Font->Style = TFontStyles() << fsBold;
	if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[ColModule->Index]))
    {
        String sErr = AViewInfo->GridRecord->DisplayTexts[ColModule->Index];
        if (sErr.Trim() == "-")
            return;

        if (sErr != "0")
        {
            ACanvas->Font->Color = clRed;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::TvStatusCustomDrawCell(TcxCustomGridTableView *Sender,
          TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    if (AViewInfo->GridRecord->Selected)
    {
        //ACanvas->Brush->Color = Sender->LookAndFeelPainter->DefaultContentColor();
        //ACanvas->Font->Color = Sender->LookAndFeelPainter->DefaultContentTextColor();
        if (AViewInfo->GridRecord->Index % 2 == 0)
        {
            ACanvas->Brush->Color = Sender->LookAndFeelPainter->DefaultContentEvenColor();
            ACanvas->Font->Color = Sender->LookAndFeelPainter->DefaultContentTextColor();
        }
        else
        {
            ACanvas->Brush->Color = Sender->LookAndFeelPainter->DefaultContentOddColor();
            ACanvas->Font->Color = Sender->LookAndFeelPainter->DefaultContentTextColor();
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::BtnMapToJpgClick(TObject *Sender)
{
    FRAMEOpenMap1->BtnMapToJpgClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::BtnMoveDefBoundsClick(TObject *Sender)
{
    FRAMEOpenMap1->BtnMoveDefBoundsClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::BtnZoomInClick(TObject *Sender)
{
    FRAMEOpenMap1->BtnZoomInClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::BtnZoomOutClick(TObject *Sender)
{
    FRAMEOpenMap1->BtnZoomOutClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::BtnMapSelectClick(TObject *Sender)
{
    if (FRAMEOpenMap1->MapStart)
    {
        sJs.printf(L"selectMode(%d)", BtnMapSelect->Down ? 1 : 0);
        FRAMEOpenMap1->ExecScript(sJs);

        sJs.printf(L"setMouseClick(%d)", (BtnMapSelect->Down) ? 1: 0);
        FRAMEOpenMap1->ExecScript(sJs);
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::BtnRefreshClick(TObject *Sender)
{
    if (FRAMEOpenMap1->MapStart)
    {
        FrmMain->FPollStatus01.Reset(); // 시설물상태정보
        FrmMain->FPollStatus02.Reset(); // 프로세스상태정보
        FrmMain->FPollStatus03.Reset(); // 돌발정보

        FrmMain->FPollTraffic00.Reset(); // 링크소통정보(전체)
        FrmMain->FPollTraffic05.Reset(); // UTIS운영정보
        FrmMain->FPollDatabase.Reset();  // 데이터베이스 상태

        FrmMain->FPollEvent01.Reset();   // 블랙박스이벤트
        FrmMain->FPollVilgFrcs.Reset();  // 기상정보

        BtnRefresh->Enabled = false;
        //TmrRefresh->Enabled = true;
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::TmrRefreshTimer(TObject *Sender)
{
    TmrRefresh->Enabled = false;
    BtnRefresh->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateGisIncident()
{
    if (!FRAMEOpenMap1->MapStart) return;

    sJs.printf(L"removeLayerObject(%d)", LyrTp_Incd);
    FRAMEOpenMap1->ExecScript(sJs);

    int    nStatus;
    String ROAD_NAME = "   ";
    String arrObj = "";
    String sTemp;
    try
    {
        ItsIncidentManager->FLists.Lock();
        FOR_STL(TItsIncident *, pObj, ItsIncidentManager->FLists)
        {
            if (pObj->DISP_INCD == "N") continue;
            if (pObj->INCD_PRGR_STEP_CD == "ISS2")
            {
                ROAD_NAME = "";
                TItsLink *pLink = ItsLinkManager->FLists.Find(pObj->LINK_ID);
                if (pLink)
                {
                    ROAD_NAME = pLink->ROAD_NAME;
                }

                nStatus = pObj->INCD_TYPE_CLSF_CD.ToIntDef(1);
                if (nStatus > 4 || nStatus < 1) nStatus = 1;

                if (arrObj != "") arrObj += "|";
                sTemp.printf(L"%s,%s,%s,%s,%s,%s,%s,%s,%d,%s,%s,%s,%s",
                                pObj->INCD_OCRR_ID.c_str(),
                                pObj->X_CRDN.c_str(),
                                pObj->Y_CRDN.c_str(),
                                ITSUtil_StrToTime(pObj->RGST_DT).c_str(),
                                ITSUtil_StrToTime(pObj->INCD_STRT_DT).c_str(),
                                ITSUtil_StrToTime(pObj->INCD_END_PRAR_DT).c_str(),
                                ROAD_NAME.c_str(),
                                pObj->INCD_TITL.c_str(),
                                nStatus,
                                g_strIncident[nStatus].c_str(),
                                pObj->OCRR_LCTN_NM.c_str(),
                                pObj->INCD_EXPL.c_str(),
                                pObj->LINK_ID.c_str());
                arrObj += sTemp;
            }
        }
    }
    __finally
    {
        ItsIncidentManager->FLists.UnLock();
    }

    if (arrObj != "")
    {
        sJs.printf(L"addIncident('%s')", arrObj.c_str());
        FRAMEOpenMap1->ExecScript(sJs);
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateGisFacility()
{
    if (!FRAMEOpenMap1->MapStart) return;

    FOR_STL(TLayerIdx*, pLayer, ItsLayerManager->FFacilityLayers)
    {
        pLayer->arrObj = "";
    }

    String      sTemp;
    TCDSObject *pObj;
    TLayerIdx  *pLayer;

    ItsFacilityManager->FLists.Lock();
    try
    {
        FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
        {
            if (pFacility->FOldComm == pFacility->FComm)
                continue;

            pObj = pFacility->Object;
            if (pObj == NULL)
            {
                continue;
            }
            if (pFacility->FCLT_TYPE == "VDS" && pFacility->FCLT_KIND == "C")
            {
                continue;
            }

            pLayer = ItsLayerManager->FFacilityLayers.Find(pFacility->FCLT_TYPE);
            if (pLayer)
            {
                if (pLayer->arrObj != "") pLayer->arrObj += "|";
                sTemp.printf(L"%s,%d", pObj->CTLR_NMBR.c_str(), pFacility->FComm.ToIntDef(2));
                pLayer->arrObj += sTemp;
            }
            pFacility->FOldComm = pFacility->FComm;
        }
    }
    __finally
    {
        ItsFacilityManager->FLists.UnLock();
    }

    FOR_STL(TLayerIdx*, pLayer, ItsLayerManager->FFacilityLayers)
    {
        if (pLayer->arrObj != "")
        {
            sJs.printf(L"updateFacility(%d, '%s')", pLayer->Index, pLayer->arrObj.c_str());
            FRAMEOpenMap1->ExecScript(sJs);
            pLayer->arrObj = "";
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::InitGisFacility()
{
    if (!FRAMEOpenMap1->MapStart) return;

    FOR_STL(TLayerIdx*, pLayer, ItsLayerManager->FFacilityLayers)
    {
        pLayer->arrObj = "";
        sJs.printf(L"removeLayerObject(%d)", pLayer->Index);
        FRAMEOpenMap1->ExecScript(sJs);
    }

    String      sTemp;
    TCDSObject *pObj;
    TLayerIdx  *pLayer;

    ItsFacilityManager->FLists.Lock();
    try
    {
        FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
        {
            pObj = pFacility->Object;
            if (pObj == NULL)
            {
                continue;
            }
            if (pFacility->FCLT_TYPE == "VDS" && pFacility->FCLT_KIND == "C")
            {
                continue;
            }

            pLayer = ItsLayerManager->FFacilityLayers.Find(pFacility->FCLT_TYPE);
            if (pLayer)
            {
                if (pLayer->arrObj != "") pLayer->arrObj += "|";
                sTemp.printf(L"%s,%s,%s,%.6f,%.6f,%d,0,0,0", pObj->CTLR_NMBR.c_str(), pObj->CTLR_ID.c_str(), pObj->NAME.c_str(), pObj->X_CRDN, pObj->Y_CRDN, pFacility->FComm.ToIntDef(2));
                pLayer->arrObj += sTemp;
            }
            pFacility->FOldComm = pFacility->FComm;
        }
    }
    __finally
    {
        ItsFacilityManager->FLists.UnLock();
    }

    FOR_STL(TLayerIdx*, pLayer, ItsLayerManager->FFacilityLayers)
    {
        if (pLayer->arrObj != "")
        {
            sJs.printf(L"addFacility(%d, '%s')", pLayer->Index, pLayer->arrObj.c_str());
            FRAMEOpenMap1->ExecScript(sJs);
            pLayer->arrObj = "";
        }
        if (pLayer->Visible == 0)
        {
            sJs.printf(L"showLayer(%d, 0)", pLayer->Index);
            FRAMEOpenMap1->ExecScript(sJs);
        }
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::UpdateGisTraffic()
{
    if (!FRAMEOpenMap1->MapStart) return;

    TItsVrtx* pVrtx;
    TItsNode* pNode;
    String    STRT_NM;
    String    END_NM;

    int nLinks, nIfscs, nRoads;
    nLinks = nIfscs = nRoads = 0;

    ItsLinkManager->FLists.Lock();
    try
    {
        FOR_STL(TItsLink*, pLink, ItsLinkManager->FLists)
        {
            if (pLink->DEL_YN == "Y")   continue;

            if (pLink->IsVertex && pLink->TRAF && (pLink->SPED != pLink->TRAF->SPED || pLink->TRAF_GRAD != pLink->TRAF->TRAF_GRAD))
            {
                sJs.printf(L"updateLink('%s', '%d', %d)",
                    pLink->LINK_ID.c_str(),
                    pLink->TRAF->SPED,
                    pLink->TRAF->TRAF_GRAD);

                FRAMEOpenMap1->ExecScript(sJs);

                pLink->SPED      = pLink->TRAF->SPED;
                pLink->TRAF_GRAD = pLink->TRAF->TRAF_GRAD;
                nLinks++;
            }
        }
    }
    __finally
    {
        ItsLinkManager->FLists.UnLock();
    }

    ItsIfscManager->FLists.Lock();
    try
    {
        FOR_STL(TItsIfsc*, pIfsc, ItsIfscManager->FLists)
        {
            if (pIfsc->DEL_YN == "Y")   continue;

            if (pIfsc->IsVertex && pIfsc->TRAF && (pIfsc->SPED != pIfsc->TRAF->SPED || pIfsc->TRAF_GRAD != pIfsc->TRAF->TRAF_GRAD))
            {
                sJs.printf(L"updateIfsc('%s', '%d', %d)",
                    pIfsc->IFSC_ID.c_str(),
                    pIfsc->TRAF->SPED,
                    pIfsc->TRAF->TRAF_GRAD);

                FRAMEOpenMap1->ExecScript(sJs);

                pIfsc->SPED      = pIfsc->TRAF->SPED;
                pIfsc->TRAF_GRAD = pIfsc->TRAF->TRAF_GRAD;
                nIfscs++;
            }
        }
    }
    __finally
    {
        ItsIfscManager->FLists.UnLock();
    }

    ItsRoadManager->FLists.Lock();
    try
    {
        FOR_STL(TItsRoad*, pRoad, ItsRoadManager->FLists)
        {
            if (pRoad->DEL_YN == "Y")   continue;

            if (pRoad->IsVertex && pRoad->TRAF && (pRoad->SPED != pRoad->TRAF->SPED || pRoad->TRAF_GRAD != pRoad->TRAF->TRAF_GRAD))
            {
                sJs.printf(L"updateRoad('%s', '%d', %d)",
                    pRoad->ROAD_ID.c_str(),
                    pRoad->TRAF->SPED,
                    pRoad->TRAF->TRAF_GRAD);

                FRAMEOpenMap1->ExecScript(sJs);

                pRoad->SPED      = pRoad->TRAF->SPED;
                pRoad->TRAF_GRAD = pRoad->TRAF->TRAF_GRAD;
                nRoads++;
            }
        }
    }
    __finally
    {
        ItsRoadManager->FLists.UnLock();
    }

    try
    {
        if (FrmLinkInfo)
        {
            FrmLinkInfo->RefreshLinkInfo();
        }
    }
    catch(...)
    {
    }

    String sMsg;
    sMsg.printf(L"GIS Traffic Update: %d, %d, %d", nLinks, nIfscs, nRoads);
    DebugLog(sMsg);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::InitGisTraffic()
{
    if (!FRAMEOpenMap1->MapStart) return;

    TItsVrtx* pVrtx;
    TItsNode* pNode;
    String    STRT_NM;
    String    END_NM;

    FLayerIdx = LyrTp_Node;
    sJs.printf(L"removeLayerObject(%d)", FLayerIdx);
    FRAMEOpenMap1->ExecScript(sJs);

    String arrObj = "";
    String sTemp;

    int cnt = 0;
    ItsNodeManager->FLists.Lock();
    try
    {
        FOR_STL(TItsNode*, pObj, ItsNodeManager->FLists)
        {
            if (arrObj != "") arrObj += "|";

            if (cnt == 0)
            {
                sTemp.printf(L"%s,%s,%s,%.6f,%.6f,0,0,0,0", pObj->NODE_ID.c_str(), pObj->NODE_ID.c_str(), pObj->NODE_NAME.c_str(), pObj->X_CRDN, pObj->Y_CRDN);
                arrObj += sTemp;
                sJs.printf(L"addFacility(%d, '%s')", FLayerIdx, arrObj.c_str());
                FRAMEOpenMap1->ExecScript(sJs);
            }
            else
            {
                sTemp.printf(L"%s,%s,%s,%.6f,%.6f,0,0,0,0", pObj->NODE_ID.c_str(), pObj->NODE_ID.c_str(), pObj->NODE_NAME.c_str(), pObj->X_CRDN, pObj->Y_CRDN);
                sJs.printf(L"addFacilityObject(%d, '%s')", FLayerIdx, sTemp.c_str());
                FRAMEOpenMap1->ExecScript(sJs);
            }
            cnt++;
        }
    }
    __finally
    {
        ItsNodeManager->FLists.UnLock();
        sJs.printf(L"showLayer(%d, 0)", FLayerIdx);
        FRAMEOpenMap1->ExecScript(sJs);
    }

    FRAMEOpenMap1->ExecScript("initTrafficLayer()");

    ItsLinkManager->FLists.Lock();
    try
    {
        FOR_STL(TItsLink*, pLink, ItsLinkManager->FLists)
        {
            if (pLink->DEL_YN == "Y")   continue;

            if (pLink->IsVertex && pLink->TRAF)
            {
                pNode = ItsNodeManager->FLists.Find(pLink->F_NODE_ID);
                if (pNode) STRT_NM = pNode->NODE_NAME; else STRT_NM = " ";
                pNode = ItsNodeManager->FLists.Find(pLink->T_NODE_ID);
                if (pNode) END_NM = pNode->NODE_NAME; else END_NM = " ";

                sJs.printf(L"addLink('%s', '%s', '%s', '%s', '%s', '%d', %d, '%s', '%s')",
                    pLink->LINK_ID.c_str(),
                    pLink->ROAD_NAME.c_str(),
                    STRT_NM.c_str(),
                    END_NM.c_str(),
                    pLink->LINK_LENG.c_str(),
                    pLink->TRAF->SPED,
                    pLink->TRAF->TRAF_GRAD,
                    pLink->X_CRDN_ARR.c_str(),
                    pLink->Y_CRDN_ARR.c_str());

                FRAMEOpenMap1->ExecScript(sJs);

                pLink->SPED      = pLink->TRAF->SPED;
                pLink->TRAF_GRAD = pLink->TRAF->TRAF_GRAD;
            }
        }
    }
    __finally
    {
        ItsLinkManager->FLists.UnLock();
    }

    ItsIfscManager->FLists.Lock();
    try
    {
        FOR_STL(TItsIfsc*, pIfsc, ItsIfscManager->FLists)
        {
            if (pIfsc->DEL_YN == "Y")   continue;

            if (pIfsc->IsVertex && pIfsc->TRAF)
            {
                sJs.printf(L"addIfsc('%s', '%s', '%s', '%s', '%s', '%d', %d, '%s', '%s')",
                    pIfsc->IFSC_ID.c_str(),
                    pIfsc->IFSC_NM.c_str(),
                    pIfsc->STRT_NM.c_str(),
                    pIfsc->END_NM.c_str(),
                    pIfsc->SECT_LNGT.c_str(),
                    pIfsc->TRAF->SPED,
                    pIfsc->TRAF->TRAF_GRAD,
                    pIfsc->X_CRDN_ARR.c_str(),
                    pIfsc->Y_CRDN_ARR.c_str());

                FRAMEOpenMap1->ExecScript(sJs);

                pIfsc->SPED      = pIfsc->TRAF->SPED;
                pIfsc->TRAF_GRAD = pIfsc->TRAF->TRAF_GRAD;
            }
        }
    }
    __finally
    {
        ItsIfscManager->FLists.UnLock();
    }

    ItsRoadManager->FLists.Lock();
    try
    {
        FOR_STL(TItsRoad*, pRoad, ItsRoadManager->FLists)
        {
            if (pRoad->DEL_YN == "Y")   continue;

            if (pRoad->IsVertex && pRoad->TRAF)
            {
                sJs.printf(L"addRoad('%s', '%s', '%s', '%s', '%s', '%d', %d, '%s', '%s')",
                    pRoad->ROAD_ID.c_str(),
                    pRoad->ROAD_NM.c_str(),
                    pRoad->STRT_NM.c_str(),
                    pRoad->END_NM.c_str(),
                    pRoad->SECT_LNGT.c_str(),
                    pRoad->TRAF->SPED,
                    pRoad->TRAF->TRAF_GRAD,
                    pRoad->X_CRDN_ARR.c_str(),
                    pRoad->Y_CRDN_ARR.c_str());

                FRAMEOpenMap1->ExecScript(sJs);

                pRoad->SPED      = pRoad->TRAF->SPED;
                pRoad->TRAF_GRAD = pRoad->TRAF->TRAF_GRAD;
            }
        }
    }
    __finally
    {
        ItsRoadManager->FLists.UnLock();
    }
    FRAMEOpenMap1->ExecScript("makeTrafficLayer()");
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::OnMapPopupMenu(int ALayerType, String AFID, bool AOnList)
{
    FSelId = AFID;

#if 0
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(FSelId);
    if (!pFacility) return;

    TCDSObject *pObj = pFacility->Object;
    if (!pObj) return;
#endif

    POINT p;
    GetCursorPos(&p);

    switch(ALayerType)
    {
    case LyrTp_Cctv:
        N1->Visible = AOnList;
        mnuMoveCctv->Visible = AOnList;
        pmuCctv->Popup(p.x, p.y);
        break;
    case LyrTp_Vms:
        N2->Visible = AOnList;
        mnuMoveVms->Visible = AOnList;
        pmuVms->Popup(p.x, p.y);
        break;
    case LyrTp_Vds:
        MenuItem6->Visible = AOnList;
        MenuItem7->Visible = AOnList;
        pmuVds->Popup(p.x, p.y);
        break;

    case LyrTp_VdsDet:
    case LyrTp_VdsR:
    case LyrTp_VdsRDet:
    case LyrTp_VdsC:
    case LyrTp_VdsCDet:
        break;
    case LyrTp_Avi:
        MenuItem11->Visible = AOnList;
        MenuItem12->Visible = AOnList;
        pmuAvi->Popup(p.x, p.y);
        break;
    case LyrTp_Rse:
        N5->Visible = AOnList;
        mnuMoveRse->Visible = AOnList;
        pmuRse->Popup(p.x, p.y);
        break;
    case LyrTp_Dsrc:
        MenuItem16->Visible = AOnList;
        MenuItem17->Visible = AOnList;
        pmuDsrc->Popup(p.x, p.y);
        break;
    case LyrTp_Park:
        MenuItem28->Visible = AOnList;
        MenuItem29->Visible = AOnList;
        pmuPark->Popup(p.x, p.y);
        break;
    case LyrTp_PVms:
        MenuItem24->Visible = AOnList;
        MenuItem25->Visible = AOnList;
        pmuPVms->Popup(p.x, p.y);
        break;
    case LyrTp_Bit:
        MenuItem18->Visible = AOnList;
        mnuMoveBit->Visible = AOnList;
        pmuBit->Popup(p.x, p.y);
        break;
    case LyrTp_Sig:
        MenuItem22->Visible = AOnList;
        mnuMoveSig->Visible = AOnList;
        pmuSig->Popup(p.x, p.y);
        break;
    case LyrTp_SigDet:
        MenuItem23->Visible = AOnList;
        mnuMoveSigDet->Visible = AOnList;
        pmuSigDet->Popup(p.x, p.y);
        break;
    case LyrTp_WCam:
        N7->Visible = AOnList;
        mnuMoveVmsWebCam->Visible = AOnList;
        pmuWCam->Popup(p.x, p.y);
        break;
    case LyrTp_CCam:
        N18->Visible = AOnList;
        mnuMoveCrsCam->Visible = AOnList;
        pmuCCam->Popup(p.x, p.y);
        break;
    case LyrTp_Event:
    case LyrTp_Wthr:
    case LyrTp_Atmp:
        break;
    case LyrTp_Incd:
        break;
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::SelectObjectByPos(double dPosX, double dPosY, bool bArrow/*=false*/)
{
    FRAMEOpenMap1->SelectObjectByPos(dPosX, dPosY, bArrow);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowLinkDetailInfo(String ALinkId, int ALinkLevel)
{
    try
    {
        if (FrmLinkInfo == NULL)
        {
            FrmLinkInfo = new TFrmLinkInfo(Application);
        }
        FrmLinkInfo->Show();
        FrmLinkInfo->ShowLinkInfo(ALinkId, ALinkLevel);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::MapZoomChanged(int AMapZoom)
{
    String sLevl = ", L ";
    switch(AMapZoom)
    {
    case 12: case 13: sLevl = ", R "; break;
    case 14: case 15: sLevl = ", I "; break;
    }
    LblZoom->Caption = "Zoom: " + String(FRAMEOpenMap1->MapZoom) + sLevl;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::OpenMapCallback(TObject *ASender, const String AFunc, const String AArgs, const bool AFirst)
{
    try
    {
        DebugLog(AFunc + " " + AArgs + (AFirst ? ", First" : ""));

        if (AFirst)
        {
            MapZoomChanged(FRAMEOpenMap1->MapZoom);
            Application->ProcessMessages();
            TmrInitGis->Enabled = true;
            return;
        }

        if (FRAMEOpenMap1->MapStart)
        {
            MapZoomChanged(FRAMEOpenMap1->MapZoom);
        }

        if (AFunc.Pos("onlinkclick"))
        {
            if (BtnMapSelect->Down)
            {
                String sLyrType = "";
                String sLinkId  = "";

                TStringList *pStringList = new TStringList;
                pStringList->CommaText = AArgs;

                try
                {
                    sLyrType = pStringList->Strings[0];
                    sLinkId  = pStringList->Strings[1];
                }
                catch(Exception &e)
                {
                }
                delete pStringList;

                if (sLinkId != "")
                {
                    ShowLinkDetailInfo(sLinkId, sLyrType.ToIntDef(1));
                }
            }
            return;
        }

        if (AFunc.Pos("onfacilityrightclick"))
        {
                int     nLyrType;
                String  sFID;
                //int     X, Y;

                TStringList *pStringList = new TStringList;
                pStringList->CommaText = AArgs;

                try
                {
                    nLyrType = pStringList->Strings[0].ToIntDef(0);
                    sFID     = pStringList->Strings[1];
                    //X        = pStringList->Strings[4].ToIntDef(0);
                    //Y        = pStringList->Strings[5].ToIntDef(0);

                    if (nLyrType != LyrTp_Vds) OnMapPopupMenu(nLyrType, sFID, false);
                }
                catch(Exception &e)
                {
                }
                delete pStringList;

        }
    }
    catch(Exception &exception)
    {
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::SetGisTrafficColor()
{
#if 0
//TODO
//소통등급별 색상을 던지는 것을 여기에 추가한다.
    TUTISLinkGrade UtisLinkColor;

    GetGisTrafficColor(UtisLinkColor);

    // 소통정보를 표출할 스레드 생성
    for (int ii = 0; ii < MAX_LAYERS; ii++)
    {
        if (m_pLinkSpeedUpdate[ii] == NULL) continue;

        m_pLinkSpeedUpdate[ii]->SetUTISLinkColor(UtisLinkColor);
    }
#endif
}
//---------------------------------------------------------------------------
bool __fastcall TITS0000M::SelectLinkById(int ALinkLevel, String AId, bool AHide/*=false*/)
{
    if (!FRAMEOpenMap1->MapStart) return false;

    int nMapZoom = FRAMEOpenMap1->MapZoom;

    switch(ALinkLevel)
    {
    case 0:
        FLayerIdx = LyrTp_Node;
        break;
    case 1:
        FLayerIdx = LyrTp_Link;
        if (nMapZoom > 20 || nMapZoom < 16) nMapZoom = 17;
        break;
    case 2:
        FLayerIdx = LyrTp_Ifsc;
        if (nMapZoom > 15 || nMapZoom < 14) nMapZoom = 15;
        break;
    case 3:
        FLayerIdx = LyrTp_Road;
        if (nMapZoom > 13 || nMapZoom < 12) nMapZoom = 13;
        break;
    }

    sJs.printf(L"selectLayerObject(%d, '%s', %d)", FLayerIdx, AId.c_str(), nMapZoom);
    FRAMEOpenMap1->ExecScript(sJs);
    return true;
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::RefreshGisLink()
{
    SelectLinkById(g_SelLink.Level, g_SelLink.Id, true);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::SelGisItem(int AType, String AId)
{
    SelectLinkById(AType, AId);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::TmrInitGisTimer(TObject *Sender)
{
    TmrInitGis->Enabled = false;

    if (!FRAMEOpenMap1->MapStart) return;

    PbLoadMap->Properties->Text = lblGisStep2->Caption;//"시설물 로딩 중...";
    PbLoadMap->Position = 60;
    Application->ProcessMessages();

    InitGisFacility();

    PbLoadMap->Properties->Text = lblGisStep3->Caption;//"소통정보 로딩 중...";
    PbLoadMap->Position = 80;
    Application->ProcessMessages();

    InitGisTraffic();

    PbLoadMap->Properties->Text = lblGisStep4->Caption;//"돌발정보 로딩 중...";
    PbLoadMap->Position = 100;
    Application->ProcessMessages();

    UpdateGisIncident();

    //여기부분은 모든 레이어를 생성한 후에 실행해야 한다.
    //ChkTrafficClick((TObject*)ChkTraffic);
    ChkTrafficTooltipClick((TObject*)ChkTrafficTooltip);

    PnlProgress->Visible = false;
    PnlToolbar->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ChkFacilityLayerShowHideClick(TObject *Sender)
{
    if (!FRAMEOpenMap1->MapStart) return;

    TcxCheckBox *pCheck = (TcxCheckBox*)Sender;
    sJs.printf(L"showLayer(%d, %d)", pCheck->Tag, pCheck->Checked ? 1 : 0);
    FRAMEOpenMap1->ExecScript(sJs);
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ChkTrafficClick(TObject *Sender)
{
    if (!FRAMEOpenMap1->MapStart) return;

    TcxCheckBox *pCheck = (TcxCheckBox*)Sender;
    sJs.printf(L"showTrafficLayer(%d)", pCheck->Checked ? 1 : 0);
    FRAMEOpenMap1->ExecScript(sJs);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ChkTrafficTooltipClick(TObject *Sender)
{
    if (!FRAMEOpenMap1->MapStart) return;

    TcxCheckBox *pCheck = (TcxCheckBox*)Sender;
    sJs.printf(L"showTrafficTooltip(%d)", pCheck->Checked ? 1 : 0);
    FRAMEOpenMap1->ExecScript(sJs);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::LblZoomDblClick(TObject *Sender)
{
    FRAMEOpenMap1->reMsg->Visible = !FRAMEOpenMap1->reMsg->Visible;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::ChkGisSearchClick(TObject *Sender)
{
    try
    {
        if (ChkGisSearch->Checked)
        {
            if (FrmGisSearch == NULL)
            {
                FrmGisSearch = new TFrmGisSearch(this);
                //FrmGisSearch->Parent = this;
            }
            FrmGisSearch->Show();
        }
        else
        {
            if (FrmGisSearch)
            {
                if (FrmGisSearch->m_bClose == false)
                {
                    FrmGisSearch->Close();
                }
            }
        }
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FormCloseQuery(TObject *Sender, bool &CanClose)
{
    FRAMEOpenMap1->OnCloseQuery(CanClose);
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::DebugMsg(String AMsg)
{
    LblMsg->Caption = AMsg;
    LblMsg->Refresh();
    if (LblMsg->Visible == false) LblMsg->Visible = true;
    TmrDebugHide->Enabled = false;
    TmrDebugHide->Enabled = true;
    DebugLog(AMsg);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::DebugLog(String AMsg)
{
    if (TabDebug->Visible)
    {
        reMsg->Lines->Add(Now().FormatString("HH:NN:SS.ZZZ") + ": " + AMsg);
    }
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::TmrDebugHideTimer(TObject *Sender)
{
    LblMsg->Visible = false;
    TmrDebugHide->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::reMsgDblClick(TObject *Sender)
{
    reMsg->Lines->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMEAtmpPltnList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMEAtmpPltnList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sId = VarToStr(pGDC->Values[nRow][FRAMEAtmpPltnList1->Col00->Index]);
        String sDx = VarToStr(pGDC->Values[nRow][FRAMEAtmpPltnList1->Col30->Index]);
        String sDy = VarToStr(pGDC->Values[nRow][FRAMEAtmpPltnList1->Col31->Index]);
        SelectObjectByPos(StrToFloat(sDx), StrToFloat(sDy), true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMEVilgShprList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMEVilgShprList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sId = VarToStr(pGDC->Values[nRow][FRAMEVilgShprList1->Col00->Index]);
        String sDx = VarToStr(pGDC->Values[nRow][FRAMEVilgShprList1->Col20->Index]);
        String sDy = VarToStr(pGDC->Values[nRow][FRAMEVilgShprList1->Col21->Index]);
        SelectObjectByPos(StrToFloat(sDx), StrToFloat(sDy), true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::FRAMEVilgFrcsList1TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    if (!ACellViewInfo) return;
    try {
        TcxDataController *pGDC = FRAMEVilgFrcsList1->TvList->DataController;
        int nRow = pGDC->FocusedRecordIndex;
        if (nRow < 0) return;

        String sId = VarToStr(pGDC->Values[nRow][FRAMEVilgFrcsList1->Col00->Index]);
        String sDx = VarToStr(pGDC->Values[nRow][FRAMEVilgFrcsList1->Col20->Index]);
        String sDy = VarToStr(pGDC->Values[nRow][FRAMEVilgFrcsList1->Col21->Index]);
        SelectObjectByPos(StrToFloat(sDx), StrToFloat(sDy), true);
    } catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::PnlFacilityDblClick(TObject *Sender)
{
    FRAMEOpenMap1->ExecScript("getMapExtent()");
}
//---------------------------------------------------------------------------

void __fastcall TITS0000M::mnuParkMsgClick(TObject *Sender)
{
    Application->ProcessMessages();
    TPoint pt;
    GetCursorPos(&pt);
    pt = ITS0000M->ScreenToClient(pt);
    ShowParkingLotInfo(FSelId, pt);
}
//---------------------------------------------------------------------------
void __fastcall TITS0000M::ShowParkingLotInfo(String AId, TPoint pt)
{
    TItsFacility *pFacility = ItsFacilityManager->FLists.Find(AId);
    if (!pFacility) return;

    TPrltCtlr *pObj = (TPrltCtlr*)pFacility->Object;
    if (!pObj) return;

    try {
        if (pObj->FData1)
        {
            TFrmParkMsg *pForm = (TFrmParkMsg *)pObj->FData1;
            pForm->SetFocus();
        }
        else
        {
            TFrmParkMsg *pForm = new TFrmParkMsg(ITS0000M, pObj);
            pForm->Parent = ITS0000M;

            if ((pt.x + pForm->Width + 5) > this->Width)
            {
                pt.x = this->Width - pForm->Width - 5;
            }
            if ((pt.y + pForm->Height + 5) > this->Height)
            {
                pt.y = this->Height - pForm->Height - 5;
            }

            pForm->Left = Left + pt.x;
            pForm->Top  = Top  + pt.y;

            pObj->FData1 = (void*)pForm;
            pForm->Show();
        }
    } catch(...) {}
}
//---------------------------------------------------------------------------

