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

#ifndef DMAdoDbFH
#define DMAdoDbFH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ADODB.hpp>
#include <DB.hpp>
//---------------------------------------------------------------------------
class TDMAdoDb : public TDataModule
{
__published:	// IDE-managed Components
    void __fastcall DataModuleCreate(TObject *Sender);
    void __fastcall DataModuleDestroy(TObject *Sender);
private:	// User declarations
    TADOConnection *FDbConn;
    AnsiString      FErrorString;
    String          FConnString;
    bool            FException;

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

    TADOConnection *GetConnection() { return FDbConn; }
    void __fastcall SetConnectString(String AProvider, String AServerName, String AUserName, String APassword, String ACatalog="");
    void __fastcall SetConnectString(String AConnString);

    bool __fastcall Connect(String AConnStr="");
    bool __fastcall Close();
    bool __fastcall IsDbConnected()
    {
        if (!FDbConn) return false;
        return FDbConn->Connected;
    }
    bool __fastcall IsDbAlive(AnsiString &ASysTime);
    void __fastcall SetDbState(bool AFlag);

    bool __fastcall SQLClose(TADOQuery *adoQry);
    bool __fastcall SQLClear(TADOQuery *adoQry);
    int  __fastcall SQLText(TADOQuery *adoQry, String sQry);
    bool __fastcall SQLBind(TADOQuery *adoQry, String param, String var);
    bool __fastcall SQLBindStream(TADOQuery *adoQry, String param, TStream * pStream);
    int  __fastcall SQLOpen(TADOQuery *adoQry);
    int  __fastcall SQLExec(TADOQuery *adoQry);
    bool __fastcall LocateItem(TADOQuery *adoQry, String sFldNm, String sFldVal);

    void __fastcall SetErrorString(AnsiString AErrorString);
	__property AnsiString  ErrorString = {read=FErrorString, write=SetErrorString};
	__property String  ConnString  = {read=FConnString,  write=FConnString};
};
//---------------------------------------------------------------------------
//extern PACKAGE TDMAdoDb *DMAdoDb;
//---------------------------------------------------------------------------

#endif
