House.H
上传用户:yuxuan88
上传日期:2022-05-09
资源大小:2290k
文件大小:3k
- // House.H : Declaration of the CHouse class
- #ifndef __HOUSE_H_
- #define __HOUSE_H_
- class CHouseAccessor
- {
- public:
- TCHAR m_beeppager[51];
LONG m_buildingnum;
LONG m_cellnum;
TCHAR m_email[51];
TCHAR m_housemaster[51];
TCHAR m_housetel[51];
TCHAR m_mobile[51];
TCHAR m_office[51];
TCHAR m_officetel[51];
LONG m_roomnum;
TCHAR m_sectionname[51];
- BEGIN_COLUMN_MAP(CHouseAccessor)
- COLUMN_ENTRY(1, m_housemaster)
COLUMN_ENTRY(2, m_sectionname)
COLUMN_ENTRY(3, m_buildingnum)
COLUMN_ENTRY(4, m_cellnum)
COLUMN_ENTRY(5, m_roomnum)
COLUMN_ENTRY(6, m_housetel)
COLUMN_ENTRY(7, m_office)
COLUMN_ENTRY(8, m_officetel)
COLUMN_ENTRY(9, m_beeppager)
COLUMN_ENTRY(10, m_mobile)
COLUMN_ENTRY(11, m_email)
END_COLUMN_MAP()
- DEFINE_COMMAND(CHouseAccessor, _T("
SELECT
housemaster,
sectionname,
buildingnum,
cellnum,
roomnum,
housetel,
office,
officetel,
beeppager,
mobile,
email
FROM house"))
- // 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 CHouse : public CCommand<CAccessor<CHouseAccessor> >
- {
- public:
- 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_CACHE_AUTHINFO, true);
dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
dbinit.AddProperty(DBPROP_AUTH_PASSWORD, OLESTR(""));
dbinit.AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));
dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("Inhabitants.mdb"));
dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, OLESTR(""));
dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
// dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
hr = db.Open(_T("Microsoft.Jet.OLEDB.4.0"), &dbinit);
- if (FAILED(hr))
- return hr;
- return m_session.Open(db);
- }
- HRESULT OpenRowset()
- {
- // Set properties for open
- CDBPropSet propset(DBPROPSET_ROWSET);
- propset.AddProperty(DBPROP_IRowsetChange, true);
- propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
- return CCommand<CAccessor<CHouseAccessor> >::Open(m_session, NULL, &propset);
- }
- CSession m_session;
- };
- #endif // __HOUSE_H_