Refresh control with modifications in database |
Post Reply |
Author | |
JoseAngel
Groupie Joined: 21 March 2006 Location: Spain Status: Offline Points: 35 |
Post Options
Thanks(0)
Posted: 16 February 2011 at 12:42pm |
Could be a good idea to modify the CXTPReportDataManager::UpdateReportRecords method to enable the control to show the registers added in the database by other process.
HRESULT CXTPReportDataManager::UpdateReportRecords(XTPREPORTADODB::_RecordsetPtr pRecordset, bool addNewItems/*=false*/) { HRESULT hr = E_FAIL; try { CXTPReportRecords* pRecords = m_pReportControl->GetRecords(); if (!(pRecordset != NULL && pRecords)) return E_FAIL; XTPREPORTADODB::FieldsPtr pFields; if (FAILED(hr = pRecordset->get_Fields(&pFields)) || pFields == NULL) return hr; long lFields; if (FAILED(hr = pFields->get_Count(&lFields)) || lFields == 0) return hr; long lRecords; if (FAILED(hr = pRecordset->get_RecordCount(&lRecords))) return hr; if (lRecords <= 0) return E_FAIL; pRecordset->MoveFirst(); VARIANT_BOOL vtRecordsEof; pRecordset->get_bEOF(&vtRecordsEof); while (!vtRecordsEof) { // get record bookmark VARIANT vtBookmark; if (FAILED(hr = pRecordset->get_Bookmark(&vtBookmark))) break; CXTPReportRecord* pRecord = pRecords->FindRecordByBookmark(vtBookmark, TRUE); if (pRecord) { // get field values VARIANT vtIdx; vtIdx.vt = VT_I4; for (int i = 0; i < lFields; i++) { vtIdx.lVal = i; XTPREPORTADODB::FieldPtr pField; if (FAILED(hr = pFields->get_Item(vtIdx, &pField)) || pField == NULL) break; VARIANT vtValue; if (FAILED(hr = pField->get_Value(&vtValue))) break; CXTPReportRecordItemVariant* pItem = (CXTPReportRecordItemVariant*)pRecord->GetItem(i); if (!pItem) break; pItem->SetValue(COleVariant(vtValue)); } m_pReportControl->UpdateRecord(pRecord, TRUE); } else if(addNewItems) { // create record CXTPReportRecord* pRecord = new CXTPReportRecord; if (!pRecord) break; // get field values VARIANT vtIdx; vtIdx.vt = VT_I4; for (int i = 0; i < lFields; i++) { vtIdx.lVal = i; XTPREPORTADODB::FieldPtr pField; if (FAILED(hr = pFields->get_Item(vtIdx, &pField)) || pField == NULL) break; VARIANT vtValue; if (FAILED(hr = pField->get_Value(&vtValue))) break; CXTPReportRecordItemVariant* pItem = new CXTPReportRecordItemVariant(vtValue); if (!pItem) break; pRecord->AddItem(pItem); } // bind report record to data source record by bookmark VARIANT vtBookmark; if (FAILED(hr = pRecordset->get_Bookmark(&vtBookmark))) break; pRecord->SetBookmark(vtBookmark); // add record to report records collection m_pReportControl->AddRecordEx(pRecord); } pRecordset->MoveNext(); pRecordset->get_bEOF(&vtRecordsEof); } } catch(_com_error &e) { TRACE_ProviderError(m_pConnection); TRACE_ComError(e); hr = FAILED(hr) ? hr : E_FAIL; } catch(...) { TRACE(_T("Unknown error in UpdateReportRecords()\n")); hr = FAILED(hr) ? hr : E_FAIL; } return FAILED(hr) ? hr : S_OK; } |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |