二叉树的HTML显示

    受经济危机的影响,最近没有做什么大项目,弄了一个二叉树的HTML显示方法,代码如下:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
protected string bf(int i, string coding, string pcoding, string s)
    {
        
string c1 = "", c2 = "";
        
if (coding == "左未注册" || coding == "右未注册")
        { c1 
= "<div style='background-color:#ccc;height:40px;line-height:40px;'> 左未注册</div>"; c2 = "<div style='background-color:#ccc;height:40px;line-height:40px;'>右未注册</div>"; }

        
else
        {
            
// c1 = "<div style='background-color:#0000ff;height:40px;line-height:40px;'> 左未注册</div>"; c2 = "<div style='background-color:#0000ff;height:40px;line-height:30px;'>右未注册</div>";

            c1 
= string.Format("<div style='background-color:#0000ff;height:40px;line-height:40px;'><a href=Register.aspx?anzhi={0}&site=0  class='qian'>{1}</a> </div>", coding, "左未注册");

            c2 
= string.Format("<div style='background-color:#0000ff;height:40px;line-height:40px;'><a href=Register.aspx?anzhi={0}&site=1  class='qian'>{1}</a> </div>", coding, "右未注册");

        }
        Sale.BLL.Customer bcustomer 
= new Sale.BLL.Customer();
        Sale.Model.Customer mcustomer 
= bcustomer.GetModel(coding);
        
if (i < 2)
        {


            i
++;

            
if (mcustomer != null)
            {
                
if (!string.IsNullOrEmpty(mcustomer.LeftChildCoding))
                {

                    c1 
= bf(i, mcustomer.LeftChildCoding, coding, s);
                }

                
else
                {


                    c1 
= bf(i, "左未注册", coding, s);

                }

                
if (!string.IsNullOrEmpty(mcustomer.RightChildCoding))
                {
                    c2 
= bf(i, mcustomer.RightChildCoding, coding, s);
                }

                
else
                {


                    c2 
= bf(i, "右未注册", coding, s);

                }
            }

            
else
            {
                c1 
= bf(i, "左未注册", coding, s);
                c2 
= bf(i, "右未注册", coding, s);


            }

        }

        
else
        {
            
if (mcustomer != null)
            {

                
if (!string.IsNullOrEmpty(mcustomer.LeftChildCoding))
                {
                  Sale.Model.Customer lcus
=bcustomer.GetModel(mcustomer.LeftChildCoding);

                                         c1 
= string.Format("<a href='NetTree.aspx?root={0}' class='{2}' >{0}<font style='color:Red; font-size:14px;'>({1}单)</font></a>", mcustomer.LeftChildCoding,lcus.RatingCoding, lcus.IsValid?"alan":"ahuang");
                }

                
if (!string.IsNullOrEmpty(mcustomer.RightChildCoding))
                {
                    Sale.Model.Customer rcus 
= bcustomer.GetModel(mcustomer.RightChildCoding);

                                         c2 
= string.Format("<a href='NetTree.aspx?root={0}' class='{2}'>{0}<font style='color:Red; font-size:14px;'>({1}单)</font></a>", mcustomer.RightChildCoding,rcus.RatingCoding,rcus.IsValid ? "alan" : "ahuang");
                }

            }


        }


        
if (coding == "左未注册" || coding == "右未注册")
        {
            
if (pcoding == "左未注册" || pcoding == "右未注册")
            {

                
return s.Replace("左孩子", c1).Replace("右孩子", c2).Replace("根节点"string.Format("<div style='background-color:#ccc;height:40px;line-height:40px;' class='qian'>{0}</a> </div>", coding));

            }
            
else


                
return s.Replace("左孩子", c1).Replace("右孩子", c2).Replace("根节点"string.Format("<div style='background-color:#0000ff;height:40px;line-height:40px;'><a href=Register.aspx?anzhi={0}&site={1} class='qian'>{2}</a> </div>", pcoding, coding == "左未注册" ? "0" : "1", coding));

        }
        
else
            
return s.Replace("左孩子", c1).Replace("右孩子", c2).Replace("根节点"string.Format("<a href='NetTree.aspx?root={0}' class='{2}'>{0}<font style='color:Red; font-size:14px;'>({1}单)</font></a>", coding, mcustomer.RatingCoding,mcustomer.IsValid?"alan":"ahuang"));

    }

 

调用时:

   

ContractedBlock.gif ExpandedBlockStart.gif Code
  string s = "<table cellpadding='0' cellspacing='0' border='1'   style='width:100%;   height:100%;   text-align:center;background-color:#0563AB; color:#ffffff; font-weight:bold;border-top:solid 1px #cccc;  border-left:solid 1px #cccc; border-bottom-width:0px; border-right-width:0px;'><tr><td colspan='2' style='height:40px;border-right:solid 1px #cccc;  border-bottom:solid 1px #cccc; border-top-width:0px; border-left-width:0px;' >根节点</td></tr><tr><td style='width:50%;height:40px;border-right:solid 1px #cccc;  border-bottom:solid 1px #cccc; border-top-width:0px; border-left-width:0px;'  >左孩子</td><td style='width:50%; height:40px;border-right:solid 1px #cccc;  border-bottom:solid 1px #cccc; border-top-width:0px; border-left-width:0px;' >右孩子</td></tr></table>";
  
 
string    str = this.bf(0,root_coding,"",s);

 

 

 

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 <style type="text/css">
    .ahuang
{
    width
:100%;
    display
:block; 
    background-color
:#FFFF00;
     height
:40px;
     line-height
:40px;
    
}
    
        .alan
{
    width
:100%;
    display
:block; 
    background-color
:#00ff00;
     height
:40px;
     line-height
:40px;
    
}
    
        .qian
{
    width
:100%;
    display
:block; 
    background-color
:#0563AB;
     height
:40px;
     line-height
:40px;
    
}
    
    
    </style>

转载于:https://www.cnblogs.com/xiaorong/archive/2008/11/17/1335406.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值