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

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

#include "WBH0010MF.h"
#include "WBH00101F.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FRAME_WebUserListF"
#pragma link "cxButtons"
#pragma link "cxCalendar"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxDropDownEdit"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxMaskEdit"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxTextEdit"
#pragma link "cxTimeEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"

TWBH0010M *WBH0010M = NULL;
//---------------------------------------------------------------------------
__fastcall TWBH0010M::TWBH0010M(TComponent* Owner)
    : TForm(Owner)
{
    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);

    FTitle = "홈페이지 관리자 이력조회";
    m_pFormList = new TList(); 
    TsList01->TabVisible = false;

    FRAMEWebUserList1->PnlTop->Visible = true;
    FRAMEWebUserList1->PnlBottom->Visible = false;
    FRAMEWebUserList1->ColumnSel->Visible = true;
}
//---------------------------------------------------------------------------

void __fastcall TWBH0010M::CommClose()
{
    try
    {
        for (int idx = m_pFormList->Count-1; idx >= 0; idx--)
        {
            m_pFormList->Delete(idx);
        }
        delete m_pFormList;

        CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TWBH0010M::FormInit()
{
    DtStDate->Date = StartOfTheMonth(Now());//Now() - 1;
    DtEdDate->Date = Now();//Now() - 1;
    //DtEdTime->EditValue = Now().FormatString("hh");
    DtStTime->Time = StrToDateTime("00:00");
    DtEdTime->Time = StrToDateTime("23:59");
}
//---------------------------------------------------------------------------

void __fastcall TWBH0010M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;

    FRAMEWebUserList1->UpdateList(true);
    BtnSearch->SetFocus();
}
//---------------------------------------------------------------------------

void __fastcall TWBH0010M::RefreshData()
{
    // 검색조건에 의한 링크 데이터 조회
    try
    {
        //SelListData();
	}
	__finally
	{
	}
}
//---------------------------------------------------------------------------

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

	FStDateTime = DtStDate->Date.FormatString("yyyymmdd") + DtStTime->Time.FormatString("hhnn");
	FEdDateTime = DtEdDate->Date.FormatString("yyyymmdd") + DtEdTime->Time.FormatString("hhnn");

    if (FStDateTime > FEdDateTime)
    {
        Application->MessageBox(FrmLang->lblQryDtErr->Caption.c_str(),//L"검색 시작시각이 검색 종료시각 보다 큽니다.",
                                FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        ActiveControl = DtStDate;
        return;
    }
    FStDateTime = FStDateTime + "00";
    FEdDateTime = FEdDateTime + "59";

    FIdList = "";
    int nSelects = CMM_GetSelectCount(FRAMEWebUserList1->TvList, FRAMEWebUserList1->ColumnSel->Index, FRAMEWebUserList1->Column01->Index, FIdList);
    if (0 == nSelects)
    {
        Application->MessageBox(FrmLang->lblSelLstErr->Caption.c_str(),//L"검색 목록을 선택하지 않았습니다.",
                                FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        FRAMEWebUserList1->CxList->SetFocus();
        return;
    }

    String sTitle = FIdList;

    try
    {
        Application->ProcessMessages();
        LockWindowUpdate(Handle);

        TcxTabSheet *pSheet = CMM_AddTabSheet(PgTab, sTitle);
        if (!pSheet) return;

        WBH00101 = new TWBH00101(this, Handle, FStDateTime, FEdDateTime, FIdList);
        WBH00101->Parent = pSheet;
        WBH00101->Show();
        PgTab->ActivePage = pSheet;
        pSheet = PgTab->ActivePage;
        m_pFormList->Add(WBH00101);
    }
    __finally
    {
        LockWindowUpdate(0);
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TWBH0010M::OnSubFormClose(TMessage Msg)
{
    int nActiveIdx = PgTab->ActivePageIndex;
    if (nActiveIdx <= 0) return;

    LockWindowUpdate(Handle);

    TcxTabSheet *pSheet = PgTab->ActivePage;
    if (pSheet)
    {
        delete pSheet;
    }
    nActiveIdx--;   // 첫번째 탭은 화면에 숨겨져 있다.
    m_pFormList->Delete(nActiveIdx);

    LockWindowUpdate(0);
}
//---------------------------------------------------------------------------

void __fastcall TWBH0010M::PgTabDblClick(TObject *Sender)
{
    TPoint APoint;
    APoint = PgTab->MouseDownPos;
    if (PgTab->IndexOfTabAt(APoint.x, APoint.y) != -1)
        POST_MSG(Handle, WM_SUBFORM_CLOSE, 0, 0);
}
//---------------------------------------------------------------------------

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

void __fastcall TWBH0010M::PgTabCanCloseEx(TObject *Sender, int ATabIndex, bool &ACanClose)
{
    int nActiveIdx = ATabIndex;
    if (nActiveIdx <= 0) return;

    nActiveIdx--;   // 첫번째 탭은 화면에 숨겨져 있다.
    m_pFormList->Delete(nActiveIdx);
}
//---------------------------------------------------------------------------

void __fastcall TWBH0010M::FormCloseQuery(TObject *Sender, bool &CanClose)
{
    FRAMEWebUserList1->OnCloseQuery(CanClose);
}
//---------------------------------------------------------------------------

