home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c08 / lab02 / ex01 / employeeview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  4.6 KB  |  176 lines

  1. // EmployeeView.cpp : implementation of the CEmployeeView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Employee.h"
  6.  
  7. #include "EmployeePaySet.h"
  8. #include "EmployeePersonalSet.h"
  9. #include "EmployeeDoc.h"
  10. #include "EmployeeView.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. // CEmployeeView
  20.  
  21. IMPLEMENT_DYNCREATE(CEmployeeView, CDaoRecordView)
  22.  
  23. BEGIN_MESSAGE_MAP(CEmployeeView, CDaoRecordView)
  24.     //{{AFX_MSG_MAP(CEmployeeView)
  25.         // NOTE - the ClassWizard will add and remove mapping macros here.
  26.         //    DO NOT EDIT what you see in these blocks of generated code!
  27.     //}}AFX_MSG_MAP
  28.     // Standard printing commands
  29.     ON_COMMAND(ID_FILE_PRINT, CDaoRecordView::OnFilePrint)
  30.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CDaoRecordView::OnFilePrint)
  31.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CDaoRecordView::OnFilePrintPreview)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CEmployeeView construction/destruction
  36.  
  37. CEmployeeView::CEmployeeView()
  38.     : CDaoRecordView(CEmployeeView::IDD)
  39. {
  40.     //{{AFX_DATA_INIT(CEmployeeView)
  41.     m_pSet = NULL;
  42.     //}}AFX_DATA_INIT
  43.     // TODO: add construction code here
  44.  
  45. }
  46.  
  47. CEmployeeView::~CEmployeeView()
  48. {
  49. }
  50.  
  51. void CEmployeeView::DoDataExchange(CDataExchange* pDX)
  52. {
  53.     CDaoRecordView::DoDataExchange(pDX);
  54.     //{{AFX_DATA_MAP(CEmployeeView)
  55.     DDX_FieldText(pDX, IDC_FNAME, m_pSet->m_First_Name, m_pSet);
  56.     DDX_FieldText(pDX, IDC_LNAME, m_pSet->m_Last_Name, m_pSet);
  57.     DDX_FieldText(pDX, IDC_EMP_NO, m_pSet->m_Employee_Number, m_pSet);
  58.     DDX_FieldText(pDX, IDC_DEPT, m_pSet->m_Department__, m_pSet);
  59.     DDX_FieldText(pDX, IDC_PAY_TYPE, m_pSet->m_Employee_Pay_Type, m_pSet);
  60.     DDX_FieldText(pDX, IDC_HOUR_RATE, m_pSet->m_Hourly_Rate, m_pSet);
  61.     //}}AFX_DATA_MAP
  62.  
  63.     //    Make sure this dataset pointer has been setup before trying
  64.     //    to access it.
  65.     if(m_pEmplInfoSet != NULL)
  66.     {
  67.         DDX_FieldText(pDX, IDC_BIRTH, m_pEmplInfoSet->m_Birthdate, m_pEmplInfoSet);
  68.         DDX_FieldText(pDX, IDC_MARITAL_STATUS, m_pEmplInfoSet->m_Sex___Marital_Status, m_pEmplInfoSet);
  69.         DDX_FieldText(pDX, IDC_HEIGHT, m_pEmplInfoSet->m_Height, m_pEmplInfoSet);
  70.         DDX_FieldText(pDX, IDC_WEIGHT, m_pEmplInfoSet->m_Weight, m_pEmplInfoSet);
  71.     }
  72.  
  73. }
  74.  
  75. BOOL CEmployeeView::PreCreateWindow(CREATESTRUCT& cs)
  76. {
  77.     // TODO: Modify the Window class or styles here by modifying
  78.     //  the CREATESTRUCT cs
  79.  
  80.     return CDaoRecordView::PreCreateWindow(cs);
  81. }
  82.  
  83. void CEmployeeView::OnInitialUpdate()
  84. {
  85.     m_pSet            = GetDocument()->GetEmployeePaySet();
  86.     m_pEmplInfoSet    = GetDocument()->GetEmployeeInfoSet();
  87.  
  88.     CDaoRecordView::OnInitialUpdate();
  89.  
  90.     //resize the window
  91.     GetParentFrame()->RecalcLayout();
  92.     ResizeParentToFit(FALSE);
  93.  
  94.     //set the parameter for the info query
  95.     m_pEmplInfoSet->m_EmployeeNumberParam = m_pSet->m_Employee_Number;
  96.  
  97.     //open the Info record set
  98.     try
  99.     {
  100.         m_pEmplInfoSet->Open();
  101.     }
  102.     catch (CDaoException* e)
  103.     {
  104.         AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  105.         e->Delete();
  106.         return;
  107.     }
  108.  
  109.     UpdateData(FALSE);
  110. }
  111.  
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CEmployeeView printing
  114.  
  115. BOOL CEmployeeView::OnPreparePrinting(CPrintInfo* pInfo)
  116. {
  117.     // default preparation
  118.     return DoPreparePrinting(pInfo);
  119. }
  120.  
  121. void CEmployeeView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  122. {
  123.     // TODO: add extra initialization before printing
  124. }
  125.  
  126. void CEmployeeView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  127. {
  128.     // TODO: add cleanup after printing
  129. }
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CEmployeeView diagnostics
  133.  
  134. #ifdef _DEBUG
  135. void CEmployeeView::AssertValid() const
  136. {
  137.     CDaoRecordView::AssertValid();
  138. }
  139.  
  140. void CEmployeeView::Dump(CDumpContext& dc) const
  141. {
  142.     CDaoRecordView::Dump(dc);
  143. }
  144.  
  145. CEmployeeDoc* CEmployeeView::GetDocument() // non-debug version is inline
  146. {
  147.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmployeeDoc)));
  148.     return (CEmployeeDoc*)m_pDocument;
  149. }
  150. #endif //_DEBUG
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CEmployeeView database support
  154. CDaoRecordset* CEmployeeView::OnGetRecordset()
  155. {
  156.     return m_pSet;
  157. }
  158.  
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CEmployeeView message handlers
  161. BOOL CEmployeeView::OnMove(UINT nIDMoveCommand) 
  162. {
  163.     CDaoRecordView::OnMove(nIDMoveCommand);
  164.  
  165.     //set the parameter for the info query
  166.     m_pEmplInfoSet->m_EmployeeNumberParam = m_pSet->m_Employee_Number;
  167.  
  168.     //do the secondary query
  169.     m_pEmplInfoSet->Requery();
  170.  
  171.     UpdateData(FALSE);
  172.  
  173.     return TRUE;
  174. }
  175.  
  176.