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

📄 s16_01set.h

📁 本书分为五个部分
💻 H
字号:
// S16_01Set.h: CS16_01Set 类的接口
//


#pragma once

// 代码生成在 2002年5月29日, 11:47

class CS16_01SetAccessor
{
public:
	LONG m_ProductID;	// Number automatically assigned to new product.
	TCHAR m_ProductName[41];
	LONG m_SupplierID;	// Same entry as in Suppliers table.
	LONG m_CategoryID;	// Same entry as in Categories table.
	TCHAR m_QuantityPerUnit[21];	// (e.g., 24-count case, 1-liter bottle).
	DB_NUMERIC m_UnitPrice;
	SHORT m_UnitsInStock;
	SHORT m_UnitsOnOrder;
	SHORT m_ReorderLevel;	// Minimum units to maintain in stock.
	VARIANT_BOOL m_Discontinued;	// Yes means item is no longer available.

	// 以下向导生成的数据成员包含列映射中相应字段的状态值。
	// 可以使用这些值保存数据库返回的 NULL 值或在编译器返回
	// 错误时保存错误信息。有关如何使用这些字段的详细信息,
	// 请参见 Visual C++ 文档中的“向导生成的访问器中的字段状态数据成员”。
	// 注意:在设置/插入数据前必须初始化这些字段!

	DBSTATUS m_dwProductIDStatus;
	DBSTATUS m_dwProductNameStatus;
	DBSTATUS m_dwSupplierIDStatus;
	DBSTATUS m_dwCategoryIDStatus;
	DBSTATUS m_dwQuantityPerUnitStatus;
	DBSTATUS m_dwUnitPriceStatus;
	DBSTATUS m_dwUnitsInStockStatus;
	DBSTATUS m_dwUnitsOnOrderStatus;
	DBSTATUS m_dwReorderLevelStatus;
	DBSTATUS m_dwDiscontinuedStatus;

	// 以下向导生成的数据成员包含列映射中相应字段的长度值。
	// 注意:对变长列,必须在设置/插入数据前初始化这些字段!

	DBLENGTH m_dwProductIDLength;
	DBLENGTH m_dwProductNameLength;
	DBLENGTH m_dwSupplierIDLength;
	DBLENGTH m_dwCategoryIDLength;
	DBLENGTH m_dwQuantityPerUnitLength;
	DBLENGTH m_dwUnitPriceLength;
	DBLENGTH m_dwUnitsInStockLength;
	DBLENGTH m_dwUnitsOnOrderLength;
	DBLENGTH m_dwReorderLevelLength;
	DBLENGTH m_dwDiscontinuedLength;


	void GetRowsetProperties(CDBPropSet* pPropSet)
	{
		pPropSet->AddProperty(DBPROP_CANFETCHBACKWARDS, true, DBPROPOPTIONS_OPTIONAL);
		pPropSet->AddProperty(DBPROP_CANSCROLLBACKWARDS, true, DBPROPOPTIONS_OPTIONAL);
	}

	HRESULT OpenDataSource()
	{
		CDataSource _db;
		HRESULT hr;
//#error Security Issue: The connection string may contain a password
// 此连接字符串中可能包含密码
// 下面的连接字符串中可能包含明文密码和/或
// 其他重要信息。请在查看完
// 此连接字符串并找到所有与安全有关的问题后移除 #error。可能需要
// 将此密码存储为其他格式或使用其他的用户身份验证。
		hr = _db.OpenFromInitializationString(L"Provider=MSDASQL.1;Persist Security Info=False;Data Source=ENorthwind;Extended Properties=\"DSN=ENorthwind;DBQ=E:\\Visual Studio Projects\\VC++.NET\\Database\\ENorthwind.mdb;DriverId=281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;\"");
		if (FAILED(hr))
		{
#ifdef _DEBUG
			AtlTraceErrorRecords(hr);
#endif
			return hr;
		}
		return m_session.Open(_db);
	}

	void CloseDataSource()
	{
		m_session.Close();
	}

	operator const CSession&()
	{
		return m_session;
	}

	CSession m_session;

	BEGIN_COLUMN_MAP(CS16_01SetAccessor)
		COLUMN_ENTRY_LENGTH_STATUS(1, m_ProductID, m_dwProductIDLength, m_dwProductIDStatus)
		COLUMN_ENTRY_LENGTH_STATUS(2, m_ProductName, m_dwProductNameLength, m_dwProductNameStatus)
		COLUMN_ENTRY_LENGTH_STATUS(3, m_SupplierID, m_dwSupplierIDLength, m_dwSupplierIDStatus)
		COLUMN_ENTRY_LENGTH_STATUS(4, m_CategoryID, m_dwCategoryIDLength, m_dwCategoryIDStatus)
		COLUMN_ENTRY_LENGTH_STATUS(5, m_QuantityPerUnit, m_dwQuantityPerUnitLength, m_dwQuantityPerUnitStatus)
		COLUMN_ENTRY_PS_LENGTH_STATUS(6, 19, 4, m_UnitPrice, m_dwUnitPriceLength, m_dwUnitPriceStatus)
		COLUMN_ENTRY_LENGTH_STATUS(7, m_UnitsInStock, m_dwUnitsInStockLength, m_dwUnitsInStockStatus)
		COLUMN_ENTRY_LENGTH_STATUS(8, m_UnitsOnOrder, m_dwUnitsOnOrderLength, m_dwUnitsOnOrderStatus)
		COLUMN_ENTRY_LENGTH_STATUS(9, m_ReorderLevel, m_dwReorderLevelLength, m_dwReorderLevelStatus)
		_COLUMN_ENTRY_CODE(10, DBTYPE_BOOL, _SIZE_TYPE(m_Discontinued), 0, 0, offsetbuf(m_Discontinued), offsetbuf(m_dwDiscontinuedLength), offsetbuf(m_dwDiscontinuedStatus))
	END_COLUMN_MAP()
};

class CS16_01Set : public CTable<CAccessor<CS16_01SetAccessor> >
{
public:
	HRESULT OpenAll()
	{
		HRESULT hr;
		hr = OpenDataSource();
		if (FAILED(hr))
			return hr;
		__if_exists(GetRowsetProperties)
		{
			CDBPropSet propset(DBPROPSET_ROWSET);
			__if_exists(HasBookmark)
			{
				propset.AddProperty(DBPROP_IRowsetLocate, true);
			}
			GetRowsetProperties(&propset);
			return OpenRowset(&propset);
		}
		__if_not_exists(GetRowsetProperties)
		{
			__if_exists(HasBookmark)
			{
				CDBPropSet propset(DBPROPSET_ROWSET);
				propset.AddProperty(DBPROP_IRowsetLocate, true);
				return OpenRowset(&propset);
			}
		}
		return OpenRowset();
	}

	HRESULT OpenRowset(DBPROPSET *pPropSet = NULL)
	{
		HRESULT hr = Open(m_session, L"Products", pPropSet);
#ifdef _DEBUG
		if(FAILED(hr))
			AtlTraceErrorRecords(hr);
#endif
		return hr;
	}

	void CloseAll()
	{
		Close();
		CloseDataSource();
	}
};

⌨️ 快捷键说明

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