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

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

#include "FRAME_VilgFrcsListF.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 resource "*.dfm"
//TFRAMEVilgFrcsList *FRAMEVilgFrcsList;
//---------------------------------------------------------------------------
__fastcall TFRAMEVilgFrcsList::TFRAMEVilgFrcsList(TComponent* Owner)
    : TFrame(Owner)
{
    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<현재 지역 날씨정보가 없습니다>";
    FAlarmCount1 = FAlarmCount2 = 0;
}
//---------------------------------------------------------------------------

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

    FAlarmCount1 = FAlarmCount2 = 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][Col03->Index] = ITSUtil_FormatStr(pObj->ANNC_DT, STR_DATETIME);
                pGDC->Values[nRow][Col04->Index] = pObj->PRST_TMPR;
                pGDC->Values[nRow][Col05->Index] = pObj->HGHS_TMPR;
                pGDC->Values[nRow][Col06->Index] = pObj->LWST_TMPR;
                pGDC->Values[nRow][Col07->Index] = pObj->ATMP_STTS;
                pGDC->Values[nRow][Col08->Index] = pObj->WTCD_KOR_NM;
                pGDC->Values[nRow][Col09->Index] = pObj->PRCP_STTS;
                pGDC->Values[nRow][Col10->Index] = pObj->PRCP_PR;
                pGDC->Values[nRow][Col11->Index] = pObj->ESTM_PRCP_AMUT_6HH;//ESTM_PRAM_12HH;
                pGDC->Values[nRow][Col12->Index] = pObj->ESTM_SNOW_AMUT_6HH;//ESTM_SNOW_AMUT_12HH;
                pGDC->Values[nRow][Col13->Index] = pObj->WNSP;
                pGDC->Values[nRow][Col14->Index] = pObj->WNDR_KOR_NM;
                pGDC->Values[nRow][Col15->Index] = pObj->HMDT;

                pGDC->Values[nRow][Col22->Index] = pObj->PRCP_ALARM;
                pGDC->Values[nRow][Col23->Index] = pObj->SNOW_ALARM;
                if (pObj->PRCP_ALARM != VILG_NONE) FAlarmCount1++;
                if (pObj->SNOW_ALARM != VILG_NONE) FAlarmCount2++;

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

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

    FAlarmCount1 = FAlarmCount2 = 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][Col03->Index] = ITSUtil_FormatStr(pObj->ANNC_DT, STR_DATETIME);
                pGDC->Values[ii][Col04->Index] = pObj->PRST_TMPR;
                pGDC->Values[ii][Col05->Index] = pObj->HGHS_TMPR;
                pGDC->Values[ii][Col06->Index] = pObj->LWST_TMPR;
                pGDC->Values[ii][Col07->Index] = pObj->ATMP_STTS;
                pGDC->Values[ii][Col08->Index] = pObj->WTCD_KOR_NM;
                pGDC->Values[ii][Col09->Index] = pObj->PRCP_STTS;
                pGDC->Values[ii][Col10->Index] = pObj->PRCP_PR;
                pGDC->Values[ii][Col11->Index] = pObj->ESTM_PRAM_12HH;
                pGDC->Values[ii][Col12->Index] = pObj->ESTM_SNOW_AMUT_12HH;
                pGDC->Values[ii][Col13->Index] = pObj->WNSP;
                pGDC->Values[ii][Col14->Index] = pObj->WNDR_KOR_NM;
                pGDC->Values[ii][Col15->Index] = pObj->HMDT;

                pGDC->Values[ii][Col22->Index] = pObj->PRCP_ALARM;
                pGDC->Values[ii][Col23->Index] = pObj->SNOW_ALARM;
                if (pObj->PRCP_ALARM != VILG_NONE) FAlarmCount1++;
                if (pObj->SNOW_ALARM != VILG_NONE) FAlarmCount2++;
            }
        }
        __finally
        {
            ItsVilgFrcsManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVilgFrcsList::Col22CustomDrawCell(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(...)
    {
    }
}
//---------------------------------------------------------------------------

