怎样利用PowerBulider的Datawindow建立中国式的动态报表

发表于:2007-07-02来源:作者:点击数: 标签:
世界上所有的报表,要算中国的报表最为复杂了。看老外的报表表头很简单都是只有一行差不多。但是中国人的表头一般都有好几层,给你来上个两层已经是很不错的一件事情了。另外中国人最喜欢的就是活动式的表头,意思就是今年是这种的明年可能要变成另外一种格

世界上所有的报表,要算中国的报表最为复杂了。看老外的报表表头很简单都是只有一行差不多。但是中国人的表头一般都有好几层,给你来上个两层已经是很不错的一件事情了。另外中国人最喜欢的就是活动式的表头,意思就是今年是这种的明年可能要变成另外一种格式了。所以这也对编写表头程序的程序员来讲提出了一个难题。我们也知道PowerBuilder的datawindow有强大的检索功能,而且Powerbuilder 就是一个数据库前端开发工具,但是初学者都认为,它只能作为静态的报表,其实它背后隐藏着更大的功能,datawindow也能制作动态的报表类型。
下面的一段程序是我以前在做项目的时候运用的,希望能给各位带来一个提示
string ls_part1,ls_aux1,ls_aux2,is_temp,ls_syntax
ulong ai_x1=0,ai_x2=0,ai_y1=0,ai_y2=88,ai_style=0,ai_width=0,ai_linecolor=1,h_y1,h_y2
ulong cil_posx,cil_width,temp_x,temp_y,temp_cil
integer char_w,i=1,font=19
ulong  f1=0,f2=0,f3=0,save_i1,save_i2
ulong col_table_len=0,as_old1,as_old2,col_len2=0,col_len3=0
string as_syntax,as_table
ulong y0,y1,y2,y3,y4,id=0
string as_name,as_unit,as_column
string as_head1,as_head2,as_head3,as_head4,as_head5,as_date
ulong height

//char_w=margin.paper_size*1000/margin.font_size
//char_w=1500/margin.font_size*10
//char_w=1500/100*10
char_w=1
of_profilestring_margin()
//margin.top=250
//margin.bottom=250
//margin.right=250
//margin.left=250
//margin.head=4330
//margin.detail=730
//margin.footer=100
//margin.title=2000
//margin.paper_size=35.4
//margin.font_size=30
y0=margin.title
y1=y0+(margin.head -y0)/4
y2=y0+2*(margin.head -y0)/4
y3=y0+3*(margin.head -y0)/4
y4=margin.head
height=y1 -y0

as_table=@#release 8;~r~n@#+&
        @#datawindow(units=3 timer_interval=0 color=1073741824 processing=0 print.margin.bottom=@#+string(margin.bottom)+&
    @# print.margin.left=@#+string(margin.left)+@# print.margin.right=@#+string(margin.right)+@# print.margin.top=@#+string(margin.top)+&
    @# print.preview.buttons=no ) header(height=@#+string(margin.head)+@#) detail(height=@#+string(margin.detail)+&
    @#) footer(height=@#+string(margin.footer)+@#)  table()@#
