Save to DB from Report Designer

HasithaHasitha Sri Lanka
edited 10:39AM in FastReport 4.0
Hi,

I'm new to FastReport and we are going to use FastReport with our new project. I have couple of questions regarding the Report Designer.

1. Is there any possibility to open Report Designer on a web application.
2. How do I save my report changes to DB from Report Designer. For an example, I'm loading report from the database using "report.LoadFromString(reportString);" Is there any way to save updated report string (through report designer) back to DB through my web application.

Appreciate your swift response.

Thanks,

Hasitha.

Comments

  • gpigpi
    edited 10:39AM
    You can't to open designer on a web application
  • mierlpmierlp Netherlands
    edited 10:39AM
    Hi

    I store all my report in a database so all when i want to modify it, i also need to load it from database.
    The following code i use:

    Create new report...but first check if there's already a report available:
    Procedure TFormReport.CreateNew;
    var
        New : boolean;
    begin
      if not dmRemain.RemainReport.FieldByName('Report').IsNull then begin
         If Application.MessageBox('ATTENTION'+#10+'There's already a report available. '+#10+'Would you like to replace this report (Y/N) ?', 'Warning', MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2+MB_APPLMODAL) = ID_YES Then begin
            FormMain.frxReport.Clear;
            New := True;
            FormMain.frxReport.DesignReport;
         end;
      end;
      if dmRemain.RemainReport.FieldByName('Report').IsNull then begin
         FormMain.frxReport.Clear;
         New := True;
         FormMain.frxReport.DesignReport;
      end;
    end;
    

    Load/Modify report into reportdesigner:
    wrote:
    Procedure TFormReport.ModifyReport;
    var
    New : boolean;
    begin
    FormMain.frxReport.Clear;
    New := False;
    try
    Mstream := TMemoryStream.Create;
    Bstream := dmRemain.RemainReport.CreateBlobStream(dmRemain.RemainReport.FieldByName('report'), bmRead);
    Mstream.CopyFrom(Bstream,Bstream.Size);
    Mstream.Position := 0;
    if Mstream.Size > 0 then
    formMain.frxReport.LoadFromStream(Mstream)
    else
    New := True;
    finally
    Mstream.Free;
    end;
    FormMain.frxReport.DesignReport
    end;

    Now the saving part...i gave the user the option to store the report into the database or
    to save it to disk...reason is that he can use a local copy to create a new report.
    In the frxDesigner.OnSaveReport i use the following code:
    function TFormMain.frxDesignerSaveReport(Report: TfrxReport;
      SaveAs: Boolean): Boolean;
    begin
      //----------------------------------------------------------------------------
      // Rapport
      //----------------------------------------------------------------------------
      If Application.MessageBox('You can save the report to disk or into the database'+#10+'If you would like to save it to disk choose '''N'''+#10+
    otherwise choose '''Y''' +#10+'Save report into database Y/N) ?', 'Save report', MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON1+MB_APPLMODAL) = ID_YES Then
         Result:=True
      else
         Result:=false;
    
      if Result=true then begin
         // datamodule dmRemain en database RemainReport....put here you're own datamodule/database
         if dmRemain.RemainReport.State in [dsBrowse] then begin
            dmRemain.RemainReport.Edit;
         end;
         try
           Mstream := TMemoryStream.Create;
           Bstream := dmRemain.RemainReport.CreateBlobStream(dmRemain.RemainReport.FieldByName('Report'), bmReadWrite);
           frxReport.SaveToStream(Mstream);
           Mstream.Position := 0;
           Bstream.CopyFrom(Mstream, Mstream.Size);
           //if dmRemain.RemainReport.State in [dsInsert,dsEdit] then begin
           //   dmRemain.RemainReport.Post;
          // end;
         finally
           Mstream.Free;
           Bstream.Free;
         end;
         Result := True;
     end;
     if Result=false then begin
        FormMain.frxDesigner.SaveDir:=cMapRapport;
        FormMain.SaveDialog.InitialDir:=cMapRapport;
        if FormMain.SaveDialog.Execute then begin
           FormMain.frxReport.Report.SaveToFile(FormMain.SaveDialog.FileName);
        end;
     end;
     Result :=true;
    end;
    

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.