BusinessObjects系统用户信息同步的解决类
前提:
BusinessObjects单点登录实现方法一
BusinessObjects单点登录实现方法二
实现BO单点登录之后一个马上面临的问题就是,如何实现外部用户信息和BO用户信息的同步。为此,我整理了一个类Utilities,来解决在BO用户管理操作中遇到的问题。
公共构造函数
名称 |
说明 |
Utilities() |
初始化Utilities类的新实例 |
|
|
公共属性
名称 |
说明 |
Token |
登录用户的Token文本 |
|
|
|
|
公共方法
名称 |
说明 |
Int AddFolder(int parentFolderID, string folderName, string folderDescription) |
增加一个目录。 参数说明: parentFolderID: 指定的父目录的ID,新增加的目录将作为这个父目录的儿子 folderName: 目录名称 folderDescription: 目录说明 返回说明: 返回增加的目录的ID |
Void AddLimit( string reportID, string userID, int limitID, int newValue) |
为一个报表的一个用户增加一个限制 参数说明: reportID: 报表的ID userID: 用户的ID limitID: 指定的限制ID newValue: 限制的值 |
void AddReport(int folderID, string reportName) |
增加一个报表 参数说明: folderID: 增加报表所在的目录 reportName: 报表的名字 |
void AddRight( string reportID, string userID, int rightID, string granted) |
为一个报表的一个用户增加一个权限 参数说明: reportID: 报表ID userID: 用户ID rightID: 权限ID granted: 1 授权, 0 拒绝. |
void AddUser(UserDataTransfer userDataTransfer) |
增加一个用户 参数说明: userDataTransfer: 用户信息对象 |
void AddUserGroup( string name, string description) |
增加一个组 参数说明: name: 组名称 description: 组说明 |
void AddUserToGroup( string userID, int groupID) |
把用户加入一个组 参数说明: userID: 用户ID groupID: 组ID |
void AddUserToNewGroup( string userID, string groupName) |
把用户加入一个新组 参数说明: userID: 用户ID groupName: 新组的名称 |
void DeleteUser( string userID) |
删除一个用户 参数说明: userID: 用户ID |
void DeleteUserGroup( string userGroupID) |
删除一个用户组 参数说明: userGroupID: 组ID |
IDictionary GetAvailableLimits( string reportID) |
获取一个报表的所有限制 参数说明: reportID: 报表ID 返回说明: 返回包含用键、值对的Dictionary. |
IDictionary GetAvailableRights( string reportID) |
获取一个报表的所有权限 参数说明: reportID: 报表ID 返回说明: 返回包含用键、值对的Dictionary. |
SecurityLimits GetCurrentLimits( string reportID, string userID) |
获取用户对一个报表的限制 参数说明: reportID: 报表ID userID: 用户ID 返回说明: 返回SecurityLimits集合对象信息. |
SecurityRights GetCurrentRights(string reportID, string userID) |
获取用户对一个报表的权限 参数说明: reportID: 报表ID userID: 用户ID 返回说明: 返回SecurityRights集合对象信息. |
int GetFolderID(string folderName) |
获取一个目录的ID 参数说明: folderName: 目录名称 返回说明: 返回目录的ID |
IDictionary GetFolders() |
获取所有目录的列表 参数说明: <returns>返回包含用键、值对的Dictionary. |
IDictionary GetMemberGroups( string userID) |
获取一个用户所在的所有组 参数说明: userID: 用户ID 返回说明: 返回包含用键、值对的Dictionary. |
IDictionary GetReports() |
获取所有的报表 参数说明: <returns>返回包含用键、值对的Dictionary. |
IDictionary GetUserGroups() |
获取所有的用户组 参数说明: <returns>返回包含用键、值对的Dictionary |
IDictionary GetUsers() |
获取所有的用户信息 参数说明: <returns>返回包含用键、值对的Dictionary. |
IDictionary GetUsersForReport( string reportID) |
获取一个报表的所有用户 参数说明: reportID: 报表ID 返回说明: 返回包含用键、值对的Dictionary. |
bool Logon(string System, string UserName, string Password, AuthenticationTypes AuthType) |
登录到BO服务器,在进行BO的各种操作之前,都必须先进行登录 参数说明: System: 系统名称 UserName: 登录用户名称 Password: 登录密码 AuthType: 登录认证类型 |
void RemoveUserFromGroup(string userID, string groupID) |
从一个用户组中移除一个用户,注意,不删除用户 参数说明: userID: 用户ID groupID: 组ID |
void ResetUserPassword( string userID, string alternatePassword) |
重置一个用户的密码 参数说明: userID: 用户ID alternatePassword: 新密码 |
|
|
using System;
using System.Data;
using System.Collections;
using CrystalDecisions.Enterprise;
using CrystalDecisions.Enterprise.Desktop;
using CrystalDecisions.Enterprise.Viewing;
using CrystalDecisions.ReportAppServer.Controllers;
namespace BOUtilities
{
public enum AuthenticationTypes
{
secEnterprise, //Enterprise
secWindowsNT //Windows NT
}
/**//// <summary>
/// 一个用户信息类,用于在BO中操作用户
/// </summary>
/// <remarks>
/// 创建人:南疯
/// 创建日期:2005年5月11日
/// </remarks>
public struct UserDataTransfer
{
/**//// <summary>
/// 登录用户名称
/// </summary>
public string AccountName;
/**//// <summary>
/// 用户全名
/// </summary>
public string FullName;
/**//// <summary>
/// 用户说明
/// </summary>
public string Description;
/**//// <summary>
/// 密码
/// </summary>
public string Password;
/**//// <summary>
/// 用户类型
/// </summary>
public int UserType;
/**//// <summary>
/// 密码是否立即失效
/// </summary>
public bool PasswordExpires;
/**//// <summary>
/// 下次登录是否需要更改密码
/// </summary>
public bool ChangePasswordAtNextLogon;
/**//// <summary>
/// 是否允许更改自己的密码
/// </summary>
public bool AllowChangePassword;
}
/**//// <summary>
/// BO的提示信息类
/// </summary>
public class BOMessages
{
public const string NOT_LOGON = "您还没有登录!";
public const string SUCCESS = "操作成功!";
public const string FAILURE = "操作失败!";
public const string NOT_ALLOWED = "您没有权限进行此操作!";
public const string FORMAT_NOT_SUPPORTED = "不支持本格式!";
public const string NO_MATCHES_FOUND = "没有找到匹配的项目!";
}
/**//// <summary>
/// BO的操作接口类
/// </summary>
/// <remarks>
/// 创建人:李涣
/// 创建日期:2007年5月11日
/// </remarks>
public class Utilities
{
/**//// <summary>
/// 登录信息对象
/// </summary>
private Identity _identity = null;
/**//// <summary>
/// 构造函数
/// </summary>
public Utilities()
{
_identity = new Identity();
}
/**//// <summary>
/// 析构函数
/// </summary>
~Utilities()
{
if (_identity != null)
{
if (_identity.IsLoggedOn)
{
_identity.Logoff();
_identity.ClearServices();
_identity.Dispose();
_identity = null;
}
}
}
/**//// <summary>
/// 登录用户的Token
/// </summary>
public string Token
{
get
{
if (_identity.IsLoggedOn)
{
return _identity.GetToken();
}
else
{
return null;
}
}
}
/**//// <summary>
/// 登录到BO服务器,在进行BO的各种操作之前,都必须先进行登录
/// </summary>
/// <param name="System">系统名称</param>
/// <param name="UserName">登录用户名称</param>
/// <param name="Password">登录密码</param>
/// <param name="AuthType">登录认证类型</param>
public bool Logon(string System, string UserName, string Password, AuthenticationTypes AuthType)
{
CrystalDecisions.Enterprise.Identity identity = new Identity();
bool Success = false;
switch (AuthType)
{
case AuthenticationTypes.secEnterprise:
Success = identity.Logon(UserName, Password, System, "Enterprise");
break;
case AuthenticationTypes.secWindowsNT:
Success = identity.Logon(UserName, Password, System, "Windows NT");
break;
default:
break;
}
if (Success)
{
_identity = identity;
}
return Success;
}
/**//// <summary>
/// 获取BO信息存储操作对象信息
/// </summary>
private InfoStore GetInfoStore()
{
if (_identity.IsLoggedOn)
{
return _identity.InfoStore;
}
else
{
throw new Exception(BOMessages.NOT_LOGON);
}
}
/**//// <summary>
/// 获取所有目录的列表
/// </summary>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetFolders()
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_ID, SI_NAME From CI_INFOOBJECTS "
+ "Where SI_KIND='Folder'";
InfoObjects infoObjects = infoStore.Query(query);
if (infoObjects.Count > 0)
{
foreach (InfoObject infoObject in infoObjects)
{
sortedList.Add(infoObject.ID, infoObject.Title);
}
}
else
{
sortedList.Add("0", "No folders found.");
}
return sortedList;
}
/**//// <summary>
/// 获取一个目录的ID
/// </summary>
/// <param name="folderName">目录名称</param>
/// <returns>返回目录的ID</returns>
public int GetFolderID(string folderName)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_ID FROM CI_INFOOBJECTS "
+ "Where SI_KIND='Folder' "
+ "And SI_NAME = '" + folderName + "'";
InfoObjects infoObjects = infoStore.Query(query);
if (infoObjects.Count > 0)
{
InfoObject infoObject = infoObjects[1];
int folderID = infoObject.ID;
return folderID;
}
else
{
throw new Exception(BOMessages.NO_MATCHES_FOUND);
}
}
/**//// <summary>
/// 增加一个目录
/// </summary>
/// <param name="parentFolderID">指定的父目录的ID,新增加的目录将作为这个父目录的儿子</param>
/// <param name="folderName">目录名称</param>
/// <param name="folderDescription">目录说明</param>
/// <returns>返回增加的目录的ID</returns>
public int AddFolder(int parentFolderID, string folderName, string folderDescription)
{
InfoStore infoStore = GetInfoStore();
InfoObjects infoObjects = infoStore.NewInfoObjectCollection();
PluginManager pluginManager = infoStore.PluginManager;
PluginInfo pluginInfo = pluginManager.GetPluginInfo("CrystalEnterprise.Folder");
InfoObject infoObject = infoObjects.Add(pluginInfo);
Folder folder = (Folder)infoObject;
folder.Title = folderName;
folder.Description = folderDescription;
folder.Properties.Add("SI_PARENTID", parentFolderID);
int folderID = folder.ID;
infoStore.Commit(infoObjects);
return folderID;
}
/**//// <summary>
/// 获取所有的报表
/// </summary>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetReports()
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS "
+ "Where SI_KIND='CrystalReport' "
+ "And SI_INSTANCE=0";
InfoObjects infoObjects = infoStore.Query(query);
if (infoObjects.Count > 0)
{
foreach (InfoObject infoObject in infoObjects)
{
sortedList.Add(infoObject.ID, infoObject.Title);
}
}
else
{
sortedList.Add("0", "No reports found.");
}
return sortedList;
}
/**//// <summary>
/// 增加一个报表
/// </summary>
/// <param name="folderID">增加报表所在的目录</param>
/// <param name="reportName">报表的名字</param>
public void AddReport(int folderID, string reportName)
{
InfoStore infoStore = GetInfoStore();
InfoObjects infoObjects = infoStore.NewInfoObjectCollection();
PluginManager pluginManager = infoStore.PluginManager;
PluginInfo pluginInfo = pluginManager.GetPluginInfo("CrystalEnterprise.Report");
InfoObject infoObject = infoObjects.Add(pluginInfo);
Report report = (Report)infoObject;
report.Files.Add(reportName);
report.Properties.Add("SI_PARENTID", folderID);
report.EnableThumbnail = true;
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 获取所有的用户信息
/// </summary>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetUsers()
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_ID, SI_NAME From CI_SYSTEMOBJECTS "
+ "Where SI_KIND='User'";
InfoObjects infoObjects = infoStore.Query(query);
foreach (InfoObject infoObject in infoObjects)
{
sortedList.Add(infoObject.ID, infoObject.Title);
}
return sortedList;
}
/**//// <summary>
/// 增加一个用户
/// </summary>
/// <param name="userDataTransfer">用户信息对象</param>
public void AddUser(UserDataTransfer userDataTransfer)
{
InfoStore infoStore = GetInfoStore();
PluginManager pluginManager = infoStore.PluginManager;
PluginInfo pluginInfo = pluginManager.GetPluginInfo("CrystalEnterprise.User");
InfoObjects infoObjects = infoStore.NewInfoObjectCollection();
infoObjects.Add(pluginInfo);
InfoObject infoObject = infoObjects[1];
CrystalDecisions.Enterprise.Desktop.User user =
(CrystalDecisions.Enterprise.Desktop.User)infoObject;
user.Title = userDataTransfer.AccountName;
user.Description = userDataTransfer.Description;
user.FullName = userDataTransfer.FullName;
user.Connection = (CeConnectionType)(userDataTransfer.UserType + 1);
user.PasswordExpires = userDataTransfer.PasswordExpires;
user.ChangePasswordAtNextLogon = userDataTransfer.ChangePasswordAtNextLogon;
user.AllowChangePassword = userDataTransfer.AllowChangePassword;
user.NewPassword = userDataTransfer.Password;
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 获取一个用户所在的所有组
/// </summary>
/// <param name="userID">用户ID</param>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetMemberGroups( string userID)
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select Top 1* From CI_SYSTEMOBJECTS "
+ "Where SI_ID=" + userID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
CrystalDecisions.Enterprise.Desktop.User user =
(CrystalDecisions.Enterprise.Desktop.User)infoObject;
Groups groups = user.Groups;
foreach (int group in groups)
{
query = "Select SI_NAME From CI_SYSTEMOBJECTS "
+ "Where SI_ID=" + group;
infoObjects = infoStore.Query(query);
infoObject = infoObjects[1];
sortedList.Add(infoObject.ID, infoObject.Title);
}
return sortedList;
}
/**//// <summary>
/// 把用户加入一个组
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="groupID">组ID</param>
public void AddUserToGroup( string userID, int groupID)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_ID From CI_SYSTEMOBJECTS "
+ "Where SI_ID=" + userID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
CrystalDecisions.Enterprise.Desktop.User user =
(CrystalDecisions.Enterprise.Desktop.User)infoObject;
Groups groups = user.Groups;
groups.Add(groupID);
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 把用户加入一个新组
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="groupName">新组的名称</param>
public void AddUserToNewGroup( string userID, string groupName)
{
InfoStore infoStore = GetInfoStore();
PluginManager pluginManager = infoStore.PluginManager;
PluginInfo pluginInfo = pluginManager.GetPluginInfo("CrystalEnterprise.UserGroup");
InfoObjects infoObjects = infoStore.NewInfoObjectCollection();
infoObjects.Add(pluginInfo);
InfoObject infoObject = infoObjects[1];
UserGroup userGroup = (UserGroup)infoObject;
userGroup.Title = groupName;
int userIDInt = Convert.ToInt32(userID);
userGroup.Users.Add(userIDInt);
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 从一个用户组中移除一个用户,注意,不删除用户
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="groupID">组ID</param>
public void RemoveUserFromGroup(string userID, string groupID)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_ID, SI_USERGROUPS From CI_SYSTEMOBJECTS "
+ "Where SI_ID=" + userID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
CrystalDecisions.Enterprise.Desktop.User user =
(CrystalDecisions.Enterprise.Desktop.User)infoObject;
Groups groups = user.Groups;
groups.Delete("#" + groupID);
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 删除一个用户
/// </summary>
/// <param name="userID">用户ID</param>
public void DeleteUser( string userID)
{
InfoStore infoStore = GetInfoStore();
string query = "Select * From CI_SYSTEMOBJECTS "
+ "Where SI_KIND='User' "
+ "And SI_ID=" + userID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
if (infoObject.Title != "Administrator")
{
infoObjects.Delete(infoObject);
infoStore.Commit(infoObjects);
}
else
{
throw new Exception(BOMessages.NOT_ALLOWED);
}
}
/**//// <summary>
/// 重置一个用户的密码
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="alternatePassword">新密码</param>
public void ResetUserPassword( string userID, string alternatePassword)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_NEW_PASSWORD From CI_SYSTEMOBJECTS "
+ "Where SI_KIND='User' "
+ "And SI_ID=" + userID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
CrystalDecisions.Enterprise.Desktop.User user =
(CrystalDecisions.Enterprise.Desktop.User)infoObject;
if (alternatePassword != "")
{
user.NewPassword = alternatePassword;
}
else
{
user.NewPassword = "NewPassword";
}
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 获取所有的用户组
/// </summary>
/// <returns>返回包含用键、值对的Dictionary</returns>
public IDictionary GetUserGroups()
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_ID, SI_NAME From CI_SYSTEMOBJECTS "
+ "Where SI_KIND='UserGroup'";
InfoObjects infoObjects = infoStore.Query(query);
foreach (InfoObject infoObject in infoObjects)
{
sortedList.Add(infoObject.ID, infoObject.Title);
}
return sortedList;
}
/**//// <summary>
/// 增加一个组
/// </summary>
/// <param name="name">组名称</param>
/// <param name="description">组说明</param>
public void AddUserGroup( string name, string description)
{
InfoStore infoStore = GetInfoStore();
PluginManager pluginManager = infoStore.PluginManager;
PluginInfo pluginInfo = pluginManager.GetPluginInfo("CrystalEnterprise.UserGroup");
InfoObjects infoObjects = infoStore.NewInfoObjectCollection();
infoObjects.Add(pluginInfo);
InfoObject infoObject = infoObjects[1];
UserGroup userGroup = (UserGroup)infoObject;
userGroup.Title = name;
userGroup.Description = description;
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 删除一个用户组
/// </summary>
/// <param name="userGroupID">组ID</param>
public void DeleteUserGroup( string userGroupID)
{
InfoStore infoStore = GetInfoStore();
string query = "Select * From CI_SYSTEMOBJECTS "
+ "Where SI_KIND='UserGroup' "
+ "And SI_ID=" + userGroupID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
UserGroup userGroup = (UserGroup)infoObject;
if (userGroup.Title != "Administrators")
{
infoObjects.Delete(userGroup);
infoStore.Commit(infoObjects);
}
else
{
throw new Exception(BOMessages.NOT_ALLOWED);
}
}
/**//// <summary>
/// 获取一个报表的所有用户
/// </summary>
/// <param name="reportID">报表ID</param>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetUsersForReport( string reportID)
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
ObjectPrincipals objectPrincipals = securityInfo.ObjectPrincipals;
foreach (ObjectPrincipal objectPrincipal in objectPrincipals)
{
sortedList.Add(objectPrincipal.ID, objectPrincipal.Name);
}
return sortedList;
}
/**//// <summary>
/// 获取用户对一个报表的权限
/// </summary>
/// <param name="reportID">报表ID</param>
/// <param name="userID">用户ID</param>
/// <returns>返回SecurityRights集合对象信息.</returns>
public SecurityRights GetCurrentRights(string reportID, string userID)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
ObjectPrincipals objectPrincipals = securityInfo.ObjectPrincipals;
ObjectPrincipal objectPrincipal = objectPrincipals["#" + userID];
SecurityRights securityRights = objectPrincipal.Rights;
return securityRights;
}
/**//// <summary>
/// 获取用户对一个报表的限制
/// </summary>
/// <param name="reportID">报表ID</param>
/// <param name="userID">用户ID</param>
/// <returns>返回SecurityLimits集合对象信息.</returns>
public SecurityLimits GetCurrentLimits( string reportID, string userID)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
ObjectPrincipals objectPrincipals = securityInfo.ObjectPrincipals;
ObjectPrincipal objectPrincipal = objectPrincipals["#" + userID];
SecurityLimits securityLimits = objectPrincipal.Limits;
return securityLimits;
}
/**//// <summary>
/// 获取一个报表的所有权限
/// </summary>
/// <param name="reportID">报表ID</param>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetAvailableRights( string reportID)
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
SecurityRights knownRights = securityInfo.KnownRights;
foreach (SecurityRight securityRight in knownRights)
{
sortedList.Add(securityRight.ID, securityRight.Description);
}
return sortedList;
}
/**//// <summary>
/// 获取一个报表的所有限制
/// </summary>
/// <param name="reportID">报表ID</param>
/// <returns>返回包含用键、值对的Dictionary.</returns>
public IDictionary GetAvailableLimits( string reportID)
{
InfoStore infoStore = GetInfoStore();
IDictionary sortedList = new SortedList();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
SecurityLimits knownLimits = securityInfo.KnownLimits;
foreach (SecurityLimit securityLimit in knownLimits)
{
sortedList.Add(securityLimit.ID, securityLimit.Description);
}
return sortedList;
}
/**//// <summary>
/// 为一个报表的一个用户增加一个权限
/// </summary>
/// <param name="reportID">报表ID</param>
/// <param name="userID">用户ID</param>
/// <param name="rightID">权限ID</param>
/// <param name="granted">1 授权, 0 拒绝.</param>
public void AddRight( string reportID, string userID, int rightID, string granted)
{
InfoStore infoStore = GetInfoStore();
bool isGranted = false;
if (granted.Equals("1"))
{
isGranted = true;
}
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
ObjectPrincipals objectPrincipals = securityInfo.ObjectPrincipals;
ObjectPrincipal objectPrincipal = objectPrincipals["#" + userID];
SecurityRights securityRights = objectPrincipal.Rights;
SecurityRight securityRight = securityRights.Add(rightID);
securityRight.Granted = isGranted;
infoStore.Commit(infoObjects);
}
/**//// <summary>
/// 为一个报表的一个用户增加一个限制
/// </summary>
/// <param name="reportID">报表的ID</param>
/// <param name="userID">用户的ID</param>
/// <param name="limitID">指定的限制ID</param>
/// <param name="newValue">限制的值</param>
public void AddLimit( string reportID, string userID, int limitID, int newValue)
{
InfoStore infoStore = GetInfoStore();
string query = "Select SI_NAME, SI_ID From CI_INFOOBJECTS Where SI_ID=" + reportID;
InfoObjects infoObjects = infoStore.Query(query);
InfoObject infoObject = infoObjects[1];
Report report = (Report)infoObject;
SecurityInfo securityInfo = report.SecurityInfo;
ObjectPrincipals objectPrincipals = securityInfo.ObjectPrincipals;
ObjectPrincipal objectPrincipal = objectPrincipals["#" + userID];
SecurityLimits securityLimits = objectPrincipal.Limits;
SecurityLimit securityLimit = securityLimits.Add(limitID, newValue);
infoStore.Commit(infoObjects);
}
}
}