home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / bindenrl / coursdlg.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  107 lines

  1. // CoursDlg.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "CoursDlg.h"
  15. #include "Msmask.h"
  16. #include "dblist.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CCoursePage property page
  25.  
  26. // IMPLEMENT_DYNCREATE(CCoursePage, CPropertyPage)
  27.  
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #endif
  31.  
  32. CCoursePage::CCoursePage() : CPropertyPage(CCoursePage::IDD)
  33. {
  34.     m_initiated=FALSE;
  35.     //{{AFX_DATA_INIT(CCoursePage)
  36.     //}}AFX_DATA_INIT
  37. }
  38.  
  39. CCoursePage::~CCoursePage()
  40. {
  41. }
  42.  
  43. void CCoursePage::DoDataExchange(CDataExchange* pDX)
  44. {
  45.     CPropertyPage::DoDataExchange(pDX);
  46.     //{{AFX_DATA_MAP(CCoursePage)
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50. BOOL CCoursePage::OnInitDialog()
  51. {
  52.     CPropertyPage::OnInitDialog();
  53.  
  54.     if(m_pCourseRDC!=NULL)
  55.     {
  56.         LPUNKNOWN pCursor=m_pCourseRDC->GetDSCCursor();
  57.         ASSERT(pCursor!=NULL);
  58.  
  59.         // CString strWnd;
  60.         // m_GridCtrl.SetCaption("Bound to "+": "+m_pRDC->GetCaption());
  61.         GetDlgItem(IDC_COURSE)->BindDefaultProperty(0x16,VT_BSTR,
  62.             _T("CourseID"),m_pCourseRDC);       // bind the edit
  63.         GetDlgItem(IDC_TITLE)->BindDefaultProperty(0x16,VT_BSTR,
  64.             _T("CourseTitle"),m_pCourseRDC);    // bind the edit
  65.         GetDlgItem(IDC_HOURS)->BindDefaultProperty(0x16,VT_BSTR,
  66.             _T("Hours"),m_pCourseRDC);          // bind the edit
  67.  
  68.         m_initiated=TRUE;
  69.         OnCourseChanged(); // adjust the rowset for students
  70.     }
  71.  
  72.     SetModified(TRUE);  // allow the APPLY button to become active
  73.  
  74.     return TRUE;
  75. }
  76.  
  77.  
  78. BEGIN_MESSAGE_MAP(CCoursePage, CPropertyPage)
  79.     //{{AFX_MSG_MAP(CCoursePage)
  80.     //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CCoursePage message handlers
  85.  
  86. BOOL CCoursePage::OnCourseChanged()
  87. {
  88.     if(m_initiated==FALSE)
  89.         return TRUE;
  90.     TRACE(_T("-----------Course changed for students.\n"));
  91.     CRdc* pStudentRDC = (CRdc*) GetDlgItem(IDC_RDCSTUDENT);
  92.     CMSMask* pCourseID = (CMSMask*) GetDlgItem(IDC_COURSE);
  93.     ASSERT(pStudentRDC!=NULL && pCourseID!=NULL);
  94.     if(pStudentRDC!=NULL && pCourseID!=NULL)
  95.     {
  96.         // change the DataSource and refresh everything
  97.         CString strCourseID=pCourseID->GetText();
  98.         CString strSQL=pStudentRDC->GetSql(); // not yet like this
  99.  
  100.         strCourseID=_T("SELECT Student.StudentID, Name, GradYear, Grade, SectionNo from Student,Enrollment WHERE Student.StudentID=Enrollment.StudentID and Enrollment.CourseID='")+strCourseID+_T("'");
  101.         pStudentRDC->SetSql(strCourseID);
  102.         pStudentRDC->Refresh();
  103.         return TRUE;
  104.     }
  105.     return FALSE;
  106. }
  107.