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

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

#include "IFM0020MF.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 "cxEdit"
#pragma link "cxFilter"
#pragma link "cxGraphics"
#pragma link "cxGrid"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma link "cxLabel"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "cxStyles"
#pragma link "cxTextEdit"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinsCore"
#pragma link "dxSkinscxPCPainter"
#pragma resource "*.dfm"

TIFM0020M *IFM0020M = NULL;
extern LOGININFO *g_pLOGIN;

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

    FTitle = Caption;//"시설물 업체관리";
    MyItsCompanyManager = new TItsCompanyManager();
}
//---------------------------------------------------------------------------

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

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

void __fastcall TIFM0020M::FormInit()
{
    m_pGDC = TvList->DataController;

    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<등록되어 있는 시설물업체 정보가 없습니다>";
}
//---------------------------------------------------------------------------

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

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

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

void __fastcall TIFM0020M::RefreshData()
{
    FUpdate = false;
    MyItsCompanyManager->LoadFromDb();
    SelListData();
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::SelListData()
{
    CMM_ClearGridTableView(TvList);

    try
    {
        TvList->BeginUpdate();

        FOR_STL(TItsCompany*, pObj, MyItsCompanyManager->FLists)
        {
            pObj->EditMode = DB_INIT;   //미리 초기화시켜야함
            pObj->Completed = true;

            if (pObj->DEL_YN == "Y") continue;

            AddObjectItem(pObj, "-");
        }
    }
    __finally
    {
        LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
        //CxList->SetFocus();
    }
}
//---------------------------------------------------------------------------

bool __fastcall TIFM0020M::AddObjectItem(TItsCompany *pObj, String AMode)
{
    int       nRow;

    try
    {
        nRow = m_pGDC->AppendRecord();
        pObj->FGridIndex = nRow;

        m_pGDC->Values[nRow][Column00->Index] = AMode;

        m_pGDC->Values[nRow][Column01->Index] = pObj->CMPY_ID;      //업체ID
        m_pGDC->Values[nRow][Column02->Index] = pObj->CMPY_NM;      //업체 명
        m_pGDC->Values[nRow][Column03->Index] = pObj->BRNO;         //사업자 등록 번호
        m_pGDC->Values[nRow][Column04->Index] = pObj->ADDR;         //주소
        m_pGDC->Values[nRow][Column05->Index] = pObj->TEL;          //전화번호
        m_pGDC->Values[nRow][Column06->Index] = pObj->FCSM_NMBR;    //팩스 번호
        m_pGDC->Values[nRow][Column07->Index] = pObj->RPRV_NM;      //대표자 명
        m_pGDC->Values[nRow][Column08->Index] = pObj->CHGR_NM;      //담당자 명
        m_pGDC->Values[nRow][Column09->Index] = pObj->CHGR_HP_NMBR; //담당자 연락처
        m_pGDC->Values[nRow][Column10->Index] = pObj->CHGR_EMAL;    //담당자 이메일
        //m_pGDC->Values[nRow][Column11->Index] = pObj->ADTN_NM;      //추가자 명
        //m_pGDC->Values[nRow][Column12->Index] = pObj->ADTN_DT;      //추가 일시
        //m_pGDC->Values[nRow][Column13->Index] = pObj->CHNG_NM;      //변경자 명
        //m_pGDC->Values[nRow][Column14->Index] = pObj->CHNG_DT;      //변경 일시
        m_pGDC->Values[nRow][Column88->Index] = pObj->DEL_YN;       //삭제 여부

        m_pGDC->Values[nRow][Column99->Index] = (int)pObj;

        return true;
    }
    catch(...)
    {
    }
    return false;
}
//---------------------------------------------------------------------------

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

void __fastcall TIFM0020M::BtnExlSaveClick(TObject *Sender)
{
    TcxGrid          *pGrid = CxList;
    TcxGridTableView *pView = TvList;
    String            sTitle= Caption;//"시설물관리업체정보";

    CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::BtnInsertClick(TObject *Sender)
{
    int nMsgType = MB_OK|MB_ICONERROR|MB_APPLMODAL;

	String sId = InputBox(lblInput->Caption,//"업체 ID",
                          lblInQry->Caption,//"신규 업체 ID를 입력하세요.",
                          lblInput->Caption);//"업체 ID" );

    sId = sId.Trim();
	if (sId == lblInput->Caption //"업체 ID"
     || sId == "")
	{
		return;
	}
	if (AnsiString(sId).Length() > 30)
	{
        Application->MessageBox(lblDigitErr->Caption.c_str(),//L"업체 ID는  30Byte를 초과할 수 없습니다.",
                                FTitle.c_str(), nMsgType);
		return;
	}

    TItsCompany *pDb = (TItsCompany *)MyItsCompanyManager->FLists.Find(sId);
    if (pDb)
    {
        String sErr = FrmLang->lbIdErr->Caption + "[" + sId + "]";
        Application->MessageBox(sErr.c_str(),//("[" + sId + "]는 사용할 수 없는 업체 ID 입니다.").c_str(),
                                FTitle.c_str(), nMsgType);
		return;
    }

    try
    {
        TvList->BeginUpdate();

        TItsCompany *pObj = new TItsCompany();
        pObj->Clear();

        pObj->CMPY_ID = sId;                                    //업체ID
        pObj->ADTN_NM = g_pLOGIN->sUserId;                      //추가자 명
        pObj->ADTN_DT = Now().FormatString("yyyymmddhhnnss");   //추가 일시
        pObj->CHNG_NM = g_pLOGIN->sUserId;                      //변경자 명
        pObj->CHNG_DT = Now().FormatString("yyyymmddhhnnss");   //변경 일시
        pObj->DEL_YN  = "N";                                    //삭제 여부

        MyItsCompanyManager->FLists.Push(pObj->CMPY_ID, pObj);
        pObj->Completed = false;

        AddObjectItem(pObj, FrmLang->lblNew->Caption);//"신규");

        pObj->EditMode = DB_NEW;
    }
    __finally
    {
        LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
#if 0
        CxList->SetFocus();
        TvList->Controller->ClearSelection();
        TvList->Controller->FocusedRowIndex = m_pGDC->GetRowIndexByRecordIndex(nRow, true);
#endif
    }
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::BtnDeleteClick(TObject *Sender)
{
    int nIdx = m_pGDC->FocusedRecordIndex;
    if (nIdx < 0) return;
    m_pGDC->Values[nIdx][Column00->Index] = FrmLang->lblDelete->Caption;//"삭제";
    int nMemPtr = m_pGDC->Values[nIdx][Column99->Index];
    TItsCompany *pObj = (TItsCompany*)nMemPtr;
    pObj->EditMode = DB_DELETE;
}
//---------------------------------------------------------------------------

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

void __fastcall TIFM0020M::BtnEditClick(TObject *Sender)
{
    TListFocus tvFocus(TvList);

    if (BtnEdit->Caption == FrmLang->lblCancel->Caption)//"취소")
    {
        CxList->SetFocus();
        Application->ProcessMessages();
        SaveData();
    }

    FrmLang->ITSSkin_ButtonClick(BtnSearch, BtnEdit, BtnInsert, BtnDelete, BtnApply);
    ChangeEditMode(BtnEdit->Down);

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

void __fastcall TIFM0020M::ChangeEditMode(bool AEdit)
{
    bool bEditing = AEdit;

    try 
    {
        TvList->BeginUpdate();
        
        Column00->Visible = bEditing;
    
        Column02->Options->Editing = bEditing;
        Column03->Options->Editing = bEditing;
        Column04->Options->Editing = bEditing;
        Column05->Options->Editing = bEditing;
        Column06->Options->Editing = bEditing;
        Column07->Options->Editing = bEditing;
        Column08->Options->Editing = bEditing;
        Column09->Options->Editing = bEditing;
        Column10->Options->Editing = bEditing;
        //Column11->Options->Editing = bEditing;
        //Column12->Options->Editing = bEditing;
        //Column13->Options->Editing = bEditing;
        //Column14->Options->Editing = bEditing;
    }
    __finally 
    {
        TvList->EndUpdate();
        if (bEditing)
        {
            BtnEdit->Caption = FrmLang->lblCancel->Caption;//"취소";
            BtnEdit->Hint    = FrmLang->lblCancel->Hint;//데이터 편집 취소";
        }
        else
        {
            BtnEdit->Caption = FrmLang->lblEdit->Caption;//"편집";
            BtnEdit->Hint    = FrmLang->lblEdit->Hint;//데이터 편집";
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::TvListColumnPropertiesValidate(TObject *Sender, Variant &DisplayValue, TCaption &ErrorText, bool &Error)
{
    if (TvList->Controller->FocusedRow->IsFilterRow) return;

    int nRow = m_pGDC->FocusedRecordIndex;
    if (nRow < 0) return;

    int nMemPtr = TvList->DataController->Values[nRow][Column99->Index];
    TItsCompany *pObj = (TItsCompany*)nMemPtr;
    if (pObj->Completed == false)
    {
        //신규이거나 삭제인 경우 편집 내용에 따른 변화가 필요없다.
        return;
    }

    String sCMPY_NM      = VarToStr(m_pGDC->Values[nRow][Column02->Index]);   //업체 명
    String sBRNO         = VarToStr(m_pGDC->Values[nRow][Column03->Index]);   //사업자 등록 번호
    String sADDR         = VarToStr(m_pGDC->Values[nRow][Column04->Index]);   //주소
    String sTEL          = VarToStr(m_pGDC->Values[nRow][Column05->Index]);   //전화번호
    String sFCSM_NMBR    = VarToStr(m_pGDC->Values[nRow][Column06->Index]);   //팩스 번호
    String sRPRV_NM      = VarToStr(m_pGDC->Values[nRow][Column07->Index]);   //대표자 명
    String sCHGR_NM      = VarToStr(m_pGDC->Values[nRow][Column08->Index]);   //담당자 명
    String sCHGR_HP_NMBR = VarToStr(m_pGDC->Values[nRow][Column09->Index]);   //담당자 연락처
    String sCHGR_EMAL    = VarToStr(m_pGDC->Values[nRow][Column10->Index]);   //담당자 이메일

    TcxGridColumn *pColumn = TvList->Controller->FocusedColumn;
    if      (pColumn == Column02) sCMPY_NM      = DisplayValue;
    else if (pColumn == Column03) sBRNO         = DisplayValue;
    else if (pColumn == Column04) sADDR         = DisplayValue;
    else if (pColumn == Column05) sTEL          = DisplayValue;
    else if (pColumn == Column06) sFCSM_NMBR    = DisplayValue;
    else if (pColumn == Column07) sRPRV_NM      = DisplayValue;
    else if (pColumn == Column08) sCHGR_NM      = DisplayValue;
    else if (pColumn == Column09) sCHGR_HP_NMBR = DisplayValue;
    else if (pColumn == Column10) sCHGR_EMAL    = DisplayValue;

    if (sCMPY_NM      != pObj->CMPY_NM      ||  //업체 명
        sBRNO         != pObj->BRNO         ||  //사업자 등록 번호
        sADDR         != pObj->ADDR         ||  //주소
        sTEL          != pObj->TEL          ||  //전화번호
        sFCSM_NMBR    != pObj->FCSM_NMBR    ||  //팩스 번호
        sRPRV_NM      != pObj->RPRV_NM      ||  //대표자 명
        sCHGR_NM      != pObj->CHGR_NM      ||  //담당자 명
        sCHGR_HP_NMBR != pObj->CHGR_HP_NMBR ||  //담당자 연락처
        sCHGR_EMAL    != pObj->CHGR_EMAL )      //담당자 이메일
    {
        m_pGDC->Values[nRow][Column00->Index] = FrmLang->lblModify->Caption;//"수정";
        pObj->EditMode = DB_UPDATE;
    }
    else
    {
        m_pGDC->Values[nRow][Column00->Index] = "-";
        pObj->EditMode = DB_INIT;
    }
}
//---------------------------------------------------------------------------

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

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

void __fastcall TIFM0020M::BtnApplyClick(TObject *Sender)
{
    FUpdate = true;
    BtnEdit->Down = false;
    BtnEdit->Click();
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::TvListCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
          bool &ADone)
{
    if (AViewInfo)
    {
        String sType = AViewInfo->GridRecord->DisplayTexts[Column00->Index];
        if (sType == FrmLang->lblModify->Caption)//"수정")
        {
            ACanvas->Brush->Color = clOlive;
        }
        else if (sType == FrmLang->lblDelete->Caption)//"삭제")
        {
            ACanvas->Brush->Color = clRed;
        }
        else if (sType == FrmLang->lblNew->Caption)//"신규")
        {
            ACanvas->Brush->Color = clLime;
            if (AViewInfo->Focused) ACanvas->Font->Color = clBlack;
        }
    }
}
//---------------------------------------------------------------------------

bool __fastcall TIFM0020M::IsUpdate()
{
    FOR_STL(TItsCompany*, pObj, MyItsCompanyManager->FLists)
    {
        if (pObj->Completed && pObj->EditMode != DB_INIT)
            return true;

        if (!pObj->Completed && pObj->EditMode == DB_NEW)
            return true;
    }
    return false;
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::SaveData()
{
    if (!IsUpdate()) return;

    if (!FUpdate)
    {
        if (Application->MessageBox(FrmLang->lblEidtConfirm->Caption.c_str(),//L"변경된 정보가 있습니다.\r\n변경된 정보를 저장 하시겠습니까?",
                                    FTitle.c_str(), MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL) != IDYES) return;
    }

    TADOQuery *pADOI = NULL;
    TADOQuery *pADOU = NULL;
    TADOQuery *pADOD = NULL;
	String sQryI;
	String sQryU;
	String sQryD;
    int    nEditMode;
    try
    {
        sQryI = "INSERT INTO TB_FCLT_CMPY (                                                               \r\n"
                "          CMPY_ID, CMPY_NM, BRNO, ADDR, TEL,  FCSM_NMBR, RPRV_NM,                        \r\n"
                "          CHGR_NM, CHGR_HP_NMBR, CHGR_EMAL, ADTN_NM, ADTN_DT, CHNG_NM, CHNG_DT, DEL_YN ) \r\n"
                " VALUES (:p01,    :p02,    :p03, :p04, :p05, :p06,      :p07,                            \r\n"
                "         :p08,    :p09,         :p10,      :p11,    :p12,    :p13,    :p14,    :p15    ) \r\n";

        sQryU = "UPDATE	TB_FCLT_CMPY        \r\n"
                "  SET CMPY_NM      = :p02, \r\n"
                "      BRNO         = :p03, \r\n"
                "      ADDR         = :p04, \r\n"
                "      TEL          = :p05, \r\n"
                "      FCSM_NMBR    = :p06, \r\n"
                "      RPRV_NM      = :p07, \r\n"
                "      CHGR_NM      = :p08, \r\n"
                "      CHGR_HP_NMBR = :p09, \r\n"
                "      CHGR_EMAL    = :p10, \r\n"
//                "      ADTN_NM      = :p11, \r\n"
//                "      ADTN_DT      = :p112 \r\n"
                "      CHNG_NM      = :p13, \r\n"
                "      CHNG_DT      = :p14, \r\n"
                "      DEL_YN       = :p15  \r\n"
                " WHERE CMPY_ID = :p01      \r\n";

        sQryD = "UPDATE TB_FCLT_CMPY    \r\n"
                "   SET DEL_YN  = 'Y',  \r\n"
                "      CHNG_NM  = :p13, \r\n"
                "      CHNG_DT  = :p14  \r\n"
                " WHERE CMPY_ID = :p01  \r\n";

        int nRow;
        TvList->BeginUpdate();
        try
        {
            pADOI = new TADOQuery(NULL);
			pADOI->Close();
            pADOI->Connection = ITSDb_GetConnection();

            pADOU = new TADOQuery(NULL);
			pADOU->Close();
            pADOU->Connection = ITSDb_GetConnection();

            pADOD = new TADOQuery(NULL);
			pADOD->Close();
            pADOD->Connection = ITSDb_GetConnection();

            ITSDb_SQLText(pADOI, sQryI);
            ITSDb_SQLText(pADOU, sQryU);
            ITSDb_SQLText(pADOD, sQryD);

            ITSDb_GetConnection()->BeginTrans();

            FOR_STL(TItsCompany*, pObj, MyItsCompanyManager->FLists)
            {
                if (pObj->FGridIndex < 0) continue;

                if (pObj->Completed && pObj->EditMode == DB_INIT)
                    continue;

                if (!pObj->Completed && pObj->EditMode != DB_NEW)
                    continue;

                nRow = pObj->FGridIndex;

                //pObj->CMPY_ID        = VarToStr(m_pGDC->Values[nRow][Column01->Index]);   //업체ID
                String sCMPY_NM      = VarToStr(m_pGDC->Values[nRow][Column02->Index]);   //업체 명
                String sBRNO         = VarToStr(m_pGDC->Values[nRow][Column03->Index]);   //사업자 등록 번호
                String sADDR         = VarToStr(m_pGDC->Values[nRow][Column04->Index]);   //주소
                String sTEL          = VarToStr(m_pGDC->Values[nRow][Column05->Index]);   //전화번호
                String sFCSM_NMBR    = VarToStr(m_pGDC->Values[nRow][Column06->Index]);   //팩스 번호
                String sRPRV_NM      = VarToStr(m_pGDC->Values[nRow][Column07->Index]);   //대표자 명
                String sCHGR_NM      = VarToStr(m_pGDC->Values[nRow][Column08->Index]);   //담당자 명
                String sCHGR_HP_NMBR = VarToStr(m_pGDC->Values[nRow][Column09->Index]);   //담당자 연락처
                String sCHGR_EMAL    = VarToStr(m_pGDC->Values[nRow][Column10->Index]);   //담당자 이메일

                pObj->CMPY_NM      = sCMPY_NM;
                pObj->BRNO         = sBRNO;
                pObj->ADDR         = sADDR;
                pObj->TEL          = sTEL;
                pObj->FCSM_NMBR    = sFCSM_NMBR;
                pObj->RPRV_NM      = sRPRV_NM;
                pObj->CHGR_NM      = sCHGR_NM;
                pObj->CHGR_HP_NMBR = sCHGR_HP_NMBR;
                pObj->CHGR_EMAL    = sCHGR_EMAL;
                pObj->CHNG_NM      = g_pLOGIN->sUserId;                      //변경자 명
                pObj->CHNG_DT      = Now().FormatString("yyyymmddhhnnss");   //변경 일시
                //pObj->DEL_YN       = "N";                                    //삭제 여부

                nEditMode = pObj->EditMode;
                if (pObj->Completed)
                {
                    if (pObj->EditMode == DB_DELETE)
                    {
                        //delete
                        ITSDb_SQLBind(pADOD, "p01", pObj->CMPY_ID);
                        ITSDb_SQLBind(pADOD, "p13", pObj->CHNG_NM);
                        ITSDb_SQLBind(pADOD, "p14", pObj->CHNG_DT);
                        ITSDb_SQLExec(pADOD);
                    }
                    else
                    if (pObj->EditMode == DB_UPDATE)
                    {
                        //update
                        ITSDb_SQLBind(pADOU, "p01", pObj->CMPY_ID);
                        ITSDb_SQLBind(pADOU, "p02", pObj->CMPY_NM);
                        ITSDb_SQLBind(pADOU, "p03", pObj->BRNO);
                        ITSDb_SQLBind(pADOU, "p04", pObj->ADDR);
                        ITSDb_SQLBind(pADOU, "p05", pObj->TEL);
                        ITSDb_SQLBind(pADOU, "p06", pObj->FCSM_NMBR);
                        ITSDb_SQLBind(pADOU, "p07", pObj->RPRV_NM);
                        ITSDb_SQLBind(pADOU, "p08", pObj->CHGR_NM);
                        ITSDb_SQLBind(pADOU, "p09", pObj->CHGR_HP_NMBR);
                        ITSDb_SQLBind(pADOU, "p10", pObj->CHGR_EMAL);

                        ITSDb_SQLBind(pADOU, "p13", pObj->CHNG_NM);
                        ITSDb_SQLBind(pADOU, "p14", pObj->CHNG_DT);
                        ITSDb_SQLBind(pADOU, "p15", pObj->DEL_YN);

                        ITSDb_SQLExec(pADOU);
                    }
                }
                else
                {
                    if (pObj->EditMode == DB_NEW)
                    {
                        //insert
                        pObj->ADTN_NM = g_pLOGIN->sUserId;                      //추가자 명
                        pObj->ADTN_DT = Now().FormatString("yyyymmddhhnnss");   //추가 일시

                        ITSDb_SQLBind(pADOI, "p01", pObj->CMPY_ID);
                        ITSDb_SQLBind(pADOI, "p02", pObj->CMPY_NM);
                        ITSDb_SQLBind(pADOI, "p03", pObj->BRNO);
                        ITSDb_SQLBind(pADOI, "p04", pObj->ADDR);
                        ITSDb_SQLBind(pADOI, "p05", pObj->TEL);
                        ITSDb_SQLBind(pADOI, "p06", pObj->FCSM_NMBR);
                        ITSDb_SQLBind(pADOI, "p07", pObj->RPRV_NM);
                        ITSDb_SQLBind(pADOI, "p08", pObj->CHGR_NM);
                        ITSDb_SQLBind(pADOI, "p09", pObj->CHGR_HP_NMBR);
                        ITSDb_SQLBind(pADOI, "p10", pObj->CHGR_EMAL);
                        ITSDb_SQLBind(pADOI, "p11", pObj->ADTN_NM);
                        ITSDb_SQLBind(pADOI, "p12", pObj->ADTN_DT);
                        ITSDb_SQLBind(pADOI, "p13", pObj->CHNG_NM);
                        ITSDb_SQLBind(pADOI, "p14", pObj->CHNG_DT);
                        ITSDb_SQLBind(pADOI, "p15", pObj->DEL_YN);

                        ITSDb_SQLExec(pADOI);
                    }
                }
                pObj->Completed = true;
            }
            ITSDb_GetConnection()->CommitTrans();
            Application->MessageBox(FrmLang->lblDbSave->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);
            if (nEditMode == DB_DELETE)
                DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQryD);
            else
            if (nEditMode == DB_UPDATE)
                DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQryU);
            else
            if (nEditMode == DB_NEW)
                DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQryI);
            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);
            if (nEditMode == DB_DELETE)
                DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQryD);
            else
            if (nEditMode == DB_UPDATE)
                DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQryU);
            else
            if (nEditMode == DB_NEW)
                DBERRORMSG(Caption, String(e.ClassName()), e.Message, sQryI);
            throw Exception(String(e.ClassName()) + e.Message);
        }
    }
    __finally
    {
        if (pADOI)
        {
            pADOI->Close();
            delete pADOI;
        }
        if (pADOU)
        {
            pADOU->Close();
            delete pADOU;
        }
        if (pADOD)
        {
            pADOD->Close();
            delete pADOD;
        }
        TvList->EndUpdate();
    }
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::FormCloseQuery(TObject *Sender, bool &CanClose)
{
    SaveData();
    delete MyItsCompanyManager;
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::TvListKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
	if (Key == VK_DELETE)
	{
		if (BtnDelete->Enabled) BtnDeleteClick(Sender);
	}
}
//---------------------------------------------------------------------------

void __fastcall TIFM0020M::TvListDataControllerFilterChanged(TObject *Sender)
{
    CMM_SetFilterLike(TvList);
    LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
}
//---------------------------------------------------------------------------

