facing issue in master relation of databands in designer

Stimulsoft Reports.ANGULAR discussion
Post Reply
ShakeebAhmed
Posts: 31
Joined: Wed Nov 12, 2014 2:22 pm

facing issue in master relation of databands in designer

Post by ShakeebAhmed »

I am using stimulsoft designer to design a report in a group by manner where the data is in the form of array of objects so i have used databands in master relation manner and it's working fine in designer preview but when i am exporting the report manually the details are not being displayed properly, this is my code ------


var result = await ExecuteGraphQL(
endpoint: gqlUrl,
query: gqlQuery,
variables: gqlVariables,
timeoutSeconds: 1200,
report: _report
);

// register result into report dataset
try
{
var items = (JArray)result[graphQLSource.Name]["items"];
LogTime(sw, $"[{_report.Name}] GraphQL response convert to DataTable started");
var table = ToDataTable(items, $"{graphQLSource.Name}_items");
LogTime(sw, $"[{_report.Name}] GraphQL response converted to DataTable");
datasources.Add($"{graphQLSource.Name}_items", table);
var payerProgramTable = CreateChildTable(
items,
"providerCategories", // array name in GraphQL
"id",
$"{graphQLSource.Name}_items_providerCategories"
);
datasources.Add($"{graphQLSource.Name}_items_providerCategories", payerProgramTable);

var treatmentTable = CreateItemsTreatmentTable(
items,
"id",
$"{graphQLSource.Name}_items_treatment"
);
datasources.Add($"{graphQLSource.Name}_items_treatment", treatmentTable);

var meenaProgramTable = CreateTreatmentProviderCategoriesTable(
items,
$"{graphQLSource.Name}_items_treatment_providerCategories"
);
datasources.Add($"{graphQLSource.Name}_items_treatment_providerCategories", meenaProgramTable);

var parent = report.Dictionary.DataSources[$"{graphQLSource.Name}_items"];
var child = report.Dictionary.DataSources[$"{graphQLSource.Name}_items_providerCategories"];
var treatment = report.Dictionary.DataSources[$"{graphQLSource.Name}_items_treatment"];
var treatmentChild = report.Dictionary.DataSources[$"{graphQLSource.Name}_items_treatment_providerCategories"];
if (parent != null && child != null)
{
var relation1 = new StiDataRelation("Items_PayerProgram", parent, child, new[] { "id" }, new[] { "parentId" });
report.Dictionary.Relations.Add(relation1);
}
if (parent != null && treatment != null)
{
var relation2 = new StiDataRelation("Items_treatment", parent, treatment, new[] { "id" }, new[] { "parentId" });
report.Dictionary.Relations.Add(relation2);
}
if (treatment != null && treatmentChild != null)
{
var relation3 = new StiDataRelation("Items_MeenaProgram", treatment, treatmentChild, new[] { "id" }, new[] { "treatmentId" });
report.Dictionary.Relations.Add(relation3);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "exception occur while setting data into dictionary");
throw;
} if (datasources.Any())
{
// Step 1: Extract relation information BEFORE clearing
var relationInfo = report.Dictionary.Relations.Cast<StiDataRelation>()
.Select(r => new
{
Name = r.Name,
ParentSourceName = r.ParentSource.Name,
ChildSourceName = r.ChildSource.Name,
ParentColumns = r.ParentColumns.ToArray(),
ChildColumns = r.ChildColumns.ToArray()
})
.ToList();

_logger.LogInformation($"Saved {relationInfo.Count} relations before clearing");

// Step 2: Clear everything
report.Dictionary.DataSources.Clear();
report.Dictionary.Databases.Clear();
report.Dictionary.Relations.Clear();

// Step 3: Register new data sources
foreach (KeyValuePair<string, DataTable> ds in datasources)
{
report.RegData(ds.Key, ds.Value);
_logger.LogInformation($"Registered data source: {ds.Key}");
}

// Step 4: Synchronize to ensure data sources are available
report.Dictionary.Synchronize();
LogTime(sw, $"[{_report.Name}] Report dictionary data set");

// Step 5: Recreate relations using the saved information
foreach (var relInfo in relationInfo)
{
try
{
// Get the NEW data source references by name
var parentSource = report.Dictionary.DataSources[relInfo.ParentSourceName];
var childSource = report.Dictionary.DataSources[relInfo.ChildSourceName];

if (parentSource != null && childSource != null)
{
var newRelation = new StiDataRelation(
relInfo.Name,
parentSource,
childSource,
relInfo.ParentColumns,
relInfo.ChildColumns
);
report.Dictionary.Relations.Add(newRelation);
_logger.LogInformation($"Restored relation: {relInfo.Name} ({relInfo.ParentSourceName}.{string.Join(",", relInfo.ParentColumns)} -> {relInfo.ChildSourceName}.{string.Join(",", relInfo.ChildColumns)})");
}
else
{
_logger.LogWarning($"Could not restore relation {relInfo.Name}. Parent '{relInfo.ParentSourceName}' found: {parentSource != null}, Child '{relInfo.ChildSourceName}' found: {childSource != null}");
}
}
catch (Exception ex)
{
_logger.LogError(ex, $"Error restoring relation {relInfo.Name}");
}
}
foreach (StiDataBand band in report.GetComponents().OfType<StiDataBand>())
{
if (band.DataRelation != null && band.MasterComponent != null)
{
band.MasterComponent = null;
}
}

// Step 6: Final synchronization
report.Dictionary.Synchronize();
LogTime(sw, $"[{_report.Name}] Report relations restored");
}


