[c#]代码库
#region 树状数据表,处理排序
//创建finaldata表和originaldata表,做为源表和处理后的表格
public static DataTable finaldata;
public static DataTable originaldata;
//调用处理方法
protected void HandledTable(int factorID)
{
getdata(factorID);
//1为产品根
step(2);
//删除表中第一行
//finaldata.Rows.RemoveAt(0);
BindGrid();
}
//调用GetDataTable得到数据,并处理finaldata,originaldata表
protected void getdata(int factorID)
{
finaldata = GetDataTable(factorID).Clone();
originaldata = GetDataTable(factorID);
}
//遍历过程
protected void step(int i)
{
//找到本节点信息
DataRow[] sortAdd = originaldata.Select("Valided=1 and ID='" + i + "'");
object[] obj = new object[originaldata.Columns.Count];
sortAdd[0].ItemArray.CopyTo(obj, 0);
// finaldata中添加本节点
finaldata.Rows.Add(obj);
//调用GetChildNode 获取子节点信息
DataTable child = GetChildNode(i);
//如存在子节点
if (child.Rows.Count > 0)
{
for (int j = 0; j < child.Rows.Count; j++)
{
int k = Convert.ToInt16(child.Rows[j]["ID"].ToString());
step(k); //进行递归
}
}
}
//查找子节点
protected DataTable GetChildNode(int x)
{
DataRow[] sortChild = originaldata.Select("Valided=1 and sort_parentID='" + x + "'");
DataTable dt = originaldata.Clone();
for (int i = 0; i < sortChild.Length; i++)
{
dt.ImportRow((DataRow)sortChild[i]);
}
return dt;
}
#endregion
by: 发表于:2018-01-03 10:43:51 顶(0) | 踩(0) 回复
??
回复评论