Create a logon instance Using PowerBuilder-I understand it at last (2 ).

Source: Internet
Author: User

Create a logon instance Using PowerBuilder-I understand it at last (2 ).

Iii. logon examples

1. Create an Application Object (1) Select file \ new, or press Ctrl + N to create a Workspace. For example, click OK and name it testSpace.

(2) Same as the above method, create a Traget \ Application library and click OK.


Enter the database name testapplication and the corresponding path, and click Finish.


 

2. Create the first Window (login Window) (1) Select file \ new, or press Ctrl + N to create a PB Object \ Window form, and then click OK. create a form and add a control.


(2) place corresponding controls according to operations


After setting, save and enter the form name frm_log to get the login form.



3. Create a data window object (skip this step. (1) Select file \ new, or press Ctrl + N to create a DataWindow \ Grid item.


(2) select the SQL select data source type.


(3) then, select the created table and click open.


(4) Right-click and Select All


(5) Finally, select Save and name it testdw.


 

4. Create a data window control (skip this step (1) Select file \ new, or press Ctrl + N to create a DataWindow \ Grid item (same as step 1 )]

(2) Select Quick Select items this time


(3) For example, select user_info, click AddAll, and then click OK.


(3) After obtaining the form, click Next and Finish. Save and name it testdatawindow.

5. Create an application (1) Compile open event Code. For example, double-click testapplication in a project.


Then, select the open event and write the code.


(2) Search for the code to be written. Select Tools \ DataBasePainter from the menu bar, or click the DataBase button in.

Select ODBC \ Testdatabase, right-click, and select Properties.


Select the Preview selection box, click Copy, and then OK.


Finally, open the open event again, paste the copied code to it, and add some code. The final code is as follows:

// Profile TestdatabaseSQLCA. DBMS = "ODBC" SQLCA. autoCommit = FalseSQLCA. DBParm = "Connectstring = 'dsn = testdatabase'" // Add the following code. Note that the semicolon is in English; otherwise, connect; open (frm_log) is returned)

(2) write the logon code. Double-click the logon button on the form or select itemchanged directly (this item is at the bottom of the form)


Select the logon button and click the event.


(3) Compile the logon button Code as follows:

// Log on to string userName, userPwd // declare the userName and password variable userName = trim (sle_name.text) // obtain the userName userPwd = trim (sle_pwd.text) // obtain the password if userName = "" then // determine whether the userName is empty messagebox ("prompt", "userName cannot be blank ") else // determine whether the user exists // SQL statement to query SELECT nameinto: userNamefrom "User_Info" where "User_Info ". "name" =: userName; // SQLCode = 100 no record found. This user does not exist if SQLCA. SQLCode = 100 then messagebox ("prompt", "user does not exist") else // whether the user's query password is correct SELECT nameinto: userNamefrom "User_Info" where "User_Info ". "name" =: userName and "User_Info ". "password" =: userPwd; if SQLCA. SQLCode = 100 then messagebox ("prompt", "Incorrect password") elsemessagebox ("prompt", "Logon successful") end ifend if
(4) Compile the exit button Code as follows:
// Close the form close (parent)

6. Run the application

Save all operations and press Ctrl + R. We will not show you here. Because the user names and passwords stored in the data table are "1", only the user names and passwords are "1.


Note:

Our simple login function has finally been completed. because we did not know much about the function of PB for the first time, the operation steps are detailed, however, the disadvantage of this program is that the data window object is created in step 3 and Step 4, but it is not used at the end (in fact this part is not used, I wanted to remove this part, but I don't know if the data window object has any function. So I stayed and hoped that I would have a deeper understanding of this Part in the subsequent learning process.


Related reading: PowerBuilder full instance

Powerbuilder initial test-uncover that layer of gauze



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.