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

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

#include "ITSSEL1MF.h"

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

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

    m_bSelected = false;

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

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

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

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

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

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

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

void __fastcall TITSSEL1M::SelListData()
{
    FRAMELinkList1->UpdateList();
}
//---------------------------------------------------------------------------

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

void __fastcall TITSSEL1M::BtnSelectClick(TObject *Sender)
{
    if (!MultiSelect)
    {
        String sLinkId = "";
        int    nSelCnt = FRAMELinkList1->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 = FRAMELinkList1->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 = FRAMELinkList1->TvList->Controller->SelectedRows[ii]->RecordIndex;
            SelList->Items->Add(FRAMELinkList1->TvList->DataController->Values[nSelIdx][FRAMELinkList1->Column01->Index]);
        }
        m_bSelected = true;
    }
    Close();
}
//---------------------------------------------------------------------------

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

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

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

