Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 18 total
Thread Reportbuilder reports/pdf module
Wed, Apr 26 2017 6:42 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi All,

I need to create/show different kind of reports from my application and
i know i can use ewb modules to do this. But i am not sure about following:

- Do I need a seperate module for every report or can a single module
contain multiple reports?

- Can I send parameters from client to server so server opens data
requested (different parameters), how is this handled?

I am using ewb 2.04 latest and reportbuilder for delphi.

If anyone can share some code, i would be more than happy. Thanks in
advance.

Regards,

Hüseyin
Wed, Apr 26 2017 8:00 AMPermanent Link

Uli Becker

Hüseyin,

> - Do I need a seperate module for every report or can a single module
> contain multiple reports?

A module can contain any number of datasets and/or reports.

> - Can I send parameters from client to server so server opens data
> requested (different parameters), how is this handled?

Sure, otherwise that wouldn't make sense. Smile

Sample code EWB:

Drop a TServerRequest (let's call it ActionRequest) component on your form:

 with ActionRequest do
   begin
      Method := rmPost;
      URL := 'modules/MyModuleName';
      Params.Clear;
      Params.Add('Action=CreateReport');
      Params.Add('Name=PrintAllInvoices');
      Execute;
   end;

This will send a request with 2 parameters to your module "MyModule".

Sample code Module:

procedure TMyModule.EWBModuleExecute(Request: TEWBServerRequest);
var
   TempAction, TempName: string;
begin
    // This is the right place to parse what the client has sent:
    TempAction := RequestParams.Values['Action'];
    TempName := RequestParams.Values['Name'];
   
   if SameText(TempAction, 'CreateReport') then
    begin
      if SameText(TempName, 'PrintAllInvoices') then
      begin
        try
          // Execute here your code to print all invoices:
          DoPrint;
     //If successful send this StatusCode back to the client:
          //HTTP_OK (200) - SendContent('') does that for you
          SendContent('');
        except
          // you'll find all StatusCode constants in webhttp.wbs
          on e: Exception do
            SendError(HTTP_INTERNAL_ERROR, e.Message);
        end;
      end;
    end
    ...
end;

Sample Code EWB:

In the ActionRequest "OnComplete" event you'll receive the server's
response like this:

procedure MyForm.ActionRequestComplete(Request: TServerRequest);
begin
   if Request.StatusCode <> HTTP_OK then
      ShowMessage('Error: Invoices could not be
printed.','MyApp',asQuadEaseOut,200)
   else
   begin
     // Success!
   end;
end;

Hope that helps.

Uli
















Wed, Apr 26 2017 8:02 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Uli thanks Smile


Den 26-04-2017 kl. 14:00 skrev Uli Becker:
> Hüseyin,
>
>> - Do I need a seperate module for every report or can a single module
>> contain multiple reports?
>
> A module can contain any number of datasets and/or reports.
>
>> - Can I send parameters from client to server so server opens data
>> requested (different parameters), how is this handled?
>
> Sure, otherwise that wouldn't make sense. Smile
>
> Sample code EWB:
>
> Drop a TServerRequest (let's call it ActionRequest) component on your
> form:
>
>  with ActionRequest do
>    begin
>       Method := rmPost;
>       URL := 'modules/MyModuleName';
>       Params.Clear;
>       Params.Add('Action=CreateReport');
>       Params.Add('Name=PrintAllInvoices');
>       Execute;
>    end;
>
> This will send a request with 2 parameters to your module "MyModule".
>
> Sample code Module:
>
> procedure TMyModule.EWBModuleExecute(Request: TEWBServerRequest);
> var
>    TempAction, TempName: string;
> begin
>     // This is the right place to parse what the client has sent:
>     TempAction := RequestParams.Values['Action'];
>     TempName := RequestParams.Values['Name'];
>
>    if SameText(TempAction, 'CreateReport') then
>     begin
>       if SameText(TempName, 'PrintAllInvoices') then
>       begin
>         try
>           // Execute here your code to print all invoices:
>           DoPrint;
>       //If successful send this StatusCode back to the client:
>           //HTTP_OK (200) - SendContent('') does that for you
>           SendContent('');
>         except
>           // you'll find all StatusCode constants in webhttp.wbs
>           on e: Exception do
>             SendError(HTTP_INTERNAL_ERROR, e.Message);
>         end;
>       end;
>     end
>     ...
> end;
>
> Sample Code EWB:
>
> In the ActionRequest "OnComplete" event you'll receive the server's
> response like this:
>
> procedure MyForm.ActionRequestComplete(Request: TServerRequest);
> begin
>    if Request.StatusCode <> HTTP_OK then
>       ShowMessage('Error: Invoices could not be
> printed.','MyApp',asQuadEaseOut,200)
>    else
>    begin
>      // Success!
>    end;
> end;
>
> Hope that helps.
>
> Uli
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
Mon, May 8 2017 9:01 AMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi Uli/All,

Can you please see following code to see whats wrong - i get internal
error from module (sorry if code are too long):

// Module part..

procedure TEWBModule1.EWBModuleExecute(Request: TEWBServerRequest);
var
TempAction, TempName, Tempfirma: string; TempFirmanr: Integer;
TempFradato,TempTildato: double;
begin
    TempAction := Request.RequestParams.Values['Type'];
    TempName := Request.RequestParams.Values['Periode'];
    TempFirma := Request.RequestParams.Values['Nr'];
    TempFirmanr := strtoint(Request.RequestParams.Values['Nr']);
    TempFraDato := strtodate(Request.RequestParams.Values['Fra']);
    TempTilDato := strtodate(Request.RequestParams.Values['Til']);
//
   if SameText(TempAction, 'VisReport') then
    begin
      if SameText(TempName, 'Dag') then
      begin
        if SameText(TempFirma, 'Nr') then
        begin
        try
        with myAppReportIdagQuery do begin
        if active then close;
        unprepare;
        prepare;
        params[0].AsInteger := Tempfirmanr;
        open;
        end;
        if (myAppReportIdagQuery.RowsAffected > 0) then begin
        myAppReportQuerySource.DataSet := myAppReportIdagQuery;
        Reportprint(Request);
        end;
        Request.SendCustomContentStream(ST,'application/pdf','');
        except
          on e: Exception do
            Request.SendError(HTTP_INTERNAL_ERROR, e.Message);
        end;
      end;
     end;
    end;
//
   if SameText(TempAction, 'VisReport') then
    begin
      if SameText(TempName, 'Uge') then
      begin
        if SameText(TempFirma, 'Nr') then
        begin
        try
        with myAppReportUgeQuery do begin
        if active then close;
        unprepare;
        prepare;
        params[0].AsInteger := Tempfirmanr;
        open;
        end;
        if (myAppReportUgeQuery.RowsAffected > 0) then begin
        myAppReportQuerySource.DataSet := myAppReportUgeQuery;
        Reportprint(Request);
        end;
        Request.SendCustomContentStream(ST,'application/pdf','');
        except
          on e: Exception do
            Request.SendError(HTTP_INTERNAL_ERROR, e.Message);
        end;
      end;
     end;
    end;
//
   if SameText(TempAction, 'VisReport') then
    begin
      if SameText(TempName, 'Interval') then
      begin
        if SameText(TempFirma, 'Nr') then
        begin
        try
        with myAppReportIntervalQuery do begin
        if active then close;
        unprepare;
        prepare;
        params[0].AsInteger := Tempfirmanr;
        params[1].AsDate := TempFraDato;
        params[2].AsDate := TempTilDato;
        open;
        end;
        if (myAppReportIntervalQuery.RowsAffected > 0) then begin
        myAppReportQuerySource.DataSet := myAppReportIntervalQuery;
        Reportprint(Request);
        end;
        Request.SendCustomContentStream(ST,'application/pdf','');
        except
          on e: Exception do
            Request.SendError(HTTP_INTERNAL_ERROR, e.Message);
        end;
      end;
    end;
  end;
end;


procedure TEWBModule1.Reportprint(ARequest: TEWBServerRequest);
begin
// ******* Here is the Report Builder part
 ST := TStringStream.Create('');
 HD := TppPDFDevice.Create(Self);
 HD.OutputStream := ST;
 HD.Publisher := myAppReport.Publisher;
 myAppReport.PrintToDevices;
 ARequest.SendCustomContentStream(ST,'application/pdf','');
 FreeAndNil(st);
 FreeAndNil(hd);
end;

// EWB part..

procedure TForm1.UdskriftButtonClick(Sender: TObject);
begin
Aktuelfirmanr := myAppFirmaDagtimer.columns['Firmanr'].asinteger;
with Report do
   begin
      Method := rmPost;
      URL := 'modules/Report';
      Params.Clear;
      Params.Add('Type=VisReport');
      Params.Add('Periode=Dag');
      Params.Add('Nr=aktuelfirmanr');
      Execute;
   end;
// VisPDF.URL := 'data:application/pdf;base64'+ Report.ResponseContent;
end;

procedure TForm1.ReportComplete(Request: TServerRequest);
begin
  if Request.StatusCode <> HTTP_OK then
  showmessage(inttostr(Request.StatusCode))
//  window.alert('Fejl: Reporten kunne ikke genereres..')
//  ShowMessage('Fejl: Reporten kunne ikke
genereres..','myApp',asQuadEaseOut,200)
  else
  begin
     // Success!
  end;
end;

Den 26/04/2017 kl. 14.02 skrev Hüseyin Aliz:
> Uli thanks Smile
>
>
> Den 26-04-2017 kl. 14:00 skrev Uli Becker:
>> Hüseyin,
>>
>>> - Do I need a seperate module for every report or can a single module
>>> contain multiple reports?
>>
>> A module can contain any number of datasets and/or reports.
>>
>>> - Can I send parameters from client to server so server opens data
>>> requested (different parameters), how is this handled?
>>
>> Sure, otherwise that wouldn't make sense. Smile
>>
>> Sample code EWB:
>>
>> Drop a TServerRequest (let's call it ActionRequest) component on your
>> form:
>>
>>  with ActionRequest do
>>    begin
>>       Method := rmPost;
>>       URL := 'modules/MyModuleName';
>>       Params.Clear;
>>       Params.Add('Action=CreateReport');
>>       Params.Add('Name=PrintAllInvoices');
>>       Execute;
>>    end;
>>
>> This will send a request with 2 parameters to your module "MyModule".
>>
>> Sample code Module:
>>
>> procedure TMyModule.EWBModuleExecute(Request: TEWBServerRequest);
>> var
>>    TempAction, TempName: string;
>> begin
>>     // This is the right place to parse what the client has sent:
>>     TempAction := RequestParams.Values['Action'];
>>     TempName := RequestParams.Values['Name'];
>>
>>    if SameText(TempAction, 'CreateReport') then
>>     begin
>>       if SameText(TempName, 'PrintAllInvoices') then
>>       begin
>>         try
>>           // Execute here your code to print all invoices:
>>           DoPrint;
>>       //If successful send this StatusCode back to the client:
>>           //HTTP_OK (200) - SendContent('') does that for you
>>           SendContent('');
>>         except
>>           // you'll find all StatusCode constants in webhttp.wbs
>>           on e: Exception do
>>             SendError(HTTP_INTERNAL_ERROR, e.Message);
>>         end;
>>       end;
>>     end
>>     ...
>> end;
>>
>> Sample Code EWB:
>>
>> In the ActionRequest "OnComplete" event you'll receive the server's
>> response like this:
>>
>> procedure MyForm.ActionRequestComplete(Request: TServerRequest);
>> begin
>>    if Request.StatusCode <> HTTP_OK then
>>       ShowMessage('Error: Invoices could not be
>> printed.','MyApp',asQuadEaseOut,200)
>>    else
>>    begin
>>      // Success!
>>    end;
>> end;
>>
>> Hope that helps.
>>
>> Uli
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
Mon, May 8 2017 11:02 AMPermanent Link

Walter Matte

Tactical Business Corporation

Why are you calling this code - it is already in your ReportPrint procedure.

Is ST a global variable here - I would have expected a compile error unless it is global- and there fore probably uninitialized - since there is a Local ST variable in PrintReport.

        Request.SendCustomContentStream(ST,'application/pdf','');      ********* <<<<<<<<<<<<<<<<<
 
Walter

//-----------------------------------

 if SameText(TempAction, 'VisReport') then
    begin
      if SameText(TempName, 'Dag') then
      begin
        if SameText(TempFirma, 'Nr') then
        begin
        try
        with myAppReportIdagQuery do begin
        if active then close;
        unprepare;
        prepare;
        params[0].AsInteger := Tempfirmanr;
        open;
        end;
        if (myAppReportIdagQuery.RowsAffected > 0) then begin
        myAppReportQuerySource.DataSet := myAppReportIdagQuery;
        Reportprint(Request);
        end;
        Request.SendCustomContentStream(ST,'application/pdf','');      ********* <<<<<<<<<<<<<<<<<
        except
          on e: Exception do
            Request.SendError(HTTP_INTERNAL_ERROR, e.Message);
        end;
      end;
     end;
    end;
//
Mon, May 8 2017 11:03 AMPermanent Link

Uli Becker

> Can you please see following code to see whats wrong - i get internal
> error from module (sorry if code are too long):

You can debug a module quite easy:

with the module project open in the Delphi IDE, select Run/Parameters
and specify the EWB Web Server (ewbsrvr.exe) as the Host Application. Be
sure to use the complete path to the executable.

Then you can set any breakpoints or display messageboxes in your code.

Uli
Mon, May 8 2017 12:47 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Walter,

Good question Smile

ST was a global variable but now moved to the local print procedure, and
i also did remove the line you have pointed out, still no go. I must
play a little more with it Smile

Regards,

Hüseyin


Den 08-05-2017 kl. 17:02 skrev Walter Matte:
> Why are you calling this code - it is already in your ReportPrint procedure.
>
> Is ST a global variable here - I would have expected a compile error unless it is global- and there fore probably uninitialized - since there is a Local ST variable in PrintReport.
>
>           Request.SendCustomContentStream(ST,'application/pdf','');      ********* <<<<<<<<<<<<<<<<<
>    
> Walter
>
> //-----------------------------------
>
>    if SameText(TempAction, 'VisReport') then
>       begin
>         if SameText(TempName, 'Dag') then
>         begin
>           if SameText(TempFirma, 'Nr') then
>           begin
>           try
>           with myAppReportIdagQuery do begin
>           if active then close;
>           unprepare;
>           prepare;
>           params[0].AsInteger := Tempfirmanr;
>           open;
>           end;
>           if (myAppReportIdagQuery.RowsAffected > 0) then begin
>           myAppReportQuerySource.DataSet := myAppReportIdagQuery;
>           Reportprint(Request);
>           end;
>           Request.SendCustomContentStream(ST,'application/pdf','');      ********* <<<<<<<<<<<<<<<<<
>           except
>             on e: Exception do
>               Request.SendError(HTTP_INTERNAL_ERROR, e.Message);
>           end;
>         end;
>        end;
>       end;
> //
>
Tue, May 9 2017 1:52 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Uli,

<< You can debug a module quite easy:

with the module project open in the Delphi IDE, select Run/Parameters
and specify the EWB Web Server (ewbsrvr.exe) as the Host Application. Be
sure to use the complete path to the executable. >>

In addition to this great tip, it must also be noted that you don't even need to use the external web server.  You can put the IDE (ewbide.exe) as the host application and debug modules directly while they're loaded in the IDE with the internal web server.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, May 22 2017 6:27 PMPermanent Link

Huseyin Aliz

myBiss ApS

Avatar

Hi All,

Quick status:

I got it (partly) working after trying several things:

- It seems that tplugin rendering/pdf from ide internal web server does
not work or at least i could not get it to display the pdf, it works
(displays) when opening from the external browser while internal web
server runs in the background.

- As i am using reportbuilder i need to use querys/datasources within
the ewb module, but here i have a strange issue, when i put a tdatabase
and set it's state to connected - running from internal webserver it
gives an error when calling tserverrequest:

"databasename 'xxx' already exists"

If i click ok it shows pdf and does not show any error with tplugin/pdf
until next time i start a new session. When deploying the module to the
webserver it runs fine until some time and rendering pdf starts to show
"waiting for..", the fix is to restart the whole server.

Removing tdatabase from module makes it not working saying tables are
missing. The ewb web server should natively handle dbisam as my database
are built on dbisam. I guess i am doing something wrong.

Sorry for the long text.

Btw. Fiddler is a great tool to see what's happening between client and
server. Walter thanks for that!


Regards and thanks,
Hüseyin
Tue, May 23 2017 4:03 AMPermanent Link

Uli Becker

> "databasename 'xxx' already exists"

Modules have to be thread-safe. That's why the property
"AutoSessionName" of the session has to be "true". Maybe you missed that.

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