Step 5. Add Search Logic to the Web Page

In this step, you will create method routines which search by invoking the xEmployeeDataServer's srvroutine SQLName and SQLDate , depending on the SearchType selected.

1.  Copy the list definition xEmployeeList, and the Group_By xEmployee from the Server Module iiixEmployeeDataServer and paste into the web page.

2.  Create a Method routine, named NameSearch with two inputs:

An input of class STD_OBJ, named NameType

An input of class iiiSearchName, named Name.

Your code should look like the following:

Mthroutine Name(NameSearch)

Define_Map For(*INPUT) Class(#std_obj) Name(#NameType)

Define_Map For(*INPUT) Class(#iiiSearchName) Name(#Name)

Endroutine

3.  Complete the NameSearch logic based on the following:

Define a component for xEmployeeDataServer's SQLName srvroutine, named SQLName.

Execute SQLName asynchronously, exchanging iiiSearchName, NameType, list xEmployeeList and field IO$STS.

Within an event routine SQLName.Completed

Clear the list EmployeeList

Select all entries in list xEmployeeList

  Assign STD_CODEL the value xEmployeeIdentification

  Assign iiiFullName the value xEmployeeSurname plus ', ' plus xEmployeeGiveNames

  Add each entry to the list EmployeeList

End Selectlist

Get the first entry from list EmployeeList

If EmployeeList.currentItem is_not null

  Set focus to EmployeeList, current item.

  Assign the group_by xEmployee to null.

     Your srvroutine should look like the following:

Mthroutine Name(NameSearch)

Define_Map For(*INPUT) Class(#std_obj) Name(#NameType)

Define_Map For(*INPUT) Class(#iiiSearchName) Name(#Name)

Define_Com Class(#iiixEmployeeDataServer.SQLName) Name(#SQLName)

#SQLName.ExecuteAsync( #Name #NameType #xEmployeeList #IO$STS )

Evtroutine Handling(#SQLName.Completed)

Clr_List Named(#EmployeeList)

Selectlist Named(#xEmployeeList)

#std_codel := #xEmployeeIdentification

#iiiFullName := #xEmployeeSurname.trim + ', ' + #xEmployeeGivenNames.trim

Add_Entry To_List(#EmployeeList)

Endselect

Get_Entry Number(1) From_List(#EmployeeList)

If (#EmployeeList.CurrentItem *IsNot *null)

#EmployeeList.CurrentItem.Focus := true

Endif

#xEmployee := *null

 

Endroutine

Endroutine

     Note: EmployeeList.CurrentItem is a reference to the current list item object. The *ISNOT *NULL operator tests for a null reference.

4.   Create a Method routine, named MonthSearch based on the following:

Map for input of class iiiSearchMonth, name SearchMonth

Define a component for xEmployeeDataServer's SQLDate srvroutine, name MonthSearch.

Clear the list EmployeeList

Execute MonthSearch asynchronously exchanging SearchMonth, list xEmployeeList and IO$STS.

Within an event routine for MonthSearch.Completed

Select all records in list xEmployeeList

   Assign STD_CODEL the value xEmployeeIdentification

   Assign iiiFullname the value xEmployeeSurname plus ', ' plus xEmployeeGiveNames.

   Add each entry to list EmployeeList

End of selectlist

Get first entry in list EmployeeList

If EmployeeList.currentItem is not null

Set focus to EmployeeList, current item.

Assign Group_By xEmployee value null.

     Your code should look like the following:

Mthroutine Name(MonthSearch)

Define_Map For(*INPUT) Class(#iiiSearchMonth) Name(#Month)

Define_Com Class(#iiixEmployeeDataServer.SQLdate) Name(#MonthSearch)

Clr_List Named(#EmployeeList)

#MonthSearch.ExecuteAsync( #Month #xEmployeeList #IO$STS )

Evtroutine Handling(#MonthSearch.Completed)

Selectlist Named(#xEmployeeList)

#std_codel := #xEmployeeIdentification

#iiiFullName := #xEmployeeSurname.trim + ', ' + #xEmployeeGivenNames.trim

Add_Entry To_List(#EmployeeList)

Endselect

Get_Entry Number(1) From_List(#EmployeeList)

If (#EmployeeList.CurrentItem *IsNot *null)

#EmployeeList.CurrentItem.Focus := true

Endif

#xEmployee := *null

 

Endroutine

Endroutine

 

5.  The SearchType dropdown was loaded with three entries which define the type of search, as shown in this table:

Caption

Value

Month

MONTH

Name Beginning

BEGIN

Name Containing

CONTAIN

 

6.  Complete the event handling routine for Search.Click, based on the following:

     Variable TypeSearch is set by the SearchType.ItemGotFocus event routine.

     Using a CASE loop for TypeSearch, invoke routine MonthSearch or NameSearch as required, passing iiiSearchMonth or iiiSearchName:

    Your code should look like the following:

Evtroutine Handling(#Search.Click)

Case Of_Field(#TypeSearch)

When (= MONTH)

#COM_SELF.MonthSearch( #SearchMonth )

When (= BEGIN)

#com_self.NameSearch( #TypeSearch #SearchName )

When (= CONTAINS)

#com_self.NameSearch( #TypeSearch #SearchName )

Endcase

Endroutine 

 7.  Compile and test your web page.

     A Name Beginning search, with the value of S should return a number of employees with surname beginning S. Remember the surname and given name fields contain proper case text. The Name beginning search value should be proper case. You could improve your logic by converting the first letter in this search value to uppercase.

#iiiSearchName := #iiiSearchName.leftmost.uppercase

     A Name Contains search with the value of rl should return employee Charles, Harris.

     A Month search for employees with a date of birth in February should return a number of employees.