AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > PowerBuilder

PB实现数据窗口动态排序的方法

51自学网 http://www.51zixue.net

  在PowerBuilder中使用数据窗口检索到的数据往往是无序的,虽然可以通过设置Select语句实现排序的功能,但是数据窗口一旦生成都无法进行动态调整。笔者总结了在已经生成的数据窗口中实现动态排序的三种方法,现介绍给大家。

  一、 准备工作

  设计如图1所示的示例窗口。为了更好地比较三种不同的方法,dw—1中的数据来自两个表student和class。student表中包含四个字段sid(学号)、sname(姓名)、saddr(住址)和cid(班号),class表中包含两个字段cid(班号)和cname(班级名称)。


图1

  二、三种方法的源程序

  三种方法中的“执行”按钮的代码分别为:

  方法1:用SetSQLselect()


  string ls—oldsql,ls—newsql,ls—order ls—column
  ls—oldsql=dw—1.getsqlselect()
  choose case ddlb—1.text
  case ″学号″ls—column=″sid″
  case ″姓名″ls—column=″sname″
  case ″住址″ls—column=″saddr″
  case ″班号″ls—column=″class.cid″
  case ″班级名称″ ls—column=″cname″
  end choose
  if rb—1.checked then ls—order=″ASC″
  else ls—order=″DESC″
  end if
  ls—newsql=ls—oldsql+″ ORDER BY ″+ &
  ls—column+″ ″+ls—order
  if dw—1.setsqlselect(ls—newsql)=-1 then
  messagebox(″警告″,″数据设置失败″,stopsign!)
  else dw—1.settransobject(sqlca)
  dw—1.reset()
  dw—1.retrieve()
  dw—1.setsqlselect(ls—oldsql)
  end if 

 

  方法2:用describe()和modify()


  string ls—mod, ls—order,ls—old,ls—column
  ls—old=dw—1.describe(′datawindow.table.select′)
  dw—1.settransobject(sqlca) 
   window.height = li_height - 2*(li_gd - li_y)
  next
 case 5      // closetype = 5,从左右向中间挤压逐渐消失
  li_cenx = li_x+li_width / 2
  for li_gd = li_x to li_cenx step 1
   window.x = li_gd
   window.width = li_width - 2*(li_gd - li_x)
  next
 case 6      // closetype = 6,从左上->右下
  for li_gd = li_y to li_height+li_y step 1
   window.y = li_gd
   window.height = li_height+li_y - li_gd
   if window.x < li_x + li_width then
    window.x = li_x + (li_gd - li_y)
   else
    window.x = li_x + li_width
   end if
   if window.width > 0 then
    window.width = li_x+li_width - window.x
   else
    window.width = 0
   end if
  next
  window.x = li_x + li_width
  window.y = li_height+li_y
  window.width = 0
  window.height = 0
   window.show()
   case 7      // closetype = 7,从右下->左上
  for li_gd = li_height to 0 step -1
   window.height = li_gd
   if window.width > 0 then
    window.width = li_width - (li_height - li_gd)
   else
    window.width = 0
   end if
  next
  window.x = li_x
  window.y = li_y
  window.width = 0
  window.height = 0
  window.show()
 case 8      // closetype = 8,从右上->左下
  for li_gd = li_y to li_height+li_y step 1
   window.y = li_gd
   window.height = li_height+li_y - li_gd
   if window.width > 0 then
    window.width = li_width - (li_gd - li_y)
   else
    window.width = 0
   end if
  next
  window.x = li_x
  window.y = li_height+li_y
  window.width = 0
  window.height = 0
  window.show()
   case 9      // closetype = 9,从左下->右上
  for li_gd = li_x to li_x+li_width step 1
   window.x = li_gd
   window.width = li_width +li_x -li_gd
   if window.height > 0 then
    window.height = li_height -(li_gd - li_x)
   else
    window.height = 0
   end if
  next
  window.x = li_x+li_width
  window.y = li_y
  window.width = 0
  window.height = 0
  window.show()
 case 10      // closetype = 10,从四面到中间
  li_ceny = li_y+li_height/2
  li_cenx = li_x+li_width / 2
  for li_gd = li_y to li_ceny step 1
   window.y = li_gd
   window.height = li_height - 2*(li_gd - li_y)
   if window.x < li_x + li_cenx then
    window.x = li_x + (li_gd - li_y)
   else
    window.x = li_x + li_cenx
   end if
   if window.width > 0 then
    window.width = li_width - 2*(li_gd - li_y)
   else
    window.width = 0
   end if
  next
  window.x = li_cenx
  window.y = li_ceny
  window.width = 0
  window.height = 0
  window.show()
 case else
  window.show()
  window.width = li_width
  window.height = li_height
  window.x = li_x
  window.y = li_y
END CHOOSE
return 0
************************
// 调用该函数在窗体的 closequery 事件中
gf_closequery (w_main,mod(integer(string(now(),"ss")),11))

    上面是关闭时的效果,窗体打开时的动态效果的语句跟上面的差不多,在此就不写啦,如果有需要的可以告诉我,我单独发送。谢谢。

 

 

 
上一篇:窗体动态效果的实现  下一篇:返回列表