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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "FrmResourceF.h"
#include "ITSLangTransF.h"
#pragma hdrstop

#include "FRAME_TrafficMissLinkListF.h"
#include "CDSNodeF.h"
#include "CDSLinkF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxClasses"
#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 "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma resource "*.dfm"
//TFRAMETrafficMissLinkList *FRAMETrafficMissLinkList;
//---------------------------------------------------------------------------
__fastcall TFRAMETrafficMissLinkList::TFRAMETrafficMissLinkList(TComponent* Owner)
    : TFrame(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());

    m_pGDC = TvList->DataController;

    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<현재 소통정보 결측구간이 없습니다>";

    FCodeLTC = ItsCodeManager->FLists.Find("LTC");
    FCodeCST = ItsCodeManager->FLists.Find("CST");
    FCodeMCS = ItsCodeManager->FLists.Find("MCS");
}
//---------------------------------------------------------------------------

void __fastcall TFRAMETrafficMissLinkList::UpdateList()
{
    TItsNode    *pNode;
    TCDSTraffic *pTraf;

    CMM_ClearGridTableView(TvList);

    int nRow = 0;
    try
    {
        TvList->BeginUpdate();

        TDateTime dtNow = Now();
        dtNow.Val -= (double)1;

        try
        {
            ItsLinkManager->FLists.Lock();
            FOR_STL(TItsLink *, pLink, ItsLinkManager->FLists)
            {
                pTraf = pLink->TRAF;
                // 24시간 이내의 데이터 체크
    //            if (YYYYMMDDHHNNSStoDateTime(pTraf->PRCN_DT).Val > dtNow.Val)
    //                continue;

#if 0
                if (pTraf->MPRCN_DT == pTraf->PRCN_DT)
                {
                    continue;
                }
#endif

                if (pLink->REGN_YN == "Y" && pTraf->MISS_YN == "Y" && pTraf->MISSING == "Y")
                {
                    nRow = m_pGDC->AppendRecord();

                    String sFNodeName = "[" + pLink->F_NODE_ID + "] ";
                    String sTNodeName = "[" + pLink->T_NODE_ID + "] ";

                    pNode = ItsNodeManager->FLists.Find(pLink->F_NODE_ID);
                    if (pNode) sFNodeName = sFNodeName + pNode->NODE_NAME;

                    pNode = ItsNodeManager->FLists.Find(pLink->T_NODE_ID);
                    if (pNode) sTNodeName = sTNodeName + pNode->NODE_NAME;

                    m_pGDC->Values[nRow][Column01->Index] = ITSUtil_StrToTime(pTraf->PRCN_DT);
                    m_pGDC->Values[nRow][Column02->Index] = pLink->LINK_ID;
                    m_pGDC->Values[nRow][Column03->Index] = sFNodeName;
                    m_pGDC->Values[nRow][Column04->Index] = sTNodeName;
                    m_pGDC->Values[nRow][Column05->Index] = pLink->ROAD_USE;
                    m_pGDC->Values[nRow][Column06->Index] = pLink->LANES;
                    m_pGDC->Values[nRow][Column07->Index] = pLink->ROAD_RANK;
                    m_pGDC->Values[nRow][Column08->Index] = pLink->ROAD_TYPE;
                    m_pGDC->Values[nRow][Column09->Index] = pLink->ROAD_NO;
                    m_pGDC->Values[nRow][Column10->Index] = pLink->ROAD_NAME;
                    m_pGDC->Values[nRow][Column11->Index] = pLink->MULTI_LINK;
                    m_pGDC->Values[nRow][Column12->Index] = pLink->LINK_CONNECT;
                    m_pGDC->Values[nRow][Column13->Index] = pLink->MAX_SPD;
                    m_pGDC->Values[nRow][Column14->Index] = pLink->REST_VEH;
                    m_pGDC->Values[nRow][Column15->Index] = pLink->REST_W;
                    m_pGDC->Values[nRow][Column16->Index] = pLink->REST_H;
                    m_pGDC->Values[nRow][Column17->Index] = pLink->LINK_LENG;
                    m_pGDC->Values[nRow][Column18->Index] = pLink->RMRK;
                }
            }
        }
        __finally
        {
            ItsLinkManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

