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

#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 "FrmCrsTrafVolLogSubF.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"

//TFrmCrsTrafVolLogSub *FrmCrsTrafVolLogSub = NULL;

//---------------------------------------------------------------------------
__fastcall TFrmCrsTrafVolLogSub::TFrmCrsTrafVolLogSub(TComponent* Owner, HWND hHandle, String sFrom, String sTo, String sCrossId, String sCamId, String sDrctCd,
                                                      int nStatType, bool isLane, String sCrossNm, String sCamNm, 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;
    FDrctCd     = sDrctCd;
    FStatType   = nStatType;
    FLane       = isLane;
    FCrossNm    = sCrossNm;
    FCamNm      = sCamNm;
    FCrossObj   = pObj;

    Col05->Visible = FLane;

    FOR_STL(TCrossCam*, pCam, FCrossObj->FLists)
    {
        TCrossCam *pObj1 = new TCrossCam();
        TCrossCam *pObj2 = new TCrossCam();
        pCam->Copy(pObj1);
        pCam->Copy(pObj2);
        FCmraIdLists.Push(pObj1->CMRA_ID, pObj1);
        FDrctCdLists.Push(IntToStr(pObj2->DRCT_DVSN_CD), pObj2);
    }

    if (FStatType > 1) {
        // 30분 통계 부터 유턴교통량 데이터가 존재하지 않음.
        ColU0->Visible = false;
        TvList->Bands->Items[5]->Visible = false;
    }

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

void __fastcall TFrmCrsTrafVolLogSub::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 TFrmCrsTrafVolLogSub::FillChartOptions()
{
    FRAMEChart1->CbOption->Properties->OnChange = NULL;
    FRAMEChart1->CbOption->Properties->Items->Clear();

    TCross* pCross = FCrossObj;//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;
}
//---------------------------------------------------------------------------

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

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

void __fastcall TFrmCrsTrafVolLogSub::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 TFrmCrsTrafVolLogSub::ChkExpandClick(TObject *Sender)
{
    CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.CMRA_ID IN (" + FCamId + ")                                                                \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("TFrmCrsTrafVolLogSub::Sel05M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel05M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.CMRA_ID IN (" + FCamId + ")                                                                \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("TFrmCrsTrafVolLogSub::Sel05M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel05M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::Sel15M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel15M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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"
           "   AND A.CMRA_ID IN (" + FCamId + ")                                                                \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("TFrmCrsTrafVolLogSub::Sel15M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel15M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::Sel30M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel30M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::Sel30M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel30M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::Sel60M", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel60M", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::Sel60M_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::Sel60M_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::SelDay", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::SelDay", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::SelDay_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::SelDay_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::SelMonth", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::SelMonth", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::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"
           "   AND A.DRCT_DVSN_CD IN (" + FDrctCd + ")                                                          \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("TFrmCrsTrafVolLogSub::SelMonth_Lane", String(E.ClassName()), E.Message, sQry);
        throw Exception(String(E.ClassName()) + E.Message);
    }
    catch(Exception &e)
    {
        DBERRORMSG("TFrmCrsTrafVolLogSub::SelMonth_Lane", String(e.ClassName()), e.Message, sQry);
        throw Exception(String(e.ClassName()) + e.Message);
    }
    DspHistory();
}
//---------------------------------------------------------------------------

void __fastcall TFrmCrsTrafVolLogSub::DspHistory()
{
    TADOQuery *pADO = ADOQry;
    try
    {
        CMM_ClearGridTableView(TvList);

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

            nDataCnt = pADO->RecordCount;
            m_pGDC->RecordCount = nDataCnt;

            for( ; !pADO->Eof; pADO->Next(), nRow++)
            {
                String CMRA_NM = "";
                String CMRA_ID = pADO->FieldByName("cmraId")->AsString;
                if (CMRA_ID == "X") {
                    int DRCT_DVSN_CD = pADO->FieldByName("drctDvsnCd")->AsInteger;
                    TCrossCam *pCam = FDrctCdLists.Find(IntToStr(DRCT_DVSN_CD));
                    if (pCam) {
                        CMRA_ID = pCam->CMRA_ID;
                    }
                }
                TCrossCam *pCam = FCmraIdLists.Find(CMRA_ID);
                if (pCam) {
                    CMRA_NM = pCam->CMRA_NM;
                }

                m_pGDC->Values[nRow][Col01->Index] = nRow+1;
                m_pGDC->Values[nRow][Col02->Index] = "["+FCrossObj->IXR_ID+"] " + FCrossObj->IXR_NM;
                m_pGDC->Values[nRow][Col03->Index] = CMRA_NM;
                m_pGDC->Values[nRow][Col04->Index] = pADO->FieldByName("dspDt")->AsString;
                m_pGDC->Values[nRow][Col05->Index] = pADO->FieldByName("lane")->AsInteger;

                int G1 = pADO->FieldByName("lrgGoTfvl")->AsInteger;
                int G2 = pADO->FieldByName("mddlGoTfvl")->AsInteger;
                int G3 = pADO->FieldByName("smalGoTfvl")->AsInteger;
                int G4 = pADO->FieldByName("busDvrsLaneGoTfvl")->AsInteger;
                int G0 = G1+G2+G3+G4;

                int L1 = pADO->FieldByName("lrgLeftTfvl")->AsInteger;
                int L2 = pADO->FieldByName("mddlLeftTfvl")->AsInteger;
                int L3 = pADO->FieldByName("smalLeftTfvl")->AsInteger;
                int L4 = pADO->FieldByName("busDvrsLaneLeftTfvl")->AsInteger;
                int L0 = L1+L2+L3;

                int R1 = pADO->FieldByName("lrgRghtTfvl")->AsInteger;
                int R2 = pADO->FieldByName("mddlRghtTfvl")->AsInteger;
                int R3 = pADO->FieldByName("smalRghtTfvl")->AsInteger;
                int R0 = R1+R2+R3;

                int U1 = pADO->FieldByName("uturnTfvl")->AsInteger;
                int U0 = U1;

                m_pGDC->Values[nRow][Col06->Index] = pADO->FieldByName("ocpyRate")->AsFloat;
                m_pGDC->Values[nRow][Col08->Index] = pADO->FieldByName("sped")->AsInteger;
                m_pGDC->Values[nRow][Col07->Index] = G0+L0+R0+U0;

                m_pGDC->Values[nRow][ColG1->Index] = G1;
                m_pGDC->Values[nRow][ColG2->Index] = G2;
                m_pGDC->Values[nRow][ColG3->Index] = G3;
                m_pGDC->Values[nRow][ColG4->Index] = G4;
                m_pGDC->Values[nRow][ColG0->Index] = G0;

                m_pGDC->Values[nRow][ColL1->Index] = L1;
                m_pGDC->Values[nRow][ColL2->Index] = L2;
                m_pGDC->Values[nRow][ColL3->Index] = L3;
                m_pGDC->Values[nRow][ColL4->Index] = L4;
                m_pGDC->Values[nRow][ColL0->Index] = L0;

                m_pGDC->Values[nRow][ColR1->Index] = R1;
                m_pGDC->Values[nRow][ColR2->Index] = R2;
                m_pGDC->Values[nRow][ColR3->Index] = R3;
                m_pGDC->Values[nRow][ColR0->Index] = R0;

                m_pGDC->Values[nRow][ColU1->Index] = U1;
                m_pGDC->Values[nRow][ColU0->Index] = U0;

                m_pGDC->Values[nRow][ColCrossId->Index] = pADO->FieldByName("ixrId")->AsString;
                m_pGDC->Values[nRow][ColCamId->Index] = CMRA_ID;
            }
        }
        __finally
        {
            if (pADO)
            {
                pADO->Close();
            }
            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 TFrmCrsTrafVolLogSub::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 *pChart1 = NULL;
    	TcxGridChartSeries *pChart2 = NULL;
    	TcxGridChartSeries *pChart3 = NULL;
    	TcxGridChartSeries *pChart4 = NULL;

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

			pChart1 = TvChart->CreateSeries();
			pChart1->DataBinding->ValueType = "Integer";
			pChart1->DisplayText = "직진";

			pChart2 = TvChart->CreateSeries();
			pChart2->DataBinding->ValueType = "Integer";
			pChart2->DisplayText = "좌회전";

			pChart3 = TvChart->CreateSeries();
			pChart3->DataBinding->ValueType = "Integer";
			pChart3->DisplayText = "우회전";

            if (TvList->Bands->Items[5]->Visible) {
                pChart4 = TvChart->CreateSeries();
                pChart4->DataBinding->ValueType = "Integer";
                pChart4->DisplayText = "유턴";
            }

#if 0
            int nRowCnt = TvList->ViewData->RecordCount;
            for (int ii = 0; ii < nRowCnt; ii++)
            {
                TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];

                String sCrossId = ARow->Values[ColCrossId->Index];
                if (FCrossId != sCrossId) continue;

                String sCamId  = ARow->Values[ColCamId->Index];
                if (sSelCamId != sCamId) continue;

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

                pChart1->Values[nRow] = ARow->Values[ColG0->Index];
                pChart2->Values[nRow] = ARow->Values[ColL0->Index];
                pChart3->Values[nRow] = ARow->Values[ColR0->Index];

                if (TvList->Bands->Items[5]->Visible) {
                    pChart4->Values[nRow] = ARow->Values[ColU0->Index];
                }

				String sCltTm = ARow->Values[Col04->Index];
                TvChart->Categories->Values[nRow] = sCltTm.SubString(12, 5);
            }
#else
            int nRowCnt = TvList->DataController->RecordCount;
            for (int ii = 0; ii < nRowCnt; ii++)
            {
                String sCrossId = TvList->DataController->Values[ii][ColCrossId->Index];
                if (FCrossId != sCrossId) continue;

                String sCamId  = TvList->DataController->Values[ii][ColCamId->Index];
                if (sSelCamId != sCamId) continue;

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

                pChart1->Values[nRow] = TvList->DataController->Values[ii][ColG0->Index];
                pChart2->Values[nRow] = TvList->DataController->Values[ii][ColL0->Index];
                pChart3->Values[nRow] = TvList->DataController->Values[ii][ColR0->Index];
                if (TvList->Bands->Items[5]->Visible) {
                    pChart4->Values[nRow] = TvList->DataController->Values[ii][ColU0->Index];
                }

				String sCltTm = TvList->DataController->Values[ii][Col04->Index];
                TvChart->Categories->Values[nRow] = sCltTm;//sCltTm.SubString(12, 5);
            }
#endif
        }
        __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 TFrmCrsTrafVolLogSub::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 TFrmCrsTrafVolLogSub::FormClose(TObject *Sender, TCloseAction &Action)
{
    POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
    CommClose();
}
//---------------------------------------------------------------------------

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

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

void __fastcall TFrmCrsTrafVolLogSub::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 TFrmCrsTrafVolLogSub::BtnBestFitClick(TObject *Sender)
{
    try
    {
        TvList->BeginUpdate();
		TvList->ApplyBestFit(NULL, false, false);
	}
	__finally
	{
        TvList->EndUpdate();
	}
}
//---------------------------------------------------------------------------

