Step 2. Add Logic to the Transfer Sections to Department Command Handler.
VFW110 – Simple Drag and Drop
1. On the
tab, select the DRAG_FROM list view and create an event.2. Select the DRAG_TO list view and create
event.3. Define a work field CURRDEPT referred to field DEPTMENT. This field will hold current department
3. Switch to the
tab. Create an method routine, which redefines the ancestor methoda. Add code to retrieve the
for the current instance list entry into field CURRDEPT. for the Departments instance list contains DEPTMENT.b. Execute a subroutine called
.Your code should look like the following:
Mthroutine Name(uExecute) Options(*redefine)
* Return Akey1 into work field CURRDEPT
#avlistmanager.getCurrentInstance Akey1(#currdept)
Execute Subroutine(BldDragTo)
Endroutine
4. Create a
subroutine to populate the DRAG_TO list view from the file SECTAB for the key CURRDEPT.Your code should look like the following:
Subroutine Name(BldDragTo)
Clr_List Named(#DRAG_TO)
Select Fields(#section #secdesc) From_File(sectab) With_Key(#currdept)
#std_codel := #currdept
#std_code := #section
#std_desc := #secdesc
Add_Entry To_List(#DRAG_TO)
Endselect
Endroutine
5. Complete the
event routine for the list view DRAG_FROM. This needs to contain entries for all records in the file SECTAB, except those for the current department.The
button click event will also rebuild the DRAG_FROM list view.a. Create a subroutine named
.b. Execute the
subroutine from the DRAG_FROM event routine.Your code should look like the following:
Evtroutine Handling(#DRAG_FROM.Initialize) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
Execute Subroutine(BldDragFrm)
Endroutine
Subroutine Name(BldDragFrm)
Clr_List Named(#DRAG_FROM)
* add all records, except for current department
Select Fields(#DRAG_FROM) From_File(sectab)
If (#deptment *NE #currdept)
Add_Entry To_List(#DRAG_FROM)
Endif
Endselect
Endroutine
6. The drag / drop operation requires that the target of the drag / drop accepts the proposed drop operation. Usually this will require that the target carries out some kind of validation in its
event. For example it may check that the payload object (which is not required for drag and drop within the same form, as here) is a valid object. In this case no validation is necessary and the DRAG_TO list view will simply return an of True. Complete the event for DRAG_TO.Your code should look like the following:
Evtroutine Handling(#DRAG_TO.DragOver) Options(*NOCLEARMESSAGES *NOCLEARERRORS) Acceptdrop(#acceptdrop)
#acceptdrop := true
Endroutine
7. The
event needs to process the copy or move operation. Once again in this case, the requirements are simplified because this is a drag / drop operation within the same form.Evtroutine Handling(#DRAG_TO.DragDrop) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
Selectlist Named(#DRAG_FROM)
If (#DRAG_FROM.currentItem.selected = true)
#std_codel := #deptment
#std_code := #section
#std_desc := #secdesc
Add_Entry To_List(#DRAG_TO)
Endif
Endselect
Endroutine
8. Complete the logic for the
button event. This needs to process the entries in the list DRAG_TO, which contains two types of entry:i. Entries for the current department. Their STD_CODEL column contains the current department code.
ii. Entries for the proposed section transfers to the current department. These have a STD_CODEL column containing their existing department code.
The requirement is to:
a. Read all DRAG_TO entries and ignore those for the current department.
b. Check if the proposed transfer section already exists for current department.
c. For accepted transfers, retrieve all fields from their current SECTAB record.
d. Insert a new record in SECTAB for current department and new section code.
e. Issue a message for successful inserts.
f. Delete the SECTAB record for the transferred section, using their previous department code.
g. Delete their entry from the DRAG_FROM list view.
h. Issue a message for each proposed transfer section which is rejected.
Your code should look like the following:
Evtroutine Handling(#PHBN_SAVE.Click)
Selectlist Named(#DRAG_TO)
#deptment := #std_codel
#section := #std_code
#secdesc := #std_desc
* Bypass entries for current department.
If (#deptment *NE #currdept)
* Check for this section in SECTAB for current department
Check_For In_File(sectab) With_Key(#currdept #section) Val_Error(*next)
If_Status Is_Not(*equalkey)
* get other data for section
Fetch Fields(*all) From_File(sectab) With_Key(#deptment #section)
* Reset department code to current
#deptment := #currdept
Insert Fields(*all) To_File(sectab) Val_Error(*next)
If_Status Is(*okay)
Message Msgtxt('Section ' + #section + ' transferred to department ' + #currdept)
* Remove section from donor department and DRAG_FROM list
#deptment := #std_codel
Delete From_File(sectab) With_Key(#deptment #section) Val_Error(*next)
Dlt_Entry From_List(#DRAG_FROM)
Endif
Else
Message Msgtxt('Section ' + #section + ' not transferred')
Dlt_Entry From_List(#DRAG_TO)
Endif
Endif
Endselect
Endroutine
9. Complete the Refresh push button
event.It should execute the
subroutine:Evtroutine Handling(#PHBN_REFRESH.Click)
Execute Subroutine(BldDragFrm)
Endroutine
10. Compile your new command handler.