ASP.net;sharepoint
c# moss 程序人生
 

Wf 不是应用程序,它只是一个架构,由Runtime和宿主来组成的。

要对工作流进行监控可以在工作流内部当它还是Runtime状态时进行操作。也就是说在工作流钝化之前对工作流的数据进行分析。对工作流xml文件进行操作,完全地控制整个工作流的状况。

一、工作流信息的数据库

在钝化之前将工作流的信息记录到数据库中,首先我们先建数据库(WorkflowInfo)再创建相关的表:wfInfo(图1, TaskInfo(图2, wf_HistoryList(图3; 工作流执行时一步一步地把数据记录到相关的表中。

  
               1

                 2
  
                    图3

提交数据的相关代码:

 

 

提交数据


二、数据展现在web页面中

新建ASP.NET Web Site , 创建WFInfo.aspxWFTaskInfo.aspxWFHistoryList.aspx页面。

WFInfo.aspx页面中读取数据表wfInfo的值。利用工作流名称,工作流状态进行筛选。

在工作流名称字段中查看工作流的任务信息,和工作流的历史纪录信息。

4

5

6

7


8

相关代码如下:

页面初始化:

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)

        {

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GSEGC_LogConnectionString"].ConnectionString))

            {

                SqlDataAdapter da = new SqlDataAdapter("select distinct WorkflowName from wfInfo", conn);

                DataSet ds = new DataSet();

                da.Fill(ds);

                this.ddlWFName.DataSource = ds;

                this.ddlWFName.DataTextField = "WorkflowName";

                this.ddlWFName.DataValueField = "WorkflowName";

                this.ddlWFName.DataBind();

                SqlDataAdapter daStatu = new SqlDataAdapter("select distinct Status from wfInfo", conn);

                DataSet dsStatu = new DataSet();

                daStatu.Fill(dsStatu);

                this.ddlWFStatus.DataSource = dsStatu;

                this.ddlWFStatus.DataTextField = "Status";

                this.ddlWFStatus.DataValueField = "Status";

                this.ddlWFStatus.DataBind();

                /*SqlDataAdapter daWFId = new SqlDataAdapter("select distinct WorkflowId from wfInfo", conn);

                DataSet dsWFId = new DataSet();

                daWFId.Fill(dsWFId);*/

                GetFilterStatus();

            }

        }

}

利用工作流ID获得任务信息的最新纪录:

    DataSet GetNewTask(string workflowId)

    {

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GSEGC_LogConnectionString"].ConnectionString))

        {

            SqlDataAdapter da = new SqlDataAdapter("select top 1 * from wfInfo where WorkflowId = '" + workflowId + "' and Status = '进行中' order by WID desc", conn);

            DataSet ds = new DataSet();

            da.Fill(ds);

            return ds;          

        }

    }

利用状态进行过滤:

    void GetFilterStatus()

    {

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GSEGC_LogConnectionString"].ConnectionString))

        {

            if (this.ddlWFStatus.SelectedValue == "进行中")

            {

                DataSet dsNew = new DataSet();

                SqlCommand cmd = new SqlCommand("select distinct WorkflowId from wfInfo", conn);

                conn.Open();

                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                while (dr.Read())

                {

                    string workflowId = string.Empty;

                    workflowId = dr[0].ToString();

                    DataSet dsTask = GetNewTask(workflowId);

                    dsNew.Merge(dsTask, false);

                }

                MemberGrid.DataSource = dsNew;

                MemberGrid.DataBind();

            }

            else

            {

                Binddata();

            }

        }

    }

    分页控件的下一页:

    protected void MemberGrid_ClickNext(object sender, EventArgs e)

    {

        if (this.ddlWFStatus.SelectedValue == "进行中")

        {

            GetFilterStatus();

        }

        else

        {

            GetFilterData();

        }

    }

  分页控件的上一页:

    protected void MemberGrid_ClickPrevious(object sender, EventArgs e)

    {

        if (this.ddlWFStatus.SelectedValue == "进行中")

        {

            GetFilterStatus();

        }

        else

        {

            GetFilterData();

        }

    }

过滤数据:

    void GetFilterData()

    {

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GSEGC_LogConnectionString"].ConnectionString))

        {

            SqlDataAdapter da = new SqlDataAdapter("select * from wfInfo where Status ='" + this.ddlWFStatus.SelectedValue + "' and WorkflowName = '" + this.ddlWFName.SelectedValue+"'", conn);

            DataSet ds = new DataSet();

            da.Fill(ds);

            MemberGrid.DataSource = ds;

            MemberGrid.DataBind();

        }

    }

初始化时过滤数据:

    void Binddata()

    {

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GSEGC_LogConnectionString"].ConnectionString))

        {

            SqlDataAdapter da = new SqlDataAdapter("select * from wfInfo", conn);

            DataSet ds = new DataSet();

            da.Fill(ds);

            MemberGrid.DataSource = ds;

            MemberGrid.DataBind();

        }

    }

筛选按钮:

    protected void btnSeleted_Click(object sender, EventArgs e)

    {

        GetFilterData();

    }

posted on 2008-05-06 19:40  sumh  阅读(2268)  评论(5编辑  收藏  举报