How do you create a custom datasource

lollol
edited 3:25PM in FastReport .NET
Hello,

I saw a very interesting post named "Custom Datasource type", by danielrail, on Aug 19 2008, 11:02 AM. but to my understanding, the solution was left pending, as there was some work to do to make it available in FR.net.

I would like to know if it is already available, because I downloaded the demo version, and it is very impressive, but the business object layer is still fully preloaded and no generated on demand.

I need to be able to generate the detail on the fly, because my master data normally is around 10,000 objects, and the detail around 1,000 objects each, so preloading that information would require 10 million objects to be present in memory vs 11,000 objects if I generate the default on demand.

This is functionality I need in order to finish my new c# application and upgrade my FR studio to FR.net, as my old application (VB) uses many UserDataSets.

Thank you,

Luis Ontaneda

Comments

  • edited 3:25PM
    Hello Luis,

    Please confirm if I understood you correctly:
    - you work with business objects
    - you register a business object by report.RegisterData(IEnumerable data, string name, BOConverterFlags flags, int maxNestingLevel) method
    - you need to create master-detail report, and you want to load detail datasource on demand
  • lollol
    edited 3:25PM
    Hi, Alex

    That is correct.

    My domain is time and attendance, so let's say I have :

    1) A employee list
    2) Each employee has a schedule list
    3) I want to be able to report both on Employee and Employee.Schedules
    4) The schedule list must be generated and bound to the detail band (or datasource) just before needed and discarded afterwards.

    The reason as I stated previously is preserving resources.

    Thanks.
  • edited 3:25PM
    Ok, I've added the LoadBusinessObject event to the BusinessObjectDataSource. It will be available in the next build.

    Here is an example of how to use it (it's based on categories/products business object that is used in the demo):
    // make categories list and register it
          List<Category> list = new List<Category>();
          list.Add(new Category("Beverages", "Soft drinks, coffees, teas, beers"));
          list.Add(new Category("Confections", "Desserts, candies, and sweet breads"));
          list.Add(new Category("Seafood", "Seaweed and fish"));
          FReport.RegisterData(list, "Categories BusinessObject", BOConverterFlags.AllowFields, 3);
          
    // find the Products datasource and attach an event to it
          BusinessObjectDataSource ds = FReport.GetDataSource("Categories BusinessObject.Products") as BusinessObjectDataSource;
          if (ds != null)
            ds.LoadBusinessObject += new LoadBusinessObjectEventHandler(ds_LoadBusinessObject);
    
        private void ds_LoadBusinessObject(object sender, LoadBusinessObjectEventArgs e)
        {
    // e.Parent is Category instance, load its Products list
          Category category = e.Parent as Category;
          category.Products.Clear();
    
          switch (category.Name)
          {
            case "Beverages":
              category.Products.Add(new Product("Chai", 18m));
              category.Products.Add(new Product("Chang", 19m));
              category.Products.Add(new Product("Ipoh coffee", 46m));
              break;
    
            case "Confections":
              category.Products.Add(new Product("Chocolade", 12.75m));
              category.Products.Add(new Product("Scottish Longbreads", 12.5m));
              category.Products.Add(new Product("Tarte au sucre", 49.3m));
              break;
    
            case "Seafood":
              category.Products.Add(new Product("Boston Crab Meat", 18.4m));
              category.Products.Add(new Product("Red caviar", 15m));
              break;
          }
        }
    

    As you can see, there is no event like "UnloadData". It's because FastReport does not know exactly when the data is no longer needed. So you need to unload previous data in the same LoadBusinessObject event. Something like this:
        private Category FLastCategory;
    
        private void ds_LoadBusinessObject(object sender, LoadBusinessObjectEventArgs e)
        {
    // e.Parent is Category instance, load its Products list
          Category category = e.Parent as Category;
          category.Products.Clear();
    
          if (FLastCategory != null)
            FLastCategory.Products.Clear();
          FLastCategory = category;
    ...
    
  • lollol
    edited 3:25PM
    Thank you,

    Looks good.

    I'll test it as soon as it's available and I'll you know my findings.
  • lollol
    edited 3:25PM
    The event worked very well, I tried it to a depth of two descendants (master-detail-subdetail) and everything is fine.

    Thank you.

    Luis

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.