StudentsPerClass.H
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:2k
- // StudentsPerClass.H : Declaration of the CStudentsPerClass class
- #ifndef __STUDENTSPERCLASS_H_
- #define __STUDENTSPERCLASS_H_
- class CStudentsPerClassAccessor
- {
- public:
- TCHAR m_DepartmentName[51];
- TCHAR m_Description[51];
- LONG m_NumberOfStudents;
- BEGIN_COLUMN_MAP(CStudentsPerClassAccessor)
- COLUMN_ENTRY(1, m_DepartmentName)
- COLUMN_ENTRY(2, m_Description)
- COLUMN_ENTRY(3, m_NumberOfStudents)
- END_COLUMN_MAP()
- DEFINE_COMMAND(CStudentsPerClassAccessor, _T("
SELECT
- DepartmentName,
- Description,
- Count(StudentID) AS NumberOfStudents
- FROM (Department
- INNER JOIN (Class
- INNER JOIN Section
- ON Class.ClassID = Section.ClassID)
- ON Department.DepartmentCode
- = Class.DepartmentCode)
- LEFT JOIN StudentClass
- ON Section.SectionID
- = StudentClass.SectionID
- GROUP BY DepartmentName,
- Description
- "))
- // 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 CStudentsPerClass : public CCommand<CAccessor<CStudentsPerClassAccessor> >
- {
- 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_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);
- if (FAILED(hr))
- return hr;
- return m_session.Open(db);
- }
- HRESULT OpenRowset()
- {
- return CCommand<CAccessor<CStudentsPerClassAccessor> >::Open(m_session);
- }
- CSession m_session;
- };
- #endif // __STUDENTSPERCLASS_H_