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

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

#include "TAS00601F.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 "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"

TTAS00601 *TAS00601 = NULL;

//---------------------------------------------------------------------------
__fastcall TTAS00601::TTAS00601(TComponent* Owner, HWND hHandle,
                                String AStDay, String AEdDay, String AStHour, String AEdHour, String AWeek, String ADir, String AAtrdNm, int ATable, int AQryType)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);

    FParent = hHandle;

    FStDay = AStDay;
    FEdDay = AEdDay;
    FStHour = AStHour;
    FEdHour = AEdHour;
    FWeek = AWeek;
    FDir = ADir;
    FAtrdNm = AAtrdNm;
    FTable = ATable;
    FQryType = AQryType;
}
//---------------------------------------------------------------------------
__fastcall TTAS00601::~TTAS00601(void)
{
}
//--------------------------------------------------------------------------

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

    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<노선별속도분석 정보>";

    LblSearch->Caption = FrmLang->lblQryCond->Caption + FStDay + " ~ " + FEdDay;
}
//---------------------------------------------------------------------------

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

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

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

    Application->ProcessMessages();

    if (FTable == 0)
    {
        Col04->Visible = true;
        SelHistory1();
    }
    else
    if (FTable == 1)
    {
        Col04->Visible = false;
        SelHistory2();
    }
}
//---------------------------------------------------------------------------

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

String __fastcall TTAS00601::GetDayWeekCode(String ADay)
{
    TDateTime dt;

    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);

    System::Word week = DayOfWeek(dt);
    //const days: array[1..7] of string = ('일','월','화','수','목','금','토');
    String sWeek[8] = { "", "DTW7", "DTW1", "DTW2", "DTW3", "DTW4", "DTW5", "DTW6" };

    return sWeek[week];
}
//---------------------------------------------------------------------------

