Condividi tramite


Implementing Business Rules in the Client/Server Sample Application

The Client/Server sample application uses a custom Automation server to enforce business rules. This architecture, known as the three-tier model, allows implementation of business rules in the middle tier, separate from the actual data and separate from the client interface. Multiple applications and multiple databases can all use the same set of business rules, coded and maintained in a single location.

The custom Automation server in the Client/Server sample application is Bizrules. The project for the Automation server is Bizrules.pjx and the class is defined in Bizrules.prg:

DEFINE CLASS SalaryRule AS Custom OLEPUBLIC

Code in the CSEngine class provides an interface to the business object with the ServerStart, ServerStop, ServerIsStarted, and ServerValidateRow methods.

The ServerStart method creates an instance of the SalaryRule class. The ServerValidateRow method passes values to the server for validation:

lcError = THIS.oServer.Validate(m.cTitle, m.nSalary, m.dBirth, m.dHire, m.cCountry)

The Validate method of the SalaryRule class enforces a common set of business rules and returns a list of error messages, one for every rule that failed. For example, the following section of code from the Validate method makes sure that the salary falls within a range specified in the Bizrules.dbf table:

PROCEDURE validate
PARAMETERS lcTitle, lnSalary, ldBirth, ldHire, lcCountry

SELECT bizrules
LOCATE FOR lcTitle = ALLTRIM(title)
IF EOF()
   * Display error message
ELSE
   IF !BETWEEN(lnSalary, min_salary, max_salary)
      * Display error message
   ENDIF
ENDIF

See Also

Solutions Samples | Client/Server Sample | Client/Server Sample Application Classes | Client/Server Sample Application Database | Updating Data in the Client/Server Sample Application | Managing Data Conflicts in the Client/Server Sample Application