回 帖 发 新 帖 刷新版面

主题:[转帖]下拉子数据窗口中的数据自动更新

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

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

----
转载  来源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 

 

回复列表 (共1个回复)

沙发

谢谢

我来回复

您尚未登录,请登录后再回复。点此登录或注册