Quick Tutorial - Demo Application - HRIS Project

This project can be run on BrightForms running in Demo Mode.

The Human Resources Information System (HRIS) project is simply an employee record information system. With this application you can create new employee records, modify or delete existing records.

This tutorial uses all the data types available in Bright projects. It will also show you how to create cursor forms and access or modify the database using expressions.

  1. Create a new project by tapping on the new Project icon in the toolbar, or selecting the 'New Project ...' operation in the File menu. Name the project "HRIS". The project will appear in the Projects panel of BrightBuilder.

  2. Select the project in the Projects panel, then modify the following project properties. The project properties may be accessed by activating the properties panel, via the Window menu, or by right clicking on the project and selecting the 'Properties' option.

    1. Author: your name.

    2. Default Font: Arial 12 Plain

    3. Description: Human Resource Info System

    4. Default Form Size: <Size of target device>

  3. Create a new table by right-clicking the Tables node of the project, then selecting 'New Table'. Name the table 'EMPLOYEE', then double click on it to define the following specifications.

  4. Create a new form that will display a list of the employees currently contained in the database; refer to the following figure for the form layout .

    1. Change the form title to 'HRIS'.

    2. Add a label control to the form, and rename the control to lblDept. Change Caption property of this label to 'Department'.

    3. Add a combo box to the form and rename it to cmbDept, this will allow users to select the departments in the company and view employees by department. Change the following combo box properties:

      • Drop Down Size: 6

      • Fixed List: add the following strings All, Engineering, IT Support, Purchasing, Production, Staff

      • Sorted: True

      • Style: Drop Down List

      • Tab Order: 1

    4. Add a listview to the form, which will create a control named listview1. This list will display the employee names depending on the department selected in the cmbDept selection. To do this, a query must be attached to the listview as described by the next step.

  5. Create a new query and rename it to qEmployeesByDept

    1. Select EMPLOYEE as the parent table .

    2. Add a parameterised condition EMPLOYEE.DEPT like ? with pDept as the parameter name .

    3. Include LNAME, FNAME and ID from EMPLOYEE table as Output Fields .

    4. Sort output fields by EMPLOYEE.LNAME in ascending order .

  6. Return to Main form.

    1. We need to attach the query we just created to the listview in the Main form. Change the following listview1 properties:

      • List Query: select qEmployeesByDept from the drop down list.

      Include the following columns with its corresponding attributes,

      • LNAME Name: Last Name, Width: 50

      • FNAME Name: First Name, Width: 50

    2. Add button1, rename to btnDelete; and change the following properties:

      • Caption: Delete Employee

      • Tab Order: 2

    3. Add button2, rename to btnEmpList and change the following properties

      • Caption: Full Employee List

      • Tab Order: 3

  7. In the Expression tab of the Main form, create a new expression by double clicking on the cmbDept control, and selecting 'Run Expression'. This will create and open a new expression named cmbDept_SelectionChange, linked to the combobox's Selection Change property.

    Continue to define this expression to initialise the listview parameter each time the combo box has a new value. The expression editor should look like this:

    IF (cmbDept == "All")

    {

    listview1.qEmployeeByDept.pDept = "%";

    }

    ELSE

    {

    listview1.qEmployeeByDept.pDept = cmbDept;

    }

    listview1.Refresh();

    Notes:

    • The IF and ELSE statements can be dragged from the expression toolbar at the bottom of the expression window. The ELSE statement must be dragged onto the IF statement.

    • cmbDept can be found in the Data Source Tree (DST) under Form -> Controls.

    • The "==" operator is found in the expressions toolbar.

    • The parameter listview1.qEmployeeByDept.pDept is found in the DST under Form -> Parameters.

    • listview1.Refresh() is an object method that is found in the DST under Form -> Controls -> lvEmployeeList. Calling this method after a parameter change will re-query records matching this parameter, and display them in the listview control.

    • "%" and "All" values are a constant string that can be entered by double clicking the ??? placeholder once operands are established, or specified using the Constants -> String node in the DST.

  8. While this expression will set the parameter of the listview every time the combo box opens, it will not initialise the parameter when the form first opens. To achieve this, create another expression that will be executed every time the Main form is opened, setting the parameter. This may be performed as follows:

    1. In the Expression tab, create a new expression and name to exprOnOpen.

    2. The expression editor should look like this,

      cmbDept.SetSelection(0);

      listview1.qEmployeeByDept.pDept = "%";

      listview1.Refresh();

      Notes:

      • The parameter listview1.qEmployeeByDept.pDept is found in the Data Source tree under Form -> Parameters.

      • cmbDept.SetSelection(???) is an object method that is found in the Data Source tree under Form -> Controls -> cmbDept. This method requires one argument which is of type Integer. This is may be specified by double clicking the ??? placeholder when the method is dropped into the editor. Alternatively, this method may be omitted by specifying a default value for the combo box.

      • listview1.Refresh() is an object method that is found in the Data Source tree under Form -> Controls -> lvEmployeeList. Calling this method after a parameter change will re-query records matching this parameter, and display them in the listview control.

    3. Select exprOnOpen from the drop down list of the Action Open form property of Main form.

    4. As the parameter of the listview on open will initially have no value, set the listview's 'Disable Load on Form Open' property to 'true'. This will defer loading until the exprOnOpen method runs, and initialises the parameter before loading the data when listview1.Refresh() is called.

  9. At this point, you can run the project to see how Main form looks. Proceed with the execution even if there are validation errors. Since we still do not have any records in the database, you will not see any data in the listview.

  10. To create, modify and delete records in the EMPLOYEE table, create a cursor form to support this functionality.

    Below is a sample layout for this form:

    1. Change the form title to 'Detail'.

    2. Add a label to the form, and change its name to lblFirst. Change its Caption property to 'First Name'.

    3. Proceed to add another 4 labels to the form, named lblLast, lblBirthday, lblDept and lblSalary. Caption these controls as 'Last Name', 'Birthday', 'Department' and 'Salary' respectively.

    4. Add an edit control to the form and, rename it to edtFirst. Change the following properties:

      • Max Length - 32

      • Tab Order property to 1.

    5. Add another edit control to the form, named edtLast. Change the following properties:

      • Max Length - 32

      • Tab Order property to 2.

    6. Add a datetime control to the form, renamed to dtBirthday. Change Tab Order property to 3.

    7. Add a combobox control to the form, renamed to cmbDept. Alternatively, this control may be copied from the previously defined form. Specify the following properties:

      • Fixed List: add the following strings Engineering, IT Support, Staff, Purchasing, Production.

      • Sorted: True

      • Style: Drop Down List

      • Tab Order: 4

      • (If copied, remove the On Selection Change expression from its properties).

    8. Add another edit control to the form, renamed to edtSalary. Change the Alignment to Right and Tab Order to 5, and Number to 'true', with precision to 2.

    9. Add a fourth edit control to the form and rename it to efID. For this control, set as a number, and change Visible property to False. The employee ID will be loaded to this edit control, for data binding purposes, but will not be visible to the user. This may alternatively be performed by using a form variable, but is a control to demonstrate the visible property of controls.

    10. Add a checkbox control and rename it to chkActive with the following properties:

      • Caption: Active

      • Default Value: True

      • Tab Order: 6

    11. Add a new label and change its name to lblSignature. Set its Caption to Signature:

    12. Add a scribble to the form, named scrSignature, with the following properties,

      • Colour-Background [231,255,255]

      • Colour-Pen [0,0,204]

    13. Add an additional button, renamed to btnClear. Set its caption value to Clear Signature.

  11. We need to create a query that will give us the record set that will be linked to this cursor form. Create a new query and rename to qEmployeeAll

    1. Select EMPLOYEE as parent table

    2. Select all columns in the Output Fields tab.

    3. Sort output fields by LNAME and FNAME in ascending order.

  12. Now we will attach the query we have just created to the Employees form to make a cursor form . Go to the Data Binding tab of Employees form and do the following,

    1. Select qEmployeeAll from the Form Query drop down list.

    2. Tick Has Cursor Bar, Has Navigation Bar, Can Create Records.

    3. Tick Can Create Modify Records and type, Do you really want to modify this record? in the Confirm Messages field.

    4. Tick Can Delete Records and type, Are you sure you want to delete this record? in the Confirm Messages field.

    5. In the Load UI Elements section, include the following form controls and load the corresponding data source for each control

      • chkActive - ACTIVE

      • edtFirst - FNAME

      • edtLast - LNAME

      • edtSalary - SALARY

      • edtID - ID

      • scrSignature- SIGNATURE

      • cmbDept - DEPT

      • dtBirthday - BDAY

      To load the form data to a form control, simply click on the customiser button in the Source field of the included UI element to display the Data Source dialog below, then select the field from the 'Select a Form Data field' table.

    6. In the Save Data to Table Columns, tap on the 'Populate' button. This will load form controls into data fields from the query, based on the 'Load UI Elements' table. Modify the BDAY field to reset the date time, then confirm the values in this table are as follows:

      • ID - edtID

      • FNAME - edtFirst

      • BDAY - DateTime.ResetTime(dtBirthday)

      • SALARY - edtSalary

      • SIGNATURE - scrSignature

      • ACTIVE - chkActive

      • LNAME - edtLast

      • DEPT - cmbDept

      DateTie.ResetTime(dtBirthday) sets the time portion of the dtBirthday to midnight since we are not concerned with the time portion of this field.

      The final Data Binding tab will appear as follows:

  13. Create two Validation Rules for edtFirst and edtLast to make sure that these fields are entered before saving the record. This makes sure that the Allow Nulls property of FNAME and LNAME columns are ensured. Create the following validation rules with its corresponding message,

  14. Create an expression to clear the scribble control, linked to the Action-Click property of btnClear. This may be achieved by double clicking on the btnClear button, and selecting 'Run Expression', creating an empty btnClear_Click expression. Proceed to define the expression as follows:

    scrSignature.Reset()

    Notes:

    scribble1.Reset() is an object method that is found in the Data Source tree under the Form > Controls > scrSignature node.

  15. Create an expression to clear all the fields when a new record is added and link this to the Action-New property of Employees form,

    1. In the Expression tab, click New and name the new expression to exprOnNew.

    2. The expression editor should look like this,

      edtID = NumberGenerator.GetUniqueNumber();

      cmbDept.SetSelection(0);

      chkActive = true;

      edtFirst = "";

      edtLast = "";

      edtSalary = 1000;

      scrSignature= "";

      dtBirthday = DateTime.Now();

      cmbDept = "";

      Notes:

      • edtID, chkActive, edtFirst, edtLast, edtSalary, scrSignature, dtBirthday and cmbDept are form controls that are found in the Data Source tree under Form > Controls.

      • NumberGenerator.GetUniqueNumber() is a object method found in the Data Source tree under Objects > NumberGenerator.

      • cmbDept.SetSelection(???) is an object method that is found in the Data Source tree under Form > Controls > cmbDept. This method requires one argument which is of type Integer. This may be specified by tapping on the ??? placeholder once the method dropped into the expression.

      • DateTime.Now() is an object method that is found in the Data Source tree under Objects > DateTime.

      • "" is an empty string constant which may be specified by double clicking on the ??? placeholder.

      • 0 and 1000 are Integers, also specified by the ??? placeholder.

    3. Select exprOnNew from the Action-New property of the form.

  16. Go back to the Layout tab of the Main form, double click the btnEmpList button, and select 'Open a Form'. This will display the OpenForm dialog. From this dialog, select to open Employees form and select exprOnOpen from the Post-Close Expression property list. The post-close expression will refresh listview1 after closing the Employees form. Specify the current listview selection's ID as the Jump to Column. This will open the Employee Detail form at the selected record.

  17. The btnDelete will delete the employee record selected from the listview. Before writing the expression, a query returning the result set to be deleted must be defined.

    1. Create a new query and rename to qEmployeeById

    2. Select EMPLOYEE as the parent table.

    3. Add a parameterised condition EMPLOYEE.ID=? with pId as the parameter name.

  18. Create and link a new expression for the btnDelete control by double clicking on the button and selecting 'Run Expression'. Define the created btnDelete_Click expression as follows:

    IF (listview1.GetSelection() == -1)

    {

    Form.MessageBox("Error", "Please select an employee record to delete.", MB_OK);

    EXIT;

    }

    local.vId = listview1.GetCurrentRowColumnValue("ID");

    Database.Reset();

    Database.SetQueryParam("pId", local.vId);

    local.vResult = Database.DeleteRecords("qEmployeeById");

    listview1.Refresh();

    IF (local.vResult == 0)

    {

    Form.MessageBox("Information", "Record was deleted successfully.", MB_OK);

    }

    ELSE

    {

    Form.MessageBox("Error", "Could not delete record.", MB_OK);

    }

    Notes:

    • The IF, ELSE and EXIT statements can be dragged from the expression toolbar at the bottom of the expression window. The ELSE statement must be dragged onto the IF statement.

    • listview1.GetSelection() is an object method that is found in the Data Source tree under Form -> Controls -> listview1. It is compared to -1, an integer which implies that no value is currently selected.

    • Form.MessageBox(???,???,???) is an object method found in the Data Source tree under Objects -> Form. This method requires three arguments: title (String), message (String), type of message box (System). The System Constant MB_OK is found under Constants -> System.

    • local.vId, and local.vResult are local variables which may be specified in the DST under Form > Variables (double click on local.Variable).

    • Database.Reset(), Database.SetQueryParam(???,???), Database.DeleteRecords(???) are object methods found under Objects > Database. Database.SetQueryParam(???,???) requires two arguments; a parameter name (String) and a parameter value (any data source). Database.DeleteRecords(???) requires one argument; the query name (String).

    • listview1.Refresh() is an object method that is found under Form -> Controls -> listview1.

  19. When a record is selected from the listview, we also would want to display the details for that employee; to do this, you need to link the Employees form to an action of the listview.  To ensure that a row is selected when the listview is double clicked create a new expression named exprPreOpenListview with the following statements,

    IF (listview1.GetSelection() == -1)

    {

    Form.CancelOpen = true;

    }

    Notes:
    • listview1.GetSelection() is an object method that is found in the Data Source tree under Objects -> Controls -> lvEmployeeList.

    • Form.CancelOpen is a form property found under Form -> Properties.

    • true is a boolean constant.

      This expression ensures that the Employees form will not be opened unless a row is selected from the listview.

      1. Select lvEmployeeList and display the OpenForm dialog from the Action Double Click property of this control by clicking on the button.

      2. Select Employees form from the Open Form list.

      3. Select exprPreOpenListview from the Pre-Open Expression list.

      4. Select exprOnOpen from the Post-Close Expression list to refresh the listview after closing the child form.

      5. In the Jump To Records Primary Keys section, select lvEmployeeList.GetCurrentRowColumnValue(ID) as the data source for the primary key ID, this will display the complete record of the row selected from the listview based on the employee ID.

  1. Execute the project. If there are any Validation errors or warnings, simply correct the errors and run the project again.

    1. The following are the screen shots for the project,

    2. Click on the Full List button to go to Employees form.

    3. Create a new employee record. Create two if you want.

    4. Close the Employees form; check if the listview was refreshed after closing the child form.

    5. Use the combo box to display employees per department.

    6. Select a row from the listview and delete the record with Delete Employee button.