Esempio n. 1
0
        /// <summary>
        /// 显示组的权限
        /// </summary>
        /// <param name="detailGroupAuths"></param>
        public void ShowGroupAutority(DataTable detailGroupAuths)
        {
            try
            {
                _treeAuthority.AfterCheck -= new TreeViewEventHandler(OnTreeAuthorityAfterCheck);
                //一级结点,模块的主菜单
                foreach (TreeNode node in _treeAuthority.Nodes)
                {
                    AuthNodeTag tag = node.Tag as AuthNodeTag;
                    if (tag.MenuItem.Tag != null && tag.MenuItem.Tag is MenuItemTag)
                    {
                        int     moduleTag = (tag.MenuItem.Tag as MenuItemTag).ModuleID;
                        DataRow row       = GetDataRowByMenuName(detailGroupAuths, moduleTag, tag.AuthID);
                        tag.DataRow  = row;
                        node.Checked = row != null;

                        if (node.Nodes.Count > 0)
                        {
                            ShowGroupAuthorityChild(node, detailGroupAuths);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
            finally
            {
                _treeAuthority.AfterCheck += new TreeViewEventHandler(OnTreeAuthorityAfterCheck);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 显示组的权限,ShowGroupAutority方法的子程序
        /// </summary>
        /// <param name="node"></param>
        /// <param name="detailGroupAuths"></param>
        private void ShowGroupAuthorityChild(TreeNode node, DataTable detailGroupAuths)
        {
            foreach (TreeNode n in node.Nodes)
            {
                AuthNodeTag tag = n.Tag as AuthNodeTag;

                if (tag.MenuItem.Tag != null && tag.MenuItem.Tag is MenuItemTag)
                {
                    int     moduleID = (tag.MenuItem.Tag as MenuItemTag).ModuleID;
                    DataRow row      = GetDataRowByMenuName(detailGroupAuths, moduleID, tag.AuthID);
                    tag.DataRow = row;
                    n.Checked   = row != null;
                    if (n.Checked)
                    {
                        this.TreeNodeParentSelected(n, true);
                    }

                    if (tag.MenuType == MenuType.DataForm)//show the business Actions
                    {
                        ShowAction(n, row);
                    }
                    else
                    if (n.Nodes.Count > 0)
                    {
                        ShowGroupAuthorityChild(n, detailGroupAuths);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 递归处理子结点,GetGroupAuthorityChanges方法的子程序。
        /// </summary>
        /// <param name="node">父结点</param>
        /// <param name="auths">树视图绑定的权限数据</param>
        private void GetGroupAuthorityChangesChild(TreeNode node, DataTable auths)
        {
            foreach (TreeNode n in node.Nodes)
            {
                if ((n.Tag == null) || (!(n.Tag is AuthNodeTag)))
                {
                    continue;                           //非菜单项.
                }
                AuthNodeTag tag = n.Tag as AuthNodeTag; //树结点的引用对象

                if (tag.DataRow == null && n.Checked)   // 此结点是新增的,勾选状态
                {
                    AddAuthority(auths, n);
                }
                else if (tag.DataRow != null && n.Checked)                                  //处理勾选状态的结点
                {
                    int changed = GetActions(n);                                            //累加权限值
                    int oringed = int.Parse(tag.DataRow[TUserRole.Authorities].ToString()); //取原始权限值
                    if (changed != oringed)
                    {
                        tag.DataRow[TUserRole.Authorities] = changed;                    //如权限有修改,更新最新的权限值
                    }
                }
                else if (tag.DataRow != null && !n.Checked) //结点非勾选状态,表示已删除
                {
                    tag.DataRow.Delete();                   //删除资料行
                }
                if (n.Nodes.Count > 0)
                {
                    GetGroupAuthorityChangesChild(n, auths);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 枚举树视图,生成保存用的临时数据。
        /// 思路:枚举树视图中所有树结点,跟据树结点的操作状态(新增,修改)生成资料行(DataRow)
        ///        新增:结点没绑定DataRow且结点打勾. 为新增权限
        ///        修改: 结点有绑定DataRow且结点没有打勾. 为删除权限
        /// </summary>
        /// <param name="auths">树视图绑定的权限数据</param>
        /// <returns></returns>
        private DataTable GetGroupAuthorityChanges(DataTable auths)
        {
            foreach (TreeNode node in _treeAuthority.Nodes)
            {
                AuthNodeTag tag = node.Tag as AuthNodeTag;

                //结点没绑定DataRow且结点打勾. 为新增权限
                if (tag.DataRow == null && node.Checked)
                {
                    AddAuthority(auths, node);
                }

                //结点有绑定DataRow且结点没有打勾. 为删除权限
                else if (tag.DataRow != null && !node.Checked)
                {
                    tag.DataRow.Delete();
                }

                //递归处理子结点
                if (node.Nodes.Count > 0)
                {
                    GetGroupAuthorityChangesChild(node, auths);
                }
            }

            //返回修改的记录
            DataTable ret = auths.GetChanges();

            return(ret == null?auths.Clone() : ret);
        }
Esempio n. 5
0
        /// <summary>
        /// 生成权限管理树视图 - 第一级树结点
        /// </summary>
        public void InitAuthorityTree()
        {
            try
            {
                //取按钮自定义名称数据表
                _FormTagCustomName = _MyBridge.GetFormTagCustomName();

                this._treeAuthority.BeforeCheck += new TreeViewCancelEventHandler(OnTreeAuthorityBeforeCheck);
                this._treeAuthority.AfterCheck  -= new TreeViewEventHandler(OnTreeAuthorityAfterCheck);
                this._treeAuthority.Nodes.Clear();
                this._treeAuthority.BeginUpdate();

                IMdiForm mainForm = (IMdiForm)_treeAuthority.FindForm().ParentForm;//取MDI主窗体的主菜单

                //枚举主窗体的菜单
                foreach (ToolStripItem item in mainForm.MainMenu.Items)
                {
                    if (item is ToolStripSeparator)
                    {
                        continue;                             //菜单分隔符不处理
                    }
                    if (item.Tag != null && item.Tag.ToString().ToUpper() == "IsSystemMenu".ToUpper())
                    {
                        continue;                                                                                //系统菜单不处理
                    }
                    if (!Loginer.CurrentUser.IsAdmin() && !item.Enabled)
                    {
                        continue;                                                  //没菜单权限(菜单不可用).不加载树
                    }
                    AuthNodeTag tag = new AuthNodeTag(item.Name, null, item);

                    TreeNode node = new TreeNode(item.Text, 0, 0);
                    node.ImageIndex         = 0;
                    node.SelectedImageIndex = 0;
                    node.Tag = tag; //标记

                    this._treeAuthority.Nodes.Add(node);

                    //处理子菜单
                    if (item is ToolStripMenuItem && (item as ToolStripMenuItem).DropDownItems.Count > 0)
                    {
                        InitAuthorityTreeChild(item as ToolStripMenuItem, node);
                        node.Expand();
                    }
                }

                this._treeAuthority.EndUpdate();
                if (this._treeAuthority.Nodes.Count == 1)
                {
                    this._treeAuthority.Nodes[0].Expand();
                }
            }
            finally
            {
                this._treeAuthority.AfterCheck += new TreeViewEventHandler(OnTreeAuthorityAfterCheck);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 生成权限管理树视图 - 子级树结点
        /// </summary>
        private void InitAuthorityTreeChild(ToolStripMenuItem parent, TreeNode parentNode)
        {
            foreach (ToolStripItem item in parent.DropDownItems)
            {
                if (item is ToolStripSeparator)
                {
                    continue;                             //分隔符不在树显示
                }
                if (!Loginer.CurrentUser.IsAdmin() && !item.Enabled)
                {
                    continue;                                                  //没菜单权限.不加载树
                }
                AuthNodeTag tag  = new AuthNodeTag(item.Name, null, item);
                TreeNode    node = new TreeNode(item.Text, 0, 0);
                node.Tag = tag;
                parentNode.Nodes.Add(node);

                if (item.Tag != null && item.Tag is MenuItemTag)       //数据窗体菜单
                {
                    if ((item.Tag as MenuItemTag).FormAuthorities > 0) //窗体有权限
                    {
                        node.ImageIndex         = 1;
                        node.SelectedImageIndex = 1;
                        InitAction(node, item); //生成功能点结点
                    }
                    else
                    {
                        node.ImageIndex         = 3; //signle form
                        node.SelectedImageIndex = 3;
                    }
                }
                else
                {
                    node.ImageIndex         = 3; //signle form
                    node.SelectedImageIndex = 3;
                }

                //处理子菜单
                if (item is ToolStripMenuItem && (item as ToolStripMenuItem).DropDownItems.Count > 0)
                {
                    InitAuthorityTreeChild(item as ToolStripMenuItem, node);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 增加菜单权限
        /// </summary>
        /// <param name="auths">权限表</param>
        /// <param name="node">当前处理的树结点</param>
        private void AddAuthority(DataTable auths, TreeNode node)
        {
            int actions  = 0;
            int moduleID = 0;

            AuthNodeTag tag = node.Tag as AuthNodeTag; //取树结点的引用对象

            //新增组权限记录
            DataRow newrow = auths.NewRow();

            newrow[TUserRole.GroupCode]   = _groupName.Text;
            newrow[TUserRole.AuthorityID] = tag.AuthID;

            if (tag.MenuItem.Tag != null && tag.MenuItem.Tag is MenuItemTag)
            {
                //取当前处理的树结点所有权限值加总
                actions  = this.GetActions(node);
                moduleID = (tag.MenuItem.Tag as MenuItemTag).ModuleID;//模块编号
            }

            newrow[TUserRole.Authorities] = actions;
            newrow[TUserRole.ModuleID]    = moduleID;
            auths.Rows.Add(newrow);
        }