提取DataWindow的参数

这里说的DataWindow是指dataobject的那个,而不是DataWindow Control

DataWindow可以有几个参数,但是PB并没有提供专门的函数去取得这些参数,DW Syntax也没有指出用那些关系可以去除这些参数信息。但是这些信息还是可以直接取得

dw_control.object.dataWindow.table.arguments

取出来的是一个字符串,参数之间通过~n连接,参数名和参数类型之间通过~t连接

比如有参数arg1/String和arg2/Number,我们用上述语句得到的结果就会是

"arg1~tString~narg2~tNumber"

所以这里取出来还需要做一些出来才能利用这些信息

// 定义一个custom user object去记录参数信息

(PB代码)

$PBExportHeader$nvo_dw_args.sru
forward
global type nvo_dw_args from nonvisualobject
end type
end forward

global type nvo_dw_args from nonvisualobject autoinstantiate
end type

type variables
string argName
string argType
end variables

on nvo_dw_args.create
call super::create
TriggerEvent( this, "constructor" )
end on

on nvo_dw_args.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;/**
 * This object use to store the argument info of datawindow
 * argName store argument's name
 * argType store argument's data type
 */
end event

// 读取和分析参数并返回参数信息

(PB代码)

$PBExportHeader$n_cst_dw_util2.sru
forward
global type n_cst_dw_util2 from nonvisualobject
end type
end forward

global type n_cst_dw_util2 from nonvisualobject
end type

global n_cst_dw_util2 n_cst_dw_util2

type variables
DataWindow		idw
end variables

forward prototypes
public function integer of_getarguments (ref nvo_dw_args args[])
end prototypes

public function integer of_getarguments (ref nvo_dw_args args[]);/**
 * get the registe datawindow arguments. 
 * the arguments will be store into nvo_dw_args array args[]
 * @param ref args[]- nvo_dw_args
 * @return integer
 * - return the arguments count if successful
 * - return 0 if no arguments
 * - return -1 if invalid idw or error
 * @author Ben
 * @history
 * 1. created	21-Apr-2008		Ben
 */

string ls_argStr
string ls_tmpArg
integer li_pos, li_posTab, li_index

if not isValid(idw) then return -1	

ls_argStr = idw.object.dataWindow.table.arguments

if isNull(ls_argStr) or ls_argStr = "" then return 0

do
	li_pos = pos(ls_argStr, '~n')	

	if li_pos > 0 then
		ls_tmpArg = left(ls_argStr, li_pos - 1)
		ls_argStr = right(ls_argStr, len(ls_argStr) - li_pos)
	else
		ls_tmpArg = ls_argStr
	end if

	if not isNull(ls_tmpArg) and ls_tmpArg <> "" then
		li_posTab = pos(ls_tmpArg, '~t')
		
		if li_posTab > 0 then
			li_index = upperBound(args) + 1
			args[li_index].argName = left(ls_tmpArg, li_posTab - 1)
			args[li_index].argType = right(ls_tmpArg, len(ls_tmpArg) - li_posTab)
		end if
	end if
loop while li_pos > 0

return 1
end function

on n_cst_dw_util2.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_dw_util2.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

返回的nvo_dw_args数组包含了参数名和参数类型,这样比较方便使用.

当数据存在主次表时,当更新了次表数据后,主表数据在后台有更变时。可利用刷新主表当前行的方法重显主表数据。 /************************************************************ 函数名称: f_refresh_currentrow(adw) 功 能: 刷新DW当前行数据,不可刷新NO update or 带arguments的DW 参数说明: adw 目标DW 返 回 值: integer 成功返回1,失败返回-1 作 者: sean 创建时间: 2010年8月18日 ************************************************************/ string ls_dataobject string ls_keys[] //key Column Name string ls_dbname[] //key field Name string ls_coltype[] //field style string ls_tablenm //table name string ls_condition //sql Condition long ll_currentrow //Current Row numeric long ll_column //Column count integer i datawindow ldw datastore ldatastore ldw=adw if ldw.rowcount( )=0 then return -1 elseif trim(ldw.describe( "datawindow.table.arguments"))<>'?' then messagebox('','刷新数据窗口当前行失败!,数据窗口需要参数',exclamation!) return -1 else ll_currentrow=ldw.getrow( ) FOR ll_column = 1 TO long(ldw.object.datawindow.column.count)//key names If ldw.Describe("#"+string(ll_column)+".key") ='yes' Then i++ ls_keys[i]=ldw.Describe("#"+string(ll_column)+".name") ls_dbname[i]=ldw.Describe("#"+string(ll_column)+".dbname") ls_coltype[i]=ldw.Describe("#"+string(ll_column)+".coltype") End If NEXT if upperbound(ls_keys[])=0 then messagebox('','刷新数据窗口当前行失败!,没有主键',exclamation!) return -1 else ls_tablenm=left(ls_dbname[1],pos(ls_dbname[1],'.') -1) //table name for i=1 to upperbound(ls_keys[]) if pos('numb,deci,long,',LeftA(ls_coltype[i],4) +',')>0 then ls_condition+="and "+ls_dbname[i]+"="+string(f_getitem(ldw,ll_currentrow,ls_keys[i])) else ls_condition+="and "+ls_dbname[i]+"='"+string(f_getitem(ldw,ll_currentrow,ls_keys[i]))+"'" end if next ls_condition=mid(ls_condition,4) //sql Condition ldatastore=create datastore ldatastore.dataobject=ldw.dataobject ldatastore.settransobject( sqlca) if f_addwhere_retrieve(ldatastore,ls_condition)=1 then if ldatastore.rowcount( )=1 then ldw.object.data[ll_currentrow]=ldatastore.object.data[1] ldw.setitemstatus( ll_currentrow, 0, primary!, NotModified!) //if ldw.getrow( )<>ll_currentrow then ldw.scrolltorow( ll_currentrow) end if else messagebox('','刷新数据窗口当前行失败!,条件语法错误',exclamation!) return -1 end if destroy ldatastore end if end if
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值