Ticket S173169
Visible to All Users

How to easily register many predefined reports using the ReportsV2 module

created 11 years ago (modified 10 years ago)

From Q567392:
"Also, there is one more thing - report registration. Currently, every V2 report needs to be registered in Module.cs. That's also fine for 10-20 reports, but when you have 1000 lines of code for just registering reports … not fun.
Give Report properties like Caption, IsInPlace, AutoRegister and other required properties and just do registration automagically if AutoRegister = true (if for some reason someone wants to add report which doesn't want to be accessible through Reports class). "
I think that we can simplify the current procedure and introduce either a special attribute or interface to mark an XtraReport to be registered and then the XAF's code would look for it within solution modules (like it is done for ViewControllers). For now, it is always possible to implement a custom attribute and registration code yourself.

Comments (2)

    Am I really the only one who needs to write lots of reports? :)

    Dennis Garavsky (DevExpress) 10 years ago

      @Mario: To be honest, we have not had other similar requests from our customers so far (though, this request was tracked by 3 more guys in ~1.5 year).
      Maybe other users had already implemented their own attribute and wrote an automatic registration routine themselves?

      Answers approved by DevExpress Support

      created 10 years ago (modified 7 years ago)

      Hello,

      While in XAF we cannot add new properties like Caption, Category, IsInplace, ParametersObjectType to the base XtraReport class from our shared DevExpress XtraReports library (essentially because these properties will have meaning only in XAF solutions and will not make much sense in non-XAF applications),
      it is possible to implement a custom .NET code attribute with all the required options:

      STEP 1

      C#
      public class RegisterReportAttribute : Attribute { public string DisplayName { get; private set; } public Type DataType { get; private set; } public Type ParametersObjectType { get; private set; } public bool InplaceReport { get; private set; } public RegisterReportAttribute(string displayName, Type dataType = null, Type parametersObjectType = null, bool isInplaceReport = false) { DisplayName = displayName; DataType = dataType; ParametersObjectType = parametersObjectType; InplaceReport = isInplaceReport; } }

      Once you did so, you can use this custom attribute with your XtraReport descendants as follows:

      C#
      [RegisterReport("Report1")] public partial class ContactsReport : XtraReport

      STEP 2
      Register all reports marked with this attribute via a helper class:

      C#
      public static class RegisterPredefienedReportsHelper { public static IEnumerable<PredefinedReportDataContainer> FindReports() { List<PredefinedReportDataContainer> reportContainers = new List<PredefinedReportDataContainer>(); foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) { if (typeof(XtraReport).IsAssignableFrom(type)) { var attributes = type.GetCustomAttributes(typeof(RegisterReportAttribute), false); if (attributes.Length > 0) { RegisterReportAttribute reportInfo = ((RegisterReportAttribute)attributes[0]); reportContainers.Add(new PredefinedReportDataContainer(type, reportInfo.DisplayName, reportInfo.DataType, reportInfo.ParametersObjectType, reportInfo.InplaceReport)); } } } return reportContainers; } }

      STEP 3
      This helper class is still supposed to be used with the standard PredefinedReportsUpdater class in the body of your ModuleBase descendant (typically located in the Module.cs file) as follows:

      C#
      namespace YourSolutionName.Module {   public sealed partial class YourSolutionNameModule : ModuleBase public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) { ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB); PredefinedReportsUpdater predefinedReportsUpdater = new PredefinedReportsUpdater(Application, objectSpace, versionFromDB); foreach (var container in RegisterPredefienedReportsHelper.FindReports()) { predefinedReportsUpdater.AddPredefinedReport(container); } return new ModuleUpdater[] { updater, predefinedReportsUpdater }; } } }

      Refer to the 5th step of the eXpressApp Framework > Concepts > Extra Modules > Reports V2 Module > Create Predefined Static Reports tutorial for more information on this standard registration procedure.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.