[新闻系统]二级分类 仿动网新闻效果

写新闻的时候不可避免的要写到分类的管理

笔者一时间陷入几级分类的痛苦中看过CS之后才发现原来CS那么大的系统也不过三级而已
自己写的是一个二级把两个都贴出来 和大家一起分享,采用遍历的方法按层级的顺序访问
 1        public static string BuildTreeByColumnID(int id)
 2        {
 3            Provider dp = Provider.Instance();
 4
 5            Column column = GetColumnByID(id);
 6            int depth = column.Depth;
 7            int sort = column.Sort;
 8            if(depth == 0)
 9            {
10                if (dp.GetChildColumns(id).Count > 0)
11                {
12                    return "images/admin_tree_plusmiddle.gif" + "&" + "images/admin_tree_folder.gif" + "&" + column.Name;                    
13                }

14                else
15                {
16                    if (!ISLastONE(id))
17                        return "images/admin_tree_minusmiddle.gif" + "&" + "images/admin_tree_folder.gif" + "&" + column.Name;
18                    else return "images/admin_tree_minusbottom.gif" + "&" + "images/admin_tree_folder.gif" + "&" + column.Name;
19                }

20            }

21            else if(depth == 1)
22            {
23                if (dp.GetChildColumns(id).Count > 0)
24                {                    
25                        return "images/admin_tree_line.gif" + "&" + "images/admin_tree_plusmiddle.gif" + "&" + "images/admin_tree_folder.gif" + "&" + column.Name;
26        
27                }

28                else
29                {
30                    if (!ISLastONE(id))
31                        return "images/admin_tree_line.gif" + "&" + "images/admin_tree_minusmiddle.gif" + "&" + "images/admin_tree_folder.gif" + "&" + column.Name;
32                    else return "images/admin_tree_line.gif" + "&" + "images/admin_tree_minusbottom.gif" + "&" + "images/admin_tree_folder.gif" + "&" + column.Name;
33                }

34            }

35            else return null;
36        }

public static bool ISLastONE(int id)
        
{
            Provider dp 
= Provider.Instance();

            ColumnCollection columns 
= GetSortColumns();
            
for (int i = 0; i < columns.Count; i++)
            
{
                
if (id == columns[i].ID)
                
{
                    
if (i + 1 < columns.Count)
                    
{
                        
if (columns[i + 1].Depth < columns[i].Depth)
                            
return true;
                    }

                    
else return true;
                }

            }


            
return false;        
        }
public static ColumnCollection GetSortColumns()
        {
            Provider dp 
= Provider.Instance(); 

            ColumnCollection columns 
= new ColumnCollection();
       
            
int i = 0;// 临时索引
            Column column = new Column();
            
for (i = 0; i < dp.GetColumnsByDepth(0).Count; i++)
            {
                column 
= dp.GetColumnsByDepth(0)[i];
                columns.Add(column);
// 按索引添加数据
                
// 添加子栏目并建立索引
                if (dp.GetChildColumns(column.ID) != null)
                {
                    
for (int k = 0; k < dp.GetChildColumns(column.ID).Count; k++)
                    {
                        columns.Add(dp.GetChildColumns(column.ID)[k]);
                    }
                }            
            }

            
return columns;
        }


上移, 下移
 public static void MoveSort(int id, int depth, Way way)
        
{
            Provider dp 
= Provider.Instance();
            
if (id != 0 && depth > -1)
            
{
                dp.SortMove(id, depth, way);
            }

            
else throw new Exception("参数不正确,请检查");
        }

posted on 2006-02-05 15:41  xwang  阅读(623)  评论(3编辑  收藏  举报

导航