logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Federico  
#1 Posted : Monday, May 16, 2016 1:03:34 PM(UTC)
Federico

Rank: Newbie

Groups: Registered
Joined: 3/18/2016(UTC)
Posts: 7
Italy

we have a support request regarding the "restrictions", as defined in the reports (The version that we are currently using is the 1.8.)

We have written a c# procedure just to open reports , without using the “Report Designer”.

If the execution of the reports is via the ReportDisegner, the restrictions are properly displayed on the report

Contrarily, If the execution of the reports is activated by and external procedure (written in c # code), the report doesn’t display any prompt at execution restrictions.

We use the code below:

"Report report Report.LoadFromFile = (@" C: \ ProgramData \ Seal Report Repository \ Reports \ test.srex ",repository);
ReportExecution execution ReportExecution = new () {} report = Report;
execution.Execute ();
while (report.Status! = ReportStatus.Executed) System.Threading.Thread.Sleep (100);
execution.GenerateHTMLResult string result = ();
Process.Start (result); "

By c# Code procedure, It looks like you can specify the restrictions’s value only by runtime code (“report.AllRestrictions”)

Is it correct ?

Best Regards
epf  
#2 Posted : Tuesday, May 17, 2016 7:33:25 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
Yes, you can of course control everything,
you can view and test a sample of report creation with a restriction in the new Unit Tests project (get from the last zip or the incoming 2.1).
The code is as below:
Code:

var repository = Repository.Create();
 Report report = Report.Create(repository);
            report.DisplayName = "Sample Report";
            var source = report.Sources.FirstOrDefault(i => i.Name.StartsWith("Northwind"));
            source.MetaData.Tables.Clear();
            //Update the data source with a new table
            var table = source.AddTable(true);
            table.DynamicColumns = true;
            table.Name = "products";
            //Instead of the name, could be a direct SQL statement:
            //table.Sql = "select * from products";
            table.Refresh();

            //Set the source of the default model
            report.Models[0].SourceGUID = source.GUID;
            //Add elements to the reports model
            foreach (var column in table.Columns)
            {
                var element = ReportElement.Create();
                element.MetaColumnGUID = column.GUID;
                element.Name = column.Name;
                element.PivotPosition = PivotPosition.Row;
                element.Source = source;
                report.Models[0].Elements.Add(element);
            }

            //Add a restriction to the model
            var restriction = ReportRestriction.CreateReportRestriction();
            restriction.Source = report.Models[0].Source;
            restriction.Model = report.Models[0];
            restriction.MetaColumnGUID = table.Columns.FirstOrDefault(i => i.Name == "products.ProductName").GUID;
            restriction.SetDefaults();
            restriction.Operator = Operator.Contains;
            restriction.Value1 = "er";
            report.Models[0].Restrictions.Add(restriction);
            //Set the restriction text
            if (!string.IsNullOrEmpty(report.Models[0].Restriction)) report.Models[0].Restriction = string.Format("({0}) AND ", report.Models[0].Restriction);
            report.Models[0].Restriction += ReportRestriction.kStartRestrictionChar + restriction.GUID + ReportRestriction.kStopRestrictionChar;

            //Then execute it
            ReportExecution execution = new ReportExecution() { Report = report };
            execution.Execute();
            while (report.Status != ReportStatus.Executed) System.Threading.Thread.Sleep(100);
            string result = execution.GenerateHTMLResult();
            Process.Start(result);

Edited by user Tuesday, May 17, 2016 7:34:00 AM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.