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

#include <vcl.h>
#include "ITSSkinF.h"
#include "ITSUtilF.h"
#include "ITSDbF.h"
#include "AppGlobalF.h"
#include "CDSIfscF.h"
#include "CDSRoadF.h"
#include "WindowMsgF.h"
#include "ITSLangTransF.h"
#pragma hdrstop

#include "IDB0050MF.h"
#include "IDB0051MF.h"  // 가공파라미터관리

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FRAME_LinkListF"
#pragma link "FRAME_RoadListF"
#pragma link "cxButtons"
#pragma link "cxCalc"
#pragma link "cxCheckBox"
#pragma link "cxClasses"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxDropDownEdit"
#pragma link "cxEdit"
#pragma link "cxFilter"
#pragma link "cxGraphics"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxGroupBox"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxMaskEdit"
#pragma link "cxPC"
#pragma link "cxPCdxBarPopupMenu"
#pragma link "cxSpinEdit"
#pragma link "cxSplitter"
#pragma link "cxStyles"
#pragma link "cxTextEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "FRAME_IfscListF"
#pragma resource "*.dfm"

TIDB0050M *IDB0050M = NULL;

//---------------------------------------------------------------------------
__fastcall TIDB0050M::TIDB0050M(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
int nWidth = PnlRight->Width;
int nClientW = ClientWidth;

    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);

if (ClientWidth < nClientW)
    ClientWidth = nClientW;
PnlRight->Width = nWidth;

    FTitle = Caption;//"가공파라미터 관리";

cxTabSheet2->TabVisible = false;
cxTabSheet4->TabVisible = false;
PgLink->ActivePage = cxTabSheet1;

    TvList0->OptionsView->NoDataToDisplayInfoText = "";
    TvList3->OptionsView->NoDataToDisplayInfoText = "";

    FRAMELinkList1->Column20->Visible = true;   //2레벨ID
    FRAMELinkList1->Column21->Visible = true;   //2레벨도로명
    FRAMELinkList1->Column22->Visible = true;   //파라미터
    FRAMELinkList1->PnlBottom->Visible = false;
    FRAMEIfscList1->PnlBottom->Visible = false;
    FRAMERoadList1->PnlBottom->Visible = false;

    FRAMELinkList1->TvList->OptionsData->Editing = true;
    FRAMEIfscList1->TvList->OptionsData->Editing = true;
    FRAMERoadList1->TvList->OptionsData->Editing = true;


    FRAMELinkList1->ColumnSel->Visible = true;
    FRAMEIfscList1->ColumnSel->Visible = true;
    FRAMERoadList1->ColumnSel->Visible = true;

#if 0
    if (!MyItsColSysManager)
    {
        MyItsColSysManager = new TItsColSysManager();
    }
