Ejemplo n.º 1
0
        /// <summary>
        /// 初始化TreeNodes集合
        /// </summary>
        /// <param name="items"></param>
        public void Init(IEnumerable items)
        {
            foreach (var item in items)
            {
                TreeNode treeNode = new TreeNode();
                Type type = item.GetType();

                PropertyInfo property = type.GetProperty(this.valueField);
                object o = property.GetValue(item, null);
                if (o != null)
                    treeNode.Value = o.ToString();

                property = type.GetProperty(this.textField);
                o = property.GetValue(item, null);
                if (o != null)
                    treeNode.Text = o.ToString();

                property = type.GetProperty(this.nodeField);
                o = property.GetValue(item, null);
                if (o != null)
                    treeNode.TreeNodeID = o.ToString();

                property = type.GetProperty(this.parentField);
                o = property.GetValue(item, null);
                if (o != null)
                    treeNode.ParentTreeNodeID = o.ToString();

                //Css样式
                if (CssField != "")
                {
                    property = type.GetProperty(this.CssField);
                    o = property.GetValue(item, null);
                    if (o != null)
                        treeNode.Css = o.ToString();
                }
                else
                    treeNode.Css = "";
                //其它

                //Controll字段
                if (ControllPath != "")
                {
                    property = type.GetProperty(this.ControllPath);
                    o = property.GetValue(item, null);
                    if (o != null)
                        treeNode.ControllPath = o.ToString();
                    //
                }

                if (NodeUrl != "")
                {
                    property = type.GetProperty(this.NodeUrl);
                    o = property.GetValue(item, null);
                    if (o != null)
                    {
                        //if (o.ToString() == "")
                        //    treeNode.NodeUrl = "javascript:void(null)";
                        //else
                        treeNode.NodeUrl = o.ToString();
                    }
                }

                if (other != "")
                {
                    property = type.GetProperty(this.other);
                    o = property.GetValue(item, null);
                    if (o != null)
                        treeNode.Other = o.ToString();
                }

                treeNodes.Add(treeNode);
            }
        }
        private static string JqBindTreeN(TreeNode treeModel, IEnumerable<TreeNode> treeModels, string controllerAction, string currentPath, string ParentField, string selectTreeNode, int lev, bool parentLink, bool blast, string urlpath, bool bopen)
        {
            StringBuilder sb = new StringBuilder();
            //if (lev == 1)
            //    sb.AppendLine("<ul class='sub' style='display: block;'>");
            //else
            //    sb.AppendLine("<ul class='sub' style='display: none;'>");
            sb.AppendLine("<ul class='sub' style='display: none;'>");
            List<TreeNode> root = treeModels.Where(p => p.ParentTreeNodeID == treeModel.TreeNodeID).ToList();
            int count = root.Count;
            for (int i = 0; i < count; i++)
            {
                List<TreeNode> Sublist = treeModels.Where(p => p.ParentTreeNodeID == root[i].TreeNodeID).ToList();//.ModularFuns.ToList();
                int SubCount = Sublist.Count();
                if (SubCount > 0)//非叶节点
                {
                    var selectIselected = "";
                    var icon = "glyphicon-folder-close";
                    bopen = false;
                    if (selectTreeNode.Contains(currentPath + root[i].TreeNodeID + "/"))
                    {
                        selectIselected = " class='selected' ";
                        icon = "glyphicon-folder-open";
                        bopen = true;
                    }
                    var liclass = "";
                    if (selectTreeNode == currentPath + root[i].TreeNodeID + "/")
                        liclass = "active";
                    sb.AppendLine("<li class='" + liclass + "'>");

                    //sb.AppendLine(string.Format("<a " + selectIselected + " href='{0}?IsFinalLevel=1&{1}={2}&currentPath={3}'><i class='glyphicon " + icon + "'></i>{4}</a>", urlpath + controllerAction, "Item." + PKField, root[i].Value, currentPath + root[i].TreeNodeID + "/", root[i].Text));
                    //sb.AppendLine(string.Format("<a class='btn-FwBtnSubmit' data-fun='9' " + selectIselected + " href='#' data-posturl='{0}?Querys[0].FieldName={1}___equal&Querys[0].Value={2}'><i class='glyphicon " + icon + "'></i>{3}</a>", urlpath, "Item." + PKField, root[i].Value, currentPath + root[i].TreeNodeID + "/", root[i].Text));
                    sb.AppendLine(string.Format("<a class='btn-FwBtnSubmit' data-fun='2' " + selectIselected + " href='javascript:void(0);' data-posturl='{0}?Querys[0].FieldName={1}___equal&Querys[0].Value={2}'><i class='glyphicon glyphicon-folder-close'></i>{3}</a>", urlpath, ParentField, root[i].Value, root[i].Text));

                    sb.AppendLine(JqBindTreeN(root[i], treeModels, controllerAction, currentPath + root[i].TreeNodeID + "/", ParentField, selectTreeNode, lev, parentLink, i == count - 1, urlpath, bopen));
                    sb.AppendLine("</li>");
                }
                else//叶子节点
                {
                    var selectIselected = "";
                    var liclass = "";
                    if (selectTreeNode == currentPath + root[i].TreeNodeID + "/")
                    {
                        selectIselected = " class='selected' ";
                        liclass = "active";
                    }
                    //sb.AppendLine(string.Format("<li class='" + liclass + "'><a  " + selectIselected + " href='{0}?IsFinalLevel=1&{1}={2}&currentPath={3}'>{4}</a></li>", urlpath + controllerAction, "Item." + PKField, root[i].Value, currentPath + root[i].TreeNodeID + "/", root[i].Text));
                    sb.AppendLine(string.Format("<li class='" + liclass + "'>"));
                    //sb.AppendLine(string.Format("<a  class='btn-FwBtnSubmit' data-fun='9' " + selectIselected + " href='#' data-posturl='{0}?IsFinalLevel=1&{1}={2}&currentPath={3}'>{4}</a>", urlpath + controllerAction, "Item." + PKField, root[i].Value, currentPath + root[i].TreeNodeID + "/", root[i].Text));
                    sb.AppendLine(string.Format("<a class='btn-FwBtnSubmit' data-fun='2' " + selectIselected + " href='javascript:void(0);' data-posturl='{0}?Querys[0].FieldName={1}___equal&Querys[0].Value={2}'>{3}</a>", urlpath, ParentField, root[i].Value, root[i].Text));
                    sb.AppendLine("</li>");
                }
            }

            sb.AppendLine("</ul>");

            return sb.ToString();
        }