コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(this.Request.QueryString["nodeid"], out this.nodeId))
            {
                this.Response.Write("<script>alert('参数错误!');</script>");
                this.Response.Write("<script>window.location = 'node_manager.aspx';</script>");
                return;
            }

            this.nodeManager = new NodeManager("EFConnectionString");
            this.node = this.nodeManager.Get(this.nodeId);
            StringDictionary roles = (this.Master as AdminLayout).UserRoles;

            if (!nodeManager.CheckNodeRole(node, roles, ActionType.ManageNode))
            {
                this.Response.Write("<script>alert('无权限!');</script>");
                this.Response.Write("<script>window.location = 'node_manager.aspx';</script>");
                return;
            }

            if (!this.IsPostBack)
            {
                this.nodeName.Text = this.node.NodeName;
                this.imagePath.Text = this.node.ImagePath;
                this.needAudit.Checked = this.node.NeedAudit;
                this.comment.Text = this.node.Comment;
                this.enable.Checked = this.node.Enable;

                this.addNodeLink.NavigateUrl += this.nodeId.ToString();
            }
        }
コード例 #2
0
ファイル: NodeManager.cs プロジェクト: suyuxuan/eFramework
        bool CheckNodeAncestorsRole(NodeEntity node, StringDictionary roles, string roleName)
        {
            for (int i = 0; i < node.FullIds.Length; i++)
            {
                if (roles.ContainsKey(node.FullIds[i].ToString() + roleName))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
ファイル: NodeManager.cs プロジェクト: suyuxuan/eFramework
        /// <summary>
        /// 获取全部节点的KV集合。
        /// </summary>
        /// <returns>节点的KV集合。</returns>
        public Dictionary <int, NodeEntity> GetAll()
        {
            Dictionary <int, NodeEntity> nodes = new Dictionary <int, NodeEntity>();

            using (IDataReader reader = this.db.ExcuteReader(CommandType.StoredProcedure, "EF_Node_GetAll"))
            {
                while (reader.Read())
                {
                    NodeEntity node = this.PopulateNode(reader);
                    nodes.Add(node.NodeId, node);
                }
            }

            return(nodes);
        }
コード例 #4
0
ファイル: add_node.aspx.cs プロジェクト: adamchuan/eFramework
        protected void addNodeButton_Click(object sender, EventArgs e)
        {
            NodeEntity node = new NodeEntity()
            {
                ParentId = this.parentId,
                NodeName = this.nodeName.Text,
                ImagePath = this.imagePath.Text.Trim(),
                NeedAudit = this.needAudit.Checked,
                Comment = this.comment.Text,
                Enable = this.enable.Checked,
                ApplicationId = 3
            };

            this.nodeManager.Add(node);
            this.Response.Redirect("node_manager.aspx");
        }
コード例 #5
0
ファイル: NodeManager.cs プロジェクト: suyuxuan/eFramework
        NodeEntity PopulateNode(IDataReader reader)
        {
            NodeEntity node = new NodeEntity()
            {
                NodeId             = (int)reader["NodeId"],
                NodeName           = reader["NodeName"].ToString(),
                ParentId           = (int)reader["ParentId"],
                FullIdsStringType  = reader["FullIds"].ToString(),
                ChildIdsStringType = reader["ChildIds"].ToString(),
                ApplicationId      = (int)reader["ApplicationId"],
                ImagePath          = reader["ImagePath"].ToString(),
                NeedAudit          = (bool)reader["NeedAudit"],
                Comment            = reader["Comment"].ToString(),
                Enable             = (bool)reader["Enable"]
            };

            return(node);
        }
コード例 #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(this.Request.QueryString["nodeid"], out nodeId))
            {
                this.Response.Write("<script>alert('参数错误!');</script>");
                this.Response.Write("<script>window.location = 'add_info.aspx';</script>");
                return;
            }

            NodeManager nodeManager = new NodeManager("EFConnectionString");
            this.node = nodeManager.Get(this.nodeId);
            StringDictionary roles = (this.Master as AdminLayout).UserRoles;

            if (!nodeManager.CheckNodeRole(node, roles, ActionType.AddInfo))
            {
                this.Response.Write("<script>alert('无权限!');</script>");
                this.Response.Write("<script>window.location = 'add_info.aspx';</script>");
                return;
            }
        }
コード例 #7
0
ファイル: NodeManager.cs プロジェクト: suyuxuan/eFramework
        /// <summary>
        /// 获取一个节点。
        /// </summary>
        /// <param name="nodeId">节点Id。</param>
        /// <returns>欲获取的节点。</returns>
        public NodeEntity Get(int nodeId)
        {
            Contract.Requires(nodeId > 0);

            IDataParameter[] parameters = new IDataParameter[1];
            parameters[0] = this.db.NewDataParameter("@NodeId", nodeId);

            NodeEntity node;

            using (IDataReader reader = this.db.ExcuteReader(CommandType.StoredProcedure, "EF_Node_Get", parameters))
            {
                if (reader.Read())
                {
                    node = this.PopulateNode(reader);
                }
                else
                {
                    node = new NodeEntity();
                }
            }

            return(node);
        }
コード例 #8
0
ファイル: NodeManager.cs プロジェクト: adamchuan/eFramework
        /// <summary>
        /// 检验是否具有指定节点的指定动作的权限。
        /// </summary>
        /// <param name="node">待检查节点。</param>
        /// <param name="roles">权限字典。</param>
        /// <param name="actionType">动作的类型。</param>
        /// <returns>是否具有权限。</returns>
        public bool CheckNodeRole(NodeEntity node, StringDictionary roles, ActionType actionType)
        {
            if (roles.ContainsKey("Administrator"))
            {
                return true;
            }
            else if (actionType == ActionType.AddInfo)
            {
                if (roles.ContainsKey("ContentAdmin") || this.CheckNodeAncestorsRole(node, roles, "Admin") || this.CheckNodeAncestorsRole(node, roles, "Author"))
                {
                    return true;
                }
            }
            else if (actionType == ActionType.ManageInfo)
            {
                if (roles.ContainsKey("ContentAdmin") || this.CheckNodeAncestorsRole(node, roles, "Admin"))
                {
                    return true;
                }
            }
            else if (actionType == ActionType.ManageRole)
            {
                if (roles.ContainsKey("MemberAdmin"))
                {
                    return true;
                }
            }
            else if (actionType == ActionType.ManageNode)
            {
                if (roles.ContainsKey("ContentAdmin") || this.CheckNodeAncestorsRole(node, roles, "Admin"))
                {
                    return true;
                }
            }

            return false;
        }
コード例 #9
0
ファイル: NodeManager.cs プロジェクト: suyuxuan/eFramework
        /// <summary>
        /// 检验是否具有指定节点的指定动作的权限。
        /// </summary>
        /// <param name="node">待检查节点。</param>
        /// <param name="roles">权限字典。</param>
        /// <param name="actionType">动作的类型。</param>
        /// <returns>是否具有权限。</returns>
        public bool CheckNodeRole(NodeEntity node, StringDictionary roles, ActionType actionType)
        {
            if (roles.ContainsKey("Administrator"))
            {
                return(true);
            }
            else if (actionType == ActionType.AddInfo)
            {
                if (roles.ContainsKey("ContentAdmin") || this.CheckNodeAncestorsRole(node, roles, "Admin") || this.CheckNodeAncestorsRole(node, roles, "Author"))
                {
                    return(true);
                }
            }
            else if (actionType == ActionType.ManageInfo)
            {
                if (roles.ContainsKey("ContentAdmin") || this.CheckNodeAncestorsRole(node, roles, "Admin"))
                {
                    return(true);
                }
            }
            else if (actionType == ActionType.ManageRole)
            {
                if (roles.ContainsKey("MemberAdmin"))
                {
                    return(true);
                }
            }
            else if (actionType == ActionType.ManageNode)
            {
                if (roles.ContainsKey("ContentAdmin") || this.CheckNodeAncestorsRole(node, roles, "Admin"))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #10
0
ファイル: NodeManager.cs プロジェクト: adamchuan/eFramework
        /// <summary>
        /// 添加一个节点。
        /// </summary>
        /// <param name="node">待添加的节点。</param>
        public void Add(NodeEntity node)
        {
            Contract.Requires(node != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(node.NodeName));
            Contract.Requires(node.ParentId > 0);
            Contract.Requires(node.ApplicationId > 0);

            IDataParameter[] parameters = new IDataParameter[7];

            parameters[0] = this.db.NewDataParameter("@NodeName", node.NodeName);
            parameters[1] = this.db.NewDataParameter("@ParentId", node.ParentId);
            parameters[2] = this.db.NewDataParameter("@ApplicationId", node.ApplicationId);
            parameters[3] = this.db.NewDataParameter("@ImagePath", node.ImagePath);
            parameters[4] = this.db.NewDataParameter("@NeedAudit", node.NeedAudit);
            parameters[5] = this.db.NewDataParameter("@Comment", node.Comment);
            parameters[6] = this.db.NewDataParameter("@Enable", node.Enable);

            int result = this.db.ExecuteNonQuery(CommandType.StoredProcedure, "EF_Node_Add", parameters);

            if (result == 0)
            {
                throw new Exception("新建节点失败!");
            }
        }
コード例 #11
0
ファイル: NodeManager.cs プロジェクト: suyuxuan/eFramework
        /// <summary>
        /// 更新一个节点。
        /// </summary>
        /// <param name="node">待更新的节点。</param>
        public void Update(NodeEntity node)
        {
            Contract.Requires(node != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(node.NodeName));
            Contract.Requires(node.ParentId > 0);
            Contract.Requires(node.ApplicationId > 0);

            IDataParameter[] parameters = new IDataParameter[7];

            parameters[0] = this.db.NewDataParameter("@NodeId", node.NodeId);
            parameters[1] = this.db.NewDataParameter("@NodeName", node.NodeName);
            parameters[2] = this.db.NewDataParameter("@ApplicationId", node.ApplicationId);
            parameters[3] = this.db.NewDataParameter("@ImagePath", node.ImagePath);
            parameters[4] = this.db.NewDataParameter("@NeedAudit", node.NeedAudit);
            parameters[5] = this.db.NewDataParameter("@Comment", node.Comment);
            parameters[6] = this.db.NewDataParameter("@Enable", node.Enable);

            int result = this.db.ExecuteNonQuery(CommandType.StoredProcedure, "EF_Node_Update", parameters);

            if (result == 0)
            {
                throw new Exception("更新节点失败!");
            }
        }
コード例 #12
0
ファイル: NodeManager.cs プロジェクト: adamchuan/eFramework
        NodeEntity PopulateNode(IDataReader reader)
        {
            NodeEntity node = new NodeEntity()
            {
                NodeId = (int)reader["NodeId"],
                NodeName = reader["NodeName"].ToString(),
                ParentId = (int)reader["ParentId"],
                FullIdsStringType = reader["FullIds"].ToString(),
                ChildIdsStringType = reader["ChildIds"].ToString(),
                ApplicationId = (int)reader["ApplicationId"],
                ImagePath = reader["ImagePath"].ToString(),
                NeedAudit = (bool)reader["NeedAudit"],
                Comment = reader["Comment"].ToString(),
                Enable = (bool)reader["Enable"]
            };

            return node;
        }
コード例 #13
0
ファイル: NodeManager.cs プロジェクト: adamchuan/eFramework
        bool CheckNodeAncestorsRole(NodeEntity node, StringDictionary roles, string roleName)
        {
            for (int i = 0; i < node.FullIds.Length; i++)
            {
                if (roles.ContainsKey(node.FullIds[i].ToString() + roleName))
                {
                    return true;
                }
            }

            return false;
        }
コード例 #14
0
ファイル: NodeManager.cs プロジェクト: adamchuan/eFramework
        /// <summary>
        /// 获取一个节点。
        /// </summary>
        /// <param name="nodeId">节点Id。</param>
        /// <returns>欲获取的节点。</returns>
        public NodeEntity Get(int nodeId)
        {
            Contract.Requires(nodeId > 0);

            IDataParameter[] parameters = new IDataParameter[1];
            parameters[0] = this.db.NewDataParameter("@NodeId", nodeId);

            NodeEntity node;

            using (IDataReader reader = this.db.ExcuteReader(CommandType.StoredProcedure, "EF_Node_Get", parameters))
            {
                if (reader.Read())
                {
                    node = this.PopulateNode(reader);
                }
                else
                {
                    node = new NodeEntity();
                }
            }

            return node;
        }