Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Step 4. Compile and run the Program

Step 1. Create the Form

You start creating an application by creating a form or a dialog. The dialog will become your application's window when it is running.

...

The first property you need to change is the form's Caption property to create a title for your window:

1.      Click   Click on the Caption property.

2.      Type   Type Employee. As you type it, the new caption is displayed in the title bar of the form.

...

Next make the form a bit larger than the default size:

1.      Select   Select it and move the cursor towards its edge.

2.      When   When the cursor changes to a double-arrow, drag the edges with the left mouse button pressed down.

3.      Alternatively  Alternatively, you can change the Height and Width properties of the form.

...

To add the PARTNAME field:

1.      Start   Start by locating it in the Repository.

2.      Drag   Drag the PARTNAME field to the form or double-click it.

3.      Bring   Bring up the Details tab and make its LabelType property Caption.

4.      Type   Type 'Enter partial surname:' in its Caption property 

...

In addition to the Get command button used with the partial surname field, you need these command buttons to work with the employee details:



To add buttons to the form:

1.

...

  Select the Controls tab.

2.

...

  Drag push button to the form four times. Alternatively you can double-click it four times.

3.

...

  Change the captions of the buttons.

a.      Make   Make the caption of the first button Get

b.      Make   Make the caption of the second button Save

c.      Make   Make the caption of the third button New

d.      Make   Make the caption of the fourth button Delete

4.

