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

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

#include "ITSSEL2MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "FRAME_IfscListF"
#pragma resource "*.dfm"

TITSSEL2M *ITSSEL2M = NULL;
//---------------------------------------------------------------------------
__fastcall TITSSEL2M::TITSSEL2M(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);

    m_bSelected = false;

    FRAMEIfscList1->PnlTop->Visible = false;
    FRAMEIfscList1->PnlBottom->Visible = false;
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::CommClose()
{
    try
    {
        CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::FormShow(TObject *Sender)
{
    Refresh();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
    BtnSearchClick((TObject*)BtnSearch);   
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::BtnSearchClick(TObject *Sender)
{
    Application->ProcessMessages();
    TSqlCursor sqlCrs((TControl*)BtnSearch);

    RefreshData();
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::RefreshData()
{
    // 검색조건에 의한 링크 데이터 조회
    try
    {
        SelListData();
	}
	__finally
	{
		//TvList->ApplyBestFit(NULL, false, false);
	}
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::SelListData()
{
    FRAMEIfscList1->UpdateList();
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::BtnCloseClick(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::BtnSelectClick(TObject *Sender)
{
    if (!MultiSelect)
    {
        String sLinkId = "";
        int    nSelCnt = FRAMEIfscList1->GetSelLinkIds(sLinkId);
        if (nSelCnt == 0)
        {
            Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"목록에서 서비스링크를 먼저 선택 하세요.",
                                    cxGroupBox1->Caption.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
            return;
        }
        m_sSelLinkId = sLinkId;
        m_bSelected = true;
    }
    else
    {
        int nSelIdx;
        int nSelRows = FRAMEIfscList1->TvList->Controller->SelectedRowCount;
        if (nSelRows <= 0)
        {
            Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"목록에서 서비스링크를 먼저 선택 하세요.",
                                    cxGroupBox1->Caption.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
            return;
        }
        SelList->Items->Clear();
        for (int ii = 0; ii < nSelRows; ii++)
        {
            nSelIdx = FRAMEIfscList1->TvList->Controller->SelectedRows[ii]->RecordIndex;
            SelList->Items->Add(FRAMEIfscList1->TvList->DataController->Values[nSelIdx][FRAMEIfscList1->Column01->Index]);
        }
        m_bSelected = true;
    }

    Close();
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::FormClose(TObject *Sender, TCloseAction &Action)
{
    CommClose();
    ITSSEL2M = NULL;
    //Action = caFree;
}
//---------------------------------------------------------------------------

void __fastcall TITSSEL2M::SetMultiSelect(bool AMultiSelect)
{
    FRAMEIfscList1->TvList->OptionsSelection->MultiSelect = AMultiSelect;
}
//---------------------------------------------------------------------------

bool __fastcall TITSSEL2M::GetMultiSelect()
{
    return FRAMEIfscList1->TvList->OptionsSelection->MultiSelect;
}
//---------------------------------------------------------------------------


