/// <summary>
        /// Find all the tokens for process instance ,and the nodeId of the token must equals to the second argument.
        /// </summary>
        /// <param name="processInstanceId">the id of the process instance</param>
        /// <param name="nodeId">if the nodeId is null ,then return all the tokens of the process instance.</param>
        /// <returns></returns>
        public IList<IToken> FindTokensForProcessInstance(String processInstanceId, String nodeId)
        {
            if (String.IsNullOrEmpty(processInstanceId)) return null;
            QueryField queryField = new QueryField();
            queryField.Add(new QueryFieldInfo("processinstance_id", CSharpType.String, processInstanceId));
            queryField.Add(new QueryFieldInfo("node_id", CSharpType.String, nodeId));
            QueryInfo queryInfo = SQLiteHelper.GetFormatQuery(queryField);

            IList<IToken> infos = new List<IToken>();
            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                string select = String.Format("select * from t_ff_rt_token {0}", queryInfo.QueryStringWhere);
                SQLiteDataReader reader = null;
                try
                {
                    reader = SQLiteHelper.ExecuteReader(connection, CommandType.Text, select, ((List<SQLiteParameter>)queryInfo.ListQueryParameters).ToArray());
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            IToken info = SQLiteDataReaderToInfo.GetToken(reader);
                            infos.Add(info);
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return infos;
        }
        /// <summary>
        /// 获得操作员发起的工作流实例列表(运行中)(分页)
        /// publishUser如果为null,获取全部
        /// </summary>
        /// <param name="creatorId">操作员主键</param>
        /// <param name="publishUser">流程定义发布者</param>
        /// <param name="pageSize">每页显示的条数</param>
        /// <param name="pageNumber">当前页数</param>
        /// <returns></returns>
        public IList<IProcessInstance> FindProcessInstanceListByCreatorId(String creatorId, String publishUser, int pageSize, int pageNumber)
        {
            int sum = 0;
            IList<IProcessInstance> _IProcessInstances = new List<IProcessInstance>();

            QueryField queryField = new QueryField();
            if(!string.IsNullOrEmpty(creatorId))
            	queryField.Add(new QueryFieldInfo("a.creator_id", CSharpType.String, creatorId));
             if(!string.IsNullOrEmpty(publishUser))
             	queryField.Add(new QueryFieldInfo("b.publish_user", CSharpType.String, publishUser));
            QueryInfo queryInfo = SQLiteHelper.GetFormatQuery(queryField);

            SQLiteConnection conn = new SQLiteConnection(connectionString);
            SQLiteDataReader reader = null;
            try
            {
                reader = SQLiteHelper.ExecuteReader(conn, pageNumber, pageSize, out sum,
                    "T_FF_RT_PROCESSINSTANCE a,t_ff_df_workflowdef b",
                    "a.id",
                    "a.*,b.publish_user",
                    String.Format("a.process_id=b.process_id and a.version=b.version {0}", queryInfo.QueryStringAnd),
                    "created_time desc",
                    queryInfo.ListQueryParameters == null ? null : queryInfo.ListQueryParameters.ToArray());

                if (reader != null)
                {
                    while (reader.Read())
                    {
                        IProcessInstance _IProcessInstance = SQLiteDataReaderToInfo.GetProcessInstance(reader);
                        _IProcessInstances.Add(_IProcessInstance);
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (reader != null) reader.Close();
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            return _IProcessInstances;
        }
        /// <summary>
        /// 查找操作员在某个流程某个任务上的已办工单。
        /// actorId,processId,taskId都可以为空(null或者""),为空的条件将被忽略
        ///  已办工单是指状态等于COMPLETED或CANCELED的工单
        ///  (Engine没有引用到该方法,提供给业务系统使用,20090303)
        /// </summary>
        public IList<IWorkItem> FindHaveDoneWorkItems(String actorId, String processId, String taskId)
        {
            QueryField queryField = new QueryField();
            queryField.Add(new QueryFieldInfo("actor_id", CSharpType.String, actorId));
            queryField.Add(new QueryFieldInfo("process_id", CSharpType.String, processId));
            queryField.Add(new QueryFieldInfo("task_id", CSharpType.String, taskId));
            QueryInfo queryInfo = SQLiteHelper.GetFormatQuery(queryField);

            IList<IWorkItem> infos = new List<IWorkItem>();
            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                String select = String.Format(
                    "select a.*,b.* from t_ff_rt_workitem a,t_ff_rt_taskinstance b where a.taskinstance_id=b.id and a.state in ({0},{1}){2}",
                    (int)WorkItemEnum.COMPLETED,
                    (int)WorkItemEnum.CANCELED,
                    queryInfo.QueryStringAnd);

                SQLiteDataReader reader = null;
                try
                {
                    reader = SQLiteHelper.ExecuteReader(connection, CommandType.Text, select, ((List<SQLiteParameter>)queryInfo.ListQueryParameters).ToArray());
                    if (reader != null)
                    {
                        while (reader.Read())
                        {
                            IWorkItem info = SQLiteDataReaderToInfo.GetWorkItem(reader);
                            ITaskInstance iTaskInstance = SQLiteDataReaderToInfo.GetTaskInstance(reader); //FindTaskInstanceById(((WorkItem)info).TaskInstanceId);
                            ((WorkItem)info).TaskInstance = iTaskInstance;
                            infos.Add(info);
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return infos;
        }