public NavViewNode SmartAdd(string key) { if (!mNodes.ContainsKey(key)) { NavViewNode Node = new NavViewNode(); Node.Name = key; mNodes.Add(key, Node); return(Node); } else { return(mNodes[key]); } }
public new void Layout(List <string> PrimaryKeys) { //選取的結點的完整路徑 List <string> selectPath = new List <string>(); #region 記錄選取的結點的完整路徑 var selectNode = advTree1.SelectedNode; if (selectNode != null) { while (selectNode != null) { selectPath.Insert(0, selectNode.Text); selectNode = selectNode.Parent; } } #endregion advTree1.Nodes.Clear(); items.Clear(); NavViewNode PrefixCategoryNode = new NavViewNode(); PrefixCategoryNode.Name = "所有班級"; NavViewNode NoPrefixCategoryNode = new NavViewNode(); NavViewNode NoPrefixNoCategoryNode = new NavViewNode(); ClassTag.Instance.SyncData(PrimaryKeys); foreach (var key in PrimaryKeys) { List <ClassTagRecord> TagRecords = Class.Instance.Items[key].GetTags(); if (TagRecords.Count == 0) { NoPrefixNoCategoryNode["未分類班級"].PrimaryKeys.Add(key); } else { foreach (ClassTagRecord TagRecord in TagRecords) { string category = TagRecord.Name; string prefix = TagRecord.Prefix; if (!prefix.Equals(string.Empty) && !category.Equals(string.Empty)) { PrefixCategoryNode[prefix][category].PrimaryKeys.Add(key); } else if (prefix.Equals(string.Empty) && !category.Equals(string.Empty)) { NoPrefixCategoryNode[category].PrimaryKeys.Add(key); } } } } NavViewNode.NodePrimaryKeys.Clear(); foreach (string key in NoPrefixCategoryNode.Nodes.Keys) { PrefixCategoryNode[key].PrimaryKeys.AddRange(NoPrefixCategoryNode[key].PrimaryKeys); } foreach (string key in NoPrefixNoCategoryNode.Nodes.Keys) { PrefixCategoryNode[key].PrimaryKeys.AddRange(NoPrefixNoCategoryNode[key].PrimaryKeys); } PrefixCategoryNode.UpdateInstance(false); PrefixCategoryNode.InstanceNode.Expand(); advTree1.Nodes.Add(PrefixCategoryNode.InstanceNode); items = NavViewNode.NodePrimaryKeys; if (selectPath.Count != 0) { var myselectNode = SelectNode(selectPath, 0, advTree1.Nodes); if (myselectNode != null) { advTree1.SelectedNode = myselectNode; } } //advTree1.Focus(); }