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

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

#include "FRAME_ProcessStatusListF.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 "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"
//TFRAMEProcessStatusList *FRAMEProcessStatusList;
//---------------------------------------------------------------------------
__fastcall TFRAMEProcessStatusList::TFRAMEProcessStatusList(TComponent* Owner)
    : TFrame(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());

    m_pGDC = TvList->DataController;

    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<프로세스 정보가 없습니다>";

	FCodeCMS = ItsCodeManager->FLists.Find("CMS");
	FCodeCDS = ItsCodeManager->FLists.Find("CDS");
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEProcessStatusList::UpdateList()
{
    CMM_ClearGridTableView(TvList);

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

        TItsSubCode *pSubCode;
        try
        {
            ItsProcessManager->FLists.Lock();
            FOR_STL(TItsProcess*, pObj, ItsProcessManager->FLists)
            {
                pObj->FGridIndex = -1;
                if (pObj->DEL_YN       == "Y") continue;
                if (pObj->STTS_DSPL_YN == "N") continue;

                nRow = m_pGDC->AppendRecord();
                pObj->FGridIndex = nRow;

#if 0
                String sCMS = pObj->CommStatus;
                if (FCodeCMS)
                {
                    pSubCode = FCodeCMS->FSubLists.Find(sCMS);
                    if (pSubCode) sCMS = pSubCode->CMMN_CD_KOR_NM;
                }
                String sCDS = pObj->DoorStatus;
                if (FCodeCDS)
                {
                    pSubCode = FCodeCDS->FSubLists.Find(sCDS);
                    if (pSubCode) sCDS = pSubCode->CMMN_CD_KOR_NM;
                }
#endif

                m_pGDC->Values[nRow][Column00->Index] = pObj->SYST_TYPE;
                m_pGDC->Values[nRow][Column01->Index] = pObj->SYST_NM;
                m_pGDC->Values[nRow][Column02->Index] = pObj->SYST_ID;
                m_pGDC->Values[nRow][Column03->Index] = pObj->CommStatus;
                m_pGDC->Values[nRow][Column04->Index] = pObj->CommStatus;

                //m_pGDC->Values[nRow][Column99->Index]  = 0;
            }
        }
        __finally
        {
            ItsProcessManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEProcessStatusList::RefreshList()
{
    int nRow = 0;
    try
    {
        int nTotalRows = m_pGDC->RecordCount;
        TvList->BeginUpdate();

        TItsSubCode *pSubCode;
        try
        {
            ItsProcessManager->FLists.Lock();
            FOR_STL(TItsProcess*, pObj, ItsProcessManager->FLists)
            {
                if (pObj->DEL_YN       == "Y") continue;
                if (pObj->STTS_DSPL_YN == "N") continue;
                if (pObj->FGridIndex   < 0)    continue;

                nRow = pObj->FGridIndex;

#if 0
                String sCMS = pObj->CommStatus;
                if (FCodeCMS)
                {
                    pSubCode = FCodeCMS->FSubLists.Find(sCMS);
                    if (pSubCode) sCMS = pSubCode->CMMN_CD_KOR_NM;
                }
#endif

                m_pGDC->Values[nRow][Column03->Index] = pObj->CommStatus;
                m_pGDC->Values[nRow][Column04->Index] = pObj->CommStatus;
            }
        }
        __finally
        {
            ItsProcessManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEProcessStatusList::Column03CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    if (AViewInfo->GridRecord->RecordIndex < 0) return;

    Graphics::TBitmap *pBmp = NULL;
    pBmp = ImgState1->Picture->Bitmap;
	if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[Column03->Index]))
    {
        String sCode = AViewInfo->GridRecord->DisplayTexts[Column03->Index];
        if      (sCode == "0") pBmp = ImgState1->Picture->Bitmap;
        else if (sCode == "1") pBmp = ImgState0->Picture->Bitmap;
        else if (sCode == "2") pBmp = ImgState2->Picture->Bitmap;
    }

    if (!pBmp) return;
    pBmp->Transparent = true;

    int nW, nH;
    nW = nH = 21;
    try
    {
        TColor bBrush = ACanvas->Brush->Color;
        if (AViewInfo->GridRecord->Selected)
        {
            if (AViewInfo->GridRecord->Index % 2 == 0)
            {
                bBrush = Sender->LookAndFeelPainter->DefaultContentEvenColor();
            }
            else
            {
                bBrush = Sender->LookAndFeelPainter->DefaultContentOddColor();
            }
        }
        ACanvas->Brush->Color = bBrush;

        TRect rc;
        TRect rcOrg = AViewInfo->Bounds;
        ACanvas->FillRect(rcOrg);

        nW = rcOrg.Bottom - rcOrg.Top - 4;
        rc.Top    = rcOrg.Top+2;
        rc.Bottom = rcOrg.Bottom - 2;
        rc.Left   = rcOrg.Left + (rcOrg.Width() - nW) / 2;
        rc.Right  = rc.Left + nW;

        ACanvas->Canvas->StretchDraw(rc, pBmp);
        //ACanvas->Draw(AViewInfo->ContentBounds.Left, AViewInfo->ContentBounds.Top, pBmp);
        ADone = true;
    }
    catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEProcessStatusList::TvListCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
//OptionsSelection.InvertSelect = False
//OptionsView.FocusRect = False
    if (AViewInfo->GridRecord->Selected)
    {
        //ACanvas->Brush->Color = Sender->LookAndFeelPainter->DefaultContentColor();
        //ACanvas->Font->Color = Sender->LookAndFeelPainter->DefaultContentTextColor();
        if (AViewInfo->GridRecord->Index % 2 == 0)
        {
            ACanvas->Brush->Color = Sender->LookAndFeelPainter->DefaultContentEvenColor();
            ACanvas->Font->Color = Sender->LookAndFeelPainter->DefaultContentTextColor();
        }
        else
        {
            ACanvas->Brush->Color = Sender->LookAndFeelPainter->DefaultContentOddColor();
            ACanvas->Font->Color = Sender->LookAndFeelPainter->DefaultContentTextColor();
        }
    }
    else
    {
    }
}
//---------------------------------------------------------------------------

