home *** CD-ROM | disk | FTP | other *** search
- // DAOEMvw.cpp : implementation of the CDAOEMPView class
- //
-
- #include "stdafx.h"
- #include "DAOEMP.h"
-
- #include "DAOEMdoc.h"
- #include "DAOEMvw.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CDAOEMPView
-
- IMPLEMENT_DYNCREATE(CDAOEMPView, CFormView)
-
- BEGIN_MESSAGE_MAP(CDAOEMPView, CFormView)
- //{{AFX_MSG_MAP(CDAOEMPView)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CDAOEMPView construction/destruction
-
- CDAOEMPView::CDAOEMPView():CFormView(IDD_MAINFORM)
- {
- //{{AFX_DATA_INIT(CDAOEMPView)
- m_nEmpNum = 0;
- m_strFirstName = _T("");
- m_strHomePhone = _T("");
- m_strLastName = _T("");
- m_strNotes = _T("");
- //}}AFX_DATA_INIT
- }
-
- CDAOEMPView::~CDAOEMPView()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDAOEMPView drawing
-
- void CDAOEMPView::OnDraw(CDC* pDC)
- {
- CDAOEMPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- }
-
-
- void CDAOEMPView::DoDataExchange(CDataExchange* pDX)
- {
- // ClassWizard maintains mappings between data of the CDAOEMPView
- // class and the controls in the dialog template resource for this
- // form view.
-
- //{{AFX_DATA_MAP(CDAOEMPView)
- DDX_Text(pDX, IDC_EMPNUM, m_nEmpNum);
- DDV_MinMaxLong(pDX, m_nEmpNum, 1, 999);
- DDX_Text(pDX, IDC_FIRSTNAME, m_strFirstName);
- DDV_MaxChars(pDX, m_strFirstName, 10);
- DDX_Text(pDX, IDC_HOMEPHONE, m_strHomePhone);
- DDV_MaxChars(pDX, m_strHomePhone, 24);
- DDX_Text(pDX, IDC_LASTNAME, m_strLastName);
- DDV_MaxChars(pDX, m_strLastName, 20);
- DDX_Text(pDX, IDC_NOTES, m_strNotes);
- DDX_Text(pDX, IDC_HIREDATE, m_HireDate);
- //}}AFX_DATA_MAP
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CDAOEMPView diagnostics
-
- #ifdef _DEBUG
- void CDAOEMPView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CDAOEMPView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CDAOEMPDoc* CDAOEMPView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDAOEMPDoc)));
- return (CDAOEMPDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CDAOEMPView miscellaneous
-
- void CDAOEMPView::SetFieldStates()
- {
- BOOL bEnabled = TRUE;
- CWnd* pControl;
- CDAOEMPDoc* pDoc = GetDocument();
-
- //If there's no currently connected database, then disable the form
- if(pDoc == NULL || !pDoc->m_bConnected)
- {
- bEnabled = FALSE;
- }
-
- pControl = GetTopWindow() ;
-
- //Disable all controls
- while(pControl != NULL)
- {
- pControl->EnableWindow(bEnabled);
- pControl = pControl->GetNextWindow();
- }
-
- //Never enable the employee ID
- (GetDlgItem(IDC_EMPNUM))->EnableWindow(FALSE);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CDAOEMPView message handlers
-
- void CDAOEMPView::OnInitialUpdate()
- {
- //Disable the fields if no databased attached
- SetFieldStates();
-
- m_pSelection = NULL; // initialize selection
-
- CFormView::OnInitialUpdate();
- }
-
- void CDAOEMPView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- CDAOEMPDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- try
- {
- m_nEmpNum = VTOLONG(pDoc->m_cEmpRecordSet.Fields[EMP_EMPLOYEE_ID].GetValue());
-
- //Convert the variant strings into CStrings
- VarToCStr(&m_strFirstName, &pDoc->m_cEmpRecordSet.Fields[EMP_FIRST_NAME].GetValue());
- VarToCStr(&m_strHomePhone, &pDoc->m_cEmpRecordSet.Fields[EMP_HOME_PHONE].GetValue());
- VarToCStr(&m_strLastName, &pDoc->m_cEmpRecordSet.Fields[EMP_LAST_NAME].GetValue());
- VarToCStr(&m_strNotes, &pDoc->m_cEmpRecordSet.Fields[EMP_NOTES].GetValue());
-
- //COleDateTime
- m_HireDate = pDoc->m_cEmpRecordSet.Fields[EMP_HIRE_DATE].GetValue();
- }
- catch (CdbException e)
- {
- CdbLastOLEError exError;
- TCHAR szBuf[256];
-
- wsprintf(szBuf, _T("Error %d : %s\n"), DBERR(e.m_hr), (LPCTSTR) exError.GetDescription());
- AfxMessageBox(szBuf);
- }
-
- UpdateData(FALSE); //Invoke Data Exchange (copy member data to form controls)
-
- Invalidate(); //Repaint
- }
-
- BOOL CDAOEMPView::CommitAlteredEmpRec()
- {
- CDAOEMPDoc* pDoc = GetDocument();
- CString strOldFirstName, strOldHomePhone, strOldLastName, strOldNotes;
-
- //Get current record string values
- VarToCStr(&strOldFirstName, &pDoc->m_cEmpRecordSet.GetField(EMP_FIRST_NAME));
- VarToCStr(&strOldHomePhone, &pDoc->m_cEmpRecordSet.GetField(EMP_HOME_PHONE));
- VarToCStr(&strOldLastName, &pDoc->m_cEmpRecordSet.GetField(EMP_LAST_NAME));
- VarToCStr(&strOldNotes, &pDoc->m_cEmpRecordSet.GetField(EMP_NOTES));
-
- //Force DDX to update member values
- if(!UpdateData())
- return FALSE;
-
- // Did any fields change value?
- if(
- (m_nEmpNum == VTOLONG(pDoc->m_cEmpRecordSet.GetField(EMP_EMPLOYEE_ID)) ) &&
- (m_strFirstName == strOldFirstName ) &&
- (m_strHomePhone == strOldHomePhone ) &&
- (m_strLastName == strOldLastName ) &&
- (m_strNotes == strOldNotes ) &&
- (m_HireDate == pDoc->m_cEmpRecordSet.GetField(EMP_HIRE_DATE)))
- return TRUE;
-
- //Save it, dump it or stay on it?
- switch (AfxMessageBox(IDS_PROMPT_COMMIT_EMPREC, MB_YESNOCANCEL))
- {
- case IDYES:
- {
- pDoc->UpdateEmpRec( m_nEmpNum,
- m_strFirstName,
- m_strHomePhone,
- m_strLastName,
- m_strNotes,
- (DATE)m_HireDate.m_dt);
- return TRUE;
- }
-
- case IDNO:
- {
- return TRUE;
- }
-
- default:
- {
- GetDlgItem(IDC_EMPNUM)->SetFocus();
- return TRUE;
- }
- }
- }
-
-