Inherited reports and persistensein database

dannidanni Denmark
edited 3:54PM in FastReport .NET
Hi,

I have been looking at the inherited part of the designer - creating / loading reports using the inherited function.

My setup:
I have implemented the 4 open and save events in the environmentSettings control, so data is saved and loaded through the SaveToString /LoadFromStringmethods and posted to a database.

1. I create a report with a Test: "header" in the pageheader and a text: "Footer" in the pagefooter. Not using the datasource at all.
2. Save the base report to the database.
3. I create a new report using the "new inherited report" function.

NOW... when I see the report I should see the items from the base report, correct? Or am I mistaken? I have a feeling that the base reprot is not loaded at all when creating an inherited report.

How can I fix this you recon?


Thank you

Comments

  • edited 3:54PM
    Hello,

    You need to implement the report.LoadBaseReport event.
    FReport.LoadBaseReport += new CustomLoadEventHandler(FReport_LoadBaseReport);
    
    private void FReport_LoadBaseReport(object sender, CustomLoadEventArgs e)
    {
      // e.FileName contains the name of base report. It may be the file name, or an ID in the database,
      // it depends on how you load the main report
      e.Report.Load(@"d:\fr.net\demos\reports\" + e.FileName);
    }
    
  • dannidanni Denmark
    edited 3:54PM
    Hello

    I have implemented the environmentSettings_CustomOpenDialog and environmentSettings_CustomOpenReport evnet.

    This is where I add the event, but the event is never called when I press newInheritedReport.
    private void FrmReportdesigner_Load(object sender, EventArgs e)
    {
           SplashController.StartSplashLoadingData("Henter data til rapportdesigner...");            
    
           ResigerData(_currentReport);
           designerControl.Report = _currentReport;
           _currentReport.LoadBaseReport += new CustomLoadEventHandler(CurrentReport_LoadBaseReport);
           designerControl.RefreshLayout();
                
           SplashController.StopSplash();
    }
    


    AlexTZ wrote: »
    Hello,

    You need to implement the report.LoadBaseReport event.
    FReport.LoadBaseReport += new CustomLoadEventHandler(FReport_LoadBaseReport);
    
    private void FReport_LoadBaseReport(object sender, CustomLoadEventArgs e)
    {
      // e.FileName contains the name of base report. It may be the file name, or an ID in the database,
      // it depends on how you load the main report
      e.Report.Load(@"d:\fr.net\demos\reports\" + e.FileName);
    }
    
  • edited 3:54PM
    Try to use the LoadBaseReport event in your CustomLoadReport event handler:

    // wire up event
    e.Report.LoadBaseReport += new CustomLoadEventHandler(CurrentReport_LoadBaseReport);

    // load the main report
    e.Report.Load(...);

    // unwire event
    e.Report.LoadBaseReport -= new CustomLoadEventHandler(CurrentReport_LoadBaseReport);
  • dannidanni Denmark
    edited July 2009
    It is not when im loading an existing inherited report. But I can see a challenge there aswell.

    It is when i want to create a new inherited report.

    when i create a new inherited report the only event thats beeing called is the event environmentSettings_CustomOpenDialog.


    the eventhandler environmentSettings_CustomOpenDialog, should know if its a basereport or just a normal report thats beeing opened. SO i can call loadReport or loadBaseReport. But I cannot see how its can done.
  • edited 3:54PM
    wrote:
    This is where I add the event, but the event is never called when I press newInheritedReport.

    I've tried to do the same, and the event is called. Could you make a simple demo for me?
  • dannidanni Denmark
    edited 3:54PM
    I can attatch the CustomreportDesigner.cs file if that can help you?


  • edited 3:54PM
    I need a simple demo that I can compile and debug.
    For example, if I modify the Demo.exe source in the following way:
        private void DesignReport()
        {
          FReport.LoadBaseReport += new CustomLoadEventHandler(FReport_LoadBaseReport);
          FReport.Design();
        }
    
        void FReport_LoadBaseReport(object sender, CustomLoadEventArgs e)
        {
          throw new Exception("The method or operation is not implemented.");
        }
    

    I see that the event handler is called when I do "New inherited report".
  • dannidanni Denmark
    edited 3:54PM
    Hi again.

    I have made a fast example where I have done the following:

    1. added the designer control to a form.
    2. added environments to the designer and oimplemented the open/save methods with a simple messagebox only.
    3. added a loadbaseReport event to the designer.report in the Form.Load evnethandler


    The message "loadignbaseReport..." is never shown.

  • edited July 2009
    The reason is simple: your opendialog event handler is empty. You don't provide a report name in this event. Since the name is not provided (empty), the LoadBaseReport event is never gets called - because there is nothing to load.

    Modify the code in the following way, and the LoadBaseReport event will fired:
            private void environmentSettings1_CustomOpenDialog(object sender, FastReport.Design.OpenSaveDialogEventArgs e)
            {
                MessageBox.Show("OpenDialog...");
                e.FileName = @"d:\1.frx";
            }
    
  • dannidanni Denmark
    edited 3:54PM
    Ahh, simple soultion :-)

    I use the e.Data Property in the openDialog handler to provide the reportID from the database into the custon openReport. But I will try using the filename insted ans see what happens.

    Thank you :-)
  • dannidanni Denmark
    edited 3:54PM
    Okay... this means the designer does not support loading basereports other than from a file.

    1. If i specify a "dummy" filename. The designer throws a FileNotFoundException.
    2. if I specify the report ID from the database as filename I get an invalid fileformat
  • edited 3:54PM
    No, it does [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> - In the CustomOpenDialog event you return a "filename" in the e.FileName parameter. It may be either a file name, or something else (for example, database row ID). - In the CustomOpenReport or LoadBaseReport events, you handle loading a report from a location specified in the e.FileName parameter. It depends on what your CustomOpenDialog returns. If you work with database, treat e.FileName as a row ID.[/img]
  • dannidanni Denmark
    edited July 2009
    if I add a rowID as filename i get the error in the attached file.

    I add the following: e.Filename = 14 + "";

    Then I get the error below.

    Is there a property I need to set to ignore true filenames in the "e.Filename"?
  • edited 3:54PM
    14 + "" would generate a compiler error [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Here is what I do and it works well for me:[/img]
        void DesignerSettings_CustomOpenDialog(object sender, OpenSaveDialogEventArgs e)
        {
          e.FileName = @"myfile:d:\1.frx";
        }
    
        void DesignerSettings_CustomOpenReport(object sender, OpenSaveReportEventArgs e)
        {
          if (e.FileName.StartsWith("myfile:"))
          {
            string fileName = e.FileName.Remove(0, "myfile:".Length);
            e.Report.Load(fileName);
          }
        }
    

    Looks like I need another test project from you >
  • dannidanni Denmark
    edited 3:54PM
    Yes, when using a real filename it works fine.

    BUT when i use id's to a database and save/load reports to a string it fails.

    Try use an id insted of a filename.
  • edited 3:54PM
    As you can see what I use is not a file name - it's a kind of ID. Yes, finally it becomes a file name, but this is just to demonstrate that the technique is working well.
  • dannidanni Denmark
    edited July 2009
    I worked out some magic.

    I had this beautifull line except it looked like this (uncommented) he he
    //designerControl.Report.LoadBaseReport += new CustomLoadEventHandler(Report_LoadBaseReport);

    Now I can create a new inherited report.


    Next: [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> I cannot save the report. How do I do that? my report.BaseReport is "14" - the id of the baseReport, which is great. thank you for your patience with me[/img]>
  • edited 3:54PM
    I will prepare a new demo under Demos\C# folder. I think it will be useful to others who want to store their reports in a database.
  • dannidanni Denmark
    edited July 2009
    I think so too.

    please include the load/save with inheritance aswell. Thats the only problem I have left in the designer apart from a few restrictions in the designer :-)

    I have no problem saving the report but when i open it again i have no small locks on the fields from the inherited report. As if I loose the conenction with the basereport when I save it to the database.
  • edited 3:54PM
    I've added CustomOpenSaveDialogs demo (under Demos\C# folder). And fixed some errors in the fastreport.dll [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> The fixed version will be available in 6 hours.[/img]
  • dannidanni Denmark
    edited 3:54PM
    Hi Alex

    Back from summer holidays.

    Can I pass an ID from a report in my database as e.Filename in report_LoadBaseReport now?

    I'm not too sure how to load the base and inherited report when storing reports in a database.

    Thanks
  • edited August 2009
    Hello,

    Please look at the C#\Demos\CustomOpenSaveDialogs demo. It does exactly what you need (in fact, this demo was written for you >.
  • dannidanni Denmark
    edited 3:54PM
    Hi Alex

    I have used your example against the xml file. Iit works very well against databases now.

    Thanks! :-)

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.