Skip to Content
0
Former Member
May 03, 2011 at 04:43 PM

CR XI - connect to dynamic XML-Datasource via VC++

51 Views

Hello,

i hope, somebody can help me.

I've a report which should read the date from an xml-File, which is build by our applicatio during runtime.

the Report Viewer should read this and show this data in our application.

But it shows only the data from the original xml-file, which i used during development for the .rpt-file (this one you define with Database Connection XML: path to an XML-file and a XSD-file).

Should i have to do something in the rpt-file or is someting missing vin VC++-Code ?

Here is the code from VC++:

CString strReportFile = _rptFileName;

ASSERT(strReportFile.GetLength());

bstrt FileName(strReportFile.AllocSysString());//in BSTR wandeln

// Handle auf report holen

m_Report = m_Application->OpenReport(FileName);

// Laut Aussage Wr nicht notwendig. Im Umfeld von TCS gibt's hiermit Abstürze.

// SysFreeString(FileName);

// Viewer darauf setzen

m_Viewer.SetReportSource(m_Report);

try {

CString strDBName = _xmlFileName;//pReportDataObject->GetActualDBFileName();

CString sTableName;

bstrt database(strDBName);

bstrt bstrDBTableName(""); //TableDef nicht nötig, da unten mit SetTableLocation

bstrt nix("");

//Alle Datenbankpfade aller Tabellen generisch aktualisieren:

long i;

//Alle Tabellen aus Hauptbericht aktualisieren

long lTableCount = m_Report->GetDatabase()->GetTables()->GetCount();

for (i=1; i<=lTableCount; i++)

{

sTableName = (const char *)m_Report->GetDatabase()->GetTables()->GetItem(i)->GetName();

sTableName.Replace ("ALIAS", "");

bstrDBTableName = sTableName;

m_Report->GetDatabase()->GetTables()->GetItem(i)->SetTableLocation(database,bstrDBTableName,nix);

}

//Unterberichte suchen in allen Berichtsbereichen

ISectionsPtr pSections = m_Report->GetSections();

long lSectionsCount = pSections->GetCount();

for (i=1; i<=lSectionsCount; i++)

{

//Counter in Variant packen

VARIANT varItemI;

VariantInit(&varItemI);

varItemI.vt = VT_I4;

varItemI.lVal = i;

//In Sektion i suchen

ISectionPtr pSection = pSections->GetItem(varItemI);

//Alle Report-Objekte der Sektion prüfen

IReportObjectsPtr pReportObjects = pSection->GetReportObjects();

long lReportObjectsCount = pReportObjects->GetCount();

for (long ij=1; ij<=lReportObjectsCount; ij++)

{

//Counter in Variant packen

VARIANT varItemJ;

VariantInit(&varItemJ);

varItemJ.vt = VT_I4;

varItemJ.lVal = ij;

// ReportObject ij untersuchen

IReportObjectPtr pReportObject = pReportObjects->GetItem(varItemJ);

if (pReportObject->GetKind() == crSubreportObject)

{

//SubReport gefunden!

ISubreportObjectPtr pSubreportObject = pReportObject;

ICRReportPtr pSubReport = pSubreportObject->OpenSubreport();

//Tabellen für den SubReport aktualisieren

long ijk;

long lTableCount = pSubReport->GetDatabase()->GetTables()->GetCount();

for(ijk=1; ijk<=lTableCount; ijk++)

{

sTableName = (const char *)pSubReport->GetDatabase()->GetTables()->GetItem(ijk)->GetName();

sTableName.Replace ("ALIAS", "");

bstrDBTableName = sTableName;

pSubReport->GetDatabase()->GetTables()->GetItem(ijk)->SetTableLocation(database,bstrDBTableName,nix);

}

}

}

}

}

catch (_com_error& e)

{

bstrt descr = e.Description();

CString msg = e. ErrorMessage();

}

// free bstrs

// Laut Aussage Wr nicht notwendig. Im Umfeld von TCS gibt's hiermit Abstürze.

// SysFreeString(bstrTableName);

// SysFreeString(database);

// SysFreeString(nix);

// view the report in the control

m_Viewer.ViewReport();

// 1 entspricht Seitenbreite; 2 entspr. GanzeSeite; 25-400 entspr. %

m_Viewer.Zoom(1);

//weitere Einstellungen - enablen ist ja schön, aber wie rufe ich direkt auf?

m_Viewer.SetEnableExportButton(true);

m_Viewer.SetEnableZoomControl(true);

m_Viewer.SetEnableSearchControl(true);

m_Viewer.SetEnableAnimationCtrl(true);

m_Viewer.SetEnableProgressControl(true);

m_Viewer.SetEnableToolbar (true);

m_Viewer.SetDisplayToolbar (true);

m_Viewer.SetEnablePopupMenu(true);

m_Viewer.SetDisplayBackgroundEdge (true);

m_Viewer.SetDisplayBorder (true);

m_Viewer.SetDisplayTabs (false);

m_Viewer.SetEnableSelectExpertButton(false);

m_Viewer.SetEnableSearchExpertButton(false);

m_Viewer.SetEnableHelpButton(false);

m_Viewer.SetEnableRefreshButton(false); // true ist default

m_Viewer.SetEnableCloseButton(false);

m_Viewer.SetEnableStopButton(false);

m_Viewer.SetEnableDrillDown(false);

m_Viewer.SetEnableGroupTree(false);

m_Viewer.SetDisplayGroupTree(false);

m_Viewer.EnableToolTips(FALSE);

}