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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "ITSDbF.h"
#include "AppGlobalF.h"
#include "WindowMsgF.h"
#include <DateUtils.hpp>
#include "ITSLangTransF.h"
#pragma hdrstop

#include "TAS00401F.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#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 "cxGridBandedTableView"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma resource "*.dfm"

TTAS00401 *TAS00401 = NULL;

//---------------------------------------------------------------------------
__fastcall TTAS00401::TTAS00401(TComponent* Owner, HWND hHandle,
                                String AAtrdId, String AAtrdNm, String AQryDay, String APtrnWeek, String APtrnWeekName)
    : TForm(Owner)
{           
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);

    FParent      = hHandle;

    FAtrdId       = AAtrdId;    //IFSC_ID
    FAtrdNm       = AAtrdNm;    //IFSC_NM
	FQryDay       = AQryDay;    //특수일
    FPtrnWeek     = AQryDay;
    FPtrnWeekName = APtrnWeekName;  //특수일명

    FHoliTrfManager = new THoliTrfManager();

    SetQueryDay(FQryDay);

    //Caption = "특수일분석";
}
//---------------------------------------------------------------------------
__fastcall TTAS00401::~TTAS00401(void)
{
}
//--------------------------------------------------------------------------

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

    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<특수일분석 정보>";

    LblSearch->Caption = FrmLang->lblQryCond->Caption + FAtrdNm + " [" + FPtrnWeekName + "]";
}
//---------------------------------------------------------------------------

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

void __fastcall TTAS00401::CommClose()
{
    try
    {
        delete FHoliTrfManager;
        FHoliTrfManager = NULL;
    }
    catch(Exception &e)
    {
    }
    CMM_SaveForm(g_sFormsDir, this);
    //TAS00401 = NULL;
}
//---------------------------------------------------------------------------

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

    Application->ProcessMessages();

    SelHistory1();
    SelHistory2();

    DspHistory();
}
//---------------------------------------------------------------------------

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

