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

#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"
#pragma hdrstop

#include "FRAME_IncidentProcessF.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinsCore"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxSplitter"
#pragma link "cxClasses"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxFilter"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxLabel"
#pragma link "cxStyles"
#pragma link "dxSkinscxPCPainter"
#pragma link "cxButtons"
#pragma link "cxTextEdit"
#pragma link "cxDropDownEdit"
#pragma link "cxMaskEdit"
#pragma link "cxCalc"
#pragma link "cxCalendar"
#pragma link "cxCheckBox"
#pragma link "dxGDIPlusClasses"
#pragma link "cxSpinEdit"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma resource "*.dfm"
TFRAMEIncidentProcess *FRAMEIncidentProcess;
//---------------------------------------------------------------------------
__fastcall TFRAMEIncidentProcess::TFRAMEIncidentProcess(TComponent* Owner)
    : TFrame(Owner)
{
    ITSSkin_Load((TForm*)this);

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

    FOcrrType   = 0;

    cxPageControl1->Properties->ActivePage = cxTabSheet1;

    m_pGDC = TvList->DataController;
    TvList->OptionsView->NoDataToDisplayInfoText = "<등록된 돌발정보가 없습니다>";
    TvList2->OptionsView->NoDataToDisplayInfoText = "<자동감지 돌발정보가 없습니다>";

    FCodeIST  = ItsCodeManager->FLists.Find("IST");  //돌발상황 원본 코드 : IST
    FCodeLTCU = ItsCodeManager->FLists.Find("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 중 하나

    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

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

void __fastcall TFRAMEIncidentProcess::InitForm()
{
	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);
		}
	}
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::InitScreen()
{
    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				= NULL;
    DtINCD_END_PRAR_DT->Date			= NULL;
    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				    = "";
    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		= "";
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentProcess::UpdateList()
{
    TItsSubCode *pSubCode;

    CMM_ClearGridTableView(TvList);

    int nRow = 0;
    try
    {
        TvList->BeginUpdate();

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

                nRow = m_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;
                        }
                    }
                }

                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;
                }

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

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

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

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

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

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

