Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Creating a report in a module?
Thu, May 2 2019 9:14 PMPermanent Link

KimHJ

Comca Systems, Inc

I need to create reports for my web dashboard. Since it is easier to create a report visually can I add a VCL Form to the module and when it ask " Enable the Visual component library" select No?

Then when a report is needed i can create the unit with the form Visible set to False?

I will then save the report convert it to PDF using eDocEngine save it on the server and send the Url for the pdf file back in the request.

Or is there a better way?

Thanks,
Kim
Fri, May 3 2019 7:59 AMPermanent Link

Matthew Jones

I have a windows service that has a standard VCL form that has the report components etc on it. When it is needed, I create as normal, run the report, then close it after. Obviously you don't see anything but it just works.


--

Matthew Jones
Fri, May 3 2019 5:47 PMPermanent Link

KimHJ

Comca Systems, Inc

"Matthew Jones" wrote:

>>I have a windows service that has a standard VCL form that has the report components etc on it. When it is needed, I create as normal, run the report, then close it after. Obviously you don't see anything but it just works.
<<

Thanks Matthew did you say yes to this:  " Enable the Visual component library"?

Kim
Mon, May 6 2019 8:11 AMPermanent Link

Walter Matte

Tactical Business Corporation

Kim:

Do you use a reporting component in your desktop Delphi applications?

Report Builder, FastReport, Quick Report ?

I use ReportBuilder.  In my backend server I generate reports with ReportBuilder as PDF's or Excel and send them back to the Browser running EWB apps.

The work is all done in the server.  The EWB app will collect parameters and send them to the Web Server or Web ISAPI (which is a Delphi application).  
Tue, May 7 2019 6:16 AMPermanent Link

Matthew Jones

KimHJ wrote:

>  " Enable the Visual component library"?

I am not familiar with such a question, nor what is asking it, so cannot help on that part. But presumably the answer would be yes. Backups, version control, all good things. 8-)

--

Matthew Jones
Tue, Nov 19 2019 6:48 PMPermanent Link

KimHJ

Comca Systems, Inc

Walter Matte wrote:

>>Do you use a reporting component in your desktop Delphi applications?

>>Report Builder, FastReport, Quick Report ?

>>I use ReportBuilder.  In my backend server I generate reports with ReportBuilder as PDF's or Excel and send >>them back to the Browser running EWB apps.

>>The work is all done in the server.  The EWB app will collect parameters and send them to the Web Server or >>Web ISAPI (which is a Delphi application).  

Hi Walter,

I have been away for awhile and now I'm back to find out how to create the PDF file.

Yes I'm use a reporting component.

Did you make a VCL Form application and then execute it from the module with parameters or did you create the report as a DLL?

If that is how you do it, how will you know when the report (PDF File) have been created?

Thanks,
Kim
Wed, Nov 20 2019 5:13 AMPermanent Link

Walter Matte

Tactical Business Corporation

Kim:

I suspect other report components have similar capabilities - but I can only provide details for using DigitalMetaphors ReportBuilder.  I have the Enterprise edition.

I here is an example - I use a Table:

RptName char(40)
RptLayout blob (the ReportBuilder Report)
RptSQL1 memo
RptSQL2 memo
RptSQL3 memo
Link2  integer
Link2Master char(30)
Link2Detail char(30)
Link3  integer
Link4Master char(30)
Link5Detail char(30)

EWB asks for a report - it is read from the database, the related SQL needed for the report is loaded from database, parameters need are sent from EWB and the give to Query and the Query executed.  ReportBuilder allows for Master Detail via its PipeLine components to the Link2. Link2Master, Link2Detail describe when needed what the field is in the both queries and which query it links to.


The code is done inside a TDataModule that can be used in a DLL (like EWB DLL), or an ISAPI DLL and hosted in an IIS Server, or a Service designed to be its own Web Server or a Standalone EXE WebServer.

So not a TForm - but a TDatamodule is the underling container.

From my EWB app I have a TDialog with a TPlugin component.

From a Button Click to ask for the report....  (the frmView TDialog is created but not yet showing)  I set the URL


 frmView.pluginView.URL := gbURL +  '/report?RPTNAME=' + sRptName + sType + sParms;
 frmView.ShowModal;


My backend server parses the request - generates the report and sends it back


      if Uppercase(Request.Query['Type']) = 'PDF' then
      begin

