treeview的问题
把权限列表的数据按一定规律组合后显示到treeview中没问题,但如何根据treeview中checked属性或其它方法保存到数据库中。不要例程,只需要思路和核心代码。谢谢了! 哥,回一个 已解决了! 论坛人气太差了,要好好整整了。{:lh_25:} 一、生成treeview
C# code
this.setredraw( false)
nvo_datastore mydtx,mydtx2
nvo_loginqx myqx
datastore mydt,mydt2
long tvlever1,tvlever2
mydt = mydtx.f_getdatastore( "select menuname,menutext from menuright where len(menuname) = 3" )
mydt.settransobject(sqlca)
mydt.retrieve( )
int i,m
treeviewitem tvitem,tvitem2
for i = 1 to mydt.rowcount( )
tvitem.label = mydt.getitemstring(i,"menutext")
tvitem.data = mydt.getitemstring(i,"menuname")
tvitem.statepictureindex = 2
tvlever1 = this.insertitemlast( 0,tvitem)
mydt2 = mydtx.f_getdatastore( "select menutext,menutag from menuright where len(menuname)>3 and left(menuname,3) ='"+ tvitem.data+"'")
mydt2.settransobject(sqlca)
mydt2.retrieve( )
for m = 1 to mydt2.rowcount()
tvitem2.label = mydt2.getitemstring(m,"menutext")
tvitem2.data = mydt2.getitemstring(m,"menutag")
tvitem2.statepictureindex = 1
this.insertitemlast(tvlever1,tvitem2)
next
this.expandall( tvlever1)
next
mydtx.f_destroydatastore( )
mydtx2.f_destroydatastore( )
this.setredraw( true)
二、点击权限组时,选择相对应的权限
1、无清空权限
C# codetreeviewitem tvi
long ll_tvi,ll_tvi2
ll_tvi = this.FindItem(RootTreeItem!, 0)
do while ll_tvi >0
ll_tvi2 = this.finditem(childtreeitem!,ll_tvi)
do while ll_tvi2>0
this.getitem(ll_tvi2,tvi)
tvi.statepictureindex = 1
this.setitem(ll_tvi2,tvi)
ll_tvi2 = this.finditem(nexttreeitem!,ll_tvi2)
loop
ll_tvi = this.finditem(nexttreeitem!,ll_tvi)
loop
2、生成权限
C# code
nvo_loginqx myqx
rightcode = myqx.f_pub_transdata_to_code( rightcode)
treeviewitem tvi
long ll_tvi,ll_tvi2
ll_tvi = this.FindItem(RootTreeItem!, 0)
do while ll_tvi >0
ll_tvi2 = this.finditem(childtreeitem!,ll_tvi)
do while ll_tvi2>0
this.getitem(ll_tvi2,tvi)
if myqx.f_pub_checkqx( tvi.data,rightcode) then
tvi.statepictureindex = 2
this.setitem(ll_tvi2,tvi)
end if
ll_tvi2 = this.finditem(nexttreeitem!,ll_tvi2)
loop
ll_tvi = this.finditem(nexttreeitem!,ll_tvi)
loop
三、保存权限
C# code
nvo_loginqx myqx
string rightcode
rightcode = fill('0',80)
treeviewitem tvi
long ll_tvi,ll_tvi2
ll_tvi = this.FindItem(RootTreeItem!, 0)
do while ll_tvi >0
ll_tvi2 = this.finditem(childtreeitem!,ll_tvi)
do while ll_tvi2>0
this.getitem(ll_tvi2,tvi)
if tvi.statepictureindex = 2 thenrightcode = replace(rightcode,integer(tvi.data),1,'1')
ll_tvi2 = this.finditem(nexttreeitem!,ll_tvi2)
loop
ll_tvi = this.finditem(nexttreeitem!,ll_tvi)
loop
return myqx.f_pub_transdata_to_string( rightcode)
myqx.f_pub_transdata_to_code( rightcode)把数据库字符串权限转化成二进制权限
myqx.f_pub_transdata_to_string( rightcode)把二进制权限转化为数据库存储的字符串
myqx.f_pub_checkqx( tvi.data,rightcode)检查当前tag值在二进制权限的数位,为1则是true否则为false 权限设置的思想,权限码用二进制的0/1表示,其数位代表需要设置权限的控件tag值,再把二进制数四位一组存为字符0,1,2,3......进行存储压缩位数,我试了试效果不错,思路也挺好。
学习!!!! 竟然是 C#的code 学习了!!!!
页:
[1]