using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient ;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ldter
{
/// <summary>
/// WebForm4 的摘要说明。
/// </summary>
public class WebForm4 : System.Web.UI.Page
{
DataSet ds;
string str;
OracleConnection con;
string strTree="<center><table width='80%' cellspacing='0' cellpadding='0'><tr valign='top'><td width='50%' align='center'><table width='100%' cellspacing='0' cellpadding='0'>";
Int32 c=0;
bool havechild=false;
public string strsort
{
get
{
return strTree+"</table></td></tr></table></center>";
}
}
private void LocalDataSet()
{
OracleDataAdapter ad;
OracleDataAdapter adpar;
str="SELECT * FROM CODESORT ORDER BY CS_ID";
ad=new OracleDataAdapter(str,con);
adpar=new OracleDataAdapter("SELECT CS_PAR FROM CODESORT ORDER BY CS_ID",con);
con.Open();
ds=new DataSet();
try
{
ad.Fill(ds,"maindoc");
adpar.Fill(ds,"par");
this.ViewState["ds"]=ds;
}
catch
{
throw;
}
finally
{
con.Close();
}
}
public void InitTree(string parent)
{
DataView dv=new DataView(ds.Tables["maindoc"]);
DataView dvpar=new DataView(ds.Tables["par"]);
dv.RowFilter="cs_par = '" + parent + "'";
foreach(DataRowView row in dv)
{
string nbsp="";
string div="";
string td="";
string checkbox="";
if(parent=="000") c=c+1;
for (Int32 i=1;i<=Int32.Parse(row["cs_clas"].ToString());i++) nbsp+=" ";
if (parent!="000")
{
div="<tr valign='top'><td width='100%' height='100%'><div width='100%' height='100%' id='div"+ row["cs_code"].ToString()
+"' style='display:none'><table width='100%' height='100%' cellspacing='0' cellpadding='0'><tr valign='top'><td width='100%'>";
}
else
{
div="<tr valign='top'><td width='100%' height='100%'><div width='100%' height='100%' id='div"+ row["cs_code"].ToString()
+"' style='display:none'><table width='100%' cellspacing='0' cellpadding='0'><tr valign='top'><td width='100%'>";
}
if(c==4)
{
td="</table></td><td width='50%' align='center'><table width='100%' cellspacing='0' cellpadding='0'><tr valign='top'><td width='80%' align='left'>";
}
else{if(havechild)td=""; else td="<tr valign='top' ><td width='80%' align='left' valign='top'>";}
foreach(DataRowView rowpar in dvpar) //是否父节点
if (row["cs_code"].ToString()==rowpar[0].ToString()){havechild=true;break;}else{havechild=false;}
if(havechild||parent=="000"){checkbox="<img border='0' id='img"+row["cs_code"]+"' src='gif/plus.gif'>";}
else{checkbox="<img border='0' id='img"+row["cs_code"]+"' src='gif/T.gif'>"+"<input id='" +row["cs_code"]+ "' type='checkbox' classname='" +row["cs_name"]+ "' onClick=javascript:subsel(this)>";}
string newname="";
if(row["cs_name"].ToString().Length.CompareTo(14)!=1){newname=row["cs_name"].ToString();}else{newname=row["cs_name"].ToString().Substring(0,10).ToString()+"...";}
strTree+=td + nbsp + checkbox +"<a title='"+row["cs_name"]+"' href=javascript:expit('" + row["cs_code"].ToString() + "','"+ row["cs_clas"].ToString() +"')"
+" cursor='hand' class='ainfo'>" + newname +"</a></td></tr>";
if(havechild){strTree+=div;InitTree(row["cs_code"].ToString());strTree+="</td></tr></table></div></td></tr>";}
}}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
ds=(DataSet)this.ViewState["ds"];
InitTree("000");
DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
con=new OracleConnection("Data Source=ora9;User Id=system;Password=manager;Integrated Security=no");
LocalDataSet();
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
本文地址:http://com.8s8s.com/it/it42445.htm