Page 1 of 2

Exporting to PDF from .mrt Template data relationships not working

Posted: Wed Oct 25, 2023 3:04 pm
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;
}


}

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

Posted: Sat Oct 28, 2023 4:54 pm
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.

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

Posted: Tue Nov 07, 2023 6:02 pm
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

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

Posted: Tue Nov 07, 2023 6:49 pm
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" />

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

Posted: Wed Nov 08, 2023 9:19 am
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.

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

Posted: Wed Nov 08, 2023 12:19 pm
by eduardo.neto
I understand...
If there´s a workaround let me know too plz...

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

Posted: Fri Nov 10, 2023 12:07 am
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.

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

Posted: Tue Nov 14, 2023 9:35 pm
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

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

Posted: Tue Nov 14, 2023 9:43 pm
by Lech Kulikowski
Hello,

Yes, it is supported.

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

Thank you.

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

Posted: Fri Nov 17, 2023 6:46 pm
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!