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

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

#include "VMSM800MF_OLD.h"
#include "VMSSEL0MF.h"
#include "VMSEDT0MF.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "cxButtons"
#pragma link "cxCalendar"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxDropDownEdit"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#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 "cxTextEdit"
#pragma link "cxTimeEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSilver"
#pragma link "dxSkinStardust"
#pragma link "cxRadioGroup"
#pragma link "cxClasses"
#pragma link "cxCustomData"
#pragma link "cxData"
#pragma link "cxDataStorage"
#pragma link "cxDBData"
#pragma link "cxFilter"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridDBTableView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxStyles"
#pragma link "cxCheckBox"
#pragma link "cxImage"
#pragma link "cxButtonEdit"
#pragma link "cxBlobEdit"
#pragma link "cxColorComboBox"
#pragma link "cxCalc"
#pragma link "VmsDesignerF"
#pragma link "FRAME_VmsSchListF"
#pragma resource "*.dfm"

TVMSM800M_OLD *VMSM800M_OLD = NULL;
//---------------------------------------------------------------------------

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

    FUpdate= false;
    FTitle = Caption;//"VMS 기본 스케줄 관리";

	FListSymb = new TList;

    EditMode = false;

    APP_InitDisplayColor();

    PgVmsSch->Properties->ActivePage = TabFixed;
    PgVmsSch->Properties->HideTabs = true;

    LblInfo1->Height = 25;

    FRAMEVmsSchList1->PnlTop->Visible = false;
    FRAMEVmsSchList1->PnlBottom->Visible = false;
    FRAMEVmsSchList1->ColAuto->Visible = false;
    FRAMEVmsSchList1->ColFix->Visible  = false;
    FRAMEVmsSchList1->ColBase->Visible = true;

    FVmsHeight = 64;

    FListSch[0] = NULL;
    FListSch[1] = NULL;
    FListSch[2] = NULL;
    FListSch[3] = NULL;
    FListSch[4] = NULL;
    FListSch[5] = NULL;
    FListSch[6] = TvGrid6;
    FListSch[7] = NULL;

    FListFrm[0] = NULL;
    FListFrm[1] = NULL;
    FListFrm[2] = NULL;
    FListFrm[3] = NULL;
    FListFrm[4] = NULL;
    FListFrm[5] = NULL;
    FListFrm[6] = TvForm6;
    FListFrm[7] = NULL;

    for (int ii = 0; ii < MAX_FORM_SCHED; ii++)
    {
        if (FListSch[ii]) InitTcxList(FListSch[ii]);
        if (FListFrm[ii]) InitTcxList(FListFrm[ii]);
    }

    //BtnSave->Caption = "Save Schedule";
    //BtnSave->Hint = "Save scheduled tasks for the currently selected VMS";
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::InitTcxList(TcxGridTableView *AView)
{
    AView->OptionsView->DataRowHeight  = 0;
    AView->OptionsView->CellAutoHeight = true;
    AView->OptionsView->Indicator      = false;

    AView->OptionsCustomize->ColumnMoving  = false;
    AView->OptionsCustomize->ColumnSorting = false;

    AView->Columns[0]->Width = 40;
    AView->Columns[0]->Options->HorzSizing = false;

    AView->Columns[1]->Width = 330;
}
//---------------------------------------------------------------------------

/*
 * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
 * Form과 DataModule class를 delete시킨다.
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TVMSM800M_OLD::CommClose()
{
    try
    {
        APP_DelVmsSizeCombo(CbSizeType);

        ClearSymbloList();
        SAFE_DELETE(FListSymb);
        CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::FormCreate(TObject *Sender)
{
    //
}
//---------------------------------------------------------------------------

/*
 * Form을 보여줄때 호출되는 event 메서드이다.
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TVMSM800M_OLD::FormShow(TObject *Sender)
{
    Refresh();
    FormInit();
    ChangeEditMode(1);
    TmrShow->Enabled = true;
}
//---------------------------------------------------------------------------

/*
 * form 초기화
 *
 *  arguments
 *
 *  return
 *      void
 */