do while table[i].name<>"\0"
 as_name=table[i].name   
 as_unit=table[i].unit 
   cil_width=table[i].len*char_w    
 as_column="column_"+string(id)   
 as_head1="h1_"+string(id) 
 as_head2="h2_"+string(id) 
 as_head3="h3_"+string(id) 
 as_head4="h4_"+string(id) 
 as_head5="h11_"+string(id)//Ö»ÓÐÒ»²ãµÄ¿ÆĿͬÆäËû¿ÆÄ¿Çø·Ö£¬ÕâÑù¶Ô×ÖÌåµÄ±ä»¯ÓкܴóºÃ´¦
 choose case table[i].layer
  case  "1"
   if table[i].unit="" then
    if f1=0 then
     save_i1=i
     f1=1
     table[i].x=col_table_len
    else
     temp_x=table[save_i1].x
               temp_cil=col_table_len -table[save_i1].x
     if table[save_i1].len*char_w>=temp_cil  then
        temp_cil=table[save_i1].len*char_w
      col_table_len=table[save_i1].x+temp_cil
       end if
     ls_aux1=uf_text("header",table[save_i1].name,as_head1,temp_x,y0,height ,temp_cil)
       as_syntax+=ls_aux1 
     //µÚÒ»²ãÓëµÚ¶þ²ãÖ®¼äµÄÁ¬Ïß
     AI_x1=temp_x
       AI_x2=col_table_len
       h_Y1=y1
       h_Y2=y1
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
     
     AI_x1=col_table_len
       AI_x2=col_table_len
       h_Y1=y0
       h_Y2=y4
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1      
     h_Y1=0
       h_Y2=margin.detail
       ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
     col_len2=0    
     save_i1=i
     f1=1
     table[i].x=col_table_len
    end if
   else //Ö»ÓÐÒ»²ãµÄ¿ÆÄ¿
    if f1=1 then     
     temp_x=table[save_i1].x
               temp_cil=col_table_len -table[save_i1].x
     if table[save_i1].len*char_w>=temp_cil  then
        temp_cil=table[save_i1].len*char_w
      col_table_len=table[save_i1].x+temp_cil
       end if
     ls_aux1=uf_text("header",table[save_i1].name,as_head1,temp_x,y0,height,temp_cil)
       as_syntax+=ls_aux1
     //µÚÒ»²ãÓëµÚ¶þ²ãÖ®¼äµÄÁ¬Ïß
     AI_x1=temp_x
       AI_x2=col_table_len
       h_Y1=y1
       h_Y2=y1
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
     
     f1=0  
     AI_x1=col_table_len
       AI_x2=col_table_len
       h_Y1=y0
       h_Y2=y4
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
       h_Y1=0
       h_Y2=margin.detail
       ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
    end if
    id ++
    as_table=uf_tablecolumn(as_table,as_column)
    ls_aux1=uf_detailcolumn(as_column,id,col_table_len,margin.detail/4,margin.detail,cil_width,font)
    as_syntax+=ls_aux1 
    temp_y=(y3+y0)/2
      ls_aux1=uf_text("header",table[i].name,as_head5,col_table_len,temp_y,height,cil_width)
    as_syntax+=ls_aux1
    ls_aux1=uf_text("header",table[i].unit,as_head4,col_table_len,y3,height,cil_width)
    as_syntax+=ls_aux1
    col_table_len+=cil_width
    AI_x1=col_table_len
    AI_x2=col_table_len
    h_Y1=y0
    h_Y2=y4
    ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
    as_syntax+=ls_aux1
    h_Y1=0
    h_Y2=margin.detail
    ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
    as_syntax+=ls_aux1    
   end if  
  case  "2"
   if table[i].unit="" then //´æÔÚµÚÈý²ã
    if f2=0 then
     save_i2=i
     f2=1
     table[i].x=col_table_len
    else //ͬʱ°ÑÉϴμǼµÄµÚ¶þ²ã
     temp_x=table[save_i2].x
     temp_cil=col_table_len -table[save_i2].x
     if table[save_i2].len*char_w>=temp_cil  then
        temp_cil=table[save_i2].len*char_w
      col_table_len=table[save_i2].x+temp_cil
       end if
     ls_aux1=uf_text("header",table[save_i2].name,as_head2,temp_x,y1,height,temp_cil)
       as_syntax+=ls_aux1
     AI_x1=col_table_len
       AI_x2=col_table_len
       h_Y1=y1
       h_Y2=y2
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
     //µÚ¶þ²ãÓëµÚÈý²ãÖ®¼äµÄÁ¬Ïß
     AI_x1=temp_x
       AI_x2=col_table_len
       h_Y1=y2
       h_Y2=y2
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1     
     col_len3=0 
     save_i2=i
     f2=1
     table[i].x=col_table_len
      end if
    f3=1
   else    //ûÓеÚÈý²ã
    if f2=1 then
     temp_x=table[save_i2].x
               temp_cil=col_table_len -table[save_i2].x
     if table[save_i2].len*char_w>=temp_cil  then
        temp_cil=table[save_i2].len*char_w
      col_table_len=table[save_i2].x+temp_cil
       end if
     ls_aux1=uf_text("header",table[save_i2].name,as_head2,temp_x,y1,height,temp_cil) 
     as_syntax+=ls_aux1
     AI_x1=col_table_len
       AI_x2=col_table_len
       h_Y1=y1
       h_Y2=y2
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
     //µÚ¶þ²ãÓëµÚÈý²ãÖ®¼äµÄÁ¬Ïß
     AI_x1=temp_x
       AI_x2=col_table_len
       h_Y1=y2
       h_Y2=y2
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1     
     f2=0 
    end if    
       id ++
       as_table=uf_tablecolumn(as_table,as_column)
               ls_aux1=uf_detailcolumn(as_column,id,col_table_len,margin.detail/4,margin.detail,cil_width,font)
       as_syntax+=ls_aux1         
       temp_y=(y1+y2)/2
         ls_aux1=uf_text("header",table[i].name,as_head2,col_table_len,temp_y,height,cil_width)
       as_syntax+=ls_aux1
       ls_aux1=uf_text("header",table[i].unit,as_head4,col_table_len,y3,height,cil_width)
       as_syntax+=ls_aux1
       AI_x1=col_table_len
       AI_x2=col_table_len
       h_Y1=y1
       h_Y2=y4
       ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
       as_syntax+=ls_aux1
       h_Y1=0
       h_Y2=margin.detail
     ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
     as_syntax+=ls_aux1 
     col_table_len+=cil_width  
      end if         
  case  "3" 
      id ++
      as_table=uf_tablecolumn(as_table,as_column)
            ls_aux1=uf_detailcolumn(as_column,id,col_table_len,margin.detail/4,margin.detail,cil_width,font)
    as_syntax+=ls_aux1 
      ls_aux1=uf_text("header",table[i].name,as_head3,col_table_len,y2,height ,cil_width)
    as_syntax+=ls_aux1
    ls_aux1=uf_text("header",table[i].unit,as_head4,col_table_len,y3,height ,cil_width)
    as_syntax+=ls_aux1
    AI_x1=col_table_len
    AI_x2=col_table_len
    //¿ÉÄÜÔÚµÚÈý²ãÖÐÒ»¿ªÊ¼¾ÍÓйÂÁ¢µÄ¶þ¼¶¿ÆÄ¿Òò´ËÓ¦¸Ã´Óy1->y4
    if f3=1 then
       h_Y1=y1
       h_Y2=y4
     f3=0
    else//¿ÉÄÜÔÚµÚÈý²ãÖÐÒ»¿ªÊ¼²»ÊǹÂÁ¢µÄ¶þ¼¶¿ÆÄ¿Òò´ËÓ¦¸Ã´Óy2->y4
     h_Y1=y2
       h_Y2=y4
    end if
    ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
    as_syntax+=ls_aux1
    h_Y1=0
    h_Y2=margin.detail
    ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
    as_syntax+=ls_aux1 
    col_len3=1
    col_table_len+=cil_width  
 end choose
 i ++
