亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

基于邏輯運(yùn)算的簡(jiǎn)單權(quán)限系統(tǒng)(原理,設(shè)計(jì),實(shí)現(xiàn)) VBS 版

 更新時(shí)間:2007年03月24日 00:00:00   作者:  
作者:slightboy
看到好多同學(xué)權(quán)限判斷都是用字符串 然后或分割或截取

其實(shí)對(duì)于 允許/不允許(true/false) 這種的權(quán)限, 用邏輯運(yùn)算再恰當(dāng)不過(guò)了

聲明下: 本文針對(duì)入門和為掌握的同學(xué), 如果已經(jīng)懂了那可以無(wú)視了

 可能意思表達(dá)的不是很清楚, 敬請(qǐng)?jiān)? 

邏輯運(yùn)算符介紹:
And: 邏輯與

0 And 0 = 0 
0 And 1 = 0 
1 And 0 = 0 
1 And 1 = 1 
Or: 邏輯或

0 Or 0 = 0 
0 Or 1 = 1 
1 Or 0 = 1 
1 Or 1 = 1 
Xor: 異或

0 Xor 0 = 0 
0 Xor 1 = 1 
1 Xor 0 = 1 
1 Xor 1 = 0 
Not: 邏輯非

Not 1 = 0 
Not 0 = 1 


表達(dá)方式介紹:

1 表示 ture, 0 表示 false

舉二位為例

第一位 表示 Read 的權(quán)限, 第二位 表示 Write 的權(quán)限, 可以表示一下四種權(quán)限

00 Read(false) Write(false) 
01 Read(true) Write(false) 
10 Read(false) Write(true) 
11 Read(true) Write(true) 


運(yùn)算方式介紹:

還是繼續(xù)上面的例子

Read = 01(1), Write = 10(2)

00(0) And Read = 0 
01(1) And Read = Read 
10(2) And Read = 0 
11(3) And Read = Read 
00(0) And Write = 0 
01(1) And Write = 0 
10(2) And Write = Write 
11(3) And Write = Write 


下面給出示例代碼:

權(quán)限定義類(要有枚舉類型該多好啊...)

Class PermissionType

    Public Read
    Public Write
    Public Delete

  Private Sub Class_Initialize
    Read = 1
    Write = 2
    Delete = 4
  End Sub

End Class
權(quán)限類

Class PermissionSetComponent

    Private intValue

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

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

  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
運(yùn)用示例代碼:

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


今天的課程就到這里, 大家可以舉一反三, 下課...

相關(guān)文章

最新評(píng)論