How to add Condition Expression

Stimulsoft Reports.NET discussion
Post Reply
markb
Posts: 17
Joined: Fri Jul 07, 2017 10:56 am

How to add Condition Expression

Post by markb »

Hi

I am dynamically generating the report from code using the .net dll version of Stimulsoft. To create a panel i do the following:

Code: Select all

                    // Add Panel
                    var stiPanel = new StiPanel()
                    {
                        Name = panel.Name,
                        Height = panel.Height,
                        Width = panel.Width,
                        DockStyle = StiDockStyle.Top,
                        CanGrow = true,
                        CanBreak = false
                    };
                    dataBand.Components.Add(stiPanel);

                    // Set the Visibility of the Panel (if specified)
                       var condition = new StiCondition
                       {
                           Expression = new StiExpression("table_name.field_name != true"),
                           Enabled = false
                       };
                       stiPanel.Conditions.Add(condition);
I expected this would create an expression based condition, however it does create the condition but without the expression.
So I tried the following method call instead, and it does exactly the same.

Code: Select all

                        var condition = new StiCondition("table_name.field_name != true", Color.Black, Color.White, font, false);
Can you explain how to create an expression based condition on a panel from code behind?
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: How to add Condition Expression

Post by Edward »

Hi Mark,

The quickest way to investigate the internal reports components features and properties, the order of their creation is just to use the Code Tab and to follow the declarations of the required components. Please check it out, how easy that is achieved:
https://www.youtube.com/watch?v=BDDDC_XkxN0

Please create the expression as a delegate for the Panel1.BeforePrint event handler.

Just search in the Code Tab something like that:

Code: Select all

private void Panel1_Conditions(object sender, System.EventArgs e)
Thank you,
Edward
markb
Posts: 17
Joined: Fri Jul 07, 2017 10:56 am

Re: How to add Condition Expression

Post by markb »

Hi Edward

Unfortunately I need to create the expression as part of the design, and not at runtime, so that the user can edit it in the designer. So to simplify the code :

Code: Select all

        public void CreateReport(string reportName)
        {
            var report = new StiReport {ReportName = reportName, ReportUnit = StiReportUnitType.Millimeters};
            report.Pages[0].ReportUnit = StiUnit.Millimeters;
            var dataBand = new StiDataBand {Name = "DataBand1", Height = 100};
            report.Pages[0].Components.Add(dataBand);
            var panel = new StiPanel {Name = "Panel1", Height = 100, Width = report.Pages[0].Width};
            var expression = new StiExpression("table_name.field_name != true");
            var condition = new StiCondition {Expression = expression, Enabled = false};
            panel.Conditions.Add(condition);
            dataBand.Components.Add(panel);
            report.Save(Server.MapPath(reportName + ".mrt"));
        }
This example creates an example report, but when checking the report xml you will notice, the databand is there, the panel is there, the condition is there, but the expression text has disappeared. The code sample is syntactically correct, so how do I add an expression in this example?

Regards

Mark
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: How to add Condition Expression

Post by Edward »

Hi Mark,

Is it possible if you send the sample project with that approach to support[at]stimulsoft.com so we can review it?

Thank you,
Edward
markb
Posts: 17
Joined: Fri Jul 07, 2017 10:56 am

Re: How to add Condition Expression

Post by markb »

Hi Edward

I've tried to email it via support, but I'm not getting the automated response, so I'm not sure you are receiving it. So I'm also posting it here for your reference,

Mark
Attachments
Example Project.zip
Visual Studio Project
(3.3 MiB) Downloaded 284 times
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: How to add Condition Expression

Post by Edward »

Hi Mark,

Yes, that could be some spam filters probably on your on our side, which is strange.

We will review your example and will come back to you shortly on that.

Thank you,
Edward
markb
Posts: 17
Joined: Fri Jul 07, 2017 10:56 am

Re: How to add Condition Expression

Post by markb »

Still unable to add a condition expression from code with version 2017.2.1.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: How to add Condition Expression

Post by HighAley »

Hello, Mark.

You didn't set the Item property of the StiCondition.
Please, look at this code:

Code: Select all

var condition = new StiCondition
{
    Item = StiFilterItem.Expression,
    Expression = new StiExpression("table_name.field_name != true"),
    Enabled = false
};
Maybe you should also set the Font and BackColor properties.

Thank you.
Post Reply