基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版

2019-01-16 10:56:39王冬梅


  Public Property Get Write()
    Write = GetValue(Permission.Write)
  End Property

  Public Property Let Write(arg)
    Call SetValue(Permission.Write, arg)
  End Property

  Public Property Get Delete()
    Delete = GetValue(Permission.Delete)
  End Property

  Public Property Let Delete(arg)
    Call SetValue(Permission.Delete, arg)
  End Property

  Public Property Get Value()
    Value = intValue
  End Property


  Public Property Let Value(arg)
    intValue = arg
  End Property

  Public Function GetValue(intType)
    GetValue = (Value and intType) = intType

  End Function

  Public Sub SetValue(intType, boolValue)
    IF (boolValue) Then
        Value = Value Or intType
    Else
        Value =  Value And (Not intType)
    End IF
  End Sub

End Class
运用示例代码:

Dim Permission : Set Permission = new PermissionType

Dim PermissionSet : Set PermissionSet = new PermissionSetComponent
PermissionSet.Value = 0
w("Read:")
PermissionSet.Read = false
w(PermissionSet.Value &" "& PermissionSet.Read)

PermissionSet.Read = true
w(PermissionSet.Value &" "& PermissionSet.Read)

w("Write:")
PermissionSet.Write = false
w(PermissionSet.Value &" "& PermissionSet.Write)

PermissionSet.Write = true
w(PermissionSet.Value &" "& PermissionSet.Write)

w("Delete:")
PermissionSet.Delete = false
w(PermissionSet.Value &" "& PermissionSet.Delete)

PermissionSet.Delete = true
w(PermissionSet.Value &" "& PermissionSet.Delete)

Function w(o)
    Response.Write("<br />"& o)
End Function


今天的课程就到这里, 大家可以举一反三, 下课...