예제 #1
0
        void SavePermission()
        {
            TreeNode _node = tvRole.SelectedNode;

            if (_node == null || _node.Tag == null)
            {
                MessageBox.Show("请选择待授权角色!", "提示");
                return;
            }
            NeuTreeListView _list = _resTreeListMap[nTabControl1.SelectedTab.Name];

            TreeListViewItem _item          = null;
            string           _permissionExp = "";

            if (_resTreeListMap[nTabControl1.SelectedTab.Name].CheckBoxes != CheckBoxesTypes.Simple)
            {
                if (_list == null || _list.SelectedItems.Count == 0 || ((_list.SelectedItems[0].Tag as Priv).Id == "root"))
                {
                    MessageBox.Show("请选择待授权资源!", "提示");
                    return;
                }
                _item = _list.SelectedItems[0];

                _permissionExp = GetSelectedPermission();
                if (string.IsNullOrEmpty(_permissionExp))
                {
                    MessageBox.Show("请选择操作权限!", "提示");
                    return;
                }
            }

            try
            {
                PrivilegeService _proxy = Common.Util.CreateProxy();
                //全部的Res
                List <Neusoft.Privilege.BizLogic.Model.Priv> allRes = new List <Priv>();
                //选中的Res
                List <Neusoft.Privilege.BizLogic.Model.Priv> res = new List <Priv>();

                NFC.Management.PublicTrans.BeginTransaction();
                if (_resTreeListMap[nTabControl1.SelectedTab.Name].CheckBoxes == CheckBoxesTypes.Simple)
                {
                    foreach (TreeListViewItem item in _resTreeListMap[nTabControl1.SelectedTab.Name].CheckedItems)
                    {
                        if ((item.Tag as Priv).Id != "root")
                        {
                            res.Add(item.Tag as Priv);
                        }
                    }

                    foreach (TreeListViewItem item in _resTreeListMap[nTabControl1.SelectedTab.Name].Items)
                    {
                        allRes.Add(item.Tag as Priv);

                        SetAllRes(allRes, item.Items);
                    }

                    GetAllChildRole(tvRole.SelectedNode.Nodes);
                    GetDeleteRes(res);

                    //当角色为系统管理员时,不考虑级联删除
                    if ((_node.Tag as Role).Id == "roleadmin")
                    {
                        deleteResList  = new List <Priv>();
                        deleteRoleList = new List <Role>();
                    }

                    int rtn = _proxy.SavePermission((_node.Tag as Role), allRes, res, _permissionExp, deleteResList, deleteRoleList);

                    NFC.Management.PublicTrans.Commit();
                    if (rtn == 0)
                    {
                        NFC.Management.PublicTrans.RollBack();
                        MessageBox.Show("保存失败!");
                        return;
                    }
                }
                else
                {
                    int rtn = _proxy.SavePermission(nTabControl1.SelectedTab.Name, (_node.Tag as Role), (_item.Tag as Priv), _permissionExp);
                    NFC.Management.PublicTrans.Commit();
                    if (rtn == 0)
                    {
                        NFC.Management.PublicTrans.RollBack();
                        MessageBox.Show("保存失败!");
                        return;
                    }
                    //父级处理,太麻烦...有需求再说吧
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "提示");
                return;
            }

            MessageBox.Show("保存成功!", "提示");
        }