public ViewReport ( Report report, Repository repository, bool render, string viewGUID, string outputGUID, string originalFilePath ) : void | ||
report | Report | |
repository | Repository | |
render | bool | |
viewGUID | string | |
outputGUID | string | |
originalFilePath | string | |
return | void |
public void ViewReport(Report report, Repository repository, bool render, string viewGUID, string outputGUID, string originalFilePath)
{
Show();
Text = Path.GetFileNameWithoutExtension(originalFilePath) + " - " + Repository.SealRootProductName + " Report Viewer";
BringToFront();
Report previousReport = _report;
_report = report;
_report.ExecutionContext = ReportExecutionContext.DesignerReport;
if (string.IsNullOrEmpty(_report.DisplayName)) _report.DisplayName = Path.GetFileNameWithoutExtension(originalFilePath);
_report.CurrentViewGUID = _report.ViewGUID;
//execute to output
if (!string.IsNullOrEmpty(outputGUID))
{
_report.OutputToExecute = _report.Outputs.FirstOrDefault(i => i.GUID == outputGUID);
_report.ExecutionContext = ReportExecutionContext.DesignerOutput;
if (_report.OutputToExecute != null) _report.CurrentViewGUID = _report.OutputToExecute.ViewGUID;
}
//execute with custom view
if (!string.IsNullOrEmpty(viewGUID)) _report.CurrentViewGUID = viewGUID;
if (previousReport != null && render)
{
//force execution
var parameter = _report.ExecutionView.Parameters.FirstOrDefault(i => i.Name == "force_execution");
if (parameter != null) parameter.BoolValue = true;
//set previous data tables and restrictions
foreach (var model in _report.Models)
{
ReportModel previousModel = previousReport.Models.FirstOrDefault(i => i.GUID == model.GUID);
if (previousModel != null)
{
model.ResultTable = previousModel.ResultTable;
model.Restrictions = previousModel.Restrictions;
model.RestrictionText = previousModel.RestrictionText;
model.Sql = previousModel.Sql;
}
}
_report.RenderOnly = true;
}
_execution = new ReportExecution() { Report = _report };
_report.InitForExecution();
_execution.RenderHTMLDisplayForViewer();
_url = "file:///" + _report.HTMLDisplayFilePath;
webBrowser.Navigate(_url);
}
static void Main(string[] args) { // Add the event handler for handling UI thread exceptions to the event. Application.ThreadException += new ThreadExceptionEventHandler(ExceptionHandler); // Set the unhandled exception mode to force all Windows Forms errors to go through // our handler. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); bool execute = (args.Length >= 1 && args[0].ToLower() == "/e"); bool executeOutputOrView = (args.Length >= 1 && args[0].ToLower() == "/x"); string reportToOpen = null; if (args.Length >= 2 && File.Exists(args[1])) reportToOpen = args[1]; if ((execute || executeOutputOrView) && reportToOpen != null) { //Execute only var report = Report.LoadFromFile(reportToOpen, Repository.Create()); string outputGUID = null, viewGUID = null; if (executeOutputOrView) { string guid = (args.Length >= 3 ? args[2] : ""); if (!string.IsNullOrEmpty(guid)) { if (report.Views.Exists(i => i.GUID == guid)) viewGUID = guid; if (report.Outputs.Exists(i => i.GUID == guid)) outputGUID = guid; } else { //by default execute first output if (report.Outputs.Count > 0) outputGUID = report.Outputs[0].GUID; } } var reportViewer = new ReportViewerForm(true, Properties.Settings.Default.ShowScriptErrors); reportViewer.ViewReport(report, report.Repository, false, viewGUID, outputGUID, report.FilePath); Application.Run(); } else { Application.Run(new ReportDesigner()); } }