求教高手,如何动态外部创建数据窗口???

twofish 2003-01-09 01:51:54
加精
求教高手,如何动态外部创建数据窗口???
...全文
91 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
twofish 2003-01-09
  • 打赏
  • 举报
回复
使用技术:1)数据窗口动态生成 2)外部(External)数据窗口
myclife 2003-01-09
  • 打赏
  • 举报
回复
global type f_createextenddw from function_object
end type

forward prototypes
global function string f_createextenddw (ref datawindow dw, string cols[])
end prototypes

global function string f_createextenddw (ref datawindow dw, string cols[]);string sql_dw_general, sql_dw_columns_type, sql_dw_headers_conf, sql_dw_columns_conf, ls_errors
int i
long ll_colcount
string ls_colnametype
string ls_colname,ls_coltype
long ll_pos

ll_colcount = upperbound(cols)

//generals
sql_dw_general = "release 8;" &
+ "datawindow(units=0 timer_interval=0 color=16777215 processing=0 print.documentname=" + char(34) + "" + char(34) + " print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no )" &
+ "header(height=72 color=" + char(34) + "536870912" + char(34) + " )" &
+ "summary(height=0 color=" + char(34) + "536870912" + char(34) + " )" &
+ "footer(height=0 color=" + char(34) + "536870912" + char(34) + " )" &
+ "detail(height=84 color=" + char(34) + "536870912" + char(34) + " )"


//列及类型
sql_dw_columns_type = "table("
FOR I=1 to ll_colcount
ls_colnametype = trim(cols[i])
ls_colname = right(ls_colnametype,len(ls_colnametype) - 1)
ls_coltype = left(ls_colnametype,1)
choose case upper(ls_coltype)
case 'C'
ls_coltype = 'char(100)'
case 'D'
ls_coltype = 'date'
case 'N'
ls_coltype = 'decimal(6)'
case else
ls_coltype = 'char(100)'
end choose
//ls_coltype = 'char(100)'
//列及类型
sql_dw_columns_type= sql_dw_columns_type + "column=(type=" +ls_coltype+" updatewhereclause=no name=" + ls_colname + " dbname=" + char(34) + ls_colname + char(34) + " ) "

//列标题
sql_dw_headers_conf = sql_dw_headers_conf + "text(band=header alignment=" + char(34) + "2" + char(34) + " text=" + char(34) + ls_colname + char(34) + " border=" + char(34) + "6" + char(34) + " color=" + char(34) + "16711680" + char(34) + " x=" + char(34) + string( ((i - 1) * 588) + 5) + char(34) + " y=" + char(34) + "4" + char(34) + " height=" + char(34) + "64" + char(34) + " width=" + char(34) + "574" + char(34) + " name=" + ls_colname + "_t font.face=" + char(34) + "Arial" + char(34) + " font.height=" + char(34) + "-10" + char(34) + " font.weight=" + char(34) + "400" + char(34) + " font.family=" + char(34) + "2" + char(34) + " font.pitch=" + char(34) + "2" + char(34) + " font.charset=" + char(34) + "0" + char(34) + " background.mode=" + char(34) + "2" + char(34) + " background.color=" + char(34) + "12632256" + char(34) + " )"

//列属性
sql_dw_columns_conf = sql_dw_columns_conf + "column(band=detail id=" + string(i) + " alignment=" + char(34) + "1" + char(34) + " tabsequence=" + string(i) + "0 border=" + char(34) + "2" + char(34) + " color=" + char(34) + "0" + char(34) + " x=" + char(34) + string( ((i - 1) * 588) + 5) + char(34) + " y=" + char(34) + "4" + char(34) + " height=" + char(34) + "76" + char(34) + " width=" + char(34) + "579" + char(34) + " format=" + char(34) + "[general]" + char(34) + " name=" + ls_colname + " edit.limit=0 edit.case=any edit.autoselect=yes edit.autohscroll=yes font.face=" + char(34) + "Arial" + char(34) + " font.height=" + char(34) + "-10" + char(34) + " font.weight=" + char(34) + "400" + char(34) + " font.family=" + char(34) + "2" + char(34) + " font.pitch=" + char(34) + "2" + char(34) + " font.charset=" + char(34) + "0" + char(34) + " background.mode=" + char(34) + "1" + char(34) + " background.color=" + char(34) + "536870912" + char(34) + " )"

