/************************************************************************/
/*  Copyright (C), 2016-2020, [IT], 保留所有权利;
/*  模 块 名：;
/*  描    述：;
/*
/*  版    本：[V];	
/*  作    者：[IT];
/*  日    期：[9/20/2016];
/*
/*
/*  注    意：;
/*
/*  修改记录：[IT];
/*  修改日期：;
/*  修改版本：;
/*  修改内容：;
/************************************************************************/
#ifndef __ODBCPTR_20160920__
#define __ODBCPTR_20160920__

//class CDatabase;
#include "IWxAdoInterface.h"

#pragma once


class AFX_EXT_CLASS CWxAdoImpl:public IWxAdoInterface
{
	CWxAdoImpl(void);
public:
	~CWxAdoImpl(void);
	ULONG	STDMETHODCALLTYPE AddRef( );
	ULONG	STDMETHODCALLTYPE Release( );
	HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refiid, void **ppvObject);

	// 获取实例指针;
	static CWxAdoImpl* GetInstance(){
		if ( m_pInstance == NULL )
			m_pInstance = new CWxAdoImpl;
		return m_pInstance;
	}

private:
	volatile LONG m_nRef;
	volatile LONG m_nObjRef;
	// 单例实例;
	static CWxAdoImpl* m_pInstance;

	void SolveDBError( IN CONST DWORD &dwError, IN LPVOID pDBConn);
	//template<typename T> BOOL GetFiedValue(IN _RecordsetPtr rst, IN LPCTSTR lpFiedName, T &value);
public:
	// 初始化所有连接;
	DWORD InitializePool( 
		IN LPCTSTR lpDBType,
		IN LPCTSTR lpDBSource, 
		IN CONST DWORD &dwDBPort, 
		IN LPCTSTR lpDBAccount, 
		IN LPCTSTR lpPassWord, 
		IN LPCTSTR lpDBName, 
		IN CONST INT &nMinConn = 1, 
		IN CONST INT &nMaxConn = 5
		);
	// 关闭所有连接;
	void ReleasePool();

	BOOL ExecuteSQL( IN LPCTSTR lpExcuteSQL, IN CONST DWORD &dwTimeOut = 30000 );
	BOOL IsUserExist( IN LPCTSTR lpPhone, IN LPCTSTR lpPassword, OUT LPVOID lpOutUserInfo,IN CONST DWORD &dwTimeOut = 3000 );
	INT QueryUserDetail(IN LPCTSTR lpStudioID, IN LPVOID lpUserDetail, IN CONST DWORD& dwTimeOut = 3000);
	INT QueryUserDetail( IN LPCTSTR lpStudioID, IN LPCTSTR lpAccount, IN LPCTSTR lpPassword, OUT LPVOID lpOutUserInfo,IN CONST DWORD &dwTimeOut = 3000 );
	INT QueryDepartmentInfo( IN LPCTSTR lpStudioID, OUT LPVOID lpOutDepartmentInfo, IN CONST DWORD& dwTimeOut = 3000  );
	INT QueryStaffInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutStaffInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryUserInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutUserInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryProductType(IN LPCTSTR lpStudioID, OUT LPVOID lpOutProductType, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryProductInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutProductInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT QuerySceneryInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutSceneryInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryPackageType(IN LPCTSTR lpStudioID, OUT LPVOID lpOutPackageType, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryPackageInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutPackageInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryPackageItems(IN LPCTSTR lpStudioID, OUT LPVOID lpOutPackageItems, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryPackageItemsView(IN LPCTSTR lpStudioID, OUT LPVOID lpOutPackageItems, IN CONST DWORD& dwTimeOut = 3000);
	INT QueryPackageItemsDetail(IN LPCTSTR lpStudioID, IN LPCTSTR lpPackageSN, OUT LPVOID lpOutPackageItems, IN CONST DWORD& dwTimeOut = 3000);
	INT QueryCustomerType(IN LPCTSTR lpStudioID, OUT LPVOID lpOutCustomerFrom, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryCustomerInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutCustomerInfo, IN LPCTSTR lpFilter, IN CONST DWORD& dwTimeOut = 3000);
	INT QueryOrderType(IN LPCTSTR lpStudioID, OUT LPVOID lpOutOrderType, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryOrderInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutOrderInfo, IN LPCTSTR lpFilter, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryOrderScenery(IN LPCTSTR lpStudioID, OUT LPVOID lpOutOrderScenery, IN LPCTSTR lpFilter, IN CONST DWORD& dwTimeOut = 3000);
	INT QueryOrderPackageItems(IN LPCTSTR lpStudioID, OUT LPVOID lpOutOrderPackageItems, IN LPCTSTR lpFilter, IN CONST DWORD& dwTimeOut = 3000);
	INT QuerySysConfig(IN LPCTSTR lpStudioID, OUT LPVOID lpOutSysConfig, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryLog(IN LPCTSTR lpStudioID, OUT LPVOID lpOutLog, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryStudioInfo(IN LPCTSTR lpStudioID, OUT LPVOID lpOutStudioInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT SupQueryStudioInfo(OUT LPVOID lpOutStudioInfo, IN CONST DWORD& dwTimeOut = 3000 );
	INT QueryMaxOrderId(IN LPCTSTR lpStudioID, IN CONST DWORD& dwTimeOut = 3000);
	INT QueryMaxPrintId(IN LPCTSTR lpStudioID, IN CONST DWORD& dwTimeOut = 3000);
	//////////////////////////////////////////////////////////////////////////
	BOOL InsertStudioInfo(IN LPVOID lpStudioInfo, IN CONST DWORD& dwTimeOut = 3000 );
	BOOL UpdateStudioInfo(IN LPVOID lpStudioInfo, IN CONST DWORD& dwTimeOut = 3000);
};

#endif