>LPARAMETER iNodeIndex >LOCAL iNodeIndex, i, iTempIndex, nChanges, lnLast_Mod, lnSeekVal, oTree > >with Thisform > nChanges = 0 > oTree = .TList2 > iTempIndex = oTree.Nodes(iNodeIndex).Child.FirstSibling.Index > > *Loop through all Parent's Child Nodes > FOR i = 1 to oTree.Nodes(iNodeIndex).Children > select itemtree > lnSeekVal = val(substr(oTree.Nodes(iTempIndex).Key, 3)) > set order to node_id > Seek lnSeekVal > if node_id == lnSeekVal > if sort_order <> i > replace sort_order with i && re-orders > nChanges = nChanges + 1 > .lUpdateItemTree = .T. > endif > else > .Log("Seek failed on node id:" + oTree.Nodes(iTempIndex).Key, program(), 1) > endif > * If the Node we are on has a child call the Sub again > IF oTree.Nodes(iTempIndex).Children > 0 > nChanges = nChanges + .SaveChild(iTempIndex) > ENDIF > * If we are not on the last child move to the next child Node > IF i <> oTree.Nodes(iNodeIndex).Children > iTempIndex = oTree.Nodes(iTempIndex).Next.Index > ENDIF > ENDFOR > >ENDWITH > >return nChanges>
>>>select node_id, parent_id, root_id, descrip, sort_order from ItemTree order by sort_order -- table has more fields, of course>>>
>>>with thisform >>> nChanges = 0 >>> nSortOrder = 1 >>>* Find a root node in the TreeView >>> oTree = .TList2 >>> if oTree.Nodes.count > 0 >>> for i = 1 to oTree.Nodes.count >>> oTmp = oTree.Nodes(i).parent >>> if isnull(oTmp) then >>> iTmpIndex = i >>> exit >>> endif >>> next i >>>* Get the index of the root node that is at the top of the TreeView >>> iIndex = oTree.Nodes(iTmpIndex).FirstSibling.index >>> iTmpIndex = iIndex >>> >>> lnSeekVal = val(substr(oTree.Nodes(iIndex).key, 3)) >>> select itemtree >>> set order to node_id >>> seek lnSeekVal >>> if node_id == lnSeekVal and lnSeekVal <> 0 >>> if thisform.nBaseRoot_id >= 0 >>> nSortOrder = sort_order >>> else >>> if sort_order <> nSortOrder >>> replace sort_order with nSortOrder >>> nChanges = nChanges + 1 >>> .lUpdateItemTree = .t. >>> endif >>> endif >>> else >>> .log("Seek Failed on node id:" + oTree.Nodes(iIndex).key, program(), 1) >>> endif >>> >>>* If the Node has Children call the sub that writes the children >>> if oTree.Nodes(iIndex).Children > 0 >>> nChanges = nChanges + .SaveChild(iIndex) >>> endif >>> >>> do while iIndex <> oTree.Nodes(iTmpIndex).LastSibling.index >>>*Loop through all the root nodes >>> nSortOrder = nSortOrder + 1 >>> lnSeekVal = val(substr(oTree.Nodes(iIndex).next.key, 3)) >>> select itemtree >>> seek lnSeekVal >>> if node_id == lnSeekVal and lnSeekVal <> 0 >>> if sort_order <> nSortOrder >>> replace sort_order with nSortOrder >>> nChanges = nChanges + 1 >>> .lUpdateItemTree = .t. >>> endif >>> else >>> .log("Seek Failed on node id:" + oTree.Nodes(iIndex).next.key, program(), 1) >>> endif >>> if oTree.Nodes(iIndex).next.Children > 0 >>> nChange = nChanges + .SaveChild(oTree.Nodes(iIndex).next.index) >>> endif >>> iIndex = oTree.Nodes(iIndex).next.index >>> enddo >>> endif >>> .log("Total number of changed records in the Item tree: " + alltrim(transform(m.nChanges,'@999,999,999')), program(), 1) >>>endwith >>> >>>return nChanges >>>>>>