Exporting to PDF from .mrt Template data relationships not working
Posted: Wed Oct 25, 2023 3:04 pm
Hello, im facing some troubles while loading and exporting data to my .mrt report template.
The Data "Pedidos" that have a list of "Produtos" does not regonize the relationship, as seen on .PDF file, comparing to the JSON FILE.
The .mrt and the json are in attachments.
Do you guys can help me plz?
-- CODE USED
public async Task<string> GerarRelatorioEmPDFLogCCConsolidadoAnaliticoMovimentacao(FiltroLogMovCC filtro)
{
try
{
IList<LogMovimentacoesPedidosUsuario> conteudo = await _contaCorrenteDal.ObtenhaLogsConsolidadoAnaliticoMovimentacoes(filtro); ;
string path = Path.Combine(_hostingEnvironment.ContentRootPath, "relatorios");
string nomeRelatorio = "relatorio-consolidado-mov-analit";
if (filtro.RelatorioSintetico)
{
nomeRelatorio = "relatorio-consolidado-mov-analit-sintetico";
}
if (filtro.OrdenarVisualizacaoPorPedidos)
{
nomeRelatorio += "-ordem-invertida";
}
string pathRelatorio = Path.Combine(path, $"{nomeRelatorio}.mrt");
var nomeArquivo = $"relatorio-mov-analitico-{DateTime.Now.Ticks}.pdf";
var pathResult = Path.Combine(path, nomeArquivo);
StiOptions.Export.Pdf.AllowImportSystemLibraries = false;
using (var report = new StiReport())
{
report.Load(pathRelatorio);
//report.Compile();
var filtros = new
{
DataInicial = filtro.DataInicial,
DataFinal = filtro.DataFinal
};
var dados = new
{
relatorio = conteudo,
filtros = filtros
};
Stimulsoft.Base.StiLicense.Key = await _stimulsoftS3Bll.RetornarChaveStimulsoft();
var listaDados = JsonConvert.SerializeObject(dados);
report.Dictionary.DataSources.Clear();
DataSet data = Stimulsoft.Base.StiJsonToDataSetConverterV2.GetDataSet(Stimulsoft.Base.Json.Linq.JToken.Parse(listaDados));
report.RegData("filtros", data.Tables["filtros"]);
report.RegData("relatorio", data.Tables["relatorio"]);
report.RegData("relatorio_movimentacoes", data.Tables["relatorio_movimentacoes"]);
report.RegData("relatorio_pedidos", data.Tables["relatorio_pedidos"]);
report.RegData("relatorio_pedidos_produtos", data.Tables["relatorio_pedidos_produtos"]);
await report.Dictionary.SynchronizeAsync();
await report.RenderAsync();
byte[] documentoExportar = report.SaveDocumentToByteArray();
var settings = new StiPdfExportSettings();
var service = new StiPdfExportService();
var stream = new MemoryStream(documentoExportar);
service.ExportTo(report, stream, settings);
string urlImagem = await _stimulsoftS3Bll.Upload(stream, nomeArquivo);
return urlImagem;
}
}
catch (Exception e)
{
return e.Message;
}
}
The Data "Pedidos" that have a list of "Produtos" does not regonize the relationship, as seen on .PDF file, comparing to the JSON FILE.
The .mrt and the json are in attachments.
Do you guys can help me plz?
-- CODE USED
public async Task<string> GerarRelatorioEmPDFLogCCConsolidadoAnaliticoMovimentacao(FiltroLogMovCC filtro)
{
try
{
IList<LogMovimentacoesPedidosUsuario> conteudo = await _contaCorrenteDal.ObtenhaLogsConsolidadoAnaliticoMovimentacoes(filtro); ;
string path = Path.Combine(_hostingEnvironment.ContentRootPath, "relatorios");
string nomeRelatorio = "relatorio-consolidado-mov-analit";
if (filtro.RelatorioSintetico)
{
nomeRelatorio = "relatorio-consolidado-mov-analit-sintetico";
}
if (filtro.OrdenarVisualizacaoPorPedidos)
{
nomeRelatorio += "-ordem-invertida";
}
string pathRelatorio = Path.Combine(path, $"{nomeRelatorio}.mrt");
var nomeArquivo = $"relatorio-mov-analitico-{DateTime.Now.Ticks}.pdf";
var pathResult = Path.Combine(path, nomeArquivo);
StiOptions.Export.Pdf.AllowImportSystemLibraries = false;
using (var report = new StiReport())
{
report.Load(pathRelatorio);
//report.Compile();
var filtros = new
{
DataInicial = filtro.DataInicial,
DataFinal = filtro.DataFinal
};
var dados = new
{
relatorio = conteudo,
filtros = filtros
};
Stimulsoft.Base.StiLicense.Key = await _stimulsoftS3Bll.RetornarChaveStimulsoft();
var listaDados = JsonConvert.SerializeObject(dados);
report.Dictionary.DataSources.Clear();
DataSet data = Stimulsoft.Base.StiJsonToDataSetConverterV2.GetDataSet(Stimulsoft.Base.Json.Linq.JToken.Parse(listaDados));
report.RegData("filtros", data.Tables["filtros"]);
report.RegData("relatorio", data.Tables["relatorio"]);
report.RegData("relatorio_movimentacoes", data.Tables["relatorio_movimentacoes"]);
report.RegData("relatorio_pedidos", data.Tables["relatorio_pedidos"]);
report.RegData("relatorio_pedidos_produtos", data.Tables["relatorio_pedidos_produtos"]);
await report.Dictionary.SynchronizeAsync();
await report.RenderAsync();
byte[] documentoExportar = report.SaveDocumentToByteArray();
var settings = new StiPdfExportSettings();
var service = new StiPdfExportService();
var stream = new MemoryStream(documentoExportar);
service.ExportTo(report, stream, settings);
string urlImagem = await _stimulsoftS3Bll.Upload(stream, nomeArquivo);
return urlImagem;
}
}
catch (Exception e)
{
return e.Message;
}
}