home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / tutorial / enroll / step2 / sectform.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.3 KB  |  172 lines

  1. // SectForm.cpp : implementation of the CSectionForm class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Enroll.h"
  6.  
  7. #include "SectSet.h"
  8. #include "CoursSet.h"
  9. #include "EnrolDoc.h"
  10. #include "SectForm.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSectionForm
  20.  
  21. IMPLEMENT_DYNCREATE(CSectionForm, CRecordView)
  22.  
  23. BEGIN_MESSAGE_MAP(CSectionForm, CRecordView)
  24.  
  25.  
  26.     //{{AFX_MSG_MAP(CSectionForm)
  27.     ON_CBN_SELENDOK(IDC_COURSELIST, OnSelendokCourselist)
  28.     //}}AFX_MSG_MAP
  29.     // Standard printing commands
  30.     ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
  31.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
  32.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
  33. END_MESSAGE_MAP()
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CSectionForm construction/destruction
  37.  
  38. CSectionForm::CSectionForm()
  39.     : CRecordView(CSectionForm::IDD)
  40. {
  41.     //{{AFX_DATA_INIT(CSectionForm)
  42.     m_pSet = NULL;
  43.     //}}AFX_DATA_INIT
  44.     // TODO: add construction code here
  45.  
  46. }
  47.  
  48. CSectionForm::~CSectionForm()
  49. {
  50. }
  51.  
  52. void CSectionForm::DoDataExchange(CDataExchange* pDX)
  53. {
  54.     CRecordView::DoDataExchange(pDX);
  55.     //{{AFX_DATA_MAP(CSectionForm)
  56.     DDX_Control(pDX, IDC_COURSELIST, m_ctlCourseList);
  57.     DDX_FieldText(pDX, IDC_SECTION, m_pSet->m_SectionNo, m_pSet);
  58.     DDX_FieldText(pDX, IDC_INSTRUCTOR, m_pSet->m_InstructorID, m_pSet);
  59.     DDX_FieldText(pDX, IDC_ROOM, m_pSet->m_RoomNo, m_pSet);
  60.     DDX_FieldText(pDX, IDC_SCHEDULE, m_pSet->m_Schedule, m_pSet);
  61.     DDX_FieldText(pDX, IDC_CAPACITY, m_pSet->m_Capacity, m_pSet);
  62.     DDX_FieldCBString(pDX, IDC_COURSELIST, m_pSet->m_CourseID, m_pSet);
  63.     //}}AFX_DATA_MAP
  64. }
  65.  
  66. BOOL CSectionForm::PreCreateWindow(CREATESTRUCT& cs)
  67. {
  68.     // TODO: Modify the Window class or styles here by modifying
  69.     //  the CREATESTRUCT cs
  70.  
  71.     return CRecordView::PreCreateWindow(cs);
  72. }
  73.  
  74. void CSectionForm::OnInitialUpdate()
  75. {
  76.     m_pSet = &GetDocument()->m_sectionSet;
  77.  
  78.     // Fill the combo box with all of the courses
  79.  
  80.     CEnrollDoc* pDoc = GetDocument();
  81.     pDoc->m_courseSet.m_strSort = "CourseID";
  82.     if (!pDoc->m_courseSet.Open())
  83.         return;
  84.  
  85.     // Filter, parameterize and sort the course recordset
  86.     m_pSet->m_strFilter = "CourseID = ?";
  87.     m_pSet->m_strCourseIDParam = pDoc->m_courseSet.m_CourseID;
  88.     m_pSet->m_strSort = "SectionNo";
  89.     m_pSet->m_pDatabase = pDoc->m_courseSet.m_pDatabase;
  90.  
  91.     CRecordView::OnInitialUpdate();
  92.  
  93.     m_ctlCourseList.ResetContent();
  94.     if (pDoc->m_courseSet.IsOpen())
  95.     {
  96.         while (!pDoc->m_courseSet.IsEOF())
  97.         {
  98.             m_ctlCourseList.AddString(
  99.                 pDoc->m_courseSet.m_CourseID);
  100.             pDoc->m_courseSet.MoveNext();
  101.         }
  102.     }
  103.     m_ctlCourseList.SetCurSel(0);
  104. }
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CSectionForm printing
  108.  
  109. BOOL CSectionForm::OnPreparePrinting(CPrintInfo* pInfo)
  110. {
  111.     // default preparation
  112.     return DoPreparePrinting(pInfo);
  113. }
  114.  
  115. void CSectionForm::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  116. {
  117.     // TODO: add extra initialization before printing
  118. }
  119.  
  120. void CSectionForm::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  121. {
  122.     // TODO: add cleanup after printing
  123. }
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CSectionForm diagnostics
  127.  
  128. #ifdef _DEBUG
  129. void CSectionForm::AssertValid() const
  130. {
  131.     CRecordView::AssertValid();
  132. }
  133.  
  134. void CSectionForm::Dump(CDumpContext& dc) const
  135. {
  136.     CRecordView::Dump(dc);
  137. }
  138.  
  139. CEnrollDoc* CSectionForm::GetDocument() // non-debug version is inline
  140. {
  141.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEnrollDoc)));
  142.     return (CEnrollDoc*)m_pDocument;
  143. }
  144. #endif //_DEBUG
  145.  
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CSectionForm database support
  148. CRecordset* CSectionForm::OnGetRecordset()
  149. {
  150.     return m_pSet;
  151. }
  152.  
  153.  
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CSectionForm message handlers
  156.  
  157.  
  158. void CSectionForm::OnSelendokCourselist()
  159. {
  160.     if (!m_pSet->IsOpen())
  161.         return;
  162.     m_ctlCourseList.GetLBText(m_ctlCourseList.GetCurSel(),
  163.         m_pSet->m_strCourseIDParam);
  164.     m_pSet->Requery();
  165.     if (m_pSet->IsEOF())
  166.     {
  167.         m_pSet->SetFieldNull(&(m_pSet->m_CourseID), FALSE);
  168.         m_pSet->m_CourseID = m_pSet->m_strCourseIDParam;
  169.     }
  170.     UpdateData(FALSE);
  171. }
  172.