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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "ITSDbF.h"
#include "CDSIfscF.h"
#include "AppGlobalF.h"
#include "ITSLangTransF.h"
#include "ITSMapF.h"
#include "ITS_OPLibF.h"
#pragma hdrstop

#include "TAS0010MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalc"
#pragma link "cxCalendar"
#pragma link "cxClasses"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxDropDownEdit"
#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 "cxMaskEdit"
#pragma link "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "cxTextEdit"
#pragma link "cxTimeEdit"
#pragma link "cxTrackBar"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "FRAME_OpenMapF"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"

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

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

    FTitle = Caption;//"혼잡지도분석";

    FTargetIdx = 0;
    CbTarget->ItemIndex = FTargetIdx;

    FIfscMngr = new TTrafficValManager();

    CbLinkLevel->ItemIndex = 1; //IFSC
    FLinkLevel = CbLinkLevel->ItemIndex+1;
    FLayerIdx = LyrTp_Node;
    FRAMEOpenMap1->LayerIdx = FLayerIdx;
    FRAMEOpenMap1->ChkShowNmbr->Visible = false;
    FRAMEOpenMap1->BtnMoveMapToFit->Visible = false;
    FRAMEOpenMap1->MapCallbackFunc = TTAS0010M_MapCallback;
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::CommClose()
{
    try
    {
        if (BtnStop->Enabled)
            BtnStopClick((TObject*)BtnStop);

        delete FIfscMngr;

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

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

    FRAMEOpenMap1->OpenMap();

    FormInit();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::FormInit()
{
    ADOQry->Connection = ITSDb_GetConnection();
    ADOSta->Connection = ITSDb_GetConnection();

    m_pGDC = TvList->DataController;

    TDateTime dtNow = Now() - ((double)3 / (double)24);

    DtStDate->Date = dtNow;
    DtEdDate->Date = Now();

    //DtStTime->EditValue = dtNow.FormatString("hh") + ":00";
    dtNow = Now() - ((double)2 / (double)24);
    //DtEdTime->EditValue = dtNow.FormatString("hh") + ":59";

    DtStTime->Time = StrToDateTime(dtNow.FormatString("hh") + ":00");
    DtEdTime->Time = StrToDateTime(dtNow.FormatString("hh") + ":59");
}
//---------------------------------------------------------------------------

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

    if (TmrShow->Tag == 1)
    {
        int nIndex = m_pGDC->FocusedRecordIndex;
        if (nIndex < 0)
        {
            cxTrackBar1->Position = 0;
            FStatTime = "";

            BtnPlay->Enabled = true;
            BtnStop->Enabled = false;
            BtnSearch->Enabled = true;
            return;
        }

        if (m_pGDC->FocusedRecordIndex + 1 == m_pGDC->RecordCount)
        {
            cxTrackBar1->Position = 0;
            FStatTime = "";

            BtnPlay->Enabled = true;
            BtnStop->Enabled = false;
            BtnSearch->Enabled = true;
            return;
        }

        m_pGDC->FocusedRecordIndex++;
        nIndex = m_pGDC->FocusedRecordIndex;

        FSimIndex = nIndex;
        cxTrackBar1->Position = nIndex;
        FStatTime = VarToStr(m_pGDC->Values[nIndex][Column04->Index]);
        //cxGroupBox1->Caption = "▶ 소통정보 표출 - " + VarToStr(m_pGDC->Values[nIndex][Column02->Index]);
        cxGroupBox1->Caption = lblText1->Caption + " - " + VarToStr(m_pGDC->Values[nIndex][Column02->Index]);
        SelStatisticsHistory(FStatTime);


        BtnPlay->Enabled = false;
        BtnStop->Enabled = true;
        TmrShow->Interval = SeRefreshSec->Value * 1000;
        TmrShow->Enabled  = true;
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::InitGisLink()
{
    if (!FRAMEOpenMap1->MapStart) return;

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

                    if (pIfsc->IsVertex)
                    {
                        TTrafficVal* pTraf = new TTrafficVal();
                        pTraf->ID = pIfsc->IFSC_ID;
                        pTraf->IsUpdate = true;
                        pTraf->GRADE_VAL = 0;
                        FIfscMngr->FLists.Push(pTraf->ID, pTraf);

                        sJs.printf(L"addEditLink('%s', '%s', '%s', '%s', '%s', '%s')",
                            pIfsc->IFSC_ID.c_str(),
                            pIfsc->IFSC_NM.c_str(),
                            pIfsc->STRT_NM.c_str(),
                            pIfsc->END_NM.c_str(),
                            pIfsc->X_CRDN_ARR.c_str(),
                            pIfsc->Y_CRDN_ARR.c_str());

                        FRAMEOpenMap1->ExecScript(sJs);
                    }
                }
            }
            __finally
            {
                ItsIfscManager->FLists.UnLock();
            }
            FRAMEOpenMap1->ExecScript("makeEditLinkLayer()");
        }
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::BtnSearchClick(TObject *Sender)
{
    Application->ProcessMessages();
    TSqlCursor sqlCrs((TControl*)BtnSearch);

	FStDateTime = DtStDate->Date.FormatString("yyyymmdd") + DtStTime->Time.FormatString("hhnn");
	FEdDateTime = DtEdDate->Date.FormatString("yyyymmdd") + DtEdTime->Time.FormatString("hhnn");
    if (FStDateTime > FEdDateTime)
    {
        Application->MessageBox(FrmLang->lblQryDtErr->Caption.c_str(),//L"검색 시작시각이 검색 종료시각 보다 큽니다.",
                                FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        ActiveControl = DtStDate;
        return;
    }
	if (StrToInt(DtEdTime->Time.FormatString("hh")) - StrToInt(DtStTime->Time.FormatString("hh")) >= 3)
	{
        Application->MessageBox(lblText2->Caption.c_str(),//L"3시간 이상의 정보를 조회할 수 없습니다.",
                                FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        ActiveControl = DtStDate;
		return;
	}

    if (FLinkLevel != CbLinkLevel->ItemIndex+1)
    {
        //링크레벨을 고정하지 않고 변경할 경우 여기에서 링크 버텍스를 다시 로딩해 줘야 한다.
    }
    FLinkLevel = CbLinkLevel->ItemIndex+1;
    FTargetIdx = CbTarget->ItemIndex;

    switch(FTargetIdx)
    {
    case 0: //이력 정보(통계 5분 정보)
    case 1: //통계 15분 정보
        FStDateTime = FStDateTime + "00";
        FEdDateTime = FEdDateTime + "59";
        break;
    case 2: //패턴 5분 정보
    case 3: //패턴 15분 정보
        FStDateTime = FStDateTime;
        FEdDateTime = FEdDateTime;
        break;
    default: return;
    }

    SelHistory();

    ClearGis();
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::BtnCloseClick(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------

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

void __fastcall TTAS0010M::DtStDatePropertiesValidate(TObject *Sender, Variant &DisplayValue, TCaption &ErrorText, bool &Error)
{
    DtEdDate->Date = DtStDate->Date;
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::SelHistory()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    //select substr('20180108xxyy', 1, 6), substr('20180108xxyy', 9, 4) from dual

    switch(FTargetIdx)
    {
    case 0: //이력 정보(통계 5분 정보)
    sQry = "SELECT PRCN_DT AS PRCN_DT, COUNT(IFSC_ID) CNT \r\n"
         "  FROM TB_IFSC_TRAF_HS A                        \r\n"
         " WHERE PRCN_DT BETWEEN :p01 AND :p03            \r\n"
         " GROUP BY PRCN_DT                               \r\n"
         " ORDER BY PRCN_DT                               \r\n";
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        break;
    case 1: //통계 15분 정보
    sQry = "SELECT STAT_DT AS PRCN_DT, COUNT(IFSC_ID) CNT \r\n"
         "  FROM TB_IFSC_15M_STAT A                       \r\n"
         " WHERE STAT_DT BETWEEN :p01 AND :p03            \r\n"
         " GROUP BY STAT_DT                               \r\n"
         " ORDER BY STAT_DT                               \r\n";
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        break;
    case 2: //패턴 5분 정보
    sQry = "SELECT STAT_YM || ' ' || STAT_HM AS PRCN_DT, COUNT(IFSC_ID) CNT \r\n"
         "  FROM TB_IFSC_5M_PTRN A                                          \r\n"
         " WHERE STAT_YM = SUBSTR(:p01, 1, 6)                               \r\n"
         "   AND STAT_HM BETWEEN SUBSTR(:p02, 9, 4) AND SUBSTR(:p03, 9, 4)  \r\n"
         " GROUP BY STAT_YM || ' ' || STAT_HM                               \r\n"
         " ORDER BY STAT_YM || ' ' || STAT_HM                               \r\n";
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FStDateTime);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        break;
    case 3: //패턴 15분 정보
    sQry = "SELECT STAT_YM || ' ' || STAT_HM AS PRCN_DT, COUNT(IFSC_ID) CNT \r\n"
         "  FROM TB_IFSC_15M_PTRN A                                         \r\n"
         " WHERE STAT_YM = SUBSTR(:p01, 1, 6)                               \r\n"
         "   AND STAT_HM BETWEEN SUBSTR(:p02, 9, 4) AND SUBSTR(:p03, 9, 4)  \r\n"
         " GROUP BY STAT_YM || ' ' || STAT_HM                               \r\n"
         " ORDER BY STAT_YM || ' ' || STAT_HM                               \r\n";
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FStDateTime);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        break;
    }
    try
    {
        ITSDb_SQLOpen(pADO);

        DspHistory();
    }
    catch(EDatabaseError &E)
    {
        ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
        DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
        DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::DspHistory()
{
    TADOQuery *pADO = ADOQry;

    try
    {
        CMM_ClearGridTableView(TvList);

        int nRow = 0;
        try
        {
            TvList->BeginUpdate(lsimImmediate);
            m_pGDC->RecordCount = pADO->RecordCount;
            for( ; !pADO->Eof; pADO->Next(), nRow++)
            {
                m_pGDC->Values[nRow][Column01->Index] = nRow+1;

                //m_pGDC->Values[nRow][Column02->Index] = pADO->FieldByName("PRCN_DT2")->AsDateTime.DateTimeString();  //가공시각
                //m_pGDC->Values[nRow][Column02->Index] = ITSUtil_StrToTime(pADO->FieldByName("PRCN_DT")->AsString);  //가공시각
                m_pGDC->Values[nRow][Column02->Index] = pADO->FieldByName("PRCN_DT")->AsString;  //가공시각
                m_pGDC->Values[nRow][Column03->Index] = pADO->FieldByName("CNT")->AsInteger;
                m_pGDC->Values[nRow][Column04->Index] = pADO->FieldByName("PRCN_DT")->AsString;
            }
        }
        __finally
        {
            if (pADO)
            {
                pADO->Close();
            }

            TvList->EndUpdate();
            CxList->SetFocus();

            cxTrackBar1->Position = 0;
	        cxTrackBar1->Properties->Max = nRow;
	        cxTrackBar1->Properties->Frequency = cxTrackBar1->Properties->Max * 0.1;

            LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + FrmLang->lblEA->Caption;//" 건";

            String sEnd = FrmLang->lblQrySel->Caption + " [" + LblRecords->Caption + "]";//"데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
            Application->MessageBox(sEnd.c_str(),
                                    FrmLang->lblQryEnd->Caption.c_str(),//L"데이터 조회 완료",
                                    MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
    }
    catch(EDatabaseError &E)
    {
        ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
        DBERRORMSG(Caption, String(E.ClassName()), E.Message, pADO->SQL->Text);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
        DBERRORMSG(Caption, String(e.ClassName()), e.Message, pADO->SQL->Text);
        throw Exception(String(e.ClassName()) + e.Message);
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::BtnPlayClick(TObject *Sender)
{
    if (m_pGDC->RecordCount <= 0)
    {
        Application->MessageBox(lblText3->Caption.c_str(),//L"표출할 정보가 없습니다. 이력정보를 다시 조회하신 후 작업을 진행 하십시요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }

	m_pGDC->FocusedRecordIndex = 0;
	int nIndex = m_pGDC->FocusedRecordIndex;
	if (nIndex < 0) return;

    FSimIndex = nIndex;

    cxTrackBar1->Position = nIndex;
    FStatTime = VarToStr(m_pGDC->Values[nIndex][Column04->Index]);

    CxList->SetFocus();
    BtnPlay->Enabled = false;
    BtnStop->Enabled = true;
    BtnSearch->Enabled = false;

    //cxGroupBox1->Caption = "▶ 소통정보 표출 - " + VarToStr(m_pGDC->Values[nIndex][Column02->Index]);
    cxGroupBox1->Caption = lblText1->Caption + " - " + VarToStr(m_pGDC->Values[nIndex][Column02->Index]);
    SelStatisticsHistory(FStatTime);

    TmrShow->Tag = 1;
    TmrShow->Interval = SeRefreshSec->Value * 1000;
    TmrShow->Enabled  = true;
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::BtnStopClick(TObject *Sender)
{
    TmrShow->Enabled = false;
    BtnPlay->Enabled = true;
    BtnStop->Enabled = false;
    BtnSearch->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::SelStatisticsHistory(String AStatTime)
{
    int        ii;
    TSqlCursor sqlCrs;

    String     sQry;
    TADOQuery *pADO = ADOSta;

    switch(FTargetIdx)
    {
    case 0: //이력 정보
    sQry = "SELECT A.IFSC_ID, NVL(B.CMTR_GRAD_CD, 'LTC0') TRFGRD, C.SPED,       \r\n"
           "       C.PRCN_DT REGDATE                                            \r\n"
           "  FROM TB_IFSC           A,                                         \r\n"
           "       TB_SECT_GRAD_STUP B,                                         \r\n"
           "       TB_IFSC_TRAF_HS   C                                          \r\n"
           " WHERE A.IFSC_ID      = C.IFSC_ID                                   \r\n"
           "   AND A.SECT_GRAD_CD = B.SECT_GRAD_CD                              \r\n"
           "   AND (C.SPED >= B.LWST_TRVL_SPED AND C.SPED <= B.HGHS_TRVL_SPED)  \r\n"
           "   AND C.PRCN_DT = :p01                                             \r\n";

        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", AStatTime);
        break;
    case 1: //통계 15분 정보
    sQry = "SELECT A.IFSC_ID, NVL(B.CMTR_GRAD_CD, 'LTC0') TRFGRD, C.SPED,       \r\n"
           "       C.STAT_DT REGDATE                                            \r\n"
           "  FROM TB_IFSC           A,                                         \r\n"
           "       TB_SECT_GRAD_STUP B,                                         \r\n"
           "       TB_IFSC_15M_STAT  C                                          \r\n"
           " WHERE A.IFSC_ID      = C.IFSC_ID                                   \r\n"
           "   AND A.SECT_GRAD_CD = B.SECT_GRAD_CD                              \r\n"
           "   AND (C.SPED >= B.LWST_TRVL_SPED AND C.SPED <= B.HGHS_TRVL_SPED)  \r\n"
           "   AND C.STAT_DT = :p01                                             \r\n";

        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", AStatTime);
        break;
    case 2: //패턴 5분 정보
    sQry = "SELECT A.IFSC_ID, NVL(B.CMTR_GRAD_CD, 'LTC0') TRFGRD,               \r\n"
           "       C.SPED, C.STAT_YM || C.STAT_HM REGDATE                       \r\n"
           "  FROM TB_IFSC           A,                                         \r\n"
           "       TB_SECT_GRAD_STUP B,                                         \r\n"
           "       TB_IFSC_5M_PTRN   C                                          \r\n"
           " WHERE A.IFSC_ID      = C.IFSC_ID                                   \r\n"
           "   AND A.SECT_GRAD_CD = B.SECT_GRAD_CD                              \r\n"
           "   AND (C.SPED >= B.LWST_TRVL_SPED AND C.SPED <= B.HGHS_TRVL_SPED)  \r\n"
           "   AND C.STAT_YM = SUBSTR(:p01, 1, 6)                               \r\n"
           "   AND C.STAT_HM = SUBSTR(:p02, 8, 4)                               \r\n";

        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", AStatTime);
        ITSDb_SQLBind(pADO, "p02", AStatTime);
        break;
    case 3: //패턴 15분 정보
    sQry = "SELECT A.IFSC_ID, NVL(B.CMTR_GRAD_CD, 'LTC0') TRFGRD,               \r\n"
           "       C.SPED, C.STAT_YM || C.STAT_HM REGDATE                       \r\n"
           "  FROM TB_IFSC           A,                                         \r\n"
           "       TB_SECT_GRAD_STUP B,                                         \r\n"
           "       TB_IFSC_15M_PTRN  C                                          \r\n"
           " WHERE A.IFSC_ID      = C.IFSC_ID                                   \r\n"
           "   AND A.SECT_GRAD_CD = B.SECT_GRAD_CD                              \r\n"
           "   AND (C.SPED >= B.LWST_TRVL_SPED AND C.SPED <= B.HGHS_TRVL_SPED)  \r\n"
           "   AND C.STAT_YM = SUBSTR(:p01, 1, 6)                               \r\n"
           "   AND C.STAT_HM = SUBSTR(:p02, 8, 4)                               \r\n";

        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", AStatTime);
        ITSDb_SQLBind(pADO, "p02", AStatTime);
        break;
    }

    int nGradeCd;
    try
    {
        String sLinkInfo = "";

        ITSDb_SQLOpen(pADO);

        for( ; !pADO->Eof; pADO->Next())
        {
            String sID = pADO->FieldByName("IFSC_ID")->AsString;
            TTrafficVal *pTraf = FIfscMngr->FLists.Find(sID);
            if (pTraf)
            {
                String TRFGRD = pADO->FieldByName("TRFGRD")->AsString;

                if      (TRFGRD == "LTC1") nGradeCd = 1;
                else if (TRFGRD == "LTC2") nGradeCd = 2;
                else if (TRFGRD == "LTC3") nGradeCd = 3;
                else                       nGradeCd = 0;

                if (pTraf->GRADE_VAL != nGradeCd)
                {
                    pTraf->GRADE_VAL = nGradeCd;

                    sJs.printf(L"updateHistLink('%s', %d)", sID.c_str(), nGradeCd);
                    FRAMEOpenMap1->ExecScript(sJs);
                }
            }
        }
    }
    catch(EDatabaseError &E)
    {
        ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
        DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
        DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::ClearGis()
{
    cxGroupBox1->Caption = lblText1->Caption;//"▶ 소통정보 표출";
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    if (BtnPlay->Enabled == false) return;

	int nRow = m_pGDC->FocusedRecordIndex;
	if( nRow <= -1 )
		return;

    FStatTime = VarToStr(m_pGDC->Values[nRow][Column04->Index]);
    //cxGroupBox1->Caption = "▶ 소통정보 표출 - " + VarToStr(m_pGDC->Values[nRow][Column02->Index]);
    cxGroupBox1->Caption = lblText1->Caption + " - " + VarToStr(m_pGDC->Values[nRow][Column02->Index]);
    SelStatisticsHistory(FStatTime);
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::BtnSearch2Click(TObject *Sender)
{
    Application->ProcessMessages();

    if (!FRAMEOpenMap1->MapStart) return;

    String sLinkId = EdLinkId->Text.Trim();
    sJs.printf(L"extentLayerObject(%d, '%s')", LyrTp_Traffic, sLinkId.c_str());
    FRAMEOpenMap1->ExecScript(sJs);
}
//---------------------------------------------------------------------------

void __fastcall TTAS0010M::OpenMapCallback(TObject *ASender, const String AFunc, const String AArgs, const bool AFirst)
{
    try
    {
        if (AFirst)
        {
            //지도를 편집모드로 변경
            sJs.printf(L"setEditMode(%d, 1)", FLayerIdx);
            FRAMEOpenMap1->ExecScript(sJs);

            //편집레이어 생성
            FRAMEOpenMap1->ExecScript("initEditLayer()");

            FRAMEOpenMap1->ExecScript("setEditArrow(0)");
            FRAMEOpenMap1->ExecScript("setEditColor()");

            //배경링크레이어 생성
            InitGisLink();

            return;
        }
    }
    catch(Exception &exception)
    {
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TTAS0010M::DtStDateChange(TObject *Sender)
{
    DtEdDate->Date = DtStDate->Date;
}
//---------------------------------------------------------------------------

