powerbuilder编程简单入门(个人总结) 联系客服

发布时间 : 星期五 文章powerbuilder编程简单入门(个人总结)更新完毕开始阅读059ec4886529647d27285292

2011-4 by 邵家鑫 From Tsinghua

SELECT employee.emp_id, employee.l_name

FROM employee

Presumably, the application builds a WHERE clause based on the user's choices. The WHERE clause might be:

WHERE emp_id > 40000

The script for the window's Open event stores the original SELECT statement in original_select, an instance variable:

dw_emp.SetTransObject(SQLCA)

original_select = &

dw_emp.Describe(\

The script for a CommandButton's Clicked event attaches a WHERE clause stored in the instance variable where_clause to original_select and assigns it to the DataWindow's Table.Select property:

string rc, mod_string

mod_string = \

+ original_select + where_clause + \

rc = dw_emp.Modify(mod_string)

IF rc = \

dw_emp.Retrieve( )

ELSE

MessageBox(\

END IF

4.6 常用PowerScript语句 1) CHOOSE CASE语句

CHOOSE CASE Weight CASE IS<16 ..

2011-4 by 邵家鑫 From Tsinghua

CASE IS 16 to 18 .. CASE ELSE .. END CHOOSE

2) 循环语句

DO UNTIL 条件 语句块 LOOP 或 DO WHILE 条件 语句块 LOOP DO 语句块 LOOP UNTIL 条件 FOR varname=start To end {STEP increment} statementblock NEXT

4.7 程序中修改数据窗口中的选择条件(不是利用过滤函数)

在数据窗口与数据库联接时的SQL语句中用过滤条件比检索后用过滤条件过滤效率更高,因此如果需要显示满足一定条件的数据时,一般时直接修改数据窗口的SQL搜索语句。程序编写过程如下:

(1) 编写全局函数f_change_where(string ps_sql,string ps_where)用某条件ps_where代替SQL选择语句ps_sql中的where条件,代码如下: if ps_sql = \ps_sql = lower(ps_sql)

string ls_front, ls_end, ls_where, ls_return if pos(ps_sql, \ ls_front = left(ps_sql, pos(ps_sql, \ if pos(ps_sql, \ ls_end = right(ps_sql, len(ps_sql) - pos(ps_sql, \ ls_where = mid(ps_sql, pos(ps_sql, \\len(ps_sql)-len(ls_front)-len(ls_end)-6) elseif pos(ps_sql, \ ls_end = right(ps_sql, len(ps_sql) - pos(ps_sql, \ ls_where = mid(ps_sql, pos(ps_sql, \\len(ps_sql)-len(ls_front)-len(ls_end)-6) else ls_where = mid(ps_sql, pos(ps_sql, \ end if

2011-4 by 邵家鑫 From Tsinghua

ls_return = ls_front + \else if pos(ps_sql, \ ls_front = left(ps_sql, pos(ps_sql, \ ls_end = right(ps_sql, len(ps_sql) - pos(ps_sql, \ elseif pos(ps_sql, \ ls_front = left(ps_sql, pos(ps_sql, \ ls_end = right(ps_sql, len(ps_sql) - pos(ps_sql, \ else ls_front = ps_sql ls_end = \ end if ls_return = ls_front + \end if

return ls_return

(2) 在窗口中声明局部变量用来记录最初的没有where语句的窗口的SQL查询语句 string is_original_sql

(3) 声明局部变量ls_old_select, ls_new_select,如下使用 string ls_old_select, ls_new_select

ls_old_select = dw_ttxx.GetSQLSelect() if is_original_sql = \ is_original_sql = ls_old_select else //避免条件被循环添加 ls_old_select = is_original_sql end if

ls_new_select = f_change_where(ls_old_select, is_conditions) dw_窗口.SetSQLSelect(ls_new_select)