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

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

#include "ITSSEL0MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FRAME_NodeListF"
#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"

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

    m_bSelected = false;

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

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

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

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

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

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

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

void __fastcall TITSSEL0M::SelListData()
{
    FRAMENodeList1->UpdateList();
}
//---------------------------------------------------------------------------

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

void __fastcall TITSSEL0M::BtnSelectClick(TObject *Sender)
{
    String sNodeId = "";
    int    nSelCnt = FRAMENodeList1->GetSelNodeIds(sNodeId);
    if (nSelCnt == 0)
    {
        Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"목록에서 노드를 먼저 선택 하세요.",
                                cxGroupBox1->Caption.c_str(),
                                MB_OK|MB_ICONWARNING|MB_APPLMODAL);
		return;
    }

    m_sSelNodeId   = sNodeId;
    m_sSelNodeName = "";

    m_sPosX = 0;
    m_sPosY = 0;

    m_bSelected = true;
    Close();
}
//---------------------------------------------------------------------------

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

