Implementation of Pb dynamic report format Customization

Source: Internet
Author: User
In the common server/client MIS development, there are always endless reports to be produced, and the time spent on debugging reports is also the most tedious and often cannot meet the requirements of customers. It would be nice if you could adjust the report format and content and save it. When the program starts next time, it automatically calls the saved report format. I finally met the requirements by using the following methods.
Pb (PowerBuilder) has a special file format (this document is short for this document as a report file) ending with a specific report ). Based on the principle that the data window can directly read the report generated by the report file, the program generates the report file to save the dynamic report format.

I. Implementation principle:

The report in Pb is actually equivalent to the data window.

Step 1: implement dynamic reports. By setting the resizeable and moveable attributes of text and columns in the data window object (dataobject) to 1, the Drag Control of object position is realized, use the modify function of the data window to change the object value (including adding and deleting ).

Step 2: Save the report format. In an application, the name of a data window object is always unique, and each data window object is converted into a data window object and stored in a database table. When the window is opened, the program first checks whether the report format exists. If the report format exists, read the report format and place it in a temporary file. Then, set the Data Object of the data window (datawindow) As the report file and extract the data. If the report format does not exist, extract data directly.

II. Implementation Process:

1. Create a database table to save report format files.

Table Name: dyn_report
Dwobject Varchar2 (20) Data window Object Name Primary Key
Rptitle Varchar2 (80) Report title name  
Memo Long raw Report Format

2. Create a window w_temp. The instance variables are defined as follows:

String is_dwtype, is_dwobject // type and name of the object stored in the report

Control name Control description
Dw_print Data window object
Cb_exit Exit button
Cb_savereport Save Report Format button

  
3. Add the following code to the open event in the window to check whether the report format exists. If a custom report format is read to the data window.

Blob emp_pic
Long ll_handle
String ls_dwobject, ls_reportfile, ls_path
Ls_dwobject = dw_print.dataobject
// Determine whether the report format of the data window exists
Select count (*) into: ll_count from dyn_report where dwobject =: ls_dwobject;
If ll_count> 0 then
// Read report format files to large text Variables
Selectblob memo into: emp_pic from dyn_report where dwobject =: ls_dwobject;
// Create a temporary file for the file to be uploaded to the hard disk.
Ls_reportfile = '/temp7089.psr'
Ll_handle = fileopen (is_reportfile, streammode !, Write !, Lockwrite !, Replace !)
Filewrite (ll_handle, emp_pic)
Fileclose (ll_handle)
Dw_print.dataobject = ls_reportfile
Dw_print.settransobject (sqlca)
Else
Dw_print.settransobject (sqlca)
End if
Dw_print.retrieve ()
4. Save the report format. Use the clicked button of the cb_savereport button.
String ls_filename
Long ll_count
Blob emp_id_pic
Ls_filename = "temp70201.psr"
// Save the report format to a temporary file on the hard disk
Dw_print.saveas (ls_filename, psreport! , False)
Sqlca. autocommit = true
Select count (*) into: ll_count from dyn_report where dwobject =: is_dwobject;
If ll_count = 0 then
Insert into dyn_report (dwobject, rptitle)
Values (: is_dwobject,: ls_filename,: ls_path );
End if
// Read data from temporary files on the hard disk and save it to the database table
Emp_id_pic = of_readbmp file (ls_filename) // This function reads the binary file content to a large Text object.
// Update the database
Updateblob dyn_report set memo =: emp_id_pic where dwobject =: is_dwobject;
Sqlca. autocommit = false

5. Implementation of Dynamic reports. Capture the objects in the data window through the clicked event of dw_print in the data window, and store the object name in the implementation variable is_dwobject to prepare for the next step of modifying the report.

String ls_type, ls_dwoname
// Obtain the object type and name
Ls_type = trim (upper (dwo. Type ))
Ls_dwoname = trim (dwo. Name)
Is_dwtype = ls_type
Choose case ls_type
Case "text", "commandbutton", "groupbox"
Is_dwobject = ls_dwoname
// Set it to be able to drag or change the size.
This. Modify (ls_dwoname + ". resizeable = '" + "1 '")
This. Modify (ls_dwoname + ". moveable =" + "1 ")
Case "line" // The line object cannot be adjusted by setting the resizeable and moveable attributes.
Is_dwobject = ls_dwoname
Case "rectangle", "ellipse", "Graph", "bitmap"
Is_dwobject = ls_dwoname
This. Modify (ls_dwoname + ". resizeable = '" + "1 '")
This. Modify (ls_dwoname + ". moveable = '" + "1 '")
Case "column", "compute"
Is_dwobject = ls_dwoname
This. Modify (ls_dwoname + ". resizeable = '" + "1 '")
This. Modify (ls_dwoname + ". moveable = '" + "1 '")
End choose

Then, the modify () function can be used to implement basic dynamic report operations. There are many articles in this category, and a large number of examples in Pb can be used directly.

6. Add close (parent) to the clicked () event of the cb_exit button ).

7. Add open (w_temp) to the application's open event ). Save and run it!

8. This program is successfully debugged under pb7.0 and oracle8.05.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.