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

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

#include "VMSSEL0MF.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 "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 "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxDropDownEdit"
#pragma link "cxLabel"
#pragma link "cxMaskEdit"
#pragma link "cxTextEdit"
#pragma resource "*.dfm"

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

    FStrTime = "";
    FEndTime = "";
    FSelected = false;
    FCurrDay  = false;
}
//---------------------------------------------------------------------------

/*
 * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
 * Form과 DataModule class를 delete시킨다.
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TVMSSEL0M::CommClose()
{
    try
    {
        //CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

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

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

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

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

void __fastcall TVMSSEL0M::SelListData()
{
    if (FStrTime == "")
    {
        DtStrDate->Date = Now();
    }
    else
    {
        TDateTime dtStrDate = APP_StrToDateTime(FStrTime);
        DtStrDate->Date = dtStrDate;
        DtStrTime->Date = dtStrDate;
        DtStrTime->Time = dtStrDate;
    }
    if (FEndTime == "")
    {
        TDateTime dtEndDate = EncodeDate(2099, 12, 31);
        if (FCurrDay)
        {
            dtEndDate = Now();
        }
        TDateTime dtEndTime = EncodeTime(23, 59, 59, 0);

        DtEndDate->Date = dtEndDate;
        DtEndTime->Date = dtEndDate;
        DtEndTime->Time = dtEndTime;
    }
    else
    {
        TDateTime dtEndDate = APP_StrToDateTime(FEndTime);
        DtEndDate->Date = dtEndDate;
        DtEndTime->Date = dtEndDate;
        DtEndTime->Time = dtEndDate;
    }
}
//---------------------------------------------------------------------------

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

/*
 * Select Button Click Event Handler
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TVMSSEL0M::BtnSelectClick(TObject *Sender)
{
    String sStrDate = DtStrDate->Date.FormatString("yyyymmdd");
    String sStrTime = DtStrTime->DateTime.FormatString("HHnn");
    String sEndDate = DtEndDate->Date.FormatString("yyyymmdd");
    String sEndTime = DtEndTime->DateTime.FormatString("HHnn");
    FStrTime = sStrDate + sStrTime;
    FEndTime = sEndDate + sEndTime;

    if (FStrTime > FEndTime)
    {
        Application->MessageBox(lblText1->Caption.c_str(),//L"표출 시작시각이 표출 종료시각 보다 큽니다.",
                                Caption.c_str(),
                                MB_OK|MB_ICONWARNING|MB_APPLMODAL);
        ActiveControl = DtStrDate;
        return;
    }
    FStrTime = FStrTime + "00";
    FEndTime = FEndTime + "59";

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

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

