Inherited reports

edited 10:20AM in FastReport .NET
I know Inheritance does have some limitations.
Like, do not use parameters in the base report.

I am not happy with that and try to create a workaround.
Because we do have hundreds of reports. A lot of them are a look a like of another report..
In the base reports we like to do the general settings by using parameters (for example 'show_price').
In the inherited reports we change only some fields,groups, sorts.


I am thinking about a workaround:
1. I Load the report by code
2. Detach the report by cocde
3. Give the parameters the right value.

Questions:
Is it possible to Load a report and Detach the Base report by code?
If not. Do you have plans to remove the limitations of inherited reports?


Comments

  • edited 10:20AM
    With the code below it is possible to use a basereport with parameters and totals.
    After loading the report by code, the basereport is resetted and all double parameters and totals are removed.
    Then it works fine.
    using (Designer frDesigner = new Designer())
                    {
                        report1.BaseReport = "";
                        report1.Designer = frDesigner;
                        report1.Designer.SetModified(this, "EditReport");
                    }
                    string xmlFR = report1.SaveToString();
                    string xmlHdr = xmlFR.Substring(1, xmlFR.IndexOf("\r\n") + 1);
                    xmlFR = xmlFR.Substring(xmlFR.IndexOf("\r\n") + 2);
                    XDocument xdoc = XDocument.Parse(xmlFR);
                    //remove double Parameters and Totals
                    xdoc.Root.Elements("Dictionary").Elements("Parameter")
                        .GroupBy(s => (string)s.Attribute("Name"))
                        .SelectMany(g => g.Skip(1)) // select all nodes from group except first one
                        .Remove();
                    xdoc.Root.Elements("Dictionary").Elements("Total")
                        .GroupBy(s => (string)s.Attribute("Name"))
                        .SelectMany(g => g.Skip(1)) // select all nodes from group except first one
                        .Remove();
                    string xmlResult = xmlHdr + xdoc.ToString(SaveOptions.DisableFormatting);
                    xmlResult = xmlResult.Replace("\r\n", Environment.NewLine);
                    report1.Clear();
                    report1.LoadFromString(xmlResult);
    

Leave a Comment