Exporting to PDF from .mrt Template data relationships not working

Stimulsoft Reports.NET discussion
eduardo.neto
Posts: 13
Joined: Wed Aug 03, 2022 6:36 pm

Exporting to PDF from .mrt Template data relationships not working

Post by eduardo.neto »

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;
}


}
Attachments
relatorio-mov-analitico-638338317645163329.pdf
(155.73 KiB) Downloaded 327 times
json-data.txt
(7.34 KiB) Downloaded 432 times
relatorio-consolidado-mov-analit.mrt
(79.99 KiB) Downloaded 323 times
Lech Kulikowski
Posts: 7334
Joined: Tue Mar 20, 2018 5:34 am

Re: Exporting to PDF from .mrt Template data relationships not working

Post by Lech Kulikowski »

Hello,

Some data sources are not present in the sent data. Please check it and sent test data for your report.

Thank you.
Attachments
Screenshot 2023-10-28 185414.png
Screenshot 2023-10-28 185414.png (173.46 KiB) Viewed 15602 times
eduardo.neto
Posts: 13
Joined: Wed Aug 03, 2022 6:36 pm

Re: Exporting to PDF from .mrt Template data relationships not working

Post by eduardo.neto »

Hello, thanks for the reply. I have trying different ways to do this working... The last attempt was this:

public async Task<string> GerarRelatorioEmPDFLogCCConsolidadoAnaliticoMovimentacao(FiltroLogMovCC filtro)
{

try
{
IList<LogMovimentacoesPedidosUsuario> relatorio = await _contaCorrenteDal.ObtenhaLogsConsolidadoAnaliticoMovimentacoes(filtro);

var c = relatorio.Count;

if (!relatorio.Any()) return "";

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 = $"{Guid.NewGuid()}.pdf";

StiOptions.Export.Pdf.AllowImportSystemLibraries = false;

using (var report = new StiReport())
{
report.Load(pathRelatorio);

var filtros = new
{
DataInicial = filtro.DataInicial,
DataFinal = filtro.DataFinal
};


var dados = new
{
relatorio = relatorio,
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));
using (data)
{
report.RegData("", null, data);

report.Dictionary.Synchronize();
report.Render(false);



var settings = new StiPdfExportSettings();
var service = new StiPdfExportService();
using (var stream = new MemoryStream())
{
service.ExportTo(report, stream, settings);

string urlImagem = _stimulsoftS3Bll.Upload(stream, nomeArquivo);
return urlImagem;
}
}
}

}
catch (Exception e)
{
throw;
}

}

The json data in attach is what i send to the method its formet as:
var dados = new
{
relatorio = relatorio,
filtros = filtros
};

I really don't know what to do anymore...please help
Attachments
Wrong-Report-Builded Via DotNet.pdf
(119.53 KiB) Downloaded 365 times
Correct-Report-Builded Via Angular.pdf
(140.99 KiB) Downloaded 381 times
json-data-sample2.json
(23.71 KiB) Downloaded 305 times
eduardo.neto
Posts: 13
Joined: Wed Aug 03, 2022 6:36 pm

Re: Exporting to PDF from .mrt Template data relationships not working

Post by eduardo.neto »

I dont know if this can be related but im using this version:

<PackageReference Include="Stimulsoft.Dashboards.Web.NetCore" Version="2019.4.2" />
<PackageReference Include="Stimulsoft.Reports.Web.NetCore" Version="2019.4.2" />
Lech Kulikowski
Posts: 7334
Joined: Tue Mar 20, 2018 5:34 am

Re: Exporting to PDF from .mrt Template data relationships not working

Post by Lech Kulikowski »

Hello,

Please check the last release build.
If the issue is still present, please send us a sample project that we can run and reproduce the issue.

Thank you.
eduardo.neto
Posts: 13
Joined: Wed Aug 03, 2022 6:36 pm

Re: Exporting to PDF from .mrt Template data relationships not working

Post by eduardo.neto »

I understand...
If there´s a workaround let me know too plz...
Lech Kulikowski
Posts: 7334
Joined: Tue Mar 20, 2018 5:34 am

Re: Exporting to PDF from .mrt Template data relationships not working

Post by Lech Kulikowski »

Hello,

We couldn't reproduce the issue on our samples.

Please check the last release build.
If the issue is still present, please send us a sample project that we can run and reproduce the issue.

Thank you.
eduardo.neto
Posts: 13
Joined: Wed Aug 03, 2022 6:36 pm

Re: Exporting to PDF from .mrt Template data relationships not working

Post by eduardo.neto »

Does Stimulsoft supports .Net 7?
I tried run the same code and i got this exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. O sistema não pode encontrar o arquivo especificado.
File name: 'System.Windows.Forms, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
at Stimulsoft.Report.StiReport..ctor()
at MaxGestao.BLL.ContaCorrenteBll.GerarRelatorioEmPDFLogCCConsolidadoAnaliticoMovimentacao(FiltroLogMovCC filtro) in C:\Maxima Sistemas\maxgestao\MaxGestao.BLL\ContaCorrenteBll.cs:line 180

The exception is thrown when i try to instantiate like this "var report = new StiReport()"

Thanks
Lech Kulikowski
Posts: 7334
Joined: Tue Mar 20, 2018 5:34 am

Re: Exporting to PDF from .mrt Template data relationships not working

Post by Lech Kulikowski »

Hello,

Yes, it is supported.

Please send us a sample project that we can run and reproduce the issue.

Thank you.
eduardo.neto
Posts: 13
Joined: Wed Aug 03, 2022 6:36 pm

Re: Exporting to PDF from .mrt Template data relationships not working

Post by eduardo.neto »

I was using Stimulsoft.Reports.Net, and it wasn't working. Then i switched to "Stimulsoft.Dashboards.Web.NetCore" Version="2023.4.3"
"Stimulsoft.Reports.Web.NetCore" Version="2023.4.3" and it generated, but with duplicate rows as i said before :(.
The correct is to follow the structure of the json that i put inside of the project as a sample of the response of a service that our project use.

Sample project in attach.
Thanks!
Attachments
sample-project.rar
(33.71 MiB) Downloaded 248 times
Post Reply