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

书籍源码

开发平台:

Visual C++

  1. // OLEDBMFCMiscView.cpp : implementation of the COLEDBMFCMiscView class
  2. //
  3. #include "stdafx.h"
  4. #include "OLEDBMFCMisc.h"
  5. #include "OLEDBMFCMiscSet.h"
  6. #include "OLEDBMFCMiscDoc.h"
  7. #include "OLEDBMFCMiscView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // COLEDBMFCMiscView
  15. IMPLEMENT_DYNCREATE(COLEDBMFCMiscView, COleDBRecordView)
  16. BEGIN_MESSAGE_MAP(COLEDBMFCMiscView, COleDBRecordView)
  17. //{{AFX_MSG_MAP(COLEDBMFCMiscView)
  18. ON_COMMAND(ID_RECORD_SETBOOKMARK, OnRecordSetbookmark)
  19. ON_COMMAND(ID_RECORD_GOTOBOOKMARK, OnRecordGotobookmark)
  20. ON_COMMAND(ID_RECORD_DISPLAYPOSITION, OnRecordDisplayposition)
  21. ON_COMMAND(ID_RECORD_CHANGEACCESSOR, OnRecordChangeaccessor)
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // COLEDBMFCMiscView construction/destruction
  26. COLEDBMFCMiscView::COLEDBMFCMiscView()
  27. : COleDBRecordView(COLEDBMFCMiscView::IDD)
  28. {
  29. //{{AFX_DATA_INIT(COLEDBMFCMiscView)
  30. // NOTE: the ClassWizard will add member initialization here
  31. m_pSet = NULL;
  32. //}}AFX_DATA_INIT
  33. }
  34. COLEDBMFCMiscView::~COLEDBMFCMiscView()
  35. {
  36. }
  37. void COLEDBMFCMiscView::DoDataExchange(CDataExchange* pDX)
  38. {
  39. COleDBRecordView::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(COLEDBMFCMiscView)
  41. // NOTE: the ClassWizard will add DDX and DDV calls here
  42. //}}AFX_DATA_MAP
  43. DDX_Text(pDX, IDC_COLUMN1, m_pSet->m_strDepartmentCode, 51);
  44. DDX_Text(pDX, IDC_COLUMN2, m_pSet->m_strDepartmentName, 51);
  45. }
  46. BOOL COLEDBMFCMiscView::PreCreateWindow(CREATESTRUCT& cs)
  47. {
  48. return COleDBRecordView::PreCreateWindow(cs);
  49. }
  50. void COLEDBMFCMiscView::OnInitialUpdate()
  51. {
  52. m_pSet = &GetDocument()->m_oLEDBMFCMiscSet;
  53. {
  54. CWaitCursor wait;
  55. HRESULT hr = m_pSet->Open();
  56. if (hr != S_OK)
  57. {
  58. COLEDBErrorChecking::DisplayHRRESULTMessage(hr, "Open");
  59. // AfxMessageBox(_T("Record set failed to open."), MB_OK);
  60. m_bOnFirstRecord = TRUE;
  61. m_bOnLastRecord = TRUE;
  62. }
  63. }
  64. COleDBRecordView::OnInitialUpdate();
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // COLEDBMFCMiscView diagnostics
  68. #ifdef _DEBUG
  69. void COLEDBMFCMiscView::AssertValid() const
  70. {
  71. COleDBRecordView::AssertValid();
  72. }
  73. void COLEDBMFCMiscView::Dump(CDumpContext& dc) const
  74. {
  75. COleDBRecordView::Dump(dc);
  76. }
  77. COLEDBMFCMiscDoc* COLEDBMFCMiscView::GetDocument() // non-debug version is inline
  78. {
  79. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COLEDBMFCMiscDoc)));
  80. return (COLEDBMFCMiscDoc*)m_pDocument;
  81. }
  82. #endif //_DEBUG
  83. /////////////////////////////////////////////////////////////////////////////
  84. // COLEDBMFCMiscView database support
  85. CRowset* COLEDBMFCMiscView::OnGetRowset()
  86. {
  87. return m_pSet;
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // COLEDBMFCMiscView message handlers
  91. //Added by Chuck Wood
  92. //I had to capture the OnMove for the bulk processing
  93. BOOL COLEDBMFCMiscView::OnMove(UINT nIDMoveCommand) 
  94. {
  95. if (nIDMoveCommand == ID_RECORD_NEXT) {
  96. UpdateData(TRUE);
  97. m_pSet->MoveNext();
  98. UpdateData(FALSE);
  99. return TRUE;
  100. }
  101. else 
  102. return COleDBRecordView::OnMove(nIDMoveCommand);
  103. }
  104. //Bookmark processing added by Chuck Wood
  105. void COLEDBMFCMiscView::OnRecordSetbookmark() 
  106. {
  107. //Assign the current row's bookmark to the 
  108. //view bookmark
  109. m_ViewBookmark = m_pSet->m_RowsetBookmark;
  110. }
  111. void COLEDBMFCMiscView::OnRecordGotobookmark() 
  112. {
  113. //Go to the view bookmark and update the window
  114. m_pSet->MoveToBookmark(m_ViewBookmark);
  115. UpdateData(FALSE);
  116. }
  117. void COLEDBMFCMiscView::OnRecordDisplayposition() 
  118. {
  119. //Display the current record
  120. CBookmark<4> tempBookmark;
  121. ULONG ulCurrentRow;
  122. ULONG ulTotalRows;
  123. char strDisplay[50]; //String to display
  124. tempBookmark = m_pSet->m_RowsetBookmark;
  125. m_pSet->GetApproximatePosition(&tempBookmark, 
  126. &ulCurrentRow, &ulTotalRows);
  127. sprintf(strDisplay, "You are at row %d out of %d total rows",
  128. ulCurrentRow, ulTotalRows);
  129. MessageBox(strDisplay, "Column Information");
  130. }
  131. void COLEDBMFCMiscView::OnRecordChangeaccessor() 
  132. {
  133. /*
  134. ULONG numAccessors = GetNumAccessors();
  135. if (m_lRecordInAccessor < 1 &&
  136. numAccessors <= m_lRecordInAccessor) {
  137. m_lRecordInAccessor = 1;
  138. return CCommand<CAccessor<CRowDefinition>, CRowset, CMultipleReoords >
  139. ::MoveNext();
  140. }
  141. else {
  142. m_lRecordInAccessor++;
  143. return GetDataHere(m_lRecordInAccessor, this);
  144. }
  145. */
  146. }