void __fastcall TVMSM800M_OLD::FormInit()
{
    for (int ii = 0; ii < MAX_FORM_SCHED; ii++)
    {
        if (FListSch[ii]) FListSch[ii]->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoSchedule->Caption;//"<등록되어 있는 스케줄 정보가 없습니다>";
        if (FListFrm[ii]) FListFrm[ii]->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoForm->Caption;//"<등록되어 있는 폼 정보가 없습니다>";
    }

    //VMS사이즈
    APP_FillVmsSizeType(CbSizeType, false);

    VmsManager->LoadVmsFormUsage();
    FRAMEVmsSchList1->RefreshVmsFormUsage();

    FNewDb = false;
}
//---------------------------------------------------------------------------

/*
 * Form이 Show되고 난 후 최초 1회 수행되는 타이머 이벤트
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TVMSM800M_OLD::TmrShowTimer(TObject *Sender)
{
    TmrShow->Enabled = false;
}
//---------------------------------------------------------------------------

/*
 * Close 버튼 클릭 이벤트 핸들러
 *  arguments
 *      Sender : event handler 객체
 *  return
 *      void
 */
void __fastcall TVMSM800M_OLD::BtnCloseClick(TObject *Sender)
{
    Close();
}
//---------------------------------------------------------------------------

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

void __fastcall TVMSM800M_OLD::FormCloseQuery(TObject *Sender, bool &CanClose)
{
    if (FUpdate)
    {
        POST_MSG(Application->MainForm->Handle, WM_DATABASE_REFRESH, WP_MSG_14, 0);
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::ChangeEditMode(int AEdit)
{
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::ClearSymbloList()
{
	for(int ii = 0; ii < FListSymb->Count; ii++)
	{
		Graphics::TBitmap *bitmap = (Graphics::TBitmap *)FListSymb->Items[ii];
		delete bitmap;
	}
	FListSymb->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::FRAMEVmsSchList1TvListCellDblClick(TcxCustomGridTableView *Sender,
          TcxGridTableDataCellViewInfo *ACellViewInfo, TMouseButton AButton,
          TShiftState AShift, bool &AHandled)
{
	if (!ACellViewInfo) return;
    DisplayInfo();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::FRAMEVmsSchList1TvListFocusedRecordChanged(TcxCustomGridTableView *Sender,
          TcxCustomGridRecord *APrevFocusedRecord, TcxCustomGridRecord *AFocusedRecord,
          bool ANewItemRecordFocusingChanged)
{
    if (!AFocusedRecord) return;
    DisplayInfo();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::CbSizeTypePropertiesChange(TObject *Sender)
{
    BtnSearchClick(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::BtnSearchClick(TObject *Sender)
{
    RefreshData();

    EdFocus->SetFocus();
    ChangeEditMode(1);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::RefreshData()
{
    FormClear();

    TVmsSizeType *pVmsSizeType = APP_GetVmsSizeTypeObject(CbSizeType);
    if (pVmsSizeType == NULL) return;

    FVmsTypeCd = pVmsSizeType->TypeCd;
    FVmsWidth  = pVmsSizeType->Width;
    FVmsHeight = pVmsSizeType->Height;

    FRAMEVmsSchList1->UpdateList(FVmsTypeCd);

    LoadVmsFormList(FVmsTypeCd);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::FormClear()
{
    FSelIdx = -1;

    EdVmsNmbr->Clear();

    for (int ii = 0; ii < MAX_FORM_SCHED; ii++)
    {
        if (FListSch[ii]) CMM_ClearGridTableView(FListSch[ii]);
    }

    GrpSchedule->Caption = lblTitle->Caption;//"▶ 기본 스케줄 설정";

    FNewDb = false;
}
//---------------------------------------------------------------------------
void __fastcall TVMSM800M_OLD::DisplayInfo()
{
    FormClear();

    FSelIdx = CMM_GetRecordIndex(FRAMEVmsSchList1->TvList);
	if (FSelIdx < 0) return;

    TcxDataController *pGDC = FRAMEVmsSchList1->TvList->DataController;

    String sVmsNmbr = VarToStr(pGDC->Values[FSelIdx][FRAMEVmsSchList1->Column01->Index]);
    EdVmsNmbr->Text = sVmsNmbr;

    GrpSchedule->Caption = lblTitle->Caption + " (" + VarToStr(pGDC->Values[FSelIdx][FRAMEVmsSchList1->Column02->Index]) + ": " + VarToStr(pGDC->Values[FSelIdx][FRAMEVmsSchList1->Column03->Index]) + ")";

    LoadVmsScheduleInfo(sVmsNmbr);

    ChangeEditMode(3);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::TvFormCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift,
          bool &AHandled)
{
	if (!ACellViewInfo) return;

	int nRow = Sender->DataController->FocusedRecordIndex;
	if( nRow <= -1 )
		return;

    TcxButton *pBtn = NULL;
    switch(Sender->Tag)
    {
    //case enFormBase:  pBtn = BtnListAdd6; break;
    default: return;
    }
    BtnListAddClick((TObject*)pBtn);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::BtnListAddClick(TObject *Sender)
{
    String sUse = "Y";
    String sTime= "4";

    TcxButton *pBtn = (TcxButton*)Sender;
    int nTag = pBtn->Tag;
    if (nTag < 0 || nTag >= MAX_FORM_SCHED) return;

    int nSelIdx = CMM_GetRecordIndex(FRAMEVmsSchList1->TvList);
	if (nSelIdx < 0) return;

    if (!FListFrm[nTag] || !FListSch[nTag]) return;

    TcxGridDataController *pDcFrm = FListFrm[nTag]->DataController;
    TcxGridDataController *pDcSch = FListSch[nTag]->DataController;

    int nFormIdx = CMM_GetRecordIndex(FListFrm[nTag]);
    if (nFormIdx < 0) return;

    if (nTag == enFormTraffic)
    {
        sUse = "N";
    }

    String sStrDate = "";
    String sEndDate = "";
    bool   bSelected= false;

    TVMSSEL0M *pSelDate = new TVMSSEL0M(this);

    pSelDate->ShowModal();
    bSelected = pSelDate->FSelected;
    sStrDate  = pSelDate->FStrTime;
    sEndDate  = pSelDate->FEndTime;
    delete pSelDate;
    pSelDate = NULL;

    if (!bSelected) return;

    int nRow = pDcSch->AppendRecord();

    pDcSch->Values[nRow][0] = pDcFrm->Values[nFormIdx][0];
    pDcSch->Values[nRow][1] = pDcFrm->Values[nFormIdx][1];
    pDcSch->Values[nRow][3] = sTime;
    pDcSch->Values[nRow][4] = ITSUtil_FormatStr(sStrDate, STR_HHNN);;
    pDcSch->Values[nRow][5] = ITSUtil_FormatStr(sEndDate, STR_HHNN);;
    pDcSch->Values[nRow][6] = sUse;
    pDcSch->Values[nRow][7] = sStrDate;
    pDcSch->Values[nRow][8] = sEndDate;
    pDcSch->Values[nRow][15] = pDcFrm->Values[nFormIdx][2];
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::BtnListDeleteClick(TObject *Sender)
{
    TcxButton *pBtn = (TcxButton*)Sender;
    int nTag = pBtn->Tag;
    if (nTag >= MAX_FORM_SCHED) return;

    int nSelIdx = CMM_GetRecordIndex(FRAMEVmsSchList1->TvList);
	if (nSelIdx < 0) return;

    if (!FListSch[nTag]) return;

    TcxGridDataController *pDcSch = FListSch[nTag]->DataController;

    nSelIdx = CMM_GetRecordIndex(FListSch[nTag]);
    if (nSelIdx < 0) return;

	FListSch[nTag]->DataController->DeleteRecord(nSelIdx);
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::TvGridCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo,
          TMouseButton AButton, TShiftState AShift,
          bool &AHandled)
{
	if (!ACellViewInfo) return;

	int nRow = Sender->DataController->FocusedRecordIndex;
	if( nRow <= -1 )
		return;

    TcxGridDataController *pGDC = (TcxGridDataController*)Sender->DataController;

    int nColIdx = ACellViewInfo->Item->Index;
    //ShowMessage(String(Sender->Tag) + "    " + String(nColIdx));

    String sFormId  = VarToStr(pGDC->Values[nRow][0]);
    String sStrDate = VarToStr(pGDC->Values[nRow][7]);
    String sEndDate = VarToStr(pGDC->Values[nRow][8]);
    if (nColIdx == 4 || nColIdx == 5)
    {
        //표출기간설정
        TVMSSEL0M *pSelDate = new TVMSSEL0M(this);
        pSelDate->FStrTime = sStrDate;
        pSelDate->FEndTime = sEndDate;

        pSelDate->ShowModal();
        bool bSelected = pSelDate->FSelected;
        sStrDate  = pSelDate->FStrTime;
        sEndDate  = pSelDate->FEndTime;
        delete pSelDate;
        pSelDate = NULL;

        if (bSelected)
        {
            pGDC->Values[nRow][4] = ITSUtil_FormatStr(sStrDate, STR_HHNN);;
            pGDC->Values[nRow][5] = ITSUtil_FormatStr(sEndDate, STR_HHNN);;
            pGDC->Values[nRow][7] = sStrDate;
            pGDC->Values[nRow][8] = sEndDate;
        }
        return;
    }

    if (Sender->Tag != enFormTraffic) return;

    if (VarToStr(pGDC->Values[nRow][15]).ToIntDef(0) == 15)
    {
        //도형식배경 소통정보 폼
        Application->MessageBox(FrmLang->lblSchErr1->Caption.c_str(),//L"VMS 교통정보 폼 구간 설정\r\n도형식 배경소통정보 폼은 폼관리 화면에서 설정 가능합니다.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::BtnAllEditClick(TObject *Sender)
{
    TcxButton *pBtn = (TcxButton*)Sender;

    //등록되어 있는 스케줄 폼을 전체 VMS에 편집하는 기능
    int nTag = PgVmsSch->Properties->ActivePage->Tag;
    if (nTag < 0 || nTag >= MAX_FORM_SCHED)
    {
        Application->MessageBox(FrmLang->lblRegErr1->Caption.c_str(),//L"VMS 스케줄 일괄 관리\r\n알수 없는 스케줄 유형입니다.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }

    if (!FListSch[nTag]) return;

    TcxGridTableView      *pTvList = FListSch[nTag];
    TcxGridDataController *pGDC;
    String sMode = "E";

    if (pBtn->Tag == 1)
    {
        sMode = "A";    //추가
        pTvList = FListFrm[nTag];
    }
    if (!pTvList) return;

    pGDC = pTvList->DataController;

    int nFormIdx = CMM_GetRecordIndex(pTvList);
    if (nFormIdx < 0)
    {
        Application->MessageBox(FrmLang->lblRegErr2->Caption.c_str(),//L"VMS 스케줄 일괄 관리\r\n등록되어 있는 스케줄 폼을 목록에서 먼저 선택하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }

    String sFormId = pGDC->Values[nFormIdx][0];

    TVmsSizeType *pVmsSizeType = APP_GetVmsSizeTypeObject(CbSizeType);
    if (pVmsSizeType == NULL)
    {
        Application->MessageBox(FrmLang->lblRegErr3->Caption.c_str(),//L"VMS 스케줄 일괄 관리\r\nVMS 유형을 알수 없습니다. VMS 크기 유형을 먼저 선택하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
        return;
    }
    String sVmsType = pVmsSizeType->TypeCd;

    TVMSEDT0M *pFrmEdt = new TVMSEDT0M(this);

    pFrmEdt->FVmsTypeCd = sVmsType;
    pFrmEdt->FScheType  = String(nTag);
    pFrmEdt->FFormId    = sFormId;
    pFrmEdt->FMode      = sMode;
    pFrmEdt->FVmsNmbr   = "";
    pFrmEdt->ShowModal();

    bool bOk = pFrmEdt->FSelected;

    delete pFrmEdt;
    pFrmEdt = NULL;

    if (bOk)
    {
        DisplayInfo();
    }
    VmsManager->LoadVmsFormUsage();
    FRAMEVmsSchList1->RefreshVmsFormUsage();
}
//---------------------------------------------------------------------------

void __fastcall TVMSM800M_OLD::BtnSaveClick(TObject *Sender)
{
    //작업한 스케줄 정보를 저장한다.
	if (EdVmsNmbr->Text.Trim().IsEmpty())
	{
        Application->MessageBox(lblErr2->Caption.c_str(),//L"VMS 기본 스케줄 관리\r\nVMS 목록에서 VMS를 먼저 선택한 후 작업을 진행하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
	}

    bool bUpdate = true;
    String sVmsNmbr = EdVmsNmbr->Text.Trim();

    if (bUpdate)
    {
        String sMsg;
        sMsg = "VMS: " + sVmsNmbr;
        sMsg+= "\r\n" + lblErr3->Caption;//선택한 VMS의 기본 스케줄 정보를 저장하시겠습니까?";

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

    try
    {
        ITSDb_GetConnection()->BeginTrans();

        DeleteVmsFixedScenario(sVmsNmbr);
        for (int ii = 0; ii < MAX_FORM_SCHED; ii++)
        {
            if (FListSch[ii]) SaveVmsFixedScenario(sVmsNmbr, FListSch[ii]);
        }
    }
    __finally
    {
        ITSDb_GetConnection()->CommitTrans();
    }

    Application->MessageBox(lblErr2->Caption.c_str(),//L"VMS 기본 스케줄 관리\r\nVMS 기본 스케줄 정보를 저장 하였습니다.",
                            FTitle.c_str(), MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);

    VmsManager->LoadVmsFormUsage();
    FRAMEVmsSchList1->RefreshVmsFormUsage();

    CMM_SetGridRow(FRAMEVmsSchList1->CxList, FRAMEVmsSchList1->TvList, sVmsNmbr, FRAMEVmsSchList1->Column01->Index);
    DisplayInfo();
}
//---------------------------------------------------------------------------

bool __fastcall TVMSM800M_OLD::SaveVmsFixedScenario(String AVmsNmbr, TcxGridTableView *AListSch)
{
    bool       bResult = false;
    String     sQry;
    TADOQuery *pADO = NULL;

    TcxDataController *pGDC = AListSch->DataController;

    String sTypeCd = String(AListSch->Tag);

    sQry = "INSERT INTO TB_VMS_DSPL_SCH (                     \r\n"
           "                              VMS_CTLR_NMBR,      \r\n"
           "                              TRFC_SITU_TYPE_CD,  \r\n"
           "                              PHASE,              \r\n"
           "                              VMS_FORM_ID,        \r\n"
           "                              VMS_FORM_PRRT_CD,   \r\n"
           "                              DSPL_HH,            \r\n"
           "                              DSPL_STRT_HH,       \r\n"
           "                              DSPL_END_HH,        \r\n"
           "                              FRST_VMS_IFSC_ID,   \r\n"
           "                              SECD_VMS_IFSC_ID,   \r\n"
           "                              THIR_VMS_IFSC_ID,   \r\n"
           "                              FOUR_VMS_IFSC_ID,   \r\n"
           "                              USE_YN              \r\n"
           "                             )                    \r\n"
           "                      VALUES(                     \r\n"
           "                             :p01, :p02, :p03,    \r\n"
           "                             :p04, :p05, :p06,    \r\n"
           "                             :p07, :p08, :p09,    \r\n"
           "                             :p10, :p11, :p12,    \r\n"
           "                             :p13                 \r\n"
           "                             )                    \r\n";

    try
    {
        AListSch->BeginUpdate();
        pGDC->BeginUpdate();
        int nRows = pGDC->RecordCount;

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

            ITSDb_SQLText(pADO, sQry);

            for (int ii = 0; ii < nRows; ii++)
            {
                String sFormId  = VarToStr(pGDC->Values[ii][0]);
                String sDispHH  = VarToStr(pGDC->Values[ii][3]);
                String sUseYn   = VarToStr(pGDC->Values[ii][6]);
                String sStrTime = VarToStr(pGDC->Values[ii][7]);
                String sEndTime = VarToStr(pGDC->Values[ii][8]);
                String sIfscId1 = VarToStr(pGDC->Values[ii][ 9]);
                String sIfscId2 = VarToStr(pGDC->Values[ii][10]);
                String sIfscId3 = VarToStr(pGDC->Values[ii][11]);
                String sIfscId4 = VarToStr(pGDC->Values[ii][12]);
                String sPrrtCd  = "";

                ITSDb_SQLBind(pADO, "p01", AVmsNmbr);
                ITSDb_SQLBind(pADO, "p02", sTypeCd);
                ITSDb_SQLBind(pADO, "p03", String(ii+1));

                ITSDb_SQLBind(pADO, "p04", sFormId);
                ITSDb_SQLBind(pADO, "p05", sPrrtCd);
                ITSDb_SQLBind(pADO, "p06", sDispHH);

                ITSDb_SQLBind(pADO, "p07", sStrTime);
                ITSDb_SQLBind(pADO, "p08", sEndTime);

                ITSDb_SQLBind(pADO, "p09", sIfscId1);
                ITSDb_SQLBind(pADO, "p10", sIfscId2);
                ITSDb_SQLBind(pADO, "p11", sIfscId3);
                ITSDb_SQLBind(pADO, "p12", sIfscId4);

                ITSDb_SQLBind(pADO, "p13", sUseYn);

                pADO->ExecSQL();
            }

            bResult = true;
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            DBERRORMSG("VMS Default Schedule Save", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            DBERRORMSG("VMS Default Schedule Save", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
        pGDC->EndUpdate();
        AListSch->EndUpdate();
    }
    return bResult;
}
//---------------------------------------------------------------------------

bool __fastcall TVMSM800M_OLD::DeleteVmsFixedScenario(String AVmsNmbr)
{
    bool       bResult = false;
    String     sQry;
    TADOQuery *pADO = NULL;

    sQry = "DELETE TB_VMS_DSPL_SCH            \r\n"
           " WHERE VMS_CTLR_NMBR = :p01       \r\n"
           "   AND TRFC_SITU_TYPE_CD IN ('6') \r\n";

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

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", AVmsNmbr);
			pADO->ExecSQL();

            bResult = true;
        }
        catch(EDatabaseError &E)
        {
            ITSDb_GetConnection()->RollbackTrans();
            DBERRORMSG("VMS Default Schedule Delete", String(E.ClassName()), E.Message, sQry);
            throw Exception(String(E.ClassName()) + E.Message);
        }
        catch(Exception &e)
        {
            ITSDb_GetConnection()->RollbackTrans();
            DBERRORMSG("VMS Default Schedule Delete", String(e.ClassName()), e.Message, sQry);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADO)
        {
            pADO->Close();
            delete pADO;
        }
    }
    return bResult;
}
//---------------------------------------------------------------------------


