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

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

#include "IDB0051MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#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 "cxGridBandedTableView"
#pragma link "dxSkinMcSkin"
#pragma resource "*.dfm"

TIDB0051M *IDB0051M = NULL;

//---------------------------------------------------------------------------
__fastcall TIDB0051M::TIDB0051M(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    CMM_LoadForm(g_sFormsDir, this);
    LoadLocalSkin();

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

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

    MyParamManager = new TPrcsParamManager();
    FInit = false;
}
//---------------------------------------------------------------------------

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

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

void __fastcall TIDB0051M::FormInit()
{
    ADOQry->Connection = ITSDb_GetConnection();
    InitCollectSysInfo();

    FormClear();
    ChangeButtonType(1);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::LoadLocalSkin()
{
    ImgDesc90->Visible = true;
    ImgDesc91->Visible = true;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::InitCollectSysInfo()
{
    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, 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;
            pGDC0->Values[nRow0][ColumnD03->Index] = String(nRow0+1);
            pGDC0->Values[nRow0][ColumnD04->Index] = nRow0;

            FColSysCnt++;
        }
    }
    __finally
    {
        TvList0->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(lblNotUse->Caption);//"사용안함");
}
//---------------------------------------------------------------------------

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

void __fastcall TIDB0051M::BtnSearchClick(TObject *Sender)
{
    FormClear();

    Application->ProcessMessages();

    TSqlCursor sqlCrs((TControl*)BtnSearch);
    RefreshData();

    CxList->SetFocus();

    ChangeButtonType(1);
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::RefreshData()
{
    FInit = true;

    try
    {
        TvList->BeginUpdate();
        SelListData();
	}
	__finally
	{
        TvList->EndUpdate();
	}
}
//---------------------------------------------------------------------------

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

void __fastcall TIDB0051M::FormClear()
{
    JobType = enJobNone;

	EdParamId->Clear();
    EdParamName->Clear();

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

    BtnFMTInitValClick(NULL);
    BtnMCAInitValClick(NULL);

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

void __fastcall TIDB0051M::ChangeButtonType(int nBtnType)
{
    if (nBtnType == 1)
    {
        BtnSave->Visible = false;
        BtnCancel->Visible = false;

        BtnInsert->Visible = true;
        if (TvList->ViewData->RecordCount > 0)
        {
            BtnEdit->Visible = true;
            BtnDelete->Visible = true;
        }
        else
        {
            BtnEdit->Visible = false;
            BtnDelete->Visible = false;
        }

        BtnSearch->Enabled = true;
        CxList->Enabled = true;
        PnlEdit->Enabled = false;
    }
    else
    {
        BtnSave->Visible = true;
        BtnCancel->Visible = true;

        BtnInsert->Visible = false;
        BtnEdit->Visible = false;
        BtnDelete->Visible = false;

        BtnSearch->Enabled = false;
        CxList->Enabled = false;
        PnlEdit->Enabled = true;
    }
}
//---------------------------------------------------------------------------

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

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

    if (ChkFMT0->Checked)
        BtnFMTInitVal->Enabled = false;
    else
        BtnFMTInitVal->Enabled = true;
}
//---------------------------------------------------------------------------

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

    if (ChkFMT0->Checked)
        BtnFMTInitVal->Enabled = false;
    else
        BtnFMTInitVal->Enabled = true;
}
//---------------------------------------------------------------------------

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

void __fastcall TIDB0051M::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 TIDB0051M::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 TIDB0051M::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 TIDB0051M::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 TIDB0051M::ChkMCA0Click(TObject *Sender)
{
    //사용안함
    if (ChkMCA0->Checked == false)
        ChkMCA0->Checked = true;
    else
        ChangeMCA(0);

    if (ChkMCA1->Checked)
        BtnMCAInitVal->Enabled = true;
    else
        BtnMCAInitVal->Enabled = false;
}
//---------------------------------------------------------------------------

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

    if (ChkMCA1->Checked)
        BtnMCAInitVal->Enabled = true;
    else
        BtnMCAInitVal->Enabled = false;
}
//---------------------------------------------------------------------------

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

    if (ChkMCA1->Checked)
        BtnMCAInitVal->Enabled = true;
    else
        BtnMCAInitVal->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::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 TIDB0051M::ChkSMT0Click(TObject *Sender)
{
    //사용안함
    if (ChkSMT0->Checked == false)
        ChkSMT0->Checked = true;
    else
        ChangeSMT(0);

    if (ChkSMT0->Checked)
        BtnSMTIintVal->Enabled = false;
    else
        BtnSMTIintVal->Enabled = true;
}
//---------------------------------------------------------------------------

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

    if (ChkSMT0->Checked)
        BtnSMTIintVal->Enabled = false;
    else
        BtnSMTIintVal->Enabled = true;
}
//---------------------------------------------------------------------------

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

    if (ChkSMT0->Checked)
        BtnSMTIintVal->Enabled = false;
    else
        BtnSMTIintVal->Enabled = true;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::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;

        //BtnSMTIintVal->Hint = "평활화 파라미터(편차제한) 초기값";
    }
    else
    {
        GrpSMT1->Color = clSilver;
        GrpSMT1->Enabled = false;
        GrpSMT2->Color = clSkyBlue;
        GrpSMT2->Enabled = true;

        ChkSMT0->Checked = false;
        ChkSMT1->Checked = false;

        //BtnSMTIintVal->Hint = "평활화 파라미터(15분 이동평균) 초기값";
    }
