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
Ali  
#1 Posted : Monday, December 5, 2016 10:44:48 AM(UTC)
Ali

Rank: Newbie

Groups: Registered
Joined: 5/27/2016(UTC)
Posts: 1
Saudi Arabia
Location: Dubai

Thanks: 1 times
Hi,
I use the following code in VB to launch my report, the report has two restrictions , I assign at run-time hard-coded values but it seems that the query does not identify, am I missing something?


' Load report from srex file
Dim repos As Repository = Repository.Create
Dim rep As Report = Report.LoadFromFile("C:\ProgramData\Seal Report Repository\Reports\QResults.srex", repos)
'
rep.Models(0).Restrictions(0).Required = False
rep.Models(0).Restrictions(1).Required = False

rep.Models(0).Restrictions(0).EnumValues.Add(2)
' debug message
Msg.Text = rep.Models(0).Sql


Dim ex As New Seal.Model.ReportExecution With {.Report = rep}
ex.Execute()
While (rep.Status <> ReportStatus.Executed)
System.Threading.Thread.Sleep(100)
End While
Dim result As String = ex.GenerateHTMLResult
Process.Start(result)

Edited by user Monday, December 5, 2016 12:04:12 PM(UTC)  | Reason: more descriptive subject

epf  
#2 Posted : Monday, December 5, 2016 12:20:11 PM(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)
Are you sure that your restriction references an Enum Value ?
If not, the values of the restriction must be set in rep.Models(0).Restrictions(0).Value1
Here is the sample code from the TestAndSamples projects:

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 Monday, December 5, 2016 12:21:10 PM(UTC)  | Reason: Not specified

thanks 1 user thanked epf for this useful post.
Ali on 12/7/2016(UTC)
Ali  
#3 Posted : Wednesday, December 7, 2016 6:58:33 AM(UTC)
Ali

Rank: Newbie

Groups: Registered
Joined: 5/27/2016(UTC)
Posts: 1
Saudi Arabia
Location: Dubai

Thanks: 1 times
My restrictions where based on Enums allright, the problem was that they were defined as "prompt" and the generated HTMl does not display restriction but expect they should be (?) and produces error message, what I did is the I set the restrictions as "no prompt" and it worked fine.
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.