实用设计模式-桥接模式

来源:互联网 发布:淘宝拍a发b平台赚钱 编辑:程序博客网 时间:2024/04/30 09:41

树形条组件Check访问方式(未完成),具有基本的筛选方法,其他方法待续


    #region 树控件操作接口
    /// <summary>
    /// 树控件操作接口
    /// </summary>
    public interface IOperation<T>
    {
        /* 特殊树节点遍历 */
        void ErgodicNodes(T tn);
        /* 特殊树节点递归 */
        void ErgodicCirculate(T tn);
        /* 特殊树访问状态 */
        void SetChecked(T tn);
    }
    #endregion


    #region 使用接口
    /// <summary>
    /// 使用接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface ITreeNode<T>
    {
        void ErgodicNodes(T t);
    }


    #endregion


    #region 树控件操作类
    /// <summary>
    /// 一般树节点操作类
    /// </summary>
    public class OperationGeneralTreeNode : IOperation<TreeNode>
    {
        private TreeNode _TreeNode;


        public OperationGeneralTreeNode()
        {


        }


        public OperationGeneralTreeNode(TreeNode UltraTreeNode)
        {
            this._TreeNode = UltraTreeNode;
        }
        /// <summary>
        /// 同级节点
        /// </summary>
        /// <param name="tn"></param>
        public void ErgodicNodes(TreeNode tn)
        {
            if (tn == null)
                return;


            SetChecked(tn);


            if (tn.NextNode != null)
                ErgodicNodes(tn.NextNode);


            if (tn.FirstNode != null)
                ErgodicCirculate(tn.FirstNode);
        }
        /// <summary>
        /// 子节点
        /// </summary>
        /// <param name="tn"></param>
        public void ErgodicCirculate(TreeNode tn)
        {
            SetChecked(tn);


            if (tn.FirstNode != null)
                ErgodicCirculate(tn.FirstNode);


            if (tn.NextNode != null)
                ErgodicCirculate(tn.NextNode);
        }
        /// <summary>
        /// 访问控制
        /// </summary>
        /// <param name="tn"></param>
        public void SetChecked(TreeNode tn)
        {
            if (tn != null)
                if (tn.Checked == true)
                    tn.Checked = false;
                else
                    tn.Checked = true;
        }
    }


    /// <summary>
    /// 第三方控件树节点操作类
    /// </summary>
    public class OperationUltraTreeNode : IOperation<UltraTreeNode>
    {
        private UltraTreeNode _UltraTreeNode;


        public OperationUltraTreeNode()
        {


        }


        public OperationUltraTreeNode(UltraTreeNode UltraTreeNode)
        {
            this._UltraTreeNode = UltraTreeNode;
        }
        /// <summary>
        /// 同级节点
        /// </summary>
        /// <param name="tn"></param>
        public void ErgodicNodes(UltraTreeNode tn)
        {
            if (tn == null)
                return;


            SetChecked(tn);


            if (tn.GetSibling(NodePosition.Next) != null)
                ErgodicNodes(tn.GetSibling(NodePosition.Next));


            if (tn.GetSibling(NodePosition.First) != null)
                ErgodicCirculate(tn.GetSibling(NodePosition.First));
        }
        /// <summary>
        /// 子节点
        /// </summary>
        /// <param name="tn"></param>
        public void ErgodicCirculate(UltraTreeNode tn)
        {
            SetChecked(tn);


            if (tn.GetSibling(NodePosition.First) != null)
                ErgodicCirculate(tn.GetSibling(NodePosition.First));


            if (tn.GetSibling(NodePosition.Next) != null)
                ErgodicCirculate(tn.GetSibling(NodePosition.Next));
        }
        /// <summary>
        /// 访问控制
        /// </summary>
        /// <param name="tn"></param>
        public void SetChecked(UltraTreeNode tn)
        {
            if (tn != null)
                if (tn.CheckedState == CheckState.Checked)
                    tn.CheckedState = CheckState.Unchecked;
                else
                    tn.CheckedState = CheckState.Checked;
        }
    }


    /// <summary>
    /// 使用一般操作方法
    /// </summary>
    public class UseGTreeNode : ITreeNode<TreeNode>
    {
        private IOperation<TreeNode> _Operation;


        public UseGTreeNode(IOperation<TreeNode> Operation)
        {
            this._Operation = Operation;
        }


        public void ErgodicNodes(TreeNode t)
        {
            _Operation.ErgodicNodes(t);
        }
    }


    /// <summary>
    /// 使用控件方操作方法
    /// </summary>
    public class UseUTreeNode : ITreeNode<UltraTreeNode>
    {
        private IOperation<UltraTreeNode> _Operation;


        public UseUTreeNode(IOperation<UltraTreeNode> Operation)
        {
            this._Operation = Operation;
        }


        public void ErgodicNodes(UltraTreeNode t)
        {
            _Operation.ErgodicNodes(t);
        }
    }


    #endregion

0 0
原创粉丝点击