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

#pragma hdrstop

#include "CDSNodeF.h"
#include "AppGlobalF.h"

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

#pragma package(smart_init)

TItsNode::TItsNode()
{
}
//---------------------------------------------------------------------------
void TItsNode::Clear()
{
}
//---------------------------------------------------------------------------
TItsNode::~TItsNode()
{
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
TItsNodeManager *ItsNodeManager = NULL;
//---------------------------------------------------------------------------

/*
* Node Manager
*/
TItsNodeManager::TItsNodeManager()
{
}
//---------------------------------------------------------------------------
TItsNodeManager::~TItsNodeManager()
{
}
//---------------------------------------------------------------------------
bool TItsNodeManager::LoadFromDb(TADOConnection *ADbConn/*=NULL*/)
{
    String sQry;
    TADOQuery *pADO = NULL;

    sQry = "SELECT A.NODE_ID, A.NODE_TYPE, A.NODE_NAME, \r\n"
           "       A.TURN_P, A.RMRK, A.X_CRDN, A.Y_CRDN \r\n"
           "  FROM TB_NODE A                            \r\n";

    FLists.Lock();
    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())
            {
				TItsNode *pNode = new TItsNode();

                pNode->NODE_ID   = pADO->FieldByName("NODE_ID")->AsString;              //노드ID
                pNode->NODE_TYPE = pADO->FieldByName("NODE_TYPE")->AsString;            //노드유형
                pNode->NODE_NAME = pADO->FieldByName("NODE_NAME")->AsString.Trim();     //교차로명칭
                pNode->TURN_P    = pADO->FieldByName("TURN_P")->AsString;               //회전제한유무
                pNode->RMRK      = pADO->FieldByName("RMRK")->AsString.Trim();          //비고
                pNode->X_CRDN    = pADO->FieldByName("X_CRDN")->AsFloat;                //X 좌표
                pNode->Y_CRDN    = pADO->FieldByName("Y_CRDN")->AsFloat;                //Y 좌표

				FLists.Push(pNode->NODE_ID, pNode);
                pNode->Completed = true;
            }
        }
        catch(EDatabaseError &E)
        {
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG("TItsNodeManager::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("TItsNodeManager::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;
}
//---------------------------------------------------------------------------

