Files
17168ERP/web/admin/item/range.aspx.cs
2025-08-29 01:27:25 +08:00

77 lines
2.1 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
public partial class admin_item_range : MyWeb.config
{
DataTable treeDt = new DataTable();
const int LevelMax = MyWeb.item.KindLevelMax; //分類層數
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
TreeTopology();
BuildChild(0, TreeView2.Nodes);
}
}
protected void TreeTopology()
{
MyWeb.sql sql = new MyWeb.sql();
OleDbConnection sqlConn = sql.conn(db, p_name);
try
{
sqlConn.Open();
OleDbCommand sqlCmd = new OleDbCommand("", sqlConn);
sqlCmd.CommandText = "SELECT num,title,root FROM item ORDER BY root, range";
treeDt = sql.dataTable(sqlCmd);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sqlConn.Close();
sqlConn.Dispose();
}
}
public void BuildChild(int RootUid, TreeNodeCollection Nodes, int Level=1)
{
DataTable dt = treeDt;
foreach (DataRow row in dt.Rows)
{
if (row["root"].ToString() == RootUid.ToString())
{
TreeNode NewNode = new TreeNode();
if (Convert.ToString(Request["num"]) == row["num"].ToString())
{
NewNode.Text = "<b><font color=blue>" + row["title"].ToString() + "</font></b>";
}
else
{
NewNode.Text = row["title"].ToString();
}
NewNode.NavigateUrl = Request.Url.AbsolutePath + "?num=" + row["num"].ToString();
NewNode.Expand();
Nodes.Add(NewNode);
if (Level + 1 <= LevelMax)
{
BuildChild((int)row["num"], NewNode.ChildNodes, Level + 1);
}
}
}
}
}