| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CommonTool
- {
- public class FunSettingTree
- {
- public static FunSettingTree Inatance = new FunSettingTree();
- public FunctionTree CreatFunctionTree(List<FunctionTree> pcFunctionTrees)
- {
- FunctionTree loRoot = null;
- var lcFunctionTrees = pcFunctionTrees.Where(a => a.FatherId == "0").ToList();
- if (lcFunctionTrees.Count() == 1)
- {
- loRoot = lcFunctionTrees.FirstOrDefault();
- if (loRoot != null)
- {
- loRoot.ChildNodes = pcFunctionTrees.Where(a => a.FatherId == loRoot.Id && a.FatherId != "0").ToList();
- if (loRoot.ChildNodes.Any())
- {
- foreach (FunctionTree tree in loRoot.ChildNodes)
- {
- CreatFunctionTree(pcFunctionTrees, tree.Id);
- }
- }
- }
- }
- return loRoot;
- }
- public FunctionTree CreatFunctionTree(List<FunctionTree> pcFunctionTrees, string id)
- {
- FunctionTree loRoot = null;
- var lcFunctionTrees = pcFunctionTrees.Where(a => a.Id == id && a.FatherId != "0").ToList();
- if (lcFunctionTrees.Count() == 1)
- {
- loRoot = lcFunctionTrees.FirstOrDefault();
- if (loRoot != null)
- {
- loRoot.ChildNodes = pcFunctionTrees.Where(a => a.FatherId == loRoot.Id && a.FatherId != "0").ToList();
- if (loRoot.ChildNodes.Any())
- {
- foreach (FunctionTree tree in loRoot.ChildNodes)
- {
- CreatFunctionTree(pcFunctionTrees, tree.Id);
- }
- }
- }
- }
- return loRoot;
- }
- }
- public class FunctionTree
- {
- public string Id { get; set; }
- public string FatherId { get; set; }
- public string FunctionName { get; set; }
- public string ActionName { get; set; }
- public string ControllerName { get; set; }
- public string Url { get; set; }
- //public int Depth { get; set; }
- //public string IsLeaf { get; set; }
- //public int Sort { get; set; }
- public List<FunctionTree> ChildNodes { get; set; }
- public string ToJason()
- {
- StringBuilder sb = new StringBuilder();
- if (ChildNodes.Count > 0)
- {
- if (FatherId != "0")
- {
- sb.AppendFormat(
- "<li><a href = \"#\" ><i class=\"fa fa-clone\"></i><span class=\"nav-label\">{0}</span></a><ul class=\"nav nav-second-level\">",
- FunctionName);
- foreach (FunctionTree loChild in ChildNodes)
- {
- sb.Append(loChild.ToJason());
- }
- sb.AppendFormat("</ul></li>");
- }
- else
- {
- foreach (FunctionTree loChild in ChildNodes)
- {
- sb.Append(loChild.ToJason());
- }
- }
- }
- else
- {
- if (string.IsNullOrEmpty(ActionName))
- Url = "#";
- sb.AppendFormat("<li><a class=\"J_menuItem\" href=\"{0}\">{1}</a></li>", Url, FunctionName);
- }
- return sb.ToString();
- }
- //public string ToJbson()
- //{
- // StringBuilder sb = new StringBuilder();
-
- // if (ChildNodes != null)
- // {
- // foreach (FunctionTree loChild in ChildNodes)
- // {
- // sb.Append(loChild.ToJason());
- // }
- // }
- // else
- // {
- // if (string.IsNullOrEmpty(ActionName))
- // Url = "#";
- // sb.AppendFormat("<li><a class=\"J_menuItem\" href=\"{0}\">{1}</a></li>", Url, FunctionName);
- // }
- // return sb.ToString();
- //}
- }
- }
|