Step 3. Create the Transfer Employees to Section Command Handler
VFW112 – Drag and Drop between Components
1. Create a new
:iiiVFW38
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
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 Automatic.
property ofThe 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
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
logic:Department and section codes are retrieved from the instance list, as
and columns.DRAG_TO is the name of the iiiVFW37 component.
The
subroutine does not yet exist.7. Create the
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
view, select the DRAG_FROM list view on the left panel and create and event routines.9. Give the
event routine and parameters as shown.Evtroutine Handling(#DRAG_FROM.StartDrag) Options(*NOCLEARMESSAGES *NOCLEARERRORS) Payload(#payload) Continue(#continue) Draglist(#draglist)
Endroutine
Note: The prompter will complete these keywords as you type.
10. In the StartDrag routine, define a
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
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
method passing the parameters required.Add the following code to the
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
object, the following is required:a. A reference to
is passed as .b. The selection, meaning that the drag image will be the list view's selected items.
parameter is set toc. The
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
and parameters to the routine.Evtroutine Handling(#DRAG_FROM.EndDrag) Options(*NOCLEARMESSAGES *NOCLEARERRORS) Payload(#Payload) Dragresult(#DragResult)
Endroutine
14. Define the
object with a class of iiiVFW36 and Reference of *dynamic.Create the
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
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
command handler (iiiVFW38). You will add additional logic for the push buttons in a later step.