PB利用树状视图分层组织和显示数据.doc

上传人:仙人指路1688 文档编号:2396047 上传时间:2023-02-17 格式:DOC 页数:3 大小:289KB
返回 下载 相关 举报
PB利用树状视图分层组织和显示数据.doc_第1页
第1页 / 共3页
PB利用树状视图分层组织和显示数据.doc_第2页
第2页 / 共3页
PB利用树状视图分层组织和显示数据.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《PB利用树状视图分层组织和显示数据.doc》由会员分享,可在线阅读,更多相关《PB利用树状视图分层组织和显示数据.doc(3页珍藏版)》请在三一办公上搜索。

1、第 15 卷第 6 期重庆职业技术学院学报2006 年 11 月Vol.15 N o.6 Journal of C hongqing Vocational & T echnical Institute N ov. 2006PB利用树状视图分层组织和显示数据童 均( 重庆大学 自动化学院, 重庆 400044; 重庆电子科技职业学院 计算机系, 重庆 401147)摘要: 在计算机信息管理中, 有许多数据之间存在一定的层次关系, 将数据像 windows 的资源管理器一样显示出来, 可以清晰表示它们之间的关系。本文以大学机构构成为例叙述如何按层次将数据在数据库中进行编码和在 PowerBuild

2、er 中利用数据窗口在 TreeView 控件中按层次显示数据。 关键词: PowerBuilder; 数据窗口; 树状视图控件中图分类号: TP311文献标识码: A文章编号: 1672- 0067( 2006) 06- 0151- 03WINDOWS的资源 管 理 器 将 信 息 按 层次 以 树 状 形 式显示, 在 PB 中我们可以通过对 TreeView 控件编程来实 现。TreeView 控件的特点是将信息项显示成树状层次结 构, 能更清晰地表现主次关系, 操作非常方便, 树状视图 项 TreeViewItem 是 TreeView 控件的基本信息单位, 树状 视图项的生成对于信息

3、的层次显示非常重要。本文采用该表表示大学的编号为“001”到“999”, 学 院 的 编 号为“* * * 01”到“* * * 99”( 其中前 3 位“* * * ”表 示 大学的编号) , 其它依次类推。计算机信息管理中, 信息一般都是存储在数据库中, 现 在 SQL Server 中 创 建 表 info_code 来 存 储 机 构 的 编 号 和名称。Create table info_code(code char( 9) not null, / / 机构编号 name char( 30) not null, / / 机构名称 PRIMARY KEY( code) / / 设置主键

4、) ;为以后显示数据, 在 info_code 表中添加下表中的几 条记录在创建 TreeView 时触发它的 Constructor 事件,在事件中先用它的 InsertItemFirst 函数添加树状视图的第 1 级, 借助动态数据窗口( Datawindow) 获得第 2 级的数据, 用循环 方式获得第一级的下级数据, 调用 InsertItemLast 函数为 第 1 级添加它的下一级, 至此, 树状视图的前两级数据以 层次方式显示出来。当用户首次点击某 TreeViewItem 项 展开时触发它的 ItemPopulate 事件来添加它的每个下级的下级,这样便可以实现将树状视图的每级

5、添加进去并显示出来。本文充分利用 PB 的数据窗口对象可从关系型数据 库或其他数据源中检索、显示和操纵数据的特性, 动态创 建了一个临时数据窗口对象来存储从数据库中获得的所编 号名 称清华大学重庆大学 自动化学院 计算机学院 网络技术系计算机应用技术系 网络工程网站建设网络管理001002002010020200202010020202002020101002020102002020103需要的数据集,然后再对从数据窗口对象中获得需要的数据添加到树状视图中。对层次关系进行数据编码在信息表示中, 常以编码来表示信息之间的关系, 如 身份证号表示了人的省、市、区和出生年月关系, 因此, 对 于存在

6、层次关系的数据, 首先是对数据编码, 用几位符号 表示一级数据。现以大学机构构成为例分析编码过程如 下表。1设计窗口新添加一个窗口 w_main, 在窗口上添加 TreeView 控 件, 命名为 tv_info, 然后创建实例变量:2机构大学学院系专业位数3579收稿日期: 2006- 09- 16作者简介: 童 均( 1973) , 男, 重庆市人, 重庆大学高师硕士, 重庆电子科技职业学院, 讲师, 主要研究方向: 计算机软件技术。添加第一级“大学”创建临时数据窗口对象 dw_temp将表中记录存入 dw_temp保留编码长度为 3 的记录 大学名称是 有下一条记录否获取该记录放入到新添

7、加的树状项 tvi 中 添加新的树状项到它的上级退出datawindow dw_temp / / 临时数据窗口integer code_len =3, 5, 7, 9 / / 保存每级长度 编写脚本在首次展开某树状项时触发该事件,的每个子项的子项。long i, j, n_handle, picTreeViewitem tvi string str, tempgetitem( handle, tvi) / / 获得当前项添加该树状项33.1 tv_info 的 constructor 事件功能: 在构造 tv_info 时先创建第 1 级“大学”, 然后以 循环方式创建第 1 级的下一级各个大

8、学。实现过程见图 1:具体实现脚本如下:TreeViewitem tvi/ / 创建第 1 级“大学” tvi.data=“” tvi.label=“大学”tv_info.insertitemfirst( 0, tvi)/ / 构造临时数据窗口 dw_temp=create datawindow openuserobject( dw_temp)string err, sqln_handle=tv_info.finditem( ChildTreeItem! , handle) / /获得当前项的第一个子项的句柄/ / 以循环方式处理该树状项的每个子项do while trueif n_handl

