/// <summary>
/// 获取类别列表
/// </summary>
/// <param name="parent_id">父ID</param>
/// <param name="nav_type">导航类别</param>
/// <returns>DataTable</returns>
public DataTable GetList(int parent_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM Core_Bus_ScenicArea");
strSql.Append(" where IsDelete=0 and PID<>0");
strSql.Append(" order by PID asc ");
DataSet ds = DbHelperSQL.Query(strSql.ToString());
//重组列表
DataTable oldData = ds.Tables[0] as DataTable;
if (oldData == null)
{
return null;
}
//创建一个新的DataTable增加一个深度字段
DataTable newData = new DataTable();
newData.Columns.Add("KeyId", typeof(int));
newData.Columns.Add("PID", typeof(int));
newData.Columns.Add("DeptId", typeof(int));
newData.Columns.Add("Deptlevel", typeof(int));
newData.Columns.Add("Code", typeof(string));
newData.Columns.Add("Name", typeof(string));
newData.Columns.Add("note", typeof(string));
//调用迭代组合成DAGATABLE
GetChilds(oldData, newData, parent_id, 0);
return newData;
}
/// <summary>
/// 从内存中取得所有下级类别列表(自身迭代)
/// </summary>
private void GetChilds(DataTable oldData, DataTable newData, int parent_id, int class_layer)
{
class_layer++;
DataRow[] dr = oldData.Select("PID=" + parent_id);
for (int i = 0; i < dr.Length; i++)
{
//添加一行数据
DataRow row = newData.NewRow();
row["KeyId"] = int.Parse(dr[i]["KeyId"].ToString());
row["PID"] = int.Parse(dr[i]["PID"].ToString());
row["DeptId"] = int.Parse(dr[i]["DeptId"].ToString());
row["Deptlevel"] = int.Parse(dr[i]["Deptlevel"].ToString());
row["Code"] = dr[i]["Code"].ToString();
row["Name"] = dr[i]["Name"].ToString();
row["note"] = dr[i]["note"].ToString();
newData.Rows.Add(row);
//调用自身迭代
this.GetChilds(oldData, newData, int.Parse(dr[i]["KeyId"].ToString()), class_layer);
}
}
/// 获取类别列表
/// </summary>
/// <param name="parent_id">父ID</param>
/// <param name="nav_type">导航类别</param>
/// <returns>DataTable</returns>
public DataTable GetList(int parent_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM Core_Bus_ScenicArea");
strSql.Append(" where IsDelete=0 and PID<>0");
strSql.Append(" order by PID asc ");
DataSet ds = DbHelperSQL.Query(strSql.ToString());
//重组列表
DataTable oldData = ds.Tables[0] as DataTable;
if (oldData == null)
{
return null;
}
//创建一个新的DataTable增加一个深度字段
DataTable newData = new DataTable();
newData.Columns.Add("KeyId", typeof(int));
newData.Columns.Add("PID", typeof(int));
newData.Columns.Add("DeptId", typeof(int));
newData.Columns.Add("Deptlevel", typeof(int));
newData.Columns.Add("Code", typeof(string));
newData.Columns.Add("Name", typeof(string));
newData.Columns.Add("note", typeof(string));
//调用迭代组合成DAGATABLE
GetChilds(oldData, newData, parent_id, 0);
return newData;
}
/// <summary>
/// 从内存中取得所有下级类别列表(自身迭代)
/// </summary>
private void GetChilds(DataTable oldData, DataTable newData, int parent_id, int class_layer)
{
class_layer++;
DataRow[] dr = oldData.Select("PID=" + parent_id);
for (int i = 0; i < dr.Length; i++)
{
//添加一行数据
DataRow row = newData.NewRow();
row["KeyId"] = int.Parse(dr[i]["KeyId"].ToString());
row["PID"] = int.Parse(dr[i]["PID"].ToString());
row["DeptId"] = int.Parse(dr[i]["DeptId"].ToString());
row["Deptlevel"] = int.Parse(dr[i]["Deptlevel"].ToString());
row["Code"] = dr[i]["Code"].ToString();
row["Name"] = dr[i]["Name"].ToString();
row["note"] = dr[i]["note"].ToString();
newData.Rows.Add(row);
//调用自身迭代
this.GetChilds(oldData, newData, int.Parse(dr[i]["KeyId"].ToString()), class_layer);
}
}