Exemple #1
0
        public HttpResponseMessage RelFaturamento(DateTime datainicio, DateTime datatermino, int?idprofissional, int?idpaciente, string situacao, string tipo)
        {
            try
            {
                if (datainicio > datatermino)
                {
                    throw new Exception("Periodo inválido");
                }

                var    lista        = _serviceRelatorio.RelFaturamento(datainicio, datatermino, idprofissional, idpaciente, situacao, tipo, base.GetUsuarioLogado().IdClinica);
                string profissional = "";
                if (idprofissional > 0)
                {
                    profissional = _serviceCadastro.ObterFuncionarioById((int)idprofissional).Pessoa.Nome;
                }
                else
                {
                    profissional = "Todos";
                }

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

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

                if (tipo == "C")
                {
                    tipo = "Convênio";
                }
                else
                {
                    tipo = "Particular";
                }

                ReportParameter[] parametros = new ReportParameter[] {
                    new ReportParameter("usuario", base.GetUsuarioLogado().Nome),
                    new ReportParameter("tipo", tipo),
                    new ReportParameter("profissional", profissional),
                    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));
            }
        }