PB]-subdata window operations

Source: Internet
Author: User
PB]-Sub-data window operation Pb]-Sub-data window

** The common sub-data window is the drop-down data window. A child data window is also a common data window object. It has no special features, such as its creation method, available controls, and functions that can be used during programming, it is the same as a common data window. In particular, it is only because it is placed in the parent data window and needs to work with the parent window.

** When you specify a field in the data window as the edit style of the drop-down data window, you must provide the following three attributes:
A) Name of the Child data window.
B) display field name: the content of this field is displayed on the fields in the parent data window, but is only displayed.
C) data field name: the fields in the field to be assigned to the parent data window are saved to the database.
Corresponds to eidt style, display column, and data column on the edit attribute page of the data window canvas.
* The child data window cannot contain child data windows. The parent data window can insert, delete, retrieve, and save child data windows.

** Obtaining subdata window references is a prerequisite for other operations. You can use the getchild function to obtain the subdata window of a specified field. The syntax of this function is as follows:
Dw_1.getchild (name, dwchildvariable)
Dw_1 is the data window control name; name is the field name, which is the string type; dwchildvariable is the datawindowchild type variable, which saves references to the child data window after the function is correctly executed. If this function is correctly executed, 1 is returned; otherwise,-1 is returned.
After obtaining the reference of the Child data window, you can retrieve the data in the child data window. However, there are many scenarios for retrieving subdata windows, and there are also multiple methods.

** Ensure data update in the subdata window
When you use the drop-down data window to input data, the data is not necessarily required by the user. In some cases, users are not allowed to enter other values. Otherwise, data inconsistency may occur. In this case, other scripts can no longer be written. However, when you allow user input, you need to save the user input data in the data table corresponding to the child data window, so that the data will not be repeatedly input in the future. In this case, you should write a script to save the data.

** Retrieve subdata window
In applications, the child data window is programmed to either retrieve data or update data. When retrieving data, if only the data corresponding to the value of a field in the parent data window is displayed in the child data window, then the definition of the child data window should have retrieval parameters. Based on the two factors of data retrieval and data update, you can divide the data retrieval into the following three types:
A) there are no conditions and update is not allowed.
B) there are no conditions and updates are allowed.
C) There are restrictions, whether or not updates are allowed.
There are two times to retrieve the child data window. One is when the child data window is pulled down, and the other is when the parent data window is retrieved. When the child data window is opened, the data is retrieved and each time this field is entered, so that the data in the child data window is up-to-date, therefore, such a search is used only when data can be updated. When updates are not allowed, the data in the child data window is always the same as that in the parent data window. If data is not retrieved based on the values of other fields, it is not necessary to retrieve the data each time it is entered, you only need to retrieve the data when the window is opened. to retrieve data based on the values of other fields, You must retrieve the data in each drop-down sub-data window.
* Share the transaction object with the parent data window
It is the easiest programming to share transaction objects with the parent data window. Because the child data window can be used with the parent data window
The interface shares the transaction object. It simply Retrieves all the data in the child data window from the parent data window. Generally, write the following script in the window open event:
Dw_1.settransobject (sqlca)
Dw_1.retrieve ()
Pay attention to a special situation. When data windows A and B share data, if B has a child data window, a sets the transaction object while B is not set. After a uses the retrieve function to retrieve data, B because shared data will also automatically obtain data, but the drop-down sub-data window field in B can only display the encoding but not the corresponding Chinese characters, this is true even if the display columns and data columns in the properties of the drop-down data window are set correctly. Only when transaction objects are set in data window B can the field data specified in the display value of the drop-down subdata window be correctly displayed after data retrieval by.
* Retrieve data in the subdata window
Because the user may input new data at any time, to ensure that the latest data is displayed in the subdata window, the data is retrieved again each time the subdata window is opened. Before opening the child data window, you can click the mouse to write a script in the clicked event of the data window control. For example, in a software for wage and personnel management, the personnel information is stored in the employee database, and the drop-down data window can be used when selecting employees in the wage data window. The child data window must contain at least the employee name and employee ID No. The complete script is as follows:
Datawindowchild ldwc_data
If dw_1.getchild ("name", ldwc_data) <>-1 then
Ldwc_data.settransobject (sqlca)
Ldwc_data.retrieve ()
End if
In many books and lectures, the preceding programming method is used to retrieve data in the subdata window. (* You can click the event to determine whether it is a drop-down field column and then retrieve the child data window.) In fact, there are more reasonable solutions. The above method executes the script no matter whether the user clicks the drop-down data window or not, and the user does not always click the mouse before selecting the data in the drop-down data window. It may also be operated through the keyboard, in addition, the program execution efficiency is not high, and the logic is not very strict. If such an event is triggered only when the user uses the drop-down data window, the script execution efficiency will be high. In addition, the preceding solution is troublesome when there are multiple child data windows in a data window. You must write multiple scripts similar to the preceding one, every field with a drop-down data window is judged, Which is cumbersome. Once the field name changes, the script must also be modified, and the versatility is also poor. Next we will introduce a method.
First, define a Custom Event ue_dropdown to map pbm_dwndropdown. This event is triggered only when the user drop-down data window is opened, so the execution efficiency is relatively high. Then write the following script in the event:
Datawindowchild ldwc_data
Getchild (getcolumnname (), ldwc_data)
Ldwc_data.settransobject (sqlca)
Ldwc_data.retrieve ()
In this way, we can solve the cumbersome and general problems mentioned above.
The second case where you need to retrieve data is that when you enter a certain segment, this field can determine the value range of other fields, in this case, we need to retrieve the data in the subdata window of the field determined by iron.
* Search with Parameters
When retrieving field data that is affected by other field input, the child data window should be designed with retrieval parameters. In an appropriate event, use parameter retrieval. For example, after a user enters the Department name, the "employee" should be allowed. The subdata window of the field only displays the employee name of the department. You can write the following script in the ue_dropdown (pbing pbm_dwndropdown event) event of the data window control:
...... // Obtain the reference of the Child data window first.
Child. Retrieve (getitemstring (getrow (), "Department "))
Of course, the above script can also be written in the clicked event of the data window control.
If the search condition of the sub-data window is always determined by a fixed field, you can use the preceding parameter-based search. If it depends on multiple fields, you can use filter.

