dr.load()
换成
dr.save
dr.load()
并用,应该无问题了吧?
代码最后一行加了datatables("sys_角色管理").save
很不幸地告诉大家,卸载表再加载后还是部分数据丢了,既然大家没问题,就我一个人有问题,即日起,我暂停我的项目,坐等大家,有别人提出类似问题再说,我不再强调了:
我的保存角色按钮代码提供给大家来解读,请各位指出错误:
If e.Form.Controls("角色选择").Value = Nothing
MessageBox.show("对不起,请先输入您要保存角色的名称!","提示", MessageBoxButtons.ok, MessageBoxIcon.Information)
Return
End If
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView授权项目")
Dim nd,nd1,nd2 As WinForm.TreeNode
Dim dr As DataRow
Dim s,s1 As String
Dim drs As List(Of DataRow)
drs = DataTables("sys_角色管理").Select("角色建立人 <> '" & Vars("当前用户") & "' and 角色名称 ='" & e.Form.Controls("角色选择").Value & "'")
If drs.Count > 0
MessageBox.show("对不起,该角色已经存在,但不为您所建,您不能覆盖保存!","提示", MessageBoxButtons.ok, MessageBoxIcon.Information)
Return
End If
drs = DataTables("sys_角色管理").Select("角色建立人 = '" & Vars("当前用户") & "' and 角色名称 ='" & e.Form.Controls("角色选择").Value & "'")
If drs.Count > 0
If MessageBox.show("对不起,该角色已经存在,您确定要覆盖保存吗?","提示", MessageBoxButtons.yesno, MessageBoxIcon.Information) = 6
Else
Return
End If
End If
DataTables("sys_角色管理").DeleteFor("角色建立人 = '" & Vars("当前用户") & "' and 角色名称 ='" & e.Form.Controls("角色选择").Value & "'")
s1 = "可视授权,编辑授权"
For i As Integer = 0 To 1
nd = trv.Nodes("表授权").Nodes(s1.split(",")(i))
For Each nd1 In nd.AllNodes
If nd1.nodes.Count > 1
If nd1.Checked = True
For Each nd2 In nd1.AllNodes
If nd2.Checked = True
If s = Nothing
s = nd2.name
Else
s = s & "," & nd2.name
End If
End If
Next
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = "表授权"
dr("表名称") = nd1.name
dr("列名称") = s
dr(s1.split(",")(i).Replace("授权","")) = 1
dr.save()
dr.load()
s = Nothing
End If
End If
Next
Next
s1 = "入库管理,出库管理"
For i As Integer = 0 To 1
nd = trv.Nodes("仓库管理").Nodes(s1.split(",")(i))
For Each nd1 In nd.AllNodes
If nd1.nodes.Count > 1
If nd1.Checked = True
For Each nd2 In nd1.AllNodes
If nd2.Checked = True
If s = Nothing
s = nd2.name
Else
s = s & "," & nd2.name
End If
End If
Next
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = s1.split(",")(i).Replace("管理","授权")
dr("表名称") = nd1.name
dr("列名称") = s
dr.save()
dr.load()
s = Nothing
End If
End If
Next
Next
nd = trv.Nodes("车辆管理").Nodes("车辆调度")
If nd.Checked = True
For Each nd1 In nd.AllNodes
If nd1.Checked = True
If s = Nothing
s = nd1.name
Else
s = s & "," & nd1.name
End If
End If
Next
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = "车辆管理"
dr("表名称") = "车辆调度"
dr("列名称") = s
dr.save()
dr.load()
s = Nothing
End If
nd = trv.Nodes("人事管理")
If nd.Checked = True
For Each nd1 In nd.AllNodes
If nd1.Checked = True
If s = Nothing
s = nd1.name
Else
s = s & "," & nd1.name
End If
End If
Next
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = "人事管理"
dr("表名称") = ""
dr("列名称") = s
dr.save()
dr.load()
s = Nothing
End If
nd = trv.Nodes("生产管理")
If nd.Checked = True
For Each nd1 In nd.AllNodes
If nd1.Checked = True
If s = Nothing
s = nd1.name
Else
s = s & "," & nd1.name
End If
End If
Next
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = "生产管理"
dr("表名称") = ""
dr("列名称") = s
dr.save()
dr.load()
s = Nothing
End If
nd = trv.Nodes("资料管理")
If nd.Checked = True
For Each nd1 In nd.AllNodes
If nd1.Checked = True
If s = Nothing
s = nd1.name
Else
s = s & "," & nd1.name
End If
End If
Next
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = "资料管理"
dr("表名称") = ""
dr("列名称") = s
dr.save()
dr.load()
s = Nothing
End If
nd = trv.Nodes("报表管理")
Dim bblb As New List(Of String)
If nd.Checked = True
For Each nd1 In nd.AllNodes
If nd1.Nodes.Count = 0
If bblb.Contains(nd1.ParentNode.FullPath) = False
bblb.Add(nd1.ParentNode.FullPath)
End If
End If
Next
End If
Dim Values() As String
For Each lb As String In bblb '遍历报表类别
Values = lb.split("\")
For n As Integer = 0 To Values.Length - 1
If n = 0
nd = trv.Nodes(Values(n))
Else
nd = nd.Nodes(Values(n))
End If
Next
If nd.Nodes.Count > 0
dr = DataTables("sys_角色管理").AddNew()
dr("角色建立人") = Vars("当前用户")
dr("角色名称") = e.Form.Controls("角色选择").Value
dr("授权类别") = "报表管理"
If nd.Nodes(0).text = "报表设置"
Dim bbsz As String = nd.Nodes(0).FullPath
dr("表名称") = bbsz.Replace("报表管理\","")
Else
For Each nd1 In nd.AllNodes
If s = Nothing
s = nd1.text
Else
s = s & "," & nd1.text
End If
Next
dr("表名称") = lb.Replace("报表管理\","")
dr("列名称") = s
End If
dr.save()
dr.load()
s = Nothing
End If
Next
DataTables("sys_角色管理").save()
MessageBox.show("恭喜您,保存角色成功!","提示", MessageBoxButtons.ok, MessageBoxIcon.Information)