动态生成数据窗口的一个例子
//2001-9-25 增加可以更新数据的功能
//2001-9-10按所选列查找表的内容
//采用动态生成数据窗口的方法,生成Gride风格
if lb_colunm.SelectedIndex() < 1 then
return
end if
string ls_SqlSyntax,ls_realse,ls_dw,ls_Header,ls_summary,ls_footer,ls_detail,ls_Table
string ls_Other
string ls_Col_Comments//列注释
string ls_tab_Comments//表注释
//string ls_Table
ls_Table =ms_User+"."+ ms_Table
string ls_Rtn = char(13)+char(10)
ls_Realse = "release 8;" + ls_Rtn
ls_dw = "datawindow(units=0 timer_interval=0 color=12632256 processing=1 print.documentname='' print.orientation=0 print.margin.left=110 print.margin.right=110 print.margin.top=96 print.margin.bottom=96 print.paper.size=0 print.paper.source=0 grid.lines=0 selected.mouse=no)"+ls_Rtn
ls_Header = "header(height=80 color=~"536870912~" )" + ls_Rtn
ls_Summary = "summary(height=0 color=~"536870912~" )" + ls_Rtn
ls_footer = "footer(height=0 color=~"536870912~" )" + ls_Rtn
ls_detail = "detail(height=92 color=~"536870912~" height.autosize=yes)" + ls_Rtn
//生成数据窗口的主体
int i
string ls_Column1,ls_Retrieve,ls_text,ls_Column2
string ls_Dbname
long ln_X = 9,ln_y = 8 ,ln_id = 1 ,ln_Width=120
ls_Column1 = "table("
ls_Retrieve = " retrieve= ~"select -1 as n_Order "+ls_Rtn
//增加一个顺序号
string str,ls_ColumnName,ls_Type,ls_Length,ls_Precision
ls_Column1 = ls_Column1 + " column=(type=number updatewhereclause=yes name=n_order dbname=~""+ls_Table+".n_order~" )" +ls_Rtn
ls_Text = ls_Text + "text(name= n_Order_t band=header font.charset=~"0~" font.face=~"宋体~" font.family=~"2~" font.height=~"-10~" font.pitch=~"2~" font.weight=~"400~" background.mode=~"1~" background.color=~"536870912~" color=~"0~" alignment=~"2~" border=~"6~" x=~""+string(ln_X)+"~" y=~""+string(ln_y)+"~" height=~"64~" width=~""+string(ln_Width)+"~" text=~"顺序~" )"+ls_Rtn
ls_Column2 = ls_Column2 +"column(name=n_order height.autosize=yes band=detail id= "+string(ln_id)+"x=~""+string(ln_X)+"~" y=~""+string(ln_y)+"~" height=~"76~" width=~""+string(ln_Width)+"~" color=~"0~" border=~"0~" alignment=~"2~" format=~"[general]~" edit.focusrectangle=no edit.autohscroll=no edit.autoselect=no edit.autovscroll=no edit.case=any edit.codetable=no edit.displayonly=no edit.hscrollbar=no edit.imemode=0 edit.limit=0 edit.password=no edit.vscrollbar=no edit.validatecode=no edit.nilisnull=no edit.required=no criteria.required=no criteria.override_edit=no crosstab.repeat=no background.mode=~"1~" background.color=~"536870912~" font.charset=~"0~" font.face=~"宋体~" font.family=~"2~" font.height=~"-10~" font.pitch=~"2~" font.weight=~"400~" tabsequence=0 )"+ls_Rtn
for i =1 to lb_colunm.TotalItems()
if lb_colunm.State(i) = 1 then //it is hilighted
str = lb_colunm.Text(i)
ls_ColumnName = left(str,pos(str,' ') -1 )
//获得数剧列的类型和长度
select DATA_TYPE,
to_Char(DATA_LENGTH),
to_Char(DATA_divCISION)
into :ls_Type,:ls_Length,:ls_Precision
from dba_tab_columns
where trim(table_name) = :ms_table
and trim(owner) = :ms_User
and trim(COLUMN_NAME) = :ls_ColumnName;
if sqlca.sqlCode = -1 then
MessageBox("数据库错误 select DATA_TYPE, ...",sqlca.sqlErrText)
goto wrong
end if
//获得数剧列的注释
select trim(COMMENTS)
into :ls_col_Comments
from dba_col_Comments
where trim(table_name) = :ms_table
and trim(owner) = :ms_User
and trim(COLUMN_NAME) = :ls_ColumnName;
if sqlca.sqlCode = -1 then
MessageBox("数据库错误 select trim(COMMENTS) ...",sqlca.sqlErrText)
goto wrong
end if
//将数据类型处理成pb的数据类型,只支持数字、字符和日期类型
ls_Type = trim(ls_Type)
if ls_Type = "LONG" then
ls_Length = "32769"//to such type , pb treat its length as 32769 2001-9-26
end if
if ls_Type = "VARCHAR" OR ls_Type = "VARCHAR2" or ls_Type = "CHAR" or ls_Type = "LONG" then
ls_Type = "char"
elseif ls_Type = "NUMBER" OR ls_Type = "FLOAT" then //FLOAT 类型先处理NUMBER型
ls_Type = "decimal"
elseif ls_Type = "DATE" then
ls_Type = "datetime"
else
continue ;//其它类型不处理
end if
ls_Column1 = ls_Column1 + "column=(type="+ls_Type
if not isNull(ls_Length) and ls_Type <> "datetime"then
ls_Column1 = ls_Column1 + "("+ls_Length+")"
end if
//坐标调整
ln_X = ln_x + ln_Width +4
//id调整
ln_id ++
//显示宽度调整,根据注释
if isNUll(ls_Col_Comments) then
ls_Col_Comments = ls_ColumnName
end if
ln_Width = 36*len(trim(ls_Col_Comments))
ls_Column1 = ls_Column1 +" update=yes updatewhereclause=yes key=yes name="+ls_ColumnName+" dbname= ~""+ls_Table+"."+ls_ColumnName+"~" )"+ls_Rtn
ls_Retrieve = ls_Retrieve +","+ ls_Table + "." + ls_ColumnName + ls_Rtn
ls_Text = ls_Text + "text(name="+ls_ColumnName+"_t band=header font.charset=~"0~" font.face=~"宋体~" font.family=~"2~" font.height=~"-10~" font.pitch=~"2~" font.weight=~"400~" background.mode=~"1~" background.color=~"536870912~" color=~"0~" alignment=~"2~" border=~"6~" x=~""+string(ln_X)+"~" y=~""+string(ln_y)+"~" height=~"64~" width=~""+string(ln_Width)+"~" text=~"&