下拉子数据窗口中的数据自动更新

dtx01 2007-01-22 08:39:33
下拉子数据窗口中的数据自动更新

----------------------------------------------------------------------------

----
转载 来源http://www.study01job.com/pb PB文章库 PB论坛 免费电子图书


数据窗口中,字段的编辑风格设置为下拉数据窗口,并且选中允许编辑。在使用过程中

,用户如果输入的内容在编码表中不存在,使用这里介绍的设计方法可以自动更新编码

表,用户使用非常方便。
设计思路是:
1、封装用户对象,使用Standard Visual,选择DataWindow
2、为了便于用户删除输入错误的内容,在用户对象的Constructor编写程序,向下拉

子数据窗口中插入一个空行。
3、在用户对象的ItemChanged事件中,查找用户输入的内容是否存在,如果不存在则

添加新数据并保存。这里进行了假设:编码采用2位String类型的编码。


程序如下:
用户对象的Constructor事件:
DataWindowChild ldwc_temp
Integer li_index
String ls_ColName

This.SetTransObject(SQLCA)
This.Retrieve( )
This.InsertRow(0)

For li_index = 1 to Integer(This.Object.Datawindow.Column.Count)
if This.Describe("#" + String(li_index) + ".edit.style") = 'dddw' then
ls_ColName = This.Describe("#" + String(li_index) + ".name")
if This.GetChild(ls_ColName,ldwc_temp) <> 1 then continue
ldwc_temp.InsertRow(0)
end if
Next
用户对象的ItemChanged事件:
Long ll_FindRow
String ls_id
String ls_DataCol
String ls_DispCol
String ls_SelCol
DatawindowChild ldwc_temp

ls_SelCol = dwo.name

if This.GetChild(ls_SelCol,ldwc_temp ) <> 1 or &
This.Describe(ls_SelCol + ".Edit.style") <> 'dddw'then return

ldwc_temp.SetTransObject(SQLCA)
ls_DataCol = This.Describe(ls_SelCol + ".dddw.DataColumn")
ls_DispCol = This.Describe(ls_SelCol + ".dddw.DisplayColumn")
ll_FindRow = ldwc_temp.Find(ls_DispCol + "='" + data +

"'",1,ldwc_temp.RowCount())
if ll_FindRow > 0 then
ls_id = ldwc_temp.GetItemString(ll_FindRow,ls_DataCol)
This.SetItem(Row,ls_SelCol,ls_id)
else
ll_FindRow = ldwc_temp.Find(ls_DataCol + "='" + data +

"'",1,ldwc_temp.RowCount())
if ll_FindRow < 1 then
ll_FindRow = ldwc_temp.InsertRow(ldwc_temp.RowCount())
ldwc_temp.SetItem(ll_FindRow,ls_DispCol,Data)
ls_id = '00'
if ldwc_temp.RowCount() > 1 then ls_id = ldwc_temp.GetItemString(ll_FindRow -

1,ls_DataCol)
ls_id = Right('000' + String(Integer(ls_id) + 1),2)
ldwc_temp.SetItem(ll_FindRow,ls_DataCol,ls_id)
end if
end if
if ldwc_temp.Update() = 1 then
commit;
else
rollback;
end if


...全文
283 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-05-01
  • 打赏
  • 举报
回复
都是很好的建议! 值得学习
lzuyh 2007-01-22
  • 打赏
  • 举报
回复
学习

401

社区成员

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

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