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

#include <vcl.h>
#include "AppGlobalF.h"
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "ITSDbF.h"
#include "ITSLogF.h"
#include "ITSLangTransF.h"
#include "CDSCrossF.h"
#pragma hdrstop

#include "FrmCrsTrafVolDirSubF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalc"
#pragma link "cxCheckBox"
#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 "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "cxTextEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxLabel"
#pragma link "cxGridBandedTableView"
#pragma link "cxSpinEdit"
#pragma link "FRAME_ChartF"
#pragma link "cxDropDownEdit"
#pragma link "cxMaskEdit"
#pragma resource "*.dfm"

//TFrmCrsTrafVolDirSub *FrmCrsTrafVolDirSub = NULL;

//---------------------------------------------------------------------------
__fastcall TFrmCrsTrafVolDirSub::TFrmCrsTrafVolDirSub(TComponent* Owner, HWND hHandle, String sFrom, String sTo, String sCrossId, String sCamId, int nStatType, bool isLane, TCross *pObj)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    //CMM_LoadForm(g_sFormsDir, this);

    FParent     = hHandle;
    FStDateTime = sFrom;
    FEdDateTime = sTo;
    FCrossId    = sCrossId;
    FCamId      = sCamId;
    FStatType   = nStatType;
    FLane       = isLane;
    FCrossObj   = pObj;
    FCrossNm    = FCrossObj->IXR_NM;
    FCamNm      = "";

    Col05->Visible = FLane;

    int bandIdx = 1;
    int colIdx = ColD10->Index;
    for (int ii = bandIdx; ii <= 10; ii++)
    {
        TvList->Bands->Items[ii]->Visible = false;
        TvList->Bands->Items[ii]->VisibleForCustomization = false;
        TvList->Columns[colIdx]->Visible = false;
        TvList->Columns[colIdx]->VisibleForCustomization = false;
        colIdx++;
    }

    bandIdx = 1;
    colIdx = ColD10->Index;
    FOR_STL(TCrossCam*, pCam, FCrossObj->FLists)
    {
        TvList->Bands->Items[bandIdx]->Caption = pCam->CMRA_NM;
        TvList->Bands->Items[bandIdx]->Visible = true;
        TvList->Bands->Items[bandIdx]->VisibleForCustomization = true;
        TvList->Columns[colIdx]->Caption = pCam->DRCT_DVSN_NM;
        TvList->Columns[colIdx]->Visible = true;
        TvList->Columns[colIdx]->VisibleForCustomization = true;
        if (FStatType > 1) {
            // 30분 통계 부터 유턴교통량 데이터가 존재하지 않음.
            TcxGridBandedColumn *pColumn = (TcxGridBandedColumn*)FindComponent("ColD" + IntToStr(bandIdx) + "U");
            if (pColumn) {
                pColumn->Visible = false;
            }
        }

        if (FStatType != 1 && FStatType != 3) {
            // 서비스수준(15분, 1시간)
            TcxGridBandedColumn *pColumn = (TcxGridBandedColumn*)FindComponent("ColD" + IntToStr(bandIdx) + "S");
            if (pColumn) {
                pColumn->Visible = false;
            }
        }


        bandIdx++;
        colIdx++;
        if (bandIdx >=11) {
            break;
        }
    }

    if (FLane)
    {
        //차선별 이력일 경우 차트를 그리지 않는다
        PnlChart->Visible = false;
        spltChart->Visible = false;
    }
    else
    {
        FRAMEChart1->LblOptionName->Caption = "카메라";
        FRAMEChart1->LblOptionName->Visible = true;
        FRAMEChart1->CbOption->Visible = true;
    }
    FRAMEChart1->LblOptionName->Visible = false;
    FRAMEChart1->CbOption->Visible = false;
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::FormInit()
{
    ADOQry->Connection = ITSDb_GetConnection();
    m_pGDC = TvList->DataController;

    TvList->OptionsView->NoDataToDisplayInfoText = Caption + ":  " + lblText1->Caption;//조회결과가 없습니다.";

    FRAMEChart1->FTitle = Caption;//"시설물 통신단절통계";
    FRAMEChart1->SetChartLegend("시간", "교통량");
    FRAMEChart1->ChartValueDisplay(FRAMEChart1->ChkDisplayVal->Checked);
    FRAMEChart1->TvChart->ToolBox->CustomizeButton = true;
    FRAMEChart1->TvChart->Legend->Position = cppDefault;
    FRAMEChart1->TvChart->DiagramStackedBar->Enabled = true;
    FRAMEChart1->TvChart->DiagramStackedColumn->Enabled = true;
    FRAMEChart1->TvChart->DiagramStackedColumn->Active = true;
    //FRAMEChart1->TvChart->DiagramColumn->Active = true;

    if (!FLane) FillChartOptions();

    LblSearch->Caption = lblText2->Caption + FStDateTime.SubString(1, 12) + " ~ " + FEdDateTime.SubString(1, 12);
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::FillChartOptions()
{
#if 0
    FRAMEChart1->CbOption->Properties->OnChange = NULL;
    FRAMEChart1->CbOption->Properties->Items->Clear();

    TCross* pCross = CrossManager->FLists.Find(FCrossId);
    if (pCross)
    {
        if (FCamNm == "*ALL*")
        {
            FOR_STL(TCrossCam*, pCam, pCross->FLists)
            {
                FRAMEChart1->CbOption->Properties->Items->Add("[" + pCam->CMRA_ID + "] " + pCam->CMRA_NM);
            }
        }
        else
        {
            String sCamId = StringReplace(FCamId, "'", "", TReplaceFlags() << rfReplaceAll);
            FRAMEChart1->CbOption->Properties->Items->Add("[" + sCamId + "] " + FCamNm);
        }
    }

    FRAMEChart1->CbOption->ItemIndex = 0;

    FRAMEChart1->CbOption->Properties->OnChange = CbOptionPropertiesChange;
#endif
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::FormShow(TObject *Sender)
{
    FormInit();
    Refresh();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::CommClose()
{
    //CMM_SaveForm(g_sFormsDir, this);
    //FrmVmsLogSub = NULL;
}
//---------------------------------------------------------------------------

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

    if (FLane)
    {
        switch(FStatType)
        {
        case 0: Sel05M_Lane(); break; //5분
        case 1: Sel15M_Lane(); break; //15분
        case 2: Sel30M_Lane(); break; //30분
        case 3: Sel60M_Lane(); break; //1시간
        case 4: SelDay_Lane(); break; //일
        case 5: SelMonth_Lane(); break; //월
        }
    }
    else
    {
        switch(FStatType)
        {
        case 0: Sel05M(); break; //5분
        case 1: Sel15M(); break; //15분
        case 2: Sel30M(); break; //30분
        case 3: Sel60M(); break; //1시간
        case 4: SelDay(); break; //일
        case 5: SelMonth(); break; //월
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::ChkExpandClick(TObject *Sender)
{
    CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel05M()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       A.CMRA_ID AS cmraId,                                                                         \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       NVL(MIN(A.LANE), 0) AS lane,                                                                 \r\n"
           "       NVL(MIN(A.INTL_ATMP_HEAT_LNGT), 0) AS intlAtmpHeatLngt,                                      \r\n"
           "       NVL(ROUND(AVG(A.OCPY_RATE), 2), 0) AS ocpyRate,                                              \r\n"
           "       NVL(SUM(A.WALK_CNT), 0) AS walkCnt,                                                          \r\n"
           "       NVL(SUM(A.LRG_GO_TFVL), 0) AS lrgGoTfvl,                                                     \r\n"
           "       NVL(SUM(A.MDDL_GO_TFVL), 0) AS mddlGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.SMAL_GO_TFVL), 0) AS smalGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.LRG_LEFT_TFVL), 0) AS lrgLeftTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_LEFT_TFVL), 0) AS mddlLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_LEFT_TFVL), 0) AS smalLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.LRG_RGHT_TFVL), 0) AS lrgRghtTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_RGHT_TFVL), 0) AS mddlRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_RGHT_TFVL), 0) AS smalRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.UTURN_TFVL), 0) AS uturnTfvl,                                                      \r\n"
           "       NVL(ROUND(AVG(A.SPEED), 0), 0) AS sped,                                                      \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_GO_TFVL), 0) AS busDvrsLaneGoTfvl,                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_LEFT_TFVL), 0) AS busDvrsLaneLeftTfvl,                               \r\n"
           "       NVL(SUM(A.BIKE_GO_TFVL), 0) AS bikeGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.BIKE_LEFT_TFVL), 0) AS bikeLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.BIKE_RGHT_TFVL), 0) AS bikeRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.ILG_WALK_CNT), 0) AS iglWalkCnt,                                                   \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       COUNT(1) AS dataCnt                                                                          \r\n"
           "  FROM TB_SC_IMGN_DTCT_RAW_CLCT A                                                                   \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " GROUP BY A.IXR_ID, A.CMRA_ID, A.DRCT_DVSN_CD, A.CLCT_DT                                            \r\n"
           " ORDER BY A.IXR_ID, A.CMRA_ID, A.DRCT_DVSN_CD, A.CLCT_DT                                            \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel05M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel05M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel05M_Lane()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       A.CMRA_ID AS cmraId,                                                                         \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       NVL(A.UTURN_TFVL, 0) AS uturnTfvl,                                                           \r\n"
           "       NVL(A.SPEED, 0) AS sped,                                                                     \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       NVL(A.BIKE_GO_TFVL, 0) AS bikeGoTfvl,                                                        \r\n"
           "       NVL(A.BIKE_LEFT_TFVL, 0) AS bikeLeftTfvl,                                                    \r\n"
           "       NVL(A.BIKE_RGHT_TFVL, 0) AS bikeRghtTfvl,                                                    \r\n"
           "       NVL(A.ILG_WALK_CNT, 0) AS iglWalkCnt,                                                        \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_IMGN_DTCT_RAW_CLCT A                                                                   \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.CMRA_ID, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                                    \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel05M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel05M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel15M()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       0 AS lane,                                                                                   \r\n"
           "       NVL(MIN(A.INTL_ATMP_HEAT_LNGT), 0) AS intlAtmpHeatLngt,                                      \r\n"
           "       NVL(ROUND(AVG(A.OCPY_RATE), 2), 0) AS ocpyRate,                                              \r\n"
           "       NVL(SUM(A.WALK_CNT), 0) AS walkCnt,                                                          \r\n"
           "       NVL(SUM(A.LRG_GO_TFVL), 0) AS lrgGoTfvl,                                                     \r\n"
           "       NVL(SUM(A.MDDL_GO_TFVL), 0) AS mddlGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.SMAL_GO_TFVL), 0) AS smalGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.LRG_LEFT_TFVL), 0) AS lrgLeftTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_LEFT_TFVL), 0) AS mddlLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_LEFT_TFVL), 0) AS smalLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.LRG_RGHT_TFVL), 0) AS lrgRghtTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_RGHT_TFVL), 0) AS mddlRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_RGHT_TFVL), 0) AS smalRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.UTURN_TFVL), 0) AS uturnTfvl,                                                      \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_GO_TFVL), 0) AS busDvrsLaneGoTfvl,                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_LEFT_TFVL), 0) AS busDvrsLaneLeftTfvl,                               \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       NVL(MIN(A.SRVC_LVL), 0) AS srvcLvl,                                                          \r\n"
           "       COUNT(1) AS dataCnt                                                                          \r\n"
           "  FROM TB_SC_ACRD_15MM_STAT A                                                                       \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " GROUP BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel15M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel15M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel15M_Lane()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

#if 0
    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       NVL(A.UTURN_TFVL, 0) AS uturnTfvl,                                                           \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       A.SRVC_LVL AS srvcLvl,                                                                       \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_ACRD_15MM_STAT A                                                                       \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                               \r\n";
           " ORDER BY B.CROSS_ID, A.DRCT_DVSN_CD, A.STAT_DT, A.LANE                                             \r\n";
#else
    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       A.CMRA_ID AS cmraId,                                                                         \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       NVL(A.UTURN_TFVL, 0) AS uturnTfvl,                                                           \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_LANE_15MM_STAT A                                                                       \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                               \r\n";
           " ORDER BY B.CROSS_ID, A.DRCT_DVSN_CD, A.STAT_DT, A.LANE                                             \r\n";
#endif

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel15M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel15M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel30M()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       0 AS lane,                                                                                   \r\n"
           "       NVL(MIN(A.INTL_ATMP_HEAT_LNGT), 0) AS intlAtmpHeatLngt,                                      \r\n"
           "       NVL(ROUND(AVG(A.OCPY_RATE), 2), 0) AS ocpyRate,                                              \r\n"
           "       NVL(SUM(A.WALK_CNT), 0) AS walkCnt,                                                          \r\n"
           "       NVL(SUM(A.LRG_GO_TFVL), 0) AS lrgGoTfvl,                                                     \r\n"
           "       NVL(SUM(A.MDDL_GO_TFVL), 0) AS mddlGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.SMAL_GO_TFVL), 0) AS smalGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.LRG_LEFT_TFVL), 0) AS lrgLeftTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_LEFT_TFVL), 0) AS mddlLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_LEFT_TFVL), 0) AS smalLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.LRG_RGHT_TFVL), 0) AS lrgRghtTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_RGHT_TFVL), 0) AS mddlRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_RGHT_TFVL), 0) AS smalRghtTfvl,                                               \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_GO_TFVL), 0) AS busDvrsLaneGoTfvl,                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_LEFT_TFVL), 0) AS busDvrsLaneLeftTfvl,                               \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       NVL(MIN(A.SRVC_LVL), 0) AS srvcLvl,                                                          \r\n"
           "       COUNT(1) AS dataCnt                                                                          \r\n"
           "  FROM TB_SC_ACRD_30MM_STAT A                                                                       \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " GROUP BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel30M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel30M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel30M_Lane()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24:MI') AS dspDt,                                           \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       A.SRVC_LVL AS srvcLvl,                                                                       \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_ACRD_30MM_STAT A                                                                       \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                               \r\n";
           " ORDER BY B.CROSS_ID, A.DRCT_DVSN_CD, A.STAT_DT, A.LANE                                             \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel30M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel30M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel60M()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24') AS dspDt,                                              \r\n"
           "       0 AS lane,                                                                                   \r\n"
           "       NVL(MIN(A.INTL_ATMP_HEAT_LNGT), 0) AS intlAtmpHeatLngt,                                      \r\n"
           "       NVL(ROUND(AVG(A.OCPY_RATE), 2), 0) AS ocpyRate,                                              \r\n"
           "       NVL(SUM(A.WALK_CNT), 0) AS walkCnt,                                                          \r\n"
           "       NVL(SUM(A.LRG_GO_TFVL), 0) AS lrgGoTfvl,                                                     \r\n"
           "       NVL(SUM(A.MDDL_GO_TFVL), 0) AS mddlGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.SMAL_GO_TFVL), 0) AS smalGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.LRG_LEFT_TFVL), 0) AS lrgLeftTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_LEFT_TFVL), 0) AS mddlLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_LEFT_TFVL), 0) AS smalLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.LRG_RGHT_TFVL), 0) AS lrgRghtTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_RGHT_TFVL), 0) AS mddlRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_RGHT_TFVL), 0) AS smalRghtTfvl,                                               \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_GO_TFVL), 0) AS busDvrsLaneGoTfvl,                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_LEFT_TFVL), 0) AS busDvrsLaneLeftTfvl,                               \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       NVL(MIN(A.SRVC_LVL), 0) AS srvcLvl,                                                          \r\n"
           "       COUNT(1) AS dataCnt                                                                          \r\n"
           "  FROM TB_SC_ACRD_HH_STAT A                                                                         \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " GROUP BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel60M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel60M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Sel60M_Lane()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD HH24') AS dspDt,                                              \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       A.SRVC_LVL AS srvcLvl,                                                                       \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_ACRD_HH_STAT A                                                                         \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                               \r\n";
           " ORDER BY B.CROSS_ID, A.DRCT_DVSN_CD, A.STAT_DT, A.LANE                                             \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel60M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::Sel60M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::SelDay()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD') AS dspDt,                                                   \r\n"
           "       0 AS lane,                                                                                   \r\n"
           "       NVL(MIN(A.INTL_ATMP_HEAT_LNGT), 0) AS intlAtmpHeatLngt,                                      \r\n"
           "       NVL(ROUND(AVG(A.OCPY_RATE), 2), 0) AS ocpyRate,                                              \r\n"
           "       NVL(SUM(A.WALK_CNT), 0) AS walkCnt,                                                          \r\n"
           "       NVL(SUM(A.LRG_GO_TFVL), 0) AS lrgGoTfvl,                                                     \r\n"
           "       NVL(SUM(A.MDDL_GO_TFVL), 0) AS mddlGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.SMAL_GO_TFVL), 0) AS smalGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.LRG_LEFT_TFVL), 0) AS lrgLeftTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_LEFT_TFVL), 0) AS mddlLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_LEFT_TFVL), 0) AS smalLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.LRG_RGHT_TFVL), 0) AS lrgRghtTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_RGHT_TFVL), 0) AS mddlRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_RGHT_TFVL), 0) AS smalRghtTfvl,                                               \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_GO_TFVL), 0) AS busDvrsLaneGoTfvl,                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_LEFT_TFVL), 0) AS busDvrsLaneLeftTfvl,                               \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       COUNT(1) AS dataCnt                                                                          \r\n"
           "  FROM TB_SC_ACRD_DD_STAT A                                                                         \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " GROUP BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelDay", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelDay", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::SelDay_Lane()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM-DD') AS dspDt,                                                   \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_ACRD_DD_STAT A                                                                         \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                               \r\n";
           " ORDER BY B.CROSS_ID, A.DRCT_DVSN_CD, A.STAT_DT, A.LANE                                             \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelDay_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelDay_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::SelMonth()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM') AS dspDt,                                                      \r\n"
           "       0 AS lane,                                                                                   \r\n"
           "       NVL(MIN(A.INTL_ATMP_HEAT_LNGT), 0) AS intlAtmpHeatLngt,                                      \r\n"
           "       NVL(ROUND(AVG(A.OCPY_RATE), 2), 0) AS ocpyRate,                                              \r\n"
           "       NVL(SUM(A.WALK_CNT), 0) AS walkCnt,                                                          \r\n"
           "       NVL(SUM(A.LRG_GO_TFVL), 0) AS lrgGoTfvl,                                                     \r\n"
           "       NVL(SUM(A.MDDL_GO_TFVL), 0) AS mddlGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.SMAL_GO_TFVL), 0) AS smalGoTfvl,                                                   \r\n"
           "       NVL(SUM(A.LRG_LEFT_TFVL), 0) AS lrgLeftTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_LEFT_TFVL), 0) AS mddlLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_LEFT_TFVL), 0) AS smalLeftTfvl,                                               \r\n"
           "       NVL(SUM(A.LRG_RGHT_TFVL), 0) AS lrgRghtTfvl,                                                 \r\n"
           "       NVL(SUM(A.MDDL_RGHT_TFVL), 0) AS mddlRghtTfvl,                                               \r\n"
           "       NVL(SUM(A.SMAL_RGHT_TFVL), 0) AS smalRghtTfvl,                                               \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_GO_TFVL), 0) AS busDvrsLaneGoTfvl,                                   \r\n"
           "       NVL(SUM(A.BUS_DVRS_LANE_LEFT_TFVL), 0) AS busDvrsLaneLeftTfvl,                               \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       COUNT(1) AS dataCnt                                                                          \r\n"
           "  FROM TB_SC_ACRD_MN_STAT A                                                                         \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " GROUP BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.DRCT_DVSN_CD, A.CLCT_DT                                       \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelMonth", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelMonth", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::SelMonth_Lane()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry = "SELECT A.IXR_ID AS ixrId,                                                                           \r\n"
           "       'X' AS cmraId,                                                                               \r\n"
           "       A.DRCT_DVSN_CD AS drctDvsnCd,                                                                \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYYMMDDHH24MISS') AS statDt,                                            \r\n"
           "       TO_CHAR(A.CLCT_DT, 'YYYY-MM') AS dspDt,                                                      \r\n"
           "       NVL(A.LANE, 0) AS lane,                                                                      \r\n"
           "       NVL(A.INTL_ATMP_HEAT_LNGT, 0) AS intlAtmpHeatLngt,                                           \r\n"
           "       NVL(A.OCPY_RATE, 0) AS ocpyRate,                                                             \r\n"
           "       NVL(A.WALK_CNT, 0) AS walkCnt,                                                               \r\n"
           "       NVL(A.LRG_GO_TFVL, 0) AS lrgGoTfvl,                                                          \r\n"
           "       NVL(A.MDDL_GO_TFVL, 0) AS mddlGoTfvl,                                                        \r\n"
           "       NVL(A.SMAL_GO_TFVL, 0) AS smalGoTfvl,                                                        \r\n"
           "       NVL(A.LRG_LEFT_TFVL, 0) AS lrgLeftTfvl,                                                      \r\n"
           "       NVL(A.MDDL_LEFT_TFVL, 0) AS mddlLeftTfvl,                                                    \r\n"
           "       NVL(A.SMAL_LEFT_TFVL, 0) AS smalLeftTfvl,                                                    \r\n"
           "       NVL(A.LRG_RGHT_TFVL, 0) AS lrgRghtTfvl,                                                      \r\n"
           "       NVL(A.MDDL_RGHT_TFVL, 0) AS mddlRghtTfvl,                                                    \r\n"
           "       NVL(A.SMAL_RGHT_TFVL, 0) AS smalRghtTfvl,                                                    \r\n"
           "       0 AS uturnTfvl,                                                                              \r\n"
           "       0 AS sped,                                                                                   \r\n"
           "       NVL(A.BUS_DVRS_LANE_GO_TFVL, 0) AS busDvrsLaneGoTfvl,                                        \r\n"
           "       NVL(A.BUS_DVRS_LANE_LEFT_TFVL, 0) AS busDvrsLaneLeftTfvl,                                    \r\n"
           "       0 AS bikeGoTfvl,                                                                             \r\n"
           "       0 AS bikeLeftTfvl,                                                                           \r\n"
           "       0 AS bikeRghtTfvl,                                                                           \r\n"
           "       0 AS iglWalkCnt,                                                                             \r\n"
           "       0 AS srvcLvl,                                                                                \r\n"
           "       1 AS dataCnt                                                                                 \r\n"
           "  FROM TB_SC_ACRD_MN_STAT A                                                                         \r\n"
           " WHERE A.IXR_ID  = :p01                                                                             \r\n"
           "   AND A.CLCT_DT BETWEEN TO_DATE(:p02, 'YYYYMMDDHH24MISS') AND TO_DATE(:p03, 'YYYYMMDDHH24MISS')    \r\n"
           " ORDER BY A.IXR_ID, A.DRCT_DVSN_CD, A.LANE, A.DRCT_DVSN_CD, A.CLCT_DT                               \r\n";
           " ORDER BY B.CROSS_ID, A.DRCT_DVSN_CD, A.STAT_DT, A.LANE                                             \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FCrossId);
        ITSDb_SQLBind(pADO, "p02", FStDateTime);
        ITSDb_SQLBind(pADO, "p03", FEdDateTime);
        ITSDb_SQLOpen(pADO);
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelMonth_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelMonth_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    SelHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::SelHistory()
{
    TADOQuery *pADO = ADOQry;

    try
    {
        int nRow = 0;
        int nDataCnt = 0;
        try {
            nDataCnt = pADO->RecordCount;

            for( ; !pADO->Eof; pADO->Next(), nRow++)
            {
                String IXR_ID = pADO->FieldByName("ixrId")->AsString;
                TCrossVol *pCrossVol = FLists.Find(IXR_ID);
                if (!pCrossVol)
                {
                    pCrossVol = new TCrossVol();
                    if (!pCrossVol) continue;

                    pCrossVol->IXR_ID = IXR_ID;
                    pCrossVol->IXR_NM = "["+FCrossObj->IXR_ID+"] " + FCrossObj->IXR_NM;
                    FLists.Push(IXR_ID, pCrossVol);
                }

                String DSP_DATE = pADO->FieldByName("dspDt")->AsString;
                TDspVol *pDspVol = pCrossVol->FLists.Find(DSP_DATE);
                if (!pDspVol)
                {
                    pDspVol = new TDspVol();
                    if (!pDspVol) continue;

                    pDspVol->DSP_DATE = DSP_DATE;
                    pCrossVol->FLists.Push(DSP_DATE, pDspVol);
                }

                String LANE = "0";
                if (FLane) LANE = pADO->FieldByName("lane")->AsString;
                TLaneVol *pLaneVol = pDspVol->FLists.Find(LANE);
                if (!pLaneVol)
                {
                    pLaneVol = new TLaneVol();
                    if (!pLaneVol) continue;

                    pLaneVol->LANE = LANE;
                    pLaneVol->VOL  = 0;
                    pDspVol->FLists.Push(LANE, pLaneVol);
                }

                TCamVol *pCamVol = new TCamVol();
                if (!pLaneVol)
                {
                    continue;
                }

                String CMRA_ID = pADO->FieldByName("cmraId")->AsString;
                if (CMRA_ID == "X") {
                    int DRCT_DVSN_CD = pADO->FieldByName("drctDvsnCd")->AsInteger;
                    FOR_STL(TCrossCam*, pCam, FCrossObj->FLists)
                    {
                        if (pCam->DRCT_DVSN_CD == DRCT_DVSN_CD) {
                            CMRA_ID = pCam->CMRA_ID;
                            break;
                        }
                    }
                }

                pCamVol->CMRA_ID = CMRA_ID;
                pLaneVol->FLists.Push(CMRA_ID, pCamVol);

                int G1 = pADO->FieldByName("lrgGoTfvl")->AsInteger;
                int G2 = pADO->FieldByName("mddlGoTfvl")->AsInteger;
                int G3 = pADO->FieldByName("smalGoTfvl")->AsInteger;
                int G4 = 0;//pADO->FieldByName("busDvrsLaneGoTfvl")->AsInteger;
                int G5 = 0;//pADO->FieldByName("bikeGoTfvl")->AsInteger;
                pCamVol->G = G1+G2+G3+G4+G5;

                int L1 = pADO->FieldByName("lrgLeftTfvl")->AsInteger;
                int L2 = pADO->FieldByName("mddlLeftTfvl")->AsInteger;
                int L3 = pADO->FieldByName("smalLeftTfvl")->AsInteger;
                int L4 = 0;//pADO->FieldByName("busDvrsLaneLeftTfvl")->AsInteger;
                int L5 = 0;//pADO->FieldByName("bikeLeftTfvl")->AsInteger;
                pCamVol->L = L1+L2+L3+L4+L5;

                int R1 = pADO->FieldByName("lrgRghtTfvl")->AsInteger;
                int R2 = pADO->FieldByName("mddlRghtTfvl")->AsInteger;
                int R3 = pADO->FieldByName("smalRghtTfvl")->AsInteger;
                int R4 = 0;
                int R5 = 0;//pADO->FieldByName("bikeRghtTfvl")->AsInteger;
                pCamVol->R = R1+R2+R3+R4+R5;

                int U1 = pADO->FieldByName("uturnTfvl")->AsInteger;
                int U2 = 0;
                int U3 = 0;
                pCamVol->U = U1+U2+U3;

                pCamVol->SRVC_LVL = pADO->FieldByName("srvcLvl")->AsString;

                pLaneVol->VOL += pCamVol->Total();
                pLaneVol->SRVC_LVL = pCamVol->SRVC_LVL;


#if 0
                m_pGDC->Values[nRow][Col03->Index] = pADO->FieldByName("CMRA_NM")->AsString;
                m_pGDC->Values[nRow][Col06->Index] = pADO->FieldByName("ocpyRate")->AsFloat;
                m_pGDC->Values[nRow][Col07->Index] = pADO->FieldByName("VOL")->AsInteger;
                m_pGDC->Values[nRow][Col08->Index] = pADO->FieldByName("sped")->AsInteger;
                m_pGDC->Values[nRow][Col09->Index] = pADO->FieldByName("intlAtmpHeatLngt")->AsInteger;
                m_pGDC->Values[nRow][Col10->Index] = pADO->FieldByName("walkCnt")->AsInteger;
                m_pGDC->Values[nRow][Col10->Index] = pADO->FieldByName("iglWalkCnt")->AsInteger;
#endif
            }
        }
        __finally
        {
            if (pADO)
            {
                pADO->Close();
            }
            DspHistory();
        }
    }
    catch(EDatabaseError &E)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelHistory", String(E.ClassName()), E.Message, pADO->SQL->Text);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolDirSub::SelHistory", String(e.ClassName()), e.Message, pADO->SQL->Text);
        throw Exception(String(e.ClassName()) + e.Message);
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::DspHistory()
{
    try
    {
        CMM_ClearGridTableView(TvList);

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

            FOR_STL(TCrossVol*, pCrossVol, FLists)
            {
                FOR_STL(TDspVol*, pDspVol, pCrossVol->FLists)
                {
                    FOR_STL(TLaneVol*, pLaneVol, pDspVol->FLists)
                    {
                        nRow = m_pGDC->AppendRecord();

                        m_pGDC->Values[nRow][ColCrossId->Index] = pCrossVol->IXR_ID;

                        m_pGDC->Values[nRow][Col01->Index] = nRow+1;
                        m_pGDC->Values[nRow][Col02->Index] = pCrossVol->IXR_NM;
                        m_pGDC->Values[nRow][Col04->Index] = pDspVol->DSP_DATE;
                        m_pGDC->Values[nRow][Col05->Index] = pLaneVol->LANE;
                        m_pGDC->Values[nRow][Col07->Index] = pLaneVol->VOL;

                        int dirIdx = ColD10->Index;
                        int volIdx = ColD1G->Index;
                        FOR_STL(TCrossCam*, pCam, FCrossObj->FLists)
                        {
                            TCamVol *pCamVol = pLaneVol->FLists.Find(pCam->CMRA_ID);
                            if (pCamVol) {
                                m_pGDC->Values[nRow][dirIdx]   = pCamVol->Total();
                                m_pGDC->Values[nRow][volIdx++] = pCamVol->G;
                                m_pGDC->Values[nRow][volIdx++] = pCamVol->L;
                                m_pGDC->Values[nRow][volIdx++] = pCamVol->R;
                                m_pGDC->Values[nRow][volIdx++] = pCamVol->U;
                                m_pGDC->Values[nRow][volIdx++] = pCamVol->SRVC_LVL;
                            }
                            else {
                                m_pGDC->Values[nRow][dirIdx]   = 0;
                                m_pGDC->Values[nRow][volIdx++] = 0;
                                m_pGDC->Values[nRow][volIdx++] = 0;
                                m_pGDC->Values[nRow][volIdx++] = 0;
                                m_pGDC->Values[nRow][volIdx++] = 0;
                                m_pGDC->Values[nRow][volIdx++] = "";
                            }
                            dirIdx++;
                        }
                    }
                }
            }
        }
        __finally
        {
            TvList->EndUpdate();
            if (!FLane)
            {
                DspChart();
            }
            LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + lblCnt->Caption;//" 건";

            String sEnd = "데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
            Application->MessageBox(sEnd.c_str(), L"데이터 조회 완료", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
    }
    catch(EDatabaseError &E)
    {
        //DBERRORMSG("History Results", String(E.ClassName()), E.Message, pADO->SQL->Text);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        //DBERRORMSG("History Results", String(e.ClassName()), e.Message, pADO->SQL->Text);
        throw Exception(String(e.ClassName()) + e.Message);
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::DspChart()
{
    FRAMEChart1->ChartValueDisplay(FRAMEChart1->ChkDisplayVal->Checked);
    TcxGridChartView *TvChart = FRAMEChart1->TvChart;

    try
    {
        TvChart->ClearSeries();
        TvChart->DataController->RecordCount = 0;

        //String sSelCamId = APP_GetCode(FRAMEChart1->CbOption);
        //if (sSelCamId == "") return;

    	TcxGridChartSeries *pChart[10];
        for (int ii = 0; ii < 10; ii++)
        {
            pChart[ii] = NULL;
        }

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

            int idx = 0;
            FOR_STL(TCrossCam*, pCam, FCrossObj->FLists)
            {
                pChart[idx] = TvChart->CreateSeries();
                pChart[idx]->DataBinding->ValueType = "Integer";
                pChart[idx]->DisplayText = pCam->CMRA_NM;
                idx++;
                if (idx == 10) break;
			}

            int nRowCnt = TvList->DataController->RecordCount;
            for (int ii = 0; ii < nRowCnt; ii++)
            {
                String sCrossId = TvList->DataController->Values[ii][ColCrossId->Index];
                if (FCrossId != sCrossId) continue;

                nRow = TvChart->DataController->AppendRecord();

                if (TvList->Columns[ColD10->Index]->Visible)
                {
                    pChart[0]->Values[nRow] = TvList->DataController->Values[ii][ColD10->Index];
                }
                if (TvList->Columns[ColD20->Index]->Visible)
                {
                    pChart[1]->Values[nRow] = TvList->DataController->Values[ii][ColD20->Index];
                }
                if (TvList->Columns[ColD30->Index]->Visible)
                {
                    pChart[2]->Values[nRow] = TvList->DataController->Values[ii][ColD30->Index];
                }
                if (TvList->Columns[ColD40->Index]->Visible)
                {
                    pChart[3]->Values[nRow] = TvList->DataController->Values[ii][ColD40->Index];
                }
                if (TvList->Columns[ColD50->Index]->Visible)
                {
                    pChart[4]->Values[nRow] = TvList->DataController->Values[ii][ColD50->Index];
                }
                if (TvList->Columns[ColD60->Index]->Visible)
                {
                    pChart[5]->Values[nRow] = TvList->DataController->Values[ii][ColD60->Index];
                }
                if (TvList->Columns[ColD70->Index]->Visible)
                {
                    pChart[6]->Values[nRow] = TvList->DataController->Values[ii][ColD70->Index];
                }
                if (TvList->Columns[ColD80->Index]->Visible)
                {
                    pChart[7]->Values[nRow] = TvList->DataController->Values[ii][ColD80->Index];
                }
                if (TvList->Columns[ColD90->Index]->Visible)
                {
                    pChart[8]->Values[nRow] = TvList->DataController->Values[ii][ColD90->Index];
                }
                if (TvList->Columns[ColD100->Index]->Visible)
                {
                    pChart[9]->Values[nRow] = TvList->DataController->Values[ii][ColD100->Index];
                }

				String sCltTm = TvList->DataController->Values[ii][Col04->Index];
                TvChart->Categories->Values[nRow] = sCltTm;//sCltTm.SubString(12, 5);
            }
        }
        __finally
        {
    		TvChart->EndUpdate();
            TvList->EndUpdate();
        }
    }
    catch(EDatabaseError &E)
    {
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        throw Exception(String(e.ClassName()) + e.Message);
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::BtnExlSaveClick(TObject *Sender)
{
    TcxGrid          *pGrid = CxList;
    TcxGridTableView *pView = TvList;
    String            sTitle= Caption;

    CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
    //CMM_ExportToExcelFile(String pTitle, TcxGrid *pGrid, TcxGridTableView *pView, TForm *pOwner, bool bExpand=true, bool bSaveAll=true, bool bUseNativeFormat=true);
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::FormClose(TObject *Sender, TCloseAction &Action)
{
    POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
    CommClose();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::FormDestroy(TObject *Sender)
{
    //
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::CbOptionPropertiesChange(TObject *Sender)
{
    //TcxComboBox *pCombo = (TcxComboBox*)Sender;
    DspChart();
    FRAMEChart1->EdFocus->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::Col07CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    TColor tColor = ACanvas->Brush->Color;
    TColor tFont  = clBlack;

    try
    {
        if (!VarIsNull(AViewInfo->Value))
        {
            int value = AViewInfo->Value;
            if (value == 0)
            {
                tColor = clSilver;
            }
            else
            {
                tColor = clLime;
            }
        }
        else
        {
            tColor = clSilver;
        }

        //if (tColor == clSilver) tFont = tColor;
        ACanvas->Font->Color = tFont;
        ACanvas->SetBrushColor(tColor);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolDirSub::BtnBestFitClick(TObject *Sender)
{
    try
    {
        TvList->BeginUpdate();
		TvList->ApplyBestFit(NULL, false, false);
	}
	__finally
	{
        TvList->EndUpdate();
	}
}
//---------------------------------------------------------------------------