void __fastcall TTAS00401::SetQueryDay(String ADay)
{
    TDateTime dt, dtTemp;

    System::Word Year  = (System::Word)ADay.SubString( 1, 4).ToIntDef(2018);
    System::Word Month = (System::Word)ADay.SubString( 5, 2).ToIntDef(1);
    System::Word Day   = (System::Word)ADay.SubString( 7, 2).ToIntDef(1);
    dt = EncodeDate(Year, Month, Day);

    int nInc = -3;
    for (int ii = 0; ii < MAX_QRY_TERM; ii++)
    {
        FQryDayList[ii] = IncDay(dt, nInc++);

        THoliTrf *pTrf = new THoliTrf();
        pTrf->dtQry = FQryDayList[ii];
        pTrf->sQryDay = FQryDayList[ii].FormatString("YYYYMMDD");
        pTrf->IFSC_ID = FAtrdId;
        FHoliTrfManager->FLists.Push(pTrf->sQryDay, pTrf);
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS00401::SelHistory1()
{
#if 0
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry =
    "SELECT L.*, M.*, DECODE(L.DRCT_CD, '0', '상행', '하행') AS DRCT_CD_NM                                \r\n"
    "  FROM (SELECT X.ATRD_ID, X.ATRD_NM, X.DRCT_CD, X.DRCT_NM,                                           \r\n"
    "               Y.ROAD_ORD, Y.IFSC_ORD, Y.IFSC_ID, Y.IFSC_NM, Y.STRT_NM, Y.END_NM, Y.SECT_LNGT        \r\n"
    "          FROM TB_ATRD X,                                                                            \r\n"
    "               (SELECT A.ATRD_ID, A.ORD AS ROAD_ORD, A.ROAD_ID, B.IFSC_ID, B.ORD AS IFSC_ORD,        \r\n"
    "                       C.IFSC_NM, C.STRT_NM, C.END_NM, C.SECT_LNGT                                   \r\n"
    "                  FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B, TB_IFSC C                           \r\n"
    "                 WHERE A.ROAD_ID = B.ROAD_ID                                                         \r\n"
    "                   AND B.IFSC_ID = C.IFSC_ID                                                         \r\n"
    "                   AND A.ATRD_ID IN (SELECT ATRD_ID FROM TB_ATRD WHERE TRIM(ATRD_NM) = :p01)         \r\n"
    "                ) Y                                                                                  \r\n"
    "         WHERE X.ATRD_ID = Y.ATRD_ID                                                                 \r\n"
    "           AND X.ATRD_ID IN (SELECT ATRD_ID FROM TB_ATRD WHERE TRIM(ATRD_NM) = :p02)                 \r\n"
    "       ) L,                                                                                          \r\n"
    "       (SELECT IFSC_ID AS IFSC_ID_H,                                                                 \r\n"
    "               SUM(DECODE(STAT_HM, '0000', DECODE(SPED, NULL,      0, SPED),      0)) AS S00,        \r\n"
    "               MAX(DECODE(STAT_HM, '0000', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G00,        \r\n"
    "               SUM(DECODE(STAT_HM, '0100', DECODE(SPED, NULL,      0, SPED),      0)) AS S01,        \r\n"
    "               MAX(DECODE(STAT_HM, '0100', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G01,        \r\n"
    "               SUM(DECODE(STAT_HM, '0200', DECODE(SPED, NULL,      0, SPED),      0)) AS S02,        \r\n"
    "               MAX(DECODE(STAT_HM, '0200', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G02,        \r\n"
    "               SUM(DECODE(STAT_HM, '0300', DECODE(SPED, NULL,      0, SPED),      0)) AS S03,        \r\n"
    "               MAX(DECODE(STAT_HM, '0300', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G03,        \r\n"
    "               SUM(DECODE(STAT_HM, '0400', DECODE(SPED, NULL,      0, SPED),      0)) AS S04,        \r\n"
    "               MAX(DECODE(STAT_HM, '0400', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G04,        \r\n"
    "               SUM(DECODE(STAT_HM, '0500', DECODE(SPED, NULL,      0, SPED),      0)) AS S05,        \r\n"
    "               MAX(DECODE(STAT_HM, '0500', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G05,        \r\n"
    "               SUM(DECODE(STAT_HM, '0600', DECODE(SPED, NULL,      0, SPED),      0)) AS S06,        \r\n"
    "               MAX(DECODE(STAT_HM, '0600', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G06,        \r\n"
    "               SUM(DECODE(STAT_HM, '0700', DECODE(SPED, NULL,      0, SPED),      0)) AS S07,        \r\n"
    "               MAX(DECODE(STAT_HM, '0700', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G07,        \r\n"
    "               SUM(DECODE(STAT_HM, '0800', DECODE(SPED, NULL,      0, SPED),      0)) AS S08,        \r\n"
    "               MAX(DECODE(STAT_HM, '0800', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G08,        \r\n"
    "               SUM(DECODE(STAT_HM, '0900', DECODE(SPED, NULL,      0, SPED),      0)) AS S09,        \r\n"
    "               MAX(DECODE(STAT_HM, '0900', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G09,        \r\n"
    "               SUM(DECODE(STAT_HM, '1000', DECODE(SPED, NULL,      0, SPED),      0)) AS S10,        \r\n"
    "               MAX(DECODE(STAT_HM, '1000', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G10,        \r\n"
    "               SUM(DECODE(STAT_HM, '1100', DECODE(SPED, NULL,      0, SPED),      0)) AS S11,        \r\n"
    "               MAX(DECODE(STAT_HM, '1100', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G11,        \r\n"
    "               SUM(DECODE(STAT_HM, '1200', DECODE(SPED, NULL,      0, SPED),      0)) AS S12,        \r\n"
    "               MAX(DECODE(STAT_HM, '1200', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G12,        \r\n"
    "               SUM(DECODE(STAT_HM, '1300', DECODE(SPED, NULL,      0, SPED),      0)) AS S13,        \r\n"
    "               MAX(DECODE(STAT_HM, '1300', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G13,        \r\n"
    "               SUM(DECODE(STAT_HM, '1400', DECODE(SPED, NULL,      0, SPED),      0)) AS S14,        \r\n"
    "               MAX(DECODE(STAT_HM, '1400', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G14,        \r\n"
    "               SUM(DECODE(STAT_HM, '1500', DECODE(SPED, NULL,      0, SPED),      0)) AS S15,        \r\n"
    "               MAX(DECODE(STAT_HM, '1500', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G15,        \r\n"
    "               SUM(DECODE(STAT_HM, '1600', DECODE(SPED, NULL,      0, SPED),      0)) AS S16,        \r\n"
    "               MAX(DECODE(STAT_HM, '1600', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G16,        \r\n"
    "               SUM(DECODE(STAT_HM, '1700', DECODE(SPED, NULL,      0, SPED),      0)) AS S17,        \r\n"
    "               MAX(DECODE(STAT_HM, '1700', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G17,        \r\n"
    "               SUM(DECODE(STAT_HM, '1800', DECODE(SPED, NULL,      0, SPED),      0)) AS S18,        \r\n"
    "               MAX(DECODE(STAT_HM, '1800', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G18,        \r\n"
    "               SUM(DECODE(STAT_HM, '1900', DECODE(SPED, NULL,      0, SPED),      0)) AS S19,        \r\n"
    "               MAX(DECODE(STAT_HM, '1900', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G19,        \r\n"
    "               SUM(DECODE(STAT_HM, '2000', DECODE(SPED, NULL,      0, SPED),      0)) AS S20,        \r\n"
    "               MAX(DECODE(STAT_HM, '2000', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G20,        \r\n"
    "               SUM(DECODE(STAT_HM, '2100', DECODE(SPED, NULL,      0, SPED),      0)) AS S21,        \r\n"
    "               MAX(DECODE(STAT_HM, '2100', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G21,        \r\n"
    "               SUM(DECODE(STAT_HM, '2200', DECODE(SPED, NULL,      0, SPED),      0)) AS S22,        \r\n"
    "               MAX(DECODE(STAT_HM, '2200', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G22,        \r\n"
    "               SUM(DECODE(STAT_HM, '2300', DECODE(SPED, NULL,      0, SPED),      0)) AS S23,        \r\n"
    "               MAX(DECODE(STAT_HM, '2300', DECODE(GRAD, NULL, 'LTC0', GRAD), 'LTC0')) AS G23         \r\n"
    "          FROM (                                                                                     \r\n"
    "                SELECT A.IFSC_ID, A.STAT_HM, A.SPED, A.TRVL_HH,                                      \r\n"
    "                       NVL(B.CMTR_GRAD_CD, 'LTC0') AS GRAD                                           \r\n"
    "                  FROM TB_IFSC_HH_PTRN   A,                                                          \r\n"
    "                       TB_SECT_GRAD_STUP B,                                                          \r\n"
    "                       TB_IFSC           C                                                           \r\n"
    "                 WHERE A.STAT_YM     = SUBSTR(:p03, 1, 6)                                            \r\n"
    "                   AND A.DAY_TYPE_CD = :p04                                                          \r\n"
    "                   AND A.IFSC_ID IN (SELECT B.IFSC_ID AS IFSC_ID                                     \r\n"
    "                                       FROM TB_ATRD_RLTN_ROAD A, TB_ROAD_RLTN_IFSC B, TB_IFSC C      \r\n"
    "                                      WHERE A.ROAD_ID = B.ROAD_ID                                    \r\n"
    "                                        AND B.IFSC_ID = C.IFSC_ID                                    \r\n"
    "                                        AND A.ATRD_ID  IN (SELECT ATRD_ID                            \r\n"
    "                                                            FROM TB_ATRD WHERE TRIM(ATRD_NM) = :p05) \r\n"
    "                                      GROUP BY B.IFSC_ID)                                            \r\n"
    "                   AND A.IFSC_ID      = C.IFSC_ID                                                    \r\n"
    "                   AND B.SECT_GRAD_CD = C.SECT_GRAD_CD                                               \r\n"
    "                   AND (A.SPED >= B.LWST_TRVL_SPED AND A.SPED <= B.HGHS_TRVL_SPED)                   \r\n"
    "               )                                                                                     \r\n"
    "         GROUP BY IFSC_ID                                                                            \r\n"
    "       ) M                                                                                           \r\n"
    " WHERE L.IFSC_ID = M.IFSC_ID_H(+)                                                                    \r\n"
    " ORDER BY L.ATRD_ID, L.DRCT_CD, L.ROAD_ORD, L.IFSC_ORD                                               \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FAtrdNm);
        ITSDb_SQLBind(pADO, "p02", FAtrdNm);
        ITSDb_SQLBind(pADO, "p03", FQryDay);
        ITSDb_SQLBind(pADO, "p04", FPtrnWeek);
        ITSDb_SQLBind(pADO, "p05", FAtrdNm);

        ITSDb_SQLOpen(pADO);

        int nRow = 0;
        String sSeq;
        for( ; !pADO->Eof; pADO->Next(), nRow++)
        {
            TAtrdInfo *pAtrd = new TAtrdInfo();

            pAtrd->ATRD_ID    = pADO->FieldByName("ATRD_ID")->AsString;
            pAtrd->ATRD_NM    = pADO->FieldByName("ATRD_NM")->AsString;
            pAtrd->DRCT_CD_NM = pADO->FieldByName("DRCT_CD_NM")->AsString;
            pAtrd->IFSC_ID    = pADO->FieldByName("IFSC_ID")->AsString;
            pAtrd->STRT_NM    = pADO->FieldByName("STRT_NM")->AsString;
            pAtrd->END_NM     = pADO->FieldByName("END_NM")->AsString;

            sSeq.printf(L"%05d", nRow);
            FAtrdManager->FLists.Push(sSeq, pAtrd);

            TIfscTrf *pTrf = FTrfManager->FLists.Find(pAtrd->IFSC_ID);
            if (pTrf == NULL)
            {
                pTrf = new TIfscTrf();
                FTrfManager->FLists.Push(pAtrd->IFSC_ID, pTrf);
            }

            String sSped, sGrad;
            for (int ii = 0; ii < 24; ii++)
            {
                sSped.printf(L"S%02d", ii);
                sGrad.printf(L"G%02d", ii);

                pTrf->INFO[ii].P_SPED = pADO->FieldByName(sSped)->AsString.ToIntDef(0);
                pTrf->INFO[ii].P_GRAD = pADO->FieldByName(sGrad)->AsString;
            }
        }

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

void __fastcall TTAS00401::SelHistory2()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    sQry =
    "SELECT A.IFSC_ID, A.STAT_DT,                                                   \r\n"
    "       SUBSTR(A.STAT_DT, 1,8) AS STAT_DD, SUBSTR(A.STAT_DT, 9,2) AS STAT_HH,   \r\n"
    "       A.SPED, A.TRVL_HH,                                                      \r\n"
    "       NVL(B.CMTR_GRAD_CD, 'LTC0') AS GRAD                                     \r\n"
    "  FROM TB_IFSC_HH_STAT   A,                                                    \r\n"
    "       TB_SECT_GRAD_STUP B,                                                    \r\n"
    "       TB_IFSC           C                                                     \r\n"
    " WHERE A.STAT_DT BETWEEN :p01 AND :p02                                         \r\n"
    "   AND A.IFSC_ID = :p03                                                        \r\n"
    "   AND A.IFSC_ID      = C.IFSC_ID                                              \r\n"
    "   AND B.SECT_GRAD_CD = C.SECT_GRAD_CD                                         \r\n"
    "   AND (A.SPED >= B.LWST_TRVL_SPED AND A.SPED <= B.HGHS_TRVL_SPED)             \r\n";

    try
    {
        ITSDb_SQLText(pADO, sQry);
        ITSDb_SQLBind(pADO, "p01", FQryDayList[             0].FormatString("YYYYMMDD") + "000000");
        ITSDb_SQLBind(pADO, "p02", FQryDayList[MAX_QRY_TERM-1].FormatString("YYYYMMDD") + "235959");
        ITSDb_SQLBind(pADO, "p03", FAtrdId);    //IFSC_ID

        ITSDb_SQLOpen(pADO);

        int nIdx;
        THoliTrf *pTrf;

        for( ; !pADO->Eof; pADO->Next())
        {
            pTrf = FHoliTrfManager->FLists.Find(pADO->FieldByName("STAT_DD")->AsString);
            if (pTrf == NULL) continue;

            nIdx = pADO->FieldByName("STAT_HH")->AsInteger;

            pTrf->INFO[nIdx].SPED = pADO->FieldByName("SPED")->AsString.ToIntDef(0);
            pTrf->INFO[nIdx].GRAD = pADO->FieldByName("GRAD")->AsString;
        }

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

void __fastcall TTAS00401::DspHistory()
{
    m_pGDC = TvList->DataController;

    try
    {
        CMM_ClearGridTableView(TvList);

        int nRow1 = 0;
        int nDataCnt = 0;
        int ii;

        try
        {
            TvList->BeginUpdate(lsimImmediate);

            nDataCnt = FHoliTrfManager->FLists.Size();

            int nIdxSped, nIdxGrad;
            FOR_STL(THoliTrf*, pObj, FHoliTrfManager->FLists)
            {
                nRow1 = m_pGDC->AppendRecord();

                m_pGDC->Values[nRow1][Col03->Index] = pObj->dtQry.FormatString("YYYY년 MM월 DD일");

                nIdxSped = ColSped->Index;
                nIdxGrad = ColGrad->Index;
                for (ii = 0; ii < DAY_HOUR; ii++)
                {
                    m_pGDC->Values[nRow1][nIdxSped++] = pObj->INFO[ii].SPED;
                    m_pGDC->Values[nRow1][nIdxGrad++] = pObj->INFO[ii].GRAD;
                }
            }
        }
        __finally
        {
            TvList->EndUpdate();
            //CxList->SetFocus();

            DrawChart(FAtrdNm + " [" + FPtrnWeekName + "]");

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

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

void __fastcall TTAS00401::DrawChart(String ATitle)
{
    TcxGridBandedTableView *pView = NULL;
    String                  sAxisX, sAxisY;
    int   nAxisY1, nAxisY2, nStColIdx, nEdColIdx, nTotColIdx;

    nEdColIdx = 0;
    nTotColIdx = -1;

    pView   = TvList;
    nAxisY1 = Col03->Index;         //특수일
    nAxisY2 = Col04->Index;         //구분(화면보이지 않음)
    nEdColIdx = TvListColumn29->Index;  // 23시
    nStColIdx = ColSped->Index;         // 00시

    /*
    *  Chart draw
    */
    try
    {
        m_pFrmChart->Clear();
        if (pView->DataController->RecordCount == 0)
        {
            return;
        }

        m_pFrmChart->BeginDraw("", "", "");
        m_pFrmChart->DrawChart5_1((TcxGridTableView *)pView, nAxisY1, nAxisY2, nStColIdx, nEdColIdx, nTotColIdx);
        m_pFrmChart->EndDraw();
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS00401::OnMessage(TMessage &Msg)
{
    switch (Msg.Msg)
    {
    case WM_PARAM_DATABASE:
        if (WP_DB_SELECT_OK == Msg.WParam)
        {
            //ShowMessage("Select Ok");
        }
        break;
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS00401::BtnExlSaveClick(TObject *Sender)
{
    TcxGrid          *pGrid = CxList;
    TcxGridTableView *pView = TvList;
    String            sTitle= Caption;//"특수일분석";

    CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
}
//---------------------------------------------------------------------------

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

void __fastcall TTAS00401::FormDestroy(TObject *Sender)
{
    CommClose();
}
//---------------------------------------------------------------------------

void __fastcall TTAS00401::FormCreate(TObject *Sender)
{
    m_pFrmChart = new TPlugInChart(this);
    m_pFrmChart->Parent = PnlChart;
    m_pFrmChart->SetChartInfo("", "시간", "속도");
    m_pFrmChart->Show();
}
//---------------------------------------------------------------------------

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

    try
    {
        if (!VarIsNull(AViewInfo->Value))
        {
            String sSpd = AViewInfo->Value;
            if (sSpd == NULL || sSpd.IsEmpty() || sSpd == "0" || sSpd == "-")
            {
                tColor = clSilver;
            }
            else
            {
                String sGrad = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index+24];
                if      (sGrad == "LTC1") tColor = clLime;
                else if (sGrad == "LTC2") tColor = clYellow;
                else if (sGrad == "LTC3") tColor = clRed;
                else                      tColor = clSilver;
            }
        }
        else
        {
            tColor = clSilver;
        }

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

