Wf 不是应用程序,它只是一个架构,由Runtime和宿主来组成的。
要对工作流进行监控可以在工作流内部当它还是Runtime状态时进行操作。也就是说在工作流钝化之前对工作流的数据进行分析。对工作流xml文件进行操作,完全地控制整个工作流的状况.............................
Wf 不是应用程序,它只是一个架构,由Runtime和宿主来组成的。
要对工作流进行监控可以在工作流内部当它还是Runtime状态时进行操作。也就是说在工作流钝化之前对工作流的数据进行分析。对工作流xml文件进行操作,完全地控制整个工作流的状况。
一、工作流信息的数据库
在钝化之前将工作流的信息记录到数据库中,首先我们先建数据库(WorkflowInfo)再创建相关的表:wfInfo(图1), TaskInfo(图2), wf_HistoryList(图3); 工作流执行时一步一步地把数据记录到相关的表中。
图1
图2
图3
提交数据的相关代码:
提交数据
dll
class wfInfoData
{
public static SqlParameter[] Getwf_Info()
{
SqlParameter[] spwf_Info = SqlHelper.GetCachedParameters("WFInfodata");
if (spwf_Info == null)
{
spwf_Info = new SqlParameter[] {
new SqlParameter("@WID", SqlDbType.Int,4),
new SqlParameter("@WorkflowId", SqlDbType.UniqueIdentifier,16),
new SqlParameter("@WorkflowName", SqlDbType.NVarChar,50),
new SqlParameter("@ItemName", SqlDbType.NVarChar,50),
new SqlParameter("@ListTitle", SqlDbType.NVarChar,50),
new SqlParameter("@DisplayName", SqlDbType.NVarChar,50),
new SqlParameter("@Created", SqlDbType.DateTime),
new SqlParameter("@Investigator", SqlDbType.NVarChar,50),
new SqlParameter("@InvCreated", SqlDbType.DateTime),
new SqlParameter("@Status", SqlDbType.NVarChar,50)
};
SqlHelper.CacheParameters("WFInfodata", spwf_Info);
}
return spwf_Info;
}
/**//// <summary>
/// 增加一条数据
/// </summary>
/// <param name="info"></param>
public static void Addwf_Info(WFInfo info)
{
using(SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringProfile))
{
SqlParameter[] spwf_Info = wfInfoData.Getwf_Info();
spwf_Info[0].Direction = ParameterDirection.Output;
spwf_Info[1].Value = info.WorkflowId;
spwf_Info[2].Value = info.WorkflowName;
spwf_Info[3].Value = info.ItemName;
spwf_Info[4].Value = info.ListTitle;
spwf_Info[5].Value = info.DisplayName;
spwf_Info[6].Value = info.Created;
spwf_Info[7].Value = info.Investigator;
spwf_Info[8].Value = info.InvCreated;
spwf_Info[9].Value = info.Status;
SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "ADDwfInfo", spwf_Info);
}
}
}
Modul
public class WFInfo
{
public WFInfo()
{ }
Model#region Model
private int _wid;
private Guid _workflowid;
private string _workflowname;
private string _itemname;
private string _listtitle;
private string _displayname;
private DateTime _created;
private string _investigator;
private DateTime _invcreated;
private string _status;
/**//// <summary>
///
/// </summary>
public int WID
{
set { _wid = value; }
get { return _wid; }
}
/**//// <summary>
/// 工作流GUID
/// </summary>
public Guid WorkflowId
{
set { _workflowid = value; }
get { return _workflowid; }
}
/**//// <summary>
/// 工作流名称
/// </summary>
public string WorkflowName
{
set { _workflowname = value; }
get { return _workflowname; }
}
/**//// <summary>
/// 表单名称
/// </summary>
public string ItemName
{
set { _itemname = value; }
get { return _itemname; }
}
/**//// <summary>
/// 表单库名称
/// </summary>
public string ListTitle
{
set { _listtitle = value; }
get { return _listtitle; }
}
/**//// <summary>
/// 申请者
/// </summary>
public string DisplayName
{
set { _displayname = value; }
get { return _displayname; }
}
/**//// <summary>
/// 申请时间
/// </summary>
public DateTime Created
{
set { _created = value; }
get { return _created; }
}
/**//// <summary>
/// 审批者
/// </summary>
public string Investigator
{
set { _investigator = value; }
get { return _investigator; }
}
/**//// <summary>
/// 审批时间
/// </summary>
public DateTime InvCreated
{
set { _invcreated = value; }
get { return _invcreated; }
}
/**//// <summary>
/// 工作流状态
/// </summary>
public string Status
{
set { _status = value; }
get { return _status; }
}
/**//// <summary>
/// 增加记录
/// </summary>
/// <param name="workflowId"></param>
/// <param name="workflowName"></param>
/// <param name="itemName"></param>
/// <param name="listTitle"></param>
/// <param name="displayName"></param>
/// <param name="created"></param>
/// <param name="investigator"></param>
/// <param name="invCreated"></param>
/// <param name="status"></param>
public WFInfo(Guid workflowId, string workflowName, string itemName, string listTitle, string displayName,
DateTime created, string investigator, DateTime invCreated, string status)
{
this.WorkflowId = workflowId;
this.WorkflowName = workflowName;
this.ItemName = itemName;
this.ListTitle = listTitle;
this.DisplayName = displayName;
this.Created = created;
this.Investigator = investigator;
this.InvCreated = invCreated;
this.Status = status;
}
public WFInfo(int wID ,Guid workflowId, string workflowName, string itemName, string listTitle, string displayName,
DateTime created, string investigator, DateTime invCreated, string status)
{
this.WID = wID;
this.WorkflowId = workflowId;
this.WorkflowName = workflowName;
this.ItemName = itemName;
this.ListTitle = listTitle;
this.DisplayName = displayName;
this.Created = created;
this.Investigator = investigator;
this.InvCreated = invCreated;
this.Status = status;
}
#endregion Model
}
//获取工作流状态
string statu = GetWorkflowStatu();
//记录工作流的基本信息
wfInfoData.Addwf_Info(new WFInfo(workflowProperties.WorkflowId,
workflowProperties.Workflow.ParentAssociation.Name,wfItemName,
this.listTitle, wfOriginator.DisplayName, applyDate, "",DateTime.Now,
statu));
string GetWorkflowStatu()
{
//获取工作流状态
SPFieldWorkflowStatus statusField = workflowProperties.List.Fields.GetField(workflowProperties.Workflow.ParentAssociation.InternalName) as SPFieldWorkflowStatus;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(workflowProperties.Workflow.Xml);
System.Xml.XmlNode node = doc.SelectSingleNode("Workflow/@Status1");
string statu = statusField.GetFieldValueAsText(node.InnerText);
return statu;
}
二、数据展现在web页面中
新建ASP.NET Web Site , 创建WFInfo.aspx,WFTaskInfo.aspx,WFHistoryList.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();
}