
//---------------------------------------------------------------------------
#ifndef DMCOMMFH
#define DMCOMMFH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Sockets.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
#include "AppGlobalF.h"

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

// 프로세스 상태
typedef struct tagDbStatusProcess
{
    AnsiString PROCESSID;       /* VARCHAR2(6) not null, 프로세스ID */
    AnsiString REGDATE;         /* DATE not null, 상태등록일시 */
	AnsiString RUNVERSION;      /* VARCHAR2(5), 실행버전 */
    int STATUS;                 /* NUMBER(1), 프로세스상태 */
	int COMM;       			/* NUMBER(1), 통신상태 */
	int DB;         			/* NUMBER(1), DB상태 */
} DB_STATUS_PROCESS;


//---------------------------------------------------------------------------
class TDMCOMM : public TDataModule
{
__published:	// IDE-managed Components
	TTcpServer *TcpServer;
	void __fastcall DataModuleCreate(TObject *Sender);
	void __fastcall DataModuleDestroy(TObject *Sender);
	void __fastcall TcpServerGetThread(TObject *Sender, TClientSocketThread *&ClientSocketThread);


private:	// User declarations

    TADOConnection *FDbConn;
    String          FErrorString;

    int             FProcessStateMin;
    int             FEquipStateMin;

public:		// User declarations
	__fastcall TDMCOMM(TComponent* Owner);

    TADOConnection *GetDbConnection() { return FDbConn; }

    bool __fastcall DbConnect(String AConnStr);
    bool __fastcall DbClose();

    bool __fastcall SQLText(TADOQuery *adoQry, String sQry, bool AReadOnly=true);
    bool __fastcall SQLBind(TADOQuery *adoQry, String param, String var);
    bool __fastcall SQLClose(TADOQuery *adoQry);
    int  __fastcall SQLOpen(TADOQuery *adoQry);
    int  __fastcall SQLExec(TADOQuery *adoQry);
    void __fastcall SQLFree(TADOQuery *adoQry)
    {
        if (adoQry)
        {
            SQLClose(adoQry);
            SAFE_DELETE(adoQry);
        }
    }

	void __fastcall DbState(bool AFlag);

    void __fastcall TcpClientDisconnect(TObject *Sender);

	TVmsCtlr* __fastcall FindVms(AnsiString AIpAddress, int APort);

	void __fastcall TerminateVms(void);
	void __fastcall ControlVms(TVmsCtlr *AObj, bool ACreate);
	void __fastcall MonitoringVms(bool ServerRun);

#ifdef RUN_CLIENT
	void __fastcall TerminateVmsClient(TVmsCtlr *AObj);
	void __fastcall TerminateVmsClient(void);
	void __fastcall ControlVmsClient(TVmsCtlr *AObj, bool ACreate);
	void __fastcall MonitoringVmsClient(bool ServerRun);
#endif

	int __fastcall GetDbSysdate();
	int __fastcall GetProcessInfo();

	int __fastcall GetVmsInfo();
	int __fastcall GetFontInfo();

	int __fastcall GetVmsStateInfo();
    int __fastcall GetVmsIfscInfo();
	int __fastcall LoadVmsOnOffTime();
	int __fastcall GetVmsLuminanceTime();
	int __fastcall GetVmsDownLoadInfo();

    /* VMS Draw Master db */
	int __fastcall GetVmsImage();
	int __fastcall GetVmsImageCell();
	int __fastcall LoadVmsForm();
	int __fastcall LoadVmsFormObject();


//
	int __fastcall SaveProcessStateProc(void);

	int __fastcall SaveEquipStateAllProc(void);
	int __fastcall SendEquipStateAllProc(void);

	int __fastcall SaveEquipStateProc(TVmsCtlr *AObj, int AServerState);

	int __fastcall DataSaveProc(void *pData);

	int __fastcall ProvideProc(void *AData);

    int __fastcall LoadIfscTrafficInfo();

	int __fastcall LoadVmsOperatorMode();
	int __fastcall SetVmsMode();

	int __fastcall MakeVmsScenarioForm(AnsiString AVmsId);
	int __fastcall SaveVmsDownloadForm();

	int __fastcall ClearVmsProvideMode(AnsiString AVmsId);
	int __fastcall LoadVmsScheduleInfo(AnsiString AVmsId);
	int __fastcall LoadVmsEventOccrInf(AnsiString AVmsId);

	int __fastcall ProvideSave(void *AData);
	int __fastcall SaveVmsDownLoad(TVmsCtlr *AObj);
	int __fastcall SaveVmsDatabaseForm(TVmsCtlr *AObj);
	int __fastcall UpdateVmsProvideResult(TVmsCtlr *AObj);

    AnsiString FFormDsplDt;

    IPC_LOG_MESSAGE FLogMsg;
    int LogWrite(int ALogKind, char *AFmt, ...);

    void __fastcall SetErrorString(String AErrorString);
	__property String  ErrorString = {read=FErrorString, write=SetErrorString};
};
//---------------------------------------------------------------------------
extern PACKAGE TDMCOMM *DMCOMM;
//---------------------------------------------------------------------------
#endif
