예제 #1
0
        public static HttpResponseMessage Report(DataTable ds, string dsName, string rdlc)
        {
            var report = new Microsoft.Reporting.WebForms.LocalReport();

            report.ReportPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Bin/Report/" + rdlc);
            report.DataSources.Add(new ReportDataSource(dsName, ds));
            report.Refresh();

            string mimeType          = "";
            string encoding          = "";
            string filenameExtension = "";

            string[] streams = null;
            Microsoft.Reporting.WebForms.Warning[] warnings = null;
            byte[] bytes = report.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streams, out warnings);

            HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

            result.Content = new ByteArrayContent(bytes);
            result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mimeType);
            return(result);
        }
예제 #2
0
        protected void BindLocalReport(MsLocalReport localReport, IReport report)
        {
            ILocalReportProcessingLocation location = (ILocalReportProcessingLocation)report.ReportProcessingLocation;

            localReport.LoadReportDefinition(ReportDefinitionCache.GetReportDefinition(location.File).GetReportStream());

            localReport.EnableHyperlinks = true;

            localReport.EnableExternalImages = true;

            localReport.SetBasePermissionsForSandboxAppDomain(new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted));
            //localReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence);
            //localReport.AddFullTrustModuleInSandboxAppDomain(new System.Security.Policy.StrongName(new System.Security.Permissions.StrongNamePublicKeyBlob(Nullable),"VB.Reports.App.ReportStyleLibrary.StyleSheet","1.0.0"));
            //localReport.AddTrustedCodeModuleInCurrentAppDomain(System.Reflection.Assembly.GetAssembly(typeof(VB.Reports.App.ReportStyleLibrary.StyleSheet)).ToString());

            if (localReport.IsDrillthroughReport)
            {
                localReport.SetParameters(localReport.OriginalParametersToDrillthrough);
            }
            else
            {
                IList <MsReportParameter> parameters = new List <MsReportParameter>();

                foreach (IReportParameter parameter in report.ReportParameters)
                {
                    parameters.Add(new MsReportParameter(parameter.Name, GetParameterValue(parameter)));
                }

                localReport.SetParameters(parameters);
            }

            localReport.DataSources.Clear();

            foreach (IReportDataCommandTemplate reportDataCommandTemplate in report.ReportDataCommandTemplates)
            {
                DictionaryDataParameterValue parameterValues = new DictionaryDataParameterValue();

                foreach (IReportParameter parameter in reportDataCommandTemplate.Parameters)
                {
                    if (localReport.IsDrillthroughReport)
                    {
                        parameterValues[parameter.Name] =
                            GetParameterValue(parameter, localReport.OriginalParametersToDrillthrough);
                    }
                    else
                    {
                        parameterValues[parameter.Name] = GetParameterValue(parameter);
                    }
                }

                using (IDataConnection connection = SimpleQuery.ConfigurationManagerConnection(location.DataSourceName))
                {
                    if (connection.State == ConnectionState.Closed)
                    {
                        connection.Open();
                    }

                    using (IDataCommand command = connection.CreateCommand(reportDataCommandTemplate, parameterValues.DataParameterValue))
                    {
                        command.CommandTimeout = 200;
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            DataTable table = DataTableMapper.ToDataTable(reader);
                            localReport.DataSources.Add(new MsReportDataSource(reportDataCommandTemplate.Name, table));
                        }
                    }
                }
            }

            localReport.Refresh();
        }