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

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

#include "FRAME_VilgShprListF.h"
#include "ITS_OPLibF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxCalc"
#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 "cxTextEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"
//TFRAMEVilgShprList *FRAMEVilgShprList;
//---------------------------------------------------------------------------
__fastcall TFRAMEVilgShprList::TFRAMEVilgShprList(TComponent* Owner)
    : TFrame(Owner)
{
    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<현재 지역 날씨정보가 없습니다>";
    FAlarmCount = 0;
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVilgShprList::UpdateList()
{
    CMM_ClearGridTableView(TvList);
    TcxDataController *pGDC = TvList->DataController;

    FAlarmCount = 0;
    int nRow = 0;
    try
    {
        TvList->BeginUpdate();

        try
        {
            ItsVilgFrcsManager->FLists.Lock();
            FOR_STL(TItsVilgFrcs *, pObj, ItsVilgFrcsManager->FLists)
            {
                nRow = pGDC->AppendRecord();

                pGDC->Values[nRow][Col00->Index] = pObj->VILG_FRCS_ZONE_CD;
                pGDC->Values[nRow][Col01->Index] = pObj->VILG_FRCS_ZONE_NM;
                pGDC->Values[nRow][Col20->Index] = pObj->X_CRDN;
                pGDC->Values[nRow][Col21->Index] = pObj->Y_CRDN;

                pGDC->Values[nRow][Col02->Index] = pObj->WTCD_KOR_CD;

                pGDC->Values[nRow][Pol01->Index] = APP_FormatStr(pObj->shpr.ANNC_DT, STR_DATETIME);
                pGDC->Values[nRow][Pol02->Index] = pObj->shpr.TMPR;
                pGDC->Values[nRow][Pol03->Index] = pObj->shpr.PRAM_1HH;
                pGDC->Values[nRow][Pol04->Index] = pObj->shpr.ATMP_STTS_NM;
                pGDC->Values[nRow][Pol05->Index] = pObj->shpr.ESWS_WNSP_NM;
                pGDC->Values[nRow][Pol06->Index] = pObj->shpr.NRST_WNSP_NM;
                pGDC->Values[nRow][Pol07->Index] = pObj->shpr.HMDT;
                pGDC->Values[nRow][Pol08->Index] = pObj->shpr.PRCP_STTS_NM;
                pGDC->Values[nRow][Pol09->Index] = pObj->shpr.THND_STTS_NM;
                pGDC->Values[nRow][Pol10->Index] = pObj->shpr.WNDR_NM;
                pGDC->Values[nRow][Pol11->Index] = pObj->shpr.WNSP;

                pGDC->Values[nRow][Col24->Index] = pObj->shpr.WNSP_ALARM;
                if (pObj->shpr.WNSP_ALARM != VILG_NONE) FAlarmCount++;

                pGDC->Values[nRow][Column99->Index] = (int)pObj;
            }
        }
        __finally
        {
            ItsVilgFrcsManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVilgShprList::RefreshList()
{
    TcxDataController *pGDC = TvList->DataController;

    FAlarmCount = 0;
    try
    {
        TvList->BeginUpdate();

        try
        {
            ItsVilgFrcsManager->FLists.Lock();

            int nMemPtr;
            int nDataCnt = pGDC->RecordCount;

            for (int ii = 0; ii < nDataCnt; ii++)
            {
                nMemPtr = pGDC->Values[ii][Column99->Index];
                TItsVilgFrcs *pObj = (TItsVilgFrcs*)nMemPtr;
                if (!pObj) continue;

                pGDC->Values[ii][Col02->Index] = pObj->WTCD_KOR_CD;

                pGDC->Values[ii][Pol01->Index] = APP_FormatStr(pObj->shpr.ANNC_DT, STR_DATETIME);
                pGDC->Values[ii][Pol02->Index] = pObj->shpr.TMPR;
                pGDC->Values[ii][Pol03->Index] = pObj->shpr.PRAM_1HH;
                pGDC->Values[ii][Pol04->Index] = pObj->shpr.ATMP_STTS_NM;
                pGDC->Values[ii][Pol05->Index] = pObj->shpr.ESWS_WNSP_NM;
                pGDC->Values[ii][Pol06->Index] = pObj->shpr.NRST_WNSP_NM;
                pGDC->Values[ii][Pol07->Index] = pObj->shpr.HMDT;
                pGDC->Values[ii][Pol08->Index] = pObj->shpr.PRCP_STTS_NM;
                pGDC->Values[ii][Pol09->Index] = pObj->shpr.THND_STTS_NM;
                pGDC->Values[ii][Pol10->Index] = pObj->shpr.WNDR;
                pGDC->Values[ii][Pol11->Index] = pObj->shpr.WNSP;

                pGDC->Values[ii][Col24->Index] = pObj->shpr.WNSP_ALARM;
                if (pObj->shpr.WNSP_ALARM != VILG_NONE) FAlarmCount++;
           }
        }
        __finally
        {
            ItsVilgFrcsManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

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

    try
    {
        if (!VarIsNull(AViewInfo->Value))
        {
            String sVal = AViewInfo->Value;
            if (sVal == VILG_ALARM)
            {
                tColor = clRed;
            }
            else
            if (sVal == VILG_WARNING)
            {
                tColor = clFuchsia;
            }
        }

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

