One, the PB Data window multi-line selected program
First define the window instance variable:
Long Il_lastselectedrow = 1
Then you start writing multiple-line selection programs. The program algorithm is described as follows:
1. If the control key is pressed
If it is on the selected row, cancel the line
Otherwise, select the row
Record the current to window instance variable
2. If you press the SHIFT key
Cancel All rows selected
Select all rows of data between the last click and the current row
Record the current to window instance variable
3. If there is no key
If you click the behavior to select a row, nothing is done
Otherwise, deselect all selected lines and select the forward
Record the current to window instance variable
For example, we wrote the script in the clicked event of the window Dw_1, with the following program:
Instance variable definition in window: long Il_lastselectedrow = 1
long ll_start
long ll_end long
ll_index
if Row < 1 then retur n
if KeyDown (keycontrol!) then
if this.isselected (Row) then
this.selectrow (row,false)
else
This.selectrow (row,true)
End If
elseif KeyDown (keyshift!) then
if Row < Il_lastselectedrow Then
Ll_start = Row
ll_end = il_lastselectedrow
else
ll_start = il_lastselectedrow
ll_end = row< C17/>end if
this.selectrow (0,false) for
Ll_index = Ll_start to Ll_end
This.selectrow (ll_index,true)
Next
Else
if not this.isselected (row) then
this.selectrow (0,false)
this.selectrow (Row, True)
End If
End If
il_lastselectedrow = Row
Second, PB tree-type structure traversal
The traversal of a tree structure is usually implemented using a recursive program, so this section gives a search by content, iterates over the tree structure, and returns the handle of the node if it is equal to what is being looked for. The functions are as follows:
*-----------------------------------------------------------------------------//* function name: Long Wf_reader (Long Al_
handle,string as_target)//* function: traverse the tree structure to find the node of the specified content.
* Return value: The handle of the node.
* Algorithm Description: Traverse the tree structure, using recursion to complete.
*----------------------------------------------------------------------------*/long Ll_handle long ll_handleold TreeViewItem Ltvi_item String Ls_label string Ls_data if Tv_1.getitem (al_handle,ltvi_item) = 1 then return-1 ls_label=t
Rim (String (Ltvi_item.label)) Ls_data=trim (String (ltvi_item.data)) If Ls_label = As_target then return al_handle else Ll_handle = Tv_1.finditem (childtreeitem!,al_handle) End If if ll_handle > 0 Then if Tv_1.getitem (ll_handle,lt Vi_item) =-1 then return 0 Ls_label=trim (string (Ltvi_item.label)) Ls_data=trim (String (ltvi_item.data)) if Ls_ Label = As_target then return ll_handle//found the node to add else return Wf_reader (ll_handle,as_target) End If Else Ll_handleold = al_handle Ll_handle = Tv_1.finditeM (nexttreeitem!,ll_handleold) do while Ll_handle < 0 ll_handle = Tv_1.finditem (parenttreeitem!,ll_handleold ) if Ll_handle > 0 Then ll_handleold = ll_handle Ll_handle = Tv_1.finditem (nexttreeitem !,ll_handleold) Else Ll_handle = Tv_1.finditem (nexttreeitem!,ll_handle) if Ll_handle < 0 Then Return-1 End If Loop if Tv_1.getitem (ll_handle,ltvi_item) = 1 T
Hen return-1 ls_label=string (ltvi_item.label) ls_data=string (ltvi_item.data) If Ls_label = As_target Then
Return ll_handle//found the node to add else return Wf_reader (ll_handle,as_target) End If End If
Three, PB write login program
Our request is, first open the main window, and then display the login interface, the user can try to log in at most 3 times, if the login is successful, the main window interface is initialized according to user rights, otherwise the entire app is closed.
The login program looks simple and actually involves a lot of knowledge. Knowledge points are: Use of SQL statements, understanding of window types, Singlelineedit controls, application of CommandButton properties, custom user events, how to trigger custom user events, using window instance variables, how to pass information between different windows, and more. Let's start implementing the program.
Design Login window W_login, place two Singleedit, two CommandButton, respectively named Sle_userid, Sle_password, Cb_cancel, CB_OK; Select Sle_ The Password property of the password. To calculate the number of times a user tries to log on, first define a window instance variable:
Integer Ii_count = 3
The user enters the user login flag in the Sle_userid, and the carriage return should automatically switch to Sle_password. So, write the following script in the Sle_userid modified event:
Sle_password. SetFocus ()
Similarly, the user entered the password in the Sle_password, and then enter, this should be the user entered the login information to verify, so need to trigger the CB_OK button clicked event. So, write the following script in the Sle_password modified event:
Cb_ok. Default = True
Why can't I use CB_OK above? Triggerevent (clicked!) it. The attentive reader should first ponder. Next is our main programming, which writes the following script on the clicked event of the CB_OK command button:
String Ls_userid
string Ls_password
integer li_count
ls_userid = Sle_userid. Text
Ls_password = Sle_password. Text
Select COUNT (*) Into:li_count from users where UserID =: Ls_userid and password =: Ls_password;
If Li_count > 0 then
gs_userid = Ls_userid
Select username into:gs_username from users where UserID =: Ls_user ID;
Closewithreturn (parent, ' OK ')
else
ii_count--
if Ii_count = 0 then halt close;
Sle_userid.text = '
sle_password.text = ' This
. Default = False
sle_userid. SetFocus ()
End If
Write the following script in the clicked event of the Cb_cancel command button:
Closewithreturn (parent, ' Cancel ')
In the window's Open event, write the following script:
Sle_userid. SetFocus ()
Then set the type of the window to the response type. At this point, the User Login window is complete. Next we call it in the main window. For example, the main window name of our program is W_main, which opens the window for the open event of the Application object. Next, we need to call W_login in W_main.
Through the above program we can see that the success of the user login is determined by W_login return information. When the user logs on successfully, the W_main continues with the interface initialization or the entire application is closed. Because W_login is a response type, W_main waits until the w_login is turned on, knowing that W_login closes the return message w_main before it resumes execution. To ensure that W_main is displayed first and then w_login, we need to define custom events for W_main, such as we define Ue_open events. Write the following procedure in the W_main Open event:
This. Postevent (' Ue_open ')
Then, write the following procedure in the Ue_open event:
String ls_temp Open
(w_login)//Open Login window
ls_temp = message.stringparm//Accept the return information of the login window.
if ls_temp <> ' OK ' then//if not logged in successfully.
halt close;//shutdown system
else//login succeeded, initialize user interface according to user rights. Statement Omit
End If
Four, PB get server time
*-----------------------------------------------------------------------//* Function Name: DateTime gf_getsysdate (string AS_DBMS)//* function Description: Date Time (datetime)//* parameter meaning: As_dbms used database DBMS//* return value: DateTime type, System date//* invocation example: Ldt_today = Gf_getsysdate (Sqlca.dbms)//*------------------------------------------------------------------- ----*/datetime ldt_date string Ls_sql Choose Case lower (AS_DBMS) case "Oracle"//oracle ls_sql = "se Lect sysdate from sys.dual ' case ' SQL Server '//ms SQL Server Ls_sql = ' Select Now () ' Case ' Sybase "//sybase ls_sql =" Select GETDATE () "Case Else Ls_sql =" Select Now () "End Choose Declare L
_cursor dynamic cursor for SQLSA;
Prepare Sqlsa From:ls_sql;
Open dynamic l_cursor;
If Sqlca.sqlcode = 0 then Fetch l_cursor into:ldt_date; End If If Sqlca.
SQLCode <> 0 Then MessageBox ("error message", "Database error at function gf_get_sysdate () Run time!") Ldt_date = Datetime (Today (), now ()) enD if Close l_cursor;
Return ldt_date
v. Find where a string last appears in another string
*---------------------------------------------------------------------------------
//* Call method: gf_ Getlastposition (String as_string,string as_substring)
//* function: Find the string as_string another substring As_ Substring the last position that appears.
* return value: The position of the last occurrence of the integer type.
* variable use: no global variable is used.
*----------------------------------------------------------------------------------*/
integer li_pos,li_ nextpos//is used to save the current position and the last position if
as_string = "" or as_substring = "then return 0 //If two empty strings are passed over.
Li_pos = pos (as_string,as_substring)//variable initialization.
If Li_pos = 0 then//not found
return 0
else
li_nextpos = Pos (As_string,as_substring,li_pos + 1)//second occurrence position
End If do while
li_nextpos<>0
li_pos = li_nextpos
li_nextpos = Pos (as_string,as_substring, Li_pos + 1)
Loop
return Li_pos