Step 3 Create the Transfer Employees to Section Command Handler

VLF Windows Application Development

Step 3. Create the Transfer Employees to Section Command Handler

VFW112 – Drag and Drop between Components

1.  Create a new Reusable Part / Panel:

     Name: iiiVFW38

     Description: Transfer Employees to Section CH

2.  To define the user interface, replace the code for iiiVFW38 with the code supplied in VFW112 – Appendix. You created a similar interface design in the VFW110 – Simple Drag and Drop.

3.  Change the supplied code so that the DRAG_TO component uses your initials for iiiVFW37.

4.  Switch to the Design view. Your design should look like the following:

     A vertical splitter component divides the panel. The DRAG_FROM list on the left will contain employees for all department / sections excluding the department/section selected in the instance list. That is, all employees that could be transferred to the current department/section. The DRAG_FROM list view has a DragStyle property of Automatic.

     The right side contains the Section Employees component, iiiVFW37. Employees may be dragged into this component's list and then saved by updating the employee file.

5.  Create work fields for current department and section values:

Define Field(#currdept) Reffld(#deptment)
Define Field(#currsec) Reffld(#section)

 

6.  Create an uExecute method routine:

Mthroutine Name(uExecute) Options(*redefine)
#avlistmanager.getCurrentInstance Akey1(#deptment) Akey2(#section)
#currdept := #deptment
#currsec := #section
#DRAG_TO.uDepartment := #deptment
#DRAG_TO.usection := #section
Execute Subroutine(BuildEmps)
Endroutine

 

     Review the uExecute logic:

     Department and section codes are retrieved from the instance list, as Akey1 and AKey2 columns.

     DRAG_TO is the name of the iiiVFW37 component.

     The BuildEmps subroutine does not yet exist.

7.  Create the BuildEmps subroutine:

Subroutine Name(BuildEmps)
Clr_List Named(#DRAG_FROM)
Select Fields(#deptment #section #empno #surname #givename) From_File(pslmst1)
If ((#currdept *NE #deptment) *And (#currsec *NE #section))
#fullname := #surname + ', ' + #givename
Add_Entry To_List(#DRAG_FROM)
Endif
Endselect
Endroutine

 

     All entries from PSLMST1 are added to the list view DRAG_FROM, except employees for the instance list current department / section.

8.  On the Design view, select the DRAG_FROM list view on the left panel and create StartDrag and EndDrag event routines.

9.  Give the StartDrag event routine Payload, Continue and DragList parameters as shown.

Evtroutine Handling(#DRAG_FROM.StartDrag) Options(*NOCLEARMESSAGES *NOCLEARERRORS) Payload(#payload) Continue(#continue) Draglist(#draglist)
Endroutine

 

     Note: The AutoComplete prompter will complete these keywords as you type.

10. In the StartDrag routine, define a Payload_Employee component with a class of iiiVFW36 which contains a list collection of Employee Object (iiiVFW35).

Evtroutine Handling(#DRAG_FROM.StartDrag) Options(*NOCLEARMESSAGES *NOCLEARERRORS) Payload(#Payload) Continue(#Continue) Draglist(#Draglist)
Define_Com Class(#iiivfw36) Name(#Payload_Employee)
Endroutine

 

11. The StartDrag event is triggered when the user selects an entry and drags the mouse with the left mouse button held down.

     This routine needs to add selected entries from the DRAG_FROM list view to the Payload_Employee component. That is, into the payload object.

     The 'add to payload list collection' is performed by invoking the Add_Item method passing the parameters required.

     Add the following code to the StartDrag event routine to achieve this:

Selectlist Named(#DRAG_FROM)
Continue If(*Not #DRAG_FROM.currentItem.selected)
#Payload_Employee.add_item Udeptment(#deptment) Usection(#section) Uemployee(#empno) Ufullname(#fullname)
Endselect

 

12. Having populated the Payload_Employee object, the following is required:

a.  A reference to Payload_Object is passed as Payload.

b.  The DragList parameter is set to selection, meaning that the drag image will be the list view's selected items.

c.  The Continue parameter is set to true.

Add the following code to achieve this:

Set_Ref Com(#Payload) To(#Payload_Employee)
Set Com(#draglist) Dragliststyle(selection)
#continue := true

 

13. Add Payload and DragResult parameters to the EndDrag routine.

Evtroutine Handling(#DRAG_FROM.EndDrag) Options(*NOCLEARMESSAGES *NOCLEARERRORS) Payload(#Payload) Dragresult(#DragResult)
Endroutine

 

14. Define the Payload_Employee object with a class of iiiVFW36 and Reference of *dynamic.

     Create the Payload_Employee object with a Set_Ref to the parameter value #Payload.

     Implement this with the following code:

Define_Com Class(#iiivfw36) Name(#Payload_Employee) Reference(*dynamic)
Set_Ref Com(#payload_employee) To(*dynamic #payload)

 

15. If the DragResult parameter is ACCEPTED, delete currently selected entries from the DRAG_FROM list view.

     Add the following code to implement this:

If (#dragresult = ACCEPTED)
Selectlist Named(#DRAG_FROM)
Continue If(*Not #DRAG_FROM.currentItem.selected)
Dlt_Entry From_List(#DRAG_FROM)
Endselect
Endif

 

16. Compile the Transfer Employees to Section command handler (iiiVFW38). You will add additional logic for the push buttons in a later step.