Building the parameterized search feature

The concept of parameterized search is simple. At its core it is nothing more than a select SQL statement with a where clause built from the user's search parameters. It allows the user to combine multiple search parameters to narrow down the search results.

Choosing which fields to expose to the user as a search parameter is an important consideration in building your search form. As screen space is a precious commodity, you don't want to clutter up your search form unnecessarily. Include only fields that are commonly used by your users to lookup their data.

For instance, searching for an account using the account ID or account name is useful, but not by phone number or e-mail address.

The first thing you will need to do is to create a class to hold the search parameters keyed in by the user. This is necessary to transport these search parameters between the different tiers of the application.

Passing search parameters around

Although you could also pass search parameters around through function arguments, using a class is generally better; if, in the future, you had to add new search parameters to your application, you would not have to change these function declarations in any way. Aesthetically,

GetAccountsByParameters (mySearchParams) also looks a lot better than GetAccountsByParameters (AcctFirstName, AcctLastName, Status, AccountType...).

Add a new class named AccountSearchParameters to the CRMLiveFramework project. You should place it in this project because the database plugin projects will also need access to this class type.

public class AccountSearchParameters {

private string _FirstName; private string _LastName; private int _Status; private string _AccountTypes;

public string FirstName {

Get {return _FirstName;} set {_FirstName = value;}

public string LastName {

public string AccountType

Get {return _AccountTypes;} set {_AccountTypes = value;}

public int Status

Keeping in mind that a long list of search results might be returned, you need to implement paging when you display these search results. You will need to create two functions at the data tier — one to return the search result record count and the other to return a dataset filled with the search results for a specific page. Does this sound familiar? It should—if you recall, you've built two similar functions in the paging example in the previous chapter.

Define these two new functions in IDataLibPlugin so that you can write separate implementations for SQL Server CE and Oracle Lite. The function definitions follow:

DataSet GetAccountsByParameters(AccountSearchParameters SearchParam, int TotalRecords, int PageNumber, int PageSize, string SortColumn, GlobalVariables.SortingOrder SortDirection);

int GetAccountsCountByParameters(AccountSearchParameters SearchParam);

Now let's take a look at how you can implement these two functions in SQL Server CE and Oracle Lite.

Was this article helpful?

0 0

Post a comment