You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

The Tree View will have three levels, departments, employees and employee notes. All data will be loaded initially.

1.  Create an AddEntry method routine. This needs five input parameters:

  • Map of class STD_OBJ, name Column1
  • Map of class STD_DESC, name Column 2
  • Map of class STD_DESCL, name Column 3
  • Map of class PRIM_BMP, name Image, passed by reference
  • Map of class PRIM_TVIT, name ParentItem, passed by reference

     Your code should look like the following:
Mthroutine Name(AddEntry)
Define_Map For(*INPUT) Class(#STD_OBJ) Name(#Column1)
Define_Map For(*INPUT) Class(#STD_desc) Name(#Column2) Mandatory(' ')
Define_Map For(*INPUT) Class(#STD_descl) Name(#Column3) Mandatory(' ')
Define_Map For(*INPUT) Class(#prim_bmp) Name(#Image) Mandatory(*NULL) Pass(*BY_REFERENCE)
Define_Map For(*input) Class(#Prim_tvit) Name(#ParentItem) Mandatory(*Null) Pass(*By_reference)
Endroutine

       Note: All except the first map have a Mandatory() parameter, meaning the parameter will be given its Mandatory value if not passed. These parameters are optional.

2.  To complete the AddEntry routine, the following logic is required:
Assign STD_OBJ to Column1
Assign STD_DESC to Column2
Assign STD_DESCL to Column3
Add entry to TreeView
Set reference to TreeView.CurrentItem.ParentItem from ParentItem
Set refrence to TreeViewcurrentItem.Image to Image
Set TreeView.CurrentItem.hasChildren property to Yes for level 1 and 2
Set TreeView.CurrentItem.hasChildren poperty to No for level 3

     

Your code should look like the following:
Mthroutine Name(AddEntry)
Define_Map For(*INPUT) Class(#STD_OBJ) Name(#Column1)
Define_Map For(*INPUT) Class(#STD_desc) Name(#Column2) Mandatory(' ')
Define_Map For(*INPUT) Class(#STD_descl) Name(#Column3) Mandatory(' ')
Define_Map For(*INPUT) Class(#prim_bmp) Name(#Image) Mandatory(*NULL) Pass(*BY_REFERENCE)
Define_Map For(*input) Class(#Prim_tvit) Name(#ParentItem) Mandatory(*Null) Pass(*By_reference)
#std_obj := #Column1
#std_desc := #Column2
#std_descl := #Column3
Add_Entry To_List(#TreeView)
#TreeView.Currentitem.ParentItem <= #ParentItem
#TreeView.Currentitem.image <= #Image

  • Employee notes have no children
    If (#TreeView.currentitem.level = 3)
    #TreeView.CurrentItem.HasChildren := No
    Else
    #TreeView.CurrentItem.HasChildren := Yes
    Endif
    Endroutine
         Note: When an item HasChildren property is No, an expand symbol is not shown. Employee Notes are level 3 and have no children.
    3.  Create a LoadDepts method routine, no maps are required. Add logic to perform the following:
    Read all departments from table xDepartments
    For each entry invoke AddEntry, passing xDepartmentCode, xDepartmentDescription, *blank, xImageDepartment32
         Your code should look like the following:
    Mthroutine Name(LoadDepts)
    Select Fields(#xDepartmentCode #xDepartmentDescription) From_File(xDepartments)
    #com_self.addentry( #xDepartmentCode #xDepartmentDescription "" #xImageDepartment32 )
    Endselect
    Endroutine
         Note: xImageDepartment32 is a Repository Bitmap component.
    4.  Create a LoadEmploys method routine with input for department code and ParentItem passed by reference.
    Mthroutine Name(LoadEmploys)
    Define_Map For(*INPUT) Class(#xDepartmentCode) Name(#DeptCode)
    Define_Map For(*INPUT) Class(#prim_tvit) Name(#ParentItem) Pass(*BY_REFERENCE)
    Endroutine
         Each employee entry must have a parent item reference to a department entry.
    5.  Complete LoadEmploys with the following logic. Note that surname and givennames must be passed to AddEntry as a native string.
    Read all employees from index xEmployeeeByDepartment with key DeptCode
    Invoke AddEntry passing xEmployeeIdentification, xEmployeeSurname, xEmployeeGivenNames, xImageEmployee32 and ParentItem
    End Select
         Your code should look like the following:
    Mthroutine Name(LoadEmploys)
    Define_Map For(*INPUT) Class(#xDepartmentCode) Name(#DeptCode)
    Define_Map For(*INPUT) Class(#prim_tvit) Name(#ParentItem) Pass(*BY_REFERENCE)
     
    Select Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames) From_File(xEmployeeByDepartment) With_Key(#DeptCode)
    #com_self.AddEntry( #xEmployeeIdentification #xEmployeeSurname.asNativeString #xEmployeeGivenNames.asNativeString #xImageEmployee32 #ParentItem )
    Endselect
    Endroutine
     
    6.  Invoke LoadEmploys for each department from LoadDepts passing department code and TreeView.currentitem:
    Mthroutine Name(LoadDepts)
    Select Fields(#xDepartmentCode #xDepartmentDescription) From_File(xDepartments)
    #com_self.addentry( #xDepartmentCode #xDepartmentDescription "" #xImageDepartment32 )
    #com_self.LoadEmploys( #xDepartmentCode #TreeView.currentitem )
    Endselect
    Endroutine
     
    7.  Create a LoadNotes method routine with input maps for EmployCode and ParentItem passed by reference
    Mthroutine Name(LoadNotes)
    Define_Map For(*INPUT) Class(#xEmployeeIdentification) Name(#EmployCode)
    Define_Map For(*INPUT) Class(#prim_tvit) Name(#ParentItem) Pass(*BY_REFERENCE)
    Endroutine
    8.  Add the following logic to LoadNotes:
    Read all employee notes from index xEmployeeNotesByEmployee with key EmployCode
      For each entry, invoke AddEntry passing these parameters:
    xEmployeeNoteCreateUpdate as display string
    xEmployeeNote as native string, trimmed
    *blank
    xImageDetail32
    ParentItem
         Your code should look like the following:
    Mthroutine Name(LoadNotes)
    Define_Map For(*INPUT) Class(#xEmployeeIdentification) Name(#EmployCode)
    Define_Map For(*INPUT) Class(#prim_tvit) Name(#ParentItem) Pass(*BY_REFERENCE)
    Select Fields(#xEmployeeNote) From_File(xemployeenotesbyemployee) With_Key(#EmployCode)
    #com_self.addentry( #xEmployeeNoteCreateUpdate.asdisplaystring #xEmployeeNote.AsNativeString.trim "" #xImageDetails32 #ParentItem )
    Endselect
     
    Endroutine
    9.  Add code to invoke LoadNotes from LoadEmploys, passing xEmployeeIdentification and TreeView.CurrentItem.
    Mthroutine Name(LoadEmploys)
    Define_Map For(*INPUT) Class(#xDepartmentCode) Name(#DeptCode)
    Define_Map For(*INPUT) Class(#prim_tvit) Name(#ParentItem) Pass(*BY_REFERENCE)
     
    Select Fields(#xEmployeeIdentification #xEmployeeSurname #xEmployeeGivenNames) From_File(xEmployeeByDepartment) With_Key(#DeptCode)
    #STD_desc := #xEmployeeSurname.AsNativeString
    #std_descl := #xEmployeeGivenNames.AsNativeString
    #com_self.AddEntry( #xEmployeeIdentification #std_desc #std_descl #xImageEmployee32 #ParentItem )
    #com_self.LoadNotes( #xEmployeeIdentification #TreeView.currentitem )
    Endselect
    Endroutine
    10. Invoke LoadDepts from form CreateInstance event routine:
    Evtroutine Handling(#com_owner.CreateInstance)
     
    Set Com(#com_owner) Caption(*component_desc)
    #com_self.LoadDepts
    Endroutine
    11. Compile and test the form.
    [ |../../index.htm#lansa/frmeng01_0540.htm]
  • No labels