.NET平台下Web树形结构程序设计
see:
http://www.microsoft.com/china/community/Column/30.mspx
see:
http://www.microsoft.com/china/community/Column/30.mspx
解决方案 »
- 东查西看,最后只好求助,奉100分以谢高手,表达敬意
- 大家帮忙看看这个reader.Read()为什么老是false
- Json传递数组,党国高手进!。
- 帮忙修改一下正则表达式
- datagrid行里某一列内容用图片显示
- VS2005发布ASP.NET的形式简直是烂到透顶了,我的其他附带文件被它统统删除了,真不知道微软是怎么想的!!
- xmlhttp的格式转换问题
- 在模式窗口中如何进行数据回调操作
- VB ServerXMLHTTP.POST 到ASP.NET程序,ASP.NET进行参数获取出错中英文字符出错??在线等不够加分!!500分
- 多文件上传时,能不能只在页面上放一个<input type=file>啊?
- ASP.NET的安全性问题
- 如何在客户端获得DataGrid中数据改动?在线等!
private void FillCustDeptTree()
{
try
{
TreeNode RootNode = new TreeNode();//根节点
RootNode.Text = GetDpNameInSysPara();
RootNode.ID = "customerdepartmentmanager";
TreeView1.Nodes.Add(RootNode); //添加一级单位节点
DataTable p1Table = Load1DeptTable();
foreach(DataRow dr1 in p1Table.Rows)
{
TreeNode p1Node = new TreeNode();
p1Node.Text = dr1["DPNAME1"].ToString();
p1Node.ID = dr1["DPCODE1"].ToString().Trim();
p1Node.Target = "_parent";
p1Node.NavigateUrl = "Rpt_customer_mx.aspx?node="+p1Node.ID;
//添加二级单位节点
DataTable p2Table = Load2DeptTable(dr1["DPCODE1"].ToString());
foreach(DataRow dr2 in p2Table.Rows)
{
TreeNode p2Node = new TreeNode();
p2Node.Text = dr2["DPNAME2"].ToString();
p2Node.ID = dr2["DPCODE1"].ToString().Trim()+dr2["DPCODE2"].ToString().Trim();
p2Node.Target = "_parent";
p2Node.NavigateUrl = "Rpt_customer_mx.aspx?node="+p2Node.ID;
strdept=p2Node.ID.ToString(); //添加三级单位节点
DataTable p3Table = Load3DeptTable(dr2["DPCODE1"].ToString(),dr2["DPCODE2"].ToString());
foreach(DataRow dr3 in p3Table.Rows)
{
TreeNode p3Node = new TreeNode();
p3Node.Text = dr3["DPNAME3"].ToString();
p3Node.ID = dr3["DPCODE1"].ToString().Trim()+dr3["DPCODE2"].ToString().Trim()+dr3["DPCODE3"].ToString().Trim();
p3Node.Target = "_parent";
p3Node.NavigateUrl = "Rpt_customer_mx.aspx?node="+p3Node.ID;
strdept=p3Node.ID.ToString(); //添加四级单位节点
DataTable p4Table = Load4DeptTable(dr3["DPCODE1"].ToString(),dr3["DPCODE2"].ToString(),dr3["DPCODE3"].ToString());
foreach(DataRow dr4 in p4Table.Rows)
{
TreeNode p4Node = new TreeNode();
p4Node.Text = dr4["DPNAME4"].ToString();
p4Node.ID = dr4["DPCODE1"].ToString().Trim()+dr4["DPCODE2"].ToString().Trim()+dr4["DPCODE3"].ToString().Trim()+dr4["DPCODE4"].ToString().Trim();
p4Node.Target = "_parent";
p4Node.NavigateUrl = "Rpt_customer_mx.aspx?node="+p4Node.ID;
strdept=p4Node.ID.ToString();
Session["dept"]=p4Node.ID.ToString();
p3Node.Nodes.Add(p4Node);
}
p2Node.Nodes.Add(p3Node);
}
p1Node.Nodes.Add(p2Node);
}
RootNode.Nodes.Add(p1Node);
}
}
catch(Exception ex)
{
throw ex;
}
}
//从一个子树subTree中找出其ID为id的节点
private TreeNode FindInSubTree(string id,TreeNode subTree)
{
if(subTree.ID ==id)
{
return subTree;
}
else
{
foreach(TreeNode tn in subTree.Nodes)
{
TreeNode value = FindInSubTree(id,tn);
if(value !=null)
{
return value;
}
}
return null;
}
} //从一个树Tree中找出其ID为id的节点
private TreeNode FindInTreeView(string id,TreeView Tree)
{
foreach(TreeNode tn in Tree.Nodes)
{
TreeNode value = FindInSubTree(id,tn);
if(value !=null)
{
return value;
}
}
return null;
} //找到树中选中的节点
private TreeNode FindSelectedNode(TreeView tree)
{
if(tree.Nodes.Count ==0)
{
return null;
}
else
{
string SelectedIndex = tree.SelectedNodeIndex;
string separatorstr = ".,;";
char[] separatorchars = separatorstr.ToCharArray();
string[] indexs = SelectedIndex.Split(separatorchars,5);
int level = indexs.Length; int index = Int32.Parse(indexs[0]);
TreeNode tn = TreeView1.Nodes[index];
for(int i = 1;i<level;i++)
{
index = Int32.Parse(indexs[i]);
tn = tn.Nodes[index];
}
return tn;
}
} //刷新后设置树的选中的节点
private void SetSelectedNode()
{
if(Request.QueryString.Count>0)
{
string nodeid = Request.QueryString["node"].ToString().Trim();
//Label1.Text = nodeid;
ExpandSelectedNodeParentInTreeView(nodeid,TreeView1);
TreeNode selectednode = FindInTreeView(nodeid,TreeView1);
TreeView1.SelectedNodeIndex = selectednode.GetNodeIndex();
}
} //在一个子树中展开选中节点的父节点
private bool ExpandSelectedNodeParentInSubTree(string id,TreeNode subTree)
{
if(subTree.ID ==id)
{
return true;
}
else
{
foreach(TreeNode tn in subTree.Nodes)
{
bool value = ExpandSelectedNodeParentInSubTree(id,tn);
if(value ==true)
{
tn.Expanded = true;
return true;
}
}
return false;
}
}
//在一个树中展开选中节点的父节点
private bool ExpandSelectedNodeParentInTreeView(string id,TreeView Tree)
{
foreach(TreeNode tn in Tree.Nodes)
{
bool value = ExpandSelectedNodeParentInSubTree(id,tn);
if(value == true)
{
tn.Expanded = true;
return true;
}
}
return false;
}
private string GetDpNameInSysPara()
{
try
{
BASE_SYSPARA syspara = new BASE_SYSPARA();
DataSet ds = syspara.GetAllDS();
return ds.Tables[0].Rows[0][1].ToString();
}
catch(Exception ex)
{
throw ex;
}
}
//获取客户单位信息
private DataTable Load1DeptTable()//获取一级部门
{
try
{
BASE_CUSTDEPT custdept= new BASE_CUSTDEPT();
DataSet ds = custdept.Get1DS();
return ds.Tables[0];
}
catch(Exception ex)
{
throw ex;
}
}
private DataTable Load2DeptTable(string p1id)//获取二级部门
{
try
{
BASE_CUSTDEPT custdept= new BASE_CUSTDEPT();
DataSet ds = custdept.Get2DS(p1id);
return ds.Tables[0];
}
catch(Exception ex)
{
throw ex;
}
}
private DataTable Load3DeptTable(string p1id,string p2id)//获取三级部门
{
try
{
BASE_CUSTDEPT custdept= new BASE_CUSTDEPT();
DataSet ds = custdept.Get3DS(p1id,p2id);
return ds.Tables[0];
}
catch(Exception ex)
{
throw ex;
}
}
private DataTable Load4DeptTable(string p1id,string p2id,string p3id)//获取四级部门
{
try
{
BASE_CUSTDEPT custdept= new BASE_CUSTDEPT();
DataSet ds = custdept.Get4DS(p1id,p2id,p3id);
return ds.Tables[0];
}
catch(Exception ex)
{
throw ex;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["UserName"].ToString()=="")
{
Response.Redirect("../../Admin_Login.aspx",true);
}
if(Page.IsPostBack == false)
{
FillCustDeptTree();
SetSelectedNode();
SetStatus(0);
}
}
{
DataSet ds = new DataSet();
try
{
OracleConnection Conn = new OracleConnection(strConn);
Conn.Open();
Int32 status = 0;
StringBuilder commandText = new StringBuilder("SELECT DISTINCT DPCODE1, DPNAME1 FROM CCENSE.BASE_CUSTDEPT a8");
OracleCommand DSCmd = new OracleCommand(commandText.ToString(),Conn);
if(status == 0 )
{
OracleDataAdapter DBAdopter = new OracleDataAdapter(DSCmd);
DBAdopter.Fill(ds);
if(status == 0 )
{
}
else
{
ds = new DataSet();
}
}
else
return ds;
Conn.Close();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return ds;
} public DataSet Get2DS(String strPrm1 )
{
DataSet ds = new DataSet();
try
{
OracleConnection Conn = new OracleConnection(strConn);
Conn.Open();
Int32 status = 0;
StringBuilder commandText = new StringBuilder("SELECT DISTINCT DPCODE1, DPNAME1, DPCODE2, DPNAME2 FROM CCENSE.BASE_CUSTDEPT a8 WHERE (a8.DPCODE1 = :prm1) AND (a8.DPCODE2 <> '00')");
OracleCommand DSCmd = new OracleCommand(commandText.ToString(),Conn);
if(status == 0 )
{
DSCmd.Parameters.Add("Prm1", OracleType.VarChar).Value = strPrm1;
OracleDataAdapter DBAdopter = new OracleDataAdapter(DSCmd);
DBAdopter.Fill(ds);
if(status == 0 )
{
}
else
{
ds = new DataSet();
}
}
else
return ds;
Conn.Close();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return ds;
} public DataSet Get3DS(String strPrm1 , String strPrm2 )
{
DataSet ds = new DataSet();
try
{
OracleConnection Conn = new OracleConnection(strConn);
Conn.Open();
Int32 status = 0;
StringBuilder commandText = new StringBuilder("SELECT DISTINCT DPCODE1, DPNAME1, DPCODE2, DPNAME2, DPCODE3, DPNAME3 FROM CCENSE.BASE_CUSTDEPT a8 WHERE (a8.DPCODE1 = :prm1) AND (a8.DPCODE2 = :prm2) AND (a8.DPCODE3 <> '000')");
OracleCommand DSCmd = new OracleCommand(commandText.ToString(),Conn);
if(status == 0 )
{
DSCmd.Parameters.Add("Prm1", OracleType.VarChar).Value = strPrm1;
DSCmd.Parameters.Add("Prm2", OracleType.VarChar).Value = strPrm2;
OracleDataAdapter DBAdopter = new OracleDataAdapter(DSCmd);
DBAdopter.Fill(ds);
if(status == 0 )
{
}
else
{
ds = new DataSet();
}
}
else
return ds;
Conn.Close();
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return ds;
}