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(); TeacherTag.Instance.SyncData(PrimaryKeys); foreach (var key in PrimaryKeys) { List <TeacherRecord> TeacherRecs = Course.Instance.Items[key].GetInstructTeachers(); if (TeacherRecs.Count == 0) { NoPrefixNoCategoryNode["未有授課教師課程"].PrimaryKeys.Add(key); } foreach (TeacherRecord Tea in TeacherRecs) { List <TeacherTagRecord> TagRecords = Tea.GetTags(); if (TagRecords.Count == 0) { NoPrefixNoCategoryNode["未分類課程"][Tea.Name].PrimaryKeys.Add(key); } else { foreach (TeacherTagRecord TagRecord in TagRecords) { string category = TagRecord.Name; string prefix = TagRecord.Prefix; if (!prefix.Equals(string.Empty) && !category.Equals(string.Empty)) { PrefixCategoryNode[prefix][category][Tea.Name].PrimaryKeys.Add(key); } else if (prefix.Equals(string.Empty) && !category.Equals(string.Empty)) { NoPrefixCategoryNode[category][Tea.Name].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) { selectNode = SelectNode(selectPath, 0, advTree1.Nodes); if (selectNode != null) { advTree1.SelectedNode = selectNode; } } advTree1.Focus(); }