NEXT

sql_dw_columns_type= sql_dw_columns_type + " )"

sql_dw_columns_conf = sql_dw_columns_conf + "htmltable(border=" + char(34) + "1" + char(34) + " cellpadding=" + char(34) + "0" + char(34) + " cellspacing=" + char(34) + "0" + char(34) + " generatecss=" + char(34) + "no" + char(34) + " nowrap=" + char(34) + "yes" + char(34) + ")"

//MESSAGEBOX('',sql_dw_general + sql_dw_columns_type + sql_dw_headers_conf + sql_dw_columns_conf)
dw.Create(sql_dw_general + sql_dw_columns_type + sql_dw_headers_conf + sql_dw_columns_conf , ls_errors)

return(ls_errors)
end function

twofish 2003-01-09
  • 打赏
  • 举报
回复
谢谢楼上的回答,其实我想问的是如何动态创建外部(External)数据窗口
pearl2002 2003-01-09
  • 打赏
  • 举报
回复
动态数据窗创建原理及实现

在实际应用中,经常需要根据用户需求来动态创建数据窗,一般方法是这样的。

在一个window中加入一个数据窗控件,如dw_new,但是该数据窗没有data object,(空白的)
就可以用以下语法来创建:
dw_new.create(ls_syntax,ls_error) // 创建语法,错误信息
ls_syntax可以用以下三种方法来形成:

一、动态由sql语法创建:

// 连接到pb的example数据库
string ls_sql,ls_syntax,ls_error
ls_syntax = 'select * from department'
ls_syntax = sqlca.SyntaxFromSQL(ls_sql,'style(type=grid)',ls_error)
if len(ls_error) >0 then
messagebox('Error','SyntaxFromSQL Error:~r'+ls_error)
else
dw_new.create(ls_syntax,ls_error)
if len(ls_error) >0 then
MessageBox("Error", "Create have these errors: ~r" + ls_error)
else
dw_new.settransobject(sqlca)
dw_new.retrieve()
end if
end if

二、由另一个数据窗的syntax来创建

string ls_syntax,ls_error
ls_syntax = dw_test.describe('datawindow.syntax')
dw_new.create(ls_syntax,ls_error)
if ls_error <> '' then
messagebox('Create Error',ls_error)
else
dw_new.settransobject(sqlca)
dw_new.retrieve()
end if

三、读取psr文件来创建

样例
string ls_syntax,ls_error,ls_ret
ls_ret = char(13)+char(10) //回车键
int li_fileNum
long li_length
li_FileNum = FileOpen("efef.psr",Streammode!, read!, shared!, Replace!)

// 以下是pb5的代码
if li_filenum >0 then
FileSeek(li_FileNum, 158, FromBeginning!)
li_length = fileRead(li_filenum,ls_syntax)
end if
fileclose(li_filenum)
if li_length = 0 then return
ls_syntax = "release 5;"+ls_ret+ls_syntax

//截掉ls_syntax中的数据部分,5.0以"sparse(names="dept_name?) "作为参考位置
//6.0以html(作为参考位置

long pos1,pos2
pos1 = pos(ls_syntax,'sparse(names="',1)
pos2 = pos(ls_syntax,'"',pos1 +16)
ls_syntax = left(ls_syntax,pos1) + mid(ls_syntax,pos1 +1,pos2 - pos1 +1)

dw_New.create(ls_syntax,ls_error)

if ls_error <> '' then
messagebox('Create Error',ls_error)
else
dw_new.settransobject(sqlca)
dw_new.retrieve()
end if

//pb6,pb7的代码可以参照pb5自己写,只是文件头和数据窗结束标记不同而已。


shahand 2003-01-09
  • 打赏
  • 举报
回复
dw_1.create()
可以参考帮助 以及 srd文件(数据窗口导出文件)
pearl2002 2003-01-09
  • 打赏
  • 举报
回复
首先制作一个自己想动态得到的数据窗口,然后将该数据窗口导出,看看语法,这样你就了解了这种数据窗口的生成语法了!

611

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder DataWindow
社区管理员
  • DataWindow社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