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

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

#include "FRAME_DatabaseStatusF.h"
#include "CDSDatabaseF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#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 "cxContainer"
#pragma link "cxProgressBar"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"

//TFRAMEDatabaseStatus *FRAMEDatabaseStatus;

//---------------------------------------------------------------------------
__fastcall TFRAMEDatabaseStatus::TFRAMEDatabaseStatus(TComponent* Owner)
    : TFrame(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());

    m_pGDC = TvList->DataController;
}
//---------------------------------------------------------------------------

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

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

        try
        {
            ItsDatabaseManager->FLists.Lock();

            FOR_STL(TItsDatabase*, pObj, ItsDatabaseManager->FLists)
            {
                if (pObj->Completed == false) continue;

                nRow = m_pGDC->AppendRecord();

                m_pGDC->Values[nRow][Column01->Index] = pObj->TABLESPACE_NAME;
                m_pGDC->Values[nRow][Column02->Index] = pObj->TOTAL_MB;
                m_pGDC->Values[nRow][Column03->Index] = pObj->USED_MB;
                m_pGDC->Values[nRow][Column04->Index] = pObj->USED_PERCENT;

            }
        }
        __finally
        {
            ItsDatabaseManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEDatabaseStatus::RefreshList()
{
    CMM_ClearGridTableView(TvList);

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

        try
        {
            ItsDatabaseManager->FLists.Lock();

            FOR_STL(TItsDatabase*, pObj, ItsDatabaseManager->FLists)
            {
                nRow = m_pGDC->AppendRecord();

                m_pGDC->Values[nRow][Column01->Index] = pObj->TABLESPACE_NAME;
                m_pGDC->Values[nRow][Column02->Index] = pObj->TOTAL_MB;
                m_pGDC->Values[nRow][Column03->Index] = pObj->USED_MB;
                m_pGDC->Values[nRow][Column04->Index] = pObj->USED_PERCENT;

            }
        }
        __finally
        {
            ItsDatabaseManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEDatabaseStatus::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();
        }
    }
}
//---------------------------------------------------------------------------

