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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "WindowMsgF.h"
#include "AppGlobalF.h"
#include "ITSSEL1MF.h"
#include "ITSSELAMF.h"
#include "CDSLinkF.h"
#include "CDSNodeF.h"
#include "ITSLangTransF.h"
#include "ITS0000MF.h"
#include "ITS_OPLibF.h"
#pragma hdrstop

#include "FRAME_IncidentProcessF.h"
#include "FrmIncidVmsInfoF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalc"
#pragma link "cxCalendar"
#pragma link "cxCheckBox"
#pragma link "cxClasses"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxDropDownEdit"
#pragma link "cxEdit"
#pragma link "cxFilter"
#pragma link "cxGraphics"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxMaskEdit"
#pragma link "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "cxTextEdit"
#pragma link "dxGDIPlusClasses"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"
TFRAMEIncidentProcess *FRAMEIncidentProcess;
//---------------------------------------------------------------------------
__fastcall TFRAMEIncidentProcess::TFRAMEIncidentProcess(TComponent* Owner)
    : TFrame(Owner)
{
    GrpIncid->Visible = false;

    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load((TForm*)this);

    FTitle = Caption;//"돌발 진행상황 처리";

    FOcrrType   = 0;

    FLinkId = "";
    FINCD_OCRR_ID = "";

    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<등록된 돌발정보가 없습니다>";

    FCodeIST  = ItsCodeManager->FLists.Find("IST");  //돌발상황 원본 코드 : IST
    FCodeLTCU = ItsCodeManager->FLists.Find("LTCU");//LTCU"); //소통 등급 코드 : LTCU
    FCodeICM  = ItsCodeManager->FLists.Find("ICM");  //돌발상황 확인 방법 코드 : ICM
    FCodeIDTU = ItsCodeManager->FLists.Find("IDTU"); //돌발상황 유형 분류 코드 : IDTU

    FCodeACTU = ItsCodeManager->FLists.Find("ACTU"); //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
    FCodeCRTU = ItsCodeManager->FLists.Find("CRTU"); //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
    FCodeEVTU = ItsCodeManager->FLists.Find("EVTU"); //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
    FCodeWETU = ItsCodeManager->FLists.Find("WETU"); //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
    FCodeCNTU = ItsCodeManager->FLists.Find("CNTU"); //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
    FCodeCATU = ItsCodeManager->FLists.Find("CATU"); //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
    FCodeAETC = ItsCodeManager->FLists.Find("AETC");

    FCodeSRLU = ItsCodeManager->FLists.Find("SRLU"); //돌발상황 심각도 코드 : SRLU
    FCodePRTU = ItsCodeManager->FLists.Find("PRTU"); //통행 제한 유형 코드 : PRTU
    FCodeRSL  = ItsCodeManager->FLists.Find("RSL");  //대응 수준 코드 : RSL
    FCodeISS  = ItsCodeManager->FLists.Find("ISS");  //돌발상황 진행 단계 코드 : ISS
    FCodeICM  = ItsCodeManager->FLists.Find("ICM");  //돌발상황 종료 확인 방법 코드 : ICM
    FCodeDFW  = ItsCodeManager->FLists.Find("DFW");  //기상 코드 : DFW
    FCodeVIT  = ItsCodeManager->FLists.Find("VIT");  //VMS 돌발 유형 코드 : VIT
    FCodeIDT  = ItsCodeManager->FLists.Find("IDT");  //VMS 돌발 유형 세부 코드 : IDT
    FCodeEDT  = ItsCodeManager->FLists.Find("EDT");  //VMS 돌발 유형 세부 코드 : EDT
    FCodeVRT  = ItsCodeManager->FLists.Find("VRT");  //VMS 돌발 통제 코드 : VRT

    InitForm();
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::InitForm()
{
    FSelLink.nSelLink = 0;
    for(int ii = 0; ii < MAX_INCLINK; ii++)
    {
        FSelLink.info[ii].sIncidentId = "";
        FSelLink.info[ii].sLinkId = "";
        FSelLink.info[ii].FPosX = 0;
        FSelLink.info[ii].FPosY = 0;
    }

	DtINCD_STRT_DT->Date = Now();
	DtINCD_END_PRAR_DT->Date = Now() + ( 1 / 24 );

    CbINCD_ORGN_CD->Properties->Items->Clear();
	if (FCodeIST)
	{
		FOR_STL(TItsSubCode *, pSubCode, FCodeIST->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbINCD_ORGN_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
    CbINCD_ORGN_CD->ItemIndex = 0;

    CbCMTR_GRAD_CD->Properties->Items->Clear();
	if (FCodeLTCU)
	{
		FOR_STL(TItsSubCode *, pSubCode, FCodeLTCU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
		    CbCMTR_GRAD_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
    CbCMTR_GRAD_CD->ItemIndex = 0;

    CbINCD_CNFM_MTHD_CD->Properties->Items->Clear();
	if (FCodeICM)
	{
		FOR_STL(TItsSubCode *, pSubCode, FCodeICM->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
		    CbINCD_CNFM_MTHD_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
    CbINCD_CNFM_MTHD_CD->ItemIndex = 0;

    CbINCD_SERN_CD->Properties->Items->Clear();
	if (FCodeSRLU)
	{
		FOR_STL(TItsSubCode *, pSubCode, FCodeSRLU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
		    CbINCD_SERN_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
    CbINCD_SERN_CD->ItemIndex = 0;

    CbINCD_TYPE_CLSF_CD->Properties->Items->Clear();
	if (FCodeIDTU)
	{
		FOR_STL(TItsSubCode *, pSubCode, FCodeIDTU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
		    CbINCD_TYPE_CLSF_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
    CbINCD_TYPE_CLSF_CD->ItemIndex = 0;
    CbINCD_TYPE_CLSF_CDClick((TObject *)CbINCD_TYPE_CLSF_CD);

#if 0
	if (FCodeACTU)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeACTU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
            CbINCD_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
	if (FCodeCRTU)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeCRTU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbINCD_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
	if (FCodeEVTU)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeEVTU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbINCD_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
	if (FCodeWETU)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeWETU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbINCD_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
#endif

	//통행 제한 유형 코드 : PRTU
	if (FCodePRTU)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodePRTU->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbTRVL_LMNT_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
	//대응 수준 코드 : RSL
	if (FCodeRSL)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeRSL->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbRESP_LVL_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}

	//기상 코드 : DFW
	if (FCodeDFW)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeDFW->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbWTHR_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}

	//VMS 돌발 유형 코드 : VIT
	if (FCodeVIT)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeVIT->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbVMS_INCD_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
	//VMS 돌발 통제 코드 : VRT
	if (FCodeVRT)
	{
		FOR_STL(TItsSubCode *, pSubCode , FCodeVRT->FSubLists)
		{
			if (pSubCode->USE_YN == "N") continue;
			CbVMS_INCD_RSTR_TYPE_CD->Properties->Items->Add( " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
		}
	}
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::InitScreen()
{
    FSelLink.nSelLink = 0;
    for(int ii = 0; ii < MAX_INCLINK; ii++)
    {
        FSelLink.info[ii].sIncidentId = "";
        FSelLink.info[ii].sLinkId = "";
        FSelLink.info[ii].FPosX = 0;
        FSelLink.info[ii].FPosY = 0;
    }

    EdINCD_OCRR_ID->Text				= "";
    EdRGST_DT->Text					    = "";
    EdRegDt->Text					    = "";
    CbINCD_ORGN_CD->Text				= "";
    EdOCRR_LCTN_NM->Text				= "";
    EdLINK_ID->Text					    = "";
    EdLinkId->Text                      = "";
    SePosX->Value						= 0;
    SePosY->Value						= 0;
    EdINCD_EXPL->Text					= "";
    CbCMTR_GRAD_CD->Text				= "";
    EdIFMR_NM->Text					    = "";
    CbINCD_CNFM_MTHD_CD->Text			= "";
    CbINCD_SERN_CD->Text				= "";
    EdINCD_TITL->Text					= "";
    CbINCD_TYPE_CLSF_CD->Text			= "";
    CbINCD_TYPE_CD->Text				= "";
    DtINCD_STRT_DT->Date				= Now();
    DtINCD_END_PRAR_DT->Date			= Now();
    ChkINCD_OCRR_LANE_Extra->Checked	= false;
    ChkINCD_OCRR_LANE_1->Checked		= false;
    ChkINCD_OCRR_LANE_2->Checked		= false;
    ChkINCD_OCRR_LANE_3->Checked		= false;
    ChkINCD_OCRR_LANE_4->Checked		= false;
    ChkINCD_OCRR_LANE_5->Checked		= false;
    ChkINCD_CLSR_LANE_Extra->Checked	= false;
    ChkINCD_CLSR_LANE_1->Checked		= false;
    ChkINCD_CLSR_LANE_2->Checked		= false;
    ChkINCD_CLSR_LANE_3->Checked		= false;
    ChkINCD_CLSR_LANE_4->Checked		= false;
    ChkINCD_CLSR_LANE_5->Checked		= false;
    SeDELY_LNGT->Value					= 0;
    SeINCD_LNGT->Value					= 0;
    SeSMLT_VHCL_UNUM->Value			    = 0;
    SeMDLT_VHCL_UNUM->Value			    = 0;
    SeINJR_PNUM->Value					= 0;
    SeFTLT_PNUM->Value					= 0;
    CbWTHR_CD->Text					    = "";
    CbRESP_LVL_CD->Text				    = "";
    if (ChkUTIS_CNCT_YN->Enabled) ChkUTIS_CNCT_YN->Checked			= false;
    ChkTRUB_VHCL_YN->Checked			= false;
    ChkFALT_YN->Checked					= false;
    ChkFRWT_YN->Checked					= false;
    CbTRVL_LMNT_TYPE_CD->Text			= "";
    ChkVMS_DSPL_YN->Checked				= false;
    EdSTRT_LCTN_NM->Text				= "";
    EdEND_LCTN_NM->Text				    = "";
    CbVMS_INCD_TYPE_CD->Text			= "";
    CbVMS_INCD_DETL_TYPE_CD->Text		= "";
#ifdef YONGIN_INC
    CbVMS_INCD_RSTR_TYPE_CD->Text		= "";
#endif
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::UpdateList()
{
    InitScreen();

    TItsSubCode *pSubCode;

    CMM_ClearGridTableView(TvList);

    TcxDataController *pGDC = TvList->DataController;
    int nRow = 0;
    try
    {
        TvList->BeginUpdate();

        try
        {
            ItsIncidentManager->FLists.Lock();
            FOR_STL(TItsIncident *, pObj, ItsIncidentManager->FLists)
            {
#if 0
                if (pObj->INCD_PRGR_STEP_CD != "ISS1" &&
                    pObj->INCD_PRGR_STEP_CD != "ISS2") continue;
#else
                if (pObj->INCD_PRGR_STEP_CD != "ISS2") continue;
#endif

                nRow = pGDC->AppendRecord();

                String sIST  = "";
                if (pObj->INCD_ORGN_CD != "") sIST = " [" + pObj->INCD_ORGN_CD + "] ";
                String sLTCU= "";
                if (pObj->CMTR_GRAD_CD != "") sLTCU = " [" + pObj->CMTR_GRAD_CD + "] ";
                String sICM = "";
                if (pObj->INCD_CNFM_MTHD_CD != "") sICM  = " [" + pObj->INCD_CNFM_MTHD_CD + "] ";
                String sSRLU= "";
                if (pObj->INCD_SERN_CD != "") sSRLU = " [" + pObj->INCD_SERN_CD + "] ";
                String sIDTU = "";
                if (pObj->INCD_TYPE_CLSF_CD != "") sIDTU = " [" + pObj->INCD_TYPE_CLSF_CD + "] ";
                String sACTU = "";
                if (pObj->INCD_TYPE_CD != "") sACTU = " [" + pObj->INCD_TYPE_CD + "] ";
                String sISS  = "";
                if (pObj->INCD_PRGR_STEP_CD != "") sISS = " [" + pObj->INCD_PRGR_STEP_CD + "] ";

                String sDFW  = "";
                if (pObj->WTHR_CD != "") sDFW = " [" + pObj->WTHR_CD + "] ";

                String sRSL  = "";
                if (pObj->RESP_LVL_CD != "") sRSL = " [" + pObj->RESP_LVL_CD + "] ";
                String sPRTU = "";
                if (pObj->TRVL_LMNT_TYPE_CD != "") sPRTU = " [" + pObj->TRVL_LMNT_TYPE_CD + "] ";

                if (FCodeIST)
                {
                    pSubCode = FCodeIST->FSubLists.Find(pObj->INCD_ORGN_CD);
                    if (pSubCode) sIST = sIST + pSubCode->CMMN_CD_KOR_NM;
                }
                if (FCodeLTCU)
                {
                    pSubCode = FCodeLTCU->FSubLists.Find(pObj->CMTR_GRAD_CD);
                    if (pSubCode) sLTCU = sLTCU + pSubCode->CMMN_CD_KOR_NM;
                }
                if (FCodeICM)
                {
                    pSubCode = FCodeICM->FSubLists.Find(pObj->INCD_CNFM_MTHD_CD);
                    if (pSubCode) sICM = sICM + pSubCode->CMMN_CD_KOR_NM;
                }
                if (FCodeSRLU)
                {
                    pSubCode = FCodeSRLU->FSubLists.Find(pObj->INCD_SERN_CD);
                    if (pSubCode) sSRLU = sSRLU + pSubCode->CMMN_CD_KOR_NM;
                }
                if (FCodeIDTU)
                {
                    pSubCode = FCodeIDTU->FSubLists.Find(pObj->INCD_TYPE_CLSF_CD);
                    if (pSubCode) sIDTU = sIDTU + pSubCode->CMMN_CD_KOR_NM;
                }

                if (!pObj->INCD_TYPE_CLSF_CD.IsEmpty() && !pObj->INCD_TYPE_CD.IsEmpty())
                {
                    if (pObj->INCD_TYPE_CLSF_CD == "1")
                    {
                        if (FCodeACTU)
                        {
                            pSubCode = FCodeACTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                    else if (pObj->INCD_TYPE_CLSF_CD == "2")
                    {
                        if (FCodeCRTU)
                        {
                            pSubCode = FCodeCRTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                    else if (pObj->INCD_TYPE_CLSF_CD == "3")
                    {
                        if (FCodeEVTU)
                        {
                            pSubCode = FCodeEVTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                    else if (pObj->INCD_TYPE_CLSF_CD == "4")
                    {
                        if (FCodeWETU)
                        {
                            pSubCode = FCodeWETU->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                    else if (pObj->INCD_TYPE_CLSF_CD == "5")
                    {
                        if (FCodeCNTU)
                        {
                            pSubCode = FCodeCNTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                    else if (pObj->INCD_TYPE_CLSF_CD == "6")
                    {
                        if (FCodeCATU)
                        {
                            pSubCode = FCodeCATU->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                    else if (pObj->INCD_TYPE_CLSF_CD == "9")
                    {
                        if (FCodeAETC)
                        {
                            pSubCode = FCodeAETC->FSubLists.Find(pObj->INCD_TYPE_CD);
                            if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                        }
                    }
                }

                if (FCodeISS)
                {
                    pSubCode = FCodeISS->FSubLists.Find(pObj->INCD_PRGR_STEP_CD);
                    if (pSubCode) sISS = sISS + pSubCode->CMMN_CD_KOR_NM;
                }

                if (FCodeDFW)
                {
                    pSubCode = FCodeISS->FSubLists.Find(pObj->WTHR_CD);
                    if (pSubCode) sDFW = sDFW + pSubCode->CMMN_CD_KOR_NM;
                }

                if (FCodeRSL)
                {
                    pSubCode = FCodeRSL->FSubLists.Find(pObj->RESP_LVL_CD);
                    if (pSubCode) sRSL = sRSL + pSubCode->CMMN_CD_KOR_NM;
                }

                if (FCodePRTU)
                {
                    pSubCode = FCodePRTU->FSubLists.Find(pObj->TRVL_LMNT_TYPE_CD);
                    if (pSubCode) sPRTU = sPRTU + pSubCode->CMMN_CD_KOR_NM;
                }

                pGDC->Values[nRow][Column01->Index] = pObj->INCD_OCRR_ID;                //돌발상황 발생 ID

                pGDC->Values[nRow][Column02->Index] = ITSUtil_StrToTime(pObj->RGST_DT);                     //등록 일시

                pGDC->Values[nRow][Column03->Index] = sISS;//pObj->INCD_PRGR_STEP_CD;    //돌발상황 진행 단계 코드 : ISS
                pGDC->Values[nRow][Column04->Index] = sIST;//pObj->INCD_ORGN_CD;         //돌발상황 원본 코드 : IST
                pGDC->Values[nRow][Column05->Index] = pObj->OCRR_LCTN_NM;                //발생 위치 명
                pGDC->Values[nRow][Column06->Index] = pObj->LINK_ID;                     //돌발발생 LINK ID
                pGDC->Values[nRow][Column07->Index] = pObj->X_CRDN;                      //X 좌표
                pGDC->Values[nRow][Column08->Index] = pObj->Y_CRDN;                      //Y 좌표
                pGDC->Values[nRow][Column09->Index] = pObj->INCD_EXPL;                   //돌발상황 설명
                pGDC->Values[nRow][Column10->Index] = sLTCU;//pObj->CMTR_GRAD_CD;        //소통 등급 코드 : LTCU
                pGDC->Values[nRow][Column11->Index] = pObj->IFMR_NM;                     //제보자 명
                pGDC->Values[nRow][Column12->Index] = sICM;//pObj->INCD_CNFM_MTHD_CD;    //돌발상황 확인 방법 코드 : ICM
                pGDC->Values[nRow][Column13->Index] = sSRLU;//pObj->INCD_SERN_CD;        //돌발상황 심각도 코드 : SRLU
                pGDC->Values[nRow][Column14->Index] = pObj->INCD_TITL;                   //돌발상황 제목
                pGDC->Values[nRow][Column15->Index] = sIDTU;//pObj->INCD_TYPE_CLSF_CD;   //돌발상황 유형 분류 코드 : IDTU
                pGDC->Values[nRow][Column16->Index] = sACTU;//pObj->INCD_TYPE_CD;        //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나

                pGDC->Values[nRow][Column17->Index] = ITSUtil_StrToTime(pObj->INCD_STRT_DT);                //돌발상황 시작 일시
                pGDC->Values[nRow][Column18->Index] = ITSUtil_StrToTime(pObj->INCD_END_PRAR_DT);            //돌발상황 종료 예정 일시

                pGDC->Values[nRow][Column19->Index] = pObj->INCD_OCRR_LANE;              //돌발상황 발생 차로
                pGDC->Values[nRow][Column20->Index] = pObj->INCD_CLSR_LANE;              //돌발상황 차단 차로
                pGDC->Values[nRow][Column21->Index] = pObj->DELY_LNGT;                   //지체 길이
                pGDC->Values[nRow][Column22->Index] = pObj->INCD_LNGT;                   //돌발상황 길이
                pGDC->Values[nRow][Column23->Index] = pObj->SMLT_VHCL_UNUM;              //소형 차량 대수
                pGDC->Values[nRow][Column24->Index] = pObj->MDLT_VHCL_UNUM;              //중대형 차량 대수
                pGDC->Values[nRow][Column25->Index] = pObj->INJR_PNUM;                   //부상자 인원수
                pGDC->Values[nRow][Column26->Index] = pObj->FTLT_PNUM;                   //사망자 인원수
                pGDC->Values[nRow][Column27->Index] = sDFW;//pObj->WTHR_CD;              //기상 코드 : DFW
                pGDC->Values[nRow][Column28->Index] = sRSL;//pObj->RESP_LVL_CD;          //대응 수준 코드 : RSL
                pGDC->Values[nRow][Column29->Index] = pObj->UTIS_CNCT_YN;                //UTIS 연계 여부
                pGDC->Values[nRow][Column30->Index] = pObj->TRUB_VHCL_YN;                //고장 차량 여부
                pGDC->Values[nRow][Column31->Index] = pObj->FALT_YN;                     //낙하물 여부
                pGDC->Values[nRow][Column32->Index] = pObj->FRWT_YN;                     //화재위험물 여부
                pGDC->Values[nRow][Column33->Index] = sPRTU;//pObj->TRVL_LMNT_TYPE_CD;   //통행 제한 유형 코드 : PRTU
                pGDC->Values[nRow][Column34->Index] = pObj->VMS_DSPL_YN;                 //VMS 표출 여부
                pGDC->Values[nRow][Column35->Index] = ITSUtil_StrToDateTime(pObj->INCD_CNFM_DT);                 //VMS 표출 여부

                pGDC->Values[nRow][Column99->Index] = (int)pObj;
            }
        }
        __finally
        {
            ItsIncidentManager->FLists.UnLock();
        }
    }
    __finally
    {
        LblRecords->Caption = "("+FormatFloat("##,##0", pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", pGDC->RecordCount) + ")";
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }

#if 0
    if (FINCD_OCRR_ID != "")
    {
        CMM_SetGridRow(CxList, TvList, FINCD_OCRR_ID, Column01->Index);
        DisplayIncidentInfo();
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::TvListDataControllerFilterChanged(TObject *Sender)
{
    CMM_SetFilterLike(TvList);
    TcxDataController *pGDC = TvList->DataController;
    LblRecords->Caption = "("+FormatFloat("##,##0", pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", pGDC->RecordCount) + ")";
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::BtnExlSaveClick(TObject *Sender)
{
    TcxGrid          *pGrid = CxList;
    TcxGridTableView *pView = TvList;
    String            sTitle= lblFileName->Caption;//"등록된 돌발정보";

    CMM_ExportToExcelFile(sTitle, pGrid, pView, (TForm*)this);
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::CbINCD_TYPE_CLSF_CDClick(TObject *Sender)
{
	if (CbINCD_TYPE_CLSF_CD->ItemIndex < 0) return;

	CbINCD_TYPE_CD->Properties->Items->Clear();

    String sCode = ITSUtil_GetCode(CbINCD_TYPE_CLSF_CD->Text);
	if (sCode == "1")
	{
		if (FCodeACTU)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeACTU->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
	else
    if (sCode == "2")
	{
		if (FCodeCRTU)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeCRTU->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
	else
    if (sCode == "3")
	{
		if (FCodeEVTU)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeEVTU->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
	else
    if (sCode == "4")
	{
		if (FCodeWETU)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeWETU->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
	else
    if (sCode == "5")
	{
		if (FCodeCNTU)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeCNTU->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
	else
    if (sCode == "6")
	{
		if (FCodeCATU)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeCATU->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
    else
    if (sCode == "9")
	{
		if (FCodeAETC)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeAETC->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbINCD_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
	}
	CbINCD_TYPE_CD->ItemIndex = 0;
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::CbVMS_INCD_TYPE_CDClick(TObject *Sender)
{
	if (CbVMS_INCD_TYPE_CD->ItemIndex < 0)
    {
        cxLabel_VMS_INCD_TYPE_CD->Caption = "사고유형";
        return;
    }

	CbVMS_INCD_DETL_TYPE_CD->Properties->Items->Clear();

#if 0
    String strText = CbVMS_INCD_TYPE_CD->Text;
    cxLabel_VMS_INCD_TYPE_CD->Caption = strText.SubString( 0, strText.Pos( "[" )-1 );
#endif

    String sCode = ITSUtil_GetCode(CbVMS_INCD_TYPE_CD->Text);
    if (sCode == "VIT1")
    {
		if (FCodeIDT)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeIDT->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbVMS_INCD_DETL_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
    }
    else
    if (sCode == "VIT2" )
    {
		if (FCodeEDT)
		{
			FOR_STL(TItsSubCode *, pSubCode, FCodeEDT->FSubLists)
			{
				if (pSubCode->USE_YN == "N") continue;
				CbVMS_INCD_DETL_TYPE_CD->Properties->Items->Add(" [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM);
			}
		}
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::CbVMS_INCD_DETL_TYPE_CDClick(TObject *Sender)
{
	if (CbVMS_INCD_DETL_TYPE_CD->ItemIndex < 0)
    {
        cxLabel_VMS_INCD_TYPE_CD->Caption = "사고유형";
        return;
    }

    String sCode = ITSUtil_GetCode(CbVMS_INCD_TYPE_CD->Text);
    if (sCode == "VIT1")
    {
        sCode = ITSUtil_GetCode(CbVMS_INCD_DETL_TYPE_CD->Text);
        cxLabel_VMS_INCD_TYPE_CD->Caption = APP_GetCodeName(CbVMS_INCD_DETL_TYPE_CD, sCode);
    }
    else
    {
        cxLabel_VMS_INCD_TYPE_CD->Caption = "사고유형";
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::DisplayIncidentInfo()
{
    FLinkId = "";
    //BtnVmsTarget->Enabled = false;

    TcxDataController *pGDC = TvList->DataController;
	int nRow = pGDC->FocusedRecordIndex;
	if( nRow <= -1 )
		return;

    TItsSubCode *pSubCode;
    //TItsIncident *pObj = NULL;
    //int nMemPtr = pGDC->Values[nRow][Column99->Index];
    //pObj = (TItsIncident *)nMemPtr;

    try
    {
        String sINCD_OCRR_ID = pGDC->Values[nRow][Column01->Index];
        FINCD_OCRR_ID = sINCD_OCRR_ID;

        TItsIncident *pObj = ItsIncidentManager->FLists.Find(sINCD_OCRR_ID);
        if (!pObj) return;

//InitScreen();
        String sIST  = "";
        String sLTCU = "";
        String sICM  = "";
        String sSRLU = "";
        String sIDTU = "";
        String sACTU = "";
        String sISS  = "";
        String sDFW  = "";
        String sRSL  = "";
        String sPRTU = "";

        if (pObj->INCD_ORGN_CD      != "") sIST  = " [" + pObj->INCD_ORGN_CD + "] ";
        if (pObj->CMTR_GRAD_CD      != "") sLTCU = " [" + pObj->CMTR_GRAD_CD + "] ";
        if (pObj->INCD_CNFM_MTHD_CD != "") sICM  = " [" + pObj->INCD_CNFM_MTHD_CD + "] ";
        if (pObj->INCD_SERN_CD      != "") sSRLU = " [" + pObj->INCD_SERN_CD + "] ";
        if (pObj->INCD_TYPE_CLSF_CD != "") sIDTU = " [" + pObj->INCD_TYPE_CLSF_CD + "] ";
        if (pObj->INCD_TYPE_CD      != "") sACTU = " [" + pObj->INCD_TYPE_CD + "] ";
        if (pObj->INCD_PRGR_STEP_CD != "") sISS  = " [" + pObj->INCD_PRGR_STEP_CD + "] ";
        if (pObj->WTHR_CD           != "") sDFW  = " [" + pObj->WTHR_CD + "] ";
        if (pObj->RESP_LVL_CD       != "") sRSL  = " [" + pObj->RESP_LVL_CD + "] ";
        if (pObj->TRVL_LMNT_TYPE_CD != "") sPRTU = " [" + pObj->TRVL_LMNT_TYPE_CD + "] ";

        if (FCodeIST)
        {
            pSubCode = FCodeIST->FSubLists.Find(pObj->INCD_ORGN_CD);
            if (pSubCode) sIST = sIST + pSubCode->CMMN_CD_KOR_NM;
        }
        if (FCodeLTCU)
        {
            pSubCode = FCodeLTCU->FSubLists.Find(pObj->CMTR_GRAD_CD);
            if (pSubCode) sLTCU = sLTCU + pSubCode->CMMN_CD_KOR_NM;
        }
        if (FCodeICM)
        {
            pSubCode = FCodeICM->FSubLists.Find(pObj->INCD_CNFM_MTHD_CD);
            if (pSubCode) sICM = sICM + pSubCode->CMMN_CD_KOR_NM;
        }
        if (FCodeSRLU)
        {
            pSubCode = FCodeSRLU->FSubLists.Find(pObj->INCD_SERN_CD);
            if (pSubCode) sSRLU = sSRLU + pSubCode->CMMN_CD_KOR_NM;
        }
        if (FCodeIDTU)
        {
            pSubCode = FCodeIDTU->FSubLists.Find(pObj->INCD_TYPE_CLSF_CD);
            if (pSubCode) sIDTU = sIDTU + pSubCode->CMMN_CD_KOR_NM;
        }

        if (!pObj->INCD_TYPE_CLSF_CD.IsEmpty() && !pObj->INCD_TYPE_CD.IsEmpty())
        {
            if (pObj->INCD_TYPE_CLSF_CD == "1")
            {
                if (FCodeACTU)
                {
                    pSubCode = FCodeACTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            else if (pObj->INCD_TYPE_CLSF_CD == "2")
            {
                if (FCodeCRTU)
                {
                    pSubCode = FCodeCRTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            else if (pObj->INCD_TYPE_CLSF_CD == "3")
            {
                if (FCodeEVTU)
                {
                    pSubCode = FCodeEVTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            else if (pObj->INCD_TYPE_CLSF_CD == "4")
            {
                if (FCodeWETU)
                {
                    pSubCode = FCodeWETU->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            else if (pObj->INCD_TYPE_CLSF_CD == "5")
            {
                if (FCodeCNTU)
                {
                    pSubCode = FCodeCNTU->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            else if (pObj->INCD_TYPE_CLSF_CD == "6")
            {
                if (FCodeCATU)
                {
                    pSubCode = FCodeCATU->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            else if (pObj->INCD_TYPE_CLSF_CD == "9")
            {
                if (FCodeAETC)
                {
                    pSubCode = FCodeAETC->FSubLists.Find(pObj->INCD_TYPE_CD);
                    if (pSubCode) sACTU = sACTU + pSubCode->CMMN_CD_KOR_NM;
                }
            }
        }

        if (FCodeISS)
        {
            pSubCode = FCodeISS->FSubLists.Find(pObj->INCD_PRGR_STEP_CD);
            if (pSubCode) sISS = sISS + pSubCode->CMMN_CD_KOR_NM;
        }

        if (FCodeDFW)
        {
            pSubCode = FCodeDFW->FSubLists.Find(pObj->WTHR_CD);
            if (pSubCode) sDFW = sDFW + pSubCode->CMMN_CD_KOR_NM;
        }

        if (FCodeRSL)
        {
            pSubCode = FCodeRSL->FSubLists.Find(pObj->RESP_LVL_CD);
            if (pSubCode) sRSL = sRSL + pSubCode->CMMN_CD_KOR_NM;
        }

        if (FCodePRTU)
        {
            pSubCode = FCodePRTU->FSubLists.Find(pObj->TRVL_LMNT_TYPE_CD);
            if (pSubCode) sPRTU = sPRTU + pSubCode->CMMN_CD_KOR_NM;
        }

        EdINCD_OCRR_ID->Text        = pObj->INCD_OCRR_ID;
        EdRGST_DT->Text             = ITSUtil_StrToDateTime(pObj->RGST_DT);
        EdRegDt->Text               = pObj->RGST_DT;
        CbINCD_ORGN_CD->Text        = sIST;
        EdOCRR_LCTN_NM->Text        = pObj->OCRR_LCTN_NM;
        EdLINK_ID->Text             = pObj->LINK_ID;
        EdLinkId->Text              = pObj->LINK_ID;
        FLinkId = pObj->LINK_ID;
        if (pObj->X_CRDN.IsEmpty()) pObj->X_CRDN = "0.0";
        SePosX->Value               = StrToFloat(pObj->X_CRDN);
        if (pObj->Y_CRDN.IsEmpty()) pObj->Y_CRDN = "0.0";
        SePosY->Value               = StrToFloat(pObj->Y_CRDN);

        FSelLink.nSelLink = 0;
        FSelLink.info[FSelLink.nSelLink].sIncidentId = EdINCD_OCRR_ID->Text;
        FSelLink.info[FSelLink.nSelLink].sLinkId = FLinkId;
        FSelLink.info[FSelLink.nSelLink].FPosX   = SePosX->Value;
        FSelLink.info[FSelLink.nSelLink].FPosY   = SePosY->Value;
        FSelLink.nSelLink++;

        EdINCD_EXPL->Text           = pObj->INCD_EXPL;
        CbCMTR_GRAD_CD->Text        = sLTCU;
        EdIFMR_NM->Text             = pObj->IFMR_NM;

        CbINCD_CNFM_MTHD_CD->Text	= sICM;
        CbINCD_SERN_CD->Text		= sSRLU;
        CbINCD_TYPE_CLSF_CD->Text	= sIDTU;
        CbINCD_TYPE_CLSF_CDClick((TObject *)CbINCD_TYPE_CLSF_CD);
        CbINCD_TYPE_CD->Text		= sACTU;

        EdINCD_TITL->Text           = pObj->INCD_TITL;

        DtINCD_STRT_DT->Date        = ITSUtil_StrToDateTime(pObj->INCD_STRT_DT);
        DtINCD_END_PRAR_DT->Date    = ITSUtil_StrToDateTime(pObj->INCD_END_PRAR_DT);

        String sTemp;
        sTemp = pObj->INCD_OCRR_LANE;   //돌발상황 발생 차로
        if (sTemp.IsEmpty())
        {
            sTemp = "000000";
        }
        else
        if (sTemp.Length() != 6)
        {
            sTemp = "000000";
        }

        int A1, A2, A3, A4, A5, A6;
        A1 = sTemp.SubString(1, 1).ToIntDef(0);
        A2 = sTemp.SubString(2, 1).ToIntDef(0);
        A3 = sTemp.SubString(3, 1).ToIntDef(0);
        A4 = sTemp.SubString(4, 1).ToIntDef(0);
        A5 = sTemp.SubString(5, 1).ToIntDef(0);
        A6 = sTemp.SubString(6, 1).ToIntDef(0);

        ChkINCD_OCRR_LANE_Extra->Checked = sTemp.SubString(1, 1).ToIntDef(0);
        ChkINCD_OCRR_LANE_1->Checked     = sTemp.SubString(2, 1).ToIntDef(0);
        ChkINCD_OCRR_LANE_2->Checked     = sTemp.SubString(3, 1).ToIntDef(0);
        ChkINCD_OCRR_LANE_3->Checked     = sTemp.SubString(4, 1).ToIntDef(0);
        ChkINCD_OCRR_LANE_4->Checked     = sTemp.SubString(5, 1).ToIntDef(0);
        ChkINCD_OCRR_LANE_5->Checked     = sTemp.SubString(6, 1).ToIntDef(0);

        sTemp = pObj->INCD_CLSR_LANE;   //돌발상황 차단 차로
        ChkINCD_CLSR_LANE_Extra->Checked = sTemp.SubString(1, 1).ToIntDef(0);
        ChkINCD_CLSR_LANE_1->Checked     = sTemp.SubString(2, 1).ToIntDef(0);
        ChkINCD_CLSR_LANE_2->Checked     = sTemp.SubString(3, 1).ToIntDef(0);
        ChkINCD_CLSR_LANE_3->Checked     = sTemp.SubString(4, 1).ToIntDef(0);
        ChkINCD_CLSR_LANE_4->Checked     = sTemp.SubString(5, 1).ToIntDef(0);
        ChkINCD_CLSR_LANE_5->Checked     = sTemp.SubString(6, 1).ToIntDef(0);

        SeDELY_LNGT->Value          = pObj->DELY_LNGT.ToIntDef(0);
        SeINCD_LNGT->Value          = pObj->INCD_LNGT.ToIntDef(0);
        SeSMLT_VHCL_UNUM->Value     = pObj->SMLT_VHCL_UNUM.ToIntDef(0);
        SeMDLT_VHCL_UNUM->Value     = pObj->MDLT_VHCL_UNUM.ToIntDef(0);
        SeINJR_PNUM->Value          = pObj->INJR_PNUM.ToIntDef(0);
        SeFTLT_PNUM->Value          = pObj->FTLT_PNUM.ToIntDef(0);
        CbWTHR_CD->Text             = sDFW;
        CbRESP_LVL_CD->Text         = sRSL;

        //공단에서 넘어온 돌발은 공단연계가 표출안되게
        if (pObj->INCD_ORGN_CD == "IST5")
        {
            ChkUTIS_CNCT_YN->Checked    = false;
            ChkUTIS_CNCT_YN->Enabled    = false;
        }
        else
        {
            ChkUTIS_CNCT_YN->Enabled    = true;
            ChkUTIS_CNCT_YN->Checked    = pObj->UTIS_CNCT_YN == "Y" ? true : false;
        }

        ChkTRUB_VHCL_YN->Checked    = pObj->TRUB_VHCL_YN == "Y" ? true : false;
        ChkFALT_YN->Checked         = pObj->FALT_YN      == "Y" ? true : false;
        ChkFRWT_YN->Checked         = pObj->FRWT_YN      == "Y" ? true : false;
        CbTRVL_LMNT_TYPE_CD->Text   = sPRTU;

        ChkVMS_DSPL_YN->Checked     = pObj->VMS_DSPL_YN  == "Y" ? true : false;
        EdSTRT_LCTN_NM->Text            = "";
        EdEND_LCTN_NM->Text             = "";
        CbVMS_INCD_TYPE_CD->Text        = "";
        CbVMS_INCD_DETL_TYPE_CD->Text   = "";
        CbVMS_INCD_RSTR_TYPE_CD->Text   = "";

        TItsVmsIncident *pVmsObj = ItsIncidentManager->FVmsLists.Find(pObj->INCD_OCRR_ID);
        if (pVmsObj)
        {
            String sVIT;
            String sIDT;
            String sVRT;

            if (FCodeVIT)
            {
                pSubCode = FCodeVIT->FSubLists.Find(pVmsObj->VMS_INCD_TYPE_CD);
                if (pSubCode)
                {
                    sVIT = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
                    if (pSubCode->CMMN_CD == "VIT1")
                    {
                        if (FCodeIDT)
                        {
                            pSubCode = FCodeIDT->FSubLists.Find(pVmsObj->VMS_INCD_DETL_TYPE_CD);
                            if (pSubCode)
                            {
                                sIDT = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
                            }
                        }
                    }
                    else if (pSubCode->CMMN_CD == "VIT2")
                    {
                        if (FCodeEDT)
                        {
                            pSubCode = FCodeEDT->FSubLists.Find(pVmsObj->VMS_INCD_DETL_TYPE_CD);
                            if (pSubCode)
                            {
                                sIDT = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
                            }
                        }
                    }
                }
            }
            if (FCodeVRT)
            {
                pSubCode = FCodeVRT->FSubLists.Find(pVmsObj->VMS_INCD_RSTR_TYPE_CD);
                if (pSubCode)
                {
                    sVRT = " [" + pSubCode->CMMN_CD + "] " + pSubCode->CMMN_CD_KOR_NM;
                }
            }
            EdSTRT_LCTN_NM->Text          = pVmsObj->STRT_LCTN_NM;
            EdEND_LCTN_NM->Text           = pVmsObj->END_LCTN_NM;
            CbVMS_INCD_TYPE_CD->Text      = sVIT;//pVmsObj->VMS_INCD_TYPE_CD
            CbVMS_INCD_DETL_TYPE_CD->Text = sIDT;//pVmsObj->VMS_INCD_DETL_TYPE_CD
            CbVMS_INCD_RSTR_TYPE_CD->Text = sVRT;
        }

        FOcrrType = 0;

        if (FLinkId != "")
        {
            //BtnVmsTarget->Enabled = true;
        }
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    DisplayIncidentInfo();
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::BtnSelectClick(TObject *Sender)
{
    PopupSelLink->Popup(BtnSelect->ClientOrigin.x, BtnSelect->ClientOrigin.y + BtnSelect->Height);
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::BtnInfoCancelClick(TObject *Sender)
{
	InitScreen();
    FOcrrType = 0;
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::BtnMissInfoClick(TObject *Sender)
{
	if (EdINCD_OCRR_ID->Text.IsEmpty())
	{
        Application->MessageBox(L"돌발 오보 판정\r\n돌발 구간을 먼저 선택하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
	}

	if (FOcrrType == 1)
	{
        Application->MessageBox(L"돌발 오보 판정\r\n돌발 예상구간 정보는 오보로 판정할 수 없습니다.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
	}

    if (Application->MessageBox(L"돌발 오보 판정\r\n현재 돌발 정보를 오보로 판정 하시겠습니까?",
                                FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;

    TItsIncident *pObj = ItsIncidentManager->FLists.Find(EdINCD_OCRR_ID->Text);
    if (!pObj) return;

    if (UpdateMissIncident(pObj->INCD_OCRR_ID))
    {
        pObj->INCD_PRGR_STEP_CD = "ISS4"; // 오보판정

        UpdateList();
        InitScreen();
        Application->ProcessMessages();
        POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_02, 0);
    }
}
//---------------------------------------------------------------------------

bool __fastcall TFRAMEIncidentProcess::UpdateMissIncident(String AINCD_OCRR_ID)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();

            sQry = "UPDATE TB_INCD_OCRR                \r\n"
                   "   SET INCD_PRGR_STEP_CD = 'ISS4'  \r\n"
				   " WHERE INCD_OCRR_ID = :p01         \r\n";

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", AINCD_OCRR_ID);

            ITSDb_SQLExec(pADO);


            ITSDb_GetConnection()->CommitTrans();

            // 공단연계 정보도 삭제해 버리자.
            ItsIncidentManager->DeleteIncidentLoc(AINCD_OCRR_ID);

            Application->MessageBox(FrmLang->lblDbSave->Caption.c_str(),//L"돌발정보를 오보 판정 돌발 정보로 저장 하였습니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

void __fastcall TFRAMEIncidentProcess::BtnSaveClick(TObject *Sender)
{
    //입력
    if (EdINCD_OCRR_ID->Text.Trim().IsEmpty())
    {
        Application->MessageBox(L"돌발정보입력\r\n목록에서 돌발정보를 선택하신 후에 작업을 진행하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }

	if (CbINCD_ORGN_CD->Text.IsEmpty())
	{
        Application->MessageBox(L"★[돌발구분] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (CbINCD_ORGN_CD->CanFocus()) CbINCD_ORGN_CD->SetFocus();
		return;
	}
	if (CbINCD_CNFM_MTHD_CD->Text.IsEmpty())
	{
        Application->MessageBox(L"★[확인방법] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (CbINCD_CNFM_MTHD_CD->CanFocus()) CbINCD_CNFM_MTHD_CD->SetFocus();
		return;
	}
	if (CbINCD_TYPE_CLSF_CD->Text.IsEmpty())
	{
        Application->MessageBox(L"★[돌발유형] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (CbINCD_TYPE_CLSF_CD->CanFocus()) CbINCD_TYPE_CLSF_CD->SetFocus();
		return;
	}
	if (CbINCD_SERN_CD->Text.IsEmpty())
	{
        Application->MessageBox(L"★[심각도] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (CbINCD_SERN_CD->CanFocus()) CbINCD_SERN_CD->SetFocus();
		return;
	}
	if (CbINCD_TYPE_CD->Text.IsEmpty())
	{
        Application->MessageBox(L"★[돌발세부유형] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (CbINCD_TYPE_CD->CanFocus()) CbINCD_TYPE_CD->SetFocus();
		return;
	}
	if (DtINCD_STRT_DT->EditValue.IsEmpty())
	{
        Application->MessageBox(L"★[돌발시작시각] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (DtINCD_STRT_DT->CanFocus()) DtINCD_STRT_DT->SetFocus();
		return;
	}
	if (DtINCD_END_PRAR_DT->EditValue.IsEmpty())
	{
        Application->MessageBox(L"★[종료예정시각] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (DtINCD_END_PRAR_DT->CanFocus()) DtINCD_END_PRAR_DT->SetFocus();
		return;
	}
	if (EdLinkId->Text.Trim().IsEmpty())
	{
        Application->MessageBox(L"★[발생구간(링크)] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (EdLinkId->CanFocus()) EdLinkId->SetFocus();
		return;
	}
	if (SePosX->Value == 0 ||
        SePosY->Value == 0)
	{
        Application->MessageBox(L"★발생구간(링크) 좌표값은 0이 될수 없습니다.] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (SePosX->CanFocus()) SePosX->SetFocus();
		return;
	}
	if (EdINCD_EXPL->Text.Trim().IsEmpty())
	{
        Application->MessageBox(L"★[돌발상황설명] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (EdINCD_EXPL->CanFocus()) EdINCD_EXPL->SetFocus();
		return;
	}
	if (EdINCD_TITL->Text.Trim().IsEmpty())
	{
        Application->MessageBox(L"★[돌발제목] 항목은 필수 입력 항목입니다.\r\n입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (EdINCD_TITL->CanFocus()) EdINCD_TITL->SetFocus();
		return;
	}

    String sStartTm = DtINCD_STRT_DT->Date.FormatString("YYYYMMDDHHNNSS");
    String sEndTm   = DtINCD_END_PRAR_DT->Date.FormatString("YYYYMMDDHHNNSS");
    if (sStartTm >= sEndTm)
    {
        Application->MessageBox(L"돌발종료예정시각이 돌발시작시각과 같거나 큽니다.\r\n확인 후 진행해 주세요",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        if (DtINCD_STRT_DT->CanFocus()) DtINCD_STRT_DT->SetFocus();
        return;
    }

    if (Application->MessageBox(L"돌발정보입력\r\n현재 입력 정보를 저장 하시겠습니까?",
                                FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;

    String sIncidentId = EdINCD_OCRR_ID->Text;
    TItsIncident *pObj = ItsIncidentManager->FLists.Find(sIncidentId);
    if (!pObj && FOcrrType == 1)
    {
        //돌발감지 정보를 돌발 정보로 등록한다.
        if (InsertAutoIncident(sIncidentId, EdRegDt->Text))
        {
            ItsIncidentManager->LoadFromDb();
            pObj = ItsIncidentManager->FLists.Find(sIncidentId);
            if (!pObj) return;  //신규로 정보가 저장되지 않은 것이다.
        }
    }

	String sINCD_OCRR_LANE;
	String sINCD_CLSR_LANE;

	sINCD_OCRR_LANE.sprintf(L"%d%d%d%d%d%d",
                            ChkINCD_OCRR_LANE_Extra->Checked,
                            ChkINCD_OCRR_LANE_1->Checked,
                            ChkINCD_OCRR_LANE_2->Checked,
                            ChkINCD_OCRR_LANE_3->Checked,
                            ChkINCD_OCRR_LANE_4->Checked,
                            ChkINCD_OCRR_LANE_5->Checked);
	sINCD_CLSR_LANE.sprintf(L"%d%d%d%d%d%d",
                            ChkINCD_CLSR_LANE_Extra->Checked,
                            ChkINCD_CLSR_LANE_1->Checked,
                            ChkINCD_CLSR_LANE_2->Checked,
                            ChkINCD_CLSR_LANE_3->Checked,
                            ChkINCD_CLSR_LANE_4->Checked,
                            ChkINCD_CLSR_LANE_5->Checked);

    pObj->INCD_ORGN_CD			= ITSUtil_GetCode(CbINCD_ORGN_CD->Text);
    pObj->OCRR_LCTN_NM			= EdOCRR_LCTN_NM->Text.Trim();
    pObj->X_CRDN				= VarToStr(SePosX->Value);
    pObj->Y_CRDN				= VarToStr(SePosY->Value);
    pObj->INCD_EXPL				= EdINCD_EXPL->Text.Trim();
    pObj->CMTR_GRAD_CD			= ITSUtil_GetCode(CbCMTR_GRAD_CD->Text);
    pObj->IFMR_NM				= EdIFMR_NM->Text.Trim();
    pObj->INCD_CNFM_MTHD_CD		= ITSUtil_GetCode(CbINCD_CNFM_MTHD_CD->Text);
    pObj->INCD_STRT_DT			= DtINCD_STRT_DT->Date.FormatString("YYYYMMDDHHNNSS");
    pObj->INCD_END_PRAR_DT		= DtINCD_END_PRAR_DT->Date.FormatString("YYYYMMDDHHNNSS");
    pObj->INCD_TYPE_CLSF_CD		= ITSUtil_GetCode(CbINCD_TYPE_CLSF_CD->Text);
    pObj->INCD_TYPE_CD			= ITSUtil_GetCode(CbINCD_TYPE_CD->Text);
    pObj->INCD_TITL				= EdINCD_TITL->Text.Trim();
    pObj->INCD_SERN_CD			= ITSUtil_GetCode(CbINCD_SERN_CD->Text);
    pObj->DELY_LNGT				= SeDELY_LNGT->Value;
    pObj->INCD_LNGT				= SeINCD_LNGT->Value;
    pObj->INCD_OCRR_LANE		= sINCD_OCRR_LANE;
    pObj->INCD_CLSR_LANE		= sINCD_CLSR_LANE;
    pObj->TRVL_LMNT_TYPE_CD		= ITSUtil_GetCode(CbTRVL_LMNT_TYPE_CD->Text);
    pObj->TRUB_VHCL_YN			= ChkTRUB_VHCL_YN->Checked ? "Y" : "N";
    pObj->FALT_YN				= ChkFALT_YN->Checked      ? "Y" : "N";
    pObj->FRWT_YN				= ChkFRWT_YN->Checked      ? "Y" : "N";
    pObj->UTIS_CNCT_YN			= ChkUTIS_CNCT_YN->Checked ? "Y" : "N";
    pObj->SMLT_VHCL_UNUM		= SeSMLT_VHCL_UNUM->Value;
    pObj->MDLT_VHCL_UNUM		= SeMDLT_VHCL_UNUM->Value;
    pObj->INJR_PNUM				= SeINJR_PNUM->Value;
    pObj->FTLT_PNUM				= SeFTLT_PNUM->Value;
    pObj->WTHR_CD				= ITSUtil_GetCode(CbWTHR_CD->Text);
    pObj->RESP_LVL_CD			= ITSUtil_GetCode(CbRESP_LVL_CD->Text);
    pObj->VMS_DSPL_YN			= ChkVMS_DSPL_YN->Checked  ? "Y" : "N";
    pObj->LINK_ID				= EdLinkId->Text.Trim();
    pObj->INCD_PRGR_STEP_CD		= "ISS2";	// 현재는 진행단계이다.

	if (!ItsIncidentManager->UpdateIncidentInfo(pObj))
    {
        return;
    }

	if (FOcrrType == 1)
	{
		UpdateAutoIncident(pObj->LINK_ID, pObj->RGST_DT);
	}

	ItsIncidentManager->MergeVmsIncidentInfo(pObj->INCD_OCRR_ID,                               // '돌발상황 발생 ID
                                             EdSTRT_LCTN_NM->Text,                             // '시작 위치 명
                                             EdEND_LCTN_NM->Text,                              // '종료 위치 명
                                             pObj->OCRR_LCTN_NM,                               // '발생 위치 명
                                             pObj->CMTR_GRAD_CD,                               // '소통 등급 코드
                                             sINCD_CLSR_LANE,                                  // '돌발상황 차단 차로
                                             pObj->VMS_DSPL_YN,                                // 'VMS 표출 여부
                                             pObj->INCD_PRGR_STEP_CD,                          // '돌발상황 진행 단계 코드
                                             pObj->INCD_STRT_DT,                               // '돌발상황 시작 일시
                                             pObj->INCD_END_PRAR_DT,                           // '돌발상황 종료 예정 일시
                                             pObj->LINK_ID,                                    // '링크ID
                                             ITSUtil_GetCode(CbVMS_INCD_TYPE_CD->Text),        // 'VMS 돌발유형코드
                                             ITSUtil_GetCode(CbVMS_INCD_DETL_TYPE_CD->Text),   // 'VMS 돌발세부유형코드
                                             ITSUtil_GetCode(CbVMS_INCD_RSTR_TYPE_CD->Text)
                                             );

    if (FSelLink.nSelLink > 1)
    {
        bool bResult;
        for (int ii = 1; ii < FSelLink.nSelLink; ii++)
        {
            String sIncidentId = "";
            if (!ItsIncidentManager->GetNextIncidentId(CenterId, sIncidentId))
            {
                Application->MessageBox(L"신규 돌발 ID를 조회하지 못하였습니다.\r\n데이터베이스 관리자에게 확인 후에 작업하세요.",
                                        FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                break;
            }
            bResult = InsertToDb(sIncidentId,
                                 pObj->INCD_ORGN_CD,
                                 pObj->OCRR_LCTN_NM,
                                 pObj->INCD_EXPL,
                                 pObj->CMTR_GRAD_CD,
                                 pObj->IFMR_NM,
                                 pObj->INCD_CNFM_MTHD_CD,
                                 pObj->INCD_SERN_CD,
                                 pObj->INCD_TYPE_CLSF_CD,
                                 pObj->INCD_TYPE_CD,
                                 pObj->INCD_CNFM_DT,
                                 pObj->INCD_STRT_DT,
                                 pObj->INCD_END_PRAR_DT,
                                 pObj->LINK_ID,
                                 pObj->INCD_TITL);
            pObj->INCD_OCRR_ID = sIncidentId;
            pObj->LINK_ID	   = FSelLink.info[ii].sLinkId;
            pObj->X_CRDN	   = VarToStr(FSelLink.info[ii].FPosX);
            pObj->Y_CRDN       = VarToStr(FSelLink.info[ii].FPosY);
            ItsIncidentManager->UpdateIncidentInfo(pObj);
        }
    }

    Application->MessageBox(FrmLang->lblDbSave->Caption.c_str(),//L"입력하신 돌발정보를 저장 하였습니다.",
                            FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);

	ItsIncidentManager->LoadFromDb();
	ItsIncidentManager->LoadFromVmsIncident();

	if (FOcrrType == 1)
	{
		ItsIncidentManager->LoadFromAutoIncident();
	}

	UpdateList();

	InitScreen();

	FOcrrType = 0;

    Application->ProcessMessages();
    POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_02, 0);

    //if (cxPageControl1->ActivePage == cxTabSheet1)
        CMM_SetGridFocusRow(CxList, TvList, sIncidentId, Column01->Index);
        DisplayIncidentInfo();
    //else
    //    CMM_SetGridRow(CxList, TvList, sIncidentId, Column01->Index);
}
//---------------------------------------------------------------------------

bool __fastcall TFRAMEIncidentProcess::InsertToDb(String AINCD_OCRR_ID,      //돌발ID
                                                 String AINCD_ORGN_CD,      //돌발상황 원본 코드 : IST
                                                 String AOCRR_LCTN_NM,      //발생 위치 명
                                                 String AINCD_EXPL,         //돌발상황 설명
                                                 String ACMTR_GRAD_CD,      //소통 등급 코드 : LTCU
                                                 String AIFMR_NM,           //제보자 명
                                                 String AINCD_CNFM_MTHD_CD, //돌발상황 확인 방법 코드 : ICM
                                                 String AINCD_SERN_CD,      //돌발상황 심각도 코드 : SRLU
                                                 String AINCD_TYPE_CLSF_CD, //돌발상황 유형 분류 코드 : IDTU
                                                 String AINCD_TYPE_CD,      //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
                                                 String AINCD_CNFM_DT,      //돌발상황 확인 일시
                                                 String AINCD_STRT_DT,      //돌발상황 시작 일시
                                                 String AINCD_END_PRAR_DT,  //돌발상황 종료 예정 일시
                                                 String ALINK_ID,
                                                 String AINCD_TITL)         //돌발제목
{
    String     sQry;
    TADOQuery *pADO = NULL;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();

            sQry = "INSERT INTO TB_INCD_OCRR(INCD_OCRR_ID, RGST_DT, INCD_ORGN_CD, OCRR_LCTN_NM,                     \r\n"
                   "                         INCD_EXPL, CMTR_GRAD_CD, IFMR_NM, INCD_CNFM_MTHD_CD,                   \r\n"
                   "                         INCD_CNFM_DT, INCD_STRT_DT, INCD_END_PRAR_DT, INCD_TYPE_CLSF_CD,       \r\n"
                   "                         INCD_TYPE_CD, INCD_SERN_CD, INCD_PRGR_STEP_CD, LINK_ID, INCD_TITL )    \r\n"
                   "                  VALUES(:p01, :p02, :p03, :p04,                                                \r\n"
                   "                         :p05, :p06, :p07, :p08,                                                \r\n"
                   "                         :p09, :p10, :p11, :p12,                                                \r\n"
                   "                         :p13, :p14, 'ISS2', :p15, :p16 )                                       \r\n";

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", AINCD_OCRR_ID);
            ITSDb_SQLBind(pADO, "p02", Now().FormatString("YYYYMMDDHHNNSS"));
            ITSDb_SQLBind(pADO, "p03", AINCD_ORGN_CD);
            ITSDb_SQLBind(pADO, "p04", AOCRR_LCTN_NM);
            ITSDb_SQLBind(pADO, "p05", AINCD_EXPL);
            ITSDb_SQLBind(pADO, "p06", ACMTR_GRAD_CD);
            ITSDb_SQLBind(pADO, "p07", AIFMR_NM);
            ITSDb_SQLBind(pADO, "p08", AINCD_CNFM_MTHD_CD);
            ITSDb_SQLBind(pADO, "p09", AINCD_CNFM_DT);
            ITSDb_SQLBind(pADO, "p10", AINCD_STRT_DT);
            ITSDb_SQLBind(pADO, "p11", AINCD_END_PRAR_DT);
            ITSDb_SQLBind(pADO, "p12", AINCD_TYPE_CLSF_CD);
            ITSDb_SQLBind(pADO, "p13", AINCD_TYPE_CD);
            ITSDb_SQLBind(pADO, "p14", AINCD_SERN_CD);
            ITSDb_SQLBind(pADO, "p15", ALINK_ID);
            ITSDb_SQLBind(pADO, "p16", AINCD_TITL);

            ITSDb_SQLExec(pADO);

            ITSDb_GetConnection()->CommitTrans();

            //Application->MessageBox(FrmLang->lblDbSave->Caption.c_str(),//L"돌발 확정 정보를 저장 하였습니다.",
            //                          FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool __fastcall TFRAMEIncidentProcess::UpdateAutoIncident(String AINCD_OCRR_ID, String ARGST_DT)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();

            sQry = "UPDATE TB_INCD_ESTM_SECT \r\n"
				   "   SET REAL_YN = 'Y'     \r\n"
                   " WHERE LINK_ID = :p01    \r\n"
                   "   AND DETC_DT = :p02    \r\n";

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", AINCD_OCRR_ID);
            ITSDb_SQLBind(pADO, "p02", ARGST_DT);

            ITSDb_SQLExec(pADO);

            ITSDb_GetConnection()->CommitTrans();

            //Application->MessageBox(FrmLang->lblDbSave->Caption.c_str(),//L"돌발정보를 오보 판정 돌발 정보로 저장 하였습니다.",
            //                          FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

bool __fastcall TFRAMEIncidentProcess::InsertAutoIncident(String AINCD_OCRR_ID, String ARGST_DT)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();

            sQry = "INSERT INTO TB_INCD_OCRR(INCD_OCRR_ID, RGST_DT, INCD_PRGR_STEP_CD) \r\n"
				   "                  VALUES(:p01, :p02, 'ISS1' )                      \r\n";

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", AINCD_OCRR_ID);
            ITSDb_SQLBind(pADO, "p02", ARGST_DT);

            ITSDb_SQLExec(pADO);

            ITSDb_GetConnection()->CommitTrans();

            //Application->MessageBox(FrmLang->lblDbSave->Caption.c_str(),//L"돌발정보를 오보 판정 돌발 정보로 저장 하였습니다.",
            //                          FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

void __fastcall TFRAMEIncidentProcess::MnuListAddClick(TObject *Sender)
{
    if (EdINCD_OCRR_ID->Text.Trim().IsEmpty())
    {
        Application->MessageBox(L"돌발정보입력\r\n목록에서 돌발정보를 선택하신 후에 작업을 진행하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }

    TITSSEL1M *pSelForm = NULL;
    try
    {
        try {
            pSelForm = new TITSSEL1M(this);
            pSelForm->m_bSelected = false;
            pSelForm->MultiSelect = false;
            pSelForm->ShowModal();
            if (pSelForm->m_bSelected)
            {
                String sLinkId = pSelForm->m_sSelLinkId;

                TItsLink *pLink = ItsLinkManager->FLists.Find(sLinkId);
                if (!pLink)
                {
                    Application->MessageBox(L"정보가 없는 구간을 선택하였습니다. 다른 구간을 선택하세요.",
                                            FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                    return;
                }

                EdLinkId->Text = sLinkId;
                EdLINK_ID->Text = sLinkId;
                TItsNode *pNode;
                String sFNode = "";
                pNode = ItsNodeManager->FLists.Find(pLink->F_NODE_ID);
                if (pNode)
                {
                    sFNode = sFNode + pNode->NODE_NAME;

                    SePosX->Value = pNode->X_CRDN;
                    SePosY->Value = pNode->Y_CRDN;
                }

                String sTNode = "";
                pNode = ItsNodeManager->FLists.Find(pLink->T_NODE_ID);
                if (pNode) sTNode = sTNode + pNode->NODE_NAME;

                EdLINK_ID->Text = "[" + sLinkId + "] " + sFNode + "→" + sTNode;
            }
        } catch(...) { }
    }
    __finally
    {
        if (pSelForm) delete pSelForm;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::MnuGisAddClick(TObject *Sender)
{
    if (EdINCD_OCRR_ID->Text.Trim().IsEmpty())
    {
        Application->MessageBox(L"돌발정보입력\r\n목록에서 돌발정보를 선택하신 후에 작업을 진행하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }

    TITSSELAM *pSelForm = NULL;
    try
    {
        try {
            pSelForm = new TITSSELAM(this);
            pSelForm->MultiSelect = true;
            pSelForm->LinkLevel = 1;
            pSelForm->FRefreshId = EdLinkId->Text;
            pSelForm->FSelPosX   = VarToStr(SePosX->Value);
            pSelForm->FSelPosY   = VarToStr(SePosY->Value);

            String sOrgLinkId = EdLinkId->Text;

            int nRow;
            TcxDataController *pGDC = pSelForm->TvList->DataController;
            for (int ii = 0; ii < FSelLink.nSelLink; ii++)
            {
                if (FSelLink.info[ii].sLinkId == "") continue;
                nRow = pGDC->AppendRecord();
                pGDC->Values[nRow][pSelForm->Column01->Index] = FSelLink.info[ii].sLinkId;
                pGDC->Values[nRow][pSelForm->Column02->Index] = FSelLink.info[ii].FPosX;
                pGDC->Values[nRow][pSelForm->Column03->Index] = FSelLink.info[ii].FPosY;
            }

            pSelForm->ShowModal();
            Application->ProcessMessages();
            if (pSelForm->Selected)
            {
#if 0
                String sLinkId = pSelForm->TvList->DataController->Values[0][pSelForm->Column01->Index];

                TItsLink *pLink = ItsLinkManager->FLists.Find(sLinkId);
                if (!pLink)
                {
                    Application->MessageBox(L"정보가 없는 구간을 선택하였습니다. 다른 구간을 선택하세요.",
                                            FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                    return;
                }

                SePosX->Value = pSelForm->FPosX;
                SePosY->Value = pSelForm->FPosY;

                EdLinkId->Text = sLinkId;
                EdLINK_ID->Text = sLinkId;
                TItsNode *pNode;
                String sFNode = "";
                pNode = ItsNodeManager->FLists.Find(pLink->F_NODE_ID);
                if (pNode)
                {
                    sFNode = sFNode + pNode->NODE_NAME;
                }

                String sTNode = "";
                pNode = ItsNodeManager->FLists.Find(pLink->T_NODE_ID);
                if (pNode) sTNode = sTNode + pNode->NODE_NAME;

                EdLINK_ID->Text = "[" + sLinkId + "] " + sFNode + "→" + sTNode;
#else
                String sFLinkId = "";
                double dX = 0;
                double dY = 0;

                try
                {
                    int nRow;
                    TcxDataController *pGDC = pSelForm->TvList->DataController;
                    pSelForm->TvList->BeginUpdate();
                    try
                    {
                        int ii;
                        for (ii = 0; ii < pGDC->RecordCount; ii++)
                        {
                            String sTmpLinkId = pGDC->Values[ii][pSelForm->Column01->Index];
                            if (sOrgLinkId == sTmpLinkId)
                            {
                                sFLinkId = sTmpLinkId;
                                String sX = pGDC->Values[ii][pSelForm->Column02->Index];
                                String sY = pGDC->Values[ii][pSelForm->Column03->Index];
                                dX = sX.ToDouble();
                                dY = sY.ToDouble();
                                break;
                            }
                        }
                        FSelLink.nSelLink = 0;
                        //무조건 첫번째는 업데이트를 해야 하기 때문에 ID를 추가하자
                        //나머지는 ID ==""로 처리해서 Insert 하도록 하자
                        FSelLink.info[FSelLink.nSelLink].sIncidentId = EdINCD_OCRR_ID->Text;
                        if (sFLinkId != "")
                        {
                            FSelLink.info[FSelLink.nSelLink].sLinkId = sFLinkId;
                            FSelLink.info[FSelLink.nSelLink].FPosX   = dX;
                            FSelLink.info[FSelLink.nSelLink].FPosY   = dY;
                            FSelLink.nSelLink++;
                        }

                        {
                            for (ii = 0; ii < pGDC->RecordCount; ii++)
                            {
                                String sTmpLinkId = pGDC->Values[ii][pSelForm->Column01->Index];
                                if (sFLinkId != "" && sFLinkId == sTmpLinkId)
                                {
                                    //이미 위에서 첫번째 인덱스에 저장했다
                                    continue;
                                }
                                String sX = pGDC->Values[ii][pSelForm->Column02->Index];
                                String sY = pGDC->Values[ii][pSelForm->Column03->Index];
                                dX = sX.ToDouble();
                                dY = sY.ToDouble();

                                FSelLink.info[FSelLink.nSelLink].sLinkId = sTmpLinkId;
                                FSelLink.info[FSelLink.nSelLink].FPosX   = dX;
                                FSelLink.info[FSelLink.nSelLink].FPosY   = dY;
                                FSelLink.nSelLink++;
                            }
                        }
                        TItsLink *pLink = ItsLinkManager->FLists.Find(FSelLink.info[0].sLinkId);
                        if (!pLink)
                        {
                            Application->MessageBox(L"정보가 없는 구간을 선택하였습니다. 다른 구간을 선택하세요.",
                                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                            return;
                        }
                        SePosX->Value = FSelLink.info[0].FPosX;
                        SePosY->Value = FSelLink.info[0].FPosY;

                        EdLinkId->Text = FSelLink.info[0].sLinkId;
                        EdLINK_ID->Text = FSelLink.info[0].sLinkId;
                        TItsNode *pNode;
                        String sFNode = "";
                        pNode = ItsNodeManager->FLists.Find(pLink->LINK_ID);
                        if (pNode)
                        {
                            sFNode = sFNode + pNode->NODE_NAME;
                        }

                        String sTNode = "";
                        pNode = ItsNodeManager->FLists.Find(pLink->T_NODE_ID);
                        if (pNode) sTNode = sTNode + pNode->NODE_NAME;

                        EdLINK_ID->Text = "[" + FSelLink.info[0].sLinkId + "] " + sFNode + "→" + sTNode;
                    }
                    catch(...)
                    {
                    }
                }
                __finally
                {
                    pSelForm->TvList->EndUpdate();
                }
#endif
            }
        } catch(...) { }
    }
    __finally
    {
        if (pSelForm) delete pSelForm;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::BtnMoveGisClick(TObject *Sender)
{
#if 0
    if (EdLinkId->Text.IsEmpty()) return;
    g_SelLink.pForm = NULL;
    g_SelLink.Level = 1;
    g_SelLink.Id    = EdLinkId->Text;
    POST_MSG(Application->MainForm->Handle, WM_PLUGINFORM, WP_MSG_15, LP_MSG_15);
#else
    double sDx = SePosX->Value;
    double sDy = SePosY->Value;
    if (sDx != 0 && sDy != 0)
    {
        if (ITS0000M) ITS0000M->SelectObjectByPos(sDx, sDy, true);
    }
    else
    {
        if (EdLinkId->Text.IsEmpty()) return;
        if (ITS0000M) ITS0000M->SelectLinkById(1, EdLinkId->Text, true);
#if 0
        g_SelLink.pForm = NULL;
        g_SelLink.Level = 1;
        g_SelLink.Id    = EdLinkId->Text;
        POST_MSG(Application->MainForm->Handle, WM_PLUGINFORM, WP_MSG_15, LP_MSG_15);
#endif
    }
#endif
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::BtnVmsTargetClick(TObject *Sender)
{
    if (!ChkVMS_DSPL_YN->Checked) return;
    if (EdLinkId->Text.IsEmpty()) return;
    String sLinkId = EdLinkId->Text.Trim();
    //if (FLinkId == "") return;
    //String sLinkId = FLinkId;
    try
    {
        if (FrmIncidVmsInfo == NULL)
        {
            FrmIncidVmsInfo = new TFrmIncidVmsInfo(Application);
        }
        FrmIncidVmsInfo->Show();
        FrmIncidVmsInfo->ShowIncidVmsInfo(sLinkId);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

