首先说明这是工作流的应用代码,主要包括两个方面--类型和工作流。按一般常理来说,类型主要处理逻辑上的判断,工作流主要做流程上的一个处理,但是在前段时间的工作上,没有做好系统上的分析,导致逻辑与流程混乱。下面就这个问题做一下说明:
首先给出需要操作的对象,目标是通过工作流实现在目标节点添加一个借出归还节点
1//工作流依附的类型,也就是工作流需要处理的对象:该工作流主要是做仪器仪表的借出归还流程
2//下面代码是在类型的保存前执行
3//首先判断该业务对象的连接是否存在
4string objID = p_bd.ID;
5string asctID = "5F73900F-12BA-411A-AFD4-F75856372E6D";
6
7string sql = string.Format("select l.link_id from MWT_OM_LINK l where l.tgt_obj_id='{0}' and l.asct_id='{1}'",objID,asctID);
8DataSet ds = DataAccessService.GetDataSet(sql);
9
10BusinessInvokeResult link = new BusinessInvokeResult();
11string parObjID = "";
12if(ds.Tables[0].Rows.Count<=0)
13{
14 if(p_bd["MC"]== DBNull.Value)
15 {
16 result.IsSuccessful = false;
17 result.ResultHint = "请填写借用的仪器仪表";
18 return result;
19 }
20
21 parObjID = p_bd["MC"].ToString();
22 link = BusinessRunTimeService.CreateLink(asctID,parObjID,objID);
23 //问题就在这里,创建连接应该是在工作流状态的提出要求完成后创建的,但是这里却是在保存对象的时候完成的,与现实世界明显不符合
24
25 if(!link.IsSuccessful)
26 {
27 result.IsSuccessful = false;
28 result.ResultHint = "创建业务对象失败!";
29 return result;
30 }
31}
32
2//下面代码是在类型的保存前执行
3//首先判断该业务对象的连接是否存在
4string objID = p_bd.ID;
5string asctID = "5F73900F-12BA-411A-AFD4-F75856372E6D";
6
7string sql = string.Format("select l.link_id from MWT_OM_LINK l where l.tgt_obj_id='{0}' and l.asct_id='{1}'",objID,asctID);
8DataSet ds = DataAccessService.GetDataSet(sql);
9
10BusinessInvokeResult link = new BusinessInvokeResult();
11string parObjID = "";
12if(ds.Tables[0].Rows.Count<=0)
13{
14 if(p_bd["MC"]== DBNull.Value)
15 {
16 result.IsSuccessful = false;
17 result.ResultHint = "请填写借用的仪器仪表";
18 return result;
19 }
20
21 parObjID = p_bd["MC"].ToString();
22 link = BusinessRunTimeService.CreateLink(asctID,parObjID,objID);
23 //问题就在这里,创建连接应该是在工作流状态的提出要求完成后创建的,但是这里却是在保存对象的时候完成的,与现实世界明显不符合
24
25 if(!link.IsSuccessful)
26 {
27 result.IsSuccessful = false;
28 result.ResultHint = "创建业务对象失败!";
29 return result;
30 }
31}
32
后来改正如下:
1//在类型中进行逻辑判断
2if(p_bd["MC"]== DBNull.Value)
3{
4 result.IsSuccessful = false;
5 result.ResultHint = "请填写借用的仪器仪表";
6
7 return result;
8}
9
10//获取父对象
11string parObjID = p_bd["MC"].ToString();
12BusinessInvokeResult link = BusinessRunTimeService.LoadBusinessData(parObjID,null,null,null,null);
13BusinessData bd =(BusinessData)link.ResultValue;
14
15if(bd.ClsID!="0FE69CE2-4DE5-45ED-A10D-D1E4863F4F84")
16{
17 result.IsSuccessful = false;
18 result.ResultHint = "您是否选择了备品件备件分类?"+"\n"+"请选择具体的备品件备件!";
19
20 return result;
21}
22
23if(Int32.Parse(p_bd["SL"].ToString())>Int32.Parse(bd["KJSL"].ToString()))
24{
25 result.IsSuccessful = false;
26 result.ResultHint = "仪器仪表的借出数量超过仪器仪表的总数量!";
27
28 return result;
29}
30
31//更新当前业务数据对象
32if(p_bd["XH"].ToString()!=bd["XH"].ToString())
33{
34 Platform.LogService.Trace(p_bd["XH"].ToString()+" "+bd["XH"].ToString());
35 p_bd["XH"] = bd["XH"];
36}
37
38
2if(p_bd["MC"]== DBNull.Value)
3{
4 result.IsSuccessful = false;
5 result.ResultHint = "请填写借用的仪器仪表";
6
7 return result;
8}
9
10//获取父对象
11string parObjID = p_bd["MC"].ToString();
12BusinessInvokeResult link = BusinessRunTimeService.LoadBusinessData(parObjID,null,null,null,null);
13BusinessData bd =(BusinessData)link.ResultValue;
14
15if(bd.ClsID!="0FE69CE2-4DE5-45ED-A10D-D1E4863F4F84")
16{
17 result.IsSuccessful = false;
18 result.ResultHint = "您是否选择了备品件备件分类?"+"\n"+"请选择具体的备品件备件!";
19
20 return result;
21}
22
23if(Int32.Parse(p_bd["SL"].ToString())>Int32.Parse(bd["KJSL"].ToString()))
24{
25 result.IsSuccessful = false;
26 result.ResultHint = "仪器仪表的借出数量超过仪器仪表的总数量!";
27
28 return result;
29}
30
31//更新当前业务数据对象
32if(p_bd["XH"].ToString()!=bd["XH"].ToString())
33{
34 Platform.LogService.Trace(p_bd["XH"].ToString()+" "+bd["XH"].ToString());
35 p_bd["XH"] = bd["XH"];
36}
37
38
下面贴出这个简单的流程和节点对象,笑话了!
1//在工作流中进行流程上的控制
2BusinessInvokeResult res = WorkflowMediator.GetObjIDOfProcessInstance(Context.SourceActivityInstance.ProcessInstanceID);
3string objID = (string)res.ResultValue;
4res = BusinessRunTimeService.LoadBusinessData(objID,null,null,null,null);//加载树节点上的业务对象
5if(res.IsSuccessful)
6{
7 BusinessData bd = (BusinessData)res.ResultValue;
8 bd["ZT"] = "提出";
9 BusinessRunTimeService.SaveBusinessData(bd, null,null, null);
10
11 string asctID = "5F73900F-12BA-411A-AFD4-F75856372E6D";
12 string parObjID = bd["MC"].ToString();//获取当前节点的父对象
13
14 BusinessInvokeResult link = BusinessRunTimeService.CreateLink(asctID,parObjID,objID);
15
16 if(!link.IsSuccessful)
17 {
18 result.IsSuccessful = false;
19 result.ResultHint = "创建业务对象失败!";
20
21 return result;
22 }
23}
24
2BusinessInvokeResult res = WorkflowMediator.GetObjIDOfProcessInstance(Context.SourceActivityInstance.ProcessInstanceID);
3string objID = (string)res.ResultValue;
4res = BusinessRunTimeService.LoadBusinessData(objID,null,null,null,null);//加载树节点上的业务对象
5if(res.IsSuccessful)
6{
7 BusinessData bd = (BusinessData)res.ResultValue;
8 bd["ZT"] = "提出";
9 BusinessRunTimeService.SaveBusinessData(bd, null,null, null);
10
11 string asctID = "5F73900F-12BA-411A-AFD4-F75856372E6D";
12 string parObjID = bd["MC"].ToString();//获取当前节点的父对象
13
14 BusinessInvokeResult link = BusinessRunTimeService.CreateLink(asctID,parObjID,objID);
15
16 if(!link.IsSuccessful)
17 {
18 result.IsSuccessful = false;
19 result.ResultHint = "创建业务对象失败!";
20
21 return result;
22 }
23}
24