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

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

#include "VMS0010MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "cxLabel"
#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 "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxCalc"
#pragma link "cxClasses"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxFilter"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxStyles"
#pragma link "cxTextEdit"
#pragma link "cxDBData"
#pragma link "cxGridDBTableView"
#pragma link "cxCheckBox"
#pragma resource "*.dfm"

TVMS0010M *VMS0010M = NULL;
//---------------------------------------------------------------------------
__fastcall TVMS0010M::TVMS0010M(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);
}
//---------------------------------------------------------------------------

void __fastcall TVMS0010M::CommClose()
{
    try
    {
        CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TVMS0010M::FormInit()
{
}
//---------------------------------------------------------------------------

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

    RefreshData();
}
//---------------------------------------------------------------------------

void __fastcall TVMS0010M::RefreshData()
{
#if 0
    int nRow;

    TcxDataController *pGDC = TvList->DataController;

    CMM_ClearGridTableView(TvList);
    TvList->BeginUpdate(lsimImmediate);
    try
    {
        FOR_STL(TVmsCtlr*, pObj, VmsCtlrManager->FLists)
        {
            if (pObj->DEL_YN == "Y") continue;

            nRow = pGDC->AppendRecord();

            pGDC->Values[nRow][Column01->Index] = String(pObj->VMS_CTLR_NMBR);
            pGDC->Values[nRow][Column02->Index] = pObj->VMS_NM;
        }
	}
	__finally
	{
        TvList->EndUpdate();
	}
#endif

    TvVmsIfsc->BeginUpdate(lsimImmediate);

    try
    {
        ADOVmsIfsc->Connection = ITSDb_GetConnection();
        ADOIfsc->Connection = ITSDb_GetConnection();

        ADOVmsIfsc->Active = false;
        ADOIfsc->Active = false;
	}
	__finally
	{
        ADOVmsIfsc->Active = true;
        ADOIfsc->Active = true;
        TvVmsIfsc->EndUpdate();
        ChkExpandClick((TObject*)ChkExpand);
	}
}
//---------------------------------------------------------------------------

void __fastcall TVMS0010M::BtnCloseClick(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------

void __fastcall TVMS0010M::FormClose(TObject *Sender, TCloseAction &Action)
{
    CommClose();
    VMS0010M = NULL;
    Action = caFree;    
}
//---------------------------------------------------------------------------

void __fastcall TVMS0010M::BtnSearchClick(TObject *Sender)
{
    Application->ProcessMessages();
    TSqlCursor sqlCrs((TControl*)BtnSearch);

    RefreshData();
}
//---------------------------------------------------------------------------
void __fastcall TVMS0010M::OnMainFormMessage(TMessage &Msg)
{
    switch(Msg.WParam)
    {
    case WP_DB_SELECT_OK:
        switch(Msg.LParam)
        {
        case LP_MSG_TRAFFIC:    //소통정보 조회 완료
            BtnSearchClick((TObject*)BtnSearch);
            break;
        }
        break;
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMS0010M::TvVmsIfscColumn16CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    if (AViewInfo)
    {
        String sGrade = VarToStr(AViewInfo->DisplayValue);//GridRecord->DisplayTexts[TvVmsIfscColumn16->Index];

        if (sGrade.Pos("1"))
        {
            ACanvas->Canvas->Brush->Color = clLime;
        }
        else if (sGrade.Pos("2"))
        {
            ACanvas->Canvas->Brush->Color = clYellow;
        }
        else if (sGrade.Pos("3"))
        {
            ACanvas->Canvas->Brush->Color = clRed;
        }
        else
        {
            ACanvas->Canvas->Brush->Color = clGray;
        }
    }
}
//---------------------------------------------------------------------------

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


