ue_after中的代码在pb65一切OK。
//////////////////////////////////////////////////////////////////////////////
integer i,ln_curx,ln_cury,ln_left,n,ln_len[10],ln_star,j, LL_ROW_CUR
any lf_field1
any lf_field[10]
string ls_title[10]
sele_info=message.powerobjectparm
//定义动态游标
PREPARE SQLSA FROM :sele_info.sql;
DESCRIBE SQLSA INTO SQLDA ;
OPEN DYNAMIC my_curs USING DESCRIPTOR SQLDA ;
//获取标题
dispnum=0
ln_star=1
if sele_info.title<>'' then
do while true
n=pos(sele_info.title,",",ln_star)
if n=0 then
exit
end if
dispnum=dispnum+1
ls_title[dispnum]=mid(sele_info.title,ln_star,n - ln_star)
ln_star=n+1
loop
dispnum=dispnum+1
ls_title[dispnum]=mid(sele_info.title,ln_star,len(sele_info.title) - ln_star+1)
end if
//debugbreak()
//获取显示数据
dispnum=0
ln_star=1
do while true
n=pos(sele_info.displayfields,",",ln_star)
if n=0 then
exit
end if
dispnum=dispnum+1
ln_len[dispnum]=integer(mid(sele_info.displayfields,ln_star,n - ln_star))
ln_star=n+1
loop
dispnum=dispnum+1
ln_len[dispnum]=integer(mid(sele_info.displayfields,ln_star,len(sele_info.displayfields) - ln_star+1))
//定义DW当前页
for i=1 to 9
dw_1.insertrow(0)
next
//总页数
il_page_nums=1
//当前页数
il_page_cur=1
//当前行数
Ll_row_cur=0
//全部读取标志
IB_PAGE_END=FALSE
i=1
do while true //while1
fetch my_curs using descriptor SQLDA;
Ll_row_cur=Ll_row_cur+1
if sqlca.sqlcode=0 then
//首次读取记录
if Ll_row_cur=1 then
ip_outtype=sqlda.outparmtype[sele_info.returnfield]
choose case ip_outtype
case typestring!
lf_field1=getdynamicstring(sqlda,sele_info.returnfield)
case typeinteger! ,typelong!
lf_field1=getdynamicnumber(sqlda,sele_info.returnfield)
case typedate!
lf_field1=GetDynamicDate(sqlda,sele_info.returnfield)
case typedatetime!
lf_field1=GetDynamicDatetime(sqlda,sele_info.returnfield)
case else
lf_field1=getdynamicnumber(sqlda,sele_info.returnfield)
end choose
//DATAWINDOW尺寸调整
if sele_info.title<>'' then
dw_1.object.datawindow.header.height=100
dw_1.height=dw_1.height+100
this.height=this.height+100
else
dw_1.object.datawindow.header.height=0
end if
dw_1.modify("field"+string(1)+".width="+string(ln_len[1]*38+100))
dw_1.modify("text"+string(1)+".text='"+ls_title[1]+"'")
dw_1.modify("text"+string(1)+".width="+string(ln_len[1]*38+100))
ln_left=120+ln_len[1]*38
for n=2 to dispnum
if sele_info.title<>'' then
dw_1.modify("text"+string(n)+".text='"+ls_title[n]+"'")
dw_1.modify("text"+string(n)+".x="+string(ln_left))
dw_1.modify("text"+string(n)+".width="+string(ln_len[n]*38))
end if
dw_1.modify("field"+string(n)+".x="+string(ln_left))
dw_1.modify("field"+string(n)+".width="+string(ln_len[n]*38))
ln_left=ln_left+ln_len[n]*38+60
next
//DATAWINDOW及窗体定位
dw_1.width=ln_left
this.width=ln_left+75
// if ln_curx+this.width>PixelsToUnits(env.ScreenWidth, XPixelsToUnits!) then
//// ln_curx=ln_curx - this.width - 200
// ln_curx=sele_info.x
// end if
// if ln_cury+this.height>PixelsToUnits(env.ScreenHeight, YPixelsToUnits!) then
//// ln_cury=ln_cury - this.height - 100
// ln_cury=sele_info.y
// end if
this.move(sele_info.x,sele_info.y)
end if
//读取当前数据
for n=1 to sqlda.numoutputs
choose case sqlda.outparmtype[n]
case typestring!
lf_field[n]=getdynamicstring(sqlda,n)
case typeinteger!
lf_field[n]=getdynamicnumber(sqlda,n)
case typedate!
lf_field[n]=GetDynamicDate(sqlda,n)
case typedatetime!
lf_field[n]=GetDynamicDatetime(sqlda,n)
case else
lf_field[n]=getdynamicnumber(sqlda,n)
end choose
next
//设置DATAWINDOW
dw_1.setitem(i,1,STRING(I)+": "+string(lf_field[1]))
for j=2 to dispnum
dw_1.setitem(i,j,string(lf_field[j]))
next
choose case ip_outtype
case typestring!
dw_1.setitem(i,'reval',lf_field[sele_info.returnfield])
case typeinteger!,typelong!
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
case typedate!
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
case typedatetime!
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
case else
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
end choose
i=i+1
end if
if sqlca.sqlcode<>0 then //ifuuuu
//没有数据
if Ll_row_cur=1 then
close my_curs;
closewithreturn(this,-1)
return
end if
//只有一条数据
if Ll_row_cur=2 then //if11
choose case ip_outtype
case typestring!
close my_curs;
closewithreturn(this,string(lf_field1))
case typeinteger!,typelong!
close my_curs;
closewithreturn(this,long(lf_field1))
case else
close my_curs;
closewithreturn(this,double(lf_field1))
end choose
return
end if //if11
// this.visible = true
IB_PAGE_END=TRUE
exit
end if //ifuuuu
if i=10 then
this.visible = true
return
end if
loop //while1
this.visible = true
do while i<=9
for j=1 to dispnum
dw_1.setitem(i,j,"")
next
setnull(lf_field1)
dw_1.setitem(i,'reval',lf_field1)
i=i+1
loop
还有一个structure
struct_call
///////////////////
$PBExportHeader$struct_call.srs
$PBExportComments$输入公用代码的调用结构
global type struct_call from structure
string displayfields
string sql
integer x
integer y
integer returnfield
string title
end type
上面保存为d_select
下面保存为w_select
/////////////////////////////////////////////////////////////
$PBExportHeader$w_select.srw
$PBExportComments$代码定位选择
forward
global type w_select from Window
end type
type dw_1 from datawindow within w_select
end type
end forward
shared variables
end variables
global type w_select from Window
int X=823
int Y=360
int Width=1189
int Height=880
boolean Visible=false
boolean TitleBar=true
string Title="选择代码"
long BackColor=79741120
WindowType WindowType=response!
event ue_after ( )
dw_1 dw_1
end type
global w_select w_select
type variables
parmtype ip_outtype
struct_call sele_info
integer dispnum
long il_page_nums, il_page_cur
boolean ib_page_end
DECLARE my_curs DYNAMIC CURSOR FOR SQLSA;
end variables
forward prototypes
public function boolean wf_show ()
end prototypes
event ue_after;integer i,ln_curx,ln_cury,ln_left,n,ln_len[10],ln_star,j, LL_ROW_CUR
any lf_field1
any lf_field[10]
string ls_title[10]
sele_info=message.powerobjectparm
//定义动态游标
PREPARE SQLSA FROM :sele_info.sql;
DESCRIBE SQLSA INTO SQLDA ;
OPEN DYNAMIC my_curs USING DESCRIPTOR SQLDA ;
//获取标题
dispnum=0
ln_star=1
if sele_info.title<>'' then
do while true
n=pos(sele_info.title,",",ln_star)
if n=0 then
exit
end if
dispnum=dispnum+1
ls_title[dispnum]=mid(sele_info.title,ln_star,n - ln_star)
ln_star=n+1
loop
dispnum=dispnum+1
ls_title[dispnum]=mid(sele_info.title,ln_star,len(sele_info.title) - ln_star+1)
end if
//debugbreak()
//获取显示数据
dispnum=0
ln_star=1
do while true
n=pos(sele_info.displayfields,",",ln_star)
if n=0 then
exit
end if
dispnum=dispnum+1
ln_len[dispnum]=integer(mid(sele_info.displayfields,ln_star,n - ln_star))
ln_star=n+1
loop
dispnum=dispnum+1
ln_len[dispnum]=integer(mid(sele_info.displayfields,ln_star,len(sele_info.displayfields) - ln_star+1))
//定义DW当前页
for i=1 to 9
dw_1.insertrow(0)
next
//总页数
il_page_nums=1
//当前页数
il_page_cur=1
//当前行数
Ll_row_cur=0
//全部读取标志
IB_PAGE_END=FALSE
i=1
do while true //while1
fetch my_curs using descriptor SQLDA;
Ll_row_cur=Ll_row_cur+1
if sqlca.sqlcode=0 then
//首次读取记录
if Ll_row_cur=1 then
ip_outtype=sqlda.outparmtype[sele_info.returnfield]
choose case ip_outtype
case typestring!
lf_field1=getdynamicstring(sqlda,sele_info.returnfield)
case typeinteger! ,typelong!
lf_field1=getdynamicnumber(sqlda,sele_info.returnfield)
case typedate!
lf_field1=GetDynamicDate(sqlda,sele_info.returnfield)
case typedatetime!
lf_field1=GetDynamicDatetime(sqlda,sele_info.returnfield)
case else
lf_field1=getdynamicnumber(sqlda,sele_info.returnfield)
end choose
//DATAWINDOW尺寸调整
if sele_info.title<>'' then
dw_1.object.datawindow.header.height=100
dw_1.height=dw_1.height+100
this.height=this.height+100
else
dw_1.object.datawindow.header.height=0
end if
dw_1.modify("field"+string(1)+".width="+string(ln_len[1]*38+100))
dw_1.modify("text"+string(1)+".text='"+ls_title[1]+"'")
dw_1.modify("text"+string(1)+".width="+string(ln_len[1]*38+100))
ln_left=120+ln_len[1]*38
for n=2 to dispnum
if sele_info.title<>'' then
dw_1.modify("text"+string(n)+".text='"+ls_title[n]+"'")
dw_1.modify("text"+string(n)+".x="+string(ln_left))
dw_1.modify("text"+string(n)+".width="+string(ln_len[n]*38))
end if
dw_1.modify("field"+string(n)+".x="+string(ln_left))
dw_1.modify("field"+string(n)+".width="+string(ln_len[n]*38))
ln_left=ln_left+ln_len[n]*38+60
next
//DATAWINDOW及窗体定位
dw_1.width=ln_left
this.width=ln_left+75
// if ln_curx+this.width>PixelsToUnits(env.ScreenWidth, XPixelsToUnits!) then
//// ln_curx=ln_curx - this.width - 200
// ln_curx=sele_info.x
// end if
// if ln_cury+this.height>PixelsToUnits(env.ScreenHeight, YPixelsToUnits!) then
//// ln_cury=ln_cury - this.height - 100
// ln_cury=sele_info.y
// end if
this.move(sele_info.x,sele_info.y)
end if
//读取当前数据
for n=1 to sqlda.numoutputs
choose case sqlda.outparmtype[n]
case typestring!
lf_field[n]=getdynamicstring(sqlda,n)
case typeinteger!
lf_field[n]=getdynamicnumber(sqlda,n)
case typedate!
lf_field[n]=GetDynamicDate(sqlda,n)
case typedatetime!
lf_field[n]=GetDynamicDatetime(sqlda,n)
case else
lf_field[n]=getdynamicnumber(sqlda,n)
end choose
next
//设置DATAWINDOW
dw_1.setitem(i,1,STRING(I)+": "+string(lf_field[1]))
for j=2 to dispnum
dw_1.setitem(i,j,string(lf_field[j]))
next
choose case ip_outtype
case typestring!
dw_1.setitem(i,'reval',lf_field[sele_info.returnfield])
case typeinteger!,typelong!
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
case typedate!
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
case typedatetime!
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
case else
dw_1.setitem(i,'reval',string(lf_field[sele_info.returnfield]))
end choose
i=i+1
end if
if sqlca.sqlcode<>0 then //ifuuuu
//没有数据
if Ll_row_cur=1 then
close my_curs;
closewithreturn(this,-1)
return
end if
//只有一条数据
if Ll_row_cur=2 then //if11
choose case ip_outtype
case typestring!
close my_curs;
closewithreturn(this,string(lf_field1))
case typeinteger!,typelong!
close my_curs;
closewithreturn(this,long(lf_field1))
case else
close my_curs;
closewithreturn(this,double(lf_field1))
end choose
return
end if //if11
// this.visible = true
IB_PAGE_END=TRUE
exit
end if //ifuuuu
if i=10 then
this.visible = true
return
end if
loop //while1
this.visible = true
do while i<=9
for j=1 to dispnum
dw_1.setitem(i,j,"")
next
setnull(lf_field1)
dw_1.setitem(i,'reval',lf_field1)
i=i+1
loop
end event
public function boolean wf_show ();integer i,j,n
any lf_field[10]
if ib_page_end then return true
if il_page_nums=1 then
fetch my_curs using descriptor SQLDA;
end if
//判断是否可继续翻屏
if sqlca.sqlcode<>0 then
ib_page_end=true
return false
end if
for i=1 to 9
dw_1.insertrow(0)
next
i=1
do while i<=9 and sqlca.sqlcode=0 //while1
for n=1 to sqlda.numoutputs //for1
choose case sqlda.outparmtype[n]
case typestring!
lf_field[n]=getdynamicstring(sqlda,n)
case typeinteger!
lf_field[n]=getdynamicnumber(sqlda,n)
case typedate!
lf_field[n]=GetDynamicDate(sqlda,n)
case typedatetime!
lf_field[n]=GetDynamicDatetime(sqlda,n)
case else
lf_field[n]=getdynamicnumber(sqlda,n)
end choose
next //for1
dw_1.setitem(i+9*il_page_nums,1,STRING(I)+": "+string(lf_field[1]))
for j=2 to dispnum
dw_1.setitem(i+9*il_page_nums,j,string(lf_field[j]))
next
choose case ip_outtype
case typestring!
dw_1.setitem(i+9*il_page_nums,'reval',lf_field[sele_info.returnfield])
case typeinteger!
dw_1.setitem(i+9*il_page_nums,'reval',string(lf_field[sele_info.returnfield]))
case typedate!
dw_1.setitem(i+9*il_page_nums,'reval',string(lf_field[sele_info.returnfield]))
case typedatetime!
dw_1.setitem(i+9*il_page_nums,'reval',string(lf_field[sele_info.returnfield]))
case else
dw_1.setitem(i+9*il_page_nums,'reval',string(lf_field[sele_info.returnfield]))
end choose
i=i+1
fetch my_curs using descriptor SQLDA;
loop //while1
do while i<=9 //while2
ib_page_end=true
for j=1 to dispnum
dw_1.setitem(i+9*il_page_nums,j,"")
next
setnull(lf_field[10])
dw_1.setitem(i+9*il_page_nums,'reval',lf_field[10])
i=i+1
loop //while2
//总页数累加
il_page_nums=il_page_nums + 1
//当前页调整
il_page_cur=il_page_nums
return true
end function
on w_select.create
this.dw_1=create dw_1
this.Control[]={this.dw_1}
end on
type dw_1 from datawindow within w_select
event key pbm_dwnkey
int X=23
int Y=28
int Width=1129
int Height=736
int TabOrder=10
string DataObject="d_select"
end type
event key;integer ln_sele,i,j
string ls_temp
if keydown(KeyDownArrow!) or keydown(keyupArrow!) then
ls_temp = left(this.object.field1[this.getrow()],1)
if key = KeyDownArrow! and (ls_temp = '9' or ls_temp='') then return 1
if key = keyupArrow! and ls_temp = '1' then return 1
return 0
end if
ln_sele=0
if keydown(keyEscape!) then
close my_curs;
login.esc = true
closewithreturn(parent,-1)
return 1
end if
if keydown(keyPageup!) then
if il_page_cur>1 then
il_page_cur=il_page_cur - 1
return 0
else
return 1
end if
end if
if keydown(keypagedown!) then
if il_page_cur=il_page_nums then
if ib_page_end then
return 1
else
if wf_show() then
return 0
else
return 1
end if
end if
else
il_page_cur=il_page_cur+1
return 0
end if
end if
if keydown(key1!) or keydown(KeyNumpad1!) then
ln_sele=1
end if
if keydown(key2!) or keydown(KeyNumpad2!) then
ln_sele=2
end if
if keydown(key3!) or keydown(KeyNumpad3!) then
ln_sele=3
end if
if keydown(key4!) or keydown(KeyNumpad4!) then
ln_sele=4
end if
if keydown(key5!) or keydown(KeyNumpad5!) then
ln_sele=5
end if
if keydown(key6!) or keydown(KeyNumpad6!) then
ln_sele=6
end if
if keydown(key7!) or keydown(KeyNumpad7!) then
ln_sele=7
end if
if keydown(key8!) or keydown(KeyNumpad8!) then
ln_sele=8
end if
if keydown(key9!) or keydown(KeyNumpad9!) then
ln_sele=9
end if
if keydown(keyenter!) then //if1
ls_temp=dw_1.getitemstring(dw_1.getrow(),'reval')
elseif ln_sele <>0 then
ls_temp=dw_1.getitemstring(ln_sele+9*(il_page_cur - 1),'reval')
else
return 1
end if
if not isnull(ls_temp) then
close my_curs;
choose case ip_outtype
case typestring!
closewithreturn(parent,ls_temp)
case typeinteger!
closewithreturn(parent,integer(ls_temp))
case typedate!
closewithreturn(parent,ls_temp)
case typedatetime!
closewithreturn(parent,ls_temp)
case typelong!
closewithreturn(parent,long(ls_temp))
case else
closewithreturn(parent,double(ls_temp))
end choose
RETURN
end if
return 1
end event
event clicked;string ls_temp
integer ln_sele
ln_sele=this.getclickedrow()
if ln_sele<>0 then
ls_temp=dw_1.getitemstring(ln_sele,'reval')
if not isnull(ls_temp) then
close my_curs;
choose case ip_outtype
case typestring!
closewithreturn(parent,ls_temp)
case typeinteger!
closewithreturn(parent,integer(ls_temp))
case typedate!
closewithreturn(parent,ls_temp)
case typedatetime!
closewithreturn(parent,ls_temp)
case typelong!
closewithreturn(parent,long(ls_temp))
case else
closewithreturn(parent,double(ls_temp))
end choose
RETURN
end if
end if
end event
event rowfocuschanged;this.scrolltorow(currentrow)
this.selectrow(0,false)
this.selectrow(currentrow,true)
end event