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

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

#include "PIS0020MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#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 "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"

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

void __fastcall TPIS0020M::CommClose()
{
    try
    {
        TmrQry->Enabled = false;
        CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

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

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

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

    TmrQry->Interval = 100;
    TmrQry->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TPIS0020M::RefreshData()
{
    // 검색조건에 의한 링크 데이터 조회
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.PRLT_CTLR_ID, A.PRLT_NM, B.*       \r\n"
           "  FROM TB_PRLT_CTLR    A,                   \r\n"
           "       TB_PRLT_RT_INFR B                    \r\n"
           " WHERE A.REAL_DATA_YN   = 'Y'               \r\n"
           "   AND A.PRLT_CTLR_NMBR = B.PRLT_CTLR_NMBR  \r\n"
           " ORDER BY A.PRLT_CTLR_NMBR, B.FLOR_NMBR     \r\n";

    CMM_ClearGridTableView(TvList);

    try
    {
        int nRow;
        TvList->BeginUpdate();
        try
        {
            int nORD;

            pADO = new TADOQuery(NULL);
            pADO->Close();
            pADO->Connection = ITSDb_GetConnection();
            pADO->SQL->Clear();
            pADO->SQL->Text = sQry;

            pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
                nRow = TvList->DataController->AppendRecord();
                TvList->DataController->Values[nRow][Col11->Index] = pADO->FieldByName("PRLT_CTLR_ID")->AsString;
                TvList->DataController->Values[nRow][Col12->Index] = pADO->FieldByName("PRLT_NM")->AsString;

                TvList->DataController->Values[nRow][Col00->Index] = pADO->FieldByName("FLOR_NMBR")->AsString;
                //TvList->DataController->Values[nRow][Col01->Index] = pADO->FieldByName("FLORNM")->AsString;
                //TvList->DataController->Values[nRow][Col02->Index] = pADO->FieldByName("UPDT_DT")->AsString;
                TvList->DataController->Values[nRow][Col02->Index] = ITSUtil_StrToDateTime(pADO->FieldByName("UPDT_DT")->AsString).FormatString(STR_DATETIME);
                TvList->DataController->Values[nRow][Col03->Index] = pADO->FieldByName("GNRL_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col04->Index] = pADO->FieldByName("LGVH_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col05->Index] = pADO->FieldByName("HVVH_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col06->Index] = pADO->FieldByName("EMVH_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col07->Index] = pADO->FieldByName("HNDC_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col08->Index] = pADO->FieldByName("WMON_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col09->Index] = pADO->FieldByName("ELVH_RMND_PRZN_NUM")->AsString;
                TvList->DataController->Values[nRow][Col10->Index] = pADO->FieldByName("ETC_RMND_PRZN_NUM")->AsString;
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("주차현황조회", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("주차현황조회", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        TvList->EndUpdate();
        //cxGroupBox3->Caption = "▶ 주차정보";// (최종가공시각: " + FRAMETrafficLinkList1->FLastAnsTime + ")";
    }
}
//---------------------------------------------------------------------------

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

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

void __fastcall TPIS0020M::TmrQryTimer(TObject *Sender)
{
    TmrQry->Enabled = false;

    RefreshData();

    TmrQry->Interval = 60 * 1000;
    TmrQry->Enabled = true;
    BtnSearch->Enabled = true;
}
//---------------------------------------------------------------------------

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

    BtnSearch->Enabled = false;
    TmrQry->Interval = 100;
    TmrQry->Enabled = true;
}
//---------------------------------------------------------------------------

