我想在自参考表中对递归搜索的结果重新排序。代码在末尾。 数据正确显示,但在所需的输出中,我想像树表示一样构建。显示PROD_NO项目时,从ROUT_NO中获取所有包含PROD_NO的元素并将其放在下面。
获取所有0077976起点的项目。
输出:
ID NAME PER_ROUTER PROD_NO ROUT_NO SEQ TYPE
POCKET, LONG LEFT - WELD 1.00000 0066772 0077976 1 4
21202 C.5LG6 PANDUIT COVERS GRAY x 6 PIEDS 2.00000 0077976 1 2
1.00000 0081253 0077976 1 4
1.00000 0081235 0077976 1 4
41978 BOITE POCKET BIN LONG 33 x 15 x 12 DOUBLE PLY 1.00000 0077976 1 2
41979 PALETTE POCKET BIN (48 x 36 HT) 0.06666 0077976 1 2
PULLEY DRIVE 1.00000 0067907 0077976 1 4
20322 HAT6-90018-C50 (HAT6-9G018) BOWE GREY TEXTURE (Kg) 0.15000 0066772 2 2
POCKET, LONG LEFT - TRAY+BEND 1.00000 0066773 0066772 1 4
BRACKET SUPPORT, LONG LH 2.00000 0066774 0066772 1 4
BRACKET, REEL SUPPORT, LH 1.00000 0066775 0066772 1 4
BRACKET, ROD SUPPORT, LH 1.00000 0066776 0066772 1 4
BRACKET, LATCH, PCKT BIN, LG 1.00000 0066777 0066772 1 4
HANDLE, POCKET, LH 1.00000 0066778 0066772 1 4
PLATE, POCKET BIN, ALL 1.00000 0066779 0066772 1 4
CUP, POCKET BIN, ALL 4.00000 0066780 0066772 1 4
PLATE, POCKET BIN, ALL 1.00000 0066781 0066772 1 4
CABLE HOOK, PCKT BIN, LONG (1/LG) 2.00000 0066782 0066772 1 4
29750 PHMS M3 X 16 PHIL ZC VIS/SCREW 4.00000 0066772 1 2
00008 CRS SHEET 16G (0.060) 1.00000 0066773 1 1
01733 S-M4-2 2.00000 0066773 5 2
所需的输出是将PROD_NO下的所有行ROUT_NO组织起来
示例
ID NAME PER_ROUTER PROD_NO ROUT_NO SEQ TYPE
POCKET, LONG LEFT - WELD 1.00000 0066772 0077976 1 4
20322 HAT6-90018-C50 (HAT6-9G018) BOWE GREY TEXTURE (Kg) 0.15000 0066772 2 2
POCKET, LONG LEFT - TRAY+BEND 1.00000 0066773 0066772 1 4
00008 CRS SHEET 16G (0.060) 1.00000 0066773 1 1
01733 S-M4-2 2.00000 0066773 5 2
BRACKET SUPPORT, LONG LH 2.00000 0066774 0066772 1 4
lines of 0066774
lines of 0066774
lines of 0066774
BRACKET, REEL SUPPORT, LH 1.00000 0066775 0066772 1 4
lines of 0066775
lines of 0066775
lines of 0066775
BRACKET, ROD SUPPORT, LH 1.00000 0066776 0066772 1 4
lines of 0066776
lines of 0066776
lines of 0066776
BRACKET, LATCH, PCKT BIN, LG 1.00000 0066777 0066772 1 4
HANDLE, POCKET, LH 1.00000 0066778 0066772 1 4
PLATE, POCKET BIN, ALL 1.00000 0066779 0066772 1 4
CUP, POCKET BIN, ALL 4.00000 0066780 0066772 1 4
PLATE, POCKET BIN, ALL 1.00000 0066781 0066772 1 4
CABLE HOOK, PCKT BIN, LONG (1/LG) 2.00000 0066782 0066772 1 4
29750 PHMS M3 X 16 PHIL ZC VIS/SCREW 4.00000 0066772 1 2
21202 C.5LG6 PANDUIT COVERS GRAY x 6 PIEDS 2.00000 0077976 1 2
1.00000 0081253 0077976 1 4
1.00000 0081235 0077976 1 4
41978 BOITE POCKET BIN LONG 33 x 15 x 12 DOUBLE PLY 1.00000 0077976 1 2
41979 PALETTE POCKET BIN (48 x 36 HT) 0.06666 0077976 1 2
PULLEY DRIVE 1.00000 0067907 0077976 1 4
递归搜索的代码是
private void ParseTableRecursive(string parent)
{
if (parent.Trim().Length != 0)
{
List<DataRow> routerbills = dt_routerData.AsEnumerable().Where(x => x.Field<string>("Rout_No").ToString() == parent).ToList();
foreach (DataRow row in routerbills)
{
rec_dt_routerData.Rows.Add(new object[] {
row.Field<String>("id") == null ? "NULL" : row.Field<String>("Id").ToString(),
row.Field<String>("Name") == null ? "NULL" : row.Field<String>("Name").ToString(),
row.Field<Decimal>("per_router").ToString(), // == 0 ? "NULL" : row.Field<double>("Id").ToString(),
row.Field<String>("prod_no") == null ? "NULL" : row.Field<String>("prod_no").ToString(),
row.Field<String>("rout_no") == null ? "NULL" : row.Field<String>("rout_no").ToString(),
row.Field<String>("seq") == null ? "NULL" : row.Field<String>("Seq").ToString(),
row.Field<String>("type") == null ? "NULL" : row.Field<String>("Type").ToString(),
});
}
foreach (string child in routerbills.Select(x => x.Field<string>("Prod_No")).Distinct())
{
ParseTableRecursive(child);
}
}
}
我希望我已经描述了我正在寻找的模式。这可以在递归方法内部完成吗?或需要创建一个空数据表以在递归方法之后进行新的排序。