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

#pragma hdrstop

#include "CDSHolidayF.h"
#include "ITS_OPLibF.h"

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

#pragma package(smart_init)

TItsHoliday::TItsHoliday()
{
	FCompleted = false;
    FEditMode  = DB_INIT;
	FGridIndex = -1;
	DEL_YN     = "N";
    //Clear();
}
//---------------------------------------------------------------------------
void TItsHoliday::Clear()
{
    YMD          = "";  //VARCHAR2(8)	N			년월일
    DAY_TYPE_CD  = "";  //VARCHAR2(7)	Y			요일 유형 코드
    LEGL_HLDY_NM = "";  //VARCHAR2(30)	Y			공휴일 명
    RMRK         = "";  //VARCHAR2(200)	Y			비고
    DEL_YN       = "N";
}
//---------------------------------------------------------------------------
TItsHoliday::~TItsHoliday()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TItsHolidayManager *ItsHolidayManager = NULL;
//---------------------------------------------------------------------------

/*
* Holiday Manager
*/
TItsHolidayManager::TItsHolidayManager()
{
}
//---------------------------------------------------------------------------
TItsHolidayManager::~TItsHolidayManager()
{
    FLists.RemoveAll();
}
//---------------------------------------------------------------------------
bool TItsHolidayManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT YMD, DAY_TYPE_CD, LEGL_HLDY_NM, RMRK \r\n"
           "  FROM TB_LEGL_HLDY_INFR                    \r\n";
           //" ORDER BY YMD, DAY_TYPE_CD, LEGL_HLDY_NM    \r\n";
    try
    {
        FLists.RemoveAll();
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = (NULL != ADbConn) ? ADbConn : ITSDb_GetConnection();
			pADO->SQL->Clear();
			pADO->SQL->Text = sQry;

            pADO->Prepared = true;
			pADO->Open();
            for( ; !pADO->Eof; pADO->Next())
            {
				TItsHoliday *pObj = new TItsHoliday();

                pObj->YMD          = pADO->FieldByName("YMD")->AsString;
                pObj->DAY_TYPE_CD  = pADO->FieldByName("DAY_TYPE_CD")->AsString;
                pObj->LEGL_HLDY_NM = pADO->FieldByName("LEGL_HLDY_NM")->AsString;
                pObj->RMRK         = pADO->FieldByName("RMRK")->AsString;

				FLists.Push(pObj->YMD, pObj);

                pObj->Completed = true;
                pObj->DEL_YN    = "N";
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsHolidayManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsHolidayManager::LoadFromDb", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

    return true;
}
//---------------------------------------------------------------------------

