コード例 #1
0
ファイル: NavViewNode.cs プロジェクト: ischoolinc/JHCore
 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]);
     }
 }
コード例 #2
0
ファイル: CategoryView.cs プロジェクト: ischoolinc/JHCore
        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();

            CourseTag.Instance.SyncData(PrimaryKeys);

            foreach (var key in PrimaryKeys)
            {
                List <CourseTagRecord> TagRecords = Course.Instance.Items[key].GetTags();

                if (TagRecords.Count == 0)
                {
                    NoPrefixNoCategoryNode["未分類課程"].PrimaryKeys.Add(key);
                }
                else
                {
                    foreach (CourseTagRecord 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)
            {
                selectNode = SelectNode(selectPath, 0, advTree1.Nodes);
                if (selectNode != null)
                {
                    advTree1.SelectedNode = selectNode;
                }
            }
            //  advTree1.Focus();
        }