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

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

#include "FrmParkMsgXF.h"
#include "ITS_OPLibF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxClasses"
#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 "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "cxContainer"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"
TFrmParkMsgX *FrmParkMsgX = NULL;
//---------------------------------------------------------------------------
__fastcall TFrmParkMsgX::TFrmParkMsgX(TComponent* Owner, TPrltCtlr *AObj)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());

    FObj = AObj;

    pADO->Connection = ITSDb_GetConnection();
    TvList->OptionsView->NoDataToDisplayInfoText = "<주차정보>";
}
//---------------------------------------------------------------------------

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

void __fastcall TFrmParkMsgX::FormShow(TObject *Sender)
{
    if (FObj)
    {
        Caption = FObj->PRLT_CTLR_ID + ": " + FObj->PRLT_NM;
        PnlMenu->Visible = FObj->REAL_DATA_YN == "Y" ? true : false;
    }
    TmrShow->Enabled = true;
    //EdNm->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TFrmParkMsgX::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
    if (FObj)
    {
        //EdNmbr->Text = FObj->PRLT_CTLR_NMBR;
        //EdId->Text = FObj->PRLT_CTLR_ID;
        EdNm->Text = FObj->PRLT_NM;
        EdTel->Text = FObj->PRLT_TEL;
        EdAddr->Text = FObj->ISTL_LCTN_ADDR;
        MoPRLT_CHARGE_DESC->Lines->Text = FObj->PRLT_CHARGE_DESC;
        MoPRLT_OPER_DESC->Lines->Text   = FObj->PRLT_OPER_DESC;
        MoPRLT_ETC_DESC->Lines->Text    = FObj->PRLT_ETC_DESC;

        PnlMenu->Visible = FObj->REAL_DATA_YN == "Y" ? true : false;
    }

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

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

    if (!FObj) return;

    if (FObj->REAL_DATA_YN == "Y")
    {
        SelectParkMsg();
    }

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

void __fastcall TFrmParkMsgX::SelectParkMsg()
{
    String sQry;

    if (!FObj)
    {
        return;
    }

    CMM_ClearGridTableView(TvList);

    sQry = "SELECT A.*                      \r\n"
           "  FROM TB_PRLT_RT_INFR A        \r\n"
           " WHERE A.PRLT_CTLR_NMBR = :p01  \r\n"
           " ORDER BY A.FLOR_NMBR           \r\n";

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

        try
        {
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", FObj->PRLT_CTLR_NMBR);
            ITSDb_SQLOpen(pADO);

            for( ; !pADO->Eof; pADO->Next())
            {
                nRow = TvList->DataController->AppendRecord();
                TvList->DataController->Values[nRow][Col00->Index] = pADO->FieldByName("FLOR_NMBR")->AsString;
                //TvList->DataController->Values[nRow][Col01->Index] = pADO->FieldByName("FLOR_NMBR")->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;
            }
            ITSDb_SQLClose(pADO);
        }
        catch(EDatabaseError &E)
        {
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(...)
        {
            throw Exception("알수없는 오류가 발생하였습니다.");
        }
    }
    __finally
    {
        TvList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmParkMsgX::FormDestroy(TObject *Sender)
{
    TmrQry->Enabled = false;
    try {
        if (FObj) FObj->FData1 = NULL;
    } catch(...) {}
}
//---------------------------------------------------------------------------

