OLEDBDepartmentMFCView.cpp
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:4k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // OLEDBDepartmentMFCView.cpp : implementation of the COLEDBDepartmentMFCView class
  2. //
  3. #include "stdafx.h"
  4. #include "OLEDBDepartmentMFC.h"
  5. #include "OLEDBDepartmentMFCSet.h"
  6. #include "OLEDBDepartmentMFCDoc.h"
  7. #include "OLEDBDepartmentMFCView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. //Added by Chuck Wood for error checking
  14. #include "..OLEDBErrorCheckingOLEDBErrorChecking.h"
  15. /////////////////////////////////////////////////////////////////////////////
  16. // COLEDBDepartmentMFCView
  17. IMPLEMENT_DYNCREATE(COLEDBDepartmentMFCView, COleDBRecordView)
  18. BEGIN_MESSAGE_MAP(COLEDBDepartmentMFCView, COleDBRecordView)
  19. //{{AFX_MSG_MAP(COLEDBDepartmentMFCView)
  20. ON_EN_CHANGE(IDC_DEPARTMENTCODE, OnChangeDepartmentcode)
  21. ON_EN_CHANGE(IDC_DEPARTMENTNAME, OnChangeDepartmentname)
  22. ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  23. ON_WM_DESTROY()
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // COLEDBDepartmentMFCView construction/destruction
  28. COLEDBDepartmentMFCView::COLEDBDepartmentMFCView()
  29. : COleDBRecordView(COLEDBDepartmentMFCView::IDD)
  30. {
  31. //{{AFX_DATA_INIT(COLEDBDepartmentMFCView)
  32. // NOTE: the ClassWizard will add member initialization here
  33. m_pSet = NULL;
  34. //}}AFX_DATA_INIT
  35. m_bChangesMade = FALSE;
  36. }
  37. COLEDBDepartmentMFCView::~COLEDBDepartmentMFCView()
  38. {
  39. }
  40. void COLEDBDepartmentMFCView::DoDataExchange(CDataExchange* pDX)
  41. {
  42. COleDBRecordView::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(COLEDBDepartmentMFCView)
  44. // NOTE: the ClassWizard will add DDX and DDV calls here
  45. //}}AFX_DATA_MAP
  46. //Added by Chuck Wood for the data exchange
  47.     DDX_Text(pDX, IDC_DEPARTMENTCODE, m_pSet->m_DepartmentCode, 5);
  48.     DDV_MaxChars(pDX, m_pSet->m_DepartmentCode, 4);
  49.     DDX_Text(pDX, IDC_DEPARTMENTNAME, m_pSet->m_DepartmentName, 51);
  50.     DDV_MaxChars(pDX, m_pSet->m_DepartmentName, 50);
  51. }
  52. BOOL COLEDBDepartmentMFCView::PreCreateWindow(CREATESTRUCT& cs)
  53. {
  54. return COleDBRecordView::PreCreateWindow(cs);
  55. }
  56. void COLEDBDepartmentMFCView::OnInitialUpdate()
  57. {
  58. m_pSet = &GetDocument()->m_oLEDBDepartmentMFCSet;
  59. {
  60. CWaitCursor wait;
  61. HRESULT hr = m_pSet->Open();
  62. if (hr != S_OK)
  63. {
  64. AfxMessageBox(_T("Record set failed to open."), MB_OK);
  65. m_bOnFirstRecord = TRUE;
  66. m_bOnLastRecord = TRUE;
  67. }
  68. }
  69. COleDBRecordView::OnInitialUpdate();
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // COLEDBDepartmentMFCView diagnostics
  73. #ifdef _DEBUG
  74. void COLEDBDepartmentMFCView::AssertValid() const
  75. {
  76. COleDBRecordView::AssertValid();
  77. }
  78. void COLEDBDepartmentMFCView::Dump(CDumpContext& dc) const
  79. {
  80. COleDBRecordView::Dump(dc);
  81. }
  82. COLEDBDepartmentMFCDoc* COLEDBDepartmentMFCView::GetDocument() // non-debug version is inline
  83. {
  84. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COLEDBDepartmentMFCDoc)));
  85. return (COLEDBDepartmentMFCDoc*)m_pDocument;
  86. }
  87. #endif //_DEBUG
  88. /////////////////////////////////////////////////////////////////////////////
  89. // COLEDBDepartmentMFCView database support
  90. CRowset* COLEDBDepartmentMFCView::OnGetRowset()
  91. {
  92. return m_pSet;
  93. }
  94. /////////////////////////////////////////////////////////////////////////////
  95. // COLEDBDepartmentMFCView message handlers
  96. void COLEDBDepartmentMFCView::OnDestroy() 
  97. {
  98.     if (m_bChangesMade) {
  99.         //Yes was chosen. Save out record
  100.         if (AfxMessageBox(
  101.             "Do you want to save changes to the database?",
  102.             MB_YESNO) == IDYES) {
  103.     UpdateData(TRUE);
  104. m_pSet->SetData();
  105.             OnFileSave();
  106.         }
  107.     }
  108. COleDBRecordView::OnDestroy();
  109. }
  110. void COLEDBDepartmentMFCView::OnFileSave() 
  111. {
  112.     if (m_bChangesMade) {
  113.         m_bChangesMade = FALSE;
  114. HRESULT hr = m_pSet->Update();
  115. if (!SUCCEEDED(hr)) {
  116. COLEDBErrorChecking::DisplaySingleError(hr, "Update in the OnFileSave");
  117. }
  118.     }
  119. }
  120. void COLEDBDepartmentMFCView::OnChangeDepartmentcode() 
  121. {
  122.     m_bChangesMade = TRUE;
  123. }
  124. void COLEDBDepartmentMFCView::OnChangeDepartmentname() 
  125. {
  126.     m_bChangesMade = TRUE;
  127. }