全部代码
项目事件
AfterOpenProject
'Forms("授权").Open()
计划管理
表事件
窗口表事件
窗口与控件事件
授权_AfterLoad
Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
trv1.BuildTree("角色管理","角色名称")
trv2.BuildTree("授权","分组|权限")
trv2.ExpandAll()
授权_Button1_Click
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim pd As WinForm.TreeNode = trv.SelectedNode
If pd.Level = 1 Then
pd = pd.ParentNode
End If
Dim i As Integer
Do
i = i+ 1
Dim nm As String = "权限" & i
If pd.Nodes.Contains(nm) = False
Dim nd As WinForm.TreeNode = pd.Nodes.Add(nm)
Dim dr As DataRow = DataTables("授权").AddNew()
dr("分组") = pd.name
dr("权限") = nm
trv.SelectedNode = nd
trv.BeginEdit
Exit Do
End If
Loop
授权_Button2_Click
DataTables("授权").Save()
e.Form.Close()
授权_Button3_Click
DataTables("授权").RejectChanges() '撤销修改
e.Form.Close()
授权_Button4_Click
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim i As Integer
Do
i = i+ 1
Dim nm As String = "分组" & i
If trv.Nodes.Contains(nm) = False
Dim dr As DataRow = DataTables("授权").AddNew
Dim nd As WinForm.TreeNode = trv.Nodes.Add(nm)
dr("分组") = nm
trv.SelectedNode = nd
trv.BeginEdit
Exit Do
End If
Loop
授权_Button5_Click
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode = trv.SelectedNode
If nd Is Nothing Then
Return
End If
If nd.Level = 0 Then '删除分组
Dim dt As DataTable = DataTables("授权")
If MessageBox.Show("确定要删除此分组码?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question) = DialogResult.Yes Then
For Each dr As DataRow In dt.Select("分组 = '" & nd.Name & "'" )
dr.Delete
Next
nd.Delete
End If
ElseIf nd.Level = 1 '删除权限
Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
Dim fz As String = nd.ParentNode.Name '获得分组名
dr = dt.Find("分组 = '" & fz & "' And 权限 = '" & nd.Name & "'" ) '找出对应的行
dr.Delete
nd.Delete
End If
授权_Button6_Click
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BeginEdit()
授权_TreeView1_AfterEditNode
If e.NewText = "" Then
e.Cancel = True
ElseIf e.Node.Level = 0 Then '重命名分组
Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
dr = dt.Find("分组 = '" & e.NewText & "' And 权限 Is Null" ) '判断新输入的分组是否存在
If dr IsNot Nothing '如果存在,取消输入.
MessageBox.Show("此分组已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
e.cancel = True
Else
For Each dr In dt.Select("分组 = '" & e.Node.Name & "'" ) '重命名分组
dr("分组") = e.NewText
Next
e.Node.Name = e.NewText '使得节点的名称和标题保持一致.
End If
ElseIf e.Node.Level = 1 '重命名权限
Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
Dim fz As String = e.Node.ParentNode.Name '获得分组名
dr = dt.Find("分组 = '" & fz & "' And 权限 = '" & e.NewText & "'" ) '判断新输入的权限是否存在
If dr IsNot Nothing '如果存在,取消输入.
MessageBox.Show("此权限已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
e.Cancel = True
Else
dr = dt.Find("分组 = '" & fz & "' And 权限 = '" & e.Node.Name & "'" ) '找出对应的行
dr("权限") = e.NewText '重命名权限
e.Node.Name = e.NewText '使得节点的名称和标题保持一致.
End If
End If
授权_TreeView1_AfterSelectNode
Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim dr As DataRow
If e.node.Level = 0 Then
dr = DataTables("角色管理").Find("角色名称 = '" & e.Node.Name & "'")
End If
For Each nd As WinForm.TreeNode In trv2.AllNodes
nd.Checked = False
Next
If dr IsNot Nothing AndAlso dr.IsNull("授权集合") = False
For Each n1 As String In dr("授权集合").split(",")
Dim ary() As String = n1.split("/")
trv2.nodes(ary(0)).Checked = True
trv2.nodes(ary(0)).Nodes(ary(1)).Checked = True
Next
End If
授权_TreeView1_NodeMouseDoubleClick
Dim trv As WinForm.TreeView = e.Sender
trv.Select()
trv.BeginEdit()
授权_TreeView2_AfterCheckNode
Dim trv1 As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim trv2 As WinForm.TreeView = e.Form.Controls("TreeView2")
Dim nd1 As WinForm.TreeNode = trv1.SelectedNode
Dim dr As DataRow
If nd1.Level = 0 Then
dr = DataTables("角色管理").Find("角色名称 = '" & nd1.Name & "'")
End If
If dr IsNot Nothing Then
Dim nms As String
For Each nd2 As WinForm.TreeNode In trv2.Nodes
If nd2.Checked Then
For Each nd3 As WinForm.TreeNode In nd2.Nodes
If nd3.Checked Then
nms &= "," & nd2.name
nms = nms & "/" & nd3.Name
End If
Next
End If
Next
If nms > "" Then
dr("授权集合") = nms.Trim(",")
Else
dr("授权集合") = Nothing
End If
End If
授权_TreeView2_Enter
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode = trv.SelectedNode
If nd IsNot Nothing Then
nd.Text = nd.Text & "←"
End If
授权_TreeView2_Leave
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
Dim nd As WinForm.TreeNode = trv.SelectedNode
If nd IsNot Nothing Then
nd.Text = nd.Text.Trim("←")
End If
自定义函数
ShouQuan
If User.Type <> UserTypeEnum.User Then ' 如果是开发者或者管理员
Return True '则具备所有权限
End If
Dim dt As DataTable = DataTables("授权")
Dim dr As DataRow
'首先判断分组的授权用户是否包括此用户或此用户所属的分组
dr = dt.Find("分组 = '" & args(0) & "' And 权限 Is Null" )
If dr Is Nothing Then
MessageBox.show("不存在名为""" & args(0) & "分组!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return False
End If
If dr.IsNull("用户") = False Then
Dim nms() As String = dr("用户").Split(",")
For Each nm As String In nms
If nm = User.Group OrElse nm = User.Name Then '如果授权用户包括登录用户所属的分组或其用户名
Return True '返回True
End If
Next
End If
'然后判断权限的授权用户是否包括此用户或此用户所属的分组
If Args(1) = "" Then
Return False
End If
dr = dt.Find("分组 = '" & args(0) & "' And 权限 = '" & args(1) & "'")
If dr Is Nothing Then
MessageBox.show("不存在名为""" & args(1) & "权限!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Return False
End If
If dr.IsNull("用户") = False Then
Dim nms() As String = dr("用户").Split(",")
For Each nm As String In nms
If nm = User.Group OrElse nm = User.Name Then '如果授权用户包括登录用户所属的分组或其用户名
Return True '返回True
End If
Next
End If
Return False
全局代码
Default
'=============用户管理===============
Public _UserName As String '登录名
Public _UserName1 As String '用户名
Public _UserGroup As String '用户分组
Public _UserTable As DataTable '
菜单事件