树的应用

介绍:
http://www.microsoft.com/china/community/Column/30.mspx

http://www.microsoft.com/china/community/Column/21.mspx

http://renyu732.cnblogs.com/archive/2005/06/28/182553.html

/// <summary>
        
/// 根据岗位ID获取上级岗位ID号。
        
/// </summary>
        
/// <param name="job_id">岗位ID</param>
        
/// <returns></returns>

        public static string GetParentIDStr(string job_id)
        
{
            
            
string StrSql="select parentid from sx_job where idno="+job_id;
            DBConnect dc
=new DBConnect();
            
string Parentid=dc.GetFieldValue(StrSql);
            dc.Close();

            
if(Parentid==""||Parentid=="0")
            
{
                
return "0";
            }

            
else
            
{
                
return Parentid+","+GetParentIDStr(Parentid);

            }
            
            
return null;
        }

    
        
/// <summary>
        
/// 根据岗位ID获取下级岗位ID号。
        
/// </summary>
        
/// <param name="job_id"></param>
        
/// <returns></returns>

        public static string GetChildIDStr(string job_id)
        
{
            
if(job_id==""||job_id=="0"return null;
            
string StrSql="select idno from sx_job where parentid="+job_id;
            DBConnect dc
=new DBConnect();
            DataTable dt
=new DataTable();
            dt
=dc.GetDtBySql(StrSql);
            dc.Close();

            
if(dt.Rows.Count==0)
            
{
                
return null;
            }

            
else
            
{
                
string ListStr=string.Empty;
            
                
for(int i=0;i<dt.Rows.Count;i++)
                
{
                    
string child=dt.Rows[i]["idno"].ToString();
                    
                    ListStr
+= child+","+GetChildIDStr(child);
                }

                
return ListStr;
            }

            
return null;
        }

posted on 2006-03-31 13:57  wen   阅读(110)  评论(0)    收藏  举报

导航