• cs-SelectTree-DropTreeNode, SelectTreeList


    ylbtech-Unitity: cs-SelectTree-DropTreeNode, SelectTreeList

     DropTreeNode.cs SelectTreeList.cs

    1.A,效果图返回顶部
     
    1.B,源代码返回顶部
    1.B.1,DropTreeNode.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Healthcare.Framework.Web.Mvc
    {
        public class DropTreeNode
        {
            public string RootValue { get; set; }
            public string TreeNodeID { get; set; }
            public string Text { get; set; }
            public string Value { get; set; }
            public string ParentTreeNodeID { get; set; }
    
            public string Css { get; set; }
        }
    
    }
    View Code

    1.B.2,SelectTreeList.cs

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Healthcare.Framework.Web.Mvc
    {
        /// <summary>
        /// 树形下拉框
        /// </summary>
        public class SelectTreeList
        {
            #region 字段
    
            List<DropTreeNode> treeNodes = new List<DropTreeNode>();
            string rootValue = null;
            string valueField = null;
            string textField = null;
            string nodeField = null;
            string parentField = null;
    
            string css = null;
    
            string selectValue = "";
    
            bool isFinalLevel = false;
    
            public bool IsFinalLevel
            {
                get { return isFinalLevel; }
                set { isFinalLevel = value; }
            }
    
            public string SelectValue
            {
                get { return selectValue; }
                set { selectValue = value; }
            }
    
            #endregion
    
            #region 构造函数
    
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <param name="items">项集合</param>
            /// <param name="rootValue">根元素字段</param>
            /// <param name="textField">显示文本字段</param>
            /// <param name="nodeField">节点字段</param>
            /// <param name="parentField">父节点字段</param>
            public SelectTreeList(IEnumerable items, string rootValue, string textField, string nodeField, string parentField)
            {
                this.rootValue = rootValue;
                this.valueField = nodeField;
                this.textField = textField;
                this.nodeField = nodeField;
                this.parentField = parentField;
                Validate();
                Init(items);
            }
    
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <param name="items">项集合</param>
            /// <param name="rootValue">根元素字段</param>
            /// <param name="valueField">获取值字段</param>
            /// <param name="textField">显示文本字段</param>
            /// <param name="nodeField">节点字段</param>
            /// <param name="parentField">父节点字段</param>
            public SelectTreeList(IEnumerable items, string rootValue, string textField, string nodeField, string parentField, string valueField, string selectValue, bool isFinalLevel = false, string Css="")
            {
                this.rootValue = rootValue;
                this.valueField = valueField;
                this.textField = textField;
                this.nodeField = nodeField;
                this.parentField = parentField;
                this.selectValue = selectValue;
                this.isFinalLevel = isFinalLevel;
                this.css = Css;
    
                Validate();
                Init(items);
            }
    
            #endregion
    
            /// <summary>
            /// 验证各个参数的有效性
            /// </summary>
            public void Validate()
            {
                StringBuilder sb = new StringBuilder();
                if (string.IsNullOrEmpty(valueField))
                    sb.AppendLine("获取值字段不能为空");
                if (string.IsNullOrEmpty(textField))
                    sb.AppendLine("显示文本字段不能为空");
                if (string.IsNullOrEmpty(nodeField))
                    sb.AppendLine("节点字段不能为空");
                if (string.IsNullOrEmpty(parentField))
                    sb.AppendLine("父节点字段字段不能为空");
                if (sb.Length > 0)
                    throw new Exception("验证错误:" + sb.ToString());
            }
    
            /// <summary>
            /// 初始化TreeNodes集合
            /// </summary>
            /// <param name="items"></param>
            public void Init(IEnumerable items)
            {
                foreach (var item in items)
                {
                    DropTreeNode treeNode = new DropTreeNode();
                    Type type = item.GetType();
    
                    PropertyInfo property = type.GetProperty(this.valueField);
                    object o = property.GetValue(item, null);
                    treeNode.Value = o.ToString();
    
                    property = type.GetProperty(this.textField);
                    o = property.GetValue(item, null);
                    treeNode.Text = o.ToString();
    
                    property = type.GetProperty(this.nodeField);
                    o = property.GetValue(item, null);
                    treeNode.TreeNodeID = o.ToString();
    
                    property = type.GetProperty(this.parentField);
                    o = property.GetValue(item, null);
                    treeNode.ParentTreeNodeID = o.ToString();
    
                    if (!string.IsNullOrEmpty(this.css))
                    {
                        property = type.GetProperty(this.css);
                        o = property.GetValue(item, null);
                        treeNode.Css = o.ToString();
                    }
                    else
                        treeNode.Css = "";
    
                    treeNodes.Add(treeNode);
                }
            }
    
            #region 字段属性
    
            public List<DropTreeNode> TreeNodes
            {
                get { return treeNodes; }
                set { treeNodes = value; }
            }
    
            public string RootValue
            {
                get { return rootValue; }
                set { rootValue = value; }
            }
    
            public string ValueField
            {
                get { return valueField; }
                set { valueField = value; }
            }
    
            public string TextField
            {
                get { return textField; }
                set { textField = value; }
            }
    
            public string NodeField
            {
                get { return nodeField; }
                set { nodeField = value; }
            }
    
            public string ParentField
            {
                get { return parentField; }
                set { parentField = value; }
            }
    
            #endregion
        }
    
    }
    View Code

    1.B.3,

    1.C,下载地址返回顶部

     

    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    SpringCloud的Archaius
    一些技术博文,有时间整理一下!
    spring-oauth-server实践:授权方式四:client_credentials 模式的refresh_token?
    spring-oauth-server实践:授权方式四:client_credentials 模式下有效期内重复申请 access_token ?
    spring-oauth-server实践:使用授权方式四:client_credentials 模式的客户端和服务端交互
    api-gateway实践(03)新服务网关
    spring-oauth-server实践:使用授权方式四:client_credentials 模式下access_token做业务!!!
    spring-oauth-server实践:授权方式四:client_credentials 模式下access_token的产生
    spring-oauth-server实践:授权方式三:PASSWORD模式下 authorities:ROLE_{user.privillege}, ROLE_USER
    spring-oauth-server实践:授权方式1、2、3和授权方式4的token对象.authorities产生方式比较
  • 原文地址:https://www.cnblogs.com/ylbtech/p/4079381.html
Copyright © 2020-2023  润新知