
private void lstExportFormatType_SelectedIndexChanged(object sender, EventArgs e)
{
// This gets populated when you click on the export ENUM
string ExportTypeSelected = lstExportFormatType.SelectedItem.ToString();
if (ExportTypeSelected == "crReportExportFormatCrystalReports")
#region RPT
{
// This works do not alter
// this gets the report name and sets the export name to be the same less the extension
string outputFileName = "";
string MyRptName = rpt.FileName.ToString();
outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
outputFileName = outputFileName.Substring(0, (outputFileName.Length - 4)) + "1.rpt";
try
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.RPTExportFormatOptions RasRPTExpOpts = new RPTExportFormatOptions();
try
{
//RasRPTExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatCrystalReports);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
//return;
}
// Set them now:
//RasPDFExpOpts.CreateBookmarksFromGroupTree = false;
//RasPDFExpOpts.EndPageNumber = 1;
//RasPDFExpOpts.StartPageNumber = 1;
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatCrystalReports;
exportOpts1.FormatOptions = RasRPTExpOpts;
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
MessageBox.Show("Export to RPT Completed. NOTE: report is *1.RPT", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
// This works do not alter
}
#endregion RPT
if (ExportTypeSelected == "crReportExportFormatMSExcel")
#region MSExcel
{
// This works do not alter
// this gets the report name and sets the export name to be the same less the extension
string outputFileName = "";
string MyRptName = rpt.FileName.ToString();
outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "xls";
try
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions RasXLSExpOpts = new ExcelExportFormatOptions();
RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel);
btnReportObjects.Text = "Excel - BaseAreaGroupNumber: " + RasXLSExpOpts.BaseAreaGroupNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - BaseAreaType: " + RasXLSExpOpts.BaseAreaType.ToString() + "\n";
btnReportObjects.Text += "Excel - FormulaExportPageAreaType: " + RasXLSExpOpts.ExportPageAreaPairType.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageBreaks: " + RasXLSExpOpts.ExportPageBreaks.ToString() + "\n";
btnReportObjects.Text += "Excel - ConstantColWidth: " + RasXLSExpOpts.ConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ConvertDatesToStrings: " + RasXLSExpOpts.ConvertDatesToStrings.ToString() + "\n";
btnReportObjects.Text += "Excel - StartPageNumber: " + RasXLSExpOpts.StartPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - EndPageNumber: " + RasXLSExpOpts.EndPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageBreaks: " + RasXLSExpOpts.ExportPageBreaks.ToString() + "\n";
btnReportObjects.Text += "Excel - MRelativeObjectPosition: " + RasXLSExpOpts.MaintainRelativeObjectPosition.ToString() + "\n";
btnReportObjects.Text += "Excel - ShowGridlines: " + RasXLSExpOpts.ShowGridlines.ToString() + "\n";
btnReportObjects.Text += "Excel - UseConstantColWidth: " + RasXLSExpOpts.UseConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ExcelTabHasColumnHeadings: " + RasXLSExpOpts.ExcelTabHasColumnHeadings + "\n";
try
{
RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatRecordToMSExcel);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
//return;
}
// Set them now:
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
RasXLSExpOpts.ExcelTabHasColumnHeadings = true;
// Save the udpated info
rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel, RasXLSExpOpts);
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatMSExcel;
exportOpts1.FormatOptions = RasXLSExpOpts;
// Show start time
DateTime dtStart;
TimeSpan difference;
dtStart = DateTime.Now;
btnReportObjects.Text += "Report Export Started: " + dtStart + "\r\n";
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
difference = DateTime.Now.Subtract(dtStart);
btnReportObjects.Text += "Report Export Completed in: " + difference.Minutes.ToString() + ":" + difference.Seconds.ToString() + "\r\n";
MessageBox.Show("Export to Excel Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
// This works do not alter
}
#endregion MSExcel
if (ExportTypeSelected == "crReportExportFormatXLSX")
#region XLSX
{
// This works do not alter
// this gets the report name and sets the export name to be the same less the extension
string outputFileName = "";
string MyRptName = rpt.FileName.ToString();
outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "xlsx";
try
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.DataOnlyExcelExportFormatOptions RASXLXSExportOpts = new DataOnlyExcelExportFormatOptions();
RASXLXSExportOpts = (DataOnlyExcelExportFormatOptions)rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatXLSX);
//btnReportObjects.Text = "Excel - BaseAreaGroupNumber: " + RASXLXSExportOpts.BaseAreaGroupNumber.ToString() + "\n";
//btnReportObjects.Text += "Excel - BaseAreaType: " + RASXLXSExportOpts.BaseAreaType.ToString() + "\n";
//btnReportObjects.Text += "Excel - ConstantColWidth: " + RASXLXSExportOpts.ConstantColWidth.ToString() + "\n";
//btnReportObjects.Text += "Excel - Export Images: " + RASXLXSExportOpts.ExportImages.ToString() + "\n";
//btnReportObjects.Text += "Excel - ExportObject Formatting: " + RASXLXSExportOpts.ExportObjectFormatting.ToString() + "\n";
//btnReportObjects.Text += "Excel - Export Page Header Footer: " + RASXLXSExportOpts.ExportPageHeaderAndFooter.ToString() + "\n";
//btnReportObjects.Text += "Excel - Maintain Column Alignment: " + RASXLXSExportOpts.MaintainColumnAlignment.ToString() + "\n";
//btnReportObjects.Text += "Excel - MaintainRelativeObjectPos: " + RASXLXSExportOpts.MaintainRelativeObjectPosition.ToString() + "\n";
//btnReportObjects.Text += "Excel - ShowGroupOutlines: " + RASXLXSExportOpts.ShowGroupOutlines.ToString() + "\n";
//btnReportObjects.Text += "Excel - SimplifyPageHeaders: " + RASXLXSExportOpts.SimplifyPageHeaders.ToString() + "\n";
//btnReportObjects.Text += "Excel - UseConstantColWidth: " + RASXLXSExportOpts.UseConstantColWidth.ToString() + "\n";
//btnReportObjects.Text += "Excel - UseWorkstFuncForSummaries: " + RASXLXSExportOpts.UseWorksheetFunctionsForSummaries.ToString() + "\n";
// Set them now:
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
try
{
RASXLXSExportOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatXLSX);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
//return;
}
// Save the udpated info
//rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatXLSX, RASXLXSExportOpts);
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatXLSX;
exportOpts1.FormatOptions = RASXLXSExportOpts;
// Manually set the values
//RASXLXSExportOpts.ConstantColWidth = Convert.ToInt32(36.6);
//RASXLXSExportOpts.ExportObjectFormatting = true;
//RASXLXSExportOpts.ExportImages = false;
//RASXLXSExportOpts.UseWorksheetFunctionsForSummaries = false;
//RASXLXSExportOpts.MaintainRelativeObjectPosition = true;
//RASXLXSExportOpts.MaintainColumnAlignment = true;
//RASXLXSExportOpts.ExportPageHeaderAndFooter = false;
//RASXLXSExportOpts.SimplifyPageHeaders = true;
//RASXLXSExportOpts.ShowGroupOutlines = false;
CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions ExpXLXSOpts = new ExcelExportFormatOptions();
//ExpXLXSOpts.ConstantColWidth = 45;
//ExpXLXSOpts.ConvertDatesToStrings = true;
exportOpts1.ExportOptionsEx = null;
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
MessageBox.Show("Export to Excel XLXS Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
}
#endregion XLSX
if (ExportTypeSelected == "crReportExportFormatRecordToXLSX") // new in SP30
#region MSRecordExcel
{
// This works do not alter
// this gets the report name and sets the export name to be the same less the extension
string outputFileName = "";
string MyRptName = rpt.FileName.ToString();
outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "xlsx";
try // test if the reprot is saved in CR 2020
{
if ((rpt.HistoryInfos[0].BuildVersion.ToString()) != null)
{
if ((rpt.HistoryInfos[0].BuildVersion.ToString()).Substring(0, 4) != "14.3")
{
MessageBox.Show("Report must be saved in CR 2020 to support this feature");
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Report must be saved in CR 2020 to support this feature");
return;
}
try
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.DataOnlyExcelExportFormatOptions RasXLSExpOpts = (DataOnlyExcelExportFormatOptions)rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatRecordToXLSX); //new API, introduced from BI 4.3 SP02 And Cortez SP30
RasXLSExpOpts = rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatRecordToXLSX);
if (RasXLSExpOpts != null)
{
btnReportObjects.Text = "Excel - BaseAreaGroupNumber: " + RasXLSExpOpts.BaseAreaGroupNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - BaseAreaType: " + RasXLSExpOpts.BaseAreaType.ToString() + "\n";
btnReportObjects.Text += "Excel - ConstantColWidth: " + RasXLSExpOpts.ConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportImages: " + RasXLSExpOpts.ExportImages.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportObjectFormatting: " + RasXLSExpOpts.ExportObjectFormatting.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportObjectFormatting: " + RasXLSExpOpts.ExportObjectFormatting.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageHeaderAndFooter: " + RasXLSExpOpts.ExportPageHeaderAndFooter.ToString() + "\n";
btnReportObjects.Text += "Excel - MaintainColumnAlignment: " + RasXLSExpOpts.MaintainColumnAlignment.ToString() + "\n";
btnReportObjects.Text += "Excel - MaintainRelativeObjectPosition: " + RasXLSExpOpts.MaintainRelativeObjectPosition.ToString() + "\n";
btnReportObjects.Text += "Excel - ShowGroupOutlines: " + RasXLSExpOpts.ShowGroupOutlines.ToString() + "\n";
btnReportObjects.Text += "Excel - SimplifyPageHeaders: " + RasXLSExpOpts.SimplifyPageHeaders.ToString() + "\n";
btnReportObjects.Text += "Excel - UseConstantColWidth: " + RasXLSExpOpts.UseConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - UseWorksheetFunctionsForSummaries: " + RasXLSExpOpts.UseWorksheetFunctionsForSummaries+ "\n";
// Set them now:
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
//RasXLSExpOpts.ExcelTabHasColumnHeadings = true;
// Save the udpated info
//rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatMSExcel, RasXLSExpOpts);
}
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatRecordToXLSX;
exportOpts1.FormatOptions = RasXLSExpOpts;
// Show start time
DateTime dtStart;
TimeSpan difference;
dtStart = DateTime.Now;
btnReportObjects.Text += "Report Export Started: " + dtStart + "\r\n";
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
difference = DateTime.Now.Subtract(dtStart);
btnReportObjects.Text += "Report Export Completed in: " + difference.Minutes.ToString() + ":" + difference.Seconds.ToString() + "\r\n";
MessageBox.Show("Export to MicrosoftExcel(XLS) Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
// This works do not alter
} // new in SP30
#endregion MSRecordExcel
if (ExportTypeSelected == "crReportExportFormatPageToXLSX") // new in SP30
#region MSPageXLSX
{
// This works do not alter
// this gets the report name and sets the export name to be the same less the extension
string outputFileName = "";
string MyRptName = rpt.FileName.ToString();
outputFileName = MyRptName.Substring(9, rpt.FileName.Length - 9);
outputFileName = outputFileName.Substring(0, (outputFileName.Length - 3)) + "xlsx";
try // test if the reprot is saved in CR 2020
{
if ((rpt.HistoryInfos[0].BuildVersion.ToString()) != null)
{
if ((rpt.HistoryInfos[0].BuildVersion.ToString()).Substring(0, 4) != "14.3")
{
MessageBox.Show("Report must be saved in CR 2020 to support this feature");
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Report must be saved in CR 2020 to support this feature");
return;
}
try
{
if (File.Exists(outputFileName))
{
File.Delete(outputFileName);
}
CrystalDecisions.ReportAppServer.ReportDefModel.ExcelExportFormatOptions RASXLXSExportOpts = (ExcelExportFormatOptions)rptClientDoc.get_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPageToXLSX);
if (RASXLXSExportOpts != null)
{
btnReportObjects.Text = "Excel - BaseAreaGroupNumber: " + RASXLXSExportOpts.BaseAreaGroupNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - BaseAreaType: " + RASXLXSExportOpts.BaseAreaType.ToString() + "\n";
btnReportObjects.Text += "Excel - ConstantColWidth: " + RASXLXSExportOpts.ConstantColWidth.ToString() + "\n";
btnReportObjects.Text += "Excel - ConvertDatesToStrings: " + RASXLXSExportOpts.ConvertDatesToStrings.ToString() + "\n";
btnReportObjects.Text += "Excel - CurrentPageNumber: " + RASXLXSExportOpts.CurrentPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - EndPageNumber: " + RASXLXSExportOpts.EndPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - ExcelTabHasColumnHeadings: " + RASXLXSExportOpts.ExcelTabHasColumnHeadings.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageAreaPairType: " + RASXLXSExportOpts.ExportPageAreaPairType.ToString() + "\n";
btnReportObjects.Text += "Excel - ExportPageBreaks: " + RASXLXSExportOpts.ExportPageBreaks.ToString() + "\n";
btnReportObjects.Text += "Excel - MaintainRelativeObjectPos: " + RASXLXSExportOpts.MaintainRelativeObjectPosition.ToString() + "\n";
btnReportObjects.Text += "Excel - ShowGridlines: " + RASXLXSExportOpts.ShowGridlines.ToString() + "\n";
btnReportObjects.Text += "Excel - StartPageNumber: " + RASXLXSExportOpts.StartPageNumber.ToString() + "\n";
btnReportObjects.Text += "Excel - UseConstantColWidth: " + RASXLXSExportOpts.UseConstantColWidth.ToString() + "\n";
}
// Manually set the values
//RasXLSExpOpts.BaseAreaType = CrAreaSectionKindEnum.crAreaSectionKindPageHeader;
//RasXLSExpOpts.UseConstantColWidth = false;
//RasXLSExpOpts.ShowGridlines = false;
//RasXLSExpOpts.StartPageNumber = 3;
//RasXLSExpOpts.EndPageNumber = 10;
//RASXLXSExportOpts.ConstantColWidth = Convert.ToInt32(36.6);
//RASXLXSExportOpts.ExportObjectFormatting = true;
//RASXLXSExportOpts.ExportImages = false;
//RASXLXSExportOpts.UseWorksheetFunctionsForSummaries = false;
//RASXLXSExportOpts.MaintainRelativeObjectPosition = true;
//RASXLXSExportOpts.MaintainColumnAlignment = true;
//RASXLXSExportOpts.ExportPageHeaderAndFooter = false;
//RASXLXSExportOpts.SimplifyPageHeaders = true;
//RASXLXSExportOpts.ShowGroupOutlines = false;
// Save the udpated info
//rptClientDoc.set_SavedExportOptions(CrReportExportFormatEnum.crReportExportFormatPageToXLSX, RASXLXSExportOpts);
CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions exportOpts1 = new CrystalDecisions.ReportAppServer.ReportDefModel.ExportOptions();
exportOpts1.ExportFormatType = CrReportExportFormatEnum.crReportExportFormatPageToXLSX;
exportOpts1.FormatOptions = RASXLXSExportOpts;
// And Export
rptClientDoc.PrintOutputController.ExportEx(exportOpts1).Save(outputFileName, true);
MessageBox.Show("Export to Excel XLXS Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
btnSQLStatement.Text = "ERROR: " + ex.Message;
return;
}
}// new in SP30
#endregion MSPageXLSX
private void btrOpenAll_Click(object sender, EventArgs e)
{
rptClientDoc = new CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument(); // ReportClientDocumentClass();
using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
DateTime dtStart;
TimeSpan difference;
System.Windows.Forms.DialogResult result = dialog.ShowDialog();
string selectedFolder = @"C:\";
if (result == System.Windows.Forms.DialogResult.OK)
{
selectedFolder = dialog.SelectedPath;
}
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = selectedFolder;
DirectoryInfo di = new DirectoryInfo(selectedFolder);
FileInfo[] rptFiles = di.GetFiles("*.rpt");
int flcnt1 = 0;
foreach (object rptName in rptFiles)
{
dtStart = DateTime.Now;
flcnt1++;
btnCount.Text = flcnt1.ToString();
try
{
rpt.Load(di.FullName + "\\" + rptName.ToString(), OpenReportMethod.OpenReportByTempCopy);
difference = DateTime.Now.Subtract(dtStart);
btnReportObjects.Text += "Report Document Load: " + difference.Minutes.ToString() + ":" + difference.Seconds.ToString() + " - " + rptName.ToString();
rptClientDoc = rpt.ReportClientDocument;
}
catch (Exception ex)
{
btnReportObjects.Text = "Error opening: " + rptName.ToString() + "\n";
}
// now do what ever to each report
// check if the report is based on a Command and if so then display the SQL. This causes a huge delay opening report
//btnReportObjects.AppendText("");
dtStart = DateTime.Now;
try
{
int dbConCount1 = rptClientDoc.DatabaseController.GetConnectionInfos().Count;
}
catch (Exception ex)
{
btnReportObjects.Text += "\nError connectionInfo: " + rptName.ToString() + "\n";
rpt.Close();
return;
}
int dbConCount = rptClientDoc.DatabaseController.GetConnectionInfos().Count;
difference = DateTime.Now.Subtract(dtStart);
//btnReportObjects.Text += "GetConnectionInfos().Count took: " + difference.Minutes.ToString() + ":" + difference.Seconds.ToString() + "\r\n";
// get the DB name from the report
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
crDatabase = rpt.Database;
crTables = crDatabase.Tables;
int dbx = 0;
String DBDriver = "";
for (int x = 0; x < dbConCount; x++)
{
try
{
if (((dynamic)rptClientDoc.Database.Tables[0].Name) == "Command")
{
CrystalDecisions.ReportAppServer.Controllers.DatabaseController databaseController = rpt.ReportClientDocument.DatabaseController;
ISCRTable oldTable = (ISCRTable)databaseController.Database.Tables[0];
btnReportObjects.Text += "Yes \n" + ((dynamic)oldTable).CommandText.ToString();
btnReportObjects.Text += "\n";
IsLoggedOn = false;
IsCMD = true;
}
if (DBDriver.ToString() == "crdb_bwmdx.dll")
IsBEX = true;
}
catch (Exception ex)
{
//btnDBDriver.Text = "ERROR: " + ex.Message;
//btnDBDriver.Text += "Main Report has no Data Driver";
}
}
//get the subreport connection infos
string SecName = "";
CrystalDecisions.CrystalReports.Engine.ReportObjects crReportObjects;
CrystalDecisions.CrystalReports.Engine.SubreportObject crSubreportObject;
CrystalDecisions.CrystalReports.Engine.ReportDocument crSubreportDocument;
//set the crSections object to the current report's sections
CrystalDecisions.CrystalReports.Engine.Sections crSections = rpt.ReportDefinition.Sections;
int flcnt = 0;
//loop through all the sections to find all the report objects
foreach (CrystalDecisions.CrystalReports.Engine.Section crSection in crSections)
{
crReportObjects = crSection.ReportObjects;
//loop through all the report objects to find all the subreports
foreach (CrystalDecisions.CrystalReports.Engine.ReportObject crReportObject in crReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
try
{
++flcnt;
btnCount.Text = flcnt.ToString();
dbx = 0;
//you will need to typecast the reportobject to a subreport
//object once you find it
crSubreportObject = (CrystalDecisions.CrystalReports.Engine.SubreportObject)crReportObject;
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
SubreportClientDocument subRCD = rptClientDoc.SubreportController.GetSubreport(crSubreportObject.SubreportName);
string mysubname = crSubreportObject.SubreportName.ToString();
try
{
CrystalDecisions.Shared.ConnectionInfo crSubConnectioninfo = new CrystalDecisions.Shared.ConnectionInfo();
//btnReportObjects.Text += "\n\nSubReport Table count: " + subRCD.DatabaseController.Database.Tables.Count.ToString();
// get the DB names from the subreport
//crDatabase = subRCD.DatabaseController.Database;
//crTables = crDatabase.Tables;
if (subRCD.DatabaseController.Database.Tables.Count != 0)
{
foreach (CrystalDecisions.ReportAppServer.DataDefModel.Table crTable in subRCD.DatabaseController.Database.Tables)
{
try
{
// Subreport is using a Command so use RAS to get the SQL
btnDBDriver.Text += DBDriver + " :";
if (((dynamic)crTable.Name) == "Command")
{
CrystalDecisions.ReportAppServer.Controllers.DatabaseController databaseController = subRCD.DatabaseController;
CommandTable SuboldTable = (CommandTable)databaseController.Database.Tables[0];
btnReportObjects.Text += "SubReport is using Command: \n" + ((dynamic)SuboldTable).CommandText.ToString();
btnReportObjects.Text += "\n";
IsLoggedOn = false;
IsCMD = true;
}
if (DBDriver.ToString() == "crdb_bwmdx.dll")
IsBEX = true;
}
catch (Exception ex)
{
//btnDBDriver.Text += "ERROR: " + ex.Message;
btnDBDriver.Text += "Main Report has no Data Driver";
}
}
}
else
{
try
{
btnReportObjects.Text += "\nSubreport: " + subRCD.Name.ToString() + ": Has no Data Source\n";
}
catch (Exception ex)
{
//btnDBDriver.Text += "ERROR: " + ex.Message;
btnReportObjects.Text += "Error: ";
}
}
}
catch (Exception ex)
{
btnReportObjects.Text += "SubreportName: " + subRCD.Name + "\n";
btnReportObjects.Update();
btnReportObjects.AppendText("Error in " + SecName + " : " + ex.Message + "\n\n");
}
break;
}
catch (Exception ex)
{
btnReportObjects.AppendText("Error in " + SecName + " : " + ex.Message + "\n");
}
}
}
}
btnReportObjects.AppendText("\n");
rpt.Close();
btnReportObjects.ScrollToCaret();
}
}
MessageBox.Show("Done");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
11 | |
11 | |
10 | |
10 | |
9 | |
8 | |
7 | |
7 | |
6 |