递归获取子结点(包括自身结点)
2007-11-23 17:40
176 查看
#region 递归获取子结点(包括自身结点)
/// <summary>
/// 递归获取子结点(包括自身结点)
/// </summary>
/// <param name="values">当前结点值</param>
/// <param name="sql">查询所有记录的Sql语句</param>
/// <param name="ParentFieldName">父ID字段名</param>
/// <param name="KeyFieldName">主键字段名</param>
/// <returns>主键字符串</returns>
/// <example>
/// private string GetChildrenDeparment(string departmentid)
///{
/// string sql = "select * from Department";
/// string DepartmentID = "DepartmentParent";
/// string KeyFieldName = "DepartmentID";
/// return GetChildren(departmentid, sql, ParentFieldName, KeyFieldName);
///}
/// </example>
public static string GetChildren(string values, string sql, string ParentFieldName, string KeyFieldName)
{
//根据Sql获得DataTable
DataTable source = GetDataTableBySql(sql);
//初始化结果字符串
string result = "";
//递归获取子串其它本身
result = GetChildren(values, source, ParentFieldName, KeyFieldName);
return result.Substring(0, result.Length - 1);
}
/// <summary>
/// 递归获取子结点(包括自身结点)
/// </summary>
/// <param name="values">当前结点值</param>
/// <param name="source">包括所有数据的数据源</param>
/// <param name="ParentFieldName">父ID字段名</param>
/// <param name="KeyFieldName">主键字段名</param>
/// <returns>主键字符串</returns>
private static string GetChildren(string values, DataTable source, string ParentFieldName, string KeyFieldName)
{
string children = values + ",";
DataRow[] results = source.Select(ParentFieldName + "='" + values + "'");
if (results.Length != 0)
{
foreach (DataRow dr in results)
{
children += GetChildren(dr[KeyFieldName].ToString().Trim(), source, ParentFieldName, KeyFieldName);
}
}
return children;
}
#endregion
/// <summary>
/// 递归获取子结点(包括自身结点)
/// </summary>
/// <param name="values">当前结点值</param>
/// <param name="sql">查询所有记录的Sql语句</param>
/// <param name="ParentFieldName">父ID字段名</param>
/// <param name="KeyFieldName">主键字段名</param>
/// <returns>主键字符串</returns>
/// <example>
/// private string GetChildrenDeparment(string departmentid)
///{
/// string sql = "select * from Department";
/// string DepartmentID = "DepartmentParent";
/// string KeyFieldName = "DepartmentID";
/// return GetChildren(departmentid, sql, ParentFieldName, KeyFieldName);
///}
/// </example>
public static string GetChildren(string values, string sql, string ParentFieldName, string KeyFieldName)
{
//根据Sql获得DataTable
DataTable source = GetDataTableBySql(sql);
//初始化结果字符串
string result = "";
//递归获取子串其它本身
result = GetChildren(values, source, ParentFieldName, KeyFieldName);
return result.Substring(0, result.Length - 1);
}
/// <summary>
/// 递归获取子结点(包括自身结点)
/// </summary>
/// <param name="values">当前结点值</param>
/// <param name="source">包括所有数据的数据源</param>
/// <param name="ParentFieldName">父ID字段名</param>
/// <param name="KeyFieldName">主键字段名</param>
/// <returns>主键字符串</returns>
private static string GetChildren(string values, DataTable source, string ParentFieldName, string KeyFieldName)
{
string children = values + ",";
DataRow[] results = source.Select(ParentFieldName + "='" + values + "'");
if (results.Length != 0)
{
foreach (DataRow dr in results)
{
children += GetChildren(dr[KeyFieldName].ToString().Trim(), source, ParentFieldName, KeyFieldName);
}
}
return children;
}
#endregion
相关文章推荐
- IOS获取自身网络信息的方法,包括自身ip,路由地址等
- TP3.2.3 无限极分类&&获取所有子分类包括自身
- scrapy xpath取包含某些特定文字的选择器,获取一个标签下的所有text(包括自身和子孙)
- Java非递归的方式获取目录中所有文件(包括目录)
- 获取当前匹配元素 包括自身的html
- 获取指定元素的最大子元素(包括自身)的width值和height值
- javase——递归获取指定目录下(包括子目录)指定后缀的文件的文件名
- java语言实现的二叉树的各种操作(包括递归与非递归遍历二叉树,求二叉树的高度,节点总数,叶子节点等)
- java之递归列出一个文件夹下的所有文件(包括文件夹)
- 【jQuery 使用】 利用jQuery.prop("outerHTML")获取包含自身在内的HTML元素的HTML代码
- 数据结构——非循环带头结点单链表的递归方法逆置
- Java 树父节点递归获取树子节点
- cesium随笔 — 简单实现获取三维范围(包括相机高度)
- javamail实例之获取邮件,包括gmail yahoo
- android之View坐标系(view获取自身坐标的方法和点击事件中坐标的获取)
- iOS使用递归来获取view的所有子视图
- python获取完整网页内容(即包括js动态加载的):selenium+phantomjs
- php递归获取一个数组中指定key的值
- DisplayMetrics类 获取手机显示屏的基本信息 包括尺寸、密度、字体缩放等信息
- Android6.0(包括)以后获取Wifi 扫描信息列表即getScanResults()为空