Use formula one in PB
Here is an example to describe F1 usage in detail. In this example, the Report and approval process for power failure application tickets of power enterprises includes process permission control. Each permission can only be modified in one part of the F1 Report, and the graphic function is available, PB 6.5 and F1 6 are used for editing. The following describes in detail: 4. read the template content to the control:
Declare instance variables: BLOB vcf_form Declare global variables: String gs_ztm, gs_lrdw, gs_gldw Datetime gd_lrsj, gd_tdsj In the window OPEN event, write the script: Datetime sj Int fh String ls_dwmc Em_1.text = string (gd_tdsj, "mm-dd, yyyy hh: mm ") Selectblob SQPNR into: vcf_form from DFS_TDSQP Where LRSJ =: gd_lrsj and LRDW =: gs_lrdw Using sqlca; // obtain the requested ticket content from the warehouse receiving If isnull (vcf_form) then Ole_1.object.Read ("template. vts", ref fh) // read the Template into the OLE Control Ole_1.object.setactivecell (21,2) Ole_1.object.Entry = string (gd_tdsj, "mm = hh: mm: dd-mm") // enter the scheduled power outage time Ole_1.object.setactivecell (4, 3) Select ZZ_DWMC into: ls_dwmc from B04 where ZZ_DWBM =: gs_lrdw; Ole_1.object.Entry = ls_dwmc // enter the planned power outage Unit Ole_1.object.setactivecell (4, 6) Ole_1.object.Entry = xm // enter the name Else If fileexists ("c:/book1.vts") then Filedelete ("c:/book1.vts ") End if Fh = fileopen ("c:/book1.vts", streammode !, Write !) // Create a temporary file If fh <>-1 then Filewrite (fh, vcf_form) // write the application ticket content in the library to the temporary file Fileclose (fh) Ole_1.object.Read ("c:/book1.vts", ref fh) // read the temporary file content into the control Else MessageBox ("error prompt", "file opening error! ") Close (this) Return End if END IF Choose case qx CASE "lr" // when the permission is set to level 2, only reports on the left half can be input. Ole_1.object.selection = "A1: G38" Ole_1.object.setprotection (false, false) // set cells A1: G38 to writable, and other cells are not allowed. Ole_1.object.enableprotection = true Ole_1.object.selection = "C4" // cursor stops at C4 Cell CASE "gl" CASE "zd" CASE "zb" END CHOOSE |
5. Right-click the ole_1 control to directly edit the report and fill in the content to the writable cell. You can use the F1 drawing tool to make a simple chart of the report.
6. Write the modified control content to the database:
Int fh OLEobject book; String filename = "c:/book1.vts" Book = ole_1.object Book. Write (filename, 12) // Write the control content to a temporary file Fh = fileopen (filename, StreamMode !) IF fh <>-1 THEN FileRead (fh, vcf_form) // write the temporary file content to the BLOB variable FileClose (fh) ELSE RETURN 0 END IF If len (vcf_form)> 0 then UPDATEBLOB DFS_TDSQP set SQPNR =: vcf_form Where LRSJ =: gd_lrsj and LRDW =: gs_lrdw Using sqlca; // writes BLOB variable content to the database IF SQLca. sqlcode = 0 THEN COMMIT using sqlca; // MessageBox ("prompt", "complete the storage of the requested database ticket! ") ELSE ROLLBACK using sqlca; MessageBox ("prompt", "ticket storage application failed! ") RETURN 0 END IF End if Gd_tdsj = datetime (date (left (em_1.text, 4) + "-" + mid (em_1.text,) + "-" + mid (em_1.text )),& Time (mid (em_1.text, 15, 5) + ": 00 ")) Update DFS_TDSQP set TDSJ =: gd_tdsj, ZTM =: ztm_wf Where LRSJ =: gd_lrsj and LRDW =: gs_lrdw Using sqlca; // Save the input time and unit value If sqlca. sqlcode = 0 then Commit using sqlca; MessageBox ("prompt", "complete database storage operations! ") Return 1 Else Rollback using sqlca; MessageBox ("prompt", "Storage operation failed during power outage! ") Return 0 End if |
7. Print the control content
Ole_1.object.fileprint (true)
In fact, all functions such as read, write, savefiledlg, and fileprint are owned by Formula One. in PowerBuilder, you only need to add an object after ole_1 to reference these functions. The function definition is in the help of F1, please refer to it in your own time.
1. Create an F1 file for the ticket application as a template, such:
To implement permission control, set the I1: hw1's cell to be protected so that the right half-side report cannot be written:
1) Select a cell and right-click format cells: Tick the locked under protection.
2) Check the sheet item protection in the Format menu. This sentence is very important; otherwise, the previous sentence does not work.
2. Create a power failure ticket table dfs_tdsqp in the database:
Lrsj entry time tdsj power failure time
Lrdw entry Unit
Gldw Management Unit
Tdsb power-off device
Gznr work content
Kgsj Start Time
Wgsj completion time
GZR employee
ZTM status code
IMAGE Type of SQPNR ticket request content
3. Insert the F1 control in the pb window:
In the window of POWERBUILDER, click the OLE icon: the "insert object" dialog box appears. Select the insert control label item (for example ),
Select Vci Formula One Workbook in the object list, press the OK key, select the insert position, and click the mouse to add an OLE object named ole_1, right-click it and select the OCX Properties item. Under the Show label, you can deselect the Row Heading and Column Heading items and change the value of Tabs from Bottom to Off (for example ), the added OLE object is a blank table without row headers, column headers, and labels.