Implementation of related joint drop-down data windows in PB

xiaoxiao2021-03-06  76

Recently, in the development process, the case of using the drop-down data window: The data table DATA has two columns DEPT_ID (executive department code), the value of Unit_ID (enterprise code) is from the data table DEPT (Administration) and Unit (basic basic) Situation), and require a certain competent department to display all companies of the competent department to choose. The structure of the data sheet is as follows (simplified):

Table Name Date Type Length Keyword Meaning DATADEPT_IDCHAR5 No Administrative Department Code Unit_IDCHAR9 is the enterprise code NUMNUMERIC7 (no decimal) No onset DEPTIDCHAR5 is the competent department code NameChar15 No Administrative department ? / Td> Unitidchar7 is a company code NameChar30 No Enterprise name de PEPT_IDCHAR5 No Administrative department code

To implement these requirements, 2 field dept_id, unit_id of the DATA table can be designed as two associated drop-down data windows. The key is how to pass the current selected value of DEPT_ID to Unit_ID to display only the corresponding administrative department. Enterprise list. To this end, I have reviewed many relevant books and related websites, find two solutions: set the retrieval parameters and use dynamic SQL statements. The common key to these two solutions is to use the getChild () function and the DataWindowChild type variable. Many data stitches that the search parameters are the easiest and most convenient effective solution, which also proposes several ways to hide the "Specify Retrieval" dialog box that automatically pops up. But unfortunately, I don't have to do everything possible (primarily unable to hide the "Specify Retrieval" dialog box that automatically pops up the system). Therefore, consider using a dynamic SQL statement. After some effort, it was finally satisfactorily achieving design requirements. The specific practices are as follows: 1. First create the application DDDW, and the operation is prompted. (PowerBuilder 8.0, first create Workspace DDDW.PDW, other operations Basically with PowerBuilder7.0) 2. Create Data Window DDDW_DEPT: Grid, Quick SELECT, Table DEPT all fields, it is best not to define the WHERE clause to avoid complex back programming Chemical, you can remove the header part (you can make it simpler). 3, create data window DDDW_Unit: Grid, Quick SELECT, all fields of the table Unit, the rest. 4. Create data window D_1: FreeForm, Quick SELECT, table Data all fields, appropriate arrangements, edit, the key is DEPT_ID and Unit fields, must be dropped down data window. The following is taken as an example: Right-click DEPT_ID field (Note: Not a column header), select "Properties ..." in the pop-up menu, then select "Edit" tab in the pop-up "Properties-Dept_ID" window, in "Style" "DROPDOWNDW" in the Type drop-down box, select the check box "Always Show Arrow", "V Scrollbar", and enter "DDDW_DEPT" in the "DataWindow" edit box, or click on "..." to choose, "DISPLAY COLUMN" drop-down box Select "Name" in the drop-down data window), select "ID" in the "Data Column" drop-down box (ie, the actual store is the ID column value). Fields Unit_ID is like a method, simply change "DDDW_DEPT" in the "DataWindow" edit box to "DDDW_Unit". 5. Create a main window W_main, and build a data window control DW_1, which DataObject is D_1. Write the following script in the OPEN event of the main window W_main: long ll_newrowsqlca.dbms = "odbc" sqlca.autocommit = truesqlca.dbparm = "ConnectString = 'DSN = SMPDB'" // ODBC data source has been configured with Connect; dw_1 .SETTRANSOBJECT (SQLCA) dw_1.retrieve ()

Then write the following script in the itemfocuschanged event of Data Window DW_1:

Integer rtncodeString ls_nowFld, ls_deptid, ls_sqlDataWindowChild fld_childrtncode = dw_1.GetChild ( "Unit_id", fld_child) file: // get Unit_id field drop-down data window handle If rtncode = -1 Then MessageBox ( "Error!", "Is not a drop-down data window! ") FLD_CHILD.SETTRANSOBJECT (SQLCA) File: // Sets Transaction Object Ls_SQL = LOWER (FLD_CHILD.GETSQLSELECT ()) // Gets the SQL statement of the DDDW to remove the WHERE condition clause in the SQL statement, such as the original SQL statement There is a WHERE condition clause, which is required for File: //, which should be done depending on the situation. IF POS (LS_SQL, "Where")> 0 THEN LS_SQL = Left (Ls_SQL, POS (LS_SQL, "WHERE")) File: // Reset the WHERE Conditions in the SQL statement LS_DEPTID = dw_1.object.dept_id [GetRow ()] file: // get the current dePT_ID selected value ls_sql = ls_sql "where dept_id = '" trim (ls_deptid) ' "File: // Reset SQL statement fld_child.setsqlselect (ls_sql) FLD_CHILD.RETRIEVE ) // Number 6 acquiring the condition 6, writing in the Open event application DDDW: Open (w_main) to this, the application is completed, it has been run. Note: In Win98 / WindowsXP, PowerBuilder8.0 / PowerBuilder7.0 / PowerBuilder 6.5.

Supplementary Description: (1), ODBC Data Source Setting Opens the "Start" menu of the Windows operating system - à Set - à Control Panel - àodbc Data Source, "ODBC Data Source Manager" window, in "System DSN" Click "Add (D) ..." button, "Create a New Data Source" window, double-click the "Adaptive Server Anywhere 7.0" option in the list box, which pops up the "ODBC Configuration for Adaptive Server ..." window, in the ODBC tab In the "Data Source Name" text box, enter SMPDB, enter the database file name and suffix of the SMPDB, Database File text box in the Database tab, and suffix, such as database SMPDB.DB in C: / Program Files / In the Sybase / Adaptive Server Anywhere 7.0 folder, you can click C: / Program Files / Sybase / Adaptive Server Anywhere 7.0 / SMPDB.DB, or click the "Browse ..." button to select the database file, then click the "OK" button, ODBC The data source is set. Other data sources can be set to the settings. (2) Powerbuilder8.0 Related to issues PowerBuilder 8.0 Create an application first must create (or open) Workspace (*. PBW) file, other operations are basically the same as PowerBuilder7.0. This example runs in PowerBuilder8.0, running as follows: DDDW.PBL, DDDW.PBW, DDDW.PBT (compressed in dddw_db.zip). The sample diagram of the main window W_main of this example is edited in PowerBuilder 8.0. Example The run results diagram in PowerBuilder6.0 / 6.5, PowerBuilder 7.0, PowerBuilder 8.0 is shown below. Figure (-) PowerBuilder 8.0 Edit the main window W_Main of this example

An example of the operation results diagram in PowerBuilder6.0 / 6.5

Attached 2 Example Running results in PowerBuilder 7.0

Figure 3 Example Running results in PowerBuilder 8.0

转载请注明原文地址:https://www.9cbs.com/read-120701.html

New Post(0)