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

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

#include "VMSM650MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalendar"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxDropDownEdit"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxMaskEdit"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxTextEdit"
#pragma link "cxTimeEdit"
#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 "cxRadioGroup"
#pragma link "cxClasses"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxDBData"
#pragma link "cxFilter"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridDBTableView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxStyles"
#pragma link "cxCheckBox"
#pragma link "cxImage"
#pragma link "cxButtonEdit"
#pragma link "cxBlobEdit"
#pragma link "cxColorComboBox"
#pragma link "cxCalc"
#pragma resource "*.dfm"

TVMSM650M *VMSM650M = NULL;
//---------------------------------------------------------------------------

__fastcall TVMSM650M::TVMSM650M(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    //CMM_LoadForm(g_sFormsDir, this);

    FSelected = false;
    FUpdate= false;
    FTitle = Caption;//"VMS 교통상황 폼 관리";
}
//---------------------------------------------------------------------------

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

void __fastcall TVMSM650M::FormCreate(TObject *Sender)
{
    //
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::FormShow(TObject *Sender)
{
    Refresh();

    FormInit();

    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::FormInit()
{
    //TvObjList->OptionsView->NoDataToDisplayInfoText = "<등록되어 있는 객체 정보가 없습니다>";
    FNewDb = false;

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

    int nRow = 0;

    TvList->BeginUpdate();

    try
    {
        for (int nWeek = 1; nWeek <= 7; nWeek++)
        {
            nRow = m_pGDC->AppendRecord();

            String sWeek;
            switch(nWeek)
            {
            case 1: sWeek = "일요일"; break;
            case 2: sWeek = "월요일"; break;
            case 3: sWeek = "화요일"; break;
            case 4: sWeek = "수요일"; break;
            case 5: sWeek = "목요일"; break;
            case 6: sWeek = "금요일"; break;
            case 7: sWeek = "토요일"; break;
            }
            m_pGDC->Values[nRow][ColWeek->Index] = sWeek;
            m_pGDC->Values[nRow][ColCode->Index] = String(nWeek);

            int nTimeIdx = Col00->Index;
            for (int ii = 0; ii < 25; ii++)
            {
                m_pGDC->Values[nRow][nTimeIdx+ii] = true;
            }
        }
    }
    __finally
    {
        TvList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
    BtnSearchClick(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::BtnSearchClick(TObject *Sender)
{
    RefreshData();

    EdFocus->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::RefreshData()
{
    // 검색조건에 의한 링크 데이터 조회
    FormClear();

    TcxDataController *m_pGDC = TvList->DataController;
    int nRow = 0;

    TvList->BeginUpdate();

    try
    {
        for (int nWeek = 0; nWeek < 7; nWeek++)
        {
            nRow = nWeek;

            int nTimeIdx = Col00->Index;
            for (int ii = 0; ii < 24; ii++)
            {
                m_pGDC->Values[nRow][nTimeIdx++] = FSchWeek[nWeek].SubString(ii+1, 1) == "1" ? true : false;
            }
        }
    }
    __finally
    {
        TvList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::BtnClosexClick(TObject *Sender)
{
    FSelected = false;
    Close();
}
//---------------------------------------------------------------------------

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

void __fastcall TVMSM650M::FormClear()
{
    FSelIdx = -1;

    FNewDb = false;
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::BtnSaveClick(TObject *Sender)
{
    FSelected = true;
    TcxDataController *m_pGDC = TvList->DataController;
    int nRow = 0;

    for (int nWeek = 0; nWeek < 7; nWeek++)
    {
        nRow = nWeek;

        FSchWeek[nWeek] = "";
        int nTimeIdx = Col00->Index;
        for (int ii = 0; ii < 24; ii++)
        {
            FSchWeek[nWeek] += m_pGDC->Values[nRow][nTimeIdx++] ? "1" : "0";
        }
    }
    Close();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::ColCheckPropertiesEditValueChanged(TObject *Sender)
{
    try
    {
        int nRows = TvList->DataController->FocusedRecordIndex;
        if (nRows < 0)
        {
            return;
        }

        bool bCheck = TvList->DataController->Values[nRows][ColCheck->Index];
        int nTimeIdx = Col00->Index;
        for (int ii = 0; ii < 24; ii++)
        {
            TvList->DataController->Values[nRows][nTimeIdx++] = bCheck;
        }
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM650M::Col00CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    try
    {
        int iIndex = AViewInfo->Item->Index;

        String val  = (String)AViewInfo->GridRecord->DisplayTexts[iIndex];
        ACanvas->Canvas->Brush->Color = val.UpperCase() == "TRUE" ? clLime : clSilver;
    }
    catch(...) {}
}
//---------------------------------------------------------------------------

