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

Notification

Icon
Error

Options
Go to last post Go to first unread
Mycroft  
#1 Posted : Monday, May 8, 2017 10:18:14 PM(UTC)
Mycroft

Rank: Member

Groups: Registered
Joined: 2/25/2017(UTC)
Posts: 13
Mexico
Location: Monterrey

Hi

Is it possible to set the value of a restriction at the init script without prompt?
And if is possible how can I do it?

Thanks.
epf  
#2 Posted : Tuesday, May 9, 2017 6:49:28 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
Yes, select the main 'Views' node in the tree view, then you can edit the property 'Init Script', you have several samples to modify your restrictions:

Code:
    //Script executed when the report is initialized
    log.LogMessage("Executing Init Script");
    //report.Models[0].Restrictions[0].Value1 = "1994"; 
    //report.Models[0].Restrictions[0].Date1 = DateTime.Now.AddYears(-20);
    //report.Models[0].GetRestrictionByName("Order Year").Value1 = "2015";
    //report.Models[0].GetRestrictionByName("Category").EnumValues.Add("1");

    //report.DisplayName = System.IO.Path.GetFileNameWithoutExtension(report.FilePath) + "-" + DateTime.Now.ToShortDateString();
    
    //Set the first value of an enum
    //var enums = report.Models[0].Source.MetaData.Enums.FirstOrDefault(i=>i.Name == "Category");
    //report.Models[0].GetRestrictionByName("Category").EnumValues.Add(enums.Values[0].Id);



Additional properties for the restrictions are:
public bool Required
public PromptType Prompt

where PromptType can be:
[Description("No prompt")]
None,
[Description("Prompt at execution")]
Prompt,
[Description("Prompt only one value")]
PromptOneValue,

e.g.
Code:
report.Models[0].Restrictions[0].Required = false; 
report.Models[0].Restrictions[0].Prompt = PromptType.None; 

Edited by user Tuesday, May 9, 2017 6:53:43 AM(UTC)  | Reason: Not specified

netpacket  
#3 Posted : Tuesday, April 23, 2019 10:21:58 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi,
I have a report that includes about 20 models. These models have some restrictions in common. My questions are:
1)How can I update my restrictions at start with your code but in a report with many models.

2)how can I set a restriction in one model to the value of another restriction in another model.

Thanks in advance
epf  
#4 Posted : Wednesday, April 24, 2019 6:10:45 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
It is just browsing the report models and restrictions:

Code:
    
      foreach (var model in report.Models) {
        foreach (var restriction in model.Restrictions) {
            restriction.Value1 = "1994"; 
        }
    }


You can also take restriction 1 from model 1 to update restriction 2 of model 2....
thanks 1 user thanked epf for this useful post.
netpacket on 4/24/2019(UTC)
netpacket  
#5 Posted : Wednesday, April 24, 2019 7:12:52 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi epf, thanks for responding.
I have attached a sample report based on Northwind. I want "Supplier Country" in "model" to be set by default to the first item in its enumerated list.Then I need to make "Customer Contry" in "model2" to be equal to the values selected in model1's "Supplier Country".
Restriction.srex

I cant't attach files, so uploaded it to my google drive.
I used your code with no luck.I really appreciate it if you would fix the attached report.
Thanks

Edited by user Wednesday, April 24, 2019 10:09:22 AM(UTC)  | Reason: Not specified

netpacket  
#6 Posted : Thursday, April 25, 2019 5:05:00 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi,
This is the code I added to my init script:
Code:
        var modelSource = report.Models[0];
     
    foreach (var model in report.Models) {
      
        foreach (var restriction in model.Restrictions) {
        
        if(restriction.Name == "Customer-Country") {
        restriction.EnumValues = modelSource.GetRestrictionByName("Supplier Country").EnumValues;
        
        }   
        }
        }


but it seem there is something wrong with this line:
Code:
if(restriction.Name == "Customer-Country")


As soon as I change it to
Code:
if(restriction.Name != null)
everything works fine.
Could you please correct me , Thanks.
netpacket  
#7 Posted : Thursday, April 25, 2019 5:32:19 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Problem Solved!
I changed
Code:
restriction.Name
with
Code:
restriction.DisplayNameEl
and it works just fine now.
Thanks
netpacket  
#8 Posted : Saturday, October 5, 2019 10:21:37 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi,
What if I want to update the other restrictions operator to the main restriction operator.For example my report has two date type restrictions : MainDate & SubDate. I want SubDate's operator and restrction value be set to whatever is selected for MainDate.
How is that possible?


