Loading detail dataset just in time by master id.

Hello,
We a have master-detail report (with master and detail dataset). Is there any event in FastReport suitable to load detail dataset just in time by id of master dataset in master databand. Is possible to use this approach here?
Thanx

Comments

  • edited 7:13PM
    Hello,

    Both master and detail datasources must be filled before you run a report. There is no event to fill the detail datasource when the master current row changes.
  • edited 7:13PM
    Jon Izman wrote: »
    Hello,
    We a have master-detail report (with master and detail dataset). Is there any event in FastReport suitable to load detail dataset just in time by id of master dataset in master databand. Is possible to use this approach here?
    Thanx

    Hi Jon,

    This code works for me:
    // Set data bands                    
    singleTAReport.RegisterData((DataTable)attendance.Days, "Days");
    singleTAReport.RegisterData((DataTable)attendance.Entries, "Entries");
    
    // Data band must be bound to correct data source!!
    ((DataBand)singleTAReport.FindObject("TADays")).DataSource = singleTAReport.GetDataSource("Days");
    DataBand entries = singleTAReport.FindObject("TAEntries") as DataBand;
    if (entries != null)
    {                                    
    entries.DataSource = singleTAReport.GetDataSource("Entries");
    
    // Create relation between master/detail...
    entries.Relation = new FastReport.Data.Relation();
    
    string[] cols = { "Day" };
    entries.Relation.Name = "Days_Entries";
    entries.Relation.ParentDataSource = singleTAReport.GetDataSource("Days");
    entries.Relation.ChildDataSource = singleTAReport.GetDataSource("Entries");
    entries.Relation.ParentColumns = cols;
    entries.Relation.ChildColumns = cols;
    
    entries.ParentIdColumn = "Day";
    
    singleTAReport.Prepare();
    ...
    
    


    Kind Regards,

    Keith Blows
  • edited 7:13PM
    Thanx, I thought "how to reload detail dataset from database by actual master ID just in time". There is a beforeprint event in MasterData, There I can get master ID and load new detail datatable by this ID. Is there any correct way how to replace old detail datatable in report by a new one?
  • edited 7:13PM
    Hello,

    If your datasource is sql-based, you may set up query parameters. For example:
    Master query ("Customers"):
    select CustName, CustID from Customers
    

    Detail query ("Orders"):
    select CustID, OrderDate, OrderTotal from Orders
    where CustID = @custid
    

    the "custid" parameter is defined in the following way:
    Name = custid
    DataType = Integer
    Expression = [Customers.CustID]
    
  • edited 7:13PM
    Hello
    For example We have a dataset CustOrd with datatables Customers and Orders.

    Datatable Custommers is assigned to DataBand MasterDataCustomer
    Datatable Order is assigned to DataBand MasterDataOrder. Orders is detail of Custommes. Order is connected to Customers by foreign key Custommer_ID

    We would like load Orders for every custommer just in time from Db by SQL statement with Custommer_ID foreign key parameter.

    We can get ID_Custommer in MasterDataCustomer_beforePrint method.
    We can load datatable Order from sql DB by Custommer_ID foreign key for every Custommers row in MasterDataCustomer_beforePrint .

    We dont know how to register data from Order table.

    We try call Ordes select with Custommer_ID = 0 on start to create empty datatable. In MasterDataCustomer_beforePrint are created datatables by selects Orders with Custommer id.
    When I register data on start, I can see only datasource corresponding to empty datatable in Design.
    When I register data in Custommers_beforePrint method, there is posible to see a lots new Orders datasources for every Customer iteration. Every datatasource has any generated name.

    We would need one datasource where we could replace data by reassign a new datatable in MasterDataCustomer_beforePrint method.
    Is it possible? Is there any way how assign to Order datasource a new Order Datatable for every Custommer iteration in MasterDataCustomer_beforePrint method?
    Thanx
  • edited 7:13PM
    Hello,

    Ok, I will add the event for your case. I will inform you when it will be available (probably tomorrow, in the next daily build).
  • edited 7:13PM
    You will be able to use this code in the next daily build (1.2.46):
          DataTable master = new DataTable();
          master.Columns.Add("CategoryID");
          master.Columns.Add("CategoryName");
          master.Rows.Add("1", "Beverages");
          master.Rows.Add("2", "Confections");
    
          DataTable detail = new DataTable();
          detail.Columns.Add("ProductID");
          detail.Columns.Add("CategoryID");
          detail.Columns.Add("ProductName");
    
          Report report = new Report();
          report.Load(...);
          report.RegisterData(master, "master");
          report.RegisterData(detail, "detail");
          DataSourceBase detailDs = report.GetDataSource("detail");
          detailDs.Load += new EventHandler(detailDs_Load);
          report.Show();
    
        void detailDs_Load(object sender, EventArgs e)
        {
          Report report = (sender as DataSourceBase).Report;
          DataTable detail = (sender as TableDataSource).Table;
          DataSourceBase masterDs = report.GetDataSource("master");
    
          detail.Rows.Clear();
          string masterId = (masterDs.CurrentRow as DataRow)["CategoryID"].ToString();
          if (masterId == "1")
          {
            detail.Rows.Add("1", "1", "Chai");
            detail.Rows.Add("2", "1", "Chang");
            detail.Rows.Add("3", "1", "Ipoh coffee");
          }
          else if (masterId == "2")
          {
            detail.Rows.Add("4", "2", "Chocolade");
            detail.Rows.Add("5", "2", "Tarte au sucre");
          }
        }
    
  • edited 7:13PM
    Good work! We make reports for a really big amount of data. Very helpful solution!
  • edited 7:13PM
    Hello,
    When a preview is runned from a design window, then detail's Load events are called, but only first time when preview is runned. Is there any option or event to call load events anytime when preview is runned from one design window?
  • edited 7:13PM
    Hello,

    You may subscribe to the Report.StartReport event and move the following code into the event handler:

    report_StartReport:
    {
    DataSourceBase detailDs = report.GetDataSource("detail");
    detailDs.Load += new EventHandler(detailDs_Load);
    }

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.