各位好﹗
我想将权限管理融入菜单编辑器中﹐权限是从数据库中通过查询语句取出的﹐请大家给一个好的建议和方案﹐(附实例更好)

解决方案 »

  1.   

    在数据库中建两个表
    一个表是授权表,其中有编号、姓名、权限、口令
    另一个是权限表,其中就有一个权限字段,把程序中所有用的权限全部写进去。
      snp.FindFirst "[" + snp.Fields(0).Name + "] = '" + Trim$(TextNumber.Text) + "'"
        If snp.NoMatch Then
            chk = 1
        Else
            If Not IsNull(snp("口令")) Then
                If TextPassWord.Text <> snp("口令") Then
                    chk = 2
                Else
                    If IsNull(snp("WorkAt")) Then
                        chk = 0
                    Else
                        If snp("WorkAt") <> MachineName Then
                            chk = 3
                        Else
                            chk = 0
                        End If
                    End If
                End If
            Else
                If TextPassWord.Text <> "" Then
                    chk = 2
                Else
                    If IsNull(snp("WorkAt")) Then
                        chk = 0
                    Else
                        If snp("WorkAt") <> MachineName Then
                            chk = 3
                        Else
                            chk = 0
                        End If
                    End If
                End If
            End If
        End If
        If chk = 0 Then
            Panel(1).Caption = snp("姓名") + ",您好:" + Chr$(13) + "祝您工作顺利!"
        ElseIf chk = 3 Then
            msg = Chr$(13) + "该用户已在" & snp("WorkAt") & "上工作" + Chr$(13) + "不准再次登录!"
            Panel(1).Caption = msg
        Else
            Counter = Counter - 1
            If Counter = 0 Then
                msg = Chr$(13) + "你不是合法用户!" + Chr$(13) + "对不起,再见!"
            ElseIf Counter = 1 Then
                msg = Chr$(13) + "这是最后一次.请仔细!"
            Else
                msg = Chr$(13) + "别急,想好.请再试一次"
            End If
            TextPassWord.Text = ""
            TextPassWord.Enabled = False
            If chk = 1 Then
                Panel(1).Caption = "无此编号∶" + TextNumber.Text + msg
            ElseIf chk = 2 Then
                Panel(1).Caption = "错误口令" + Chr$(13) + msg
            End If
        End If
    以上是登陆时执行的。以后在程序中用到权限的时候就按下边写就可以了。
        If InStr(Employee.Empower, "档案") <= 0 Then Exit Sub
    这句的意思是当档案菜单的时候,如果有新建、修改档案的权限就向下进行,否则就执行Exit Sub
      

  2.   

    检测权限后,设置菜单的Enabled属性即可。
      

  3.   

    有权限---->菜单.Enabled=真
    没权限---->菜单.Enabled=假