Step 2 Add Logic to the Transfer Sections to Department Command Handler

VLF Windows Application Development

Step 2. Add Logic to the Transfer Sections to Department Command Handler.

VFW110 – Simple Drag and Drop

1.  On the Design tab, select the DRAG_FROM list view and create an Initialize event.

2.  Select the DRAG_TO list view and create DragDrop event.

3.  Define a work field CURRDEPT referred to field DEPTMENT. This field will hold current department

3.  Switch to the Source tab. Create an uExecute method routine, which redefines the ancestor method

a.  Add code to retrieve the Akey1 for the current instance list entry into field CURRDEPT. Akey1 for the Departments instance list contains DEPTMENT.

b.  Execute a subroutine called BldDragTo.

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 BldDragTo 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 Initialize 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 Refresh button click event will also rebuild the DRAG_FROM list view.

a.  Create a subroutine named BldDragFrm.

b.  Execute the BldDragFrm subroutine from the DRAG_FROM Initialize 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 DragOver 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 AcceptDrop of True. Complete the DragOver 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 DragDrop 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 Save button Click 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 Click event.

     It should execute the BldDragFrm subroutine:

Evtroutine Handling(#PHBN_REFRESH.Click)
Execute Subroutine(BldDragFrm)
Endroutine

 

10. Compile your new command handler.