** Share subdata window
When multiple child data windows with the same fields are opened at the same time, it is necessary to ensure data synchronization between these child data windows, which is an important issue. Because, if there is a child data window, the user enters the new data and
This sub-data window is properly saved. If other sub-data interfaces cannot be reflected synchronously, this may cause many problems. If another user does not re-enter the data, it will be better. If the data is re-entered, an error message will appear and the user will feel inexplicable. Therefore, we must pay attention to the synchronization problem at this time.
Data sharing can effectively solve the synchronization problem between multiple child data windows opened by the same client at the same time. For example, in the wage and personnel management software, the salary and bonus payment window may be opened at the same time. The data window in these two windows contains the subdata window containing the ID card number. The following describes how to synchronize data.
Assume that the opening of the two windows has a certain order. For example, when you double-click the data window in the Payroll window, the HR maintenance window w_rs is opened. Write the following script in the dubleclicked event of the w_gz data window:
Datawindowchild ldwc_data
If getchild ("no", ldwc_data) =-1 then return
If w_rs.dw_1.20.data (ldwc_data) =-1 then
Beep (1)
If MessageBox ("error", "An Unexpected error occurs. Continue? ", Yesno, 2) = 1 then
Open (w_jj)
End if
End if
The above script ensures that any update operations on the master buffer in the data window dw_1 In the bonus window w_jj are performed
It will be reflected in the child data window.
When there is no sequence between the windows to be opened and the windows to be opened are not determined, you can define global variables. For example, in the material management system, the material name and corresponding code are saved using a data table. This subdata window is used when many data windows input materials. Global variables can be defined in the system. The statement is as follows:
Datawindowchild gdwc_data
Then, the following script is written in the window open events that use the child data window:
Datawindowchild ldwc_data
If getchild ("no", ldwc_data) =-1 then return
If ldwc_data.1_data (gdwc_data) =-1 then
Ldwc_data.settansobject (sqlca)
Ldwc_data.retrieve ()
End if
In this way, data updates in each data window can be automatically reflected in other data windows.

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.