/// <summary>
        /// 获取用户项目来源权限(仅用于权限分配)
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static List <RightItem> GetUserProjectSourceRights(int userId)
        {
            string cmdText = @"select ProjectSource,if(sum(FromRole)>0,1,0) FromRole  
                               from (
                                   select ProjectSource,0 FromRole from R_UserProjectSourceRights where `UserID`=?UserID
                                   union all
                                   select ProjectSource,1 FromRole from R_UserRoles A inner join R_RoleProjectSourceRights B on A.RoleID=B.RoleID and A.`UserID`=?UserID) A
                               group by ProjectSource";

            MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("?UserID", userId) };
            List <RightItem> items      = new List <RightItem>();

            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(DACommonHelper.ConnectionString, cmdText, parameters))
            {
                while (reader.Read())
                {
                    RightItem r = new RightItem
                    {
                        RightID  = Convert.ToInt32(reader["ProjectSource"]),
                        FromRole = Convert.ToInt32(reader["FromRole"]) == 1
                    };
                    items.Add(r);
                }
            }
            return(items);
        }
        /// <summary>
        /// 获取用户权限(仅用于权限分配)
        /// </summary>
        /// <param name="sysId"></param>
        /// <param name="userId"></param>
        /// <param name="accountType"></param>
        /// <returns></returns>
        public static List <RightItem> GetUserRights(int sysId, int userId, UserTypeOptions accountType)
        {
            string cmdText;

            //渠道相关的用户只能限于角色(系统定义的)关联的权限
            if (accountType == UserTypeOptions.Channel || accountType == UserTypeOptions.ChannelPartner)
            {
                cmdText = string.Format(@"select distinct C.RightID,1 FromRole 
                                        from R_UserRoles A 
                                            inner join R_Roles B on A.RoleID=B.ID and B.RoleType={0} and A.`UserID`=?UserID and B.SysID=?SysID 
                                            inner join R_RoleRights C on B.ID=C.RoleID",
                                        accountType == UserTypeOptions.Channel
                                            ? (int)RoleTypeOptions.Channel
                                            : (int)RoleTypeOptions.ChannelPartner);
            }
            else
            {
                cmdText = @"select RightID,if(sum(FromRole)>0,1,0) FromRole  
                            from (
                                select RightID,0 FromRole from R_UserRights A inner join R_Rights B on A.RightID=B.ID and B.SysID=?SysID and A.`UserID`=?UserID
                                union all
                                select RightID,1 FromRole from R_UserRoles A inner join R_Roles B on A.RoleID=B.ID and B.SysID=?SysID and A.`UserID`=?UserID inner join R_RoleRights C on A.RoleID=C.RoleID) A
                            group by RightID";
            }
            MySqlParameter[] parms = new MySqlParameter[]
            {
                new MySqlParameter("?SysID", sysId),
                new MySqlParameter("?UserID", userId)
            };
            List <RightItem> items = new List <RightItem>();

            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(DACommonHelper.ConnectionString, cmdText, parms))
            {
                while (reader.Read())
                {
                    RightItem r = new RightItem
                    {
                        RightID  = Convert.ToInt32(reader["RightID"]),
                        FromRole = Convert.ToInt32(reader["FromRole"]) == 1
                    };
                    items.Add(r);
                }
            }
            return(items);
        }
        /// <summary>
        /// 获取角色项目来源权限(仅用于权限分配)
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public static List <RightItem> GetRoleProjectSourceRights(int roleId)
        {
            string cmdText = @"select ProjectSource,0 FromRole from R_RoleProjectSourceRights where RoleID=?RoleID";

            MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("?RoleID", roleId) };
            List <RightItem> items      = new List <RightItem>();

            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(DACommonHelper.ConnectionString, cmdText, parameters))
            {
                while (reader.Read())
                {
                    RightItem r = new RightItem
                    {
                        RightID  = Convert.ToInt32(reader["ProjectSource"]),
                        FromRole = Convert.ToInt32(reader["FromRole"]) == 1
                    };
                    items.Add(r);
                }
            }
            return(items);
        }
        /// <summary>
        /// 获取用户资源权限
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static List <RightItem> GetUserResRights(int userId)
        {
            string cmdText = "SELECT ResID,0 FromRole FROM R_UserResRights WHERE `UserID`=?UserID";

            MySqlParameter[] parameters = new MySqlParameter[] { new MySqlParameter("?UserID", userId) };
            List <RightItem> items      = new List <RightItem>();

            using (MySqlDataReader reader = MySqlHelper.ExecuteReader(DACommonHelper.ConnectionString, cmdText, parameters))
            {
                while (reader.Read())
                {
                    RightItem r = new RightItem
                    {
                        RightID  = Convert.ToInt32(reader["ResID"]),
                        FromRole = Convert.ToInt32(reader["FromRole"]) == 1
                    };
                    items.Add(r);
                }
            }
            return(items);
        }