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

书籍源码

开发平台:

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("  SELECT 
  16. DepartmentName, 
  17. Description, 
  18. Count(StudentID) AS NumberOfStudents 
  19. FROM (Department 
  20. INNER JOIN (Class 
  21. INNER JOIN Section 
  22. ON Class.ClassID = Section.ClassID) 
  23. ON Department.DepartmentCode 
  24. = Class.DepartmentCode) 
  25. LEFT JOIN StudentClass 
  26. ON Section.SectionID 
  27. = StudentClass.SectionID 
  28. GROUP BY DepartmentName, 
  29.  Description 
  30. "))
  31. // You may wish to call this function if you are inserting a record and wish to
  32. // initialize all the fields, if you are not going to explicitly set all of them.
  33. void ClearRecord()
  34. {
  35. memset(this, 0, sizeof(*this));
  36. }
  37. };
  38. class CStudentsPerClass : public CCommand<CAccessor<CStudentsPerClassAccessor> >
  39. {
  40. public:
  41. HRESULT Open()
  42. {
  43. HRESULT hr;
  44. hr = OpenDataSource();
  45. if (FAILED(hr))
  46. return hr;
  47. return OpenRowset();
  48. }
  49. HRESULT OpenDataSource()
  50. {
  51. HRESULT hr;
  52. CDataSource db;
  53. CDBPropSet dbinit(DBPROPSET_DBINIT);
  54. 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);
  55. if (FAILED(hr))
  56. return hr;
  57. return m_session.Open(db);
  58. }
  59. HRESULT OpenRowset()
  60. {
  61. return CCommand<CAccessor<CStudentsPerClassAccessor> >::Open(m_session);
  62. }
  63. CSession m_session;
  64. };
  65. #endif // __STUDENTSPERCLASS_H_