8.2 启动与执行业务流程
8.2.2 完成任务实例的TaskInstance.aspx程序代码
图8.4所示为建设用地审批业务的用地报批环节处理。从页面包含的按钮可以看出,该任务节点是一个或分支节点。完成业务数据编辑、资料上传、填写审核信息(沟通栏)等工作后,点击不同的迁移按钮(后两个按钮,代表不同的业务过程走向),业务过程将转入不同的分支继续执行。
从页面内容可以看出,用户可以下载浏览前面环节上传的资料,可以打印业务表格,可以浏览前面环节的审核过程(包括审核人和审核意见,实际上就是把前面的业务参与者和他填写的沟通栏信息显示出来)。用户可以选择临时保存当前任务处理,可以结束当前任务并进入下一环节,如果发现前面环节有错误,还可以选择将过程退回到特定环节重新执行。
图8.4 完成任务实例
TaskInstance.aspx页面设计如图8.5所示:
图8.5 TaskInstance.aspx页面设计
TaskInstance.aspx文件代码:
......
<script language="jscript">
//增加附件上传的脚本
function preview_pic(fileId, prevId)
{
var picLink = document.getElementByIdx(fileId).value;
document.getElementByIdx(prevId).src =picLink;
}
var count=1;
function delp(id)
{
for(var i=0;i<document.getElementByIdx("addUpList").childNodes.length;i++)
{
//<span> is its child node.
var child=document.getElementByIdx("addUpList").childNodes[i];
if(child.id=="d"+id)
{
document.getElementByIdx("addUpList").removeChild(child);
}
}
//删除一项之后,需要将后续项的附件名称输入框的name属性值递减,以满足后台代码顺序获取
//附件名称控件的需要。
while(count>id)
{
var num=++id;
document.getElementByIdx("filename"+num).name="filename"+(--num);
}
if(count>=2)
count=count-1; //删除一项后,计数减一.
}
function Button1_onclick()
{
var filenum=++count;
var str="<span id=\"d"+filenum+"\">"
+"<table width=\"100%\" align=\"center\" bgColor=\"#f5fafe\">"
+"<tr height=\"26px\">"
+"<td vAlign=\"middle\" width=\"15%\" align=\"right\">"
+"</td>"
+"<td align=\"left\"><INPUT type=\"file\" size=\"60\" id=\"file"+filenum+"\"
name=\"file"+filenum+"\"> "
+"<input name=\"delp"+filenum+"\" type=\"button\" value=\"删除\"
οnclick=\"delp('"+filenum+"')\"></td>"
+"</tr>"
+"<TR height=\"26px\">"
+"<TD vAlign=\"middle\" align=\"right\"></TD>"
+"<TD align=\"left\">"
+"<input id=\"filename"+filenum+"\" name=\"filename"+filenum+"\" size=\"60\"
type=\"text\" /></TD>"
+"</TR>"
+"</table>"
+"</span>";
document.getElementByIdx("addUpList").insertAdjacentHTML("beforeEnd",str);
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" encType="multipart/form-data" runat="server">
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr>
<td style="FONT-SIZE: 16px" align="center">
<asp:Label id="Label3" runat="server"></asp:Label>
</td>
</tr>
<tr height="50">
<td align="right">
<asp:label id="Label2" runat="server" ForeColor="Red"></asp:label>
</td>
</tr>
<tr>
<td><asp:table id="Tbl" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid;
BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; FONT-FAMILY: 宋体;
BORDER-COLLAPSE: collapse" runat="server" border="1" cellPadding="3"
cellSpacing="0" Width="100%"></asp:table>
</td>
</tr>
</table>
<table height="30" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td></td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr>
<td><asp:table id="Tbl2" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid;
BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; FONT-FAMILY: 宋体;
BORDER-COLLAPSE: collapse" runat="server" border="1" cellPadding="3"
cellSpacing="0" Width="100%"></asp:table>
</td>
</tr>
</table>
<table height="20" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td></td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr>
<td><asp:table id="Tbl3" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid;
BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; FONT-FAMILY: 宋体;
BORDER-COLLAPSE: collapse" runat="server" border="1" cellPadding="3"
cellSpacing="0" Width="100%"></asp:table>
</td>
</tr>
</table>
<table height="20" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td></td></tr>
</table>
<%
if(ds !=null)
{
if(ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "L"
|| ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "LR")
{
%>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr height="26">
<td vAlign="middle" align="right" width="15%">上传附件:</td>
<td align="left">
<INPUT id="file1" type="file" size="60" name="file1">
<INPUT οnclick="return Button1_onclick()" type="button" value="增加上传">
</td>
</tr>
<TR height="26"><TD vAlign="middle" align="right">附件名称:</TD>
<TD align="left">
<INPUT id="filename1" type="text" size="60" name="filename1">
</TD>
</TR>
</table>
<div id="addUpList" style="BACKGROUND-COLOR: #f5fafe"></div>
<%
}
}
%>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr>
<td><asp:table id="PTable" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid;
BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; FONT-FAMILY: 宋体;
BORDER-COLLAPSE: collapse" runat="server" border="1" cellPadding="3"
cellSpacing="0" Width="100%"></asp:table>
</td>
</tr>
</table>
<table height="15" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr><td></td></tr>
</table>
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr>
<td width="15%" align="right">沟通栏:</td>
<td>
<asp:LinkButton id="LinkButton1" runat="server">浏览留言信息</asp:LinkButton><br>
<asp:TextBox id="TextBox1" runat="server" Columns="90" Rows="5"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
</table>
<table height="60" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td vAlign="middle" align="right"> </td>
<td align="center" width="50%">
<asp:Button id="Button1" runat="server" Text="临时保存"></asp:Button>
<asp:Button id="Button2" runat="server" Text="完成任务"></asp:Button>
<asp:Label id="Label1" runat="server" ForeColor="Red"></asp:Label>
<asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
<asp:Button id="Button3" runat="server" Text="退回任务"></asp:Button>
</td>
<td width="50%">
<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<tr>
<td><asp:table id="TransTbl" style="BORDER-RIGHT: 1px solid;
BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid;
FONT-FAMILY: 宋体; BORDER-COLLAPSE: collapse" runat="server" border="1"
cellPadding="3" cellSpacing="0" Width="100%"></asp:table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
......
TaskInstance.aspx.cs文件代码:
......
using System.IO;
using System.Text.RegularExpressions;
using DataAccess;
using CommonTools;
using WFEngine;
namespace workflow.Process
{
public class TaskInstance : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Table Tbl2;
protected System.Web.UI.WebControls.Table Tbl;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Table Tbl3;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Table PTable;//动态设置打印业务表格链接
protected System.Web.UI.WebControls.Table TransTbl;//动态设置迁移按钮
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected DataSet ds;//保存任务定义记录,页面中判断是否显示有关附件时用得到.
DataSet wfields=null;//包含可写字段集
DataSet identityname;//包含标识字段名
private void Page_Load(object sender, System.EventArgs e)
{
if(! IsPostBack)
{
//验证用户是否登录
if(Session["userid"] == null)
Response.Redirect("../Message.aspx");
//接受url参数
string taskinstanceid=Request.QueryString["id"].ToString();
ViewState["taskinstanceid"]=taskinstanceid;
TaskInstanceClass taskins=new TaskInstanceClass();
//获取任务的关联角色
ViewState["AssignedRole"]=taskins.GetAssignedRole(taskinstanceid);
//如果当前任务的TaskUserID为空,将其设置为当前用户(即抢占任务,使其它同角色用户不
//能再处理该任务),并把任务状态设置为Running.
if(! taskins.IfTaskIsPicked(taskinstanceid))
{
if( ! taskins.PickTask(Session["userid"].ToString(),taskinstanceid))
{
Label2.Text="1:"+taskins.TaskInstancesErrDes;//便于发现哪里出现的错误
return;
}
}
//如果任务已由其他用户(非当前用户)处理,则显示提示信息
else
{
string taskuser=taskins.GetTaskUser(taskinstanceid);
//TaskPickedMessage.aspx.cs文件只有一个提示信息语句--Response.Write("抱歉!当前
//任务已被其他用户处理,请回到任务列表处理其它任务.");
if(taskuser != Session["userid"].ToString())
Response.Redirect("TaskPickedMessage.aspx");
}
ViewState["processinstanceID"]=taskins.GetProcessInstanceID(taskinstanceid);
ViewState["taskID"]=taskins.GetTaskDefinitionID(taskinstanceid);
//初始化DropDownList1,列表显示当前任务实例的前驱任务实例列表,供回退操作使用。
DataSet tasklistds=taskins.GetPreTaskInstancesList(taskinstanceid,
ViewState["processinstanceID"].ToString());
DropDownList1.DataSource=tasklistds;
DropDownList1.DataTextField="taskuser";
DropDownList1.DataValueField="TaskInstanceID";
DropDownList1.DataBind();
//保存要打印的表格ID数组,用于LinkButton按钮方法
ViewState["printedtablearray"]="";
}
Label2.Text="";
//获取任务定义表与流程实例表记录集
Base basecode=new Base();
string strSql="select * from TaskDefinition where TaskID="
+ViewState["taskID"].ToString()+";";
strSql=strSql+"select * from ProcessInstance where ProcessInstanceID="
+ViewState["processinstanceID"].ToString();
ds=basecode.SQLExeDataSet(strSql);//DataSet加载多数据表
if(ds == null)
{
Label2.Text="3:"+basecode.BaseSqlErrDes;
return;
}
//设置Label3为任务名称
Label3.Text=ds.Tables[0].Rows[0]["TaskName"].ToString();
//获取业务表标识字段名
strSql="select IdentifiedField from ProcessDefinition where ProcessID="
+ds.Tables[1].Rows[0]["ProcessDefinitionID"].ToString();
identityname=basecode.SQLExeDataSet(strSql);
if(identityname == null)
{
Label2.Text="4:"+basecode.BaseSqlErrDes;
return;
}
//获取可读字段中文名及字段值集合并显示
if((ds.Tables[0].Rows[0]["Readablefields"] != DBNull.Value)
& (ds.Tables[0].Rows[0]["Readablefields"].ToString().Length>1))
{
string[] readablefields=new Tools().StringSplit(ds.Tables[0]
.Rows[0]["Readablefields"].ToString(),",");
//获取可读字段中文名集合的sql语句
strSql="select FieldName,FieldAlias,ControlType from RelatedTablesFields
where (FieldName='"+readablefields[0]+"'";
//i<readablefields.Length-1因为最后一个是空格
for(int i=1;i<readablefields.Length-1;i++)
{
strSql=strSql+" or FieldName='"+readablefields[i]+"'";
}
//还得加上TableName和TableOwer条件后再添加另一获取可读字段值集合的sql语句
string[] tabown=new Tools().StringSplit(ds.Tables[1]
.Rows[0]["RelatedTable"].ToString(),".");
string owner=tabown[0];
string tabname=tabown[1];
strSql=strSql+") and TableOwer ='"+owner+"' and TableName='"+tabname
+"';select "+readablefields[0];
for(int i=1;i<readablefields.Length-1;i++)
{
strSql=strSql+","+readablefields[i];
}
strSql=strSql+" from "+ds.Tables[1].Rows[0]["RelatedTable"].ToString()
+" where "+identityname.Tables[0].Rows[0]["IdentifiedField"].ToString()
+"="+ds.Tables[1].Rows[0]["IdentityFieldValue"].ToString();
//Response.Write(strSql);
DataSet fieldsds=basecode.SQLExeDataSet(strSql);
if(fieldsds == null)
{
Label2.Text="5:"+basecode.BaseSqlErrDes;
return;
}
TableRow tr;
TableCell tc;
for(int j=0;j<fieldsds.Tables[0].Rows.Count;j++)
{
tr=new TableRow();
tc=new TableCell();
tc.HorizontalAlign=HorizontalAlign.Right;
tc.Width=Unit.Percentage(15);//注意此处用法
tc.Text=fieldsds.Tables[0].Rows[j]["FieldAlias"].ToString();//字段中文名
tr.Cells.Add(tc);
tc=new TableCell();
tc.HorizontalAlign=HorizontalAlign.Left;
tc.Text=fieldsds.Tables[1].Rows[0][fieldsds.Tables[0]
.Rows[j]["FieldName"].ToString()].ToString();//对应的字段值
tr.Cells.Add(tc);
Tbl.Rows.Add(tr);
}
}//结束显示可读字段值的if语句
......(待续)