OLEDBDepartmentMFCView.cpp
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:4k
源码类别:
书籍源码
开发平台:
Visual C++
- // OLEDBDepartmentMFCView.cpp : implementation of the COLEDBDepartmentMFCView class
- //
- #include "stdafx.h"
- #include "OLEDBDepartmentMFC.h"
- #include "OLEDBDepartmentMFCSet.h"
- #include "OLEDBDepartmentMFCDoc.h"
- #include "OLEDBDepartmentMFCView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //Added by Chuck Wood for error checking
- #include "..OLEDBErrorCheckingOLEDBErrorChecking.h"
- /////////////////////////////////////////////////////////////////////////////
- // COLEDBDepartmentMFCView
- IMPLEMENT_DYNCREATE(COLEDBDepartmentMFCView, COleDBRecordView)
- BEGIN_MESSAGE_MAP(COLEDBDepartmentMFCView, COleDBRecordView)
- //{{AFX_MSG_MAP(COLEDBDepartmentMFCView)
- ON_EN_CHANGE(IDC_DEPARTMENTCODE, OnChangeDepartmentcode)
- ON_EN_CHANGE(IDC_DEPARTMENTNAME, OnChangeDepartmentname)
- ON_COMMAND(ID_FILE_SAVE, OnFileSave)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // COLEDBDepartmentMFCView construction/destruction
- COLEDBDepartmentMFCView::COLEDBDepartmentMFCView()
- : COleDBRecordView(COLEDBDepartmentMFCView::IDD)
- {
- //{{AFX_DATA_INIT(COLEDBDepartmentMFCView)
- // NOTE: the ClassWizard will add member initialization here
- m_pSet = NULL;
- //}}AFX_DATA_INIT
- m_bChangesMade = FALSE;
- }
- COLEDBDepartmentMFCView::~COLEDBDepartmentMFCView()
- {
- }
- void COLEDBDepartmentMFCView::DoDataExchange(CDataExchange* pDX)
- {
- COleDBRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(COLEDBDepartmentMFCView)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- //Added by Chuck Wood for the data exchange
- DDX_Text(pDX, IDC_DEPARTMENTCODE, m_pSet->m_DepartmentCode, 5);
- DDV_MaxChars(pDX, m_pSet->m_DepartmentCode, 4);
- DDX_Text(pDX, IDC_DEPARTMENTNAME, m_pSet->m_DepartmentName, 51);
- DDV_MaxChars(pDX, m_pSet->m_DepartmentName, 50);
- }
- BOOL COLEDBDepartmentMFCView::PreCreateWindow(CREATESTRUCT& cs)
- {
- return COleDBRecordView::PreCreateWindow(cs);
- }
- void COLEDBDepartmentMFCView::OnInitialUpdate()
- {
- m_pSet = &GetDocument()->m_oLEDBDepartmentMFCSet;
- {
- CWaitCursor wait;
- HRESULT hr = m_pSet->Open();
- if (hr != S_OK)
- {
- AfxMessageBox(_T("Record set failed to open."), MB_OK);
- m_bOnFirstRecord = TRUE;
- m_bOnLastRecord = TRUE;
- }
- }
- COleDBRecordView::OnInitialUpdate();
- }
- /////////////////////////////////////////////////////////////////////////////
- // COLEDBDepartmentMFCView diagnostics
- #ifdef _DEBUG
- void COLEDBDepartmentMFCView::AssertValid() const
- {
- COleDBRecordView::AssertValid();
- }
- void COLEDBDepartmentMFCView::Dump(CDumpContext& dc) const
- {
- COleDBRecordView::Dump(dc);
- }
- COLEDBDepartmentMFCDoc* COLEDBDepartmentMFCView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COLEDBDepartmentMFCDoc)));
- return (COLEDBDepartmentMFCDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // COLEDBDepartmentMFCView database support
- CRowset* COLEDBDepartmentMFCView::OnGetRowset()
- {
- return m_pSet;
- }
- /////////////////////////////////////////////////////////////////////////////
- // COLEDBDepartmentMFCView message handlers
- void COLEDBDepartmentMFCView::OnDestroy()
- {
- if (m_bChangesMade) {
- //Yes was chosen. Save out record
- if (AfxMessageBox(
- "Do you want to save changes to the database?",
- MB_YESNO) == IDYES) {
- UpdateData(TRUE);
- m_pSet->SetData();
- OnFileSave();
- }
- }
- COleDBRecordView::OnDestroy();
- }
- void COLEDBDepartmentMFCView::OnFileSave()
- {
- if (m_bChangesMade) {
- m_bChangesMade = FALSE;
- HRESULT hr = m_pSet->Update();
- if (!SUCCEEDED(hr)) {
- COLEDBErrorChecking::DisplaySingleError(hr, "Update in the OnFileSave");
- }
- }
- }
- void COLEDBDepartmentMFCView::OnChangeDepartmentcode()
- {
- m_bChangesMade = TRUE;
- }
- void COLEDBDepartmentMFCView::OnChangeDepartmentname()
- {
- m_bChangesMade = TRUE;
- }