Tree list newie lol
ksargent at oversiteonline.com
ksargent at oversiteonline.com
Tue Jan 22 18:53:01 EST 2019
I have an Omnis project that has a perfect application for a tree list.
When applying to actual data this will get documents that are stored in a
MySEQ database. These documents with be displayed in a tree list like what
you would see in File Explorer. This structure with be totally user defined.
I am brand new to tree list.
In my test for learning this I have created an Employee file. Most
Employees have a boss. An employee with a zero in field for boss has no
boss and with be at the first level of the list.
employee_id
emoplyee_name
employee_boss_id
employee_boss_name
1
Jim
0
NULL
2
Kim
1
Jim
3
Jeff
1
Jim
4
Will
2
Kim
5
Sarah
4
Will
6
Katherine
4
Will
7
Ben
6
Katherine
8
Tom
6
Katherine
9
Jane
6
Katherine
10
Allison
5
Sarah
11
June
5
Sarah
12
Rick
3
Jeff
13
Mike
2
Kim
14
Susan
13
Mike
15
Betty
13
Mike
16
Beverly
13
Mike
17
Madeline
1
Jim
18
Roger
7
Ben
19
Ty
7
Ben
20
Rebecca
7
Ben
41
Jenny
0
NULL
Employee 1 and 41 do not have a boss assigned. Jim and Jenny.
Jim has 3 employees assigned to him and each of these have employees
assigned.
Jenny
Jim
Jeff
Kim
Will
Mike
Madeline
And this continues
What I want to do is load the root level of the tree list with the employees
without a boss. When a click is made to expand the tree list I want to make
an MySQL call to load the employees assigned to the person in the tree list.
In order to do this, I have to have some reference in the tree list
associated with the Employee ID of the boss so I can load them.
I have made the following attempt to load a tree list.
If not(#1) ;; during the testing #1 is zero if intent is to get employee
with no boss. ie the boss id is zero
Do $cinst.$objs.Test_tree.$clearallnodes
End If
Do $redraw()
;
Set current list transfer_list
Define list
{Employee_Boss_id,Employee_name,Employee_ID,pIcon,pIdent,pEnterable,pShowexo
andalways,pTextColor}
;
Set current list TreeListL
Define list
{Employee_Boss_id,Employee_name,Employee_ID,pIcon,pIdent,pEnterable,pShowexo
andalways,pTextColor}
Calculate pNodeItem as 0
Calculate pIcon as 0
Calculate pIdent as 0
Calculate pEnterable as 1
Calculate pShowexoandalways as 0
Calculate pTextColor as 0
;
Do code method SignIn_Out/Sign_in ;; logs into MySQL data base
;
;
Calculate F_MySQL.MySQL_statement_name as 'Get BudgetHeaders'
;
Do F_MySQL.MySQL_session_object.$newstatement(F_MySQL.MySQL_statement_name)
Returns F_MySQL.MySQL_StatementObj
;
Do F_MySQL.MySQL_StatementObj.$prepare('SELECT employee_boss_id,
emoplyee_name, employee_id FROM zemployee where employee_boss_id =
@[#1]')
If flag false
OK message {false on prepare select budget header
20181120.1328}
End If
;
Do F_MySQL.MySQL_StatementObj.$execute() Returns #F
If flag false
OK message {false on execute get budget header
20181120.1328}
End If
;
Do F_MySQL.MySQL_StatementObj.$fetch(TreeListL,9999) Returns
F_MySQL.MySQL_fetch_status
;
Do code method SignIn_Out/Sign_out ;; logs out of MySQL data
; Tree_listL now has the data from the MySQL data
If #LN
Clear sort fields
Set sort field Employee_name
Sort list
Clear sort fields
Calculate #L as 1
Repeat
Load from list
Calculate pTextColor as 0
Calculate pEnterable as 1
Calculate pIdent as Employee_ID
Calculate pIcon as 0
Replace line in list
;
Set current list transfer_list
Add line to list
Set current list TreeListL
Do $redraw()
Calculate #L as #L+1
Until #L>#LN
; Do $cinst.$objs.Test_tree.$setnodelist(kFlatList,pNodeItem,transfer_list)
;; this was used in an earlier attempt
Set current list transfer_list
If #LN
;
Calculate #L as 1
Calculate vEmployeeName as ''
Repeat
Load from list
;
If
vEmployeeName<>Employee_name
Calculate
vEmployeeName as Employee_name
;
Do $cinst.$objs.Test_tree.$add(Employee_name,Employee_ID) Returns vNode
;; vNode is a local variable set with type Item reference
; according to Programing reference manual. I am adding the Employee name
to the tree list and assigning the ident the value of Employee_ID which is
employee record number
; according to Programing reference manual. The VNode will return a item
reference .I assume this is a unique reference to the node
OK message
{[vNode] is value of vNode ..... pNodeItem is [pNodeItem]}
; the value
returned for the item reference is always 1
Do vNode.$tag.$assign(Employee_ID)
;; attempt to assign the $Tag the employee ID
Do
vNode.$showexpandalways.$assign(kTrue)
;
End If
;
Calculate #L as #L+1
Until #L>#LN
Calculate #L as 1
Load from list
End If
End If
;
Do $redraw()
This adds the correct employees to the tree list.
I see the two names at the root
I expected the value of VNode to be different for each node. Also, I
expected the $Ident to have the value of Employee_ID. When I have tried to
retrieve $Ident the value is zero. Now I might be doing this wrong.
Suggestions?????????
More information about the omnisdev-en
mailing list