Department.H
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:2k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // Department.H : Declaration of the CDepartment class
  2. #ifndef __DEPARTMENT_H_
  3. #define __DEPARTMENT_H_
  4. class CDepartmentAccessor
  5. {
  6. public:
  7. TCHAR m_DepartmentCode[5]; TCHAR m_DepartmentName[51];
  8. BEGIN_COLUMN_MAP(CDepartmentAccessor)
  9. COLUMN_ENTRY(1, m_DepartmentCode) COLUMN_ENTRY(2, m_DepartmentName) END_COLUMN_MAP()
  10. DEFINE_COMMAND(CDepartmentAccessor, _T("  SELECT  DepartmentCode,  DepartmentName   FROM Department"))
  11. // You may wish to call this function if you are inserting a record and wish to
  12. // initialize all the fields, if you are not going to explicitly set all of them.
  13. void ClearRecord()
  14. {
  15. memset(this, 0, sizeof(*this));
  16. }
  17. };
  18. //Chuck Wood changed class definition to use an array rowset
  19. class CDepartment : 
  20. // public CCommand<CAccessor<CDepartmentAccessor>>
  21. public CCommand<CAccessor<CDepartmentAccessor>, CArrayRowset<CDepartmentAccessor> >
  22. {
  23. public:
  24. HRESULT Open()
  25. {
  26. HRESULT hr;
  27. hr = OpenDataSource();
  28. if (FAILED(hr))
  29. return hr;
  30. return OpenRowset();
  31. }
  32. HRESULT OpenDataSource()
  33. {
  34. HRESULT hr;
  35. CDataSource db;
  36. CDBPropSet dbinit(DBPROPSET_DBINIT);
  37. 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);
  38. if (FAILED(hr))
  39. return hr;
  40. return m_session.Open(db);
  41. }
  42. HRESULT OpenRowset()
  43. {
  44. // Set properties for open
  45. CDBPropSet propset(DBPROPSET_ROWSET);
  46. propset.AddProperty(DBPROP_IRowsetChange, true);
  47. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
  48. //Changed by Chuck Wood to use proper ancestor
  49. return CCommand<CAccessor<CDepartmentAccessor>, CArrayRowset<CDepartmentAccessor> >::Open(m_session, NULL, &propset);
  50. }
  51. CSession m_session;
  52. };
  53. #endif // __DEPARTMENT_H_