最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于邏輯運算的簡單權限系統(tǒng)(原理,設計,實現(xiàn)) VBS 版

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

其實對于 允許/不允許(true/false) 這種的權限, 用邏輯運算再恰當不過了

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

 可能意思表達的不是很清楚, 敬請原諒. 

邏輯運算符介紹:
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 


表達方式介紹:

1 表示 ture, 0 表示 false

舉二位為例

第一位 表示 Read 的權限, 第二位 表示 Write 的權限, 可以表示一下四種權限

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


運算方式介紹:

還是繼續(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 


下面給出示例代碼:

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

Class PermissionType

    Public Read
    Public Write
    Public Delete

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

End Class
權限類

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
運用示例代碼:

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


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

相關文章

最新評論

安国市| 车致| 民和| 西吉县| 西华县| 黄平县| 马关县| 昔阳县| 昌吉市| 治多县| 微博| 西乌珠穆沁旗| 漳平市| 河南省| 建始县| 临泉县| 张家港市| 巢湖市| 闽清县| 海门市| 湟源县| 林芝县| 南昌县| 宝清县| 航空| 武定县| 兖州市| 舟山市| 盖州市| 洪泽县| 民勤县| 山东省| 扎兰屯市| 子长县| 德州市| 岗巴县| 阿拉善盟| 光山县| 米林县| 湟中县| 南投市|