现在的位置: 首页 > 综合 > 正文

比较权限字符串

2012年02月25日 ⁄ 综合 ⁄ 共 635字 ⁄ 字号 评论关闭

//权限类型
public enum LicenseType
{
None = 0,ReadOnly = 1 ,All = 2
}
//根据权限码获取是否通过指定的权限
public bool IsLicense(string LicenseCode,LicenseType License)
{
char[] chr = LicenseCode.ToCharArray();

switch(License)
{
case LicenseType.None:
{
if (chr[0] == '1') return true;
return false;
break;
}
case LicenseType.ReadOnly:
{
if (chr[1] == '1') return true;
return false;
break;
}
case LicenseType.All:
{
if (chr[2] == '1') return true;
return false;
break;
}
default:
{
return false;
break;
}
}
return false;
}

//测试
if (GetLicense("011",LicenseType.None) == true) MessageBox.Show("无权!");
if (GetLicense("011",LicenseType.ReadOnly) == true) MessageBox.Show("只读!");
if (GetLicense("011",LicenseType.None) == true) MessageBox.Show("全部!");

抱歉!评论已关闭.