void __fastcall TFRAMEIncidentProcess::UpdateAutoList()
{
    ItsIncidentManager->LoadFromVmsIncident();
    ItsIncidentManager->LoadFromAutoIncident();

    CMM_ClearGridTableView(TvList2);
    TcxDataController *pGDC = TvList2->DataController;

    int nRow = 0;
    try
    {
        TvList2->BeginUpdate();

        try
        {
            ItsIncidentManager->FAutoLists.Lock();
            FOR_STL(TItsAutoIncident *, pObj, ItsIncidentManager->FAutoLists)
            {
                if (pObj->REAL_YN == "Y") continue;

                nRow = pGDC->AppendRecord();

                pGDC->Values[nRow][ColumnA01->Index] = pObj->LINK_ID;                           //링크ID
                pGDC->Values[nRow][ColumnA02->Index] = ITSUtil_StrToDateTime(pObj->DETC_DT);    //검지 일시
                pGDC->Values[nRow][ColumnA03->Index] = pObj->CLCT_SPED_AVRG;                    //수집 속도 평균
                pGDC->Values[nRow][ColumnA04->Index] = pObj->ESTM_SPED_AVRG;                    //예상 속도 평균
                pGDC->Values[nRow][ColumnA05->Index] = pObj->REAL_YN;                           //사실 여부
                pGDC->Values[nRow][ColumnA06->Index] = pObj->LINK_ID;                           //링크ID
                pGDC->Values[nRow][ColumnA07->Index] = pObj->ROAD_NAME;                         //도로명
                pGDC->Values[nRow][ColumnA08->Index] = pObj->STNAME;                            //시점명
                pGDC->Values[nRow][ColumnA09->Index] = pObj->EDNAME;                            //종점명

                pGDC->Values[nRow][ColumnA99->Index] = (int)pObj;
            }
        }
        __finally
        {
            ItsIncidentManager->FAutoLists.UnLock();
        }
    }
    __finally
    {
        TvList2->EndUpdate();
        TvList2->DataController->GotoFirst();
        TvList2->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

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

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

    if (cxPageControl1->Properties->ActivePage != cxTabSheet1)
    {
        pGrid = CxList2;
        pView = TvList2;
        sTitle= "자동감지 돌발정보";
    }
    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);
			}
		}
	}
	CbINCD_TYPE_CD->ItemIndex = 0;
}
//---------------------------------------------------------------------------

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

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

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


    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::TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
	int nRow = m_pGDC->FocusedRecordIndex;
	if( nRow <= -1 )
		return;

    TItsSubCode *pSubCode;

    int nMemPtr = m_pGDC->Values[nRow][Column99->Index];
    TItsIncident *pObj = (TItsIncident *)nMemPtr;

    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;
            }
        }
    }

    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;
    }

	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;
    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);
	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;   //돌발상황 발생 차로
	ChkINCD_OCRR_LANE_Extra->Checked    = sTemp.SubString(0, 1).ToIntDef(0);
	ChkINCD_OCRR_LANE_1->Checked        = sTemp.SubString(1, 1).ToIntDef(0);
	ChkINCD_OCRR_LANE_2->Checked        = sTemp.SubString(2, 1).ToIntDef(0);
	ChkINCD_OCRR_LANE_3->Checked        = sTemp.SubString(3, 1).ToIntDef(0);
	ChkINCD_OCRR_LANE_4->Checked        = sTemp.SubString(4, 1).ToIntDef(0);
	ChkINCD_OCRR_LANE_5->Checked        = sTemp.SubString(5, 1).ToIntDef(0);

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

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

		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;
						}
					}
				}
			}
		}

		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
	}

	FOcrrType = 0;
}
//---------------------------------------------------------------------------

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::TvList2CellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift, bool &AHandled)
{
    TcxDataController *pGDC = TvList2->DataController;
	int nRow = pGDC->FocusedRecordIndex;
	if( nRow <= -1 )
		return;

    String sIncidentId = "";
    if (!ItsIncidentManager->GetNextIncidentId(CenterId, sIncidentId)) return;

    int nMemPtr = pGDC->Values[nRow][ColumnA99->Index];
    TItsAutoIncident *pObj = (TItsAutoIncident *)nMemPtr;

    if (pObj)
    {                                   //[1100003] 송정IC램프->송정앞
        EdINCD_OCRR_ID->Text        = sIncidentId;
        EdRGST_DT->Text             = ITSUtil_StrToDateTime(pObj->DETC_DT);
        EdRegDt->Text               = pObj->DETC_DT;
        CbINCD_ORGN_CD->Text        = "";
        EdOCRR_LCTN_NM->Text        = pObj->ROAD_NAME;
        EdLINK_ID->Text             = "[" + pObj->LINK_ID + "] " + pObj->STNAME + "->" + pObj->EDNAME;
        EdLinkId->Text              = 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);
        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() + 1;

        ChkVMS_DSPL_YN->Checked     = false;
        EdSTRT_LCTN_NM->Text        = "";
        EdEND_LCTN_NM->Text         = "";
        CbVMS_INCD_TYPE_CD->Text    = "";
        CbVMS_INCD_DETL_TYPE_CD->Text = "";

        FOcrrType = 1;
    }
}
//---------------------------------------------------------------------------

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();

            Application->MessageBox(L"돌발정보를 오보 판정 돌발 정보로 저장 하였습니다.", FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(exception.ClassName()) + exception.Message);
        }
        catch(...)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage("데이터 작업 중에 알수없는 DB 오류가 발생하였습니다.");
        }
    }
    __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()          ||
        CbINCD_CNFM_MTHD_CD->Text.IsEmpty()     ||
        CbINCD_TYPE_CLSF_CD->Text.IsEmpty()     ||
        CbINCD_SERN_CD->Text.IsEmpty()          ||
        CbINCD_TYPE_CD->Text.IsEmpty()          ||
        DtINCD_STRT_DT->EditValue.IsEmpty()     ||
        DtINCD_END_PRAR_DT->EditValue.IsEmpty() ||
        EdLinkId->Text.Trim().IsEmpty()         ||
        SePosX->Value == 0                      ||
        SePosY->Value == 0                      ||
        EdINCD_EXPL->Text.Trim().IsEmpty()      ||
        EdINCD_OCRR_ID->Text.Trim().IsEmpty()   ||
        EdINCD_TITL->Text.Trim().IsEmpty())
	{
        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;

    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 돌발세부유형코드

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

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

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

	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);
    else
        CMM_SetGridRow(CxList, TvList, sIncidentId, Column01->Index);
}
//---------------------------------------------------------------------------

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(L"돌발정보를 오보 판정 돌발 정보로 저장 하였습니다.", FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(exception.ClassName()) + exception.Message);
        }
        catch(...)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage("데이터 작업 중에 알수없는 DB 오류가 발생하였습니다.");
        }
    }
    __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(L"돌발정보를 오보 판정 돌발 정보로 저장 하였습니다.", FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(exception.ClassName()) + exception.Message);
        }
        catch(...)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage("데이터 작업 중에 알수없는 DB 오류가 발생하였습니다.");
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

void __fastcall TFRAMEIncidentProcess::MnuListAddClick(TObject *Sender)
{
    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_NODEID);
                if (pNode)
                {
                    sFNode = sFNode + pNode->NODE_NAME;

                    SePosX->Value = StrToFloat(pNode->FX_CRDN);
                    SePosY->Value = StrToFloat(pNode->FY_CRDN);
                }

                String sTNode = "";
                pNode = ItsNodeManager->FLists.Find(pLink->T_NODEID);
                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)
{
    TITSSELAM *pSelForm = NULL;
    try
    {
        try {
            pSelForm = new TITSSELAM(this);
            pSelForm->MultiSelect = false;
            pSelForm->LinkLevel = 1;
            pSelForm->ShowModal();
            Application->ProcessMessages();
            if (pSelForm->Selected)
            {
                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_NODEID);
                if (pNode)
                {
                    sFNode = sFNode + pNode->NODE_NAME;
                }

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

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

