国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

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

2020-06-26 18:07:06
字體:
來源:轉載
供稿:網友
看到好多同學權限判斷都是用字符串 然后或分割或截取 

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

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

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

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


運算方式介紹: 

還是繼續上面的例子 

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 


今天的課程就到這里, 大家可以舉一反三, 下課... 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 镇坪县| 陵川县| 上林县| 新丰县| 修水县| 怀仁县| 原平市| 松溪县| 临澧县| 陆河县| 潜江市| 株洲县| 灵寿县| 逊克县| 广河县| 永川市| 尤溪县| 高台县| 南丰县| 沙坪坝区| 清水河县| 万州区| 和平区| 三明市| 虹口区| 襄樊市| 修水县| 沙田区| 宜丰县| 景东| 靖州| 孝昌县| 五常市| 博客| 玉溪市| 桐庐县| 彰武县| 昭通市| 马山县| 洪洞县| 东乡族自治县|