home *** CD-ROM | disk | FTP | other *** search
- // EmployeeView.cpp : implementation of the CEmployeeView class
- //
-
- #include "stdafx.h"
- #include "Employee.h"
-
- #include "EmployeePaySet.h"
- #include "EmployeePersonalSet.h"
-
- #include "EmployeeDoc.h"
- #include "EmployeeView.h"
- #include "EmployeeDDX.cpp"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CEmployeeView
-
-
- IMPLEMENT_DYNCREATE(CEmployeeView, CRecordView)
-
- BEGIN_MESSAGE_MAP(CEmployeeView, CRecordView)
- //{{AFX_MSG_MAP(CEmployeeView)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CEmployeeView construction/destruction
-
- CEmployeeView::CEmployeeView()
- : CRecordView(CEmployeeView::IDD)
- {
- //{{AFX_DATA_INIT(CEmployeeView)
- m_pSet = NULL;
- m_pEmplInfoSet = NULL;
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- }
-
- CEmployeeView::~CEmployeeView()
- {
- }
-
- void CEmployeeView::DoDataExchange(CDataExchange* pDX)
- {
- CRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CEmployeeView)
- DDX_FieldText(pDX, IDC_FNAME, m_pSet->m_First_Name, m_pSet);
- DDX_FieldText(pDX, IDC_LNAME, m_pSet->m_Last_Name, m_pSet);
- DDX_FieldText(pDX, IDC_EMP_NO, m_pSet->m_Employee_Number, m_pSet);
- DDX_FieldText(pDX, IDC_DEPT, m_pSet->m_Department__, m_pSet);
- DDX_FieldText(pDX, IDC_PAY_TYPE, m_pSet->m_Employee_Pay_Type, m_pSet);
- DDX_FieldText(pDX, IDC_HOUR_RATE, m_pSet->m_Hourly_Rate, m_pSet);
- //}}AFX_DATA_MAP
-
- //Ensure pointer is valid
- if ( NULL != m_pEmplInfoSet )
- {
- DDX_FieldText(pDX, IDC_BIRTH, m_pEmplInfoSet->m_Birthdate, m_pEmplInfoSet);
- DDV_Date( pDX, m_pEmplInfoSet->m_Birthdate, m_pEmplInfoSet );
- DDX_FieldText(pDX, IDC_MARITAL_STATUS, m_pEmplInfoSet->m_Sex___Marital_Status, m_pEmplInfoSet);
- DDX_FieldText(pDX, IDC_HEIGHT, m_pEmplInfoSet->m_Height, m_pEmplInfoSet);
- DDX_FieldText(pDX, IDC_WEIGHT, m_pEmplInfoSet->m_Weight, m_pEmplInfoSet);
- }
- }
-
- BOOL CEmployeeView::PreCreateWindow(CREATESTRUCT& cs)
- {
- return CRecordView::PreCreateWindow(cs);
- }
-
- void CEmployeeView::OnInitialUpdate()
- {
- // AppWizard provided this line.
- // m_pSet = &GetDocument( )->m_employeePaySet;
-
- // Best to replace it with an accessor function.
- m_pSet = GetDocument( )->GetEmployeePaySet( );
-
- m_pEmplInfoSet = GetDocument( )->GetEmployeeInfoSet( );
- GetParentFrame( )->RecalcLayout( );
- ResizeParentToFit( FALSE );
-
- try
- {
- //Open the primary table
- m_pSet->Open( );
- m_pEmplInfoSet->m_EmployeeNumberParam
- = m_pSet->m_Employee_Number; //Set join param
- //Open foreign table
- m_pEmplInfoSet->Open( );
- }
- catch( CException * pEx )
- {
- pEx->ReportError( );
- pEx->Delete( );
- return;
- }
-
- UpdateData( FALSE );
-
- CRecordView::OnInitialUpdate( );
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CEmployeeView diagnostics
-
- #ifdef _DEBUG
- void CEmployeeView::AssertValid() const
- {
- CRecordView::AssertValid();
- }
-
- void CEmployeeView::Dump(CDumpContext& dc) const
- {
- CRecordView::Dump(dc);
- }
-
- CEmployeeDoc* CEmployeeView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmployeeDoc)));
- return (CEmployeeDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CEmployeeView database support
- CRecordset* CEmployeeView::OnGetRecordset()
- {
- return m_pSet;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CEmployeeView message handlers
-
- BOOL CEmployeeView::OnMove(UINT nIDMoveCommand)
- {
- if ( ! UpdateData( TRUE ) )
- return FALSE; //Bad data: We don't want to move
- m_pSet->SetFieldDirty( NULL ); //Otherwise DB update won't occur
-
- BOOL bMove = CRecordView::OnMove(nIDMoveCommand); //Primary table updated
-
- if ( bMove ) //If successful update the foreign info
- {
- m_pEmplInfoSet->Edit( ); //Turn on edit mode
- m_pEmplInfoSet->SetFieldDirty( NULL ); //Mark the fields dirty
- m_pEmplInfoSet->Update( );
- m_pEmplInfoSet->m_EmployeeNumberParam =
- m_pSet->m_Employee_Number;
- m_pEmplInfoSet->Requery( ); //Find foreign record
- UpdateData( FALSE ); //Display foreign record
- }
- return bMove;
- }
-