9、e=- 1 then exit/ / 添加树状视图名柄为 n_handle 的子项addTreeViewitem( n_handle)n_handle=tv_info.finditem( NextTreeItem!/ / 查找下一项loop, h_handle)定义 addTreeViewitem 函数功能: 添加句柄为 handle 的所有下级 参数: long handle / / 树状视图项句柄 返回值: ( None)TreeViewitem tvi string codelong m, n, itv_info.getitem( handle, tvi) code=string( tv

10、i.data) dw_temp.retrieve( )m=len( code)n=nextgrade_length( code)/ / 过滤符合条件( 下一级) 的数据dw_temp.setfilter (“left ( code, ”+string code+“and len( code) =”+string( n) )dw_temp.filter( ) dw_temp.SetRedraw( false) dw_temp.SetSort(“#1 A”) / / 按编号排序dw_temp.Sort( )dw_temp.SetRedraw( true)/ / 循环添加编号为 code 的每个下级

11、for i=1 to dw_temp.rowcount( )3.3sql =“SELECTder by code asc”code, name FROM info_code where or-sql =SQLCA.SyntaxFromSQL ( sql, style ( type =“grid) ”,err)( m) +“) =”+dw_temp.Create( sql, err)dw_temp.settrans( sqlca)dw_temp.retrieve( )/ / 过滤符合条件( 下一级) 的数据 dw_temp.setfilter( len( code) =3 ) dw_temp.f

12、ilter( )long i/ / 循环添加第 2 级for i=1 to dw_temp.rowcount( ) tvi.label=dw_temp.getitemstring( i,“name”) tvi.data=dw_temp.getitemstring( i,“code”)tv_info.insertitemlast( 1, tvi)next编写 tv_info 的 itempopulate 事件tvi.label=dw_temp.getitemstring( i,“name”)tvi.data=dw_temp.getitemstring( i,“code”)tv_info.inse

13、rtitemlast( handle, tvi)next函数 nextgrade_length功能: 得到 code 的下级长度 参数: string code返回值: integer / /- 1 表示无下级long i, num num=len( code)if num=0 then return 2for i=1 to upperbound( code_len) - 1if code_len i =num then return code_len i +1next3.43.2图 2运行结果return - 1运行结果在应用的 open 事件中连接数据库,参考文献:4打开 w_main 窗

14、 1刘增进 .PowerBuilder7.0 数据窗口技术详解 M .北京: 电子工业出版社, 2002.樊金生.Powerbuilder8.0 实用教程 M .北京: 科学出版社,2001.万琪 .PB6.5 中 TreeView 控件的使用技巧 M . 吉林省松 原市李超 .PowerBuilder8.0 编程基础 M .北京: 清华大学出版 社, 2003.口, 得到如下图。 2 3 4责任编辑郑 文PB Uses Hierarchical Treeview Organizations And Displays DataTONG Jun( Computer Department, Cho

15、ngqing College of Electronic technology, Chongqing 401147, China;Automation School, Chongqing University, Chongqing 400044, China.)Abs tra ct: In Computer information management, there is a certain level of relations between data, equally demonstratedthe data like the Windows resource management, ma

16、y clearly expresses the relations between them.This article takes the uni-versity organization constitution as the example to describe how does the data code in the database and uses datawindow inTreeView control to display the data in PowerBuilder.Ke y words : powerbuilder; datawindow; treeview con

17、trol!( 上接第 150 页) Cs.cbInQue, BufferSize, LoverLapped) ;WriteFile ( Hcomml, DataOut, Cs.cbOutQue, BufferSize,LoverLapped) ;有效地提高控制系统的整体自动化程度。实践证明, 该方案结构简单、投资少、开发周期短、运行稳定可靠, 对小规 模的系统极具现实意义。参考文献: 1 胡汉才.单片机原理与接口技术 M . 北京: 清华大学出版 社.2003: 251- 282. 2 黄红.基于自由口模式实现 S7- 200 系列 PLC 与 PC 机无线 串行通信 J .湖南理工学院学报(

18、 自然科学版) , 2005, ( 1) :81- 83. 3 王兆义.可编程控制器教程 M .北京: 机械工业出版社,2002: 229- 248.责任编辑郑文释放串口通 信 完 毕 后 释 放 所 有 串 口 ,Hcomml) ;3.6程 序 为 : Closehandal (结束语将 PLC 与计算机通信网络连接起来, 通过利用 PLC ( 下位机) 的自由口通信协议和上位机的 Delphi 开发工 具, 可以方便地开发出 PC 机和 PLC 通信应用软件, PLC 完成对现场开 / 关量、模拟输入 / 输出量的控制处理, 计算 机实现对过程参数的监控、分析、统计、修改等, 从而可以4C

19、arry out the mode string line correspondence of calculator and PLC freedom of researchHE Zhi - ming( Chongqing Yangtse gorges occupation college, Wanzhou Chongqing 404001, China)Abs tra ct:PLC conduct and actions 1 kind stabilizes dependable controller to get an extensive usage,but it also hassome w

20、eakness of oneself: Calculation processing and management ability of data are weaker, can t provide good interface etc. for customer. But the calculator can make up PLC shortage by luck, it has a good data calculation a processing and manage an ability not only, and can give the customer provide ver

21、y beautiful but again be easy to the interface of operation.Corresponding by letter PLC and calculator the network conjunction gets up, and carry out a string of line correspondence, can raise control system availably of whole automation degree.Ke y words : Calculator; PLC; Free mode; the string line corresponds by letter; the correspondence negotiates.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号