Ejemplo n.º 1
0
        public static void Initialize(this ReportViewer reportViewer, ReportViewParamenters parameters)
        {
            var handlers = CreateEventHandlers(parameters);

            SetupLocalProcessing(reportViewer, parameters, handlers);
            if (handlers != null)
            {
                reportViewer.Drillthrough += (sender, e) => handlers.OnDrillthrough(reportViewer, e);
            }
        }
Ejemplo n.º 2
0
        public GeradorReportViewer(
            Formato reportFormat,
            string reportPath,
            string reportServerUrl,
            string username,
            string password,
            IEnumerable <KeyValuePair <string, object> > reportParameters,
            ModoProcessamento mode = ModoProcessamento.Remote,
            IDictionary <string, DataTable> localReportDataSources    = null,
            IDictionary <string, IEnumerable> localReportEnumerable   = null,
            IDictionary <string, IDataSource> localReportUiDataSource = null,
            string filename               = null,
            string eventsHandlerType      = null,
            Stream embeddedResourceStream = null,
            string embededResourcePath    = null)
        {
            _viewerParameters = new ReportViewParamenters
            {
                IsGeradorReportViewerExecution = true
            };

            _reportFormat = reportFormat;
            Filename      = filename;
            if (mode == ModoProcessamento.Local)
            {
                _viewerParameters.ProcessingMode = ProcessingMode.Local;
            }
            else if (mode == ModoProcessamento.Remote)
            {
                _viewerParameters.ProcessingMode = ProcessingMode.Remote;
            }

            if (mode == ModoProcessamento.Local && localReportDataSources != null)
            {
                _viewerParameters.LocalReportDataSources = localReportDataSources;
            }
            else if (mode == ModoProcessamento.Local && localReportEnumerable != null)
            {
                _viewerParameters.LocalReportDatasourceEnumerable = localReportEnumerable;
            }
            else if (mode == ModoProcessamento.Local && localReportUiDataSource != null)
            {
                _viewerParameters.LocalReportIDataSource = localReportUiDataSource;
            }

            _viewerParameters.EmbeddedResourceStream = embeddedResourceStream;
            _viewerParameters.LocalPath            = reportPath;
            _viewerParameters.EmbeddedResourcePath = embededResourcePath;

            if (!string.IsNullOrEmpty(eventsHandlerType))
            {
                _viewerParameters.EventsHandlerType = eventsHandlerType;
            }
            ParseParameters(reportParameters);
        }
        private static void SetupLocalProcessing(ReportViewer reportViewer, ReportViewParamenters parameters,
                                                 IReportViewerEventsHandler handlers)
        {
            reportViewer.ProcessingMode = ProcessingMode.Local;
            var localReport = reportViewer.LocalReport;

            if (!string.IsNullOrWhiteSpace(parameters.EmbeddedResourcePath))
            {
                localReport.ReportEmbeddedResource = parameters.EmbeddedResourcePath;
            }
            else if (!string.IsNullOrWhiteSpace(parameters.LocalPath))
            {
                localReport.ReportPath = parameters.LocalPath;
            }
            else
            {
                localReport.LoadReportDefinition(parameters.EmbeddedResourceStream);
            }

            if (parameters.ControlSettings != null && parameters.ControlSettings.UseCurrentAppDomainPermissionSet != null &&
                parameters.ControlSettings.UseCurrentAppDomainPermissionSet.Value)
            {
                localReport.SetBasePermissionsForSandboxAppDomain(AppDomain.CurrentDomain.PermissionSet.Copy());
            }

            if (parameters.ControlSettings != null && parameters.ControlSettings.EnableExternalImages != null &&
                parameters.ControlSettings.EnableExternalImages.Value)
            {
                localReport.EnableExternalImages = true;
            }

            if (parameters.ControlSettings != null && parameters.ControlSettings.EnableHyperlinks != null &&
                parameters.ControlSettings.EnableHyperlinks.Value)
            {
                localReport.EnableHyperlinks = true;
            }

            if (parameters.ReportParameters.Count > 0)
            {
                localReport.SetParameters(parameters.ReportParameters.Values);
            }
            if (handlers != null)
            {
                localReport.SubreportProcessing += (sender, e) => handlers.OnSubreportProcessing(reportViewer, e);
            }

            // If parameters.LocalReportDataSources then we should get report data source
            // from local data source provider (ignore it for Report Runner)
            if (parameters.LocalReportDataSources == null && !parameters.IsGeradorReportViewerExecution)
            {
                if (parameters.ControlId == null)
                {
                    throw new ReportException("ReportViewer control ID is missing");
                }
                localReport.DataSources.Clear();
                if (parameters.LocalReportDataSources != null)
                {
                    foreach (var dataSource in parameters.LocalReportDataSources)
                    {
                        var reportDatasource = new ReportDataSource(dataSource.Key, dataSource.Value);
                        localReport.DataSources.Add(reportDatasource);
                    }
                }
            }
        }