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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "AppGlobalF.h"
#pragma hdrstop

#include "FRAME_IncidentRegistF.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 resource "*.dfm"
TFRAMEIncidentRegist *FRAMEIncidentRegist;
//---------------------------------------------------------------------------
__fastcall TFRAMEIncidentRegist::TFRAMEIncidentRegist(TComponent* Owner)
    : TFrame(Owner)
{
    ITSSkin_Load((TForm*)this);

    FTitle = "신규 돌발 등록";

    m_pGDC = TvList->DataController;
    TvList->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 TFRAMEIncidentRegist::InitForm()
{
	DtINCD_CNFM_DT->Date = Now();
	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);
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentRegist::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") 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->FINCD_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 TFRAMEIncidentRegist::TvListDataControllerFilterChanged(TObject *Sender)
{
    LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
}
//---------------------------------------------------------------------------

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

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

void __fastcall TFRAMEIncidentRegist::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 TFRAMEIncidentRegist::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);
	CbINCD_ORGN_CD->Text		= sIST;
	EdOCRR_LCTN_NM->Text		= pObj->OCRR_LCTN_NM;
	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;
	DtINCD_CNFM_DT->Date		= ITSUtil_StrToDateTime(pObj->INCD_CNFM_DT);
	DtINCD_STRT_DT->Date		= ITSUtil_StrToDateTime(pObj->FINCD_STRT_DT);
	DtINCD_END_PRAR_DT->Date	= ITSUtil_StrToDateTime(pObj->INCD_END_PRAR_DT);
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEIncidentRegist::BtnSaveClick(TObject *Sender)
{
    //입력
	if (EdOCRR_LCTN_NM->Text.IsEmpty() || EdINCD_EXPL->Text.IsEmpty() || DtINCD_CNFM_DT->EditValue.IsEmpty())
	{
        Application->MessageBox(L"★항목은 필수 입력 항목입니다.\r\n모두 입력후 진행해 주세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
	}

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

    String sIncidentId = "";
    if (!ItsIncidentManager->GetNextIncidentId(CenterId, sIncidentId))
    {
        Application->MessageBox(L"신규 돌발 ID를 조회하지 못하였습니다.\r\n데이터베이스 관리자에게 확인 후에 작업하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
    }

    bool bResult = InsertToDb(sIncidentId,
                              ITSUtil_GetCode(CbINCD_ORGN_CD->Text),
                              EdOCRR_LCTN_NM->Text.Trim(),
                              EdINCD_EXPL->Text.Trim(),
                              ITSUtil_GetCode(CbCMTR_GRAD_CD->Text),
                              EdIFMR_NM->Text.Trim(),
                              ITSUtil_GetCode(CbINCD_CNFM_MTHD_CD->Text),
                              ITSUtil_GetCode(CbINCD_SERN_CD->Text),
                              ITSUtil_GetCode(CbINCD_TYPE_CLSF_CD->Text),
                              ITSUtil_GetCode(CbINCD_TYPE_CD->Text),
                              DtINCD_CNFM_DT->Date.FormatString("YYYYMMDDHHNNSS"),
                              DtINCD_STRT_DT->Date.FormatString("YYYYMMDDHHNNSS"),
                              DtINCD_END_PRAR_DT->Date.FormatString("YYYYMMDDHHNNSS"));
    if (bResult)
    {
        ItsIncidentManager->LoadFromDb();
        UpdateList();
        CMM_SetGridFocusRow(CxList, TvList, sIncidentId, Column01->Index);
    }
}
//---------------------------------------------------------------------------

bool __fastcall TFRAMEIncidentRegist::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     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 )                  \r\n"
                   "                  VALUES(:p01, :p02, :p03, :p04,                                          \r\n"
                   "                         :p05, :p06, :p07, :p08,                                          \r\n"
                   "                         :p09, :p10, :p11, :p12,                                          \r\n"
                   "                         :p13, :p14, 'ISS1' )                                             \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_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;
}
//---------------------------------------------------------------------------

