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

#pragma hdrstop

#include "CDSVilgFrcsF.h"
#include "ITS_OPLibF.h"

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

#pragma package(smart_init)

//---------------------------------------------------------------------------
TItsVilgFrcsManager *ItsVilgFrcsManager = NULL;
//---------------------------------------------------------------------------

/*
* VilgFrcs Manager
*/
TItsVilgFrcsManager::TItsVilgFrcsManager()
{
}
//---------------------------------------------------------------------------
TItsVilgFrcsManager::~TItsVilgFrcsManager()
{
}
//---------------------------------------------------------------------------

bool TItsVilgFrcsManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                    \r\n"
           "  FROM TB_VILG_FRCS_ZONE    \r\n"
           " ORDER BY VILG_FRCS_ZONE_NM \r\n";

    try
    {
        FLists.Lock();
        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())
            {
				TItsVilgFrcs *pObj = new TItsVilgFrcs();

                pObj->VILG_FRCS_ZONE_CD = pADO->FieldByName("VILG_FRCS_ZONE_CD")->AsString;      //	N	NUMBER(14)	    N			동네 예보 구역 코드
                pObj->VILG_FRCS_ZONE_NM = pADO->FieldByName("VILG_FRCS_ZONE_NM")->AsString;      //	N	VARCHAR2(40)	Y			동네 예보 구역 명
                pObj->X_CRDN = pADO->FieldByName("X_CRDN")->AsString;    //X 좌표
                pObj->Y_CRDN = pADO->FieldByName("Y_CRDN")->AsString;    //Y 좌표

				FLists.Push(pObj->VILG_FRCS_ZONE_CD, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadFromDb", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadFromDb", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

    return true;
    //return LoadFromDbAtmp(ADbConn);
}
//---------------------------------------------------------------------------
bool TItsVilgFrcsManager::LoadFromDbAtmp(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                  \r\n"
           "  FROM TB_ATMP_PLTN_STTN  \r\n"
           " ORDER BY ATMP_STTN_NMBR  \r\n";

    try
    {
        FAtmpLists.Lock();
        FAtmpLists.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())
            {
				TItsAtmpPltn *pObj = new TItsAtmpPltn();

                pObj->ATMP_STTN_NMBR = pADO->FieldByName("ATMP_STTN_NMBR")->AsString;   //		N	NUMBER(10)	N			측정소 번호
                pObj->ATMP_STTN_NM   = pADO->FieldByName("ATMP_STTN_NM")->AsString;     //		N	VARCHAR2(30)	N			측정소 명
                pObj->ATMP_STTN_ADDR = pADO->FieldByName("ATMP_STTN_ADDR")->AsString;   //		N	VARCHAR2(200)	Y			측정소 주소
                pObj->ISTL_YY        = pADO->FieldByName("ISTL_YY")->AsString;          //		N	VARCHAR2(4)	Y			설치 년도
                pObj->MNGM_INTN_NM   = pADO->FieldByName("MNGM_INTN_NM")->AsString;     //		N	VARCHAR2(100)	Y			관리 기관 명
                pObj->MSRM_SYST_NM   = pADO->FieldByName("MSRM_SYST_NM")->AsString;     //		N	VARCHAR2(10)	Y			측정 시스템 명
                pObj->MSRM_ITEM      = pADO->FieldByName("MSRM_ITEM")->AsString;        //		N	VARCHAR2(100)	Y			측정 항목
                pObj->X_CRDN         = pADO->FieldByName("X_CRDN")->AsString;           //X 좌표
                pObj->Y_CRDN         = pADO->FieldByName("Y_CRDN")->AsString;           //Y 좌표

				FAtmpLists.Push(pObj->ATMP_STTN_NMBR, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadFromDbAtmp", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadFromDbAtmp", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FAtmpLists.UnLock();
    }

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

bool TItsVilgFrcsManager::LoadVilgFrcsInfo(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.*,                                                                                                  \r\n"
           "       NVL((SELECT CMMN_CD                                                                                   \r\n"
           "              FROM TB_CMMN_CD                                                                                \r\n"
           "             WHERE CMMN_CLSF_CD = 'DFW'                                                                      \r\n"
           "               AND CMMN_CD_KOR_NM(+) = WTCD_KOR_NM), 'XXX') AS WTCD_KOR_CD                                   \r\n"
           "  FROM TB_VILG_FRCS A                                                                                        \r\n"
           " WHERE (A.VILG_FRCS_ZONE_CD, A.ANNC_DT) IN (SELECT VILG_FRCS_ZONE_CD, MAX(ANNC_DT) AS ANNC_DT                \r\n"
           "                                              FROM TB_VILG_FRCS                                              \r\n"
           "                                             WHERE ANNC_DT >= TO_CHAR(SYSDATE-240/1440,'YYYYMMDDHH24MISS')   \r\n"
           "                                               AND ORD = 0                                                   \r\n"
           "                                             GROUP BY VILG_FRCS_ZONE_CD)                                     \r\n"
           "   AND A.ORD = 0                                                                                             \r\n";

    try
    {
        float fTemp;
        FLists.Lock();
        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())
            {
                String VILG_FRCS_ZONE_CD = pADO->FieldByName("VILG_FRCS_ZONE_CD")->AsString;
				TItsVilgFrcs *pObj = FLists.Find(VILG_FRCS_ZONE_CD);
                if (!pObj) continue;

                pObj->ANNC_DT             = pADO->FieldByName("ANNC_DT")->AsString;                //	N	VARCHAR2(14)	N			발표 일시
                pObj->ORD                 = pADO->FieldByName("ORD")->AsString;                    //	N	NUMBER(3)	    N	0		순서
                pObj->HH                  = pADO->FieldByName("HH")->AsString;                     //	N	NUMBER(3)	    Y	0		시간
                pObj->DD                  = pADO->FieldByName("DD")->AsString;                     //	N	NUMBER(3)	    Y	0		일
                pObj->PRST_TMPR           = pADO->FieldByName("PRST_TMPR")->AsString;              //	N	NUMBER(6,3)	    Y			현재 온도
                pObj->HGHS_TMPR           = pADO->FieldByName("HGHS_TMPR")->AsString;              //	N	NUMBER(6,3)	    Y			최고 온도
                pObj->LWST_TMPR           = pADO->FieldByName("LWST_TMPR")->AsString;              //	N	NUMBER(6,3)	    Y			최저 온도
#if 0
                pObj->ATMP_STTS           = pADO->FieldByName("ATMP_STTS")->AsString;              //	N	NUMBER(2)	    Y			대기 상태
#else
                switch(pADO->FieldByName("ATMP_STTS")->AsInteger)
                {
                case 1: pObj->ATMP_STTS = "맑음";       break;
                case 2: pObj->ATMP_STTS = "구름조금";   break;
                case 3: pObj->ATMP_STTS = "구름많음";   break;
                case 4: pObj->ATMP_STTS = "흐림";       break;
                default:
                    pObj->ATMP_STTS = pADO->FieldByName("ATMP_STTS")->AsString;
                    break;
                }
#endif

                pObj->WTCD_KOR_NM         = pADO->FieldByName("WTCD_KOR_NM")->AsString;            //	N	VARCHAR2(20)	Y			날씨 한글 명
#if 0
                pObj->PRCP_STTS           = pADO->FieldByName("PRCP_STTS")->AsString;              //	N	NUMBER(3)	    Y	0		강수 상태
#else
                switch(pADO->FieldByName("PRCP_STTS")->AsInteger)
                {
                case 0: pObj->PRCP_STTS = "없음";   break;
                case 1: pObj->PRCP_STTS = "비";     break;
                case 2: pObj->PRCP_STTS = "비/눈";  break;
                case 3: pObj->PRCP_STTS = "눈";     break;
                default:
                    pObj->PRCP_STTS = pADO->FieldByName("PRCP_STTS")->AsString;
                    break;
                }
#endif
                pObj->WTCD_ENGL_NM        = pADO->FieldByName("WTCD_ENGL_NM")->AsString;           //	N	VARCHAR2(20)	Y			날씨 영문 명
                pObj->PRCP_PR             = pADO->FieldByName("PRCP_PR")->AsString;                //	N	NUMBER(5,2)	    Y	0		강수 확률
                pObj->ESTM_PRAM_12HH      = pADO->FieldByName("ESTM_PRAM_12HH")->AsString;         //	N	NUMBER(5,2)	    Y	0		예상 강수량 12시간
                pObj->ESTM_SNOW_AMUT_12HH = pADO->FieldByName("ESTM_SNOW_AMUT_12HH")->AsString;    //	N	NUMBER(5,2)	    Y	0		예상 눈 량 12시간
                pObj->WNSP                = pADO->FieldByName("WNSP")->AsString;                   //	N	NUMBER(5,2)	    Y	0		풍속
                pObj->WNDR                = pADO->FieldByName("WNDR")->AsString;                   //	N	NUMBER(2)	    Y			풍향
                pObj->WNDR_KOR_NM         = pADO->FieldByName("WNDR_KOR_NM")->AsString;            //	N	VARCHAR2(20)	Y			풍향 한글 명
                pObj->WNDR_ENGL_NM        = pADO->FieldByName("WNDR_ENGL_NM")->AsString;           //	N	VARCHAR2(20)	Y			풍향 영문 명
                pObj->HMDT                = pADO->FieldByName("HMDT")->AsString;                   //	N	NUMBER(5,2)	    Y	0		습도
                pObj->ESTM_PRCP_AMUT_6HH  = pADO->FieldByName("ESTM_PRCP_AMUT_6HH")->AsString;     //	N	NUMBER(5,2)	    Y	0		예상 강수 량 6시간
                pObj->ESTM_SNOW_AMUT_6HH  = pADO->FieldByName("ESTM_SNOW_AMUT_6HH")->AsString;     //	N	NUMBER(5,2)	    Y	0		예상 눈 량 6시간
                pObj->WTCD_KOR_CD         = pADO->FieldByName("WTCD_KOR_CD")->AsString;

                if (pObj->WTCD_KOR_CD == "XXX" || pObj->VILG_FRCS_ZONE_NM.Trim() == "")
                {
                    pObj->VILG_FRCS_ZONE_NM = "정보없음";
                }

                // 호우알람
                fTemp = pADO->FieldByName("ESTM_PRCP_AMUT_6HH")->AsFloat;
                pObj->PRCP_ALARM = VILG_NONE;         // 강풍알람
                if      (fTemp >= 110) pObj->PRCP_ALARM = VILG_ALARM;
                else if (fTemp >=  70) pObj->PRCP_ALARM = VILG_WARNING;
                if (pObj->PRCP_ALARM != VILG_NONE)
                {
                }
                // 대설알람
                fTemp = pADO->FieldByName("ESTM_SNOW_AMUT_6HH")->AsFloat;
                fTemp *= 4;
                //pObj->ESTM_SNOW_AMUT_6HH = FormatFloat("#0.#0", fTemp);
                pObj->SNOW_ALARM = VILG_NONE;         // 강풍알람
                if      (fTemp >= 20) pObj->SNOW_ALARM = VILG_ALARM;
                else if (fTemp >=  5) pObj->SNOW_ALARM = VILG_WARNING;
                if (pObj->SNOW_ALARM != VILG_NONE)
                {
                }
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadVilgFrcsInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadVilgFrcsInfo", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

    LoadVilgShprInfo(ADbConn);
    return true;
    //return LoadAtmpPltnInfo(ADbConn);
    //return LoadAtmpSprpInfo(ADbConn);
}
//---------------------------------------------------------------------------
bool TItsVilgFrcsManager::LoadVilgShprInfo(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                                                       \r\n"
           "  FROM TB_VILG_SHPR                                            \r\n"
           " WHERE ANNC_DT >= TO_CHAR(SYSDATE-120/1440,'YYYYMMDDHH24MISS') \r\n";

    try
    {
        int nTemp;
        float fTemp;
        FLists.Lock();
        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())
            {
                String VILG_FRCS_ZONE_CD = pADO->FieldByName("VILG_FRCS_ZONE_CD")->AsString;
				TItsVilgFrcs *pObj = FLists.Find(VILG_FRCS_ZONE_CD);
                if (!pObj) continue;

                pObj->shpr.ANNC_DT   = pADO->FieldByName("ANNC_DT")->AsString;            //	N	VARCHAR2(14)	N			발표 일시
                pObj->shpr.TMPR      = pADO->FieldByName("TMPR")->AsString;               //	N	NUMBER(6,3)	    Y			온도
                pObj->shpr.PRAM_1HH  = pADO->FieldByName("PRAM_1HH")->AsString;           //	N	NUMBER(5,2)	    Y	0		강수량 1시간
                pObj->shpr.ATMP_STTS = pADO->FieldByName("ATMP_STTS")->AsString;          //	N	NUMBER(2)	    Y			대기 상태
                pObj->shpr.ESWS_WNSP = pADO->FieldByName("ESWS_WNSP")->AsString;          //	N	NUMBER(5,2)	    Y	0		동서 풍속
                pObj->shpr.NRST_WNSP = pADO->FieldByName("NRST_WNSP")->AsString;          //	N	NUMBER(5,2)	    Y	0		남북 풍속
                pObj->shpr.HMDT      = pADO->FieldByName("HMDT")->AsString;               //	N	NUMBER(5,2)	    Y	0		습도
                pObj->shpr.PRCP_STTS = pADO->FieldByName("PRCP_STTS")->AsString;          //	N	NUMBER(3)	    Y	0		강수 상태
                pObj->shpr.THND_STTS = pADO->FieldByName("THND_STTS")->AsString;          //	N	NUMBER(2)	    Y			낙뢰 상태
                pObj->shpr.WNDR      = pADO->FieldByName("WNDR")->AsString;               //	N	NUMBER(2)	    Y			풍향
                pObj->shpr.WNSP      = pADO->FieldByName("WNSP")->AsString;               //	N	NUMBER(5,2)	    Y	0		풍속

#if 0
                int wndr = pObj->shpr.WNDR.ToIntDef(0);
                if (wndr >=   0 && wndr <    45) pObj->shpr.WNDR_NM = "N-NE";
                if (wndr >=  45 && wndr <    90) pObj->shpr.WNDR_NM = "NE-E";
                if (wndr >=  90 && wndr <   135) pObj->shpr.WNDR_NM = "E-SE";
                if (wndr >= 135 && wndr <   180) pObj->shpr.WNDR_NM = "SE-S";
                if (wndr >= 180 && wndr <   225) pObj->shpr.WNDR_NM = "S-SW";
                if (wndr >= 225 && wndr <   270) pObj->shpr.WNDR_NM = "SW-W";
                if (wndr >= 270 && wndr <   315) pObj->shpr.WNDR_NM = "W-NW";
                if (wndr >= 315 && wndr <=  360) pObj->shpr.WNDR_NM = "NW-N";
#else
                //풍향값에 따른 16방위 변환
                int wndr = pObj->shpr.WNDR.ToIntDef(0);
                int wndrDir = (int)(((float)wndr + 22.5 * 0.5 ) / 22.5);
                switch(wndrDir)
                {
                case  0: pObj->shpr.WNDR_NM = "N";   break;
                case  1: pObj->shpr.WNDR_NM = "NNE"; break;
                case  2: pObj->shpr.WNDR_NM = "NE";  break;
                case  3: pObj->shpr.WNDR_NM = "ENE"; break;
                case  4: pObj->shpr.WNDR_NM = "E";   break;
                case  5: pObj->shpr.WNDR_NM = "ESE"; break;
                case  6: pObj->shpr.WNDR_NM = "SE";  break;
                case  7: pObj->shpr.WNDR_NM = "SSE"; break;
                case  8: pObj->shpr.WNDR_NM = "S";   break;
                case  9: pObj->shpr.WNDR_NM = "SSW"; break;
                case 10: pObj->shpr.WNDR_NM = "SW";  break;
                case 11: pObj->shpr.WNDR_NM = "WSW"; break;
                case 12: pObj->shpr.WNDR_NM = "W";   break;
                case 13: pObj->shpr.WNDR_NM = "WNW"; break;
                case 14: pObj->shpr.WNDR_NM = "NW";  break;
                case 15: pObj->shpr.WNDR_NM = "NNW"; break;
                case 16: pObj->shpr.WNDR_NM = "N";   break;
                }
#endif

                //하늘상태 - 맑음(1), 구름조금(2), 구름많음(3), 흐림(4)
                switch(pObj->shpr.ATMP_STTS.ToIntDef(0))
                {
                case 1:  pObj->shpr.ATMP_STTS_NM = "맑음";     break;
                case 2:  pObj->shpr.ATMP_STTS_NM = "구름조금"; break;
                case 3:  pObj->shpr.ATMP_STTS_NM = "구름많음"; break;
                case 4:  pObj->shpr.ATMP_STTS_NM = "흐림";     break;
                default: pObj->shpr.ATMP_STTS_NM = "-";        break;
                }

                // 동서바람성분(m/s) - 동(+), 서(-)
                fTemp = pADO->FieldByName("ESWS_WNSP")->AsFloat;
                if      (fTemp > 0)  pObj->shpr.ESWS_WNSP_NM = "동 " + FormatFloat("#0.#0", fTemp);
                else if (fTemp < 0)  pObj->shpr.ESWS_WNSP_NM = "서 " + FormatFloat("#0.#0", fTemp*-1);
                else                 pObj->shpr.ESWS_WNSP_NM = "-";

                // 남북바람성분(m/s) - 북(+), 남(-)
                fTemp = pADO->FieldByName("NRST_WNSP")->AsFloat;
                if      (fTemp > 0)  pObj->shpr.NRST_WNSP_NM = "북 " + FormatFloat("#0.#0", fTemp);
                else if (fTemp < 0)  pObj->shpr.NRST_WNSP_NM = "남 " + FormatFloat("#0.#0", fTemp*-1);
                else                 pObj->shpr.NRST_WNSP_NM = "-";

                //강수형태 - 없음(0), 비(1), 비/눈(2), 눈(3)
                switch(pObj->shpr.PRCP_STTS.ToIntDef(0))
                {
                case 0:  pObj->shpr.PRCP_STTS_NM = "없음";  break;
                case 1:  pObj->shpr.PRCP_STTS_NM = "비";    break;
                case 2:  pObj->shpr.PRCP_STTS_NM = "비/눈"; break;
                case 3:  pObj->shpr.PRCP_STTS_NM = "눈";    break;
                default: pObj->shpr.PRCP_STTS_NM = "-";     break;
                }

                //낙뢰 - 없음(0), 있음(1)
                switch(pObj->shpr.THND_STTS.ToIntDef(0))
                {
                case 0:  pObj->shpr.THND_STTS_NM = "없음"; break;
                case 1:  pObj->shpr.THND_STTS_NM = "비";   break;
                default: pObj->shpr.THND_STTS_NM = "-";    break;
                }

                fTemp = pADO->FieldByName("WNSP")->AsFloat;
                pObj->shpr.WNSP_ALARM = VILG_NONE;         // 강풍알람
                if      (fTemp >= 21) pObj->shpr.WNSP_ALARM = VILG_ALARM;
                else if (fTemp >= 14) pObj->shpr.WNSP_ALARM = VILG_WARNING;
                if (pObj->shpr.WNSP_ALARM != VILG_NONE)
                {
                }
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadVilgShprInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadVilgShprInfo", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FLists.UnLock();
    }

    return true;
}
//---------------------------------------------------------------------------
String TItsVilgFrcsManager::GetGradeDesc(String &ACode)
{
    ACode = ACode.Trim();
    if (ACode == "1") return ATMP_GOOD;
    if (ACode == "2") return ATMP_NORMAL;
    if (ACode == "3") return ATMP_BAD;
    if (ACode == "4") return ATM_VERY_BAD;

    ACode = "0";
    return ATMP_NONE;
}
//---------------------------------------------------------------------------

bool TItsVilgFrcsManager::LoadAtmpPltnInfo(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                                                       \r\n"
           "  FROM TB_ATMP_PLTN_RT_PNST                                    \r\n"
           " WHERE MSRM_DT >= TO_CHAR(SYSDATE-120/1440,'YYYYMMDDHH24MISS') \r\n";

    try
    {
        int nTemp;
        float fTemp;
        FAtmpLists.Lock();
        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())
            {
                String ATMP_STTN_NMBR = pADO->FieldByName("ATMP_STTN_NMBR")->AsString;
				TItsAtmpPltn *pObj = FAtmpLists.Find(ATMP_STTN_NMBR);
                if (!pObj) continue;

                pObj->pnst.MSRM_DT          = pADO->FieldByName("MSRM_DT")->AsString;        //	N	VARCHAR2(14)	Y			측정 일시
                pObj->pnst.MSRM_SYST_NM     = pADO->FieldByName("MSRM_SYST_NM")->AsString;   //	N	VARCHAR2(10)	Y			측정 시스템 명
                pObj->pnst.CO_VAL           = pADO->FieldByName("CO_VAL")->AsString;         //	N	VARCHAR2(10)	Y			CO 값
                pObj->pnst.SO2_VAL          = pADO->FieldByName("SO2_VAL")->AsString;        //	N	VARCHAR2(10)	Y			SO2 값
                pObj->pnst.NO2_VAL          = pADO->FieldByName("NO2_VAL")->AsString;        //	N	VARCHAR2(10)	Y			NO2 값
                pObj->pnst.O3_VAL           = pADO->FieldByName("O3_VAL")->AsString;         //	N	VARCHAR2(10)	Y			O3 값
                pObj->pnst.PM10_VAL         = pADO->FieldByName("PM10_VAL")->AsString;       //	N	VARCHAR2(10)	Y			PM10 값
                pObj->pnst.PM10_24HH_VAL    = pADO->FieldByName("PM10_24HH_VAL")->AsString;  //	N	VARCHAR2(10)	Y			PM10 24시간 값
                pObj->pnst.PM25_VAL         = pADO->FieldByName("PM25_VAL")->AsString;       //	N	VARCHAR2(10)	Y			PM25 값
                pObj->pnst.PM25_24HH_VAL    = pADO->FieldByName("PM25_24HH_VAL")->AsString;  //	N	VARCHAR2(10)	Y			PM25 24시간 값
                pObj->pnst.INTG_ATMP_VAL    = pADO->FieldByName("INTG_ATMP_VAL")->AsString;  //	N	VARCHAR2(10)	Y			통합 대기 값
                pObj->pnst.INTG_ATMP_GRAD   = pADO->FieldByName("INTG_ATMP_GRAD")->AsString; //	N	VARCHAR2(10)	Y			통합 대기 등급
                pObj->pnst.SO2_GRAD         = pADO->FieldByName("SO2_GRAD")->AsString;       //	N	VARCHAR2(10)	Y			SO2 등급
                pObj->pnst.CO_GRAD          = pADO->FieldByName("CO_GRAD")->AsString;        //	N	VARCHAR2(10)	Y			CO 등급
                pObj->pnst.O3_GRAD          = pADO->FieldByName("O3_GRAD")->AsString;        //	N	VARCHAR2(10)	Y			O3 드급
                pObj->pnst.NO2_GRAD         = pADO->FieldByName("NO2_GRAD")->AsString;       //	N	VARCHAR2(10)	Y			NO2 등급
                pObj->pnst.PM10_24HH_GRAD   = pADO->FieldByName("PM10_24HH_GRAD")->AsString; //	N	VARCHAR2(10)	Y			PM10 24시간 등급
                pObj->pnst.PM25_24HH_GRAD   = pADO->FieldByName("PM25_24HH_GRAD")->AsString; //	N	VARCHAR2(10)	Y			PM25 24시간 등급
                pObj->pnst.PM10_1HH_GRAD    = pADO->FieldByName("PM10_1HH_GRAD")->AsString;  //	N	VARCHAR2(10)	Y			PM10 1시간 등급
                pObj->pnst.PM25_1HH_GRAD    = pADO->FieldByName("PM25_1HH_GRAD")->AsString;  //	N	VARCHAR2(10)	Y			PM25 1시간 등급
                pObj->pnst.UPDT_DT          = pADO->FieldByName("UPDT_DT")->AsString;        // N	VARCHAR2(14)	Y			갱신 일시

                pObj->pnst.INTG_ATMP_GRAD_NM   = GetGradeDesc(pObj->pnst.INTG_ATMP_GRAD);
                pObj->pnst.SO2_GRAD_NM         = GetGradeDesc(pObj->pnst.SO2_GRAD);
                pObj->pnst.CO_GRAD_NM          = GetGradeDesc(pObj->pnst.CO_GRAD);
                pObj->pnst.O3_GRAD_NM          = GetGradeDesc(pObj->pnst.O3_GRAD);
                pObj->pnst.NO2_GRAD_NM         = GetGradeDesc(pObj->pnst.NO2_GRAD);
                pObj->pnst.PM10_24HH_GRAD_NM   = GetGradeDesc(pObj->pnst.PM10_24HH_GRAD);
                pObj->pnst.PM25_24HH_GRAD_NM   = GetGradeDesc(pObj->pnst.PM25_24HH_GRAD);
                pObj->pnst.PM10_1HH_GRAD_NM    = GetGradeDesc(pObj->pnst.PM10_1HH_GRAD);
                pObj->pnst.PM25_1HH_GRAD_NM    = GetGradeDesc(pObj->pnst.PM25_1HH_GRAD);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadAtmpPltnInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadAtmpPltnInfo", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FAtmpLists.UnLock();
    }

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

bool TItsVilgFrcsManager::LoadAtmpSprpInfo(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT *                                                    \r\n"
           "  FROM TB_ATMP_PLTN_SPRP_PNST A                             \r\n"
           " WHERE A.ANNC_DVSN = '1'                                    \r\n"
           "   AND A.ANNC_DT > TO_CHAR(SYSDATE-31/1440,'YYYYMMDDHH24')  \r\n";

    try
    {
        FSprpLists.Lock();
        FSprpLists.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())
            {
                TItsAtmpSprp *pObj = new TItsAtmpSprp();

                pObj->ATMP_PLTN_KIND = pADO->FieldByName("ATMP_PLTN_KIND")->AsString.Trim(); //	N	VARCHAR2(1)	    N			대기 오염 종류(1:미세먼지, 2:초미세먼지)
                pObj->ANNC_DT        = pADO->FieldByName("ANNC_DT")->AsString.Trim();        //	N	VARCHAR2(14)	Y			Update 시간
                pObj->REGN_CD        = pADO->FieldByName("REGN_CD")->AsString.Trim();        //	N	VARCHAR2(1)	    Y	2		권역 코드(1:북부권, 2:동부권, 3:중부권, 4:남부권) 남양주=동부권
                pObj->ANNC_YMD       = pADO->FieldByName("ANNC_YMD")->AsString.Trim();       //	N	VARCHAR2(8)	    Y			발표 일자(4)
                pObj->ANNC_HH        = pADO->FieldByName("ANNC_HH")->AsString.Trim();        //	N	VARCHAR2(2)	    Y			발표 시간(2)
                pObj->ANNC_GRAD      = pADO->FieldByName("ANNC_GRAD")->AsString.Trim();      //	N	VARCHAR2(1)	    Y			발표 등급(1:주의보, 2:경보, 5:황사경보)
                pObj->ANNC_DVSN      = pADO->FieldByName("ANNC_DVSN")->AsString.Trim();      //	N	VARCHAR2(1)	    Y			발표 구분(1:발령, 0:해제, 2:발령내역없음)

				FSprpLists.Push(pObj->ATMP_PLTN_KIND, pObj);
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadAtmpSprpInfo", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsVilgFrcsManager::LoadAtmpSprpInfo", String(exception.ClassName()), exception.Message, sQry);
            throw Exception(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        FSprpLists.UnLock();
    }

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