PS: I have added this code to my init script to just update the restriction values :
Code:
  var modelSource = report.Models[0];
     
    foreach (var model in report.Models) {
      
        foreach (var restriction in model.Restrictions) {
        
        if(restriction.DisplayNameEl == "SubDate") {
        restriction.Date1 = modelSource.GetRestrictionByName("MainDate").Date1;
        restriction.Date2 = modelSource.GetRestrictionByName("MainDate").Date2;
        
        }


But there is a problem that at first execution of my report the "MainDate" values are not updated to "SubDate" but at the second execution it works fine !!!

Edited by user Sunday, October 6, 2019 8:14:38 AM(UTC)  | Reason: Not specified

epf  
#9 Posted : Monday, October 7, 2019 7:56:07 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
I made a quick test on the 'Order Search' sample report.
Just added the 'Required Date' as a restriction and the following init script:
Code:
    var restr = modelSource.GetRestrictionByName("Required Date");
    restr.Date1 = modelSource.GetRestrictionByName("Order Date").Date1; 
    restr.Date2 = modelSource.GetRestrictionByName("Order Date").Date2;

and this works fine at the first execution... can you redo the sample to find the problem
netpacket  
#10 Posted : Monday, October 7, 2019 8:12:33 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Originally Posted by: epf Go to Quoted Post
I made a quick test on the 'Order Search' sample report.
Just added the 'Required Date' as a restriction and the following init script:
Code:
    var restr = modelSource.GetRestrictionByName("Required Date");
    restr.Date1 = modelSource.GetRestrictionByName("Order Date").Date1; 
    restr.Date2 = modelSource.GetRestrictionByName("Order Date").Date2;

and this works fine at the first execution... can you redo the sample to find the problem



Hi epf,
I did what you mentioned above , but the operator for "Order Date" is set to "is between"
bu the operator for "Required Date" is "Equals". How to update the operators??
Thanks
epf  
#11 Posted : Monday, October 7, 2019 11:46:11 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
Actually, you should use the Pre-Load Script of your model to update the restriction values:
Select you model, then edit the 'Pre-Load Script' property and set:

Here is the code to update the restriction:

Code:
@using Seal.Model
@{
    ReportModel model = Model;
    var modelSource = model.Report.Models[0];
    var restrSource = modelSource.GetRestrictionByName("Order Date");
    var restr = model.GetRestrictionByName("Required Date");
    
    restr.Date1 = restrSource.Date1; 
    restr.Date2 = restrSource.Date2;
    restr.Operator = restrSource.Operator;    
}




Check also: https://sealreport.org/H...ad-09f5-b2facac3ff82.htm

Edited by user Monday, October 7, 2019 11:53:27 AM(UTC)  | Reason: Not specified

netpacket  
#12 Posted : Tuesday, October 8, 2019 7:34:19 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi epf,
The init script works fine. The problem is that when the restriction is date/time type, it is not updated at the first execution .
I attached a sample to show that:
Just Open the report and before executing it change the end time to "1/30/1995". You will see results that have Required Date of 1/31/1995 ,although I have changed the init script to make the Required Date the same as Order Date. But if you just press execute for the second time you will notice that only results with Required Date of 1/30/1995 are shown.
https://gofile.io/?c=1rbvOH

I have no problem with other restriction using enumlist. Only date/time type is making problem.
Thanks

Edited by user Tuesday, October 8, 2019 7:37:51 AM(UTC)  | Reason: Not specified

epf  
#13 Posted : Tuesday, October 8, 2019 2:54:30 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
I checked the code and it appears that the Init Script is executed before the prompted restrictions are set in the report...
So you should move your code the the 'Pre Load' script of your models...

Note that you can share C# function/script using the Server Manager -> Configure Server and then create a Common Script using the 'Common Scripts' property.
Then just call your function from any script in your reports.
netpacket  
#14 Posted : Wednesday, October 9, 2019 6:24:44 AM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Originally Posted by: epf Go to Quoted Post
I checked the code and it appears that the Init Script is executed before the prompted restrictions are set in the report...
So you should move your code the the 'Pre Load' script of your models...

Note that you can share C# function/script using the Server Manager -> Configure Server and then create a Common Script using the 'Common Scripts' property.
Then just call your function from any script in your reports.


Hi epf,
I just edited this report and changed the restriction to enumlist type and added the "DateEnum" enumlist to Northwind DB.
You can see in this Report that whatever you set for the first restriction gets updated to the second one even at the first report execution.

Report & DB

So it appears Init Script is executed after the prompted restrictions are set in the report When they are set to custom enumlist.

Edited by user Wednesday, October 9, 2019 6:26:37 AM(UTC)  | Reason: Not specified

netpacket  
#15 Posted : Wednesday, October 16, 2019 10:23:44 PM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi epf,
Did you get any chance to check what the problem is?
Thanks
epf  
#16 Posted : Thursday, October 17, 2019 3:04:01 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
Yes, in your sample you assign the reference of the Enum Value list...so you did not made the copy by value (it's C# consideration).

Code:
restriction.EnumValues = modelSource.GetRestrictionByName("Order Date").EnumValues;


so it works because the EnumValues of the "Required Date" restriction is the same object as the one of the "Order Date" restriction

once again you should not use the Init Script to do that, the best practice is to create a Task that will do the job:

Just create a task in you report, then add the following script:

Code:
@using Seal.Model
@{
    ReportTask task = Model;
    Report report = task.Report;
    
    report.Models[0].GetRestrictionByName("Required Date").Date1 = report.Models[0].GetRestrictionByName("Order Date").Date1;
    report.Models[0].GetRestrictionByName("Required Date").Date2 = report.Models[0].GetRestrictionByName("Order Date").Date2;    
}


this will always work, even the first time...
netpacket  
#17 Posted : Thursday, October 17, 2019 3:33:47 PM(UTC)
netpacket

Rank: Member

Groups: Registered
Joined: 12/3/2018(UTC)
Posts: 26
Man
Switzerland

Thanks: 12 times
Hi epf, thanks for your reply.
What if there are many models in my report?
epf  
#18 Posted : Thursday, October 17, 2019 3:39:39 PM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 735
Switzerland

Thanks: 14 times
Was thanked: 135 time(s) in 131 post(s)
Code:
    foreach (var model in report.Models) {
    }
Users browsing this topic
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.