/// <summary>
        /// 获取能访问的字段列表
        /// </summary>
        /// <param name="userId">用户代码</param>
        /// <param name="tableCode">表名</param>
        /// <returns>数据表</returns>
        public DataTable GetTableColumns(string userId, string tableCode)
        {
            // 当前用户对哪些资源有权限(用户自己的权限 + 相应的角色拥有的权限)
            PiPermissionScopeManager permissionScopeManager = new PiPermissionScopeManager(DBProvider, UserInfo);

            string[] ids = permissionScopeManager.GetResourceScopeIds(userId, "TableColumns", "ColumnAccess");

            // 获取有效的,没删除标志的
            string sqlQuery = " SELECT * FROM " + CiTableColumnsTable.TableName + " WHERE (" + CiTableColumnsTable.FieldDeleteMark + " = 0 AND " + CiTableColumnsTable.FieldEnabled + " = 1) ";

            // 是否指定了表名
            if (!string.IsNullOrEmpty(tableCode))
            {
                sqlQuery += " AND (" + CiTableColumnsTable.FieldTableCode + "= '" + tableCode + "') ";
            }

            // 公开的或者按权限来过滤字段
            sqlQuery += " AND (" + CiTableColumnsTable.FieldIsPublic + " = 1 ";
            if (ids != null && ids.Length > 0)
            {
                string idList = BusinessLogic.ArrayToList(ids, "'");
                sqlQuery += " OR " + CiTableColumnsTable.FieldId + " IN (" + idList + ")";
            }
            sqlQuery += ") ORDER BY " + CiTableColumnsTable.FieldSortCode;

            return(DBProvider.Fill(sqlQuery));
        }
        /// <summary>
        /// 获取用户有权限访问的模块主键
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <returns>主键数组</returns>
        public string[] GetIDsByUser(string userId)
        {
            // 公开的模块谁都可以访问
            string[] openModuleIds = null;

            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(PiModuleTable.FieldIsPublic, 1),
                new KeyValuePair <string, object>(PiModuleTable.FieldEnabled, 1),
                new KeyValuePair <string, object>(PiModuleTable.FieldDeleteMark, 0)
            };

            openModuleIds = this.GetIds(parameters);

            string[] twoModuleIds = null;

            if (!string.IsNullOrEmpty(userId))
            {
                // 按第一个解决方案进行计算 (用户 ---> 权限 --- 权限 <--- 菜单)
                // 获取用户的所有权限ID数组
                // PiPermissionManager permissionManager = new PiPermissionManager(DBProvider, UserInfo);
                // DataTable dtPermission = permissionManager.GetPermissionByUser(UserInfo.Id);
                // string[] permissionItemIds = BusinessLogic.FieldToArray(dtPermission, BasePermissionItemEntity.FieldId);

                /*
                 * string[] oneModuleIds = new string[0];
                 * if ((permissionItemIds != null) && (permissionItemIds.Length > 0))
                 * {
                 *  // 获取所有跟这个权限有关联的模块ID数组
                 *  string sqlQuery = string.Empty;
                 *  sqlQuery = " SELECT " + PiPermissionTable.FieldResourceId
                 + "   FROM " + PiPermissionTable.TableName
                 + "  WHERE " + PiPermissionTable.FieldResourceCategory + " = '" + PiModuleTable.TableName + "' "
                 + "        AND " + PiPermissionTable.FieldPermissionId + " IN (" + BusinessLogic.ObjectsToList(permissionItemIds) + ")";
                 +
                 +  dtPermission = DBProvider.Fill(sqlQuery);
                 +  oneModuleIds = BusinessLogic.FieldToArray(dtPermission, PiPermissionTable.FieldResourceId);
                 + }
                 */

                //按第二个解决方案进行计算 (用户 ---> 模块访问权限 ---> 菜单)
                string tableName = PiPermissionScopeTable.TableName;
                PiPermissionScopeManager permissionScopeManager = new PiPermissionScopeManager(DBProvider, UserInfo, tableName);
                // 模块访问,连同用户本身的,还有角色的,全部获取出来
                string permissionItemCode = "Resource.AccessPermission";
                twoModuleIds = permissionScopeManager.GetResourceScopeIds(userId, PiModuleTable.TableName, permissionItemCode);

                // 这些模块是有效的才可以
                parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(PiModuleTable.FieldId, twoModuleIds),
                    new KeyValuePair <string, object>(PiModuleTable.FieldEnabled, 1),
                    new KeyValuePair <string, object>(PiModuleTable.FieldDeleteMark, 0)
                };
                twoModuleIds = this.GetProperties(parameters, PiModuleTable.FieldId);
            }
            // 返回相应的模块列表
            string[] moduleIds = BusinessLogic.Concat(openModuleIds, twoModuleIds);
            return(moduleIds);
        }
 /// <summary>
 /// 获取用户的列权限
 /// </summary>
 /// <param name="userId">用户主键</param>
 /// <param name="tableCode">表名</param>
 /// <param name="permissionCode">操作权限</param>
 /// <returns>有权限的列数组</returns>
 public string[] GetColumns(string userId, string tableCode, string permissionCode = "Column.Access")
 {
     // Column.Edit
     string[] returnValue = null;
     if (permissionCode.Equals("Column.Deney") || permissionCode.Equals("Column.Edit"))
     {
         // 按数据权限来过滤数据
         PiPermissionScopeManager permissionScopeManager = new PiPermissionScopeManager(DBProvider, UserInfo);
         returnValue = permissionScopeManager.GetResourceScopeIds(userId, tableCode, permissionCode);
     }
     else if (permissionCode.Equals("Column.Access"))
     {
         // 1: 用户有权限的列名
         PiPermissionScopeManager permissionScopeManager = new PiPermissionScopeManager(DBProvider, UserInfo);
         returnValue = permissionScopeManager.GetResourceScopeIds(userId, tableCode, permissionCode);
         // 2: 先获取公开的列名
         string[] publicIds = this.GetIds(CiTableColumnsTable.FieldTableCode, tableCode, CiTableColumnsTable.FieldIsPublic, 1, CiTableColumnsTable.FieldColumnCode);
         returnValue = BusinessLogic.Concat(returnValue, publicIds);
     }
     return(returnValue);
 }
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDT(UserInfo userInfo)
        {
            var dataTable = new DataTable(CiItemsTable.TableName);
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.ItemsService_GetDT);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var itemsManager = new CiItemsManager(dbProvider, userInfo);
                // 若是系统管理员,那就返回全部数据
                if (userInfo.IsAdministrator)
                {
                    dataTable = itemsManager.GetDT(CiItemsTable.FieldDeleteMark, 0, CiItemsTable.FieldSortCode);
                }
                else
                {
                    // 按数据权限来过滤数据
                    var permissionScopeManager = new PiPermissionScopeManager(dbProvider, userInfo);
                    string[] ids = permissionScopeManager.GetResourceScopeIds(userInfo.Id, CiItemsTable.TableName, "Resource.ManagePermission");
                    dataTable    = itemsManager.GetDT(ids);
                }
                dataTable.TableName = CiItemsTable.TableName;
            });
            return(dataTable);
        }