⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookup.h

📁 vc++6.0数据库编程大全一书得各个章节得源码,比较详细.可以仔细参照学习!
💻 H
字号:
// Lookup.H : Declaration of the CLookup class

#ifndef __LOOKUP_H_
#define __LOOKUP_H_

class CLookupAccessor
{
public:
	TCHAR m_Name[62];	//Reduce size.  1024 is not necessary.
	TCHAR m_Description[51];
	TCHAR m_Assignment[51];
	double m_Score;

BEGIN_COLUMN_MAP(CLookupAccessor)
	COLUMN_ENTRY(1, m_Name)
	COLUMN_ENTRY(2, m_Description)
	COLUMN_ENTRY(3, m_Assignment)
	COLUMN_ENTRY(4, m_Score)
END_COLUMN_MAP()

DEFINE_COMMAND(CLookupAccessor, _T(" \
	SELECT \
		Name, \
		Description, \
		Assignment, \
		Score  \
		FROM Lookup"))

	// You may wish to call this function if you are inserting a record and wish to
	// initialize all the fields, if you are not going to explicitly set all of them.
	void ClearRecord()
	{
		memset(this, 0, sizeof(*this));
	}
};

class CLookup : public CCommand<CAccessor<CLookupAccessor> >
{
public:
	HRESULT findUser(BSTR uid, BSTR pwd)
	{
		char userID[51];
		char password[51];
		sprintf(userID, "%S", uid);
		sprintf(password, "%S", pwd);
		return findUser(userID, password);
	}
	HRESULT findUser(char *userID, char *password) {
		if (strlen(userID) > 50 || strlen(password) > 50) {
			::MessageBox(NULL, 
		"User name and password cannot be more than 50 characters",
			"Could not find user", MB_OK);
			return -1;
		}
		strcpy(m_strUser, userID);
		strcpy(m_strPassword, password);
		return Open();
	}
	HRESULT Open()
	{
		HRESULT		hr;
		hr = OpenDataSource();
		if (FAILED(hr))
			return hr;

		return OpenRowset();
	}
	HRESULT OpenDataSource()
	{
		HRESULT		hr;
		CDataSource db;
		CDBPropSet	dbinit(DBPROPSET_DBINIT);

		dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);		dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("Classes"));		dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);		dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);		hr = db.Open(_T("MSDASQL"), &dbinit);
		if (FAILED(hr))
			return hr;

		return m_session.Open(db);
	}
	HRESULT OpenRowset()
	{
		//The rest of this function was added by Chuck Wood
		//Allow 512 bytes for the new SQL Command
		char newSQL[512];
		char *SQLCommand;
		GetDefaultCommand((const char **) &SQLCommand);
		strcpy(newSQL, SQLCommand);	//Get the default SQL
		strcat(newSQL, " WHERE UserID = '"); //Add the filter
		strcat(newSQL, m_strUser);
		strcat(newSQL, "' AND Password = '");
		strcat(newSQL, m_strPassword);
		strcat(newSQL, "'");
		strcat(newSQL, " ORDER BY Description, Assignment"); //Add the sort
//Message box for debugging
//		::MessageBox(NULL, newSQL, "Lookup.h", MB_OK);
		return CCommand<CAccessor<CLookupAccessor> >::Open(m_session, newSQL);
	}
private:
	CSession	m_session;
	char	 	m_strUser[50];
	char	 	m_strPassword[50];
};

#endif // __LOOKUP_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -