/// <summary> /// 更新[流程审批明细表] /// </summary> /// <param name="con">//OracleConnection连接对象</param> /// <param name="detail">流程审批明细表</param> public static int Update( FLOW_FLOWRECORDDETAIL_T model) { try { string updSql = "UPDATE FLOW_FLOWRECORDDETAIL_T SET FLOWRECORDMASTERID=@FLOWRECORDMASTERID,STATECODE=@STATECODE,PARENTSTATEID=@PARENTSTATEID,CONTENT=@CONTENT,CHECKSTATE=@CHECKSTATE,FLAG=@FLAG,CREATEUSERID=@CREATEUSERID,CREATEUSERNAME=@CREATEUSERNAME,CREATECOMPANYID=@CREATECOMPANYID,CREATEDEPARTMENTID=@CREATEDEPARTMENTID,CREATEPOSTID=@CREATEPOSTID,CREATEDATE=@CREATEDATE,EDITUSERID=@EDITUSERID,EDITUSERNAME=@EDITUSERNAME,EDITCOMPANYID=@EDITCOMPANYID,EDITDEPARTMENTID=@EDITDEPARTMENTID,EDITPOSTID=@EDITPOSTID,EDITDATE=@EDITDATE,AGENTUSERID=@AGENTUSERID,AGENTERNAME=@AGENTERNAME,AGENTEDITDATE=@AGENTEDITDATE WHERE FLOWRECORDDETAILID=@FLOWRECORDDETAILID"; Parameter[] pageparm = { new Parameter("@FLOWRECORDDETAILID"), new Parameter("@FLOWRECORDMASTERID"), new Parameter("@STATECODE"), new Parameter("@PARENTSTATEID"), new Parameter("@CONTENT"), new Parameter("@CHECKSTATE"), new Parameter("@FLAG"), new Parameter("@CREATEUSERID"), new Parameter("@CREATEUSERNAME"), new Parameter("@CREATECOMPANYID"), new Parameter("@CREATEDEPARTMENTID"), new Parameter("@CREATEPOSTID"), new Parameter("@CREATEDATE"), new Parameter("@EDITUSERID"), new Parameter("@EDITUSERNAME"), new Parameter("@EDITCOMPANYID"), new Parameter("@EDITDEPARTMENTID"), new Parameter("@EDITPOSTID"), new Parameter("@EDITDATE"), new Parameter("@AGENTUSERID"), new Parameter("@AGENTERNAME"), new Parameter("@AGENTEDITDATE") }; pageparm[0].ParameterValue = GetValue( model.FLOWRECORDDETAILID);// pageparm[1].ParameterValue = GetValue( model.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID );// pageparm[2].ParameterValue =GetValue( model.STATECODE);// pageparm[3].ParameterValue = GetValue( model.PARENTSTATEID );// pageparm[4].ParameterValue =GetValue( model.CONTENT);// pageparm[5].ParameterValue = GetValue( model.CHECKSTATE);//同意:1,不同意:0 ,未处理:2,会签同意7,会签不同意8 pageparm[6].ParameterValue =GetValue( model.FLAG);//已审批:1,未审批:0 pageparm[7].ParameterValue = GetValue( model.CREATEUSERID );// pageparm[8].ParameterValue = GetValue( model.CREATEUSERNAME );// pageparm[9].ParameterValue =GetValue( model.CREATECOMPANYID);// pageparm[10].ParameterValue =GetValue( model.CREATEDEPARTMENTID );// pageparm[11].ParameterValue =GetValue( model.CREATEPOSTID);// pageparm[12].ParameterValue = GetValue( model.CREATEDATE);// pageparm[13].ParameterValue =GetValue( model.EDITUSERID);// pageparm[14].ParameterValue =GetValue( model.EDITUSERNAME );// pageparm[15].ParameterValue =GetValue( model.EDITCOMPANYID);// pageparm[16].ParameterValue =GetValue( model.EDITDEPARTMENTID);// pageparm[17].ParameterValue =GetValue( model.EDITPOSTID);// pageparm[18].ParameterValue = GetValue( model.EDITDATE);// pageparm[19].ParameterValue =GetValue( model.AGENTUSERID );// pageparm[20].ParameterValue =GetValue( model.AGENTERNAME);// pageparm[21].ParameterValue = GetValue(model.AGENTEDITDATE);// int n= dao.ExecuteNonQuery(updSql, pageparm); Tracer.Debug("FLOW_FLOWRECORDDETAIL_TDAL->Update:更新[流程审批明细表]成功:FLOWRECORDDETAILID=" + model.FLOWRECORDDETAILID + ";FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID=" + model.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID + ";时间:" + DateTime.Now.ToString()); return n; } catch (Exception ex) { Tracer.Debug("FLOW_FLOWRECORDDETAIL_TDAL->Update:更新[流程审批明细表]失败:FLOWRECORDDETAILID=" + model.FLOWRECORDDETAILID + ";FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID=" + model.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID + ";时间:" + DateTime.Now.ToString() + "\r\n异常信息:" + ex.Message); throw new Exception("FLOW_FLOWRECORDDETAIL_TDAL->Update:" + ex.Message); } }
/// <summary> /// 自选流程(对数据库操作、对服务操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <param name="fd"></param> /// <returns></returns> public DataResult ApprovalFreeFlow(SubmitData ApprovalData, DataResult APPDataResult, List<FLOW_FLOWRECORDDETAIL_T> fd, ref FlowUser user) { // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); UserInfo AppUser = new UserInfo(); //下一审核人 UserInfo AgentAppUser = new UserInfo(); //代理下一审核人 try { APPDataResult.RunTime += "---GetAppInfoStart:" + DateTime.Now.ToString(); List<FLOW_FLOWRECORDDETAIL_T> tmp = fd.Where(c => (c.EDITUSERID == ApprovalData.ApprovalUser.UserID || c.AGENTUSERID == ApprovalData.ApprovalUser.UserID) && c.FLAG == "0").ToList(); APPDataResult.RunTime += "---GetAppInfoEnd:" + DateTime.Now.ToString(); if (tmp == null) { APPDataResult.FlowResult = FlowResult.FAIL; APPDataResult.Err = "没有找到待审核信息"; user.TrackingMessage += "没有找到待审核信息\r\n"; // DataResult.UserInfo = null; return APPDataResult; } entity = tmp[0]; entity.EDITDATE = DateTime.Now; //审批时间 if (entity.AGENTUSERID == ApprovalData.ApprovalUser.UserID) { entity.AGENTEDITDATE = entity.EDITDATE; //代理审批时审批时间与代理审批时间到致 } //entity.EditUserID = AppUserId; entity.CONTENT = ApprovalData.ApprovalContent; entity.CHECKSTATE = ((int)ApprovalData.ApprovalResult).ToString(); try { workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); Tracer.Debug("Formid=" + ApprovalData.FormID + ";开始 审核获取[自选流程]工作流实例ID=" + tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID); instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID);// workflowRuntime.GetWorkflow(new Guid(tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID)); Tracer.Debug("Formid=" + ApprovalData.FormID + ";完成 审核获取[自选流程]工作流实例ID=" + instance.InstanceId.ToString()); } catch { Tracer.Debug("Formid=" + ApprovalData.FormID + ";完成 审核获取[自选流程]工作流实例 出错,需要重新构造工作流程实例,原来的实例ID=" + tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID); workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); instance = SMTWorkFlowManage.CreateFreeWorkflowInstance(workflowRuntime, "FreeFlow.xml");//自选流程使用 tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID = instance.InstanceId.ToString(); Tracer.Debug("Formid=" + ApprovalData.FormID + ";完成 重新构造[自选流程]工作流程实例,新的实例ID=" + tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID); } //不同意状态处理 if (ApprovalData.ApprovalResult == ApprovalResult.NoPass) { instance.Terminate("0"); user.TrackingMessage += "终审不通过,中止流程 FORMID=" + user.FormID; entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "3"; //设为终审不通过 entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = ApprovalData.ApprovalUser.UserID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = ApprovalData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowDetailRecord(entity, ApprovalData.NextStateCode, ApprovalData.NextApprovalUser.UserID); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 APPDataResult.CheckState = "3";// user.TrackingMessage += "终审不通过,设置状态 CheckState=3;FORMID=" + user.FormID; APPDataResult.FlowResult = FlowResult.END; // DataResult.UserInfo = null; // return DataResult; } else { //下一审核人赋值 if (ApprovalData.NextApprovalUser != null && !string.IsNullOrEmpty(ApprovalData.NextApprovalUser.UserID)) { AppUser = ApprovalData.NextApprovalUser; } else { AppUser = ApprovalData.ApprovalUser;//如果没有下一审核人,下一审核人就是当前的审核人 } user.TrackingMessage += "选择了下一个审核人 AppUser="******";FORMID=" + user.FormID; AgentAppUser = GetAgentUserInfo(ApprovalData.ModelCode, AppUser.UserID); //查询是否启用了代理人(对服务操作) user.TrackingMessage += "查询是否启用了代理人 AppUser="******";FORMID=" + user.FormID; FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = ApprovalData.XML; //workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) //{//完成工作流实例 // instance = null; //}; ApprovalData.NextStateCode = ApprovalData.NextStateCode == "EndFlow" ? "EndFlow" : "Approval"; APPDataResult.RunTime += "---DoFlowStart:" + DateTime.Now.ToString(); APPDataResult = DoFlowRecord(workflowRuntime, instance, entity, ApprovalData.NextStateCode, AppUser, AgentAppUser, ApprovalData.SubmitFlag, ApprovalData.FlowType, ref user); //处理流程数据 APPDataResult.AgentUserInfo = AgentAppUser; APPDataResult.RunTime += "---DoFlowEnd:" + DateTime.Now.ToString(); if (ApprovalData.NextStateCode == "EndFlow") { //ManualWorkflowSchedulerService scheduleService = workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService; //scheduleService.RunWorkflow(instance.InstanceId); //workflowRuntime.GetService<FlowEvent>().OnDoFlow(instance.InstanceId, FlowData); //激发流程引擎执行到一下流程 //scheduleService.RunWorkflow(instance.InstanceId); //System.Threading.Thread.Sleep(1000); } } return APPDataResult; } catch (Exception e) { Tracer.Debug("自选流程提交出错:FORMID=" + user.FormID + "\r\n 异常信息:" + e.ToString()); throw new Exception("自选流程提交出错,请联系管理员! \r\n FormID=" + user.FormID + ""); } finally { AppUser = null; AgentAppUser = null; entity = null; instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
/// <summary> /// 获取流程 /// </summary> /// <param name="con">//OracleConnection连接对象</param> /// <param name="FormID">表单ID</param> /// <param name="FlowGUID">明细ID</param> /// <param name="CheckState">审批状态(同意:1,不同意:0 ,未处理:2,会签同意7,会签不同意8)</param> /// <param name="Flag">审批状态(已审批:1,未审批:0)</param> /// <param name="ModelCode">模块代码</param> /// <param name="CompanyID">创建公司ID</param> /// <param name="EditUserID">操作人</param> /// <param name="FlowType">流程类型(0:审批流程,1:任务流程)</param> /// <returns></returns> public static List<FLOW_FLOWRECORDDETAIL_T> GetFlowRecordV(string FormID, string FlowGUID, string CheckState, string Flag, string ModelCode, string CompanyID, string EditUserID, List<string> FlowType) { #region sql StringBuilder sb = new StringBuilder(); sb.Append(@"select FLOW_FLOWRECORDDETAIL_T.* from FLOW_FLOWRECORDDETAIL_T join FLOW_FLOWRECORDMASTER_T on FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID=FLOW_FLOWRECORDDETAIL_T.FLOWRECORDMASTERID where 1=1 "); if (!string.IsNullOrEmpty(FlowGUID)) { sb.Append(" and FLOW_FLOWRECORDDETAIL_T.FLOWRECORDDETAILID='" + FlowGUID + "'"); } if (!string.IsNullOrEmpty(Flag)) { sb.Append(" and FLOW_FLOWRECORDDETAIL_T.FLAG='" + Flag + "'"); } if (!string.IsNullOrEmpty(EditUserID)) { sb.Append(" and (FLOW_FLOWRECORDDETAIL_T.EDITUSERID='" + EditUserID + "' or FLOW_FLOWRECORDDETAIL_T.AGENTUSERID='" + EditUserID + "')"); } if (!string.IsNullOrEmpty(CompanyID)) { sb.Append(" and FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID='" + CompanyID + "'"); } if (!string.IsNullOrEmpty(ModelCode)) { sb.Append(" and FLOW_FLOWRECORDMASTER_T.MODELCODE='" + ModelCode + "'"); } if (!string.IsNullOrEmpty(FormID)) { sb.Append(" and FLOW_FLOWRECORDMASTER_T.FORMID='" + FormID + "'"); } if (!string.IsNullOrEmpty(CheckState)) { sb.Append(" and FLOW_FLOWRECORDMASTER_T.CHECKSTATE='" + CheckState + "'"); } if (FlowType != null) { if (FlowType.Count == 1) { sb.Append(" and FLOW_FLOWRECORDMASTER_T.FLOWTYPE='" + FlowType[0] + "'"); } else { sb.Append(" and FLOW_FLOWRECORDMASTER_T.FLOWTYPE in ("); for (int i = 0; i < FlowType.Count - 1; i++) { sb.Append("'" + FlowType[i] + "',"); } sb.Append("'" + FlowType[FlowType.Count - 1] + "'"); sb.Append(")"); } } #endregion List<FLOW_FLOWRECORDDETAIL_T> listDetail = new List<FLOW_FLOWRECORDDETAIL_T>(); List<FLOW_FLOWRECORDMASTER_T> listMaster = new List<FLOW_FLOWRECORDMASTER_T>(); IDataReader dr = null; try { List<string> listDetailID = new List<string>(); List<string> listMasterID = new List<string>(); ////OracleCommand command = con.CreateCommand(); //command.CommandText = sb.ToString(); //dr = command.ExecuteReader(); dr = dao.ExecuteReader(sb.ToString(), null); while (dr.Read()) { #region detail FLOW_FLOWRECORDDETAIL_T detail = new FLOW_FLOWRECORDDETAIL_T(); detail.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); detail.AGENTEDITDATE = dr["AGENTEDITDATE"] == DBNull.Value ? null : (DateTime?)dr["AGENTEDITDATE"]; detail.AGENTERNAME = dr["AGENTERNAME"] == DBNull.Value ? null : dr["AGENTERNAME"].ToString(); detail.AGENTUSERID = dr["AGENTUSERID"] == DBNull.Value ? null : dr["AGENTUSERID"].ToString(); detail.CHECKSTATE = dr["CHECKSTATE"] == DBNull.Value ? null : dr["CHECKSTATE"].ToString(); detail.CONTENT = dr["CONTENT"] == DBNull.Value ? null : dr["CONTENT"].ToString(); detail.CREATECOMPANYID = dr["CREATECOMPANYID"] == DBNull.Value ? null : dr["CREATECOMPANYID"].ToString(); detail.CREATEDATE = (DateTime)dr["CREATEDATE"]; detail.CREATEDEPARTMENTID = dr["CREATEDEPARTMENTID"] == DBNull.Value ? null : dr["CREATEDEPARTMENTID"].ToString(); detail.CREATEPOSTID = dr["CREATEPOSTID"] == DBNull.Value ? null : dr["CREATEPOSTID"].ToString(); detail.CREATEUSERID = dr["CREATEUSERID"] == DBNull.Value ? null : dr["CREATEUSERID"].ToString(); detail.CREATEUSERNAME = dr["CREATEUSERNAME"] == DBNull.Value ? null : dr["CREATEUSERNAME"].ToString(); detail.EDITCOMPANYID = dr["EDITCOMPANYID"] == DBNull.Value ? null : dr["EDITCOMPANYID"].ToString(); detail.EDITDATE = dr["EDITDATE"] == DBNull.Value ? null : (DateTime?)dr["EDITDATE"]; detail.EDITDEPARTMENTID = dr["EDITDEPARTMENTID"] == DBNull.Value ? null : dr["EDITDEPARTMENTID"].ToString(); detail.EDITPOSTID = dr["EDITPOSTID"] == DBNull.Value ? null : dr["EDITPOSTID"].ToString(); detail.EDITUSERID = dr["EDITUSERID"] == DBNull.Value ? null : dr["EDITUSERID"].ToString(); detail.EDITUSERNAME = dr["EDITUSERNAME"] == DBNull.Value ? null : dr["EDITUSERNAME"].ToString(); detail.FLAG = dr["FLAG"] == DBNull.Value ? null : dr["FLAG"].ToString(); detail.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = dr["FLOWRECORDMASTERID"].ToString(); detail.FLOWRECORDDETAILID = dr["FLOWRECORDDETAILID"] == DBNull.Value ? null : dr["FLOWRECORDDETAILID"].ToString(); detail.PARENTSTATEID = dr["PARENTSTATEID"] == DBNull.Value ? null : dr["PARENTSTATEID"].ToString(); detail.STATECODE = dr["STATECODE"] == DBNull.Value ? null : dr["STATECODE"].ToString(); detail.FLOW_CONSULTATION_T = new EntityCollection<FLOW_CONSULTATION_T>(); listDetail.Add(detail); listDetailID.Add("'" + detail.FLOWRECORDDETAILID + "'"); if (!listMasterID.Contains(detail.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID)) { listMasterID.Add("'" + detail.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID + "'"); } #endregion } dr.Close(); #region master if (listMasterID.Count > 0) { string sql= @"select CHECKSTATE,CREATECOMPANYID,CREATEDATE,CREATEDEPARTMENTID,CREATEPOSTID,CREATEUSERID,CREATEUSERNAME, EDITDATE,EDITUSERID,EDITUSERNAME,FLOWCODE,FLOWRECORDMASTERID,FLOWSELECTTYPE,FLOWTYPE,FORMID,INSTANCEID,MODELCODE from FLOW_FLOWRECORDMASTER_T where FLOWRECORDMASTERID in (" + string.Join(",", listMasterID.ToArray()) + ")"; dr = dao.ExecuteReader(sql); while (dr.Read()) { #region master FLOW_FLOWRECORDMASTER_T master = new FLOW_FLOWRECORDMASTER_T(); //master.ACTIVEROLE = dr["ACTIVEROLE"] == DBNull.Value ? null : dr["ACTIVEROLE"].ToString(); //master.BUSINESSOBJECT = dr["BUSINESSOBJECT"] == DBNull.Value ? null : dr["BUSINESSOBJECT"].ToString(); master.CHECKSTATE = dr["CHECKSTATE"] == DBNull.Value ? null : dr["CHECKSTATE"].ToString(); master.CREATECOMPANYID = dr["CREATECOMPANYID"] == DBNull.Value ? null : dr["CREATECOMPANYID"].ToString(); master.CREATEDATE = (DateTime)dr["CREATEDATE"]; master.CREATEDEPARTMENTID = dr["CREATEDEPARTMENTID"] == DBNull.Value ? null : dr["CREATEDEPARTMENTID"].ToString(); master.CREATEPOSTID = dr["CREATEPOSTID"] == DBNull.Value ? null : dr["CREATEPOSTID"].ToString(); master.CREATEUSERID = dr["CREATEUSERID"] == DBNull.Value ? null : dr["CREATEUSERID"].ToString(); master.CREATEUSERNAME = dr["CREATEUSERNAME"] == DBNull.Value ? null : dr["CREATEUSERNAME"].ToString(); master.EDITDATE = dr["EDITDATE"] == DBNull.Value ? null : (DateTime?)dr["EDITDATE"]; master.EDITUSERID = dr["EDITUSERID"] == DBNull.Value ? null : dr["EDITUSERID"].ToString(); master.EDITUSERNAME = dr["EDITUSERNAME"] == DBNull.Value ? null : dr["EDITUSERNAME"].ToString(); master.FLOWCODE = dr["FLOWCODE"] == DBNull.Value ? null : dr["FLOWCODE"].ToString(); master.FLOWRECORDMASTERID = dr["FLOWRECORDMASTERID"].ToString(); master.FLOWSELECTTYPE = dr["FLOWSELECTTYPE"] == DBNull.Value ? null : dr["FLOWSELECTTYPE"].ToString(); master.FLOWTYPE = dr["FLOWTYPE"] == DBNull.Value ? null : dr["FLOWTYPE"].ToString(); master.FORMID = dr["FORMID"] == DBNull.Value ? null : dr["FORMID"].ToString(); master.INSTANCEID = dr["INSTANCEID"] == DBNull.Value ? null : dr["INSTANCEID"].ToString(); //master.KPITIMEXML = dr["KPITIMEXML"] == DBNull.Value ? null : dr["KPITIMEXML"].ToString(); master.MODELCODE = dr["MODELCODE"] == DBNull.Value ? null : dr["MODELCODE"].ToString(); master.FLOW_FLOWRECORDDETAIL_T = new EntityCollection<FLOW_FLOWRECORDDETAIL_T>(); listMaster.Add(master); #endregion } dr.Close(); } #endregion #region FLOW_CONSULTATION_T List<FLOW_CONSULTATION_T> listConsultation = new List<FLOW_CONSULTATION_T>(); if (!string.IsNullOrEmpty(FormID) && !string.IsNullOrEmpty(ModelCode)) { if (listDetailID.Count > 0) { string sql = @"select * from FLOW_CONSULTATION_T where FLOWRECORDDETAILID in (" + string.Join(",", listDetailID.ToArray()) + ")"; dr = dao.ExecuteReader(sql); while (dr.Read()) { #region FLOW_CONSULTATION_T FLOW_CONSULTATION_T consul = new FLOW_CONSULTATION_T(); consul.CONSULTATIONCONTENT = dr["CONSULTATIONCONTENT"] == DBNull.Value ? null : dr["CONSULTATIONCONTENT"].ToString(); consul.CONSULTATIONDATE = dr["CONSULTATIONDATE"] == DBNull.Value ? null : (DateTime?)dr["CONSULTATIONDATE"]; consul.CONSULTATIONID = dr["CONSULTATIONID"] == DBNull.Value ? null : dr["CONSULTATIONID"].ToString(); consul.CONSULTATIONUSERID = dr["CONSULTATIONUSERID"] == DBNull.Value ? null : dr["CONSULTATIONUSERID"].ToString(); consul.CONSULTATIONUSERNAME = dr["CONSULTATIONUSERNAME"] == DBNull.Value ? null : dr["CONSULTATIONUSERNAME"].ToString(); consul.FLAG = dr["FLAG"] == DBNull.Value ? null : dr["FLAG"].ToString(); consul.FLOW_FLOWRECORDDETAIL_T = new FLOW_FLOWRECORDDETAIL_T(); consul.FLOW_FLOWRECORDDETAIL_T.FLOWRECORDDETAILID = dr["FLOWRECORDDETAILID"].ToString(); consul.REPLYCONTENT = dr["REPLYCONTENT"] == DBNull.Value ? null : dr["REPLYCONTENT"].ToString(); consul.REPLYDATE = dr["REPLYDATE"] == DBNull.Value ? null : (DateTime?)dr["REPLYDATE"]; consul.REPLYUSERID = dr["REPLYUSERID"] == DBNull.Value ? null : dr["REPLYUSERID"].ToString(); consul.REPLYUSERNAME = dr["REPLYUSERNAME"] == DBNull.Value ? null : dr["REPLYUSERNAME"].ToString(); listConsultation.Add(consul); #endregion } dr.Close(); } } #endregion listDetail.ForEach(detail => { #region FLOW_FLOWRECORDMASTER_T master = listMaster.FirstOrDefault(m => m.FLOWRECORDMASTERID == detail.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID); detail.FLOW_FLOWRECORDMASTER_T = master; if (master.FLOW_FLOWRECORDDETAIL_T == null) { master.FLOW_FLOWRECORDDETAIL_T = new EntityCollection<FLOW_FLOWRECORDDETAIL_T>(); } master.FLOW_FLOWRECORDDETAIL_T.Add(detail); if (!string.IsNullOrEmpty(FormID) && !string.IsNullOrEmpty(ModelCode)) { IEnumerable<FLOW_CONSULTATION_T> iFLOW_CONSULTATION_T = listConsultation.Where(c => c.FLOW_FLOWRECORDDETAIL_T.FLOWRECORDDETAILID == detail.FLOWRECORDDETAILID); if (iFLOW_CONSULTATION_T.Count() > 0) { detail.FLOW_CONSULTATION_T = new EntityCollection<FLOW_CONSULTATION_T>(); foreach (var consultation in iFLOW_CONSULTATION_T) { consultation.FLOW_FLOWRECORDDETAIL_T = detail; detail.FLOW_CONSULTATION_T.Add(consultation); } } } #endregion }); return listDetail; } catch (Exception ex) { if (dr != null && !dr.IsClosed) { dr.Close(); } throw new Exception("FLOW_FLOWRECORDDETAIL_TDAL->GetFlowRecordV:-" + FormID + "-" + ex.Message + ex.InnerException); } }
/// <summary> /// 自选流程使用:流程数据处理(对应SubmitFlow)对数据库操作 /// </summary> /// <param name="workflowRuntime"></param> /// <param name="instance"></param> /// <param name="entity"></param> /// <param name="NextStateCode"></param> /// <param name="EditUserId"></param> /// <param name="EditUserName"></param> /// <param name="SubmitFlag"></param> /// <param name="FlowType"></param> /// <returns></returns> public DataResult DoFlowRecord( WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, UserInfo AppUser, UserInfo AgentUser, SubmitFlag SubmitFlag, FlowType FlowType,ref FlowUser fUser) { DataResult tmpDataResult = new DataResult(); UserInfo tmpUserInfo = AppUser; //tmpUserInfo.UserID = EditUserId; //tmpUserInfo.UserName = EditUserName; tmpDataResult.UserInfo.Add(tmpUserInfo); try { if (SubmitFlag == SubmitFlag.New) { #region 新增流程 //添加启动状态 entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; #region 引擎自动提交时停留在提交人处 if (FlowType == FlowType.Pending) { entity.FLAG = "0"; entity.EDITUSERID = AppUser.UserID; entity.EDITUSERNAME = AppUser.UserName; entity.EDITCOMPANYID = AppUser.CompanyID; entity.EDITDEPARTMENTID = AppUser.DepartmentID; entity.EDITPOSTID = AppUser.PostID; FLOW_FLOWRECORDMASTER_TDAL.Add( entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 fUser.NextEditUserID = entity.EDITUSERID; fUser.NextEditUserName = entity.EDITUSERNAME; AddFlowDetailRecord( entity, NextStateCode, AppUser.UserID); tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; return tmpDataResult; } #endregion FLOW_FLOWRECORDMASTER_TDAL.Add( entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 fUser.NextEditUserID = entity.EDITUSERID; fUser.NextEditUserName = entity.EDITUSERNAME; AddFlowDetailRecord( entity, NextStateCode, AppUser.UserID); FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); //添加下一状态 entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.STATECODE = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; //entity2.Content = "."; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.CREATEDATE = DateTime.Now; entity2.EDITUSERID = AppUser.UserID; entity2.EDITUSERNAME = AppUser.UserName; entity2.EDITCOMPANYID = AppUser.CompanyID; entity2.EDITDEPARTMENTID = AppUser.DepartmentID; entity2.EDITPOSTID = AppUser.PostID; entity2.EDITDATE = DateTime.Now; if (AgentUser != null) //如果启用了代理,把代理人信息写入 { entity2.AGENTUSERID = AgentUser.UserID; entity2.AGENTERNAME = AgentUser.UserName; entity2.AGENTEDITDATE = DateTime.Now; } tmpDataResult.AppState = entity2.STATECODE; if (entity2.STATECODE != "EndFlow") { fUser.NextEditUserID = entity2.EDITUSERID; fUser.NextEditUserName = entity2.EDITUSERNAME; AddFlowDetailRecord( entity2, NextStateCode, AppUser.UserID);//对数据库操作 tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.CheckState = "2"; tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END } return tmpDataResult; #endregion } else { #region 更新流程 //如果NextStateCode为空则自动获取模型中的下一状态,如果不为空则使用传入状态代码,并使用传入下一任务人ID //更新本流程 entity = UpdateFlowDetailRecord( entity, NextStateCode, AppUser.UserID);//对数据库操作 //添加下一状态 FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); //添加下一状态 entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); if (NextStateCode != "") { entity2.STATECODE = NextStateCode; //entity2.EditUserID = EditUserId; //entity2.EditUserName = EditUserName; } else { entity2.STATECODE = SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE); // entity2.EditUserID = entity2.StateCode=="EndFlow" ? "" : "EditUserId"; //根据状态查询权限表中用户ID } if (entity2.STATECODE == "EndFlow") { entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "2"; //设为终审通过 if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.AGENTUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.AGENTERNAME; } else //正常审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.EDITUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.EDITUSERNAME; } entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowDetailRecord( entity, NextStateCode, AppUser.UserID);//对数据库操作 FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 } entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;// entity.StateCode; //entity2.Content = ""; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; //if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 //{ // entity2.CREATEUSERID = entity.AGENTUSERID; // entity2.CREATEUSERNAME = entity.AGENTERNAME; //} //else //正常审核时 //{ entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; //} entity2.EDITUSERID = AppUser.UserID; entity2.EDITUSERNAME = AppUser.UserName; entity2.EDITCOMPANYID = AppUser.CompanyID; entity2.EDITDEPARTMENTID = AppUser.DepartmentID; entity2.EDITPOSTID = AppUser.PostID; entity2.CREATEDATE = DateTime.Now; entity2.EDITDATE = DateTime.Now; if (AgentUser != null) //如果启用了代理,把代理人信息写入 { entity2.AGENTUSERID = AgentUser.UserID; entity2.AGENTERNAME = AgentUser.UserName; entity2.AGENTEDITDATE = DateTime.Now; } tmpDataResult.AppState = entity2.STATECODE; if (entity2.STATECODE != "EndFlow") { entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; fUser.NextEditUserID = entity2.EDITUSERID; fUser.NextEditUserName = entity2.EDITUSERNAME; AddFlowDetailRecord( entity2, NextStateCode, AppUser.UserID);//对数据库操作 tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END tmpDataResult.CheckState = "2"; } return tmpDataResult; //如有下一节点,返回SUCCESS #endregion } } catch (Exception ex) { Tracer.Debug("提交自选流程数据出错,DoFlowRecord异常信息 :" + ex.ToString()); throw new Exception("提交自选流程数据出错!请联系管理员!"); //tmpDataResult.FlowResult = FlowResult.FAIL; //tmpDataResult.Err = ex.Message; //return tmpDataResult; } }
/// <summary> /// 自选流程审批(对服务操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <returns></returns> public DataResult SubmitFreeFlow(SubmitData ApprovalData, DataResult APPDataResult, ref FlowUser user) { // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); UserInfo AppUser = new UserInfo(); //下一审核人 UserInfo AgentAppUser = new UserInfo(); //代理下一审核人 try { entity.FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT = ApprovalData.XML; entity.FLOW_FLOWRECORDMASTER_T.FORMID = ApprovalData.FormID; entity.FLOW_FLOWRECORDMASTER_T.MODELCODE = ApprovalData.ModelCode; // entity.FLOWRECORDDETAILID = FlowGUID; entity.CREATECOMPANYID = ApprovalData.ApprovalUser.CompanyID; entity.CREATEDEPARTMENTID = ApprovalData.ApprovalUser.DepartmentID; entity.CREATEPOSTID = ApprovalData.ApprovalUser.PostID; entity.CREATEUSERID = ApprovalData.ApprovalUser.UserID; entity.CREATEUSERNAME = ApprovalData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.FLOWTYPE = ((int)ApprovalData.FlowType).ToString(); entity.FLOW_FLOWRECORDMASTER_T.FLOWSELECTTYPE = ((int)ApprovalData.FlowSelectType).ToString(); entity.FLOW_FLOWRECORDMASTER_T.FLOWCODE = "FreeFlow"; workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); instance = SMTWorkFlowManage.CreateFreeWorkflowInstance(workflowRuntime, "FreeFlow.xml");//自选流程使用 user.TrackingMessage += "自选流程使用 AddFreeFlow(try)创建工作流实例完成 ID=" + instance.InstanceId; entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID = instance.InstanceId.ToString(); //下一审核人赋值 AppUser = ApprovalData.NextApprovalUser; APPDataResult.RunTime += "---DoFlowStart:" + DateTime.Now.ToString(); ApprovalData.NextStateCode = "Approval"; AgentAppUser = GetAgentUserInfo(ApprovalData.ModelCode, AppUser.UserID); //查询是否启用了代理人(对服务操作) if (AgentAppUser != null) { Tracer.Debug("查询 启用了代理人 FormID=" + user.FormID + " UserID=" + AgentAppUser.UserID); } else { Tracer.Debug("查询 没有启用了代理人 FormID=" + user.FormID + " AgentAppUser=null"); } APPDataResult = DoFlowRecord(workflowRuntime, instance, entity, ApprovalData.NextStateCode, AppUser, AgentAppUser, ApprovalData.SubmitFlag, ApprovalData.FlowType, ref user); //处理流程数据 APPDataResult.AgentUserInfo = AgentAppUser; APPDataResult.RunTime += "---DoFlowEnd:" + DateTime.Now.ToString(); Tracer.Debug("Formid=" + ApprovalData.FormID + ";自选流程工作流实例ID:" + instance.InstanceId.ToString()); return APPDataResult; } catch (Exception e) { user.ErrorMsg += "自选流程审批出错 FormID=" + ApprovalData.FormID + ";异常信息:\r\n" + e.ToString() + "\r\n"; Tracer.Debug("自选流程审批出错 FormID=" + ApprovalData.FormID + ";跟踪信息:\r\n" + user.TrackingMessage + "异常信息:\r\n" + e.ToString()); throw new Exception("自选流程审批出错,请联系管理员! \r\n FormID=" + user.FormID + ""); } finally { AppUser = null; AgentAppUser = null; entity = null; instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
//下一审核人提交审核时调用方法 /// <summary> /// 固定流程:下一审核人提交审核时调用方法 /// </summary> /// <param name="submitData"></param> /// <param name="dataResult"></param> /// <param name="listDetail"></param> /// <returns></returns> public DataResult ApprovalFlow(SubmitData submitData, DataResult dataResult, List<FLOW_FLOWRECORDDETAIL_T> listDetail, ref FlowUser user, ref string msg) { if (submitData.NextApprovalUser == null) { submitData.NextApprovalUser = new UserInfo(); } ///针对会签,该次审核成功后是否跳转至下一状态 bool isGotoNextState = true; // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); try { #region Entity赋值 List<FLOW_FLOWRECORDDETAIL_T> tmpEntity = listDetail.Where(c => (c.EDITUSERID == submitData.ApprovalUser.UserID || c.AGENTUSERID == submitData.ApprovalUser.UserID) && c.FLAG == "0").ToList(); if (tmpEntity == null) { dataResult.FlowResult = FlowResult.FAIL; dataResult.Err = "没有找到待审核信息 FORMID=" + user.FormID + "\r\n"; user.TrackingMessage += "没有找到待审核信息 FORMID=" + user.FormID + "\r\n"; return dataResult; } entity = tmpEntity[0]; entity.EDITDATE = DateTime.Now; //审批时间 if (entity.AGENTUSERID == submitData.ApprovalUser.UserID) { entity.AGENTEDITDATE = entity.EDITDATE; //代理审批时审批时间与代理审批时间到致 } entity.CONTENT = submitData.ApprovalContent; entity.CHECKSTATE = ((int)submitData.ApprovalResult).ToString(); #endregion #region backup persisted workflow instanceState if (!string.IsNullOrEmpty(entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID)) { String connStringPersistence = ConfigurationManager.ConnectionStrings["//OracleConnection"].ConnectionString;//Data Source=172.30.50.110;Initial Catalog=WorkflowPersistence;Persist Security Info=True;User ID=sa;Password=fbaz2012;MultipleActiveResultSets=True"; string sql = string.Format("select * from instance_state where instance_id='{0}'", entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID); DataTable dt = dao.GetDataTable(sql); DataSet Dataset = new DataSet(); Dataset.Tables.Add(dt); user.InstanceState = Dataset; } #endregion //workflowRuntime.StartRuntime(); user.TrackingMessage += "创建工作流运行时开始 FORMID=" + user.FormID + "\r\n"; workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); try { instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID);// workflowRuntime.GetWorkflow(new Guid(tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID)); user.TrackingMessage += "FormID=" + submitData.FormID + ";ApprovalFlow2(try)从持久化库[ 完成 ]恢复创建工作流实例ID=" + entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID + "\r\n"; Tracer.Debug("审核 FormID=" + user.FormID + " WorkflowInstance ID=" + instance.InstanceId.ToString()); } catch (Exception exGetWorkflowInstance) { #region 重新创建新流程,将新流程设置为当前状态。 try { user.TrackingMessage += "FormID=" + submitData.FormID + ";从持久化恢复工作流失败 SMTWorkFlowManage.GetWorkflowInstance(" + workflowRuntime.Name + ", " + entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID + ");原因如下:\r\n" + exGetWorkflowInstance.ToString() + ";\r\n下面重新创建新流程,并将新流程设置为当前状态;\r\nGetFlowByModelName:submitData.ApprovalUser.DepartmentID=" + submitData.ApprovalUser.DepartmentID + ";OrgType='" + ((int)submitData.FlowType).ToString() + "'"; List<FLOW_MODELFLOWRELATION_T> MODELFLOWRELATION = GetFlowByModelName(entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID, entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID, submitData.ModelCode, ((int)submitData.FlowType).ToString(), ref user); FLOW_MODELFLOWRELATION_T flowRelation = MODELFLOWRELATION[0]; FLOW_FLOWDEFINE_T flowDefine = flowRelation.FLOW_FLOWDEFINE_T; instance = SMTWorkFlowManage.CreateWorkflowInstance(workflowRuntime, flowDefine.LAYOUT, flowDefine.RULES); user.TrackingMessage += "FormID=" + submitData.FormID + ";ApprovalFlow2(catch)完成重新创建工作流实例ID=" + instance.InstanceId + "\r\n"; //StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); //ManualWorkflowSchedulerService scheduleService = workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService; //scheduleService.RunWorkflow(workflowinstance.InstanceId); //workflowinstance.SetState(entity.STATECODE); //System.Threading.Thread.Sleep(1000); //commented by alan 2012/9/7 instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, instance.InstanceId.ToString()); user.TrackingMessage += "FormID=" + submitData.FormID + ";ApprovalFlow2(catch)从持久化库再恢复刚才创建工作流实例ID=" + instance.InstanceId + "\r\n"; entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID = instance.InstanceId.ToString(); //FLOW_FLOWRECORDDETAIL_TDAL.UpdateMasterINSTANCEID(entity.FLOW_FLOWRECORDMASTER_T); FLOW_FLOWRECORDMASTER_TDAL.UpdateMasterINSTANCEID(entity.FLOW_FLOWRECORDMASTER_T); } catch (Exception exNewInstance) { user.ErrorMsg += "重新创建新流程,将新流程设置为当前状态失败:FormID=" + submitData.FormID + "异常信息:\r\n" + exNewInstance.Message + "\r\n"; Tracer.Debug("重新创建新流程,将新流程设置为当前状态失败:FormID=" + submitData.FormID + "FlowBLL->ApprovalFlow2" + exNewInstance.Message); //Tracer.Debug("exNewInstance: -" + submitData.FormID + "--submitDataXML:" + submitData.XML + "-" + exNewInstance.InnerException + exNewInstance.Message); throw new Exception("重新创建新流程,将新流程设置为当前状态失败,请联系管理!"); } #endregion } user.TrackingMessage += "SMTWorkFlowManage.CreateWorkFlowRuntime(true)完成FORMID=" + user.FormID + " \r\n"; #region 当前状态会签状态处理 bool currentIsCountersign = false; string currentCountersignType = "0"; FlowUtility.IsCountersign(entity.FLOW_FLOWRECORDMASTER_T.ACTIVEROLE, entity.STATECODE, ref currentIsCountersign, ref currentCountersignType); if (currentIsCountersign) { user.TrackingMessage += "状态会签状态处理 FORMID=" + user.FormID + " \r\n"; if (currentCountersignType == "1")//一人通过即所有通过,可以跳转至下一状态 { isGotoNextState = true; } else { ///该审核是会签的最后的审核人 if (entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T.Count == 1) { isGotoNextState = true; } else { isGotoNextState = false; } } user.TrackingMessage += "状态会签状态处理完成 FORMID=" + user.FormID + " \r\n"; } #endregion //不同意状态处理 if (submitData.ApprovalResult == ApprovalResult.NoPass) { user.TrackingMessage += "审核不通过状态处理(开始) FORMID=" + user.FormID + " \r\n"; #region instance.Terminate("0"); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "3"; //设为终审不通过 entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = submitData.ApprovalUser.UserID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = submitData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; user.TrackingMessage += "审核不通过【开始更新明细表】!FORMID=" + user.FormID; //user.TrackingMessage += "entity.FLOWRECORDDETAILID" + entity.FLOWRECORDDETAILID + "\r\n";// //user.TrackingMessage += "entity.STATECODE=" + entity.STATECODE + "\r\n";// //user.TrackingMessage += "entity.PARENTSTATEID =" + entity.PARENTSTATEID + "\r\n";// //user.TrackingMessage += "entity.CONTENT=" + entity.CONTENT + "\r\n";// //user.TrackingMessage += "entity.CHECKSTATE=" + entity.CHECKSTATE + "\r\n";//同意:1,不同意:0 ,未处理:2,会签同意7,会签不同意8 //user.TrackingMessage += "entity.FLAG =" + entity.FLAG + "\r\n";//已审批:1,未审批:0 //user.TrackingMessage += " entity.CREATEUSERID =" + entity.CREATEUSERID + "\r\n";// //user.TrackingMessage += "entity.CREATEUSERNAME="******"\r\n";// //user.TrackingMessage += " entity.CREATECOMPANYID=" + entity.CREATECOMPANYID + "\r\n";// //user.TrackingMessage += " entity.CREATEDEPARTMENTID =" + entity.CREATEDEPARTMENTID + "\r\n";// //user.TrackingMessage += "entity.CREATEPOSTID=" + entity.CREATEPOSTID + "\r\n";// //user.TrackingMessage += "entity.CREATEDATE=" + entity.CREATEDATE + "\r\n";// //user.TrackingMessage += " entity.EDITUSERID=" + entity.EDITUSERID + "\r\n";// //user.TrackingMessage += "entity.EDITUSERNAME="******"\r\n";// //user.TrackingMessage += " entity.EDITCOMPANYID =" + entity.EDITCOMPANYID + "\r\n";// //user.TrackingMessage += " entity.EDITDEPARTMENTID=" + entity.EDITDEPARTMENTID + "\r\n";// //user.TrackingMessage += "entity.EDITPOSTID=" + entity.EDITPOSTID + "\r\n";// //user.TrackingMessage += "entity.EDITDATE=" + entity.EDITDATE + "\r\n";// //user.TrackingMessage += "entity.AGENTUSERID =" + entity.AGENTUSERID + "\r\n";// //user.TrackingMessage += " entity.AGENTERNAME=" + entity.AGENTERNAME + "\r\n";// //user.TrackingMessage += "entity.AGENTEDITDATE=" + entity.AGENTEDITDATE + "\r\n";// //user.TrackingMessage += "submitData.NextStateCode=" + submitData.NextStateCode + "\r\n";// //user.TrackingMessage += "submitData.NextApprovalUser.UserID=" + submitData.NextApprovalUser.UserID + "\r\n";// //user.TrackingMessage += " entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID=" + entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID + "\r\n";// UpdateFlowDetailRecord(entity, submitData.NextStateCode, submitData.NextApprovalUser.UserID); user.TrackingMessage += "审核不通过【开始更新主表】!FORMID=" + user.FormID; FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); dataResult.CheckState = "3";// dataResult.FlowResult = FlowResult.END; if (currentIsCountersign) { #region 当前是会签状态,删除未审核记录 user.TrackingMessage += "审核不通过【当前是会签状态,删除未审核记录】!FORMID=" + user.FormID; entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T .Where(detail => detail.FLOWRECORDDETAILID != entity.FLOWRECORDDETAILID && detail.STATECODE == entity.STATECODE && detail.FLAG == "0") .ToList().ForEach(item => { item.FLAG = "1"; item.CHECKSTATE = "8"; UpdateFlowRecord2(item); }); #endregion } #endregion user.TrackingMessage += "审核通过状态处理(完成) FORMID=" + user.FormID + " \r\n"; } else { if (!isGotoNextState) { user.TrackingMessage += "isGotoNextState开始 FORMID=" + user.FormID + " \r\n"; #region UpdateFlowRecord2(entity); dataResult.AppState = entity.STATECODE; dataResult.FlowResult = FlowResult.SUCCESS; dataResult.CheckState = "1"; #endregion user.TrackingMessage += "isGotoNextState完成 FORMID=" + user.FormID + "\r\n"; } else { user.TrackingMessage += "获取下一状态数据开始 FORMID=" + user.FormID + " \r\n"; #region 获取下一状态数据 List<string> User = new List<string>(); User.Add(entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID); User.Add(submitData.ApprovalUser.UserID); List<string> tmpPostID = new List<string>(); tmpPostID.Add(entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID); tmpPostID.Add(entity.EDITPOSTID); GetUserByInstance2(entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID, workflowRuntime, instance, entity.FLOW_FLOWRECORDMASTER_T.ACTIVEROLE, submitData.XML, entity.STATECODE, User, tmpPostID, submitData.FlowType, ref dataResult, ref user); if (dataResult.FlowResult == FlowResult.FAIL) { return dataResult; } submitData.NextStateCode = dataResult.AppState; if (dataResult.IsCountersign) { #region if (dataResult.FlowResult == FlowResult.Countersign) { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.DictCounterUser = dataResult.DictCounterUser; } } #endregion } else { #region if (dataResult.FlowResult == FlowResult.MULTIUSER) { if (submitData.NextApprovalUser == null || (FlowUtility.GetString(submitData.NextApprovalUser.UserID) == "" || FlowUtility.GetString(submitData.NextApprovalUser.UserName) == "")) { return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.NextApprovalUser = dataResult.UserInfo[0]; } } #endregion } #endregion user.TrackingMessage += "获取下一状态数据完成 FORMID=" + user.FormID + "\r\n"; user.TrackingMessage += "单据会签情况开始 FORMID=" + user.FormID + "\r\n"; #region 对于单会签情况,需要将其他审核人的审核设为会签通过状态 if (currentIsCountersign && currentCountersignType == "1") { entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T .Where(detail => detail.FLOWRECORDDETAILID != entity.FLOWRECORDDETAILID && detail.STATECODE == entity.STATECODE && detail.FLAG == "0") .ToList().ForEach(item => { item.FLAG = "1"; item.CHECKSTATE = "7"; UpdateFlowRecord2(item); }); } #endregion user.TrackingMessage += "单据会签情况完成 FORMID=" + user.FormID + "\r\n"; #region FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = submitData.XML; //workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) //{ // instance = null; //}; user.TrackingMessage += "处理kpi 开始 FORMID=" + user.FormID + "\r\n"; #region 处理kpi时间 string KPITime = ""; //PerformanceServiceWS.PerformanceServiceClient psc = new PerformanceServiceWS.PerformanceServiceClient(); string pscResult = entity.FLOW_FLOWRECORDMASTER_T.KPITIMEXML; //psc.Close(); if (!string.IsNullOrEmpty(pscResult)) { XElement xe = XElement.Parse(pscResult); Func<XElement, bool> f = (x) => { XAttribute xid = x.Attribute("id"); XAttribute xvalue = x.Attribute("value"); if (xid == null || xvalue == null) return false; else { if (xid.Value == dataResult.AppState) return true; else return false; } }; XElement FlowNode = xe.Elements("FlowNode").FirstOrDefault(f); if (FlowNode != null) { KPITime = FlowNode.Attribute("value").Value; } } dataResult.KPITime = KPITime; #endregion user.TrackingMessage += "处理kpi 完成 FORMID=" + user.FormID + "\r\n"; if (!dataResult.IsCountersign) { user.TrackingMessage += "非会签 开始 FORMID=" + user.FormID + "\r\n"; #region 非会签 UserInfo AppUser = submitData.NextApprovalUser; dataResult.UserInfo.Clear(); dataResult.UserInfo.Add(AppUser); UserInfo AgentAppUser = GetAgentUserInfo(submitData.ModelCode, AppUser.UserID);//查询是否启用了代理人 dataResult = AddOrUpdateFlowRecord(workflowRuntime, instance, entity, submitData.NextStateCode, AppUser, AgentAppUser, submitData.SubmitFlag, submitData.FlowType, ref user); //处理流程数据 dataResult.AgentUserInfo = AgentAppUser; dataResult.IsCountersign = false; #endregion user.TrackingMessage += "非会签 完成 FORMID=" + user.FormID + "\r\n"; } else { #region 会签 dataResult.DictCounterUser = submitData.DictCounterUser; Dictionary<UserInfo, UserInfo> dictAgentUserInfo = GetAgentUserInfo2(submitData.ModelCode, submitData.DictCounterUser); dataResult = DoFlowRecord_Approval(workflowRuntime, instance, entity, submitData.NextStateCode, submitData.DictCounterUser, dictAgentUserInfo, submitData.SubmitFlag, submitData.FlowType); //处理流程数据 dataResult.DictAgentUserInfo = dictAgentUserInfo; dataResult.IsCountersign = true; #endregion } user.TrackingMessage += "激发流程引擎执行到一下流程 开始 FORMID=" + user.FormID + "\r\n"; #region 激发流程引擎执行到一下流程 //StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); //ManualWorkflowSchedulerService scheduleService = workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService; //if (dataResult.AppState == null || dataResult.AppState == "") //{ // scheduleService.RunWorkflow(workflowinstance.InstanceId); // workflowRuntime.GetService<FlowEvent>().OnDoFlow(instance.InstanceId, FlowData); //激发流程引擎执行到一下流程 // scheduleService.RunWorkflow(workflowinstance.InstanceId); //} //else //{ // string ss = ""; // int n = 0; // scheduleService.RunWorkflow(workflowinstance.InstanceId); // workflowinstance.SetState(dataResult.AppState); //流程跳转到指定节点 // //while (true) // //{ // // ss += (n++).ToString()+"|" + workflowinstance.CurrentStateName; // // string stateName = workflowinstance.CurrentStateName; // // if (stateName != null && stateName.ToUpper().IndexOf("START") == -1) // // { // // break; // // } // //} //} #endregion user.TrackingMessage += "激发流程引擎执行到一下流程 完成 FORMID=" + user.FormID + "\r\n"; //dataResult.CanSendMessage = true; user.TrackingMessage += "System.Threading.Thread.Sleep(1000)\r\n"; //System.Threading.Thread.Sleep(1000); //Commented by Alan 2012-7-25 ,使用手动ScheduleService运行工作流,此处不需要 if (submitData.FlowType == FlowType.Task) dataResult.SubModelCode = FlowUtility.GetSubModelCode(entity.FLOW_FLOWRECORDMASTER_T.ACTIVEROLE, dataResult.AppState); //返回下一子模块代码 user.TrackingMessage += "System.Threading.Thread.Sleep(1000)完成\r\n"; #endregion } } dataResult.CurrentIsCountersign = currentIsCountersign; dataResult.IsGotoNextState = isGotoNextState; return dataResult; } catch (Exception e) { user.ErrorMsg += "提交审核时出错!FORMID=" + user.FormID + " 异常信息:" + e.ToString() + "\r\n"; Tracer.Debug("提交审核时出错!FORMID=" + user.FormID + " 异常信息:" + e.ToString()); throw new Exception("提交审核时出错,请联系管理员! \r\n FormID=" + user.FormID + ""); } finally { entity = null; instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
/// <summary> /// 非会签是使用 /// </summary> /// <param name="con"></param> /// <param name="workflowRuntime"></param> /// <param name="instance"></param> /// <param name="entity"></param> /// <param name="NextStateCode"></param> /// <param name="AppUser"></param> /// <param name="AgentUser"></param> /// <param name="SubmitFlag"></param> /// <param name="FlowType"></param> /// <returns></returns> public DataResult AddOrUpdateFlowRecord( WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, UserInfo AppUser, UserInfo AgentUser, SubmitFlag SubmitFlag, FlowType FlowType,ref FlowUser fUser) { DataResult tmpDataResult = new DataResult(); UserInfo tmpUserInfo = AppUser; tmpDataResult.UserInfo.Add(tmpUserInfo); try { if (SubmitFlag == SubmitFlag.New) { #region 新增流程 //添加启动状态 if (SubmitFlag == FlowWFService.SubmitFlag.New) { entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); } entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; #region 引擎自动提交时停留在提交人处 if (FlowType == FlowType.Pending) { entity.FLAG = "0"; entity.EDITUSERID = AppUser.UserID; entity.EDITUSERNAME = AppUser.UserName; entity.EDITCOMPANYID = AppUser.CompanyID; entity.EDITDEPARTMENTID = AppUser.DepartmentID; entity.EDITPOSTID = AppUser.PostID; fUser.NextEditUserID = entity.EDITUSERID; fUser.NextEditUserName = entity.EDITUSERNAME; FLOW_FLOWRECORDMASTER_TDAL.Add( entity.FLOW_FLOWRECORDMASTER_T); AddFlowDetailRecord( entity, NextStateCode, AppUser.UserID); tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; return tmpDataResult; } #endregion FLOW_FLOWRECORDMASTER_TDAL.Add( entity.FLOW_FLOWRECORDMASTER_T); fUser.NextEditUserID = entity.EDITUSERID; fUser.NextEditUserName = entity.EDITUSERNAME; AddFlowDetailRecord( entity, NextStateCode, AppUser.UserID); FLOW_FLOWRECORDDETAIL_T entDetail = new FLOW_FLOWRECORDDETAIL_T(); //添加下一状态 entDetail.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entDetail.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entDetail.STATECODE = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; entDetail.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; //entity2.Content = "."; entDetail.FLAG = "0"; entDetail.CHECKSTATE = "2"; entDetail.CREATEPOSTID = entity.CREATEPOSTID; entDetail.CREATECOMPANYID = entity.CREATECOMPANYID; entDetail.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entDetail.CREATEUSERID = entity.EDITUSERID; entDetail.CREATEUSERNAME = entity.EDITUSERNAME; entDetail.CREATEDATE = DateTime.Now; entDetail.EDITUSERID = AppUser.UserID; entDetail.EDITUSERNAME = AppUser.UserName; entDetail.EDITCOMPANYID = AppUser.CompanyID; entDetail.EDITDEPARTMENTID = AppUser.DepartmentID; entDetail.EDITPOSTID = AppUser.PostID; entDetail.EDITDATE = DateTime.Now; if (AgentUser != null) //如果启用了代理,把代理人信息写入 { entDetail.AGENTUSERID = AgentUser.UserID; entDetail.AGENTERNAME = AgentUser.UserName; entDetail.AGENTEDITDATE = DateTime.Now; } tmpDataResult.AppState = entDetail.STATECODE; if (entDetail.STATECODE != "EndFlow") { fUser.NextEditUserID = entDetail.EDITUSERID; fUser.NextEditUserName = entDetail.EDITUSERNAME; AddFlowDetailRecord( entDetail, NextStateCode, AppUser.UserID); tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.CheckState = "2"; tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END } tmpDataResult.IsCountersignComplete = true; return tmpDataResult; #endregion } else { #region 更新流程 //如果NextStateCode为空则自动获取模型中的下一状态,如果不为空则使用传入状态代码,并使用传入下一任务人ID //更新本流程 entity = UpdateFlowDetailRecord( entity, NextStateCode, AppUser.UserID); string stateCode = ""; if (NextStateCode.ToUpper() == "ENDFLOW") { stateCode = NextStateCode; } else { stateCode = string.IsNullOrEmpty(NextStateCode) ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; } if (stateCode == "EndFlow") { #region entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "2"; //设为终审通过 if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.AGENTUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.AGENTERNAME; } else //正常审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.EDITUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.EDITUSERNAME; } entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowDetailRecord( entity, NextStateCode, AppUser.UserID); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); tmpDataResult.AppState = stateCode; tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END tmpDataResult.CheckState = "2"; #endregion } else { #region //添加下一状态 FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); //添加下一状态 entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); if (NextStateCode != "") { entity2.STATECODE = NextStateCode; } else { entity2.STATECODE = stateCode; } entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;// entity.StateCode; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.EDITUSERID = AppUser.UserID; entity2.EDITUSERNAME = AppUser.UserName; entity2.EDITCOMPANYID = AppUser.CompanyID; entity2.EDITDEPARTMENTID = AppUser.DepartmentID; entity2.EDITPOSTID = AppUser.PostID; entity2.CREATEDATE = DateTime.Now; entity2.EDITDATE = DateTime.Now; if (AgentUser != null) //如果启用了代理,把代理人信息写入 { entity2.AGENTUSERID = AgentUser.UserID; entity2.AGENTERNAME = AgentUser.UserName; entity2.AGENTEDITDATE = DateTime.Now; } tmpDataResult.AppState = entity2.STATECODE; fUser.NextEditUserID = entity2.EDITUSERID; fUser.NextEditUserName = entity2.EDITUSERNAME; AddFlowDetailRecord( entity2, NextStateCode, AppUser.UserID); tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; #endregion #region 更新审核主表的审核人(提莫科技新增) entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; if (entity.EDITDATE == entity.AGENTEDITDATE) { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.AGENTUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.AGENTERNAME; } else //正常审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.EDITUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.EDITUSERNAME; } entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); #endregion } tmpDataResult.IsCountersignComplete = true; return tmpDataResult; //如有下一节点,返回SUCCESS #endregion } } catch (Exception ex) { Tracer.Debug("DoFlowRecord2异常信息 :" + ex.ToString()); throw new Exception("DoFlowRecord2:" + ex.InnerException + ex.Message); } }
/// <summary> /// 更新[流程审批明细表] /// </summary> /// <param name="entity">流程审批明细表</param> /// <returns></returns> public FLOW_FLOWRECORDDETAIL_T UpdateFlowRecord2( FLOW_FLOWRECORDDETAIL_T entity) { FLOW_FLOWRECORDDETAIL_TDAL Dal = new FLOW_FLOWRECORDDETAIL_TDAL(); entity.FLAG = "1"; FLOW_FLOWRECORDDETAIL_TDAL.Update( entity); return entity; }
/// <summary> /// 新增[流程审批明细表] /// </summary> /// <param name="entity">流程审批明细表</param> /// <param name="NextStateCode">下一个状态代码</param> /// <param name="EditUserId">编辑用户ID</param> void AddFlowDetailRecord( FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, string EditUserId) { FLOW_FLOWRECORDDETAIL_TDAL.Add( entity); }
/// <summary> /// 回定流程中,会签 /// </summary> /// <param name="con"></param> /// <param name="workflowRuntime"></param> /// <param name="instance"></param> /// <param name="entity"></param> /// <param name="NextStateCode"></param> /// <param name="dictUserInfo"></param> /// <param name="dictAgentUserInfo"></param> /// <param name="SubmitFlag"></param> /// <param name="FlowType"></param> /// <returns></returns> public DataResult DoFlowRecord_Approval( WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, Dictionary<FlowRole, List<UserInfo>> dictUserInfo, Dictionary<UserInfo, UserInfo> dictAgentUserInfo, SubmitFlag SubmitFlag, FlowType FlowType) { DataResult tmpDataResult = new DataResult(); tmpDataResult.DictCounterUser = dictUserInfo; try { #region 更新流程 //如果NextStateCode为空则自动获取模型中的下一状态,如果不为空则使用传入状态代码,并使用传入下一任务人ID //更新本流程 entity = UpdateFlowRecord2( entity); string stateCode = ""; if (NextStateCode.ToUpper() == "ENDFLOW") { stateCode = NextStateCode; } else { stateCode = string.IsNullOrEmpty(NextStateCode) ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; } //string stateCode = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; tmpDataResult.AppState = stateCode; if (stateCode == "EndFlow") { entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "2"; //设为终审通过 if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.AGENTUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.AGENTERNAME; } else //正常审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.EDITUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.EDITUSERNAME; } entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowRecord2( entity); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END tmpDataResult.CheckState = "2"; } else { dictUserInfo.Values.ToList().ForEach(users => { users.ForEach(user => { #region //添加下一状态 //FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); ////添加下一状态 //entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); //entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; //entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;// entity.StateCode; ////entity2.Content = ""; //entity2.STATECODE = stateCode; //entity2.FLAG = "0"; //entity2.CHECKSTATE = "2"; //entity2.CREATEPOSTID = entity.CREATEPOSTID; //entity2.CREATECOMPANYID = entity.CREATECOMPANYID; //entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; ////if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 ////{ //// entity2.CREATEUSERID = entity.AGENTUSERID; //// entity2.CREATEUSERNAME = entity.AGENTERNAME; ////} ////else //正常审核时 ////{ //entity2.CREATEUSERID = entity.EDITUSERID; //entity2.CREATEUSERNAME = entity.EDITUSERNAME; ////} //entity2.EDITUSERID = user.UserID; //entity2.EDITUSERNAME = user.UserName; //entity2.EDITCOMPANYID = user.CompanyID; //entity2.EDITDEPARTMENTID = user.DepartmentID; //entity2.EDITPOSTID = user.PostID; //entity2.CREATEDATE = DateTime.Now; //entity2.EDITDATE = DateTime.Now; //if (dictAgentUserInfo.ContainsKey(user)) //{ // entity2.AGENTUSERID = dictAgentUserInfo[user].UserID; // entity2.AGENTERNAME = dictAgentUserInfo[user].UserName; // entity2.AGENTEDITDATE = DateTime.Now; //} //AddFlowRecord2(entity2); #endregion #region FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.STATECODE = stateCode; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.CREATEDATE = DateTime.Now; entity2.EDITUSERID = user.UserID; entity2.EDITUSERNAME = user.UserName; entity2.EDITCOMPANYID = user.CompanyID; entity2.EDITDEPARTMENTID = user.DepartmentID; entity2.EDITPOSTID = user.PostID; entity2.EDITDATE = DateTime.Now; if (dictAgentUserInfo.ContainsKey(user)) { entity2.AGENTUSERID = dictAgentUserInfo[user].UserID; entity2.AGENTERNAME = dictAgentUserInfo[user].UserName; entity2.AGENTEDITDATE = DateTime.Now; } AddFlowRecord2( entity2); #endregion }); }); tmpDataResult.AppState = stateCode; tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } tmpDataResult.IsCountersignComplete = true; return tmpDataResult; #endregion } catch (Exception ex) { Tracer.Debug("DoFlowRecord_Approval异常信息 :" + ex.ToString()); throw new Exception("DoFlowRecord_Approval:" + ex.InnerException + ex.Message); //tmpDataResult.FlowResult = FlowResult.FAIL; //tmpDataResult.Err = ex.Message; //return tmpDataResult; } }
/// <summary> /// 更新[流程审批明细表] /// </summary> /// <param name="entity">流程审批明细表</param> /// <param name="NextStateCode">下一个状态代码</param> /// <param name="EditUserId">编辑用户ID</param> /// <returns></returns> public FLOW_FLOWRECORDDETAIL_T UpdateFlowDetailRecord( FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, string EditUserId) { entity.FLAG = "1"; FLOW_FLOWRECORDDETAIL_TDAL.Update( entity); return entity; }
/// <summary> /// 会签 /// </summary> /// <param name="workflowRuntime"></param> /// <param name="instance"></param> /// <param name="entity"></param> /// <param name="NextStateCode"></param> /// <param name="dictUserInfo"></param> /// <param name="dictAgentUserInfo"></param> /// <param name="SubmitFlag"></param> /// <param name="FlowType"></param> /// <returns></returns> public DataResult DoFlowRecord_Add( WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, Dictionary<FlowRole, List<UserInfo>> dictUserInfo, Dictionary<UserInfo, UserInfo> dictAgentUserInfo, SubmitFlag SubmitFlag, FlowType FlowType) { DataResult tmpDataResult = new DataResult(); tmpDataResult.DictCounterUser = dictUserInfo; try { if (SubmitFlag == SubmitFlag.New) { #region 添加启动状态 entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; FLOW_FLOWRECORDMASTER_TDAL.Add( entity.FLOW_FLOWRECORDMASTER_T); AddFlowRecord2( entity); #endregion } else { #region //entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; entity.CHECKSTATE = "6"; entity.STATECODE = "ReSubmit"; entity.FLAG = "1"; AddFlowRecord2( entity); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); #endregion } //System.Threading.Thread.Sleep(1000); string stateCode = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; tmpDataResult.AppState = stateCode; if (stateCode != "EndFlow") { #region dictUserInfo.Values.ToList().ForEach(users => { users.ForEach(user => { #region FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.STATECODE = stateCode; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.CREATEDATE = DateTime.Now; entity2.EDITUSERID = user.UserID; entity2.EDITUSERNAME = user.UserName; entity2.EDITCOMPANYID = user.CompanyID; entity2.EDITDEPARTMENTID = user.DepartmentID; entity2.EDITPOSTID = user.PostID; entity2.EDITDATE = DateTime.Now; if (dictAgentUserInfo.ContainsKey(user)) { entity2.AGENTUSERID = dictAgentUserInfo[user].UserID; entity2.AGENTERNAME = dictAgentUserInfo[user].UserName; entity2.AGENTEDITDATE = DateTime.Now; } AddFlowRecord2( entity2); #endregion }); }); #endregion tmpDataResult.AppState = stateCode; tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.CheckState = "2"; tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END } tmpDataResult.IsCountersignComplete = true; return tmpDataResult; } catch (Exception ex) { Tracer.Debug("DoFlowRecord_Add异常信息 :" + ex.ToString()); throw new Exception("DoFlowRecord_Add:" + ex.InnerException + ex.Message); //tmpDataResult.FlowResult = FlowResult.FAIL; //tmpDataResult.Err = ex.Message; //return tmpDataResult; } }
/// <summary> /// 新增流程(对数据库操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <returns></returns> public DataResult SubmitFlow(SubmitData submitData, DataResult dataResult, ref FlowUser user) { WorkflowInstance instance = null; try { #region 获取定义的流程 user.TrackingMessage += "获取定义的流程.GetFlowByModelName:submitData.ApprovalUser.DepartmentID=" + submitData.ApprovalUser.DepartmentID + ";OrgType='" + ((int)submitData.FlowType).ToString() + "'"; List<FLOW_MODELFLOWRELATION_T> MODELFLOWRELATION = GetFlowByModelName(submitData.ApprovalUser.CompanyID, submitData.ApprovalUser.DepartmentID, submitData.ModelCode, ((int)submitData.FlowType).ToString(), ref user);//对数据库操作 if (MODELFLOWRELATION == null || MODELFLOWRELATION.Count == 0) { dataResult.FlowResult = FlowResult.FAIL; dataResult.Err = "没有找到可使用的流程"; if (submitData.ApprovalUser.CompanyID == user.CompayID && submitData.ApprovalUser.DepartmentID == user.DepartmentID) { dataResult.Err = "没有找到公司[ " + user.CompayName + " ]下部门[ " + user.DepartmentName + " ]的匹配流程返回"; } else { dataResult.Err = "没有找到公司[ " + user.CompayName + " ]的可使用匹配流程"; } return dataResult; } #endregion FLOW_MODELFLOWRELATION_T flowRelation = MODELFLOWRELATION[0];//只取其中一条流程 FLOW_FLOWDEFINE_T flowDefine = flowRelation.FLOW_FLOWDEFINE_T; user.FlowCode = flowDefine.FLOWCODE;//流程代码 user.FlowName = flowDefine.DESCRIPTION;//流程名称 if (flowDefine.RULES != null && flowDefine.RULES.Trim() == "") { flowDefine.RULES = null; } if (string.IsNullOrEmpty(flowDefine.LAYOUT)) { dataResult.Err = "公司[ " + user.CompayName + " ]的匹配流程定义为空!"; return dataResult; } workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); instance = SMTWorkFlowManage.CreateWorkflowInstance(workflowRuntime, flowDefine.LAYOUT, flowDefine.RULES); Tracer.Debug("新增 FormID=" + user.FormID + " 流程名称=" + flowDefine.DESCRIPTION + "(" + flowDefine.FLOWCODE + ") 提交人=" + user.UserName + " 公司名称=" + user.CompayName + " 部门名称=" + user.DepartmentName + " 岗位名称=" + user.PostName + " WorkflowInstance ID=" + instance.InstanceId.ToString()); #region master赋值 FLOW_FLOWRECORDMASTER_T master = new FLOW_FLOWRECORDMASTER_T(); master.INSTANCEID = instance.InstanceId.ToString(); master.BUSINESSOBJECT = submitData.XML; master.FORMID = submitData.FormID; master.MODELCODE = submitData.ModelCode; master.ACTIVEROLE = FlowUtility.GetActiveRlue(flowDefine.LAYOUT);//此字段可以保存当前节点ActivitID master.FLOWTYPE = ((int)submitData.FlowType).ToString(); master.FLOWSELECTTYPE = ((int)submitData.FlowSelectType).ToString(); master.FLOWCODE = flowDefine.FLOWCODE; #endregion #region 获取下一状态数据 user.TrackingMessage += "FORMID=" + user.FormID + "获取下一状态数据(开始)"; TmFlowToNextStep(submitData.ApprovalUser.CompanyID, flowDefine.LAYOUT, flowDefine.RULES, master.ACTIVEROLE, submitData.XML, submitData.ApprovalUser.UserID, submitData.ApprovalUser.PostID, submitData.FlowType, ref dataResult, ref user); Tracer.Debug("FormID=" + user.FormID + " 获取下一状态数据! dataResult.FlowResult=" + dataResult.FlowResult.ToString()); user.TrackingMessage += "FORMID=" + user.FormID + "获取下一状态数据(结束)"; if (dataResult.FlowResult == FlowResult.FAIL) { return dataResult; } submitData.NextStateCode = dataResult.AppState; if (dataResult.IsCountersign) { #region 检查会签是角色是否有审核人员 #region 记录日志 if (submitData.DictCounterUser != null) { Tracer.Debug("FormID=" + user.FormID + " submitData.DictCounterUser="******"FormID=" + user.FormID + " dataResult.DictCounterUser="******"FormID=" + user.FormID + " submitData.DictCounterUser 会签角色里没有发现有审核人员,所以返回!"); return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.DictCounterUser = dataResult.DictCounterUser; } } #endregion } else { #region 检查非会签角色里是否有审核人员 if (dataResult.FlowResult == FlowResult.MULTIUSER) { Tracer.Debug("FormID=" + user.FormID + " 发现有多个审核人员!"); if (submitData.NextApprovalUser == null || (FlowUtility.GetString(submitData.NextApprovalUser.UserID) == "" || FlowUtility.GetString(submitData.NextApprovalUser.UserName) == "")) { Tracer.Debug("FormID=" + user.FormID + " 发现有多个审核人员!但下一审核人为空,所以返回选择审核人!"); return dataResult; } else { Tracer.Debug("FormID=" + user.FormID + " 发现有多个审核人员,但发现下一审核人不为空 usrid=" + (FlowUtility.GetString(submitData.NextApprovalUser.UserID) + " 姓名=" + FlowUtility.GetString(submitData.NextApprovalUser.UserName))); } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.NextApprovalUser = dataResult.UserInfo[0]; } } #endregion } #endregion #region 流程明细赋值 //当提交人为空时,创建人变成单据所属人,如果不为空,则创建人保存为系统登录人;创建公司,部门,岗位,仍然保存单据所属人的公司,部门,岗位 FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = master; entity.CREATECOMPANYID = submitData.ApprovalUser.CompanyID; entity.CREATEDEPARTMENTID = submitData.ApprovalUser.DepartmentID; entity.CREATEPOSTID = submitData.ApprovalUser.PostID; entity.CREATEUSERID = string.IsNullOrEmpty(submitData.SumbitUserID) ? submitData.ApprovalUser.UserID : submitData.SumbitUserID; entity.CREATEUSERNAME = string.IsNullOrEmpty(submitData.SumbitUserName) ? submitData.ApprovalUser.UserName : submitData.SumbitUserName; #endregion #region 处理kpi时间 user.TrackingMessage += " 处理kpi时间\r\n"; string KPITime = ""; #region 加入缓存 string pscResult = CacheProvider.GetCache<string>(flowRelation.MODELFLOWRELATIONID); if (string.IsNullOrEmpty(pscResult)) { //ken 暂时屏蔽kpi //PerformanceServiceWS.PerformanceServiceClient psc = new PerformanceServiceWS.PerformanceServiceClient(); //pscResult = psc.GetKPIPointsByBusinessCode(flowRelation.MODELFLOWRELATIONID);//调用服务 //CacheProvider.Add<string>(flowRelation.MODELFLOWRELATIONID, pscResult); //psc.Close(); } #endregion //PerformanceServiceWS.PerformanceServiceClient psc = new PerformanceServiceWS.PerformanceServiceClient(); //string pscResult = psc.GetKPIPointsByBusinessCode(flowRelation.MODELFLOWRELATIONID);//调用服务 //psc.Close(); if (!string.IsNullOrEmpty(pscResult)) { XElement xe = XElement.Parse(pscResult); Func<XElement, bool> f = (x) => { XAttribute xid = x.Attribute("id"); XAttribute xvalue = x.Attribute("value"); if (xid == null || xvalue == null) return false; else { if (xid.Value == dataResult.AppState) return true; else return false; } }; XElement FlowNode = xe.Elements("FlowNode").FirstOrDefault(f); if (FlowNode != null) { KPITime = FlowNode.Attribute("value").Value; } } dataResult.KPITime = KPITime; master.KPITIMEXML = pscResult; user.TrackingMessage += " 处理kpi时间完成\r\n"; #endregion FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = submitData.XML; if (!dataResult.IsCountersign) { #region 确定非会签的下一个审核人 UserInfo AppUser = new UserInfo(); //下一审核人 AppUser = submitData.NextApprovalUser; dataResult.UserInfo.Clear(); dataResult.UserInfo.Add(AppUser); //暂时不处理代理,ken2015-7-17 UserInfo AgentAppUser = null;// GetAgentUserInfo(submitData.ModelCode, AppUser.UserID);//查询是否启用了代理人 dataResult = AddOrUpdateFlowRecord(workflowRuntime, instance, entity, submitData.NextStateCode, AppUser, AgentAppUser, submitData.SubmitFlag, submitData.FlowType, ref user); //处理流程数据 dataResult.IsCountersign = false; dataResult.AgentUserInfo = AgentAppUser; #endregion } else { user.TrackingMessage += " 会签\r\n"; #region 确定会签角色里的审核人员 //Tracer.Debug("-----DoFlowRecord_Add:" + DateTime.Now.ToString()+"\n"); dataResult.DictCounterUser = submitData.DictCounterUser; Dictionary<UserInfo, UserInfo> dictAgentUserInfo = GetAgentUserInfo2(submitData.ModelCode, submitData.DictCounterUser); dataResult = DoFlowRecord_Add(workflowRuntime, instance, entity, submitData.NextStateCode, submitData.DictCounterUser, dictAgentUserInfo, submitData.SubmitFlag, submitData.FlowType); //处理流程数据 //Tracer.Debug("-----DoFlowRecord_AddEnd:" + DateTime.Now.ToString()+"\n"); dataResult.IsCountersign = true; dataResult.DictAgentUserInfo = dictAgentUserInfo; #endregion user.TrackingMessage += "会签完成\r\n"; } user.TrackingMessage += "激发流程引擎执行到一下流程\r\n"; #region 激发流程引擎执行到一下流程 // string ss = ""; // int n = 0; // //StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); // //ManualWorkflowSchedulerService scheduleService = workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService)) as ManualWorkflowSchedulerService; //if (dataResult.AppState == null || dataResult.AppState == "") // { // user.TrackingMessage += " workflowRuntime.GetService<FlowEvent>()\r\n"; // //scheduleService.RunWorkflow(workflowinstance.InstanceId); // //workflowRuntime.GetService<FlowEvent>().OnDoFlow(instance.InstanceId, FlowData); //激发流程引擎执行到一下流程 // //scheduleService.RunWorkflow(workflowinstance.InstanceId); // user.TrackingMessage += " workflowRuntime.GetService<FlowEvent>()完成\r\n"; // } // else // { // //scheduleService.RunWorkflow(workflowinstance.InstanceId); // //workflowinstance.SetState(dataResult.AppState); //流程跳转到指定节点 // } #endregion //user.TrackingMessage += "激发流程引擎执行到一下流程完成\r\n"; //user.TrackingMessage += "System.Threading.Thread.Sleep(1000)\r\n"; //System.Threading.Thread.Sleep(1000);//当前用到 dataResult.ModelFlowRelationID = flowRelation.MODELFLOWRELATIONID; //返回关联ID dataResult.KPITime = KPITime; //dataResult.CanSendMessage = true; if (submitData.FlowType == FlowType.Task) { dataResult.SubModelCode = FlowUtility.GetSubModelCode(master.ACTIVEROLE, dataResult.AppState); //返回下一子模块代码 } //user.TrackingMessage += "System.Threading.Thread.Sleep(1000)完成\r\n"; return dataResult; } catch (Exception e) { user.ErrorMsg += "新增流程出错 FormID=" + user.FormID + " CompayName=" + user.CompayName + "FlowName=" + user.FlowName + "异常信息:\r\n" + e.ToString() + "\r\n"; Tracer.Debug("FormID=" + user.FormID + " CompayName=" + user.CompayName + "FlowName=" + user.FlowName + " 新增流程出错,异常信息:\r\n" + e.ToString()); throw new Exception("FormID=" + user.FormID + " 时间:" + DateTime.Now.ToString() + " 新增流程出错,请联系管理员! "); } finally { instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
public DataResult CancelFlow(SubmitData submitData, DataResult dataResult, List<FLOW_FLOWRECORDDETAIL_T> fd) { //WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); #region entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity.CREATECOMPANYID = submitData.ApprovalUser.CompanyID; entity.CREATEDEPARTMENTID = submitData.ApprovalUser.DepartmentID; entity.CREATEPOSTID = submitData.ApprovalUser.PostID; entity.CREATEUSERID = submitData.ApprovalUser.UserID; entity.CREATEUSERNAME = submitData.ApprovalUser.UserName; entity.EDITDATE = DateTime.Now; entity.CONTENT = submitData.ApprovalContent; entity.CHECKSTATE = "9"; entity.STATECODE = "Cancel"; entity.FLAG = "1"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T = fd[0].FLOW_FLOWRECORDMASTER_T; entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T.Add(entity); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "9"; //设为撤销 entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = submitData.ApprovalUser.UserID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = submitData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; #endregion workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); Tracer.Debug("CancelFlow从持久化库在恢复创建工作流实例ID=" + entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID); instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID); instance.Terminate("0"); FLOW_FLOWRECORDDETAIL_TDAL Dal = new FLOW_FLOWRECORDDETAIL_TDAL(); entity.FLAG = "1"; //Dal.AddFlowRecord(entity); FLOW_FLOWRECORDDETAIL_TDAL.Add(entity); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); fd.Where(detail => detail.FLAG == "0").ToList().ForEach(item => { //Dal.Delete(item); //Dal.DeleteFlowRecord(item); FLOW_FLOWRECORDDETAIL_TDAL.Delete(item); }); dataResult.CheckState = "9";// dataResult.FlowResult = FlowResult.SUCCESS; return dataResult; }
/// <summary> /// 删除[流程审批明细表] /// </summary> /// <param name="con">//OracleConnection连接对象</param> /// <param name="detail">流程审批明细表</param> public static int Delete( FLOW_FLOWRECORDDETAIL_T detail) { try { string delSql = "DELETE FROM FLOW_FLOWRECORDDETAIL_T WHERE FLOWRECORDDETAILID=@FLOWRECORDDETAILID"; Parameter[] pageparm = { new Parameter("@FLOWRECORDDETAILID") }; pageparm[0].ParameterValue = detail.FLOWRECORDDETAILID; return dao.ExecuteNonQuery(delSql, pageparm); } catch (Exception ex) { Tracer.Debug("FLOW_FLOWRECORDDETAIL_TDAL->Delete:FLOWRECORDDETAILID=" + detail.FLOWRECORDDETAILID +";时间:" + DateTime.Now.ToString() + "\r\n异常信息:" + ex.Message); throw new Exception("FLOW_FLOWRECORDDETAIL_TDAL->Delete:" + ex.Message); } }
/// <summary> /// 新增[流程审批明细表] /// </summary> /// <param name="entity">流程审批明细表</param> void AddFlowRecord2( FLOW_FLOWRECORDDETAIL_T entity) { FLOW_FLOWRECORDDETAIL_TDAL.Add( entity); }
public static List<FLOW_FLOWRECORDMASTER_T> GetFlowRecordBySubmitUserID(string CheckState, string EditUserID) { List<FLOW_FLOWRECORDMASTER_T> listMaster = new List<FLOW_FLOWRECORDMASTER_T>(); List<string> listMasterID = new List<string>(); IDataReader dr = null; try { StringBuilder sbMaster = new StringBuilder(); sbMaster.Append(@"select FLOWRECORDMASTERID,INSTANCEID,MODELCODE,FLOWCODE, FORMID,CHECKSTATE,CREATEUSERID,CREATEUSERNAME,CREATECOMPANYID,CREATEDEPARTMENTID,CREATEPOSTID, CREATEDATE,EDITUSERID,EDITUSERNAME,EDITDATE,FLOWTYPE,FLOWSELECTTYPE from FLOW_FLOWRECORDMASTER_T where 1=1 "); if (!string.IsNullOrEmpty(EditUserID)) { sbMaster.Append(" and CREATEUSERID='" + EditUserID + "'"); } if (!string.IsNullOrEmpty(CheckState)) { sbMaster.Append(" and CHECKSTATE='" + CheckState + "'"); } #region ////OracleCommand cmd = con.CreateCommand(); ////cmd.CommandText = sbMaster.ToString(); //dr = cmd.ExecuteReader(); dr = dao.ExecuteReader(sbMaster.ToString()); while (dr.Read()) { #region master FLOW_FLOWRECORDMASTER_T master = new FLOW_FLOWRECORDMASTER_T(); //master.ACTIVEROLE = dr["ACTIVEROLE"] == DBNull.Value ? null : dr["ACTIVEROLE"].ToString(); //master.BUSINESSOBJECT = dr["BUSINESSOBJECT"] == DBNull.Value ? null : dr["BUSINESSOBJECT"].ToString(); master.CHECKSTATE = dr["CHECKSTATE"] == DBNull.Value ? null : dr["CHECKSTATE"].ToString(); master.CREATECOMPANYID = dr["CREATECOMPANYID"] == DBNull.Value ? null : dr["CREATECOMPANYID"].ToString(); master.CREATEDATE = (DateTime)dr["CREATEDATE"]; master.CREATEDEPARTMENTID = dr["CREATEDEPARTMENTID"] == DBNull.Value ? null : dr["CREATEDEPARTMENTID"].ToString(); master.CREATEPOSTID = dr["CREATEPOSTID"] == DBNull.Value ? null : dr["CREATEPOSTID"].ToString(); master.CREATEUSERID = dr["CREATEUSERID"] == DBNull.Value ? null : dr["CREATEUSERID"].ToString(); master.CREATEUSERNAME = dr["CREATEUSERNAME"] == DBNull.Value ? null : dr["CREATEUSERNAME"].ToString(); master.EDITDATE = dr["EDITDATE"] == DBNull.Value ? null : (DateTime?)dr["EDITDATE"]; master.EDITUSERID = dr["EDITUSERID"] == DBNull.Value ? null : dr["EDITUSERID"].ToString(); master.EDITUSERNAME = dr["EDITUSERNAME"] == DBNull.Value ? null : dr["EDITUSERNAME"].ToString(); master.FLOWCODE = dr["FLOWCODE"] == DBNull.Value ? null : dr["FLOWCODE"].ToString(); master.FLOWRECORDMASTERID = dr["FLOWRECORDMASTERID"].ToString(); master.FLOWSELECTTYPE = dr["FLOWSELECTTYPE"] == DBNull.Value ? null : dr["FLOWSELECTTYPE"].ToString(); master.FLOWTYPE = dr["FLOWTYPE"] == DBNull.Value ? null : dr["FLOWTYPE"].ToString(); master.FORMID = dr["FORMID"] == DBNull.Value ? null : dr["FORMID"].ToString(); master.INSTANCEID = dr["INSTANCEID"] == DBNull.Value ? null : dr["INSTANCEID"].ToString(); //master.KPITIMEXML = dr["KPITIMEXML"] == DBNull.Value ? null : dr["KPITIMEXML"].ToString(); master.MODELCODE = dr["MODELCODE"] == DBNull.Value ? null : dr["MODELCODE"].ToString(); master.FLOW_FLOWRECORDDETAIL_T = new EntityCollection<FLOW_FLOWRECORDDETAIL_T>(); listMaster.Add(master); listMasterID.Add("'" + master.FLOWRECORDMASTERID + "'"); #endregion } dr.Close(); if (listMasterID.Count > 0) { #region detail string sql = @"select * from FLOW_FLOWRECORDDETAIL_T where FLOWRECORDMASTERID in (" + string.Join(",", listMasterID.ToArray()) + ")"; //dr = cmd.ExecuteReader(); dr = dao.ExecuteReader(sql); while (dr.Read()) { #region detail FLOW_FLOWRECORDDETAIL_T detail = new FLOW_FLOWRECORDDETAIL_T(); detail.FLOW_FLOWRECORDMASTER_T = listMaster.FirstOrDefault(m => m.FLOWRECORDMASTERID == dr["FLOWRECORDMASTERID"].ToString()); detail.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T.Add(detail); detail.AGENTEDITDATE = dr["AGENTEDITDATE"] == DBNull.Value ? null : (DateTime?)dr["AGENTEDITDATE"]; detail.AGENTERNAME = dr["AGENTERNAME"] == DBNull.Value ? null : dr["AGENTERNAME"].ToString(); detail.AGENTUSERID = dr["AGENTUSERID"] == DBNull.Value ? null : dr["AGENTUSERID"].ToString(); detail.CHECKSTATE = dr["CHECKSTATE"] == DBNull.Value ? null : dr["CHECKSTATE"].ToString(); detail.CONTENT = dr["CONTENT"] == DBNull.Value ? null : dr["CONTENT"].ToString(); detail.CREATECOMPANYID = dr["CREATECOMPANYID"] == DBNull.Value ? null : dr["CREATECOMPANYID"].ToString(); detail.CREATEDATE = (DateTime)dr["CREATEDATE"]; detail.CREATEDEPARTMENTID = dr["CREATEDEPARTMENTID"] == DBNull.Value ? null : dr["CREATEDEPARTMENTID"].ToString(); detail.CREATEPOSTID = dr["CREATEPOSTID"] == DBNull.Value ? null : dr["CREATEPOSTID"].ToString(); detail.CREATEUSERID = dr["CREATEUSERID"] == DBNull.Value ? null : dr["CREATEUSERID"].ToString(); detail.CREATEUSERNAME = dr["CREATEUSERNAME"] == DBNull.Value ? null : dr["CREATEUSERNAME"].ToString(); detail.EDITCOMPANYID = dr["EDITCOMPANYID"] == DBNull.Value ? null : dr["EDITCOMPANYID"].ToString(); detail.EDITDATE = dr["EDITDATE"] == DBNull.Value ? null : (DateTime?)dr["EDITDATE"]; detail.EDITDEPARTMENTID = dr["EDITDEPARTMENTID"] == DBNull.Value ? null : dr["EDITDEPARTMENTID"].ToString(); detail.EDITPOSTID = dr["EDITPOSTID"] == DBNull.Value ? null : dr["EDITPOSTID"].ToString(); detail.EDITUSERID = dr["EDITUSERID"] == DBNull.Value ? null : dr["EDITUSERID"].ToString(); detail.EDITUSERNAME = dr["EDITUSERNAME"] == DBNull.Value ? null : dr["EDITUSERNAME"].ToString(); detail.FLAG = dr["FLAG"] == DBNull.Value ? null : dr["FLAG"].ToString(); //detail.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = dr["FLOWRECORDMASTERID"].ToString(); detail.FLOWRECORDDETAILID = dr["FLOWRECORDDETAILID"] == DBNull.Value ? null : dr["FLOWRECORDDETAILID"].ToString(); detail.PARENTSTATEID = dr["PARENTSTATEID"] == DBNull.Value ? null : dr["PARENTSTATEID"].ToString(); detail.STATECODE = dr["STATECODE"] == DBNull.Value ? null : dr["STATECODE"].ToString(); #endregion } dr.Close(); #endregion } return listMaster; #endregion } catch (Exception ex) { if (dr != null && !dr.IsClosed) { dr.Close(); } throw ex; } }
public string UpdateFlow(FLOW_FLOWRECORDDETAIL_T entity) { //OracleConnection con = ADOHelper.GetOracleConnection(); SMT.FlowWFService.NewFlow.FlowService s2 = new SMT.FlowWFService.NewFlow.FlowService(); return s2.UpdateFlow( entity); #region 旧代码 //FlowBLL bll = new FlowBLL(); //bll.UpdateFlowRecord(entity, "", ""); //return ""; #endregion }