// Set Up Response Headers based on EWB Request
// file type PDF, XLS, DOC
// and  Download or just send content

           Response.ContentType := 'application/pdf';
     
           Response.HeaderText :=
              Response.HeaderText +
                RtcString('Access-Control-Allow-Origin: *' + #13#10) +
                RtcString('Cache-Control: must-revalidate, post-check=0, pre-check=0' + #13#10) +
                RtcString('Cache-Control: public' + #13#10);
                
           if Uppercase(Request.Query['DOWNLOAD']) = '1' then
             Response.HeaderText :=
                  Response.HeaderText +
                  RtcString('Content-Description: File Transfer' + #13#10) +
                  RtcString('Content-Disposition: attachment; filename=Report.pdf' + #13#10);

// NOW Generate Content - in this case PDF
// <<<<<<  SEE BELOW the EWBPrintReport is in TDataModule   >>>>>>>

          // the Conn component is a Thread Database Pool managed TDataModule that
          // contains all the business and database handling, reporting, emailing , anything needed
          // to serve up to the EWB client.....

           Write(RtcString(Conn.EWBPrintReport(Request.Query)));    // Where report is generated
      end;


Report Component on datamodule rptMain


function TdmDBISAM.EWBPrintReport(Query: TRtcHttpValues): string;
var
 PDFDev : TppPDFDevice;
 DOCDev : TppDOCDevice;
 XLSDev : TppXLSReportDevice;
//  XLSDev : TppXLSDataDevice;
 
 ST: TStringStream;
 i : integer;
 sRptName : string;
 sType    : string;


 procedure CheckParameters(qX : TDBISAMQuery);
 var
   i : integer;
   sType : char;
   sName, sValue : string;
 begin
   for i := 0 to Query.ItemCount - 1 do
   begin
     sName := Uppercase(Query.ItemName[i]);
   
     if (sName <> 'DATASET') and (sName <> 'METHOD') and
        (sName <> 'RPTNAME') and (sName <> 'TYPE') then  
     begin
       sType := UpCase(sName[1]);

       sValue := TNetEncoding.URL.Decode(Query.ItemValue[i]);

       if qX.Params.FindParam(sName) <> nil then
       begin
         case sType of
         'I' : qX.ParamByName(sName).AsInteger := StrToInt(sValue);
         'F' : qX.ParamByName(sName).AsString := sValue;
         'S' : qX.ParamByName(sName).AsString := sValue;
         'D' : qX.ParamByName(sName).AsDateTime := StrToDate(sValue, fmtset);
         'B' : qX.ParamByName(sName).AsBoolean := (Uppercase(sValue) = 'TRUE');
         end;
       end;
     end
   end;
 end;               


begin
 //Log('EWBPrintReport ', 'DBSvr');

 sType := 'PDF';
 
 for i := 0 to Query.ItemCount - 1 do
 begin
   if Uppercase(Query.ItemName[i]) = 'RPTNAME' then
     sRptName := Query.ItemValue[i];
   if Uppercase(Query.ItemName[i]) = 'TYPE' then
     sType := Query.ItemValue[i];
 end;       
 
 
 tbRptDesign.Open;
 tbRptDesign.SetKey;
 tbRptDesign.FieldByName('RptName').AsString := sRptName;
 if not tbRptDesign.GotoKey then
 begin
   result := 'XX';
   exit;
 end;


 
 plData2.MasterDataPipeline := nil;
 plData2.MasterFieldLinks := '';
 plData3.MasterDataPipeline := nil;
 plData3.MasterFieldLinks := '';

 qData1.SQL.Clear;
 qData1.SQL.Text :=  tbRptDesign.FieldByName('RptSQL1').AsString;
 
 CheckParameters(qData1);

 qData1.Open;

 if (Length(tbRptDesign.FieldByName('RptSQL2').AsString) > 0) then
 begin
   qData2.SQL.Clear;
   qData2.SQL.Text :=  tbRptDesign.FieldByName('RptSQL2').AsString;

   CheckParameters(qData2);

   qData2.Open;
   if tbRptDesign.FieldByName('Link2').AsInteger = 1 then
     plData2.AddLink(plData1, tbRptDesign.FieldByName('Link2Master').AsString, tbRptDesign.FieldByName('Link2Detail').AsString);
   if tbRptDesign.FieldByName('Link2').AsInteger = 3 then
     plData2.AddLink(plData3,tbRptDesign.FieldByName('Link2Master').AsString, tbRptDesign.FieldByName('Link2Detail').AsString);
 end;

 if  length(tbRptDesign.FieldByName('RptSQL3').AsString) > 0 then
 begin
   qData3.SQL.Clear;
   qData3.SQL.Text :=  tbRptDesign.FieldByName('RptSQL3').AsString;

   CheckParameters(qData3);
   
   qData3.Open;
   if tbRptDesign.FieldByName('Link3').AsInteger = 1 then
     plData3.AddLink(plData1, tbRptDesign.FieldByName('Link3Master').AsString, tbRptDesign.FieldByName('Link3Detail').AsString);
   if tbRptDesign.FieldByName('Link3').AsInteger = 2 then
     plData3.AddLink(plData2,tbRptDesign.FieldByName('Link3Master').AsString, tbRptDesign.FieldByName('Link3Detail').AsString);
 end;                                                                 
 

 rptMain.Template.DatabaseSettings.Name := tbRptDesign.FieldByName('RptName').AsString;
 try
   rptMain.Template.LoadFromDatabase;
 except;
 end;

 rptMain.XLSSettings.ExportComponents := [ecText,ecLine,ecImage,ecRichText,ecBarCode,ecTable,ecOther];
 

 rptMain.Parameters.Clear;
 // Code ReportBuilder parameters here
 //rptMain.Parameters.Add('RptPeriod', dtString, false);
 
 // Output to StringSteam
 ST := TStringStream.Create('');
 

 // Prepare the desired output device
 if sType = 'PDF' then
 begin
   PDFDev := TppPDFDevice.Create(Self);
   PDFDev.OutputStream := ST;
   PDFDev.Publisher := rptMain.Publisher;
 end;

 if sType = 'DOC' then
 begin
   DOCDev := TppDOCDevice.Create(Self);
   DOCDev.OutputStream := ST;
   DOCDev.Publisher := rptMain.Publisher;
 end;
 
 if sType = 'XLS' then
 begin
   XLSDev := TppXLSReportDevice.Create(Self);
   XLSDev.XLSSettings.ExportComponents := [ecText,ecLine,ecImage,ecRichText,ecBarCode,ecTable,ecOther];
   XLSDev.OutputStream := ST;             
   XLSDev.Publisher := rptMain.Publisher;
 end;
 
 rptMain.EnableProcessMessages := False;
                                        

 // PRINT - execute report
 rptMain.PrintToDevices;


 // Here it is  send back the report
 result := ST.DataString;

 // close tables & free stuff
 qData1.Close;
 if qData2.Active then
   qData2.Close;
 plData2.MasterDataPipeline := nil;
 plData2.MasterFieldLinks := '';
 if qData3.Active then
   qData3.Close;
 plData3.MasterDataPipeline := nil;
 plData3.MasterFieldLinks := '';
 
 
 tbRptDesign.Close;
 
 if Assigned(PDFDev) then
   FreeAndNil(PDFDev);

 if Assigned(DOCDev) then
   FreeAndNil(DOCDev);
   
 if Assigned(XLSDev) then
   FreeAndNil(XLSDev);
   
 FreeAndNil(ST);
end;



Walter
Wed, Nov 20 2019 10:12 AMPermanent Link

KimHJ

Comca Systems, Inc

Walter Matte wrote:

>>I suspect other report components have similar capabilities - but I can only provide details for using ??>>DigitalMetaphors ReportBuilder.  I have the Enterprise edition.

>>I here is an example - I use a Table:

Thanks for all the code, very helpful.


Kim
Wed, Nov 20 2019 1:16 PMPermanent Link

KimHJ

Comca Systems, Inc

>>Walter Matte wrote:

>>From a Button Click to ask for the report....  (the frmView TDialog is created but not yet showing)  I set the URL

>>  frmView.pluginView.URL := gbURL +  '/report?RPTNAME=' + sRptName + sType + sParms;
>>  frmView.ShowModal;

Walter,

I get an error popup with the heading "Adobe PDF Document" and the text "Access denied."
I tried to run the EWB sample program as well and I get the same error. All the PDF files is in a shared folder with Everyone Full Access. This is on my development computer.

Any idea?

Thanks,
Kim
Wed, Nov 20 2019 2:51 PMPermanent Link

Walter Matte

Tactical Business Corporation

Are the PDF's are already open....  are you viewing them and trying to serve them up at the same time?  Were the PDF just created by the program - and - did the program release them.  Or are these PDF's just sitting there as files on disk?

Walter
Page 1 of 2Next Page »
Jump to Page:  1 2
Image