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

书籍源码

开发平台:

Visual C++

  1. // StudentsPerClass.H : Declaration of the CStudentsPerClass class
  2. #ifndef __STUDENTSPERCLASS_H_
  3. #define __STUDENTSPERCLASS_H_
  4. class CStudentsPerClassAccessor
  5. {
  6. public:
  7. TCHAR m_DepartmentName[51];
  8. TCHAR m_Description[51];
  9. LONG m_NumberOfStudents;
  10. BEGIN_COLUMN_MAP(CStudentsPerClassAccessor)
  11. COLUMN_ENTRY(1, m_DepartmentName)
  12. COLUMN_ENTRY(2, m_Description)
  13. COLUMN_ENTRY(3, m_NumberOfStudents)
  14. END_COLUMN_MAP()
  15. DEFINE_COMMAND(CStudentsPerClassAccessor, _T(" 
  16. SELECT 
  17. DepartmentName, 
  18. Description, 
  19. Count(StudentID) AS NumberOfStudents 
  20. FROM (Department 
  21. INNER JOIN (Class 
  22. INNER JOIN Section 
  23. ON Class.ClassID = Section.ClassID) 
  24. ON Department.DepartmentCode 
  25. = Class.DepartmentCode) 
  26. LEFT JOIN StudentClass 
  27. ON Section.SectionID 
  28. = StudentClass.SectionID 
  29. GROUP BY DepartmentName, 
  30.  Description 
  31. "))
  32. /*
  33. DEFINE_COMMAND(CStudentsPerClassAccessor, _T("  SELECT 
  34. DepartmentName, 
  35. Description, 
  36. Count(StudentID) AS NumberOfStudents 
  37. FROM ((Department 
  38. INNER JOIN (Class 
  39. INNER JOIN Section 
  40. ON Class.ClassID = Section.ClassID) 
  41. ON Department.DepartmentCode 
  42. = Class.DepartmentCode) 
  43. LEFT JOIN StudentClass 
  44. ON Section.SectionID 
  45. = StudentClass.SectionID 
  46. GROUP BY DepartmentName, 
  47.  Description 
  48. "))
  49. */
  50. CStudentsPerClassAccessor () //Constructor added by cw
  51. {
  52. ClearRecord();
  53. }
  54. // You may wish to call this function if you are inserting a record and wish to
  55. // initialize all the fields, if you are not going to explicitly set all of them.
  56. void ClearRecord()
  57. {
  58. memset(this, 0, sizeof(*this));
  59. }
  60. };
  61. class CStudentsPerClass : public CCommand<CAccessor<CStudentsPerClassAccessor> >
  62. {
  63. public:
  64. HRESULT Open()
  65. {
  66. CDataSource db;
  67. CSession session;
  68. HRESULT hr;
  69. CDBPropSet dbinit(DBPROPSET_DBINIT);
  70. dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
  71. dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
  72. dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
  73. dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
  74. dbinit.AddProperty(DBPROP_AUTH_PERSIST_ENCRYPTED, false);
  75. dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
  76. dbinit.AddProperty(DBPROP_AUTH_USERID, "Admin");
  77. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "C:\My Documents\Visual C++\Classes.mdb");
  78. dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
  79. dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
  80. dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, ";COUNTRY=0;CP=1252;LANGID=0x0409");
  81. dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
  82. hr = db.OpenWithServiceComponents("Microsoft.Jet.OLEDB.3.51", &dbinit);
  83. if (FAILED(hr))
  84. return hr;
  85. hr = session.Open(db);
  86. if (FAILED(hr))
  87. return hr;
  88. CDBPropSet propset(DBPROPSET_ROWSET);
  89. propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
  90. propset.AddProperty(DBPROP_IRowsetScroll, true);
  91. propset.AddProperty(DBPROP_IRowsetChange, true);
  92. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
  93. hr = CCommand<CAccessor<CStudentsPerClassAccessor> >::Open(session, NULL, &propset);
  94. if (FAILED(hr))
  95. return hr;
  96. return MoveFirst();
  97. }
  98. };
  99. #endif // __STUDENTSPERCLASS_H_