ChkSMT0->OnClick = OnChkSMT0;
ChkSMT1->OnClick = OnChkSMT1;
ChkSMT2->OnClick = OnChkSMT2;
}
//---------------------------------------------------------------------------

bool __fastcall TIDB0051M::CheckParameterValue()
{
    //필터링 파라미터
    FFMTVolMin = FFMTVolMax = FFMTSpdMin = FFMTSpdMax = 0;
    FFMTVolMin = SeVolMin->Value;
    FFMTVolMax = SeVolMax->Value;
    FFMTSpdMin = SeSpdMin->Value;
    FFMTSpdMax = SeSpdMax->Value;
    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(lblText1->Caption.c_str(),//L"필터링 파라미터 - 범위값 사용.\r\n교통량 최저값은 교통량 최대값 미만이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
        if (FFMTSpdMin >= FFMTSpdMax)
        {
            Application->MessageBox(lblText2->Caption.c_str(),//L"필터링 파라미터 - 범위값 사용.\r\n속도 최저값은 속도 최대값 미만이어야 합니다.",
                                    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(lblText3->Caption.c_str(),//L"퓨전 파라미터 - 우선순위.\r\n우선순위 항목을 선택하셔야 합니다.",
                                    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 == lblNotUse->Caption)//"사용안함")
                    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(lblText4->Caption.c_str(),//L"퓨전 파라미터 - 우선순위.\r\n우선순위는 순서에 맞게 각자 다른값을 가져야 합니다.",
                                    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(lblText5->Caption.c_str(),//L"퓨전 파라미터 - 가중치.\r\n가중치의 전체합은 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;
    FMCAVal3 = SeMCAVal3->Value;
    FMCAVal2 = SeMCAVal2->Value;
    FMCAVal1 = SeMCAVal1->Value;
    F15MinPtrn = Chk15MinPtrn->Checked ? "Y" : "N";
    FMissCycle = SeMissCycle->Value;
    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(lblText6->Caption.c_str(),//L"보정 파라미터 - 단기(15분이동평균)/장기(패턴).\r\n평균 가중치의 전체합은 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;
    //기본값으로 디비 저장하기 위해
    FSMTSpdMin = SeSMTValMin->Value;
    FSMTSpdMax = SeSMTValMax->Value;
    FSMTVal2 = SeSMTVal2->Value;
    FSMTVal1 = SeSMTVal1->Value;
    FSMTValC = SeSMTValC->Value;

    if (ChkSMT0->Checked)
    {
        FSMT = "SMT0";  //사용안함
    }
    else
    if (ChkSMT1->Checked)
    {
        FSMT = "SMT1";  //패턴적용
        FSMTSpdMin = SeSMTValMin->Value;
        FSMTSpdMax = SeSMTValMax->Value;
        if (FSMTSpdMin >= FSMTSpdMax)
        {
            Application->MessageBox(lblText7->Caption.c_str(),//L"평활화 파라미터 - 편차제한.\r\n최저속도계수값은 최대속도계수값 미만이어야 합니다.",
                                    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(lblText8->Caption.c_str(),//L"평활화 파라미터 - 15분 이동평균.\r\n15분 이동평균값 가중치의 전체합은 100 이어야 합니다.",
                                    FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
            return false;
        }
    } else return false;

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

bool __fastcall TIDB0051M::MergeData(String PARA_ID, String PARA_NM)
{
    String     sQry;
    TADOQuery *pADO = NULL;
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();

            // TB_LINK_PARA_STUP
            sQry = "MERGE INTO TB_LINK_PARA_STUP L               \r\n"
                   "USING (SELECT :p01 AS FLTR_MTHD_CD,          \r\n"
                   "              :p02 AS FUSN_MTHD_CD,          \r\n"
                   "              :p03 AS ADJS_MTHD_CD,          \r\n"
                   "              :p04 AS SMTH_MTHD_CD,          \r\n"
                   "              :p05 AS PARA_NM,               \r\n"
                   "              :P06 AS PARA_ID                \r\n"
                   "         FROM DUAL ) M                       \r\n"
                   "   ON (L.PARA_ID = M.PARA_ID)                \r\n"
                   " WHEN MATCHED THEN                           \r\n"
                   " UPDATE SET L.FLTR_MTHD_CD = M.FLTR_MTHD_CD, \r\n"
                   "            L.FUSN_MTHD_CD = M.FUSN_MTHD_CD, \r\n"
                   "            L.ADJS_MTHD_CD = M.ADJS_MTHD_CD, \r\n"
                   "            L.SMTH_MTHD_CD = M.SMTH_MTHD_CD, \r\n"
                   "            L.PARA_NM      = M.PARA_NM       \r\n"
                   " WHEN NOT MATCHED THEN                       \r\n"
                   " INSERT (L.PARA_ID,                          \r\n"
                   "         L.FLTR_MTHD_CD, L.FUSN_MTHD_CD,     \r\n"
                   "         L.ADJS_MTHD_CD, L.SMTH_MTHD_CD,     \r\n"
                   "         L.PARA_NM)                          \r\n"
                   " VALUES (M.PARA_ID,                          \r\n"
                   "         M.FLTR_MTHD_CD, M.FUSN_MTHD_CD,     \r\n"
                   "         M.ADJS_MTHD_CD, M.SMTH_MTHD_CD,     \r\n"
                   "         M.PARA_NM)                          \r\n";

			pADO->SQL->Text = sQry;

            pADO->Parameters->ParamByName("p01")->Value = FFMT;
            pADO->Parameters->ParamByName("p02")->Value = FFST;
            pADO->Parameters->ParamByName("p03")->Value = FMCA;
            pADO->Parameters->ParamByName("p04")->Value = FSMT;
            pADO->Parameters->ParamByName("p05")->Value = PARA_NM;
            pADO->Parameters->ParamByName("P06")->Value = PARA_ID;

			pADO->ExecSQL();

            sQry = "MERGE INTO TB_LINK_PARA_DETL L                                  \r\n"
                   "USING (SELECT :p01 AS FLTR_MIN_TFVL,                            \r\n"
                   "              :p02 AS FLTR_MAX_TFVL,                            \r\n"
                   "              :p03 AS FLTR_LWST_SPED,                           \r\n"
                   "              :p04 AS FLTR_HGHS_SPED,                           \r\n"
                   "              :p05 AS ADJS_WGHT_AVRG_PRE_1CYCL,                 \r\n"
                   "              :p06 AS ADJS_WGHT_AVRG_PRE_2CYCL,                 \r\n"
                   "              :p07 AS ADJS_WGHT_AVRG_PRE_3CYCL,                 \r\n"
                   "              :p08 AS ADJS_15M_PTRN_APLY_YN,                    \r\n"
                   "              :p09 AS ADJS_SHTR_MISS_DECS_CYCL,                 \r\n"
                   "              :p10 AS SMTH_LWST_SPED_FCTR,                      \r\n"
                   "              :p11 AS SMTH_HGHS_SPED_FCTR,                      \r\n"
                   "              :p12 AS SMTH_WGHT_AVRG_PRST,                      \r\n"
                   "              :p13 AS SMTH_WGHT_AVRG_PRE_1CYCL,                 \r\n"
                   "              :p14 AS SMTH_WGHT_AVRG_PRE_2CYCL,                 \r\n"
                   "              :p15 AS PARA_ID                                   \r\n"
                   "         FROM DUAL ) M                                          \r\n"
                   "   ON (L.PARA_ID = M.PARA_ID)                                   \r\n"
                   " WHEN MATCHED THEN                                              \r\n"
                   " UPDATE                                                         \r\n"
                   "   SET L.FLTR_MIN_TFVL            = M.FLTR_MIN_TFVL,            \r\n"
                   "       L.FLTR_MAX_TFVL            = M.FLTR_MAX_TFVL,            \r\n"
                   "       L.FLTR_LWST_SPED           = M.FLTR_LWST_SPED,           \r\n"
                   "       L.FLTR_HGHS_SPED           = M.FLTR_HGHS_SPED,           \r\n"
                   "       L.ADJS_WGHT_AVRG_PRE_1CYCL = M.ADJS_WGHT_AVRG_PRE_1CYCL, \r\n"
                   "       L.ADJS_WGHT_AVRG_PRE_2CYCL = M.ADJS_WGHT_AVRG_PRE_2CYCL, \r\n"
                   "       L.ADJS_WGHT_AVRG_PRE_3CYCL = M.ADJS_WGHT_AVRG_PRE_3CYCL, \r\n"
                   "       L.ADJS_15M_PTRN_APLY_YN    = M.ADJS_15M_PTRN_APLY_YN,    \r\n"
                   "       L.ADJS_SHTR_MISS_DECS_CYCL = M.ADJS_SHTR_MISS_DECS_CYCL, \r\n"
                   "       L.SMTH_LWST_SPED_FCTR      = M.SMTH_LWST_SPED_FCTR,      \r\n"
                   "       L.SMTH_HGHS_SPED_FCTR      = M.SMTH_HGHS_SPED_FCTR,      \r\n"
                   "       L.SMTH_WGHT_AVRG_PRST      = M.SMTH_WGHT_AVRG_PRST,      \r\n"
                   "       L.SMTH_WGHT_AVRG_PRE_1CYCL = M.SMTH_WGHT_AVRG_PRE_1CYCL, \r\n"
                   "       L.SMTH_WGHT_AVRG_PRE_2CYCL = M.SMTH_WGHT_AVRG_PRE_2CYCL  \r\n"
                   " WHEN NOT MATCHED THEN                                          \r\n"
                   " INSERT ( L.PARA_ID              ,                              \r\n"
                   "       L.FLTR_MIN_TFVL           ,                              \r\n"
                   "       L.FLTR_MAX_TFVL           ,                              \r\n"
                   "       L.FLTR_LWST_SPED          ,                              \r\n"
                   "       L.FLTR_HGHS_SPED          ,                              \r\n"
                   "       L.ADJS_WGHT_AVRG_PRE_1CYCL,                              \r\n"
                   "       L.ADJS_WGHT_AVRG_PRE_2CYCL,                              \r\n"
                   "       L.ADJS_WGHT_AVRG_PRE_3CYCL,                              \r\n"
                   "       L.ADJS_15M_PTRN_APLY_YN   ,                              \r\n"
                   "       L.ADJS_SHTR_MISS_DECS_CYCL,                              \r\n"
                   "       L.SMTH_LWST_SPED_FCTR     ,                              \r\n"
                   "       L.SMTH_HGHS_SPED_FCTR     ,                              \r\n"
                   "       L.SMTH_WGHT_AVRG_PRST     ,                              \r\n"
                   "       L.SMTH_WGHT_AVRG_PRE_1CYCL,                              \r\n"
                   "       L.SMTH_WGHT_AVRG_PRE_2CYCL )                             \r\n"
                   " VALUES ( M.PARA_ID              ,                              \r\n"
                   "       M.FLTR_MIN_TFVL           ,                              \r\n"
                   "       M.FLTR_MAX_TFVL           ,                              \r\n"
                   "       M.FLTR_LWST_SPED          ,                              \r\n"
                   "       M.FLTR_HGHS_SPED          ,                              \r\n"
                   "       M.ADJS_WGHT_AVRG_PRE_1CYCL,                              \r\n"
                   "       M.ADJS_WGHT_AVRG_PRE_2CYCL,                              \r\n"
                   "       M.ADJS_WGHT_AVRG_PRE_3CYCL,                              \r\n"
                   "       M.ADJS_15M_PTRN_APLY_YN   ,                              \r\n"
                   "       M.ADJS_SHTR_MISS_DECS_CYCL,                              \r\n"
                   "       M.SMTH_LWST_SPED_FCTR     ,                              \r\n"
                   "       M.SMTH_HGHS_SPED_FCTR     ,                              \r\n"
                   "       M.SMTH_WGHT_AVRG_PRST     ,                              \r\n"
                   "       M.SMTH_WGHT_AVRG_PRE_1CYCL,                              \r\n"
                   "       M.SMTH_WGHT_AVRG_PRE_2CYCL )                             \r\n";

			pADO->SQL->Text = sQry;

            pADO->Parameters->ParamByName("p01")->Value = FFMTVolMin;
            pADO->Parameters->ParamByName("p02")->Value = FFMTVolMax;
            pADO->Parameters->ParamByName("p03")->Value = FFMTSpdMin;
            pADO->Parameters->ParamByName("p04")->Value = FFMTSpdMax;
            pADO->Parameters->ParamByName("p05")->Value = FMCAVal1/100.;
            pADO->Parameters->ParamByName("p06")->Value = FMCAVal2/100.;
            pADO->Parameters->ParamByName("p07")->Value = FMCAVal3/100.;
            pADO->Parameters->ParamByName("p08")->Value = F15MinPtrn;
            pADO->Parameters->ParamByName("p09")->Value = FMissCycle;
            pADO->Parameters->ParamByName("p10")->Value = FSMTSpdMin/1.;
            pADO->Parameters->ParamByName("p11")->Value = FSMTSpdMax/1.;
            pADO->Parameters->ParamByName("p12")->Value = FSMTValC/100.;
            pADO->Parameters->ParamByName("p13")->Value = FSMTVal1/100.;
            pADO->Parameters->ParamByName("p14")->Value = FSMTVal2/100.;
            pADO->Parameters->ParamByName("p15")->Value = PARA_ID;

			pADO->ExecSQL();


            sQry = "DELETE TB_LINK_PARA_CLCT_SYST  \r\n"
                   " WHERE PARA_ID = :p01          \r\n";

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


            sQry = "INSERT INTO TB_LINK_PARA_CLCT_SYST                  \r\n"
                   "      (PARA_ID, CLCT_SYST_CD, FUSN_PRRT, FUSN_WGHT) \r\n"
                   "VALUES(:p04,    :p01,         :p02,      :p03     ) \r\n";

			pADO->SQL->Text = sQry;

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

                if (FFST == "FST1") // 우선순위
                {
                    for(ii = 0; ii < pGDC0->RecordCount; ii++)
                    {
                        String sPrrt = pGDC0->Values[ii][ColumnD03->Index];
                        if (sPrrt == lblNotUse->Caption) continue;

                        String sClctCd = pGDC0->Values[ii][ColumnD02->Index];
                        int    nPrrt = sPrrt.ToIntDef(1);
                        int    nWigt = 0;
                        for(jj = 0; jj < pGDC3->RecordCount; jj++)
                        {
                            if (sClctCd == VarToStr(pGDC3->Values[jj][ColumnC02->Index]))
                            {
                                nWigt = pGDC3->Values[jj][ColumnC03->Index];
                                break;
                            }
                        }
                        double dWeight = nWigt/100.;

                        pADO->Parameters->ParamByName("p01")->Value = sClctCd;
                        pADO->Parameters->ParamByName("p02")->Value = nPrrt;
                        pADO->Parameters->ParamByName("p03")->Value = dWeight;
                        pADO->Parameters->ParamByName("p04")->Value = PARA_ID;

            			pADO->ExecSQL();
                    }
                }
                else
                if (FFST == "FST2") // 가중치
                {
                    for(ii = 0; ii < pGDC3->RecordCount; ii++)
                    {
                        int    nWigt   = 0;
                        nWigt = pGDC3->Values[ii][ColumnC03->Index];
                        if (nWigt == 0) continue;

                        String sClctCd = pGDC3->Values[ii][ColumnC02->Index];
                        String sPrrt   = "1";
                        int    nPrrt   = sPrrt.ToIntDef(1);
                        for(jj = 0; jj < pGDC0->RecordCount; jj++)
                        {
                            if (sClctCd == VarToStr(pGDC0->Values[jj][ColumnD02->Index]))
                            {
                                sPrrt = pGDC0->Values[jj][ColumnD03->Index];
                                if (sPrrt == lblNotUse->Caption) sPrrt = "1";
                                nPrrt = sPrrt.ToIntDef(1);
                                break;
                            }
                        }
                        double dWeight = nWigt/100.;

                        pADO->Parameters->ParamByName("p01")->Value = sClctCd;
                        pADO->Parameters->ParamByName("p02")->Value = nPrrt;
                        pADO->Parameters->ParamByName("p03")->Value = dWeight;
                        pADO->Parameters->ParamByName("p04")->Value = PARA_ID;

            			pADO->ExecSQL();
                    }
                }
            }
            __finally
            {
                TvList0->EndUpdate();
                TvList3->EndUpdate();
            }

            ITSDb_GetConnection()->CommitTrans();

            Application->MessageBox(lblText9->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);
            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
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }

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

void __fastcall TIDB0051M::SelListData()
{
    TSqlCursor sqlCursor;
    Application->ProcessMessages();

    MyParamManager->LoadFromDb();

    CMM_ClearGridTableView(TvList);

    int nRow;
    TcxDataController* pGDC = TvList->DataController;

    try
    {
        TvList->BeginUpdate();

        FOR_STL(TPrcsParam*, pObj, MyParamManager->FLists)
        {
            if (pObj->DEL_YN != "N") continue;

            nRow = pGDC->AppendRecord();

            pGDC->Values[nRow][Column10->Index] = pObj->PARA_ID;
            pGDC->Values[nRow][Column11->Index] = pObj->PARA_NM;

            if (pObj->FLTR_MTHD_CD == "FMT0") pGDC->Values[nRow][Column20->Index] = ChkFMT0->Caption;
            else
            if (pObj->FLTR_MTHD_CD == "FMT1")
            {
                pGDC->Values[nRow][Column20->Index] = ChkFMT1->Caption;

                pGDC->Values[nRow][Column21->Index] = pObj->FLTR_MIN_TFVL;
                pGDC->Values[nRow][Column22->Index] = pObj->FLTR_MAX_TFVL;
                pGDC->Values[nRow][Column23->Index] = pObj->FLTR_LWST_SPED;
                pGDC->Values[nRow][Column24->Index] = pObj->FLTR_HGHS_SPED;
            }

            if (pObj->FUSN_MTHD_CD == "FST1") pGDC->Values[nRow][Column30->Index] = ChkFST1->Caption;
            else
            if (pObj->FUSN_MTHD_CD == "FST2") pGDC->Values[nRow][Column30->Index] = ChkFST2->Caption;
            else
            if (pObj->FUSN_MTHD_CD == "FST3") pGDC->Values[nRow][Column30->Index] = ChkFST3->Caption;

            if (pObj->ADJS_MTHD_CD == "MCA0") pGDC->Values[nRow][Column40->Index] = ChkMCA0->Caption;
            else
            if (pObj->ADJS_MTHD_CD == "MCA1")
            {
                pGDC->Values[nRow][Column40->Index] = ChkMCA1->Caption;

                pGDC->Values[nRow][Column41->Index] = pObj->ADJS_WGHT_AVRG_PRE_3CYCL * 100;
                pGDC->Values[nRow][Column42->Index] = pObj->ADJS_WGHT_AVRG_PRE_2CYCL * 100;
                pGDC->Values[nRow][Column43->Index] = pObj->ADJS_WGHT_AVRG_PRE_1CYCL * 100;
                pGDC->Values[nRow][Column44->Index] = pObj->ADJS_15M_PTRN_APLY_YN;
                pGDC->Values[nRow][Column45->Index] = pObj->ADJS_SHTR_MISS_DECS_CYCL;
            }
            else
            if (pObj->ADJS_MTHD_CD == "MCA2") pGDC->Values[nRow][Column40->Index] = ChkMCA2->Caption;

            if (pObj->SMTH_MTHD_CD == "SMT0") pGDC->Values[nRow][Column50->Index] = ChkSMT0->Caption;
            else
            if (pObj->SMTH_MTHD_CD == "SMT1")
            {
                pGDC->Values[nRow][Column50->Index] = ChkSMT1->Caption;

                pGDC->Values[nRow][Column51->Index] = FormatFloat("#0.#0", pObj->SMTH_LWST_SPED_FCTR);
                pGDC->Values[nRow][Column52->Index] = FormatFloat("#0.#0", pObj->SMTH_HGHS_SPED_FCTR);
            }
            else
            if (pObj->SMTH_MTHD_CD == "SMT2")
            {
                pGDC->Values[nRow][Column50->Index] = ChkSMT2->Caption;

                pGDC->Values[nRow][Column53->Index] = pObj->SMTH_WGHT_AVRG_PRE_2CYCL * 100;
                pGDC->Values[nRow][Column54->Index] = pObj->SMTH_WGHT_AVRG_PRE_1CYCL * 100;
                pGDC->Values[nRow][Column55->Index] = pObj->SMTH_WGHT_AVRG_PRST * 100;
            }
#if 0

            pGDC->Values[nRow][Column31->Index] = ;
            pGDC->Values[nRow][Column32->Index] = ;


#endif
            pGDC->Values[nRow][Column99->Index] = (int)pObj;

        }
    }
    __finally
    {
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnSMTIintValClick(TObject *Sender)
{
    if (ChkSMT1->Checked)
    {
        SeSMTValMin->Value = 0.50;
        SeSMTValMax->Value = 2.00;
    }
    else
    if (ChkSMT2->Checked)
    {
        SeSMTVal2->Value = 20;
        SeSMTVal1->Value = 30;
        SeSMTValC->Value = 50;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnMCAInitValClick(TObject *Sender)
{
    if (ChkMCA1->Checked)
    {
        SeMCAVal3->Value = 20;
        SeMCAVal2->Value = 30;
        SeMCAVal1->Value = 50;

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

void __fastcall TIDB0051M::BtnFMTInitValClick(TObject *Sender)
{
    if (ChkFMT1->Checked)
    {
        SeVolMin->Value = 1;
        SeVolMax->Value = 200;
        SeSpdMin->Value = 1;
        SeSpdMax->Value = 200;
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::DisplayListData()
{
    FormClear();

    if (TvList->ViewData->RecordCount <= 0) return;

    TcxDataController* pGDC = TvList->DataController;
    int nIndex = pGDC->FocusedRecordIndex;
    if (nIndex < 0) return;

    int nMemPtr = pGDC->Values[nIndex][Column99->Index];
    TPrcsParam *pObj = (TPrcsParam*)nMemPtr;
    if (!pObj) return;

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

    EdParamId->Text = pObj->PARA_ID;
    EdParamName->Text = pObj->PARA_NM;
    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;
        }


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

        if (sMCA == "MCA1")
        {
            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;
        }
        else
        {
            SeMCAVal3->Value = 20;
            SeMCAVal2->Value = 30;
            SeMCAVal1->Value = 50;

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

        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 = pObj->SMTH_LWST_SPED_FCTR;
            SeSMTValMax->Value = pObj->SMTH_HGHS_SPED_FCTR;

            SeSMTVal2->Value = 20;
            SeSMTVal1->Value = 30;
            SeSMTValC->Value = 50;
        }
        else
        if (sSMT == "SMT2")
        {
            SeSMTValMin->Value = 0.50;
            SeSMTValMax->Value = 2.00;

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

        InitCollectSysInfo();
        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);
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnSaveClick(TObject *Sender)
{
    String sMsgTitle, sMsgString;
    int nMsgType = MB_OK|MB_ICONWARNING|MB_APPLMODAL;

    String sId = EdParamId->Text.Trim();

    TPrcsParam* pObj;
    if (JobType == enJobSave)
    {
        sMsgTitle = lblSave->Caption;//"가공파라미터 정보 등록";
        pObj = new TPrcsParam();
        pObj->PARA_ID = sId;
        pObj->DEL_YN = "N";
        MyParamManager->FLists.Push(pObj->PARA_ID, pObj);
    }
    else
    {
        sMsgTitle = lblEdit->Caption;//"가공파라미터 정보 수정";
        pObj = MyParamManager->FLists.Find(sId);
    }

	if (sId == "" || pObj == NULL)
    {
    	sMsgString = lblSelErr->Caption;//"가공파라미터를 선택하세요.";
        Application->MessageBox(sMsgString.c_str(), sMsgTitle.c_str(), nMsgType);
        //ActiveControl = EdParamId;
        return;
	}

    String sName = EdParamName->Text.Trim();
	if (sName == "")
    {
    	sMsgString = lblText10->Caption;//"가공파라미터 명칭을 입력하세요.";
        Application->MessageBox(sMsgString.c_str(), sMsgTitle.c_str(), nMsgType);
        //ActiveControl = EdParamName;
        return;
	}
    pObj->PARA_NM = sName;

    if (!CheckParameterValue())
    {
        return;
    }

    if (MergeData(sId, sName))
    {
        pObj->FLTR_MTHD_CD             = FFMT;               //	N	VARCHAR2(7)	Y			필터링 방법 코드
        pObj->FUSN_MTHD_CD             = FFST;               //	N	VARCHAR2(7)	Y			퓨전 방법 코드
        pObj->ADJS_MTHD_CD             = FMCA;               //	N	VARCHAR2(7)	Y			보정 방법 코드
        pObj->SMTH_MTHD_CD             = FSMT;               //	N	VARCHAR2(7)	Y			평활화 방법 코드

        pObj->FLTR_MIN_TFVL            = FFMTVolMin;             //	N	NUMBER(6)	Y	0		필터링 최소 교통량
        pObj->FLTR_MAX_TFVL            = FFMTVolMax;             //	N	NUMBER(6)	Y	0		필터링 최대 교통량
        pObj->FLTR_LWST_SPED           = FFMTSpdMin;            //	N	NUMBER(3)	Y	0		필터링 최저 속도
        pObj->FLTR_HGHS_SPED           = FFMTSpdMax;            //	N	NUMBER(3)	Y	0		필터링 최고 속도
        pObj->ADJS_WGHT_AVRG_PRE_1CYCL = FMCAVal1/100.;    //	N	NUMBER(5,2)	Y	0		보정 가중치 평균 이전 1주기
        pObj->ADJS_WGHT_AVRG_PRE_2CYCL = FMCAVal2/100.;    //	N	NUMBER(5,2)	Y	0		보정 가중치 평균 이전 2주기
        pObj->ADJS_WGHT_AVRG_PRE_3CYCL = FMCAVal3/100.;    //	N	NUMBER(5,2)	Y	0		보정 가중치 평균 이전 3주기
        pObj->ADJS_15M_PTRN_APLY_YN    = F15MinPtrn;      //	N	CHAR(1)	    Y	'N'		보정 15분 패턴 적용 여부
        pObj->ADJS_SHTR_MISS_DECS_CYCL = FMissCycle;  //	N	NUMBER(2)	Y			보정 단기 결측 판단 주기
        pObj->SMTH_LWST_SPED_FCTR      = FSMTSpdMin;         //	N	NUMBER(3,2)	Y	0		평활화 최저 속도 계수
        pObj->SMTH_HGHS_SPED_FCTR      = FSMTSpdMax;         //	N	NUMBER(3,2)	Y	0		평활화 최고 속도 계수
        pObj->SMTH_WGHT_AVRG_PRST      = FSMTValC/100.;         //	N	NUMBER(5,2)	Y	0		평활화 가중치 평균 현재
        pObj->SMTH_WGHT_AVRG_PRE_1CYCL = FSMTVal1/100.;    //	N	NUMBER(5,2)	Y	0		평활화 가중치 평균 이전 1주기
        pObj->SMTH_WGHT_AVRG_PRE_2CYCL = FSMTVal2/100.;    //	N	NUMBER(5,2)	Y	0		평활화 가중치 평균 이전 2주기
        pObj->CLCTS.RemoveAll();
        try
        {
            int ii, jj;
            TcxGridDataController *pGDC0 = TvList0->DataController;
            TcxGridDataController *pGDC3 = TvList3->DataController;
            TvList0->BeginUpdate();
            TvList3->BeginUpdate();

            if (FFST == "FST1") // 우선순위
            {
                for(ii = 0; ii < pGDC0->RecordCount; ii++)
                {
                    String sPrrt = pGDC0->Values[ii][ColumnD03->Index];
                    if (sPrrt == lblNotUse->Caption) continue;

                    String sClctCd = pGDC0->Values[ii][ColumnD02->Index];
                    int    nPrrt = sPrrt.ToIntDef(1);
                    int    nWigt = 0;
                    for(jj = 0; jj < pGDC3->RecordCount; jj++)
                    {
                        if (sClctCd == VarToStr(pGDC3->Values[jj][ColumnC02->Index]))
                        {
                            nWigt = pGDC3->Values[jj][ColumnC03->Index];
                            break;
                        }
                    }
                    TPrcsParamClct* pClct = new TPrcsParamClct();
                    pClct->CLCT_SYST_CD = sClctCd;
                    pClct->FUSN_PRRT    = nPrrt;
                    pClct->FUSN_WGHT    = nWigt/100.;

                    pObj->CLCTS.Push(pClct->FUSN_PRRT, pClct);
                }
            }
            else
            if (FFST == "FST2") // 가중치
            {
                for(ii = 0; ii < pGDC3->RecordCount; ii++)
                {
                    int    nWigt   = 0;
                    nWigt = pGDC3->Values[ii][ColumnC03->Index];
                    if (nWigt == 0) continue;

                    String sClctCd = pGDC3->Values[ii][ColumnC02->Index];
                    String sPrrt   = "1";
                    int    nPrrt   = sPrrt.ToIntDef(1);
                    for(jj = 0; jj < pGDC0->RecordCount; jj++)
                    {
                        if (sClctCd == VarToStr(pGDC0->Values[jj][ColumnD02->Index]))
                        {
                            sPrrt = pGDC0->Values[jj][ColumnD03->Index];
                            if (sPrrt == lblNotUse->Caption) sPrrt = "1";
                            nPrrt = sPrrt.ToIntDef(1);
                            break;
                        }
                    }
                    TPrcsParamClct* pClct = new TPrcsParamClct();
                    pClct->CLCT_SYST_CD = sClctCd;
                    pClct->FUSN_PRRT    = nPrrt;
                    pClct->FUSN_WGHT    = nWigt/100.;

                    pObj->CLCTS.Push(pClct->FUSN_PRRT, pClct);
                }
            }
        }
        __finally
        {
            TvList0->EndUpdate();
            TvList3->EndUpdate();
        }

        RefreshData();
        CMM_SetGridRow(CxList, TvList, sId, Column10->Index);
        DisplayListData();
        ChangeButtonType(1);
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnCancelClick(TObject *Sender)
{
    ChangeButtonType(1);
    JobType = enJobNone;
    //EdParamId->Enabled = true;
    DisplayListData();
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnInsertClick(TObject *Sender)
{
    ChangeButtonType(2);
    FormClear();
    JobType = enJobSave;
    String sNewParamId;
    MyParamManager->GetNewPrcsParamId(sNewParamId);
    EdParamId->Text = sNewParamId;
    //EdParamId->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnEditClick(TObject *Sender)
{
    ChangeButtonType(2);
    JobType = enJobEdit;
    //EdParamId->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnDeleteClick(TObject *Sender)
{
    String sMsgTitle;
    String sMsgString;

    if (TvList->ViewData->RecordCount <= 0) return;
    if (TvList->DataController->FocusedRowIndex < 0) return;

    String sId = EdParamId->Text.Trim();
    TPrcsParam* pObj = MyParamManager->FLists.Find(sId);
	if (sId == "" || pObj == NULL)
    {
    	sMsgString = lblSelErr->Caption;//"가공파라미터를 선택하세요.";
        Application->MessageBox(sMsgString.c_str(), sMsgTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        //ActiveControl = EdParamId;
        return;
	}

    if (MyParamManager->IsUsing(sId))
    {
    	sMsgString = lblNoDelete->Caption;//"현재 가공파라미터는 사용중입니다.\r\n삭제 할 수 없습니다.";
        Application->MessageBox(sMsgString.c_str(), sMsgTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        //ActiveControl = EdParamId;
        return;
    }
    sMsgTitle  = lblDelete->Caption;//"가공파라미터 정보 삭제";
    sMsgString = lblDelCnfm->Caption;//"가공파라미터 정보를 삭제 하시겠습니까?" ;
    if (Application->MessageBox(sMsgString.c_str(), sMsgTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) == IDYES)
    {
        if (MyParamManager->DeleteData(pObj))
        {
            Application->MessageBox(lblDeleteOk->Caption.c_str(),//L"가공 파라미터 정보를 삭제 하였습니다.",
                                    sMsgTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
            BtnSearchClick(NULL);
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::TvListFocusedRecordChanged(TcxCustomGridTableView *Sender,
          TcxCustomGridRecord *APrevFocusedRecord, TcxCustomGridRecord *AFocusedRecord,
          bool ANewItemRecordFocusingChanged)
{
    DisplayListData();
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::ChkAutoWidthPropertiesChange(TObject *Sender)
{
    try
    {
        TvList->BeginUpdate();
		TvList->OptionsView->ColumnAutoWidth = ChkAutoWidth->Checked;
        BtnBestFit->Visible = !ChkAutoWidth->Checked;
	}
	__finally
	{
        TvList->EndUpdate();
	}
}
//---------------------------------------------------------------------------

void __fastcall TIDB0051M::BtnBestFitClick(TObject *Sender)
{
    try
    {
        TvList->BeginUpdate();
		TvList->ApplyBestFit(NULL, false, false);
	}
	__finally
	{
        TvList->EndUpdate();
	}
}
//---------------------------------------------------------------------------

