>>* All parent values of A0 are top level branches - any self value of >>* nothing in spaces 5 and 6 or the value of B1 in spaces 5 and 6 are top level. >>* All other values in spaces 5 and 6 are sub levels and fall under the branch >>* of its parent >> >>cPARENT cSELF SEQ >> >>A0 1MHG && top level message header >>A0 2TRG 1829 && top level 1st transaction >>A0 5BISB10001 1829 && top level >>A0 9BISB10001 1829 && top level >>5BISB10001 5BPIF10001 1829 && 2nd level branch, directly under 5BISB10001 >>5BPIF10001 5DRVF20001 1829 && 3rd level branch, directly under 5BPIF10001 >>5BPIF10001 5DRVF20002 1829 && 3rd level branch, directly under 5BPIF10001 >>5DRVF20001 6PDRF30001 1829 && 4th level branch, directly under 5DRVF20001 >>A0 2TRG 1830 && top level 2nd transaction >>A0 5BISB10001 1830 && top level >>A0 9BISB10001 1830 && top level >>5BISB10001 5BPIF10001 1830 && 2nd level branch, directly under 5BISB10001 >>5BPIF10001 5DRVF20001 1830 && 3rd level branch, directly under 5BPIF10001 >>5BPIF10001 5DRVF20002 1830 && 3rd level branch, directly under 5BPIF10001 >>5DRVF20001 6PDRF30001 1830 && 4th level branch, directly under 5DRVF20001 >>5DRVF20001 6PDRF30002 1830 && 4th level branch, directly under 5DRVF20001 >> >>Note: 1st four characters are type i.e. 5BPI, 5BIS, 1MHG, etc. >> 5&6 are 'sortof' levels i.e. B1, F1, F2, etc >> 7-10 is a counter that denotes it is the first, 2nd, etc 0001, 0002, etc. >> Records are stored in this order and each 2TRG record denotes the >> next 'group' or transaction >> >>The records should look like this in the treeview: >> >>1MHG && 1st Message >>2TRG && 1st transaction or 'group' in this message >>5BISB10001 >> 5BPIF10001 && 1st 5BPI under this 5BIS in 1st transactioin >> 5DRVF20001 && 1st 5DRV under this 5BPI >> 5DRVF20002 && 2nd 5DRV under this 5BPI >> 6PDRF30001 && 1st 6PDR under this 5DRV >>9BISB10001 >>2TRG && 2nd transaction or 'group' in this message >>5BISB10001 >> 5BPIF10001 && 1st 5BPI under this 5BIS in 2nd transaction >> 5DRVF20001 && 1st 5DRV under this 5BPI in 2nd transaction >> 5DRVF20002 && 2nd 5DRV under this 5BPI in 2nd transaction >> 6PDRF30001 && 1st 6PDR under this 5DRV in 2nd transaction >> 6PDRF30002 && 2nd 6PDR under this 5DRV in 2nd transaction >>9BISB10001 >> >>>>
>>SELE Al3Parnt >>set ORDER to 0 >>GO TOP >>SCAN >> STORE RECNO('al3parnt') TO mrecno >> * al3parnt.cparent is the parent of this record or upper branch >> * al3parnt.cself is the identity of this record >> STORE al3parnt.seq TO mseq && transaction sequence number >> IF al3parnt.cparent = "A0" && this record's parent 'branch' A0 is always top level branch >> tNode = THISFORM.AddNode(oNode) && add this top level node >> tNode.Text = al3parnt.cSELF && this record's identity >> tNode.Expanded = .T. >> tNode.Image = 1*5 + 1 >> mtext = tNode.Text >> * Now create the child branches for this top level branch >> * based on the records' cparent field matching this record's cself field >> SCAN FOR ALLTRIM(UPPER(al3parnt.cparent)) = ALLTRIM(UPPER(mtext)) .and. al3parnt.seq=mseq >> xNode = THISFORM.AddNode(tNode) && add the child branch to the above parent branch >> xNode.Text = al3parnt.cSELF && this child branch's identity >> xNode.Expanded = .T. >> xNode.Image = 1*5 + 1 >> mtext = xNode.Text >> *!* Here is where I get stuck >> * Now need to process this child record's sub branches if any, but my >> * logic is wrong because this obviously won't work. I need to determine >> * how many levels it could possibly go or handle an infinite number of >> * sublevels (child branches) >> ENDSCAN >> ENDIF >> IF RECNO()<>mrecno >> GOTO mrecno >> ENDIF >>ENDSCAN >>>>
>+-1MHG >+-2TRG >+-5BISB10001 >| +-5BPIF10001 >| +-5DRVF20001 >| | +-6PDRF30001 >| +-5DRVF20002 >+-9BISB10001 >+-2TRG >+-5BISB10001 >| +-5BPIF10001 >| +-5DRVF20001 >| | +-6PDRF30001 >| | +-6PDRF30002 >| +-5DRVF20002 >+-9BISB10001 >>
>Create Cursor Al3Parnt (cPARENT c(10), cSELF c(10), SEQ i) >Insert into Al3Parnt values ("A0 ","1MHG ",0 ) &&top level message header >Insert into Al3Parnt values ("A0 ","2TRG ",1829 ) && top level 1st transaction >Insert into Al3Parnt values ("A0 ","5BISB10001 ",1829 ) && top level >Insert into Al3Parnt values ("A0 ","9BISB10001 ",1829 ) && top level >Insert into Al3Parnt values ("5BISB10001 ","5BPIF10001 ",1829 ) && 2nd level branch, directly under 5BISB10001 >Insert into Al3Parnt values ("5BPIF10001 ","5DRVF20001 ",1829 ) && 3rd level branch, directly under 5BPIF10001 >Insert into Al3Parnt values ("5BPIF10001 ","5DRVF20002 ",1829 ) && 3rd level branch, directly under 5BPIF10001 >Insert into Al3Parnt values ("5DRVF20001 ","6PDRF30001 ",1829 ) && 4th level branch, directly under 5DRVF20001 >Insert into Al3Parnt values ("A0 ","2TRG ",1830 ) && top level 2nd transaction >Insert into Al3Parnt values ("A0 ","5BISB10001 ",1830 ) && top level >Insert into Al3Parnt values ("A0 ","9BISB10001 ",1830 ) && top level >Insert into Al3Parnt values ("5BISB10001 ","5BPIF10001 ",1830 ) && 2nd level branch, directly under 5BISB10001 >Insert into Al3Parnt values ("5BPIF10001 ","5DRVF20001 ",1830 ) && 3rd level branch, directly under 5BPIF10001 >Insert into Al3Parnt values ("5BPIF10001 ","5DRVF20002 ",1830 ) && 3rd level branch, directly under 5BPIF10001 >Insert into Al3Parnt values ("5DRVF20001 ","6PDRF30001 ",1830 ) && 4th level branch, directly under 5DRVF20001 >Insert into Al3Parnt values ("5DRVF20001 ","6PDRF30002 ",1830 ) && 4th level branch, directly under 5DRVF20001 > >* Define some constants. >#Define tvwFirst 0 >#Define tvwLast 1 >#Define tvwNext 2 >#Define tvwPrevious 3 >#Define tvwChild 4 > >#Define cnLOG_PIXELS_X 88 >#Define cnLOG_PIXELS_Y 90 >#Define cnTWIPS_PER_INCH 1440 >* 1440 twips per inch >oForm = createobject('myForm') >oForm.Show >Read events > >Define CLASS myForm AS form > > > Top = 2 > Left = 2 > Height = 600 > Width = 300 > DoCreate = .T. > Caption = "TreeView - testpad" > BackColor = RGB(192,192,192) > Name = "myForm" > ShowWindow=2 > > Add OBJECT myTree AS olecontrol WITH ; > Top = 12, ; > Left = 0, ; > Height = 500, ; > Width = 300, ; > Name = "OleTreeView", ; > OleClass = 'MSComCtlLib.TreeCtrl' > > *-- Fill the tree values > Procedure filltree > This.show >With THIS.oletreeview.nodes > >SELE Al3Parnt >set ORDER to 0 >SCAN > IF al3parnt.cparent = "A0" && this record's parent 'branch' A0 is always top level branch > .add(,tvwFirst,Trim(al3parnt.cself)+'_'+Ltrim(Str(seq)),Trim(al3parnt.cSelf)) > Else > .Add(Trim(al3parnt.cParent)+'_'+Ltrim(Str(seq)), tvwChild, ; > Trim(al3parnt.cself)+'_'+Ltrim(Str(seq)),Trim(al3parnt.cSelf)) > endif >EndScan >EndWith >Endproc > > Procedure QueryUnload > Clear events >Endproc > > > Procedure Init > Set TALK OFF > * Check to see if OCX installed and loaded. > If TYPE("THIS.oleTreeView") # "O" OR ISNULL(THIS.oletreeview) > Return .F. > Endif > With THIS.oletreeview > .linestyle =1 > .labeledit =1 > .indentation = 5 > .PathSeparator = '\' > .Scroll = .t. > .OleDragMode = 0 > .OleDropMode = 0 > Endwith > This.filltree() > loTVUtils = CreateObject('TVUtils') > _cliptext = loTVUtils.tvlister(this.OleTreeView) >Endproc > > > Procedure oletreeview.NodeClick > *** ActiveX Control Event *** > Lparameters node > Node.ensurevisible >Endproc > >ENDDEFINE > >Define Class TvUtils as Line >TVText = '' >Procedure TVLister >Lparameters toTV > Local lnIndex,lnLastIndex > this.TVText='' > With toTV > lnIndex = .Nodes(1).Root.FirstSibling.Index > lnLastIndex = .Nodes(1).Root.LastSibling.Index > this._GetSubNodes(lnIndex,toTV,lnIndex) > Do While lnIndex # lnLastIndex > lnIndex = .Nodes(lnIndex).Next.Index > this._GetSubNodes(lnIndex,toTV,lnIndex) > Enddo > Endwith > Return this.TVText >EndProc > >Procedure _GetSubNodes > Lparameters tnIndex, toTV, tnRootIndex > Local lnIndex, lnLastIndex > With toTV > this.WriteNode(tnIndex,toTV, tnRootIndex) > If .Nodes(tnIndex).Children > 0 > lnIndex = .Nodes(tnIndex).Child.Index > lnLastIndex = .Nodes(tnIndex).Child.LastSibling.Index > this._GetSubNodes(lnIndex,toTV,tnRootIndex) > Do While lnIndex # lnLastIndex > lnIndex = .Nodes(lnIndex).Next.Index > this._GetSubNodes(lnIndex,toTV,tnRootIndex) > Enddo > Endif > Endwith >EndProc > >Procedure WriteNode > Lparameters tnCurIndex, toTV,tnRootIndex > Local lnRootIndex, lnIndex, lcPrefix, lcKey, lnLevel > lnIndex = tnCurIndex > > With toTV > lcPrefix = '+-' + .Nodes(lnIndex).Text > lnLevel = 0 > Do While lnIndex # tnRootIndex > lnIndex = .Nodes(lnIndex).Parent.Index > lcPrefix = Iif(.Nodes(lnIndex).LastSibling.Index = lnIndex,' ','|')+Space(3)+lcPrefix > lnLevel = lnLevel + 1 > EndDo > this.TVText = this.TVText + lcPrefix + Chr(13) > EndWith >endproc >enddefine >>Cetin