void __fastcall TTAS00601::SelHistory1()
{
    TSqlCursor sqlCrs;

    String sQry;
    TADOQuery *pADO = ADOQry;

    String SQLAtrd = "";
    String SQLDrct = "";
    String SQLWeek = "";

    if (FAtrdNm != "")
    {
        SQLAtrd = "                              AND ATRD_NM IN (" + FAtrdNm + ")  \r\n";
    }
    if (FDir != "")
    {
        SQLDrct = "                              AND DRCT_CD IN (" + FDir + ")  \r\n";
    }
    if (FWeek != "")
    {
        SQLWeek = "           AND A.DAY_TYPE_CD IN (" + FWeek + ") \r\n";
    }

    sQry = "SELECT Y.ATRD_NM, Y.DRCT_CD_NM,                                       \r\n"
           "       Y.IFSC_STRT_NM||' → '||Y.IFSC_END_NM AS IFSC_NM,              \r\n"
           "       Y.LINK_STRT_NM||' → '||Y.LINK_END_NM AS LINK_NM,              \r\n"
           "       X.*                                                            \r\n"
           "  FROM (SELECT /*+ INDEX(A PK_TAS_LINK_SPED_HH) */                    \r\n"
           "               A.LINK_ID,                                             \r\n"
           "               ROUND(AVG(H00), 0) AS H00,                             \r\n"
           "               ROUND(AVG(H01), 0) AS H01,                             \r\n"
           "               ROUND(AVG(H02), 0) AS H02,                             \r\n"
           "               ROUND(AVG(H03), 0) AS H03,                             \r\n"
           "               ROUND(AVG(H04), 0) AS H04,                             \r\n"
           "               ROUND(AVG(H05), 0) AS H05,                             \r\n"
           "               ROUND(AVG(H06), 0) AS H06,                             \r\n"
           "               ROUND(AVG(H07), 0) AS H07,                             \r\n"
           "               ROUND(AVG(H08), 0) AS H08,                             \r\n"
           "               ROUND(AVG(H09), 0) AS H09,                             \r\n"
           "               ROUND(AVG(H10), 0) AS H10,                             \r\n"
           "               ROUND(AVG(H11), 0) AS H11,                             \r\n"
           "               ROUND(AVG(H12), 0) AS H12,                             \r\n"
           "               ROUND(AVG(H13), 0) AS H13,                             \r\n"
           "               ROUND(AVG(H14), 0) AS H14,                             \r\n"
           "               ROUND(AVG(H15), 0) AS H15,                             \r\n"
           "               ROUND(AVG(H16), 0) AS H16,                             \r\n"
           "               ROUND(AVG(H17), 0) AS H17,                             \r\n"
           "               ROUND(AVG(H18), 0) AS H18,                             \r\n"
           "               ROUND(AVG(H19), 0) AS H19,                             \r\n"
           "               ROUND(AVG(H20), 0) AS H20,                             \r\n"
           "               ROUND(AVG(H21), 0) AS H21,                             \r\n"
           "               ROUND(AVG(H22), 0) AS H22,                             \r\n"
           "               ROUND(AVG(H23), 0) AS H23,                             \r\n"
           "               ROUND(AVG(SPD), 0) AS SPD                              \r\n"
           "          FROM TB_TAS_LINK_SPED_HH A                                  \r\n"
           "         WHERE A.STAT_DAY BETWEEN :p01 AND :p02                       \r\n"
           "           AND A.LINK_ID IN (SELECT DISTINCT LINK_ID AS LINK_ID       \r\n"
           "                               FROM MV_ATRD_LINK                      \r\n"
           "                              WHERE 1=1                               \r\n"
           + SQLAtrd + SQLDrct +
           "                            )                                         \r\n"
           + SQLWeek +
           "         GROUP BY A.LINK_ID                                           \r\n"
           "       ) X,                                                           \r\n"
           "       MV_ATRD_LINK Y                                                 \r\n"
           " WHERE 1=1                                                            \r\n"
           "   AND Y.LINK_ID = X.LINK_ID                                          \r\n"
           + SQLAtrd + SQLDrct +
           " ORDER BY Y.ATRD_NM, Y.DRCT_CD_NM, Y.LINK_SEQ                         \r\n";

    m_pGDC = TvList->DataController;
    CMM_ClearGridTableView(TvList);

    int nRow = 0;
    int nIdxSped, ii;
    String colName;
    TvList->BeginUpdate(lsimImmediate);
    try
    {
        try
        {
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", FStDay);
            ITSDb_SQLBind(pADO, "p02", FEdDay);

            ITSDb_SQLOpen(pADO);

            for( ; !pADO->Eof; pADO->Next(), nRow++)
            {
                nRow = m_pGDC->AppendRecord();

                m_pGDC->Values[nRow][Col01->Index] = pADO->FieldByName("ATRD_NM")->AsString;
                m_pGDC->Values[nRow][Col02->Index] = pADO->FieldByName("DRCT_CD_NM")->AsString;
                m_pGDC->Values[nRow][Col03->Index] = pADO->FieldByName("IFSC_NM")->AsString;
                m_pGDC->Values[nRow][Col04->Index] = pADO->FieldByName("LINK_NM")->AsString;
                m_pGDC->Values[nRow][Col05->Index] = pADO->FieldByName("SPD")->AsString;

                nIdxSped = ColSped->Index;
                for (ii = 0; ii < DAY_HOUR; ii++)
                {
                    colName.printf(L"h%02d", ii);
                    m_pGDC->Values[nRow][nIdxSped] = pADO->FieldByName(colName)->AsInteger;

                    nIdxSped++;
                }
            }

            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);
        }
    }
    __finally
    {
        TvList->EndUpdate();

        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);
    }
}
//---------------------------------------------------------------------------

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

    String sQry;
    TADOQuery *pADO = ADOQry;

    String SQLAtrd = "";
    String SQLDrct = "";
    String SQLWeek = "";

    if (FAtrdNm != "")
    {
        SQLAtrd = "                              AND ATRD_NM IN (" + FAtrdNm + ")  \r\n";
    }
    if (FDir != "")
    {
        SQLDrct = "                              AND DRCT_CD IN (" + FDir + ")  \r\n";
    }
    if (FWeek != "")
    {
        SQLWeek = "           AND A.DAY_TYPE_CD IN (" + FWeek + ") \r\n";
    }

    sQry = "SELECT Y.ATRD_NM, Y.DRCT_CD_NM,                                       \r\n"
           "       Y.IFSC_STRT_NM||' → '||Y.IFSC_END_NM AS IFSC_NM,              \r\n"
           "       Y.IFSC_STRT_NM||' → '||Y.IFSC_END_NM AS LINK_NM,              \r\n"
           "       X.*                                                            \r\n"
           "  FROM (SELECT /*+ INDEX(A PK_TAS_IFSC_SPED_HH) */                    \r\n"
           "               A.IFSC_ID,                                             \r\n"
           "               ROUND(AVG(H00), 0) AS H00,                             \r\n"
           "               ROUND(AVG(H01), 0) AS H01,                             \r\n"
           "               ROUND(AVG(H02), 0) AS H02,                             \r\n"
           "               ROUND(AVG(H03), 0) AS H03,                             \r\n"
           "               ROUND(AVG(H04), 0) AS H04,                             \r\n"
           "               ROUND(AVG(H05), 0) AS H05,                             \r\n"
           "               ROUND(AVG(H06), 0) AS H06,                             \r\n"
           "               ROUND(AVG(H07), 0) AS H07,                             \r\n"
           "               ROUND(AVG(H08), 0) AS H08,                             \r\n"
           "               ROUND(AVG(H09), 0) AS H09,                             \r\n"
           "               ROUND(AVG(H10), 0) AS H10,                             \r\n"
           "               ROUND(AVG(H11), 0) AS H11,                             \r\n"
           "               ROUND(AVG(H12), 0) AS H12,                             \r\n"
           "               ROUND(AVG(H13), 0) AS H13,                             \r\n"
           "               ROUND(AVG(H14), 0) AS H14,                             \r\n"
           "               ROUND(AVG(H15), 0) AS H15,                             \r\n"
           "               ROUND(AVG(H16), 0) AS H16,                             \r\n"
           "               ROUND(AVG(H17), 0) AS H17,                             \r\n"
           "               ROUND(AVG(H18), 0) AS H18,                             \r\n"
           "               ROUND(AVG(H19), 0) AS H19,                             \r\n"
           "               ROUND(AVG(H20), 0) AS H20,                             \r\n"
           "               ROUND(AVG(H21), 0) AS H21,                             \r\n"
           "               ROUND(AVG(H22), 0) AS H22,                             \r\n"
           "               ROUND(AVG(H23), 0) AS H23,                             \r\n"
           "               ROUND(AVG(SPD), 0) AS SPD                              \r\n"
           "          FROM TB_TAS_IFSC_SPED_HH A                                  \r\n"
           "         WHERE A.STAT_DAY BETWEEN :p01 AND :p02                       \r\n"
           "           AND A.IFSC_ID IN (SELECT DISTINCT IFSC_ID AS IFSC_ID       \r\n"
           "                               FROM MV_ATRD_IFSC                      \r\n"
           "                              WHERE 1=1                               \r\n"
           + SQLAtrd + SQLDrct +
           "                            )                                         \r\n"
           + SQLWeek +
           "         GROUP BY A.IFSC_ID                                           \r\n"
           "       ) X,                                                           \r\n"
           "       MV_ATRD_IFSC Y                                                 \r\n"
           " WHERE 1=1                                                            \r\n"
           "   AND Y.IFSC_ID = X.IFSC_ID                                          \r\n"
           + SQLAtrd + SQLDrct +
           " ORDER BY Y.ATRD_NM, Y.DRCT_CD_NM, Y.IFSC_SEQ                         \r\n";

    m_pGDC = TvList->DataController;
    CMM_ClearGridTableView(TvList);

    int nRow = 0;
    int nIdxSped, ii;
    String colName;
    TvList->BeginUpdate(lsimImmediate);
    try
    {
        try
        {
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", FStDay);
            ITSDb_SQLBind(pADO, "p02", FEdDay);

            ITSDb_SQLOpen(pADO);

            for( ; !pADO->Eof; pADO->Next(), nRow++)
            {
                nRow = m_pGDC->AppendRecord();

                m_pGDC->Values[nRow][Col01->Index] = pADO->FieldByName("ATRD_NM")->AsString;
                m_pGDC->Values[nRow][Col02->Index] = pADO->FieldByName("DRCT_CD_NM")->AsString;
                m_pGDC->Values[nRow][Col03->Index] = pADO->FieldByName("IFSC_NM")->AsString;
                m_pGDC->Values[nRow][Col04->Index] = pADO->FieldByName("LINK_NM")->AsString;
                m_pGDC->Values[nRow][Col05->Index] = pADO->FieldByName("SPD")->AsString;

                nIdxSped = ColSped->Index;
                for (ii = 0; ii < DAY_HOUR; ii++)
                {
                    colName.printf(L"h%02d", ii);
                    m_pGDC->Values[nRow][nIdxSped] = pADO->FieldByName(colName)->AsInteger;

                    nIdxSped++;
                }
            }

            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);
        }
    }
    __finally
    {
        TvList->EndUpdate();

        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);
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS00601::DspHistory()
{
#if 0
    m_pGDC = TvList->DataController;

    try
    {
        CMM_ClearGridTableView(TvList);

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

        try
        {
            TvList->BeginUpdate(lsimImmediate);

            nDataCnt = FAtrdManager->FLists.Size();

            int nIdxSped, nIdxGrad;
            FOR_STL(TAtrdInfo*, pObj, FAtrdManager->FLists)
            {
                nRow1 = m_pGDC->AppendRecord();
                nRow2 = m_pGDC->AppendRecord();

                m_pGDC->Values[nRow1][Col01->Index] = pObj->ATRD_NM;
                m_pGDC->Values[nRow1][Col02->Index] = pObj->DRCT_CD_NM;
                m_pGDC->Values[nRow1][Col03->Index] = pObj->STRT_NM + " → " + pObj->END_NM;
                m_pGDC->Values[nRow1][Col04->Index] = "현재";

                m_pGDC->Values[nRow2][Col01->Index] = pObj->ATRD_NM;
                m_pGDC->Values[nRow2][Col02->Index] = pObj->DRCT_CD_NM;
                m_pGDC->Values[nRow2][Col03->Index] = pObj->STRT_NM + " → " + pObj->END_NM;
                m_pGDC->Values[nRow2][Col04->Index] = "패턴";

                TIfscTrf *pTrf = FTrfManager->FLists.Find(pObj->IFSC_ID);
                if (pTrf == NULL)
                {
                    continue;
                }

                nIdxSped = ColSped->Index;
                nIdxGrad = ColGrad->Index;
                for (ii = 0; ii < DAY_HOUR; ii++)
                {
                    m_pGDC->Values[nRow1][nIdxSped] = pTrf->INFO[ii].C_SPED;
                    m_pGDC->Values[nRow1][nIdxGrad] = pTrf->INFO[ii].C_GRAD;

                    m_pGDC->Values[nRow2][nIdxSped] = pTrf->INFO[ii].P_SPED;
                    m_pGDC->Values[nRow2][nIdxGrad] = pTrf->INFO[ii].P_GRAD;

                    nIdxSped++;
                    nIdxGrad++;
                }
            }
        }
        __finally
        {
            TvList->EndUpdate();
            //CxList->SetFocus();

            DrawChart(FAtrdNm + " " + FQryDay);

            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);
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TTAS00601::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 TTAS00601::OnMessage(TMessage &Msg)
{
    switch (Msg.Msg)
    {
    case WM_PARAM_DATABASE:
        if (WP_DB_SELECT_OK == Msg.WParam)
        {
            //ShowMessage("Select Ok");
        }
        break;
    }
}
//---------------------------------------------------------------------------

void __fastcall TTAS00601::BtnExlSaveClick(TObject *Sender)
{
    TcxGrid          *pGrid = CxList;
    TcxGridTableView *pView = TvList;
    String            sTitle= Caption;//"노선별속도분석";

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

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

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

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

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

    try
    {
        if (!VarIsNull(AViewInfo->Value))
        {
            int nSpd = AViewInfo->Value;
            if (nSpd == 0)
            {
                tFont = tColor;
                tColor = tFont;
            }
            else
            {
                if (nSpd <= 10)
                {
                    tFont = clWhite;
                    tColor = (TColor)0x333333;
                }
                else
                if (nSpd <= 20)
                {
                    tFont = tFont;
                    tColor = (TColor)0x575757;
                }
                else
                if (nSpd <= 30)
                {
                    tFont = tFont;
                    tColor = (TColor)0x7B7B7B;
                }
                else
                if (nSpd <= 40)
                {
                    tFont = tFont;
                    tColor = (TColor)0x9F9F9F;
                }
                else
                if (nSpd <= 50)
                {
                    tFont = clBlue;
                    tColor = (TColor)0xC3C3C3;
                }
                else
                if (nSpd <= 60)
                {
                    tFont = clBlue;
                    tColor = (TColor)0xE7E7E7;
                }
                else
                {
                    tFont = clBlue;
                    tColor = (TColor)0xF3F3F3;
                }
            }
        }
        else
        {
            tColor = clSilver;
            tFont = tColor;
        }

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

