Пример #1
0
        public HttpResponseMessage RelFinanceiro(DateTime datainicio, DateTime datatermino, string tipo, string situacao, int idpessoa)
        {
            try
            {
                if (datainicio > datatermino)
                {
                    throw new Exception("Periodo inválido");
                }

                var lista = _serviceRelatorio.RelFinanceiro(datainicio, datatermino, tipo, situacao, idpessoa, base.GetUsuarioLogado().IdClinica);

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

                var report = new LocalReport()
                {
                    ReportPath = AppDomain.CurrentDomain.BaseDirectory + "Report/RelatorioFinanceiro.rdlc"
                };
                report.DataSources.Add(ds);
                report.Refresh();

                ReportParameter[] parametros = new ReportParameter[] {
                    new ReportParameter("usuario", base.GetUsuarioLogado().Nome),
                    new ReportParameter("tipo", tipo),
                    new ReportParameter("datainicio", datainicio.ToString("dd/MM/yyyy")),
                    new ReportParameter("datatermino", datatermino.ToString("dd/MM/yyyy"))
                };

                report.SetParameters(parametros);

                //configurações da página ex: margin, top, left ...
                string deviceInfo =
                    "<DeviceInfo>" +
                    "<OutputFormat>PDF</OutputFormat>" +
                    "<PageWidth>29.7cm</PageWidth>" +
                    "<PageHeight>21cm</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));
            }
        }