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

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

#include "IDB0050MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FRAME_LinkListF"
#pragma link "FRAME_IfscListF"
#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 "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinBlack"
#pragma link "dxSkinMcSkin"
#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 = "";
    TvList1->OptionsView->NoDataToDisplayInfoText = "";
    TvList2->OptionsView->NoDataToDisplayInfoText = "";
    TvList3->OptionsView->NoDataToDisplayInfoText = "";

    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

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

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

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

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

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

            nRow2 = pGDC2->AppendRecord();
            pGDC2->Values[nRow2][ColumnA01->Index] = pObj->CLCT_SYST_NM;
            pGDC2->Values[nRow2][ColumnA02->Index] = pObj->CLCT_SYST_CD;

            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;
            pGDC0->Values[nRow0][ColumnD03->Index] = (nRow0+1);
            pGDC0->Values[nRow0][ColumnD04->Index] = nRow3;

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

	TcxComboBoxProperties *pcxCboProperties10 = (TcxComboBoxProperties*)ColumnD03->Properties;
    pcxCboProperties10->Items->Clear();
    for (int ii = 0; ii < FColSysCnt; ii++)
    {
	    pcxCboProperties10->Items->Add(String(ii+1));
    }
    pcxCboProperties10->Items->Add("사용안함");
}
//---------------------------------------------------------------------------

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)
{
    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)
{
    ChkFST2->Checked = !ChkFST1->Checked;
    ChangeFST(ChkFST1->Checked);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChkFST2Click(TObject *Sender)
{
    ChkFST1->Checked = !ChkFST2->Checked;
    ChangeFST(ChkFST1->Checked);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::ChangeFST(bool AUse)
{
    if (AUse)
    {
        GrpFST1->Color = clSkyBlue;
        GrpFST1->Enabled = true;

        GrpFST2->Color = clSilver;
        GrpFST2->Enabled = false;
    }
    else
    {
        GrpFST1->Color = clSilver;
        GrpFST1->Enabled = false;

        GrpFST2->Color = clSkyBlue;
        GrpFST2->Enabled = true;
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TIDB0050M::BtnListAddClick(TObject *Sender)
{
    int nSelRows = TvList1->Controller->SelectedRowCount;
    if (nSelRows <= 0)
    {
        return;
    }

    try
    {
        TcxGridDataController *pGDC = (TcxGridDataController *)TvList2->DataController;
        TvList1->BeginUpdate();
        TvList2->BeginUpdate();
        try
        {
            for (int ii = 0; ii < nSelRows; ii++)
            {
                int nSelIdx = TvList1->Controller->SelectedRows[ii]->RecordIndex;
                int nRow = pGDC->AppendRecord();

                pGDC->Values[nRow][ColumnB01->Index] = TvList1->DataController->Values[nSelIdx][ColumnA01->Index];
                pGDC->Values[nRow][ColumnB02->Index] = TvList1->DataController->Values[nSelIdx][ColumnA02->Index];
            }
            TvList1->Controller->DeleteSelection();
        }
        catch(...)
        {
        }
    }
    __finally
    {
        TvList1->EndUpdate();
        TvList2->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::BtnListDeleteClick(TObject *Sender)
{
    int nSelRows = TvList2->Controller->SelectedRowCount;
    if (nSelRows <= 0)
    {
        return;
    }

    try
    {
        TcxGridDataController *pGDC = (TcxGridDataController *)TvList1->DataController;
        TvList1->BeginUpdate();
        TvList2->BeginUpdate();
        try
        {
            for (int ii = 0; ii < nSelRows; ii++)
            {
                int nSelIdx = TvList2->Controller->SelectedRows[ii]->RecordIndex;
                int nRow = pGDC->AppendRecord();

                pGDC->Values[nRow][ColumnA01->Index] = TvList2->DataController->Values[nSelIdx][ColumnB01->Index];
                pGDC->Values[nRow][ColumnA02->Index] = TvList2->DataController->Values[nSelIdx][ColumnB02->Index];
            }
            TvList2->Controller->DeleteSelection();
        }
        catch(...)
        {
        }
    }
    __finally
    {
        TvList1->EndUpdate();
        TvList2->EndUpdate();
    }
}
//---------------------------------------------------------------------------

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 nSeq = 0;
        int nTot = 0;
        int nItem= 0;
        try
        {
            TcxGridDataController *pGDC = TvList0->DataController;
            TvList0->BeginUpdate();
            for(int ii = 0; ii < pGDC->RecordCount; ii++)
            {
                String sPri = VarToStr(pGDC->Values[ii][ColumnD03->Index]);
                if (sPri == "사용안함") continue;

                int nTmp = StrToIntDef(sPri, 1);
                nSeq += nTmp;
                nTot += (nItem+1);
                nItem++;
#if 0
                int nTmp = pGDC->Values[ii][ColumnD03->Index];
                nSeq += nTmp;
                nTot += (ii+1);
#endif
            }
        }
        __finally
        {
            TvList0->EndUpdate();
        }
        if (nSeq != nTot)
        {
            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 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)
{
    //전체구간적용
    if (!CheckParameterValue())
    {
        return;
    }

    String sMsg;
    sMsg = "전체구간에 대하여 파라미터 정보를 설정합니다.                        \r\n"
           "선택한 구간에 대하여 작업을 원하시는 경우 [선택구간 적용]을 하십시요.\r\n"
           "전체구간에 대하여 파라미터 정보를 적용하시겠습니까?";

    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);
    }
    POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_07, 0);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0050M::BtnApplySelClick(TObject *Sender)
{
    //선택구간적용
    if (!CheckParameterValue())
    {
        return;
    }

    String sMsg;
    sMsg = "선택한 구간에 대하여 파라미터 정보를 설정합니다.                   \r\n"
           "전체 구간에 대하여 작업을 원하시는 경우 [전체구간 적용]을 하십시요.\r\n"
           "선택한 구간에 대하여 파라미터 정보를 적용하시겠습니까?";

    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(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(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(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;
    }
    POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_07, 0);
}
//---------------------------------------------------------------------------

bool __fastcall TIDB0050M::ModifyLinkParam(int ALevel, TStringList *AStringList)
{
#if 0
    String sQry;
    String sWhere  = "";
    String sIdList = "";

    if (AStringList)
    {
		if (AStringList->Count > 0)
		{
            for (int ii = 0; ii < AStringList->Count; ii++)
            {
                sIdList += "'" + AStringList->Strings[ii] +"',";
			}
		}
        if (AStringList->Count > 0)
            sIdList.Delete(sIdList.Length(), 1);
    }

    if (!sIdList.IsEmpty())
    {
        switch(ALevel)
        {
        case 1:
            sWhere = "LINK_ID IN(" + sIdList + ") \r\n";
            break;
        case 2:
            sWhere = "LINK_ID IN((SELECT LINK_ID FROM TB_IFSC_LINK_RLTN WHERE IFSC_ID IN( " + sIdList + "))) \r\n";
            break;
        case 3:
            sWhere = "LINK_ID IN (SELECT LINK_ID                                             \r\n"
                     "              FROM TB_IFSC_LINK_RLTN                                   \r\n"
                     "             WHERE IFSC_ID IN((SELECT IFSC_ID                          \r\n"
                     "                                 FROM TB_ROAD_IFSC_RLTN                \r\n"
                     "                                WHERE ROAD_ID IN( " + sIdList + " )))) \r\n";
            break;
        default: return false;
        }
    }

    String s15MinPtrn = Chk15MinPtrn->Checked ? "Y" : "N";
    int    nMissCycle = SeMissCycle->Value;

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

            ITSDb_GetConnection()->BeginTrans();

            // TB_LINK_PARA_STUP
            sQry = "UPDATE TB_LINK_PARA_STUP    \r\n"
                   "   SET FLTR_MTHD_CD = :p01, \r\n"
                   "       FUSN_MTHD_CD = :p02, \r\n"
                   "       ADJS_MTHD_CD = :p03, \r\n"
                   "       SMTH_MTHD_CD = :p04  \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", FFMT);
            ITSDb_SQLBind(pADO, "p02", FFST);
            ITSDb_SQLBind(pADO, "p03", FMCA);
            ITSDb_SQLBind(pADO, "p04", FSMT);

            ITSDb_SQLExec(pADO);

            sQry = "UPDATE TB_LINK_PARA_DETL                \r\n"
                   "   SET FLTR_MIN_TFVL            = :p01, \r\n"
                   "       FLTR_MAX_TFVL            = :p02, \r\n"
                   "       FLTR_LWST_SPED           = :p03, \r\n"
                   "       FLTR_HGHS_SPED           = :p04, \r\n"
                   "       ADJS_WGHT_AVRG_PRE_1CYCL = :p05, \r\n"
                   "       ADJS_WGHT_AVRG_PRE_2CYCL = :p06, \r\n"
                   "       ADJS_WGHT_AVRG_PRE_3CYCL = :p07, \r\n"
                   "       ADJS_15M_PTRN_APLY_YN    = :p08, \r\n"
                   "       ADJS_SHTR_MISS_DECS_CYCL = :p09, \r\n"
                   "       SMTH_LWST_SPED_FCTR      = :p10, \r\n"
                   "       SMTH_HGHS_SPED_FCTR      = :p11, \r\n"
                   "       SMTH_WGHT_AVRG_PRST      = :p12, \r\n"
                   "       SMTH_WGHT_AVRG_PRE_1CYCL = :p13, \r\n"
                   "       SMTH_WGHT_AVRG_PRE_2CYCL = :p14  \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", FFMTVolMin);
            ITSDb_SQLBind(pADO, "p02", FFMTVolMax);
            ITSDb_SQLBind(pADO, "p03", FFMTSpdMin);
            ITSDb_SQLBind(pADO, "p04", FFMTSpdMax);
            ITSDb_SQLBind(pADO, "p05", FMCAVal1/100);
            ITSDb_SQLBind(pADO, "p06", FMCAVal2/100);
            ITSDb_SQLBind(pADO, "p07", FMCAVal3/100);
            ITSDb_SQLBind(pADO, "p08", s15MinPtrn);
            ITSDb_SQLBind(pADO, "p09", nMissCycle);
            ITSDb_SQLBind(pADO, "p10", FSMTSpdMin);
            ITSDb_SQLBind(pADO, "p11", FSMTSpdMax);
            ITSDb_SQLBind(pADO, "p12", FSMTValC/100);
            ITSDb_SQLBind(pADO, "p13", FSMTVal1/100);
            ITSDb_SQLBind(pADO, "p14", FSMTVal2/100);

            ITSDb_SQLExec(pADO);

            sQry = "UPDATE TB_LINK_PARA_CLCT_SYST \r\n"
                   "   SET FUSN_PRRT    = :p02,   \r\n"
                   "       FUSN_WGHT    = :p03    \r\n"
                   " WHERE CLCT_SYST_CD = :p01    \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += "   AND " + sWhere;
            }

            ITSDb_SQLText(pADO, sQry);

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

                    String sCode = pGDC->Values[ii][ColumnD02->Index];
                    int    nOrdr = pGDC->Values[ii][ColumnD03->Index];
                    int    nIndx = pGDC->Values[ii][ColumnD04->Index];
                    int    nWigt = TvList3->DataController->Values[nIndx][ColumnC03->Index];

                    double dWeight = nWigt/100.;
                    ITSDb_SQLBind(pADO, "p01", sCode);
                    ITSDb_SQLBind(pADO, "p02", nOrdr);
                    ITSDb_SQLBind(pADO, "p03", dWeight);

                    ITSDb_SQLExec(pADO);
                }
            }
            __finally
            {
                TvList0->EndUpdate();
            }

            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;
#endif

    String sQry;
    String sWhere  = "";
    String sIdList = "";
    TSqlCursor sqlCursor;

    if (AStringList)
    {
		if (AStringList->Count > 0)
		{
            for (int ii = 0; ii < AStringList->Count; ii++)
            {
                sIdList += "'" + AStringList->Strings[ii] +"',";
			}
		}
        if (AStringList->Count > 0)
            sIdList.Delete(sIdList.Length(), 1);
    }

    if (!sIdList.IsEmpty())
    {
        switch(ALevel)
        {
        case 1:
            sWhere = "LINK_ID IN(" + sIdList + ") \r\n";
            break;
        case 2:
            sWhere = "LINK_ID IN((SELECT LINK_ID FROM TB_IFSC_LINK_RLTN WHERE IFSC_ID IN( " + sIdList + "))) \r\n";
            break;
        case 3:
            sWhere = "LINK_ID IN (SELECT LINK_ID                                             \r\n"
                     "              FROM TB_IFSC_LINK_RLTN                                   \r\n"
                     "             WHERE IFSC_ID IN((SELECT IFSC_ID                          \r\n"
                     "                                 FROM TB_ROAD_IFSC_RLTN                \r\n"
                     "                                WHERE ROAD_ID IN( " + sIdList + " )))) \r\n";
            break;
        default: return false;
        }
    }

    String s15MinPtrn = Chk15MinPtrn->Checked ? "Y" : "N";
    int    nMissCycle = SeMissCycle->Value;

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

Application->ProcessMessages();
            ITSDb_GetConnection()->BeginTrans();

            // TB_LINK_PARA_STUP
            sQry = "DELETE TB_LINK_PARA_STUP \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLExec(pADO);

Application->ProcessMessages();
            sQry = "INSERT INTO TB_LINK_PARA_STUP(LINK_ID, FLTR_MTHD_CD, FUSN_MTHD_CD, ADJS_MTHD_CD, SMTH_MTHD_CD) \r\n"
                   "SELECT LINK_ID, :p01, :p02, :p03,  :p04  \r\n"
                   "  FROM TB_LINK                           \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }

            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", FFMT);
            ITSDb_SQLBind(pADO, "p02", FFST);
            ITSDb_SQLBind(pADO, "p03", FMCA);
            ITSDb_SQLBind(pADO, "p04", FSMT);

            ITSDb_SQLExec(pADO);

            // TB_LINK_PARA_DETL
Application->ProcessMessages();
            sQry = "DELETE TB_LINK_PARA_DETL \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLExec(pADO);

Application->ProcessMessages();
            sQry = "INSERT INTO TB_LINK_PARA_DETL(           \r\n"
                   "       LINK_ID,                          \r\n"
                   "       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"
                   "SELECT LINK_ID, :p01, :p02, :p03, :p04,  \r\n"
                   "                :p05, :p06, :p07, :p08,  \r\n"
                   "                :p09, :p10, :p11, :p12,  \r\n"
                   "                :p13, :p14               \r\n"
                   "  FROM TB_LINK                           \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }

float ff = FMCAVal1/100;
float dd = FMCAVal1/100.;
            ITSDb_SQLText(pADO, sQry);

            ITSDb_SQLBind(pADO, "p01", FFMTVolMin);
            ITSDb_SQLBind(pADO, "p02", FFMTVolMax);
            ITSDb_SQLBind(pADO, "p03", FFMTSpdMin);
            ITSDb_SQLBind(pADO, "p04", FFMTSpdMax);
            ITSDb_SQLBind(pADO, "p05", FMCAVal1/100);
            ITSDb_SQLBind(pADO, "p06", FMCAVal2/100);
            ITSDb_SQLBind(pADO, "p07", FMCAVal3/100);
            ITSDb_SQLBind(pADO, "p08", s15MinPtrn);
            ITSDb_SQLBind(pADO, "p09", nMissCycle);
            ITSDb_SQLBind(pADO, "p10", FSMTSpdMin);
            ITSDb_SQLBind(pADO, "p11", FSMTSpdMax);
            ITSDb_SQLBind(pADO, "p12", FSMTValC/100);
            ITSDb_SQLBind(pADO, "p13", FSMTVal1/100);
            ITSDb_SQLBind(pADO, "p14", FSMTVal2/100);

            ITSDb_SQLExec(pADO);

            //TB_LINK_PARA_CLCT_SYST
Application->ProcessMessages();
            sQry = "DELETE TB_LINK_PARA_CLCT_SYST \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }
            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLExec(pADO);

            sQry = "INSERT INTO TB_LINK_PARA_CLCT_SYST(LINK_ID, CLCT_SYST_CD, FUSN_PRRT, FUSN_WGHT) \r\n"
                   "SELECT LINK_ID, :p01, :p02, :p03  \r\n"
                   "  FROM TB_LINK                    \r\n";
            if (!sWhere.IsEmpty())
            {
                sQry += " WHERE " + sWhere;
            }

            ITSDb_SQLText(pADO, sQry);

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

                    String sCode = pGDC->Values[ii][ColumnD02->Index];
                    int    nOrdr = pGDC->Values[ii][ColumnD03->Index];
                    int    nIndx = pGDC->Values[ii][ColumnD04->Index];
                    int    nWigt = TvList3->DataController->Values[nIndx][ColumnC03->Index];

                    double dWeight = nWigt/100.;
                    ITSDb_SQLBind(pADO, "p01", sCode);
                    ITSDb_SQLBind(pADO, "p02", nOrdr);
                    ITSDb_SQLBind(pADO, "p03", dWeight);

Application->ProcessMessages();
                    ITSDb_SQLExec(pADO);
                }
            }
            __finally
            {
                TvList0->EndUpdate();
            }

            ITSDb_GetConnection()->CommitTrans();

            Application->MessageBox(L"파라미터 정보를 설정 하였습니다.", FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(E.ClassName()) + E.Message);
        }
        catch(Exception &exception)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage(String(exception.ClassName()) + exception.Message);
        }
        catch(...)
        {
            ITSDb_GetConnection()->RollbackTrans();
            ShowMessage("데이터 작업 중에 알수없는 DB 오류가 발생하였습니다.");
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

void __fastcall 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::DisplayLinkParam(int ALevel, String ALinkId)
{
    if (ALevel != 1) return;

    TSqlCursor sqlCursor;

    String sQry;
    TADOQuery *pADO = ADOQry;
    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())
            {
                String sFMT = pADO->FieldByName("FLTR_MTHD_CD")->AsString;
                String sFST = pADO->FieldByName("FUSN_MTHD_CD")->AsString;
                String sMCA = pADO->FieldByName("ADJS_MTHD_CD")->AsString;
                String 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 (!ChkFST2->Checked) ChkFST2->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())
            {
                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;
                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;

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

            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";
            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] = "사용안함";
                }

                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)
                        {
                            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();
            }
        }
        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
    {
        pADO->Close();
    }
}
//---------------------------------------------------------------------------

