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

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

#include "IHS0040MF.h"
#include "IHS00401F.h"

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

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

    FTitle = "가공데이터 이력조회";
    m_pFormList = new TList();
    TsList01->TabVisible = false;

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

/*
 * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
 * Form과 DataModule class를 delete시킨다.
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TIHS0040M::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(...)
    {
    }
}
//---------------------------------------------------------------------------

/*
 * Form을 보여줄때 호출되는 event 메서드이다.
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TIHS0040M::FormShow(TObject *Sender)
{
    Refresh();
    FormInit();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

/*
 * form 초기화
 *
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TIHS0040M::FormInit()
{
    DtStDate->Date = Now() - 1;
    DtEdDate->Date = Now();
    DtEdTime->EditValue = Now().FormatString("hh");
}
//---------------------------------------------------------------------------

/*
 * Form이 Show되고 난 후 최초 1회 수행되는 타이머 이벤트
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TIHS0040M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;

    FRAMELinkList1->UpdateList();
}
//---------------------------------------------------------------------------

/*
 * Refresh Data Event Function
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TIHS0040M::RefreshData()
{
    // 검색조건에 의한 링크 데이터 조회
    try
    {
        //SelListData();
	}
	__finally
	{
	}
}
//---------------------------------------------------------------------------

/*
 * Search 버튼 클릭 이벤트 핸들러
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TIHS0040M::BtnSearchClick(TObject *Sender)
{
	FStDateTime = DtStDate->Date.FormatString("yyyymmdd") + DtStTime->Time.FormatString("hh");
	FEdDateTime = DtEdDate->Date.FormatString("yyyymmdd") + DtEdTime->Time.FormatString("hh");
    if (FStDateTime > FEdDateTime)
    {
        Application->MessageBox(L"검색 시작시각이 검색 종료시각 보다 큽니다.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        ActiveControl = DtStDate;
        return;
    }
    FStDateTime = FStDateTime + "0000";
    FEdDateTime = FEdDateTime + "5959";

    FIdList = "";
    int nSelects = FRAMELinkList1->GetSelLinkIds(FIdList);
    if (0 == nSelects)
    {
        Application->MessageBox(L"검색 목록을 선택하지 않았습니다.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        FRAMELinkList1->CxList->SetFocus();
        return;
    }

    String sTitle = "[" + FStDateTime + "-" + FEdDateTime + "]";

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

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

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

/*
 * Close 버튼 클릭 이벤트 핸들러
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TIHS0040M::BtnCloseClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------

/*
 * 조회결과 폼이 닫힐때 메시지를 받아 처리한다.
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TIHS0040M::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);
}
//---------------------------------------------------------------------------

/*
 * Tab Control의 Tab을 더블클릭하여 닫는다.
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TIHS0040M::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 TIHS0040M::FormClose(TObject *Sender, TCloseAction &Action)
{
    CommClose();
    IHS0040M = NULL;
    Action = caFree;
}
//---------------------------------------------------------------------------

