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

书籍源码

开发平台:

Visual C++

  1. // Department.H : Declaration of the CDepartment class
  2. #ifndef __DEPARTMENT_H_
  3. #define __DEPARTMENT_H_
  4. //Added by Chuck Wood for error checking
  5. #include "..OLEDBErrorCheckingOLEDBErrorChecking.h"
  6. class CDepartmentAccessor
  7. {
  8. public:
  9. TCHAR m_DepartmentCode[5]; TCHAR m_DepartmentName[51];
  10. BEGIN_COLUMN_MAP(CDepartmentAccessor)
  11. COLUMN_ENTRY(1, m_DepartmentCode) COLUMN_ENTRY(2, m_DepartmentName) END_COLUMN_MAP()
  12. DEFINE_COMMAND(CDepartmentAccessor, _T("  SELECT  DepartmentCode,  DepartmentName   FROM Department"))
  13. // You may wish to call this function if you are inserting a record and wish to
  14. // initialize all the fields, if you are not going to explicitly set all of them.
  15. void ClearRecord()
  16. {
  17. memset(this, 0, sizeof(*this));
  18. }
  19. };
  20. class CDepartment : public CCommand<CAccessor<CDepartmentAccessor> >
  21. {
  22. public:
  23. //Constructor added by Chuck Wood
  24. CDepartment () {
  25. //Allow 1 k for SQL WHERE clause
  26. m_strFilter = new char[1];
  27. strcpy (m_strFilter, "");
  28. }
  29. //Destructor added by Chuck Wood
  30. ~CDepartment () {
  31. //Release resources
  32. delete m_strFilter;
  33. }
  34. HRESULT Open()
  35. {
  36. HRESULT hr;
  37. hr = OpenDataSource();
  38. if (FAILED(hr))
  39. return hr;
  40. return OpenRowset();
  41. }
  42. HRESULT OpenDataSource()
  43. {
  44. HRESULT hr;
  45. CDataSource db;
  46. CDBPropSet dbinit(DBPROPSET_DBINIT);
  47. 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_PERSIST_ENCRYPTED, false); dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false); dbinit.AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin")); dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("C:\My Documents\Visual C++\Classes.MDB")); dbinit.AddProperty(DBPROP_INIT_MODE, (long)16); dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4); dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, OLESTR(";COUNTRY=0;CP=1252;LANGID=0x0409")); dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033); hr = db.Open(_T("Microsoft.Jet.OLEDB.3.51"), &dbinit);
  48. if (FAILED(hr))
  49. return hr;
  50. return m_session.Open(db);
  51. }
  52. HRESULT OpenRowset()
  53. {
  54. // Set properties for open
  55. CDBPropSet propset(DBPROPSET_ROWSET);
  56. propset.AddProperty(DBPROP_IRowsetChange, true);
  57. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);
  58. //The rest of this function was added by Chuck Wood
  59. //Allow 512 bytes for the new SQL Command
  60. char newSQL[512];
  61. char *SQLCommand;
  62. GetDefaultCommand((const char **) &SQLCommand);
  63. strcpy(newSQL, SQLCommand);
  64. if (strlen(m_strFilter)) {
  65. strcat(newSQL, " WHERE ");
  66. strcat(newSQL, m_strFilter);
  67. }
  68. return CCommand<CAccessor<CDepartmentAccessor> >
  69. ::Open(m_session, newSQL, &propset);
  70. }
  71. char   *m_strFilter;
  72. CSession m_session;
  73. };
  74. #endif // __DEPARTMENT_H_