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

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

#include "FRAME_VmsMsgListF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalc"
#pragma link "cxCheckBox"
#pragma link "cxClasses"
#pragma link "cxContainer"
#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 "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxGridBandedTableView"
#pragma link "cxGridCardView"
#pragma link "cxGridCustomLayoutView"
#pragma link "cxDropDownEdit"
#pragma link "cxImage"
#pragma link "cxLabel"
#pragma resource "*.dfm"
//TFRAMEVmsStateList *FRAMEVmsStateList;
//---------------------------------------------------------------------------
__fastcall TFRAMEVmsMsgList::TFRAMEVmsMsgList(TComponent* Owner)
    : TFrame(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    FSelVmsObj = NULL;

    TvVmsMsg->OptionsView->DataRowHeight  = 0;
    TvVmsMsg->OptionsView->CellAutoHeight = true;
    TvVmsMsg->OptionsView->Indicator      = false;

    TvVmsMsg->OptionsCustomize->ColumnMoving  = false;
    TvVmsMsg->OptionsCustomize->ColumnSorting = false;

    TvVmsMsg->Columns[0]->Width = 40;
    TvVmsMsg->Columns[0]->Options->HorzSizing = false;

    FTitle = lblTitle->Caption;
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVmsMsgList::UpdateList()
{
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVmsMsgList::SetVmsObject(TVmsCtlr *ASelVmsObj)
{
    FSelVmsObj = ASelVmsObj;
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVmsMsgList::ClearVmsMsg()
{
    CMM_ClearGridTableView(TvVmsMsg);
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVmsMsgList::LoadVmsMsgScenario(String AVmsNmbr)
{
    CMM_ClearGridTableView(TvVmsMsg);
    PnlSvcTime->Caption     = lblText1->Caption + "-";//"  Á¦°ø½Ã°¢: -";
    PnlSvcTime->Font->Color = clNavy;

    TVmsCtlr *pObj = VmsCtlrManager->FLists.Find(AVmsNmbr);
    if (!pObj) return;

    PnlSvcTime->Caption = lblText1->Caption + ITSUtil_FormatStr(pObj->VmsMsg->OFFER_DT, STR_DATETIME);

    try
    {
        int nRow;
        TcxDataController *pGDC = TvVmsMsg->DataController;
        TvVmsMsg->BeginUpdate();
        pObj->Lock();

        for(int ii = 0; ii < pObj->VmsMsg->Total && ii < INT_VMS_MAX_FORM; ii++)
        {
            Graphics::TBitmap *pBitmap = pObj->VmsMsg->PHASE[ii].pVmsBmp;
            TStream	*pImgStream = new TMemoryStream();
            try
            {
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][ColSch01->Index] = String(ii+1);

                pBitmap->SaveToStream(pImgStream);
                void    *p;
                Variant  v;
                int aBound[]={0, pImgStream->Size - 1};
                v = VarArrayCreate(aBound, 1, varByte);
                p = VarArrayLock(v);
                pImgStream->Position = 0;
                pImgStream->Read(p, pImgStream->Size);
                VarArrayUnlock(v);
                //pGDC->Values[nRow][ColSch02->Index] = pBitmap;
                pGDC->Values[nRow][ColSch02->Index] = v;
            } catch(Exception &e) {}
            SAFE_DELETE(pImgStream);
        }
    }
    __finally
    {
        pObj->UnLock();
        TvVmsMsg->EndUpdate();
        PnlSvcTime->Font->Color = pObj->VmsMsg->OFFER_YN ? clNavy : clRed;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEVmsMsgList::OnCloseQuery(bool &CanClose)
{
}
//---------------------------------------------------------------------------

