Ejemplo n.º 1
0
        void RemoveResource()
        {
            if (IsJudgeOperationForOne(nTabControl1.SelectedTab.Name))
            {
                if (tvRole.SelectedNode != null)
                {
                    if ((tvRole.SelectedNode.Tag as Role).Id != "roleadmin" && (tvRole.SelectedNode.Tag as Role).ParentId != "roleadmin")
                    {
                        MessageBox.Show("请在当前角色的根结点上删除资源!", "提示");
                        return;
                    }
                }
            }

            if (nTabControl1.SelectedTab == null)
            {
                return;
            }
            TreeListView _current = _resTreeListMap[nTabControl1.SelectedTab.Name];

            if (_current.SelectedItems.Count <= 0 || _current.SelectedItems[0].Level == 0)
            {
                return;
            }
            TreeListViewItem _item = _current.SelectedItems[0];

            //不可以删除父级节点
            if (_current.SelectedItems[0].Items.Count > 0)
            {
                MessageBox.Show("请先删除子节点!");
                return;
            }

            if (MessageBox.Show("是否要删除:'" + (_item.Tag as Priv).Name + "'资源?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
            {
                return;
            }

            try
            {
                PrivilegeService _proxy = Common.Util.CreateProxy();
                using (_proxy as IDisposable)
                {
                    try
                    {
                        NFC.Management.PublicTrans.BeginTransaction();
                        if (IsJudgeOperationForOne(nTabControl1.SelectedTab.Name))
                        {
                            int rtn = _proxy.RemoveResource(_item.Tag as Priv);
                        }
                        else
                        {
                            int rtn = _proxy.RemoveResource((_item.Tag as Priv).Id);
                        }
                        NFC.Management.PublicTrans.Commit();
                    }
                    catch (Exception e)
                    {
                        NFC.Management.PublicTrans.RollBack();
                        throw e;
                    }
                    //没找到记录
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "提示");
                return;
            }

            if (_item.Level == 0)
            {
                _current.Items.Remove(_item);
            }
            else
            {
                _item.Parent.Items.Remove(_item);
            }

            MessageBox.Show("删除成功!", "提示");
        }