partial void DeletesysTree(sysTree instance);
partial void UpdatesysTree(sysTree instance);
public string getSubNode(sysTree x) { StringBuilder sb = new StringBuilder(); //添加这个节点父节点的所有子节点 List<sysTree> sbnodes = (from node in allNode where node.PNodeid == x.NodeId orderby node.NodeId ascending select node).ToList<sysTree>(); if (sbnodes.Count() <= 0) { sbnodes = (from node in st where node.PNodeid == x.NodeId orderby node.NodeId ascending select node).ToList<sysTree>(); } foreach (var sbn in sbnodes) { string tmpsb = ""; string nodetxt = ""; if (addedid.Contains(sbn.NodeId)) continue; nodetxt = string.Format("{0}\"id\":\"{1}\",\"text\":\"{2}\",\"attributes\":{0}\"live\":\"{4}\",\"des\":\"{5}\"{6}", "{", sbn.NodeId, sbn.NodeName.Trim(), "closed", sbn.live, sbn.des, "}"); tmpsb = getSubNode(sbn); if (!string.IsNullOrEmpty(tmpsb)) { nodetxt += ",\"state\":\"closed\",\"children\": [" + tmpsb + "]"; addedid.Add(sbn.NodeId); } sb.Append(nodetxt).Append("},"); st.Remove(sbn); } if (sb.Length > 0) { if (sb[sb.Length - 1] == ',') { sb.Remove(sb.Length - 1, 1); } } return sb.ToString(); }
partial void InsertsysTree(sysTree instance);
//向上查找父节点的时候用堆栈,当找到根节点的时候 把堆栈里的节点都加载上去的同事加载检索结果中的节点与堆栈节点同一个父节节点的节点。 public string GetPNode(sysTree x) { StringBuilder sb = new StringBuilder(); //如果到根节点 if (x.live == 0) { if (addedid.Contains(x.NodeId)) return ""; sb.Append(string.Format("{0}\"id\":\"{1}\",\"text\":\"{2}\",\"attributes\":{0}\"live\":\"{4}\",\"des\":\"{5}\"{6}", "{", x.NodeId, x.NodeName.Trim(), "closed", x.live, x.des, "}")); addedid.Add(x.NodeId); if (st.Count > 0) { string tmpsb = getSubNode(x); if (!string.IsNullOrEmpty(tmpsb)) { sb.Append(",\"state\":\"closed\",\"children\": ["); sb.Append(tmpsb.Trim(',')); sb.Append("]"); } } sb.Append("}"); } else //寻找父节点 { var parentNode = from pnode in db.sysTree where pnode.NodeId == x.PNodeid select pnode; st.Add(parentNode.First()); if (parentNode.Count() > 0) { //如果有父节点 添加父节点 sb.Append(GetPNode(parentNode.First())); } } if (sb.Length > 0) { if (sb[sb.Length - 1] == ',') { sb.Remove(sb.Length - 1, 1); } } return sb.ToString(); }