Exemplo n.º 1
0
        public HttpResponseMessage RelProcedimentos()
        {
            try
            {
                var lista = _serviceRelatorio.RelProcedimentos();

                //vinculando dataset ao objeto relat
                var ds = new ReportDataSource();
                ds.Name = "dsdados"; ds.Value = lista;

                var report = new LocalReport();
                report.ReportPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Report/RelatorioProcedimentos.rdlc");
                report.DataSources.Add(ds);
                report.Refresh();

                // parametros
                ReportParameter[] parametros = new ReportParameter[] {
                    new ReportParameter("usuario", base.GetUsuarioLogado().Nome)
                };

                report.SetParameters(parametros);

                //configurações da página ex: margin, top, left ...
                string deviceInfo =
                    "<DeviceInfo>" +
                    "<OutputFormat>PDF</OutputFormat>" +
                    "<PageWidth>20cm</PageWidth>" +
                    "<PageHeight>29.7cm</PageHeight>" +
                    "<MarginTop>0.5cm</MarginTop>" +
                    "<MarginLeft>0.5cm</MarginLeft>" +
                    "<MarginRight>0.5cm</MarginRight>" +
                    "<MarginBottom>0.5cm</MarginBottom>" +
                    "</DeviceInfo>";

                string   mimeType          = "";
                string   encoding          = "";
                string   filenameExtension = "";
                string[] streams           = null;
                Microsoft.Reporting.WebForms.Warning[] warnings = null;
                byte[] bytes = report.Render("PDF", deviceInfo, 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);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }