您的位置:首页 > 其它

第八章 启动与执行业务流程(二)

2012-09-20 09:54 423 查看
8.1 对业务过程定义的细化

8.1.2 UpdateTaskDefinitionList.aspx文件代码

......

<form id="Form1" method="post" runat="server">

<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">

<tr><td style="FONT-SIZE: 16px" align="center">任务定义列表</td></tr>

<tr height="50">

<td align="right"><span id="Message" style="FONT-SIZE: 11pt; FONT-FAMILY: Arial"

runat="server" MaintainState="false"></span> </td>

</tr>

<tr>

<td><asp:datagrid id="DataGrid1" runat="server"

HeaderStyle-HorizontalAlign="Center" Width="100%" DataKeyField="TaskID"

AllowPaging="True" PageSize="6">

<ItemStyle Font-Size="13px" HorizontalAlign="Center" Height="28px"

VerticalAlign="Bottom"></ItemStyle>

<HeaderStyle Font-Size="16px" HorizontalAlign="Center" Height="30px"

VerticalAlign="Middle" BackColor="#EEEEEE"></HeaderStyle>

<Columns>

<asp:BoundColumn DataField="TaskName" HeaderText="任务名称"></asp:BoundColumn>

<asp:BoundColumn DataField="role_name" HeaderText="关联角色"></asp:BoundColumn>

<asp:BoundColumn DataField="ReadableFields" HeaderText="可读字段">

<ItemStyle HorizontalAlign="Left" Width="20%"></ItemStyle>

</asp:BoundColumn>

<asp:BoundColumn DataField="WritableFields" HeaderText="可编辑字段">

<ItemStyle HorizontalAlign="Left" Width="20%"></ItemStyle>

</asp:BoundColumn>

<asp:BoundColumn DataField="DueDate" HeaderText="任务完成期限(天数)">

</asp:BoundColumn>

<asp:HyperLinkColumn Text="编辑" DataNavigateUrlField="TaskID"

DataNavigateUrlFormatString="UpdateTaskDefinition.aspx?id={0}">

</asp:HyperLinkColumn>

</Columns>

<PagerStyle Font-Size="9pt" HorizontalAlign="Right" ForeColor="#3366FF"

Mode="NumericPages"></PagerStyle>

</asp:datagrid></td>

</tr>

</table>

</form>

......

UpdateTaskDefinitionList.aspx.cs文件代码:

......

using DataAccess;

using WFEngine;

namespace workflow.admin

{

public class UpdateTaskDefinitionList : System.Web.UI.Page

{

protected System.Web.UI.WebControls.DataGrid DataGrid1;

protected System.Web.UI.HtmlControls.HtmlGenericControl Message;

private void Page_Load(object sender, System.EventArgs e)

{

if(! IsPostBack)

{

//验证用户是否登录

if(Session["userid"] == null)

Response.Redirect("./Message.aspx");

string processid=Request.QueryString["id"].ToString();

ViewState["processid"]=processid;

BindGrid();

}

}

void BindGrid()

{

string processid=ViewState["processid"].ToString();

//根据过程定义编号获取该过程的所有任务节点定义

DataSet ds=new ProcessDefinitionClass().GetProcessDefinitionByID(processid);

DataGrid1.DataSource=ds;

DataGrid1.DataBind();

}

private void DataGrid1_ItemDataBound(object sender,

System.Web.UI.WebControls.DataGridItemEventArgs e)

{

if( e.Item.ItemType == ListItemType.Item

|| e.Item.ItemType == ListItemType.AlternatingItem)

{

e.Item.Cells[2].Attributes.Add("style","WORD-BREAK:break-all;

WORD-WRAP:break-word");

e.Item.Cells[3].Attributes.Add("style","WORD-BREAK:break-all;

WORD-WRAP:break-word");

}

}

private void DataGrid1_PageIndexChanged(object source,

System.Web.UI.WebControls.DataGridPageChangedEventArgs e)

{

DataGrid1.CurrentPageIndex=e.NewPageIndex;

BindGrid();

}

}

}

8.1.3 UpdateTaskDefinition.aspx文件代码

......

<form id="Form1" method="post" runat="server">

<table cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">

<tr><td style="FONT-SIZE: 16px" align="center">定义业务流程任务</td></tr>

<tr height="50"><td align="right"> </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" Width="100%"

cellPadding="3" cellSpacing="0"></asp:table>

</td>

</tr>

</table>

<table height="100" cellSpacing="0" cellPadding="0" width="100%" border="0">

<tr>

<td>          </td>

<td align="center"> 

<asp:button id="Button1" runat="server" Text="保存当前任务"></asp:button>

<asp:Label id="Label2" runat="server" ForeColor="Red"></asp:Label>

</td>

</tr>

</table>

</form>

......

UpdateTaskDefinition.aspx.cs文件代码

......

using System.Text.RegularExpressions;

using DataAccess;

using CommonTools;

using WFEngine;

namespace workflow.admin

{

public class UpdateTaskDefinition : System.Web.UI.Page

{

protected System.Web.UI.WebControls.Button Button1;

protected System.Web.UI.WebControls.Label Label2;

protected System.Web.UI.WebControls.Table Tbl;

private void Page_Load(object sender, System.EventArgs e)

{

if(! IsPostBack)

{

//验证用户是否登录

if(Session["userid"] == null)

Response.Redirect("./Message.aspx");

string taskid1=Request.QueryString["id"].ToString();

ViewState["taskid"]=taskid1;

}

//以下代码不能放在IsPostBack条件中,否则按钮方法不能正常找到动态加载的控件

//接受参数任务定义ID

string taskid=ViewState["taskid"].ToString();

Base basecode=new Base();

//设置提示信息为空

Label2.Text="";

//获取任务定义记录

TaskDefinitionClass taskdef=new TaskDefinitionClass();

DataSet ds=taskdef.GetTaskByID(taskid);

//获取processID

string processid=taskdef.GetProcessID(taskid);

ViewState["processid"]=processid;

//获取角色记录集

string strSql="select RoleID,isnull(RoleName+' '+(select Group_Name from

organization where Group_ID=OrganizationID),RoleName) as role_group

from RolesManagement";

DataSet ds1=basecode.SQLExeDataSet(strSql);

//根据流程定义ID获得流程关联的数据表名称,因为表名为"ower.tablename",所以要分割出

//表的所有者和表名.

string relatedtablename=new ProcessDefinitionClass().GetRelatedTable(processid);

string[] owertblname=new Tools().StringSplit(relatedtablename,".");

string ower=owertblname[0];

string tablename=owertblname[1];

//根据关联表获得关联表的字段名及其中文描述.

strSql="select * from RelatedTablesFields where TableName='"+tablename+"'

and TableOwer='"+ower+"'";

DataSet ds3=basecode.SQLExeDataSet(strSql);

//将关联表的字段名列表保存起来提供给保存任务按钮方法使用.

ViewState["RelatedTablesFields"]=ds3;

//任务名称编辑行

TableRow tr=new TableRow();

TableCell tc=new TableCell();

tc.Text="任务名称:";

tc.HorizontalAlign=HorizontalAlign.Right;

tr.Cells.Add(tc);

tc=new TableCell();

TextBox tx=new TextBox();

tx.Columns=50;

tx.ID="taskname";

tx.Text=ds.Tables[0].Rows[0]["TaskName"].ToString();

tc.Controls.Add(tx);

tc.ColumnSpan=9;

tr.Cells.Add(tc);

Tbl.Rows.Add(tr);

//分配角色

tr=new TableRow();

tc=new TableCell();

tc.Text="分配角色:";

tc.HorizontalAlign=HorizontalAlign.Right;

tr.Cells.Add(tc);

tc=new TableCell();

DropDownList roleList=new DropDownList();

roleList.ID="roleList";

roleList.DataTextField="role_group";

roleList.DataValueField="RoleID";

roleList.DataSource=ds1;

roleList.DataBind();

//以下语句也可以正常使用

//if(ds.Tables[0].Rows[0]["AssignedRole"] == DBNull.Value)

//if(ds.Tables[0].Rows[0].IsNull(3))

if(! ds.Tables[0].Rows[0].IsNull("AssignedRole"))

roleList.SelectedValue=ds.Tables[0].Rows[0]["AssignedRole"].ToString();

tc.Controls.Add(roleList);

tc.ColumnSpan=9;

tr.Cells.Add(tc);

Tbl.Rows.Add(tr);

//有关附件

tr=new TableRow();

tc=new TableCell();

tc.Text="有关附件:";

tc.HorizontalAlign=HorizontalAlign.Right;

tr.Cells.Add(tc);

tc=new TableCell();

DropDownList attachedList=new DropDownList();

attachedList.ID="attachedList";

ListItem item1=new ListItem("","");

attachedList.Items.Add(item1);

item1=new ListItem("可以上传附件","L");

attachedList.Items.Add(item1);

item1=new ListItem("可以浏览附件","R");

attachedList.Items.Add(item1);

item1=new ListItem("可以上传和浏览附件","LR");

attachedList.Items.Add(item1);

if(ds.Tables[0].Rows[0]["AboutAttached"] == DBNull.Value

|| ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim() == "")

attachedList.SelectedValue="";

else

attachedList.SelectedValue=

ds.Tables[0].Rows[0]["AboutAttached"].ToString().Trim();

tc.Controls.Add(attachedList);

tc.ColumnSpan=9;

tr.Cells.Add(tc);

Tbl.Rows.Add(tr);

//<可读字段控件集>

tr=new TableRow();

tc=new TableCell();

tc.Text="可读字段:";

tc.HorizontalAlign=HorizontalAlign.Right;

tr.Cells.Add(tc);

//为每一个关联字段设置单选框,并将字段名作为它的ID.

CheckBox chk=null;

Label lb=null;

for(int i=0;i<ds3.Tables[0].Rows.Count;i++)

{

//8个字段选择控件为一行

if((i% 8) == 0 & i>0)

{

//一行尾部加一列

tc=new TableCell();

tc.Text="   ";

tr.Cells.Add(tc);

//另起一行并加一列空白列

Tbl.Rows.Add(tr);

tr=new TableRow();

tc=new TableCell();

tr.Cells.Add(tc);

}

tc=new TableCell();

tc.HorizontalAlign=HorizontalAlign.Right;

lb=new Label();

lb.Text=ds3.Tables[0].Rows[i]["FieldAlias"].ToString();

tc.Controls.Add(lb);

chk=new CheckBox();

//为避免出现ID重复错误

chk.ID=ds3.Tables[0].Rows[i]["FieldName"].ToString()+"_R";

//如果是标识字段则默认钩选并不可编辑.

if(ds3.Tables[0].Rows[i]["IsIdentity"].ToString() =="Y")

{

chk.Checked=true;

chk.Enabled=false;

}

tc.Controls.Add(chk);

tr.Cells.Add(tc);

}

//最后一行列跨度设置为最大值.

tc=new TableCell();

tc.ColumnSpan=9;

tr.Cells.Add(tc);

Tbl.Rows.Add(tr);

//如果记录中已有可读字段的内容,要分割字符串,得到字段名并设置对应控件的钩选.

string readablefieldsstr="";

if(ds.Tables[0].Rows[0]["ReadableFields"] !=DBNull.Value)

readablefieldsstr=ds.Tables[0].Rows[0]["ReadableFields"].ToString().Trim();

if(readablefieldsstr != "")

{

string[] refieldsarray=new Tools().StringSplit(readablefieldsstr,",");

for(int j=0;j<refieldsarray.Length;j++)

{

//由于字段名字符串最后多一个",",使得字符串数组多一行空白字串,所以要判断.

if(refieldsarray[j] !="")

{

chk=(CheckBox)this.FindControl(refieldsarray[j]+"_R");

if(chk !=null)//避免找不到指定的控件

chk.Checked=true;

}

}

}

......(待续)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: