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

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

#include "IDB00301F.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "FRAME_NodeListF"
#pragma link "cxButtons"
#pragma link "cxContainer"
#pragma link "cxControls"
#pragma link "cxEdit"
#pragma link "cxGraphics"
#pragma link "cxGroupBox"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxTextEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma resource "*.dfm"

TIDB00301 *IDB00301 = NULL;
//---------------------------------------------------------------------------
__fastcall TIDB00301::TIDB00301(TComponent* Owner)
    : TForm(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load(this);
    //CMM_LoadForm(g_sFormsDir, this);

    FUpdated = false;
}
//---------------------------------------------------------------------------

void __fastcall TIDB00301::CommClose()
{
    try
    {
        //CMM_SaveForm(g_sFormsDir, this);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------

void __fastcall TIDB00301::FormShow(TObject *Sender)
{
    Refresh();
}
//---------------------------------------------------------------------------

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

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

void __fastcall TIDB00301::BtnSaveClick(TObject *Sender)
{
    if (Application->MessageBox(FrmLang->lblChangeInfo->Caption.c_str(), //L"정보를 수정 하시겠습니까?",
                                Caption.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;

    TADOQuery *pADO = NULL;
	String sQry;

    String sId = EdId->Text.Trim();
    String sNm = EdNm->Text.Trim();
    String sStNm = EdStNm->Text.Trim();
    String sEdNm = EdEdNm->Text.Trim();
    try
    {
        try
        {
            pADO = new TADOQuery(NULL);
			pADO->Close();
            pADO->Connection = ITSDb_GetConnection();

            ITSDb_GetConnection()->BeginTrans();
            // 세부코드 삭제
        	sQry = "UPDATE TB_IFSC         \r\n"
                   "   SET IFSC_NM = :p02, \r\n"
                   "       STRT_NM = :p03, \r\n"
                   "       END_NM  = :p04  \r\n"
                   " WHERE IFSC_ID = :p01  \r\n";

            ITSDb_SQLText(pADO, sQry);
            ITSDb_SQLBind(pADO, "p01", sId);
            ITSDb_SQLBind(pADO, "p02", sNm);
            ITSDb_SQLBind(pADO, "p03", sStNm);
            ITSDb_SQLBind(pADO, "p04", sEdNm);
            ITSDb_SQLExec(pADO);

            ITSDb_GetConnection()->CommitTrans();

            FUpdated = true;

            Application->MessageBox(FrmLang->lblChangeOk->Caption.c_str(),//L"정보를 수정 하였습니다.",
                                    Caption.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;
        }
    }
}
//---------------------------------------------------------------------------