...

  Change also the default names (#PHBN_n) of the buttons to match the caption. In this way it will be easier to identify the buttons when you write event routines for them.

5.

...

  Position them on the form as shown in the picture in Create an Application at the beginning of these steps.

List View

Next create the list view which shows the employees:

Image Modified

To create the list view, display again the the Controls tab. Drag a list view control (PRIM_LTVW) to the form or double-click it. Now you need to create the columns for the list. To do this:

Image Modified

1.  Locate the file PSLMST in the Repository tab.

2.  Click on the plus sign in front of it to display the fields defined for this file.

3.  Make sure the list view has the focus in the Design view. In the Repository tab double-click these fields to add them to the list view (or drag them):

SURNAME

GIVENAME

EMPNO

When you add a field to a list, a list column is created.

Display the Outline tab. The list view columns are named LVCL_n:

  • LVCL_1 is the column created from the #SURNAME field

  • LVCL_2 is the column created from the #GIVENAME field

  • LVCL_3 is the column created from the #EMPNO field

You can rename these fields if you want to use more descriptive names.

Image Modified


In the Design view notice how the list view shows that a column has been added to it.

1.  Now size the columns as shown by dragging them.

2.  Display the Details tab for all three columns and set their CaptionType property to ColumnHeadings.
This sets the column headings to the value specified in the field definition of the source fields.

Employee Details Fields

You will need these fields showing employee details on the form:

...


Image Modified

Image Modified

To add the fields, again display the PSLMST file in the Repository tab.

Drag and drop these fields to the form:

  • EMPNO, GIVENAME, SURNAME (add these fields to the form even though they are in the list to make it simple to add new employees)

  • ADDRESS1, ADDRESS2, ADDRESS3 and POSTCODE

  • PHONEHME and PHONEBUS

  • SALARY

  • STARTDTE and TERMDATE

  • DEPARTMENT and SECTION

Notice that as you drag the fields to the form, they are displayed with a label specified in the field definition. Also, they are filled with sample data which indicates the required length for the field.

Status Bar

Lastly, you need a status bar for showing messages:

Image Modified

Display the the Controls tab and drag a status bar to the form. It will automatically attach itself to the bottom of the form.

Finalize the Interface

Make sure that the interface of the application corresponds to the picture shown in Create an Application at the beginning of these steps.

Step 3. Write the Code

Now that your user interface is complete, it is time to write the code. Click on the Source tab to display the source code for the form. You will notice that the editor has automatically created the DEFINE_COM statements for the controls and fields you have included on the form. These statements show the properties defined for the components.

3a. Create a Group for All the Employee Details Fields

To make it easier to deal with all the employee details fields, create a group for them:

     GROUP_BY NAME(#ALLFLDS) FIELDS(#EMPNO #SURNAME #GIVENAME #ADDRESS1 #ADDRESS2 #ADDRESS3 #POSTCODE #PHONEHME #PHONEBUS #STARTDTE #TERMDATE #DEPTMENT #SECTION #SALARY #MNTHSAL)

3b. Write an Event Routine for the Get Button

1.

...

  To write the code to fill the list view according to a partial surname, display the Details tab, select the GET button on the list and then bring the event tab to the front.

2.

...

  Double-click on the Click event. Notice that editor inserts the EVTROUTINE and ENDROUTINE statements for you in the Source view.

Image Added

The icon in front of the Click event in the Details tab changes to indicate that a routine has been specified for the event:

Image Added

3.  Add the following code in the Click event of the Get button:

EVTROUTINE HANDLING(#GET.Click)
  change #surname #partname
  clr_list #ltvW_1
  SELECT FIELDS(#ltvw_1) FROM_FILE(PSLMST2) WITH_KEY(#SURNAME) GENERIC(*YES)
     add_entry #ltvw_1
  endselect 
ENDROUTINE

The event routine assigns the value entered in the #PARTNAME field to #SURNAME. It then clears the list view. The SELECT loop selects all employees whose surname matches the value of #SURNAME and adds the entries to the list view.

4.  Write an Event Routine to Fetch the Details for an Employee:

a.  Create a Click event routine for the ItemGotSelection event of the list view. This event is triggered when the user selects an employee in the list view.

b.  Now write the following code to fetch the details for the selected employee.

EVTROUTINE HANDLING(#LTVW_1.ItemGotSelection)
  FETCH FIELDS(#ALLFLDS) FROM_FILE(PSLMST) WITH_KEY(#EMPNO) ISSUE_MSG(*YES)
ENDROUTINE

5.  Write an Event Routine to Enter a New Employee

Create an event routine for the Click event of the New button. Use the event to blank out all the fields so that the details of a new employee can be entered.

EVTROUTINE HANDLING(#NEW.Click)
  change #allflds *Null
ENDROUTINE

6.  Write the Event Routine to Delete an Employee

Create an event routine for the Click event of the Delete button to delete the currently selected employee:

EVTROUTINE HANDLING(#DELETE.CLICK)
  DELETE FROM_FILE(PSLMST) WITH_KEY(#EMPNO) ISSUE_MSG(*YES)
ENDROUTINE

7.  Write the Event Routine to Save Changes

Create an event routine for the Click event of the Save button to either update the details of an existing employee or to insert the details of a new employee:

EVTROUTINE HANDLING(#SAVE.CLICK)
check_for in_file(pslmst) with_key(#empno) val_error(*next)
if_status is(*EQUALKEY)
     UPDATE FIELDS(#ALLFLDS) IN_FILE(PSLMST) WITH_KEY(#EMPNO) ISSUE_MSG(*YES)
     IF_STATUS IS(*OKAY)
        MESSAGE MSGTXT('Employee details have been updated.')
     endif 
else
     INSERT FIELDS(#ALLFLDS) TO_FILE(PSLMST)  ISSUE_MSG(*YES)
     IF_STATUS IS(*OKAY)
        MESSAGE MSGTXT('Employee details have been added.')
     endif 
  endif 
ENDROUTINE

The event routine first checks to see if the employee exists. If it does, it updates the employee details. If no record with the matching employee number is found, it inserts the employee details. A message is displayed after the update and the insert.

Step 4. Compile and run the Program

The application is now complete.

1.  To compile the program, select the Compile command on the ribbon.

You do not need to keep the generated source or debug enable your component. In the Component Compile Options dialog box specify the options like this:

Image Added

2.  Click OK.

3.  After the compilation has ended, execute your program using the Execute command:

Image Added

Note that you can also execute the form outside the LANSA development environment. From your LANSA System's desktop folder, select Execute Applications and then Exec Form:

Image Added