loop
if f1=1 then
temp_x=table[save_i1].x
temp_cil=col_table_len -table[save_i1].x
if table[save_i1].len*char_w>=temp_cil  then
 temp_cil=table[save_i1].len*char_w
 col_table_len=table[save_i1].x+temp_cil
end if
ls_aux1=uf_text("header",table[save_i1].name,as_head1,temp_x,y0,height,temp_cil)
as_syntax+=ls_aux1 
id ++
//µÚÒ»²ãÓëµÚ¶þ²ãÖ®¼äµÄÁ¬Ïß
AI_x1=temp_x
AI_x2=col_table_len
h_Y1=y1
h_Y2=y1
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
end if
if f2=1 then
temp_x=table[save_i2].x
temp_cil=col_table_len -table[save_i2].x
if table[save_i2].len*char_w>=temp_cil  then
 temp_cil=table[save_i2].len*char_w
 col_table_len=table[save_i2].x+temp_cil
end if
ls_aux1=uf_text("header",table[save_i2].name,as_head1,temp_x,y1,height,temp_cil)
as_syntax+=ls_aux1
//µÚ¶þ²ãÓëµÚÈý²ãÖ®¼äµÄÁ¬Ïß
AI_x1=temp_x
AI_x2=col_table_len
h_Y1=y2
h_Y2=y2
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y1,0,0,1)
as_syntax+=ls_aux1
end if

//±í¸ñµÄ×î×ó¶ËµÄheaderÖ±Ïß
id ++
AI_x1=0
AI_x2=0
h_Y1=y0
h_Y2=y4
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
//±í¸ñµÄ×î×ó¶ËµÄdetailÖ±Ïß
id ++
AI_x1=0
AI_x2=0
h_Y1=0
//h_Y2=margin.detail -3
ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
//±í¸ñµÄ×îÓҶ˵ÄheaderÖ±Ïß
id ++
AI_x1=col_table_len
AI_x2=col_table_len
h_Y1=y0
h_Y2=y4
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
//±í¸ñµÄ×îÓҶ˵ÄdetailÖ±Ïß
id ++
AI_x1=col_table_len
AI_x2=col_table_len
h_Y1=0
//h_Y2=margin.detail -3
ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
//±í¸ñµÄ×îÉ϶˵ÄheaderÖ±Ïß
id ++
AI_x1=0
AI_x2=col_table_len
h_Y1=y0
h_Y2=y0
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
//±í¸ñµÄµÚÈý²ãÓ뵥λ֮¼äµÄheaderÖ±Ïß
id ++
h_Y1=y3
h_Y2=y3
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1