when i am not doing master component null no data for payer program or meena program is being displayed and when i am doing it the data are not being displayed relation wise, i have also created new relation but am not sure if it's even using those relation as databands have their own relation and the table columns that i have created, and the ones present in databands data relation are different so that could also be the problem but i don't know how am i supposed to fix it, I have attached my designer image to, please do check. I would appreciate help as soon as possible.
Attachments
2.png
2.png (385.41 KiB) Viewed 832 times
Lech Kulikowski
Posts: 7627
Joined: Tue Mar 20, 2018 5:34 am

Re: facing issue in master relation of databands in designer

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
ShakeebAhmed
Posts: 31
Joined: Wed Nov 12, 2014 2:22 pm

Re: facing issue in master relation of databands in designer

Post by ShakeebAhmed »

We did it but it does not works as we expected and the relations aren't forming well. Please check attached zip for solution that we are using.

Attached Zip:
- Solution file for the project that has one API endpoint to generate report
- Please use "reportString.txt" file to grab packedString of report which has everything in it. (graphql datasource and all relations)

It does shows data properly in DESIGNER PREVIEW (with limited data as you know) but when I did fetch the same data using custom method (you can check the code) and covert it to datatable but it didn't work. If I do create hardcoded relations then it works but we need it dynamically to be set.

Thanks.
Attachments
GenerateReportApi.zip
(19.12 KiB) Downloaded 6 times
Lech Kulikowski
Posts: 7627
Joined: Tue Mar 20, 2018 5:34 am

Re: facing issue in master relation of databands in designer

Post by Lech Kulikowski »

Hello,

> If I do create hardcoded relations then it works but we need it dynamically to be set.

Please explain this in more detail.

Thank you.
ShakeebAhmed
Posts: 31
Joined: Wed Nov 12, 2014 2:22 pm

Re: facing issue in master relation of databands in designer

Post by ShakeebAhmed »

Hi,

If you can see the image in my original request, There are relations that I have created in DataSource side which I am utilizing in designer to binding data. if I fetch datasource directly from graphQL and set with RegData() then it does not bind any values in report, hence I tried to create relations in code side replicating designers to test and it does works, check below code which I am talking about.

Code: Select all

                    if (graphQLSourceNames.Any())
                    {
                        foreach (var gqlSourceName in graphQLSourceNames)
                        {
                            var itemsSourceName = $"{gqlSourceName}_items";
        var providerCategoriesSourceName = $"{gqlSourceName}_items_providerCategories";
        var treatmentSourceName = $"{gqlSourceName}_items_treatment";
        var treatmentProviderCategoriesSourceName = $"{gqlSourceName}_items_treatment_providerCategories";

        var providerCategoriesRelation = report.Dictionary.Relations.Cast<StiDataRelation>()
            .FirstOrDefault(r => r.ParentSource?.Name == itemsSourceName &&
                               r.ChildSource?.Name == providerCategoriesSourceName);
                            if (providerCategoriesRelation == null)
                            {
                                var newRelation = new StiDataRelation(
                                    "Relation",
                                    report.Dictionary.DataSources[itemsSourceName],
                                    report.Dictionary.DataSources[providerCategoriesSourceName],
                                    new[] { "id" },
                                    new[] { "parentId" }
                                );
        report.Dictionary.Relations.Add(newRelation);
                            }

                            var treatmentRelation = report.Dictionary.Relations.Cast<StiDataRelation>()
                                .FirstOrDefault(r => r.ParentSource?.Name == itemsSourceName &&
                                                   r.ChildSource?.Name == treatmentSourceName);
                            if (treatmentRelation == null)
                            {
                                var newRelation = new StiDataRelation(
                                    "Relation3",
                                    report.Dictionary.DataSources[itemsSourceName],
                                    report.Dictionary.DataSources[treatmentSourceName],
                                    new[] { "id" },
                                    new[] { "parentId" }
                                );
    report.Dictionary.Relations.Add(newRelation);
                            }

var treatmentProviderCategoriesRelation = report.Dictionary.Relations.Cast<StiDataRelation>()
    .FirstOrDefault(r => r.ParentSource?.Name == treatmentSourceName &&
                       r.ChildSource?.Name == treatmentProviderCategoriesSourceName);
if (treatmentProviderCategoriesRelation == null)
{
    var newRelation = new StiDataRelation(
        "Relation2",
        report.Dictionary.DataSources[treatmentSourceName],
        report.Dictionary.DataSources[treatmentProviderCategoriesSourceName],
        new[] { "id" },
        new[] { "treatmentId" }
    );
    report.Dictionary.Relations.Add(newRelation);
}
                        }
                    }

                   
                    report.Dictionary.Synchronize();
This is hardcoded relations that I have created but in dynamic world this never works for us. What I think of more is creating DataTable is something that causing an issue for graphQL request as in designer preview it does works well. Not sure what am I missing in it.

If you can help us with this would be really appreciated.

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

Re: facing issue in master relation of databands in designer

Post by Lech Kulikowski »

Hello,

The RegData method receives a DataSet that you populate with data; you can also add relations directly to this DataSet, and they will be added to the report with the RegData() method.

Thank you.
ShakeebAhmed
Posts: 31
Joined: Wed Nov 12, 2014 2:22 pm

Re: facing issue in master relation of databands in designer

Post by ShakeebAhmed »

Hello,

That is what my question is, Do we need to create relations hardcoded/manual? It's hard to do that due to dynamic nature of our data sources. Can't we have any other way around? like I can bring GraphQL data and pass it to report which can handle themself to manage all relations and setting up data into it?

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

Re: facing issue in master relation of databands in designer

Post by Lech Kulikowski »

Hello,

Yes, you can, but then the first issue with the timeout will occur again.
As an option, you can implement your own data adapter with all the requirements you need.

Thank you.
Post Reply