Powerbuilder tips
Script untuk Mengubah object datawindow secara manual:
// Changing DataWindow object by code methods
string error_syntaxfromSQL, error_create
string new_sql, new_syntax
new_sql = 'SELECT emp_data.emp_id, emp_data.emp_name from emp_data' &
+ 'WHERE emp_data.emp_salary> 45000'
new_syntax = SQLCA.SyntaxFromSQL (new_sql, 'Style (Type = Form)', error_syntaxfromSQL)
IF Len (error_syntaxfromSQL)> 0 THEN // Display errors
mle_sfs.Text = error_syntaxfromSQL
ELSE // Generate new DataWindow
dw_new.Create (new_syntax, error_create)
IF Len (error_create)> 0 THEN
mle_create.Text = error_create
END IF
END IF
dw_new.SetTransObject (SQLCA)
dw_new.Retrieve ()
Array Datawindow:
// Open dynamic window approach:
window newarray [3]
string win [3]
int i
win [1] = "w_employee"
win [2] = "w_customer"
win [3] = "w_sales"
for i = 1 to 3
Open (newarray [i], win [i])
next
// Displays a consistent style with the Windows operating system About dialog. First, the following
statement external function:
function int ShellAboutA (ulong al_hWnd, string as_szApp, string as_szOtherStuff, ulong hIcon) library
"shell32"
ShellAboutA (handle (parent), "About ... # ferryman studio", "Welcome to the ferryman studio", 0)
// How COLUMN display style between EDIT, DDDW, DDLB switch between:
(1) is switched to the DDDW:
dw_1.Modify ("# 1.dddw.Name = 'dddw_jg'")
dw_1.Modify ("# 1.dddw.DisplayColumn = 'name_jg'")
dw_1.Modify ("# 1.dddw.DataColumn = 'id_jg'")
(2) switch to DDLB:
dw_1.Modify ("# 1.ddlb.case = 'any'")
dw_1.Object. # 1.Values = "red ~ t1 / white ~ t2"
(3) switch to the EDIT:
dw_1.Modify ("# 1.edit.case = 'any'")
dw_1.Modify ("# 1.edit.")
(4) Get the current style:
dw_1.Describe ("# 1.Edit.Style")
(5) If not enough, you may have to do the following:
dw_1.Modify ("# 1.dddw.Name = ''") about;
// Few records you want to print selected in the dw_1
long ll_pos
dataStore lds_ds
lds_ds = create dataStore
lds_ds.dataObject = dw_1.dataObject
for ll_pos = 1 to dw_1.rowCount ()
if dw_1.IsSelected (ll_pos) then
dw_1.RowsCopy (ll_pos, ll_pos, Primary!, lds_ds, lds_ds.rowCount () + 1, Primary!)
end if
next
lds_ds.print ()
// SQL statement calling convention
INTEGER li_customer_id = 1
STRING ls_city_code = '501'
PREPARE SQLSA FROM "DELETE bb_customer_info_t WHERE city_code = AND customer_id = ";
EXECUTE SQLSA USING: ls_city_code,: li_customer_id;
Bekerja dengan database:
// Modify function by modifying multiple tables simultaneously
1, a new data window d_grid_dep_emp, its Select statement
SELECT department.dept_id,
department.dept_name,
employee.emp_id,
employee.emp_fname,
employee.emp_lname
FROM department, employee
WHERE employee.dept_id = department.dept_id
2, set the data window d_grid_dep_emp properties of the column taborder to non-zero value; and click
on the menu Rows -> Update
Properties, set this data window Allow Updates, Table to Update to department, Updateable Columns of
department.dept_id, department.dept_name.
3, update the data window button in the window clicked event scripting:
long ll_rtn
// Modify Department table (Department table in step 2 is set to be updated)
ll_rtn = dw_1.update (true, false)
If ll_rtn = 1 then
// Close modifications to the Department table
dw_1.Modify ("department_dept_name.Update = 'No'")
dw_1.Modify ("department_dept_id.Update = 'No'")
dw_1.Modify ("department_dept_id.Key = 'No'")
// Set the Employee table into a new table can be modified
dw_1.Modify ("DataWindow.Table.UpdateTable = 'employee'")
dw_1.Modify ("employee_emp_id.Update = 'Yes'")
dw_1.Modify ("employee_emp_fname.Update = 'Yes'")
dw_1.Modify ("employee_emp_lname.Update = 'Yes'")
dw_1.Modify ("employee_emp_id.Key = 'Yes'")
// Modify the Employee table
ll_rtn = dw_1.Update ()
IF ll_rtn = 1 THEN
COMMIT USING SQLCA;
dw_1.retrieve ()
messagebox ('message', 'updated successfully!')
ELSE
ROLLBACK USING SQLCA;
MessageBox ('message', 'update failed!')
END IF
// Reset modify flag
dw_1.Modify ("department_dept_name.Update = 'Yes'")
dw_1.Modify ("department_dept_id.Update = 'Yes'")
dw_1.Modify ("department_dept_id.Key = 'Yes'")
dw_1.Modify ("DataWindow.Table.UpdateTable = 'department'")
dw_1.Modify ("employee_emp_id.Update = 'No'")
dw_1.Modify ("employee_emp_fname.Update = 'No'")
dw_1.Modify ("employee_emp_lname.Update = 'No'")
dw_1.Modify ("employee_emp_id.Key = 'No'")
ELSE
ROLLBACK USING SQLCA;
MessageBox ('message', 'update failed!')
END IF
// Above functions can be made a function call can be when necessary.
// Click Edit marquee in which the content
getfocus event write code: this.selecttext (1, len (this.text)). Save running, do not get what we want
Effect. Think of an alternative approach: to pbm_bnclicked for the event ID, create a single-line edit box
custom event ue_clicked,
Code is: this.selecttext (1, len (this.text)),
code getfocus event changed: This.Post Event ue_clicked (). After the save operation, the effect came
out!
// How to get the number of characters in the string
For i = 1 to Len (aString)
ls_ch = Mid (aString, i, 1)
If Asc (ls_ch)> = 128 then // Chinese characters
li_num ++
i=i+1
End if
Next
// Finally, li_num is the number of characters
// DW supports double-click the title to sort
String ls_old_sort, ls_column, ls_name, ls_criteria
Char lc_sort
IF Right (dwo.Name, 2) = '_t' THEN // made whether the column header name
ls_column = LEFT (dwo.Name, LEN (String (dwo.Name)) - 2)
ls_old_sort = this.Describe ("Datawindow.Table.sort")
IF ls_column = LEFT (ls_old_sort, LEN (ls_old_sort) - 2) THEN
lc_sort = RIGHT (ls_old_sort, 1)
IF lc_sort = 'A' THEN
lc_sort = 'D'
ELSE
lc_sort = 'A'
END IF
this.SetSort (ls_column + "" + lc_sort)
ELSE
ls_criteria = ls_column + "A"
this.SetSort (ls_criteria)
END IF
this.Sort ()
END IF