// MIRADO.h: interface for the CMirAdo class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MIRADO_H__1B4F72E2_690A_11D7_BBD3_0000E8481EEF__INCLUDED_)
#define AFX_MIRADO_H__1B4F72E2_690A_11D7_BBD3_0000E8481EEF__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define	ADO_OK		0L

#define	ADO_SQL_DUPLICATE			_T("23000")
#define	ADO_SQL_CONNECT_FAILURE		_T("S1009")
#define	ADO_SQL_OPEN_FAILURE		_T("S1000")


class CMirAdo : public CObject
{
public:
	CMirAdo();
	virtual ~CMirAdo();

private:
    // Define ADO object pointers.
    // Initialize pointers on define.
    // These are in the ADODB::  namespace.
    _ConnectionPtr  m_pConnect;
    _CommandPtr     m_pCommand;
    _RecordsetPtr   m_pRecordSet;

	CString		m_ErrorMessgae;
	CString		m_ErrorCode;

public:
	BOOL DBConnectOLE(TCHAR* pSource);
	BOOL InitMirAdo(void);
	void CloseMirAdo(void);
	BOOL DBConnectMDB(TCHAR* pDSN, TCHAR* pUID, TCHAR* pPWD);
	BOOL DBConnectSQL(TCHAR* connectSTR);
	BOOL ReQuery();
	BOOL MoveFirst();
	BOOL MoveLast();
	BOOL MoveNext();
	BOOL MovePrev();
	BOOL IsEOF();
	BOOL IsRSOpen();
	BOOL IsOpen();

	BOOL Execute(_bstr_t strSql, long lnOption = adCmdText);
	BOOL Execute(LPCTSTR strSql, long lnOption = adCmdText);
	int  ExecuteUpDel(CString strSql, long lnOption = adCmdText);

	BOOL Open(_bstr_t strSql, long lnOption = adCmdUnknown);
	BOOL Open(LPCTSTR strSql, long lnOption = adCmdUnknown);

	int GetRecordCount();
	int GetFieldCount();
	void Close();
	BOOL RSClose();
	long BeginTrans();
	void CommitTrans();
	void RollbackTrans();
	void ConCancel();
	void GetValue(short shFieldNo, CString& ret);
	void GetValue(short shFieldNo, _variant_t& ret);
	void GetValue(short shFieldNo, _bstr_t& ret);
	void GetValue(short shFieldNo, TCHAR* ret);
	void GetValue(short shFieldNo, TCHAR& ret);
	void GetValue(short shFieldNo, double& ret);
	void GetValue(short shFieldNo, float& ret);
	void GetValue(short shFieldNo, long& ret);
	void GetValue(short shFieldNo, int& ret);
	void ClearError(void);
	CString	GetErrorMessage(void);
	CString GetErrorCode(void);
	BOOL DBConnectProc(_bstr_t strConnect);

private:
	BOOL IsDBOpen();
	void AlertProviderError();
	void AlertComError(_com_error &e);
	inline void INSTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};

};

#endif // !defined(AFX_MIRADO_H__1B4F72E2_690A_11D7_BBD3_0000E8481EEF__INCLUDED_)
