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

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

#include "FRAME_IncidentListF.h"
#include "CDSNodeF.h"
#include "CDSLinkF.h"
#include "CDSIncidentF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxClasses"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#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 "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxStyles"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"
//TFRAMEIncidentList *FRAMEIncidentList;
//---------------------------------------------------------------------------
__fastcall TFRAMEIncidentList::TFRAMEIncidentList(TComponent* Owner)
    : TFrame(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());

    m_pGDC = TvList->DataController;

    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 중 하나

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

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

    CMM_ClearGridTableView(TvList);

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

        try
        {
            ItsIncidentManager->FLists.Lock();
            FOR_STL(TItsIncident *, pIncident, ItsIncidentManager->FLists)
            {
                if (pIncident->INCD_PRGR_STEP_CD != "ISS2") continue;
                if (pIncident->DISP_INCD == "N") continue;

                nRow = m_pGDC->AppendRecord();

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

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

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

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

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

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

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

                m_pGDC->Values[nRow][Column01->Index] = pIncident->INCD_OCRR_ID;                //돌발상황 발생 ID
                m_pGDC->Values[nRow][Column02->Index] = ITSUtil_StrToTime(pIncident->RGST_DT);                     //등록 일시
                m_pGDC->Values[nRow][Column03->Index] = sISS;//pIncident->INCD_PRGR_STEP_CD;    //돌발상황 진행 단계 코드 : ISS
                m_pGDC->Values[nRow][Column04->Index] = sIST;//pIncident->INCD_ORGN_CD;         //돌발상황 원본 코드 : IST
                m_pGDC->Values[nRow][Column05->Index] = pIncident->OCRR_LCTN_NM;                //발생 위치 명
                m_pGDC->Values[nRow][Column06->Index] = pIncident->LINK_ID;                     //돌발발생 LINK ID
                m_pGDC->Values[nRow][Column07->Index] = pIncident->X_CRDN;                      //X 좌표
                m_pGDC->Values[nRow][Column08->Index] = pIncident->Y_CRDN;                      //Y 좌표
                m_pGDC->Values[nRow][Column09->Index] = pIncident->INCD_EXPL;                   //돌발상황 설명
                m_pGDC->Values[nRow][Column10->Index] = sLTCU;//pIncident->CMTR_GRAD_CD;        //소통 등급 코드 : LTCU
                m_pGDC->Values[nRow][Column11->Index] = pIncident->IFMR_NM;                     //제보자 명
                m_pGDC->Values[nRow][Column12->Index] = sICM;//pIncident->INCD_CNFM_MTHD_CD;    //돌발상황 확인 방법 코드 : ICM
                m_pGDC->Values[nRow][Column13->Index] = sSRLU;//pIncident->INCD_SERN_CD;        //돌발상황 심각도 코드 : SRLU
                m_pGDC->Values[nRow][Column14->Index] = pIncident->INCD_TITL;                   //돌발상황 제목
                m_pGDC->Values[nRow][Column15->Index] = sIDTU;//pIncident->INCD_TYPE_CLSF_CD;   //돌발상황 유형 분류 코드 : IDTU
                m_pGDC->Values[nRow][Column16->Index] = sACTU;//pIncident->INCD_TYPE_CD;        //돌발상황 유형 코드 : ACTU, CRTU, EVTU, WETU 중 하나
                m_pGDC->Values[nRow][Column17->Index] = ITSUtil_StrToTime(pIncident->INCD_STRT_DT);                //돌발상황 시작 일시
                m_pGDC->Values[nRow][Column18->Index] = ITSUtil_StrToTime(pIncident->INCD_END_PRAR_DT);            //돌발상황 종료 예정 일시
                m_pGDC->Values[nRow][Column19->Index] = pIncident->INCD_OCRR_LANE;              //돌발상황 발생 차로
                m_pGDC->Values[nRow][Column20->Index] = pIncident->INCD_CLSR_LANE;              //돌발상황 차단 차로
                m_pGDC->Values[nRow][Column21->Index] = pIncident->DELY_LNGT;                   //지체 길이
                m_pGDC->Values[nRow][Column22->Index] = pIncident->INCD_LNGT;                   //돌발상황 길이
                m_pGDC->Values[nRow][Column23->Index] = pIncident->SMLT_VHCL_UNUM;              //소형 차량 대수
                m_pGDC->Values[nRow][Column24->Index] = pIncident->MDLT_VHCL_UNUM;              //중대형 차량 대수
                m_pGDC->Values[nRow][Column25->Index] = pIncident->INJR_PNUM;                   //부상자 인원수
                m_pGDC->Values[nRow][Column26->Index] = pIncident->FTLT_PNUM;                   //사망자 인원수
                m_pGDC->Values[nRow][Column27->Index] = sDFW;//pIncident->WTHR_CD;              //기상 코드 : DFW
                m_pGDC->Values[nRow][Column28->Index] = sRSL;//pIncident->RESP_LVL_CD;          //대응 수준 코드 : RSL
                m_pGDC->Values[nRow][Column29->Index] = pIncident->UTIS_CNCT_YN;                //UTIS 연계 여부
                m_pGDC->Values[nRow][Column30->Index] = pIncident->TRUB_VHCL_YN;                //고장 차량 여부
                m_pGDC->Values[nRow][Column31->Index] = pIncident->FALT_YN;                     //낙하물 여부
                m_pGDC->Values[nRow][Column32->Index] = pIncident->FRWT_YN;                     //화재위험물 여부
                m_pGDC->Values[nRow][Column33->Index] = sPRTU;//pIncident->TRVL_LMNT_TYPE_CD;   //통행 제한 유형 코드 : PRTU
                m_pGDC->Values[nRow][Column34->Index] = pIncident->VMS_DSPL_YN;                 //VMS 표출 여부
            }
        }
        __finally
        {
            ItsIncidentManager->FLists.UnLock();
        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

