示例#1
0
        /// <summary>
        /// 设置权限
        /// </summary>
        public void SetPermission()
        {
            string isChecked    = Request["IsChecked"].ToString();
            int    roleId       = Convert.ToInt32(Request["RoleId"].ToString());
            string permissionId = Request["PermissionId"].ToString();

            //如果为true,则添加权限
            if (isChecked == "true")
            {
                RolePermissionAccess.GetInstance().AddPermission(roleId, permissionId);
            }
            else
            {
                RolePermissionAccess.GetInstance().DeletePermission(roleId, permissionId);
            }
        }
示例#2
0
        /// <summary>
        /// 设置权限树
        /// </summary>
        public void SetPermissionTree()
        {
            int    roleId    = Convert.ToInt32(Server.UrlDecode(Request["RoleId"].ToString()));
            string resultStr = string.Empty;

            List <string> lsP = new List <string>();

            lsP = PermissionAccess.GetInstance().GetParentPermission();
            //此处省略得到数据列表的代码
            resultStr  = "";
            resultStr += "[";
            foreach (string item in lsP)
            {
                resultStr += "{";

                List <PermissionEntity> lsC = new List <PermissionEntity>();
                lsC = PermissionAccess.GetInstance().GetChildPermission(item);
                //如果某变电站下有线路
                if (lsC.Count > 0)
                {
                    resultStr += string.Format("\"id\": \"{0}\", \"text\": \"{1}\", \"state\": \"closed\"", item, item);
                    resultStr += ",\"children\":[";

                    for (int i = 0; i < lsC.Count; i++)
                    {
                        resultStr += "{";
                        resultStr += string.Format("\"id\": \"{0}\", \"text\": \"{1}\",\"checked\":{2} ", lsC[i].PermissionId, lsC[i].OperationName, RolePermissionAccess.GetInstance().IsPermissionOn(roleId, lsC[i].PermissionId) == null ? "false" : "true");
                        resultStr += "},";
                    }
                    resultStr  = resultStr.Substring(0, resultStr.Length - 1);
                    resultStr += "]";
                }
                else
                {
                    resultStr += string.Format("\"id\": \"{0}\", \"text\": \"{1}\" ", item, item);
                }
                resultStr += "},";
            }

            resultStr  = resultStr.Substring(0, resultStr.Length - 1);
            resultStr += "]";

            Response.Write(resultStr);
        }