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

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

#include "FRAME_FacilityFailActionF.h"

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

extern LOGININFO *g_pLOGIN;

//TFRAMEFacilityFailAction *FRAMEFacilityFailAction;
//---------------------------------------------------------------------------
__fastcall TFRAMEFacilityFailAction::TFRAMEFacilityFailAction(TComponent* Owner)
    : TFrame(Owner)
{
    LangTrans->Translate(this, ITSDb_GetConnection());
    ITSSkin_Load((TForm*)this);

    FTitle = lblTitle->Caption;//"시설물 장애 내역 조치";
    m_pGDC = TvList->DataController;
    TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<시설물 장애 내역처리 정보가 없습니다>";

    FFacilityFail = NULL;
    FUpdate       = false;
    FKeySeq       = -1;

#if 0
    if (!ItsFacilityFailActionManager)
    {
        ItsFacilityFailActionManager = new TItsFacilityFailActionManager();
    }
    ItsFacilityFailActionManager->LoadFromDb();
#endif

    //작업완료여부
	TcxComboBoxProperties *pcxCboProperties07 = (TcxComboBoxProperties*)Column07->Properties;
    pcxCboProperties07->Items->Clear();
	pcxCboProperties07->Items->Add("Y");
	pcxCboProperties07->Items->Add("N");
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEFacilityFailAction::UpdateCheck()
{
    if (FFacilityFail)
    {
        if (BtnEdit->Down)
        {
            FUpdate = false;
            BtnEdit->Down = false;
            BtnEdit->Click();
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEFacilityFailAction::UpdateList(TItsFacilityFail *AFacilityFail)
{
/*
*  데이터가 많은 경우 문제가 될수 있으니
*  시설물 아이디로 이력을 조회하여 처리하는 것으로 수정하는것이 좋을듯.
*  그런데 실재 데이터가 많이 들어가 있지 않은게 함정.
*/
    FUpdate = false;

    FFacilityFail = AFacilityFail;

    LblFacility->Caption = "---";
    CMM_ClearGridTableView(TvList);

    if (!FFacilityFail) return;
    LblFacility->Caption = "[" + FFacilityFail->FCLT_ID + "] [" + FFacilityFail->FAIL_HS_SEQ + "] " + FFacilityFail->FAIL_CONT;

    try
    {
        TvList->BeginUpdate();

        FOR_STL(TItsFacilityFailAction*, pObj, FFacilityFail->FLists)
        {
            pObj->EditMode = DB_INIT;   //미리 초기화시켜야함
            pObj->Completed = true;
            if (pObj->DEL_YN == "Y") continue;

            if (pObj->FAIL_HS_SEQ != FFacilityFail->FAIL_HS_SEQ) 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 TFRAMEFacilityFailAction::AddObjectItem(TItsFacilityFailAction *pObj, String AMode)
{
    int nRow;
    try
    {
        nRow = m_pGDC->AppendRecord();
        pObj->GridIndex = nRow;

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

        m_pGDC->Values[nRow][Column01->Index] = ITSUtil_StrToDateTime(pObj->CRTN_DT);        //'생성 일시
        m_pGDC->Values[nRow][Column02->Index] = pObj->FAIL_HS_SEQ;    //'장애 이력 일련번호
        m_pGDC->Values[nRow][Column03->Index] = pObj->WRKR_NM;        //'작업자 명
        m_pGDC->Values[nRow][Column04->Index] = pObj->WORK_CONT;      //'작업 내용

        if (!pObj->WORK_STRT_DT.IsEmpty())
        m_pGDC->Values[nRow][Column05->Index] = ITSUtil_StrToDateTime(pObj->WORK_STRT_DT);   //'작업 시작 일시

        if (!pObj->WORK_END_DT.IsEmpty())
        m_pGDC->Values[nRow][Column06->Index] = ITSUtil_StrToDateTime(pObj->WORK_END_DT);    //'작업 종료 일시

        m_pGDC->Values[nRow][Column07->Index] = pObj->WORK_FINS_YN;   //'작업 완료 여부
        m_pGDC->Values[nRow][Column08->Index] = pObj->ADTN_NM;        //'추가자 명
        m_pGDC->Values[nRow][Column09->Index] = pObj->CHNG_NM;        //'변경자 명

        if (!pObj->CHNG_DT.IsEmpty())
        m_pGDC->Values[nRow][Column10->Index] = ITSUtil_StrToDateTime(pObj->CHNG_DT);        //'변경 일시*/

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

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

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

void __fastcall TFRAMEFacilityFailAction::BtnExlSaveClick(TObject *Sender)
{
    TcxGrid          *pGrid = CxList;
    TcxGridTableView *pView = TvList;
    String            sTitle= lblFileName->Caption;//"시설물장애처리내역";

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

void __fastcall TFRAMEFacilityFailAction::BtnEditClick(TObject *Sender)
{
    if (!FFacilityFail)
    {
        Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"시설물 장애내역 정보를 먼저 선택하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
    }

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

    //ItsFacilityFailManager->LoadFromDb();
    UpdateList(FFacilityFail);
}
//---------------------------------------------------------------------------

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

    try
    {
        TvList->BeginUpdate();

        Column00->Visible = 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;  //'변경자 명
    }
    __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;//데이터 편집";
        }
    }
}
//---------------------------------------------------------------------------

bool __fastcall TFRAMEFacilityFailAction::GetNewId(String &ANewId)
{
    String sQry;
    TADOQuery *pADO = NULL;
    String sNowDate = Now().FormatString("YYYYMMDDHHNNSS");

    ANewId = "";
    ANewId = sNowDate;
    return true;
}
//---------------------------------------------------------------------------

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

    if (!FFacilityFail)
    {
        Application->MessageBox(FrmLang->lblSelErr->Caption.c_str(),//L"시설물 장애내역 정보를 먼저 선택하세요.",
                                FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
		return;
    }

    String sNewId = "";
    GetNewId(sNewId);

    try
    {
        TvList->BeginUpdate();

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

        pObj->CRTN_DT      = sNewId;                                //'생성 일시
        pObj->FAIL_HS_SEQ  = FFacilityFail->FAIL_HS_SEQ;            //'장애 이력 일련번호
        pObj->WRKR_NM      = g_pLOGIN->sUserId;                     //'작업자 명
        pObj->WORK_CONT    = "";                                    //'작업 내용
        pObj->WORK_STRT_DT = Now().FormatString("yyyymmddhhnnss");  //'작업 시작 일시
        pObj->WORK_END_DT  = Now().FormatString("yyyymmddhhnnss");  //'작업 종료 일시
        pObj->WORK_FINS_YN = "N";                                   //'작업 완료 여부
        pObj->ADTN_NM      = g_pLOGIN->sUserId;                     //'추가자 명
        pObj->CHNG_NM      = g_pLOGIN->sUserId;                     //'변경자 명
        pObj->CHNG_DT      = Now().FormatString("yyyymmddhhnnss"); //'변경 일시*/

        FFacilityFail->FLists.Push(pObj->CRTN_DT, pObj);

        pObj->Completed = false;
        pObj->EditMode = DB_NEW;

        AddObjectItem(pObj, FrmLang->lblNew->Caption);//"신규");
        Application->ProcessMessages();
        Sleep(1000);    //생성시각을 유니크하게 하기위함.
    }
    __finally
    {
        LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
        TvList->EndUpdate();
        TvList->DataController->GotoFirst();
        TvList->DataController->FocusedRecordIndex = 0;
    }
}
//---------------------------------------------------------------------------

void __fastcall TFRAMEFacilityFailAction::BtnDeleteClick(TObject *Sender)
{
    int nIdx = m_pGDC->FocusedRecordIndex;
    if (nIdx < 0) return;

    int nMemPtr = m_pGDC->Values[nIdx][Column99->Index];
    TItsFacilityFailAction *pObj = (TItsFacilityFailAction*)nMemPtr;
    pObj->EditMode = DB_DELETE;
    m_pGDC->Values[nIdx][Column00->Index] = FrmLang->lblDelete->Caption;//"삭제";
}
//---------------------------------------------------------------------------

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

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

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


bool __fastcall TFRAMEFacilityFailAction::IsUpdate()
{
    if (!FFacilityFail) return false;

    FOR_STL(TItsFacilityFailAction*, pObj, FFacilityFail->FLists)
    {
        if (pObj->Completed && pObj->EditMode != DB_INIT)
            return true;

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

void __fastcall TFRAMEFacilityFailAction::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)
        {
            //추가했던것 삭제
            FOR_STL(TItsFacilityFailAction*, pObj, FFacilityFail->FLists)
            {
                if (pObj->EditMode == DB_NEW)
                    FFacilityFail->FLists.Remove(pObj->CRTN_DT);
            }
            return;
        }
    }

    TADOQuery *pADOI = NULL;
    TADOQuery *pADOU = NULL;
    TADOQuery *pADOD = NULL;
	String sQryI;
	String sQryU;
	String sQryD;
    int    nEditMode;
    try
    {
        sQryI = "INSERT INTO TB_FCLT_FAIL_RPAR_HS (CRTN_DT, FAIL_HS_SEQ,  WRKR_NM,     \r\n"
                "                             WORK_CONT,    WORK_STRT_DT, WORK_END_DT, \r\n"
                "                             WORK_FINS_YN, ADTN_NM,     CHNG_NM,      \r\n"
                "                             CHNG_DT)                                 \r\n"
                "                      VALUES(:p01, :p02, :p03,                        \r\n"
                "                             :p04, :p05, :p06,                        \r\n"
                "                             :p07, :p08, :p09,                        \r\n"
                "                             TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS'))    \r\n";

        sQryU = "UPDATE TB_FCLT_FAIL_RPAR_HS                                \r\n"
                "   SET WRKR_NM      = :p03,                                \r\n"
                "       WORK_CONT    = :p04,                                \r\n"
                "       WORK_STRT_DT = :p05,                                \r\n"
                "       WORK_END_DT  = :p06,                                \r\n"
                "       WORK_FINS_YN = :p07,                                \r\n"
                "       ADTN_NM      = :p08,                                \r\n"
                "       CHNG_NM      = :p09,                                \r\n"
                "       CHNG_DT      = TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') \r\n"
                " WHERE CRTN_DT     = :p01                                  \r\n"
                "   AND FAIL_HS_SEQ = :p02                                  \r\n";

        sQryD = "DELETE TB_FCLT_FAIL_RPAR_HS \r\n"
                " WHERE CRTN_DT     = :p01   \r\n"
                "   AND FAIL_HS_SEQ = :p02   \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(TItsFacilityFailAction*, pObj, FFacilityFail->FLists)
            {
                if (pObj->GridIndex < 0) continue;

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

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

                nRow = pObj->GridIndex;

                String  WRKR_NM      = VarToStr(m_pGDC->Values[nRow][Column03->Index]); //'작업자 명
                String  WORK_CONT    = VarToStr(m_pGDC->Values[nRow][Column04->Index]); //'작업 내용
                String  WORK_STRT_DT = "";   //'작업 시작 일시
                String  WORK_END_DT  = "";    //'작업 종료 일시
                String  WORK_FINS_YN = VarToStr(m_pGDC->Values[nRow][Column07->Index]); //'작업 완료 여부
                String  ADTN_NM      = VarToStr(m_pGDC->Values[nRow][Column08->Index]); //'추가자 명
                String  CHNG_NM      = VarToStr(m_pGDC->Values[nRow][Column09->Index]); //'변경자 명


                if (!VarIsNull(m_pGDC->Values[nRow][Column05->Index]))
                {
                    TDateTime dtTmp = m_pGDC->Values[nRow][Column05->Index];
                    WORK_STRT_DT = dtTmp.FormatString("YYYYMMDDHHNNSS");
                }
                if (!VarIsNull(m_pGDC->Values[nRow][Column06->Index]))
                {
                    TDateTime dtTmp = m_pGDC->Values[nRow][Column06->Index];
                    WORK_END_DT = dtTmp.FormatString("YYYYMMDDHHNNSS");
                }

                //pObj->CRTN_DT;        //'생성 일시
                //pObj->FAIL_HS_SEQ;    //'장애 이력 일련번호
                pObj->WRKR_NM      = WRKR_NM;        //'작업자 명
                pObj->WORK_CONT    = WORK_CONT;      //'작업 내용
                pObj->WORK_STRT_DT = WORK_STRT_DT;   //'작업 시작 일시
                pObj->WORK_END_DT  = WORK_END_DT;    //'작업 종료 일시
                pObj->WORK_FINS_YN = WORK_FINS_YN;   //'작업 완료 여부
                pObj->ADTN_NM      = ADTN_NM;        //'추가자 명
                pObj->CHNG_NM      = CHNG_NM;        //'변경자 명
                pObj->CHNG_DT      = Now().FormatString("yyyymmddhhnnss"); //'변경 일시*/

                nEditMode = pObj->EditMode;
                if (pObj->Completed)
                {
                    if (pObj->EditMode == DB_DELETE)
                    {
                        //delete
                        ITSDb_SQLBind(pADOD, "p01", pObj->CRTN_DT);
                        ITSDb_SQLBind(pADOD, "p02", pObj->FAIL_HS_SEQ);
                        ITSDb_SQLExec(pADOD);
                        pObj->DEL_YN = "Y";
                        FFacilityFail->ActionCnt--;
                    }
                    else
                    if (pObj->EditMode == DB_UPDATE)
                    {
                        //update
                        ITSDb_SQLBind(pADOU, "p01", pObj->CRTN_DT);
                        ITSDb_SQLBind(pADOU, "p02", pObj->FAIL_HS_SEQ);

                        ITSDb_SQLBind(pADOU, "p03", pObj->WRKR_NM);
                        ITSDb_SQLBind(pADOU, "p04", pObj->WORK_CONT);
                        ITSDb_SQLBind(pADOU, "p05", pObj->WORK_STRT_DT);
                        ITSDb_SQLBind(pADOU, "p06", pObj->WORK_END_DT);
                        ITSDb_SQLBind(pADOU, "p07", pObj->WORK_FINS_YN);
                        ITSDb_SQLBind(pADOU, "p08", pObj->ADTN_NM);
                        ITSDb_SQLBind(pADOU, "p09", pObj->CHNG_NM);

                        ITSDb_SQLExec(pADOU);
                    }
                }
                else
                {
                    if (pObj->EditMode == DB_NEW)
                    {
                        //insert
                        ITSDb_SQLBind(pADOI, "p01", pObj->CRTN_DT);
                        ITSDb_SQLBind(pADOI, "p02", pObj->FAIL_HS_SEQ);

                        ITSDb_SQLBind(pADOI, "p03", pObj->WRKR_NM);
                        ITSDb_SQLBind(pADOI, "p04", pObj->WORK_CONT);
                        ITSDb_SQLBind(pADOI, "p05", pObj->WORK_STRT_DT);
                        ITSDb_SQLBind(pADOI, "p06", pObj->WORK_END_DT);
                        ITSDb_SQLBind(pADOI, "p07", pObj->WORK_FINS_YN);
                        ITSDb_SQLBind(pADOI, "p08", pObj->ADTN_NM);
                        ITSDb_SQLBind(pADOI, "p09", pObj->CHNG_NM);

                        ITSDb_SQLExec(pADOI);
                        FFacilityFail->FLists.Push(pObj->CRTN_DT, pObj);
                        FFacilityFail->ActionCnt++;
                    }
                }
                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 TFRAMEFacilityFailAction::ColumnPropertiesValidate(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 = m_pGDC->Values[nRow][Column99->Index];
    TItsFacilityFailAction *pObj = (TItsFacilityFailAction*)nMemPtr;
    if (pObj->Completed == false)
    {
        //신규이거나 삭제인 경우 편집 내용에 따른 변화가 필요없다.
        return;
    }

    String  WRKR_NM      = VarToStr(m_pGDC->Values[nRow][Column03->Index]); //'작업자 명
    String  WORK_CONT    = VarToStr(m_pGDC->Values[nRow][Column04->Index]); //'작업 내용
    String  WORK_STRT_DT = "";   //'작업 시작 일시
    String  WORK_END_DT  = "";    //'작업 종료 일시
    String  WORK_FINS_YN = VarToStr(m_pGDC->Values[nRow][Column07->Index]); //'작업 완료 여부
    String  ADTN_NM      = VarToStr(m_pGDC->Values[nRow][Column08->Index]); //'추가자 명
    String  CHNG_NM      = VarToStr(m_pGDC->Values[nRow][Column09->Index]); //'변경자 명


    if (!VarIsNull(m_pGDC->Values[nRow][Column05->Index]))
    {
        TDateTime dtTmp = m_pGDC->Values[nRow][Column05->Index];
        WORK_STRT_DT = dtTmp.FormatString("YYYYMMDDHHNNSS");
    }
    if (!VarIsNull(m_pGDC->Values[nRow][Column06->Index]))
    {
        TDateTime dtTmp = m_pGDC->Values[nRow][Column06->Index];
        WORK_END_DT = dtTmp.FormatString("YYYYMMDDHHNNSS");
    }

    TcxGridColumn *pColumn = TvList->Controller->FocusedColumn;
    if (pColumn == Column05)
    {
        TDateTime dtTmp = DisplayValue;
        WORK_STRT_DT = dtTmp.FormatString("YYYYMMDDHHNNSS");
    }
    else
    if (pColumn == Column06)
    {
        TDateTime dtTmp = DisplayValue;
        WORK_END_DT = dtTmp.FormatString("YYYYMMDDHHNNSS");
    }
    else if (pColumn == Column03) WRKR_NM      = DisplayValue;
    else if (pColumn == Column04) WORK_CONT    = DisplayValue;
    else if (pColumn == Column07) WORK_FINS_YN = DisplayValue;
    else if (pColumn == Column08) ADTN_NM      = DisplayValue;
    else if (pColumn == Column09) CHNG_NM      = DisplayValue;

    if (pObj->WRKR_NM      != WRKR_NM      || //'작업자 명
        pObj->WORK_CONT    != WORK_CONT    || //'작업 내용
        pObj->WORK_STRT_DT != WORK_STRT_DT || //'작업 시작 일시
        pObj->WORK_END_DT  != WORK_END_DT  || //'작업 종료 일시
        pObj->WORK_FINS_YN != WORK_FINS_YN || //'작업 완료 여부
        pObj->ADTN_NM      != ADTN_NM      || //'추가자 명
        pObj->CHNG_NM      != CHNG_NM       ) //'변경자 명
    {
        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 TFRAMEFacilityFailAction::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;
        }
    }
}
//---------------------------------------------------------------------------

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

void __fastcall TFRAMEFacilityFailAction::OnCloseQuery(bool &CanClose)
{
    SaveData();
#if 0
    if (ItsFacilityFailActionManager)
    {
        delete ItsFacilityFailActionManager;
        ItsFacilityFailActionManager = NULL;
    }
#endif
}
//---------------------------------------------------------------------------