#endif

    FSelParamId = "";
    MyParamManager = new TPrcsParamManager();
    MyParamManager->LoadFromDb();
    ImgDesc90->Visible = true;

    cxGroupBoxFMT->Enabled = false;
    cxGroupBoxFST->Enabled = false;
    cxGroupBoxMCA->Enabled = false;
    cxGroupBoxSMT->Enabled = false;

    FInit = false;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::CommClose()
{
    try
    {
#if 0
        if (MyItsColSysManager)
        {
            delete MyItsColSysManager;
            MyItsColSysManager = NULL;
        }
#endif
        if (MyParamManager)
        {
            MyParamManager->FLists.RemoveAll();
            delete MyParamManager;
            MyParamManager = NULL;
        }
        CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::FormInit()
{
    PgLink->Properties->ActivePage = cxTabSheet1;
    ADOQry->Connection = ITSDb_GetConnection();
    //MyItsColSysManager->LoadFromDb();
    LoadCollectSysInfo();
    FillProcessingParam();
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::FillProcessingParam()
{
    CbProcessingParam->Properties->Items->Clear();
    FOR_STL(TPrcsParam*, pObj, MyParamManager->FLists)
    {
        if (pObj->DEL_YN != "N") continue;
        CbProcessingParam->Properties->Items->AddObject(" [" + pObj->PARA_ID + "] " + pObj->PARA_NM, (TObject*)pObj);
    }
    CbProcessingParam->ItemIndex = 0;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::LoadCollectSysInfo()
{
    CMM_ClearGridTableView(TvList0);
    CMM_ClearGridTableView(TvList3);

    TcxDataController *pGDC0 = TvList0->DataController;
    TcxDataController *pGDC3 = TvList3->DataController;
    int nRow0 = 0;
    int nRow2 = 0;
    int nRow3 = 0;
    FColSysCnt = 0;
    try
    {
        TvList0->BeginUpdate();
        TvList3->BeginUpdate();
        //FOR_STL(TItsColSys*, pObj, MyItsColSysManager->FLists)
        FOR_STL(TItsColSys*, pObj, ItsColSysManager->FLists)
        {
            if (pObj->USE_YN == "N") continue;

            nRow3 = pGDC3->AppendRecord();
            pGDC3->Values[nRow3][ColumnC01->Index] = pObj->CLCT_SYST_NM;
            pGDC3->Values[nRow3][ColumnC02->Index] = pObj->CLCT_SYST_CD;
            pGDC3->Values[nRow3][ColumnC03->Index] = 10;

            nRow0 = pGDC0->AppendRecord();
            pGDC0->Values[nRow0][ColumnD01->Index] = pObj->CLCT_SYST_NM;
            pGDC0->Values[nRow0][ColumnD02->Index] = pObj->CLCT_SYST_CD;
            String sPri;
            sPri.printf(L"%d", (nRow0+1));
            pGDC0->Values[nRow0][ColumnD03->Index] = sPri;
            //pGDC0->Values[nRow0][ColumnD03->Index] = (nRow0+1);
            pGDC0->Values[nRow0][ColumnD04->Index] = nRow3;

            FColSysCnt++;
        }
    }
    __finally
    {
        TvList0->EndUpdate();
        TvList3->EndUpdate();
    }

	TcxComboBoxProperties *pcxCboProperties10 = (TcxComboBoxProperties*)ColumnD03->Properties;
    pcxCboProperties10->Items->Clear();
    for (int ii = 0; ii < FColSysCnt; ii++)
    {
        String sPri;
        sPri.printf(L"%d", (ii+1));
	    pcxCboProperties10->Items->Add(sPri);
	    //pcxCboProperties10->Items->Add(String(ii+1));
    }
    pcxCboProperties10->Items->Add(lblNotUse->Caption);//"사용안함");
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::FormShow(TObject *Sender)
{
    Refresh();
    FormInit();
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
    BtnSearchClick((TObject*)BtnSearch);   
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::BtnSearchClick(TObject *Sender)
{
    Application->ProcessMessages();
    TSqlCursor sqlCrs((TControl*)BtnSearch);

    RefreshData();
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::RefreshData()
{
    FRAMELinkList1->UpdateList();
    FRAMEIfscList1->UpdateList();
    FRAMERoadList1->UpdateList();
    FInit = true;

    DisplayLink();
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::BtnCloseClick(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::FormClose(TObject *Sender, TCloseAction &Action)
{
    CommClose();
    IDB0050M = NULL;
    Action = caFree;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkFMT0Click(TObject *Sender)
{
    ChkFMT1->Checked = !ChkFMT0->Checked;
    ChangeFMT(ChkFMT1->Checked);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkFMT1Click(TObject *Sender)
{
    ChkFMT0->Checked = !ChkFMT1->Checked;
    ChangeFMT(ChkFMT1->Checked);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChangeFMT(bool AUse)
{
    if (AUse)
    {
        GrpFMT1->Color = clSkyBlue;
        GrpFMT1->Enabled = true;
    }
    else
    {
        GrpFMT1->Color = clSilver;
        GrpFMT1->Enabled = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkFST1Click(TObject *Sender)
{
    TNotifyEvent OnClickEvent1 = ChkFST1->OnClick;
    TNotifyEvent OnClickEvent2 = ChkFST2->OnClick;
    TNotifyEvent OnClickEvent3 = ChkFST3->OnClick;

    try
    {
        ChkFST1->OnClick = NULL;
        ChkFST2->OnClick = NULL;
        ChkFST3->OnClick = NULL;

        if (ChkFST1->Checked == true)
        {
            ChkFST2->Checked = false;
            ChkFST3->Checked = false;
        }
        else
        if (ChkFST1->Checked == false)
        {
            ChkFST2->Checked = true;
            ChkFST3->Checked = false;
        }

        ChangeFST(false);
    }
    __finally
    {
        ChkFST1->OnClick = OnClickEvent1;
        ChkFST2->OnClick = OnClickEvent2;
        ChkFST3->OnClick = OnClickEvent3;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkFST2Click(TObject *Sender)
{
    TNotifyEvent OnClickEvent1 = ChkFST1->OnClick;
    TNotifyEvent OnClickEvent2 = ChkFST2->OnClick;
    TNotifyEvent OnClickEvent3 = ChkFST3->OnClick;

    try
    {
        ChkFST1->OnClick = NULL;
        ChkFST2->OnClick = NULL;
        ChkFST3->OnClick = NULL;

        if (ChkFST2->Checked == true)
        {
            ChkFST1->Checked = false;
            ChkFST3->Checked = false;
        }
        else
        if (ChkFST2->Checked == false)
        {
            ChkFST1->Checked = true;
            ChkFST3->Checked = false;
        }

        ChangeFST(false);
    }
    __finally
    {
        ChkFST1->OnClick = OnClickEvent1;
        ChkFST2->OnClick = OnClickEvent2;
        ChkFST3->OnClick = OnClickEvent3;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkFST3Click(TObject *Sender)
{
    TNotifyEvent OnClickEvent1 = ChkFST1->OnClick;
    TNotifyEvent OnClickEvent2 = ChkFST2->OnClick;
    TNotifyEvent OnClickEvent3 = ChkFST3->OnClick;

    try
    {
        ChkFST1->OnClick = NULL;
        ChkFST2->OnClick = NULL;
        ChkFST3->OnClick = NULL;

        if (ChkFST3->Checked == true)
        {
            ChkFST1->Checked = false;
            ChkFST2->Checked = false;
        }
        else
        if (ChkFST3->Checked == false)
        {
            ChkFST1->Checked = true;
            ChkFST2->Checked = false;
        }

        ChangeFST(false);
    }
    __finally
    {
        ChkFST1->OnClick = OnClickEvent1;
        ChkFST2->OnClick = OnClickEvent2;
        ChkFST3->OnClick = OnClickEvent3;
    }
}
//---------------------------------------------------------------------------
void __fastcall TIDB0050M::ChangeFST(bool AUse)
{
    if (ChkFST1->Checked)
    {
        GrpFST1->Color = clSkyBlue;
        GrpFST1->Enabled = true;

        GrpFST2->Color = clSilver;
        GrpFST2->Enabled = false;
    }
    else
    if (ChkFST2->Checked)
    {
        GrpFST1->Color = clSilver;
        GrpFST1->Enabled = false;

        GrpFST2->Color = clSkyBlue;
        GrpFST2->Enabled = true;
    }
    else
    if (ChkFST3->Checked)
    {
        GrpFST1->Color = clSilver;
        GrpFST1->Enabled = false;

        GrpFST2->Color = clSilver;
        GrpFST2->Enabled = false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkMCA0Click(TObject *Sender)
{
    //사용안함
    if (ChkMCA0->Checked == false)
        ChkMCA0->Checked = true;
    else
        ChangeMCA(0);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkMCA2Click(TObject *Sender)
{
    //패턴적용
    if (ChkMCA2->Checked == false)
        ChkMCA2->Checked = true;
    else
        ChangeMCA(2);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkMCA1Click(TObject *Sender)
{
    //단기(15분이동평균)/장기(패턴)
    if (ChkMCA1->Checked == false)
        ChkMCA1->Checked = true;
    else
        ChangeMCA(1);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChangeMCA(int AType)
{
TNotifyEvent OnChkMCA0 = ChkMCA0->OnClick;
TNotifyEvent OnChkMCA1 = ChkMCA1->OnClick;
TNotifyEvent OnChkMCA2 = ChkMCA2->OnClick;

ChkMCA0->OnClick = NULL;
ChkMCA1->OnClick = NULL;
ChkMCA2->OnClick = NULL;


    if (AType == 1)
    {
        GrpMCA1->Color = clSkyBlue;
        GrpMCA1->Enabled = true;
        ChkMCA0->Checked = false;
        ChkMCA2->Checked = false;
    }
    else
    {
        GrpMCA1->Color = clSilver;
        GrpMCA1->Enabled = false;
        if (AType == 0)
        {
            ChkMCA1->Checked = false;
            ChkMCA2->Checked = false;
        }
        else
        {
            ChkMCA0->Checked = false;
            ChkMCA1->Checked = false;
        }
    }
ChkMCA0->OnClick = OnChkMCA0;
ChkMCA1->OnClick = OnChkMCA1;
ChkMCA2->OnClick = OnChkMCA2;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkSMT0Click(TObject *Sender)
{
    //사용안함
    if (ChkSMT0->Checked == false)
        ChkSMT0->Checked = true;
    else
        ChangeSMT(0);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkSMT1Click(TObject *Sender)
{
    //범위값 사용
    if (ChkSMT1->Checked == false)
        ChkSMT1->Checked = true;
    else
        ChangeSMT(1);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkSMT2Click(TObject *Sender)
{
    //15분 이동평균
    if (ChkSMT2->Checked == false)
        ChkSMT2->Checked = true;
    else
        ChangeSMT(2);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChangeSMT(int AType)
{
TNotifyEvent OnChkSMT0 = ChkSMT0->OnClick;
TNotifyEvent OnChkSMT1 = ChkSMT1->OnClick;
TNotifyEvent OnChkSMT2 = ChkSMT2->OnClick;

ChkSMT0->OnClick = NULL;
ChkSMT1->OnClick = NULL;
ChkSMT2->OnClick = NULL;

    if (AType == 0)
    {
        GrpSMT1->Color = clSilver;
        GrpSMT1->Enabled = false;
        GrpSMT2->Color = clSilver;
        GrpSMT2->Enabled = false;

        ChkSMT1->Checked = false;
        ChkSMT2->Checked = false;
    }
    else
    if (AType == 1)
    {
        GrpSMT1->Color = clSkyBlue;
        GrpSMT1->Enabled = true;
        GrpSMT2->Color = clSilver;
        GrpSMT2->Enabled = false;

        ChkSMT0->Checked = false;
        ChkSMT2->Checked = false;
    }
    else
    {
        GrpSMT1->Color = clSilver;
        GrpSMT1->Enabled = false;
        GrpSMT2->Color = clSkyBlue;
        GrpSMT2->Enabled = true;

        ChkSMT0->Checked = false;
        ChkSMT1->Checked = false;
    }
ChkSMT0->OnClick = OnChkSMT0;
ChkSMT1->OnClick = OnChkSMT1;
ChkSMT2->OnClick = OnChkSMT2;
}
//---------------------------------------------------------------------------

bool __fastcall TIDB0050M::CheckParameterValue()
{
    //필터링 파라미터
    FFMTVolMin = FFMTVolMax = FFMTSpdMin = FFMTSpdMax = 0;
    if (ChkFMT0->Checked)
    {
        FFMT = "FMT0";  //사용안함
    }
    else
    if (ChkFMT1->Checked)
    {
        FFMT = "FMT1";  //범위값사용
        FFMTVolMin = SeVolMin->Value;
        FFMTVolMax = SeVolMax->Value;
        FFMTSpdMin = SeSpdMin->Value;
        FFMTSpdMax = SeSpdMax->Value;
        if (FFMTVolMin >= FFMTVolMax)
        {
            Application->MessageBox(L"필터링 파라미터 - 범위값 사용.\r\n교통량 최저값은 교통량 최대값 미만이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
        if (FFMTSpdMin >= FFMTSpdMax)
        {
            Application->MessageBox(L"필터링 파라미터 - 범위값 사용.\r\속도 최저값은 속도 최대값 미만이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
    } else return false;

    //퓨전 파라미터
    if (ChkFST1->Checked)
    {
        FFST = "FST1";  //우선순위
#if 0
        if (TvList2->DataController->RecordCount == 0)
        {
            Application->MessageBox(L"퓨전 파라미터 - 우선순위.\r\우선순위 항목을 선택하셔야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
#else
        int ii;
        int nSeq = 0;
        int nTot = 0;
        int nItem= 0;
        bool bSet[100];
        for (ii = 0; ii < 100; ii++)
            bSet[ii] = false;

        bool bDupFail = false;
        try
        {
            TcxGridDataController *pGDC = TvList0->DataController;
            TvList0->BeginUpdate();
            for(ii = 0; ii < pGDC->RecordCount; ii++)
            {
                String sPri = VarToStr(pGDC->Values[ii][ColumnD03->Index]);
                if (sPri == "사용안함") continue;

                int nTmp = StrToIntDef(sPri, 1);
#if 1
                if (bSet[nTmp])
                {
                    bDupFail = true;
                    break;
                }
                else
                {
                    bSet[nTmp] = true;
                }
#else
                nSeq += nTmp;
                nTot += (nItem+1);
                nItem++;
#endif
            }
        }
        __finally
        {
            TvList0->EndUpdate();
        }
#if 1
        if (bDupFail)
#else
        if (nSeq != nTot)
#endif
        {
            Application->MessageBox(L"퓨전 파라미터 - 우선순위.\r\우선순위는 순서에 맞게 각자 다른값을 가져야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
#endif
    }
    else
    if (ChkFST2->Checked)
    {
        FFST = "FST2";  //가중치
        int dFST = 0;
        try
        {
            TcxGridDataController *pGDC = TvList3->DataController;
            TvList3->BeginUpdate();
            for(int ii = 0; ii < pGDC->RecordCount; ii++)
            {
                int fTmp = pGDC->Values[ii][ColumnC03->Index];
                dFST += fTmp;
            }
        }
        __finally
        {
            TvList3->EndUpdate();
        }
        if (dFST != 100)
        {
            Application->MessageBox(L"퓨전 파라미터 - 가중치.\r\가중치의 전체합은 100 이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
    }
    else
    if (ChkFST3->Checked)
    {
        FFST = "FST3";  //최대값적용
    } else return false;

    //보정 파라미터
    FMCAVal3 = FMCAVal2 = FMCAVal1 = 0;
    if (ChkMCA0->Checked)
    {
        FMCA = "MCA0";  //사용안함
    }
    else
    if (ChkMCA1->Checked)
    {
        FMCA = "MCA1";  //단기(15분이동평균)/장기(패턴)
        FMCAVal3 = SeMCAVal3->Value;
        FMCAVal2 = SeMCAVal2->Value;
        FMCAVal1 = SeMCAVal1->Value;
        int nTotVal = (FMCAVal3+FMCAVal2+FMCAVal1);
        if (nTotVal != 100)
        {
            Application->MessageBox(L"보정 파라미터 - 단기(15분이동평균)/장기(패턴).\r\평균 가중치의 전체합은 100 이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
    }
    else
    if (ChkMCA2->Checked)
    {
        FMCA = "MCA2";  //패턴적용
    } else return false;

    //평활화 파라미터
    FSMTSpdMin = FSMTSpdMax = FSMTVal2 = FSMTVal1 = FSMTValC = 0;
    if (ChkSMT0->Checked)
    {
        FSMT = "SMT0";  //사용안함
    }
    else
    if (ChkSMT1->Checked)
    {
        FSMT = "SMT1";  //패턴적용
        FSMTSpdMin = SeSMTValMin->Value;
        FSMTSpdMax = SeSMTValMax->Value;
        if (FSMTSpdMin >= FSMTSpdMax)
        {
            Application->MessageBox(L"평활화 파라미터 - 편차제한.\r\최저속도계수값은 최대속도계수값 미만이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
    }
    else
    if (ChkSMT2->Checked)
    {
        FSMT = "SMT2";  //15분 이동평균
        FSMTVal2 = SeSMTVal2->Value;
        FSMTVal1 = SeSMTVal1->Value;
        FSMTValC = SeSMTValC->Value;
        int nTotVal = (FSMTVal2+FSMTVal1+FSMTValC);
        if (nTotVal != 100)
        {
            Application->MessageBox(L"평활화 파라미터 - 15분 이동평균.\r\15분 이동평균값 가중치의 전체합은 100 이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
    } else return false;

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

void __fastcall TIDB0050M::BtnApplyAllClick(TObject *Sender)
{
    String sMsg;
#if 0
    sMsg = "전체구간에 대하여 파라미터 정보를 설정합니다.                        \r\n"
           "선택한 구간에 대하여 작업을 원하시는 경우 [선택구간 적용]을 하십시요.\r\n"
           "전체구간에 대하여 파라미터 정보를 적용하시겠습니까?";
#else
    sMsg = lblAll->Caption;
#endif

    if (Application->MessageBox(sMsg.c_str(), FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;

    if (PgLink->ActivePageIndex == 0)
    {
        ModifyLinkParam(1, NULL);
    }
    else
    if (PgLink->ActivePageIndex == 1)
    {
        ModifyLinkParam(2, NULL);
    }
    else
    {
        ModifyLinkParam(3, NULL);
    }
    FRAMELinkList1->UpdateParam();

    POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_07, 0);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::BtnApplySelClick(TObject *Sender)
{
    String sMsg;
#if 0
    sMsg = "선택한 구간에 대하여 파라미터 정보를 설정합니다.                   \r\n"
           "전체 구간에 대하여 작업을 원하시는 경우 [전체구간 적용]을 하십시요.\r\n"
           "선택한 구간에 대하여 파라미터 정보를 적용하시겠습니까?";
#else
    sMsg = lblSel->Caption;
#endif

    if (Application->MessageBox(sMsg.c_str(), FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;

    int nSelCnt = 0;
    TStringList *pStringList = NULL;
    try
    {
        pStringList = new TStringList();
        if (PgLink->ActivePageIndex == 0)
        {
            //레벨1 링크
            nSelCnt = FRAMELinkList1->GetSelLinkIds(pStringList);
            if (nSelCnt <= 0)
            {
                Application->MessageBox(lblSelErr->Caption.c_str(),//L"목록에서 구간을 선택하셔야 합니다.",
                                        FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                return ;
            }
#if 0
            if (nSelCnt > 500)
            {
                Application->MessageBox(L"선택한 구간이 너무 많아 작업을 수행할 수 없습니다[최대 500개].", FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                return ;
            }
#endif
            ModifyLinkParam(1, pStringList);
        }
        else
        if (PgLink->ActivePageIndex == 1)
        {
            //서비스 링크(레벨2)
            nSelCnt = FRAMEIfscList1->GetSelLinkIds(pStringList);
            if (nSelCnt <= 0)
            {
                Application->MessageBox(lblSelErr->Caption.c_str(),//L"목록에서 구간을 선택하셔야 합니다.",
                                        FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                return ;
            }
#if 0
            if (nSelCnt > 500)
            {
                Application->MessageBox(L"선택한 구간이 너무 많아 작업을 수행할 수 없습니다[최대 500개].", FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                return ;
            }
#endif
            ModifyLinkParam(2, pStringList);
        }
        else
        {
            //도로(레벨3)
            nSelCnt = FRAMERoadList1->GetSelLinkIds(pStringList);
            if (nSelCnt <= 0)
            {
                Application->MessageBox(lblSelErr->Caption.c_str(),//L"목록에서 구간을 선택하셔야 합니다.",
                                        FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                return ;
            }
#if 0
            if (nSelCnt > 500)
            {
                Application->MessageBox(L"선택한 구간이 너무 많아 작업을 수행할 수 없습니다[최대 500개].", FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
                return ;
            }
#endif
            ModifyLinkParam(3, pStringList);
        }
    }
    __finally
    {
        if (pStringList) delete pStringList;
        FRAMELinkList1->UpdateParam();
    }
    POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_07, 0);
}
//---------------------------------------------------------------------------

bool __fastcall TIDB0050M::ModifyLinkParam(int ALevel, TStringList *AStringList)
{
    String PARA_ID = FSelParamId;
    if (PARA_ID == "") return false;

    String sQry;
    String sWhere = "";

    TADOQuery *pADO = NULL;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();

            if (AStringList)
            {
                sQry = "UPDATE TB_LINK         \r\n"
                       "   SET PARA_ID = :p01  \r\n";

                switch(ALevel)
                {
                case 1:
                    sWhere = "WHERE LINK_ID = :p02 \r\n";
                    break;
                case 2:
                    sWhere = "WHERE LINK_ID IN (SELECT LINK_ID             \r\n"
                             "                    FROM TB_IFSC_RLTN_LINK   \r\n"
                             "                   WHERE IFSC_ID = :p02 )    \r\n";
                    break;
                case 3:
                    sWhere = "WHERE LINK_ID IN (SELECT LINK_ID                                \r\n"
                             "                   FROM TB_IFSC_RLTN_LINK                       \r\n"
                             "                  WHERE IFSC_ID IN (SELECT IFSC_ID              \r\n"
                             "                                      FROM TB_ROAD_RLTN_IFSC    \r\n"
                             "                                     WHERE ROAD_ID = :p01 ) )   \r\n";
                    break;
                default: return false;
                }

                sQry = sQry + sWhere;
    			pADO->SQL->Text = sQry;

                for (int ii = 0; ii < AStringList->Count; ii++)
                {
                    String LINK_ID = AStringList->Strings[ii];
                    pADO->Parameters->ParamByName("p01")->Value = PARA_ID;
                    pADO->Parameters->ParamByName("p02")->Value = LINK_ID;
                    pADO->ExecSQL();
                }
            }
            else
            {
                sQry = "UPDATE TB_LINK         \r\n"
                       "   SET PARA_ID = :p01  \r\n";
                switch(ALevel)
                {
                case 1:
                    sWhere = "";
                    break;
                case 2:
                    sWhere = "WHERE LINK_ID IN (SELECT LINK_ID             \r\n"
                             "                    FROM TB_IFSC_RLTN_LINK ) \r\n";
                    break;
                case 3:
                    sWhere = "WHERE LINK_ID IN (SELECT LINK_ID                                \r\n"
                             "                   FROM TB_IFSC_RLTN_LINK                       \r\n"
                             "                  WHERE IFSC_ID IN (SELECT IFSC_ID              \r\n"
                             "                                      FROM TB_ROAD_RLTN_IFSC )) \r\n";
                    break;
                default: return false;
                }

                sQry = sQry + sWhere;
    			pADO->SQL->Text = sQry;
                pADO->Parameters->ParamByName("p01")->Value = PARA_ID;
                pADO->ExecSQL();
            }

            ITSDb_GetConnection()->CommitTrans();

            if (AStringList)
            {
                switch(ALevel)
                {
                case 1:
                    for (int ii = 0; ii < AStringList->Count; ii++)
                    {
                        String LINK_ID = AStringList->Strings[ii];
                        TItsLink* pLink = ItsLinkManager->FLists.Find(LINK_ID);
                        if (pLink) pLink->PARA_ID = PARA_ID;
                    }
                    break;
                case 2:
                    for (int ii = 0; ii < AStringList->Count; ii++)
                    {
                        String IFSC_ID = AStringList->Strings[ii];
                        TItsIfsc* pIfsc = ItsIfscManager->FLists.Find(IFSC_ID);
                        if (pIfsc)
                        {
                            std::map<int, String>::iterator itPos;
                            for(itPos = pIfsc->FLinks.begin(); itPos != pIfsc->FLinks.end(); ++itPos)
                            {
                                String LINK_ID = itPos->second;
                                TItsLink* pLink = ItsLinkManager->FLists.Find(LINK_ID);
                                if (pLink) pLink->PARA_ID = PARA_ID;
                            }
                        }
                    }
                    break;
                case 3:
                    for (int ii = 0; ii < AStringList->Count; ii++)
                    {
                        String ROAD_ID = AStringList->Strings[ii];
                        TItsRoad* pRoad = ItsRoadManager->FLists.Find(ROAD_ID);
                        if (pRoad)
                        {
                            std::map<int, String>::iterator itPos, itIfscPos;
                            for(itPos = pRoad->FIfscs.begin(); itPos != pRoad->FIfscs.end(); ++itPos)
                            {
                                String IFSC_ID = itPos->second;
                                TItsIfsc* pIfsc = ItsIfscManager->FLists.Find(IFSC_ID);
                                if (pIfsc)
                                {
                                    for(itIfscPos = pIfsc->FLinks.begin(); itIfscPos != pIfsc->FLinks.end(); ++itIfscPos)
                                    {
                                        String LINK_ID = itIfscPos->second;
                                        TItsLink* pLink = ItsLinkManager->FLists.Find(LINK_ID);
                                        if (pLink) pLink->PARA_ID = PARA_ID;
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
            }
            else
            {
                switch(ALevel)
                {
                case 1:
                    FOR_STL(TItsLink*, pLink, ItsLinkManager->FLists)
                    {
                        pLink->PARA_ID = PARA_ID;
                    }
                    break;
                case 2:
                    FOR_STL(TItsLink*, pLink, ItsLinkManager->FLists)
                    {
                        if (pLink->IFSC_ID != "") pLink->PARA_ID = PARA_ID;
                    }
                    break;
                case 3:
                    FOR_STL(TItsLink*, pLink, ItsLinkManager->FLists)
                    {
                        if (pLink->ROAD_ID != "") pLink->PARA_ID = PARA_ID;
                    }
                    break;
                }
            }

            Application->MessageBox(lblSaveOk->Caption.c_str(),//L"파라미터 정보를 설정 하였습니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            ShowMessage(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            ShowMessage(String(exception.ClassName()) + exception.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

void __fastcall TIDB0050M::FRAMELinkList1TvListFocusedRecordChanged(TcxCustomGridTableView *Sender, TcxCustomGridRecord *APrevFocusedRecord,
          TcxCustomGridRecord *AFocusedRecord, bool ANewItemRecordFocusingChanged)
{
    if (!FInit) return;
	if (!AFocusedRecord) return;
    if (FRAMELinkList1->TvList->ViewData->RecordCount <= 0) return;
    int nIndex = FRAMELinkList1->TvList->DataController->FocusedRecordIndex;
    if (nIndex < 0) return;

    String sLinkId = VarToStr(FRAMELinkList1->TvList->DataController->Values[nIndex][FRAMELinkList1->Column01->Index]);
    DisplayLinkParam(1, sLinkId);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::FRAMEIfscList1TvListFocusedRecordChanged(TcxCustomGridTableView *Sender, TcxCustomGridRecord *APrevFocusedRecord,
          TcxCustomGridRecord *AFocusedRecord, bool ANewItemRecordFocusingChanged)
{
    if (!FInit) return;
	if (!AFocusedRecord) return;
    if (FRAMEIfscList1->TvList->ViewData->RecordCount <= 0) return;
    int nIndex = FRAMEIfscList1->TvList->DataController->FocusedRecordIndex;
    if (nIndex < 0) return;

    String sLinkId = VarToStr(FRAMEIfscList1->TvList->DataController->Values[nIndex][FRAMEIfscList1->Column01->Index]);
    DisplayLinkParam(2, sLinkId);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::FRAMERoadList1TvListFocusedRecordChanged(TcxCustomGridTableView *Sender, TcxCustomGridRecord *APrevFocusedRecord,
          TcxCustomGridRecord *AFocusedRecord, bool ANewItemRecordFocusingChanged)
{
    if (!FInit) return;
	if (!AFocusedRecord) return;
    if (FRAMERoadList1->TvList->ViewData->RecordCount <= 0) return;
    int nIndex = FRAMERoadList1->TvList->DataController->FocusedRecordIndex;
    if (nIndex < 0) return;

    String sLinkId = VarToStr(FRAMERoadList1->TvList->DataController->Values[nIndex][FRAMERoadList1->Column01->Index]);
    DisplayLinkParam(3, sLinkId);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::DisplayLink()
{
    if (PgLink->Properties->ActivePage != cxTabSheet1) return;

    if (FRAMELinkList1->TvList->ViewData->RecordCount <= 0) return;
    int nIndex = FRAMELinkList1->TvList->DataController->FocusedRecordIndex;
    if (nIndex < 0) return;

    String sLinkId = VarToStr(FRAMELinkList1->TvList->DataController->Values[nIndex][FRAMELinkList1->Column01->Index]);
    DisplayLinkParam(1, sLinkId);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::DisplayProcessingParam(String AParamId)
{
    TPrcsParam *pObj = MyParamManager->FLists.Find(AParamId);
    if (!pObj) return;

    String sFMT;
    String sFST;
    String sMCA;
    String sSMT;

    //cxGroupBoxFMT->Enabled = true;
    //cxGroupBoxFST->Enabled = true;
    //cxGroupBoxMCA->Enabled = true;
    //cxGroupBoxSMT->Enabled = true;

    ChkFMT1->Checked = true;
    ChkMCA1->Checked = true;
    ChkSMT1->Checked = true;
    ChkFST1->Checked = true;

    {
        SeSMTValMin->Value = 0.50;
        SeSMTValMax->Value = 2.00;
    }
    {
        SeSMTVal2->Value = 20;
        SeSMTVal1->Value = 30;
        SeSMTValC->Value = 50;
    }


    try
    {
        sFMT = pObj->FLTR_MTHD_CD;
        sFST = pObj->FUSN_MTHD_CD;
        sMCA = pObj->ADJS_MTHD_CD;
        sSMT = pObj->SMTH_MTHD_CD;

        // filtering
        if (sFMT == "FMT0") {
            if (!ChkFMT0->Checked) ChkFMT0->Checked = true;
        } else
        if (sFMT == "FMT1") {
            if (!ChkFMT1->Checked) ChkFMT1->Checked = true;
        }

        // fusion
        if (sFST == "FST1") {
            if (!ChkFST1->Checked) ChkFST1->Checked = true;
        } else
        if (sFST == "FST2") {
            if (!ChkFST2->Checked) ChkFST2->Checked = true;
        } else
        if (sFST == "FST3") {
            if (!ChkFST3->Checked) ChkFST3->Checked = true;
        }

        // correct
        if (sMCA == "MCA0") {
            if (!ChkMCA0->Checked) ChkMCA0->Checked = true;
        } else
        if (sMCA == "MCA1") {
            if (!ChkMCA1->Checked) ChkMCA1->Checked = true;
        } else
        if (sMCA == "MCA2") {
            if (!ChkMCA2->Checked) ChkMCA2->Checked = true;
        }

        // smoothing
        if (sSMT == "SMT0") {
            if (!ChkSMT0->Checked) ChkSMT0->Checked = true;
        } else
        if (sSMT == "SMT1") {
            if (!ChkSMT1->Checked) ChkSMT1->Checked = true;
        } else
        if (sSMT == "SMT2") {
            if (!ChkSMT2->Checked) ChkSMT2->Checked = true;
        }


        SeVolMin->Value  = pObj->FLTR_MIN_TFVL;
        SeVolMax->Value  = pObj->FLTR_MAX_TFVL;
        SeSpdMin->Value  = pObj->FLTR_LWST_SPED;
        SeSpdMax->Value  = pObj->FLTR_HGHS_SPED;

        SeMCAVal1->Value = pObj->ADJS_WGHT_AVRG_PRE_1CYCL * 100;
        SeMCAVal2->Value = pObj->ADJS_WGHT_AVRG_PRE_2CYCL * 100;
        SeMCAVal3->Value = pObj->ADJS_WGHT_AVRG_PRE_3CYCL * 100;

        Chk15MinPtrn->Checked = pObj->ADJS_15M_PTRN_APLY_YN == "N" ? false : true;
        SeMissCycle->Value    = pObj->ADJS_SHTR_MISS_DECS_CYCL;

        SeSMTValMin->Value = pObj->SMTH_LWST_SPED_FCTR;
        SeSMTValMax->Value = pObj->SMTH_HGHS_SPED_FCTR;

        SeSMTValC->Value = (int)(pObj->SMTH_WGHT_AVRG_PRST * 100);
        SeSMTVal1->Value = (int)(pObj->SMTH_WGHT_AVRG_PRE_1CYCL * 100);
        SeSMTVal2->Value = (int)(pObj->SMTH_WGHT_AVRG_PRE_2CYCL * 100);

        LoadCollectSysInfo();
        try
        {
            int ii, nIndx;
            TcxGridDataController *pGDC0 = TvList0->DataController;
            TcxGridDataController *pGDC3 = TvList3->DataController;
            TvList0->BeginUpdate();
            TvList3->BeginUpdate();

            if (sFST == "FST1") // 우선순위
            {
                for(ii = 0; ii < pGDC0->RecordCount; ii++)
                {
                    pGDC0->Values[ii][ColumnD03->Index] = lblNotUse->Caption;//"사용안함";
                }

                FOR_STL(TPrcsParamClct*, pClct, pObj->CLCTS)
                {
                    for(ii = 0; ii < pGDC0->RecordCount; ii++)
                    {
                        if (pClct->CLCT_SYST_CD == VarToStr(pGDC0->Values[ii][ColumnD02->Index]))
                        {
                            pGDC0->Values[ii][ColumnD03->Index] = String(pClct->FUSN_PRRT);
                            break;
                        }
                    }
                }
            }
            else
            if (sFST == "FST2") // 가중치
            {
                for(ii = 0; ii < pGDC3->RecordCount; ii++)
                {
                    pGDC3->Values[ii][ColumnC03->Index] = 0;
                }

                FOR_STL(TPrcsParamClct*, pClct, pObj->CLCTS)
                {
                    for(ii = 0; ii < pGDC3->RecordCount; ii++)
                    {
                        if (pClct->CLCT_SYST_CD == VarToStr(pGDC3->Values[ii][ColumnC02->Index]))
                        {
                            pGDC3->Values[ii][ColumnC03->Index] = (pClct->FUSN_WGHT * 100.);
                            break;
                        }
                    }
                }
            }
        }
        __finally
        {
            TvList0->EndUpdate();
            TvList3->EndUpdate();

            ColumnD03->SortIndex = ColumnD03->Index;
            ColumnD03->SortOrder = soAscending;
        }
    }
    catch(Exception &exception)
    {
        ShowMessage(String(exception.ClassName()) + exception.Message);
    }

    //cxGroupBoxFMT->Enabled = false;
    //cxGroupBoxFST->Enabled = false;
    //cxGroupBoxMCA->Enabled = false;
    //cxGroupBoxSMT->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TIDB0050M::SelectParam(String AParamId)
{
    for (int ii = 0; ii < CbProcessingParam->Properties->Items->Count; ii++)
    {
        TPrcsParam *pObj = (TPrcsParam*)CbProcessingParam->Properties->Items->Objects[ii];
        if (AParamId == pObj->PARA_ID)
        {
            CbProcessingParam->ItemIndex = ii;
            break;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::DisplayLinkParam(int ALevel, String ALinkId)
{
    if (ALevel != 1) return;

    TSqlCursor sqlCursor;

    TItsLink *pLink = ItsLinkManager->FLists.Find(ALinkId);
    if (!pLink) return;
    SelectParam(pLink->PARA_ID);
    return;

    String sQry;
    TADOQuery *pADO = ADOQry;

    String sFMT;
    String sFST;
    String sMCA;
    String sSMT;

    try
    {
        try
        {
            sQry = "SELECT FLTR_MTHD_CD,     \r\n"
                   "       FUSN_MTHD_CD,     \r\n"
                   "       ADJS_MTHD_CD,     \r\n"
                   "       SMTH_MTHD_CD      \r\n"
                   "  FROM TB_LINK_PARA_STUP \r\n"
                   " WHERE LINK_ID = :p01    \r\n";
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ALinkId);
            ITSDb_SQLOpen(pADO);
            for( ; !pADO->Eof; pADO->Next())
            {
                sFMT = pADO->FieldByName("FLTR_MTHD_CD")->AsString;
                sFST = pADO->FieldByName("FUSN_MTHD_CD")->AsString;
                sMCA = pADO->FieldByName("ADJS_MTHD_CD")->AsString;
                sSMT = pADO->FieldByName("SMTH_MTHD_CD")->AsString;

                if (sFMT == "FMT0")
                {
                    if (!ChkFMT0->Checked) ChkFMT0->Checked = true;
                }
                else
                {
                    if (!ChkFMT1->Checked) ChkFMT1->Checked = true;
                }

                if (sFST == "FST1")
                {
                    if (!ChkFST1->Checked) ChkFST1->Checked = true;
                }
                else
                if (sFST == "FST2")
                {
                    if (!ChkFST2->Checked) ChkFST2->Checked = true;
                }
                else
                {
                    //"FST3"
                    if (!ChkFST3->Checked) ChkFST3->Checked = true;
                }

                if (sMCA == "MCA0")
                {
                    if (!ChkMCA0->Checked) ChkMCA0->Checked = true;
                }
                else
                if (sMCA == "MCA1")
                {
                    if (!ChkMCA1->Checked) ChkMCA1->Checked = true;
                }
                else
                {
                    if (!ChkMCA2->Checked) ChkMCA2->Checked = true;
                }

                if (sSMT == "SMT0")
                {
                    if (!ChkSMT0->Checked) ChkSMT0->Checked = true;
                }
                else
                if (sSMT == "SMT1")
                {
                    if (!ChkSMT1->Checked) ChkSMT1->Checked = true;
                }
                else
                {
                    if (!ChkSMT2->Checked) ChkSMT2->Checked = true;
                }
            }

            sQry = "SELECT FLTR_MIN_TFVL,            \r\n"
                   "       FLTR_MAX_TFVL,            \r\n"
                   "       FLTR_LWST_SPED,           \r\n"
                   "       FLTR_HGHS_SPED,           \r\n"
                   "       ADJS_WGHT_AVRG_PRE_1CYCL, \r\n"
                   "       ADJS_WGHT_AVRG_PRE_2CYCL, \r\n"
                   "       ADJS_WGHT_AVRG_PRE_3CYCL, \r\n"
                   "       ADJS_15M_PTRN_APLY_YN,    \r\n"
                   "       ADJS_SHTR_MISS_DECS_CYCL, \r\n"
                   "       SMTH_LWST_SPED_FCTR,      \r\n"
                   "       SMTH_HGHS_SPED_FCTR,      \r\n"
                   "       SMTH_WGHT_AVRG_PRST,      \r\n"
                   "       SMTH_WGHT_AVRG_PRE_1CYCL, \r\n"
                   "       SMTH_WGHT_AVRG_PRE_2CYCL  \r\n"
                   "  FROM TB_LINK_PARA_DETL         \r\n"
                   " WHERE LINK_ID = :p01            \r\n";
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ALinkId);
            ITSDb_SQLOpen(pADO);
            for( ; !pADO->Eof; pADO->Next())
            {
#if 0
                SeVolMin->Value  = pADO->FieldByName("FLTR_MIN_TFVL")->AsInteger;
                SeVolMax->Value  = pADO->FieldByName("FLTR_MAX_TFVL")->AsInteger;
                SeSpdMin->Value  = pADO->FieldByName("FLTR_LWST_SPED")->AsInteger;
                SeSpdMax->Value  = pADO->FieldByName("FLTR_HGHS_SPED")->AsInteger;
#endif

                if (sFMT == "FMT0")
                {
                    SeVolMin->Value = 1;
                    SeVolMax->Value = 200;
                    SeSpdMin->Value = 1;
                    SeSpdMax->Value = 200;
                }
                else
                {
                    SeVolMin->Value  = pADO->FieldByName("FLTR_MIN_TFVL")->AsInteger;
                    SeVolMax->Value  = pADO->FieldByName("FLTR_MAX_TFVL")->AsInteger;
                    SeSpdMin->Value  = pADO->FieldByName("FLTR_LWST_SPED")->AsInteger;
                    SeSpdMax->Value  = pADO->FieldByName("FLTR_HGHS_SPED")->AsInteger;
                }

#if 0
                SeMCAVal1->Value = pADO->FieldByName("ADJS_WGHT_AVRG_PRE_1CYCL")->AsFloat * 100;
                SeMCAVal2->Value = pADO->FieldByName("ADJS_WGHT_AVRG_PRE_2CYCL")->AsFloat * 100;
                SeMCAVal3->Value = pADO->FieldByName("ADJS_WGHT_AVRG_PRE_3CYCL")->AsFloat * 100;

                String sPtrnYn        = pADO->FieldByName("ADJS_15M_PTRN_APLY_YN")->AsString;
                Chk15MinPtrn->Checked = sPtrnYn == "N" ? false : true;
                SeMissCycle->Value    = pADO->FieldByName("ADJS_SHTR_MISS_DECS_CYCL")->AsInteger;
#endif

                if (sMCA == "MCA1")
                {
                    SeMCAVal1->Value = pADO->FieldByName("ADJS_WGHT_AVRG_PRE_1CYCL")->AsFloat * 100;
                    SeMCAVal2->Value = pADO->FieldByName("ADJS_WGHT_AVRG_PRE_2CYCL")->AsFloat * 100;
                    SeMCAVal3->Value = pADO->FieldByName("ADJS_WGHT_AVRG_PRE_3CYCL")->AsFloat * 100;

                    String sPtrnYn        = pADO->FieldByName("ADJS_15M_PTRN_APLY_YN")->AsString;
                    Chk15MinPtrn->Checked = sPtrnYn == "N" ? false : true;
                    SeMissCycle->Value    = pADO->FieldByName("ADJS_SHTR_MISS_DECS_CYCL")->AsInteger;
                }
                else
                {
                    SeMCAVal3->Value = 20;
                    SeMCAVal2->Value = 30;
                    SeMCAVal1->Value = 50;

                    Chk15MinPtrn->Checked = false;
                    SeMissCycle->Value = 3;
                }

#if 0
                SeSMTValMin->Value = pADO->FieldByName("SMTH_LWST_SPED_FCTR")->AsFloat;// * 100;
                SeSMTValMax->Value = pADO->FieldByName("SMTH_HGHS_SPED_FCTR")->AsFloat;// * 100;
                SeSMTValC->Value   = pADO->FieldByName("SMTH_WGHT_AVRG_PRST")->AsFloat * 100;
                SeSMTVal1->Value   = pADO->FieldByName("SMTH_WGHT_AVRG_PRE_1CYCL")->AsFloat * 100;
                SeSMTVal2->Value   = pADO->FieldByName("SMTH_WGHT_AVRG_PRE_2CYCL")->AsFloat * 100;
#endif

                if (sSMT == "SMT0")
                {
                    SeSMTValMin->Value = 0.50;
                    SeSMTValMax->Value = 2.00;
                    SeSMTVal2->Value = 20;
                    SeSMTVal1->Value = 30;
                    SeSMTValC->Value = 50;
                }
                else
                if (sSMT == "SMT1")
                {
                    SeSMTValMin->Value = pADO->FieldByName("SMTH_LWST_SPED_FCTR")->AsFloat;// * 100;
                    SeSMTValMax->Value = pADO->FieldByName("SMTH_HGHS_SPED_FCTR")->AsFloat;// * 100;
                }
                else
                {
                    SeSMTValC->Value   = pADO->FieldByName("SMTH_WGHT_AVRG_PRST")->AsFloat * 100;
                    SeSMTVal1->Value   = pADO->FieldByName("SMTH_WGHT_AVRG_PRE_1CYCL")->AsFloat * 100;
                    SeSMTVal2->Value   = pADO->FieldByName("SMTH_WGHT_AVRG_PRE_2CYCL")->AsFloat * 100;
                }
            }

            sQry = "SELECT FUSN_PRRT,             \r\n"
                   "       FUSN_WGHT,             \r\n"
                   "       CLCT_SYST_CD           \r\n"
                   "  FROM TB_LINK_PARA_CLCT_SYST \r\n"
                   " WHERE LINK_ID = :p01         \r\n"
                   " ORDER BY FUSN_PRRT           \r\n";
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", ALinkId);
            ITSDb_SQLOpen(pADO);
            try
            {
                int ii, nIndx;
                TcxGridDataController *pGDC = TvList0->DataController;
                TvList0->BeginUpdate();
                TvList3->BeginUpdate();

                for(ii = 0; ii < pGDC->RecordCount; ii++)
                {
                    pGDC->Values[ii][ColumnD03->Index] = "사용안함";
                    //TvList3->DataController->Values[ii][ColumnC03->Index] = 0;
                }

                for( ; !pADO->Eof; pADO->Next())
                {
                    String sCLCT_SYST_CD = pADO->FieldByName("CLCT_SYST_CD")->AsString;
                    int    nFUSN_PRRT    = pADO->FieldByName("FUSN_PRRT")->AsInteger;
                    double dFUSN_WGHT    = pADO->FieldByName("FUSN_WGHT")->AsFloat * 100;

                    for(ii = 0; ii < pGDC->RecordCount; ii++)
                    {
                        String sCode = pGDC->Values[ii][ColumnD02->Index];
                        if (sCode == sCLCT_SYST_CD)
                        {
                            String sPri;
                            sPri.printf(L"%02d", nFUSN_PRRT);
                            pGDC->Values[ii][ColumnD03->Index] = sPri;
                            //pGDC->Values[ii][ColumnD03->Index] = String(nFUSN_PRRT);
                            nIndx = pGDC->Values[ii][ColumnD04->Index];
                            TvList3->DataController->Values[nIndx][ColumnC03->Index] = dFUSN_WGHT;
                            break;
                        }
                    }
                }
            }
            __finally
            {
                TvList0->EndUpdate();
                TvList3->EndUpdate();

                ColumnD03->SortIndex = ColumnD03->Index;
                ColumnD03->SortOrder = soAscending;
            }
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
            DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        pADO->Close();
    }
}
//---------------------------------------------------------------------------


void __fastcall TIDB0050M::CbProcessingParamPropertiesChange(TObject *Sender)
{
    int nIndex = CbProcessingParam->ItemIndex;
    if (nIndex < 0) return;

    TPrcsParam *pObj = (TPrcsParam*)CbProcessingParam->Properties->Items->Objects[nIndex];
    if (!pObj) return;

    FSelParamId = pObj->PARA_ID;
    DisplayProcessingParam(FSelParamId);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::BtnProcessParamClick(TObject *Sender)
{
    IDB0051M = new TIDB0051M(this);
    IDB0051M->ShowModal();

    MyParamManager->LoadFromDb();
    FillProcessingParam();
    SelectParam(FSelParamId);
    DisplayProcessingParam(FSelParamId);
}
//---------------------------------------------------------------------------

