Hello Dave,
We've discussed this task with one of our customers in an private issue, and there are two solutions for this problem:
1. I do not recommend that you allow end-users to work with the Report Designer. Please review the Action based Permission issue to learn how to disable the Show Report Designer action for certain users. In this case, you can use an approach demonstrated in the How to allow users to create filter via the criteria editor before previewing a report example to allow users to set custom criteria for reported data, and use the following code to filter the report by its owner:
2. Otherwise, the simplest way is to set the required filter via the XtraReport.FilterString property, and hide this property from the Properties grid, as shown in the following code:[C#]public class ViewController1 : ViewController { public ViewController1() { } protected override void OnActivated() { base.OnActivated(); Frame.GetController<WinReportServiceController>().CustomShowPreview += new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview); } void ViewController1_CustomShowPreview(object sender, CustomShowPreviewEventArgs e) { e.Report.FilterString = CriteriaOperator.Parse("Owner.Oid=?", SecuritySystem.CurrentUserId).ToString(); } protected override void OnDeactivating() { base.OnDeactivating(); Frame.GetController<WinReportServiceController>().CustomShowPreview -= new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview); } }
In this case end-users will be able to filter the report via the Filtering object.[C#]public class ViewController1 : ViewController { public ViewController1() { } protected override void OnActivated() { base.OnActivated(); XtraReport.FilterControlProperties += new FilterControlPropertiesEventHandler(XtraReport_FilterControlProperties); Frame.GetController<WinReportServiceController>().CustomShowPreview += new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview); Frame.GetController<WinReportServiceController>().CustomShowDesignForm += new EventHandler<CustomShowDesignFormEventArgs>(ViewController1_CustomShowDesignForm); } void XtraReport_FilterControlProperties(object sender, FilterControlPropertiesEventArgs e) { if (e.Control is XtraReport) { e.Properties.Remove("FilterString"); } } void ViewController1_CustomShowDesignForm(object sender, CustomShowDesignFormEventArgs e) { e.Report.FilterString = CriteriaOperator.Parse("Owner.Oid=?", SecuritySystem.CurrentUserId).ToString(); } void ViewController1_CustomShowPreview(object sender, CustomShowPreviewEventArgs e) { e.Report.FilterString = CriteriaOperator.Parse("Owner.Oid=?", SecuritySystem.CurrentUserId).ToString(); } protected override void OnDeactivating() { base.OnDeactivating(); Frame.GetController<WinReportServiceController>().CustomShowPreview -= new EventHandler<CustomShowPreviewEventArgs>(ViewController1_CustomShowPreview); Frame.GetController<WinReportServiceController>().CustomShowDesignForm -= new EventHandler<CustomShowDesignFormEventArgs>(ViewController1_CustomShowDesignForm); } }
Does any of these solutions meet your requirements?
Thanks,
Anatol
-
Anatol,
Some code has changed, could you help me?
this code: Frame.GetController<WinReportServiceController>()
Error 88 The type 'DevExpress.ExpressApp.Reports.Win.WinReportServiceController' cannot be used as type parameter 'ControllerType' in the generic type or method 'DevExpress.ExpressApp.Frame.GetController<ControllerType>()'. There is no implicit reference conversion from 'DevExpress.ExpressApp.Reports.Win.WinReportServiceController' to 'DevExpress.ExpressApp.Controller'.
The WinReportServiceController class should be convertible to Controller, and it should be possible to pass it to the Frame.GetController method. It is unclear why this functionality does not work in your project. Please ensure that the class name passed to the GetController method references a class from our assembly, and a class with the same name and namespace is not defined in your project. If this does not help, please provide a sample project reproducing the problem.