diff --git a/PROMS/DataLoader/Procedures.cs b/PROMS/DataLoader/Procedures.cs index 3bd957f9..c0583c45 100644 --- a/PROMS/DataLoader/Procedures.cs +++ b/PROMS/DataLoader/Procedures.cs @@ -329,17 +329,13 @@ namespace DataLoader // addpart = false; //} //FrType = 0; + Console.WriteLine("'before',{0},{1},{2},{3}", SectItm == null ? "" : SectItm.DisplayNumber, parentitem.DisplayNumber, level, dicSecCount.Count > 0 ? dicSecCount[level] : 0); dicSecParentItem[level] = SectItm; + int subSecs = drw["Sequence"].ToString().PadRight(12, ' ')[5] - 48; if (level > 0) { - if ((dicSecCount[level]) == 1) - // shift up a level, i.e. give me the parent for the previous level - SectItm = dicSecParentItem[--level]; - else - dicSecCount[level]--; // decrements number of sections to process + dicSecCount[level]--; // decrements number of sections to process } - // get number of subsections for this section - int subSecs = drw["Sequence"].ToString().PadRight(12, ' ')[5] - 48; if (subSecs > 0) { dicSecCount[++level] = subSecs; @@ -348,6 +344,20 @@ namespace DataLoader addpart = true; SectItm = null; // no previous sibling for the first child node. } + if (level > 0) + { + while (level > 0 && dicSecCount[level] == 0) + { + // shift up a level, i.e. give me the parent for the previous level + dicSecCount.Remove(level); + SectItm = dicSecParentItem[--level]; + if (level > 0) + parentitem = dicSecParentItem[level - 1]; + else + parentitem = itm; + } + } + Console.WriteLine("'after',{0},{1},{2},{3}", SectItm == null ? "" : SectItm.DisplayNumber, parentitem.DisplayNumber, level, dicSecCount.Count > 0 ? dicSecCount[level] : 0); } dv.Dispose(); //foreach (Item secItm in dicSecParentItem.Values)