//±í¸ñÔÚheaderÇøÓòÖÐ×îµ×²¿µÄÖ±Ïß
h_Y1=y4 -50
h_Y2=y4 -50
ls_aux1=uf_lineh(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1

//±í¸ñµÄÔÚdetailÇøÓò×îµ×²¿µÄÖ±Ïß
id ++
h_Y1=margin.detail  -50
h_Y2=margin.detail  -50
ls_aux1=uf_lined(id,Ai_x1,h_y1,Ai_x2,h_y2,0,0,1)
as_syntax+=ls_aux1
/*

id ++
h_Y1=margin.detail  -10
h_Y2=margin.detail  -10
ls_aux1=uf_lined(id,ai_x1,20,ai_x2,20,0,0,1)
as_syntax+=ls_aux1
*/
//ÒÔÏÂÊÇ´¦Àí±í¸ñµÄ±êÌâ¼°Æäҳü¡¢Ò³½Å

//cil_width=len("Õã½­Ê¡Å©ÌïË®Àûͳ¼Æ±í")*char_w
cil_width=col_table_len
ls_aux1=uf_title_text("header",title,(col_table_len -cil_width )/2,y0/8,height,cil_width,-20,2)
as_syntax+=ls_aux1
string startday,deadday,startmonth,deadmonth
if day(startdate)<10 then
 startday="0"+string(day(startdate))
else
 startday=string(day(startdate))
end if
if day(deadline)<10 then
 deadday="0"+string(day(deadline))
else
 deadday=string(day(deadline))
end if

if month(startdate)<10 then
 startmonth="0"+string(month(startdate))
else
 startmonth=string(month(startdate))
end if
if month(deadline)<10 then
 deadmonth="0"+string(month(deadline))
else
 deadmonth=string(month(deadline))
end if

as_date=string(year(startdate))+"-"+startmonth+"-"+startday+"ÖÁ"+&
        string(year(deadline))+"-"+deadmonth+"-"+deadday   

cil_width=len(as_date)*char_W
cil_width=col_table_len
ls_aux1=uf_title_text("header",as_date,(col_table_len -cil_width )/2,y0/2,height,cil_width,-12,2)
as_syntax+=ls_aux1

 

//¸±±êÌâ
temp_x=10
char_w=400
cil_width=len("Ìî±íµ¥Î»:Õã½­Ê¡")*char_w
ls_aux1=uf_title_text("header","Ìµ¥Î»£º"+tbdw,temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1


temp_x+=cil_width
cil_width=len("ÖƱí")*char_w
ls_aux1=uf_title_text("header","ÖÆ±í£º",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("¶­")*char_w
ls_aux1=uf_title_text("header","11",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("У¶Ô")*char_w
ls_aux1=uf_title_text("header","У¶Ô£º",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("¶­")*char_w
ls_aux1=uf_title_text("header","12",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("Ç©·¢")*char_w
ls_aux1=uf_title_text("header","Ç©·¢£º",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("¶­")*char_w
ls_aux1=uf_title_text("header","13",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("À¸Ä¿:")*char_w
ls_aux1=uf_title_text("header","À¸Ä¿Êý",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("¶­ºÆ")*char_w
ls_aux1=uf_title_text("header",lms,temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("ÏîÄ¿´úÂë:")*char_w
ls_aux1=uf_title_text("header","ÏîÄ¿´úÂë",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("¶­ºÆ")*char_w
ls_aux1=uf_title_text("header",xmdm,temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("ÏØÊÐÊý:")*char_w
ls_aux1=uf_title_text("header","ÏØÊÐÊý",temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

temp_x+=cil_width
cil_width=len("¶­ºÆ")*char_w
ls_aux1=uf_title_text("header",xss,temp_x,y0*3/4,height,cil_width,-12,0)
as_syntax+=ls_aux1

//
ls_syntax=as_table+as_syntax
//idw_area.create(ls_syntax)
return(ls_syntax)

原文转自:http://www.ltesting.net