Until recently, building a customized task list involved having an intimate knowledge with our database schema. The
BQueryRuntime API, new to Captaris Workflow 6.5, was designed to change all that by introducing a simple model that would allow you to develop a query without the need to poke around in our database tables.
The
BQueryRuntime class has only two responsibilities. The first is to create and return a query object and the second is to execute a query object and return the results in a DataSet. Both operations can be seen in the following sample:
using System;
using System.Data;
using System.Web.UI;
using Teamplate.BLL;
using Teamplate.BLL.Data;
namespace SimpleTaskList
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
BSession bSession = new BSession();
bSession.Connect(string.Empty, string.Empty, string.Empty);
gridView.DataSource = SelectAllTasks(bSession.GetToken());
gridView.DataBind();
}
private DataSet SelectAllTasks(string sessionToken)
{
BQueryRuntime runtime = new BQueryRuntime();
runtime.SetSessionToken(sessionToken);
IQuery query = runtime.CreateQuery(QueryType.TaskList);
return runtime.ExecuteDataSet(query);
}
}
}
The above sample is useful if you only have a few task records in your database. Since this is generally not the case, you need a way to limit the result set to only those records you are interested in. This is done by adding criteria to the query object. Criteria objects are created using the following syntax:
ColumnName.Operator(valueToCompare)The task list columns themselves are made available via the
TaskList column collection object as seen in the following example:
using System;
using System.Data;
using System.Web.UI;
using Teamplate.BLL;
using Teamplate.BLL.Data;
namespace SimpleTaskList
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
BSession bSession = new BSession();
bSession.Connect(string.Empty, string.Empty, string.Empty);
gridView.DataSource = SelectAllTasksFor(bSession.GetUserId(), bSession.GetToken());
gridView.DataBind();
}
private DataSet SelectAllTasksFor(int userId, string sessionToken)
{
BQueryRuntime runtime = new BQueryRuntime();
runtime.SetSessionToken(sessionToken);
IQuery query = runtime.CreateQuery(QueryType.TaskList);
query.AddCriteria(TaskList.TaskStatus.MatchAny(TaskStatus.Ready | TaskStatus.Waiting));
query.AddCriteria(TaskList.ResponsibleId.EqualTo(userId));
return runtime.ExecuteDataSet(query);
}
}
}
That's it. Simply ask the
BQueryRuntime to create a query object, add some criteria objects to limit the result set, and then ask the
BQueryRuntime to execute your query object and return you a nice new DataSet.