/// <summary> /// 初始化流程定义 /// </summary> private void InitFLDefinition() { Activity wfActivity = GetActivityByXoml(FLDefinitionFile, _flRulesFile); IFLRootActivity rootActivity = null; // FLActivity if (wfActivity is IFLRootActivity) { rootActivity = new FLRootActivity(); InitFLActivities((IFLActivity)rootActivity, wfActivity); } else { String message = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "ErrorInXoml"); throw new FLException(message); } _rootFLActivity = (FLRootActivity)rootActivity; _flDefinition = (FLActivity)rootActivity; CheckFL(); //if (_rootFLActivity.GetFLActivitiesByType(typeof(FLParallelActivity)).Count != 0) //{ // _isSupportRetake = false; //} //else //{ // _isSupportRetake = true; //} }
/// <summary> /// 修改流程定义 /// </summary> /// <param name="flDefinitionFile">流程XOML文件</param> /// <param name="flRulesFile">流程规则文件</param> public void ModifyFLDefinition(string flDefinitionFile, string flRulesFile) { //Assembly assembly = Assembly.LoadFrom(EEPRegistry.Server + "\\" + dllName); //Type type = assembly.GetType(className); //MethodInfo method = type.GetMethod(methodName); //object obj = method.Invoke(null, new object[] { _flDefinitionFile, _flRulesFile }); //Activity wfActivity = (Activity)obj; Activity wfActivity = FLInstance.GetWorkflowDefinition(flDefinitionFile, flRulesFile); IFLRootActivity tempRootActivity = null; // FLActivity if (wfActivity is IFLRootActivity) { tempRootActivity = new FLRootActivity(); InitFLActivities((IFLActivity)tempRootActivity, wfActivity); } else { String message = SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "ErrorInXoml"); throw new FLException(message); } ICollection keys = _rootFLActivity.GetAllChildFLActivities().Keys; foreach (object obj1 in keys) { FLActivity a0 = _rootFLActivity.GetFLActivityByName(obj1.ToString()); FLActivity a1 = ((FLRootActivity)tempRootActivity).GetFLActivityByName(obj1.ToString()); if (a0 != null && a1 != null && a0.GetType() == a1.GetType()) { InitFLActivities2(a0, a1); } } _flDefinition = _rootFLActivity; CheckFL(); //if (_rootFLActivity.GetFLActivitiesByType(typeof(FLParallelActivity)).Count != 0) //{ // _isSupportRetake = false; //} //else //{ // _isSupportRetake = true; //} InitFLDefinitionXmlString(); }
/// <summary> /// 取得下一Activity的集合 /// </summary> /// <param name="currentFLActivity">当前Activity</param> /// <param name="nextFLActivities">下一Activity的集合</param> private void GetNextFLActivities(FLActivity currentFLActivity, List<FLActivity> nextFLActivities) { SetUpperParallel(currentFLActivity); SetLocation(currentFLActivity); if (_isFirstInParallel && ((_tempParallel != currentFLActivity.UpperParallel) || (_tempParallelBranch != currentFLActivity.UpperParallelBranch))) { return; } if (currentFLActivity is IFLNotifyActivity || currentFLActivity is IFLProcedureActivity) { if (!nextFLActivities.Exists( delegate(FLActivity flActivity) { if (currentFLActivity.Name == flActivity.Name) return true; else return false; } ) && currentFLActivity.Enabled) { if (currentFLActivity is IFLProcedureActivity && !preview) { Logic.CallServerMethod(this, FLInstanceParms, this._keyValues, this._clientInfo, currentFLActivity as IFLProcedureActivity); } nextFLActivities.Add(currentFLActivity); } } if (currentFLActivity is IFLRejectActivity && currentFLActivity.Enabled) { nextFLActivities.Clear(); nextFLActivities.Add(currentFLActivity); return; } if (currentFLActivity is IFLGotoActivity && currentFLActivity.Enabled) { nextFLActivities.Clear(); nextFLActivities.Add(currentFLActivity); return; } if (currentFLActivity is IFLValidateActivity) { if (!nextFLActivities.Exists( delegate(FLActivity flActivity) { if (currentFLActivity.Name == flActivity.Name) return true; else return false; } ) && currentFLActivity.Enabled && !preview) { nextFLActivities.Add(currentFLActivity); if (!JudgeCondition(((IFLValidateActivity)currentFLActivity).Expression)) { _v = false; _vN = currentFLActivity.Name; VM = ((IFLValidateActivity)currentFLActivity).Message; return; //String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "ValidateFail"), currentFLActivity.Name); //throw new FLException(2, message); } } } FLActivity activity = null; if ((currentFLActivity is IFLApproveActivity && currentFLActivity.ExecutionStatus != FLActivityExecutionStatus.Executed) || currentFLActivity is IFLApproveBranchActivity) { #region List<FLActivity> approveRights; FLActivity approveActivity = null; if (currentFLActivity is IFLApproveActivity) { approveRights = currentFLActivity.ChildFLActivities; approveActivity = currentFLActivity; } else { approveActivity = _rootFLActivity.GetFLActivityByName(((IFLApproveBranchActivity)currentFLActivity).ParentActivity); approveRights = approveActivity.ChildFLActivities; } string roleId = string.Empty; string orgKind = ((IFLRootActivity)_rootFLActivity).OrgKind; if (((IEventWaiting)approveActivity).SendToKind == SendToKind.Manager || ((FLApproveActivity)approveActivity).I > 0) // Manager或者RefManager第一次进 { roleId = ((IEventWaitingExecute)_sendFromFLActivity).RoleId; } else if (((IEventWaiting)approveActivity).SendToKind == SendToKind.RefManager) // RefManager第二次进 { string sendToField = ((IEventWaiting)approveActivity).SendToField; string values = _keyValues[1].ToString(); string tableName = _rootFLActivity.TableName; string qq = Global.GetRoleIdByRefRole(this, sendToField, tableName, values, _clientInfo); roleId = qq;//Global.GetManagerRoleId(qq.ToString(), orgKind, _clientInfo); } else if (((IEventWaiting)approveActivity).SendToKind == SendToKind.ApplicateManager) { if (!string.IsNullOrEmpty(this.CreateRole)) { roleId = this.CreateRole; } else { string user = this.Creator; List<string> roles = Global.GetRoleIdsByUserId(user, _clientInfo); if (roles.Count > 0) { roleId = roles[0]; } } } if (((IEventWaiting)approveActivity).SendToKind == SendToKind.Manager && string.IsNullOrEmpty(roleId)) { if (preview) { return; } else { String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "InstanceManager", "UserNotHaveRole"), ((IEventWaitingExecute)_sendFromFLActivity).UserId); throw new FLException(2, message); } } bool b = false; string levelNo = Global.GetLevelNo(roleId, orgKind, _clientInfo); if (!string.IsNullOrEmpty(levelNo)) { List<string> gRoleIds = new List<string>(); foreach (FLActivity a in approveRights) { gRoleIds.Clear(); if (JudgeCondition(((IFLApproveBranchActivity)a).Expression)) { string grade = string.Empty; string name = string.Empty; string roleId2 = roleId; string roleId3 = string.Empty; bool bb = true; do { roleId3 = roleId2; grade = Global.GetManagerLevelNo(roleId3, orgKind, _clientInfo); if (string.IsNullOrEmpty(grade)) { bb = false; break; } name = approveActivity.Name + "-" + grade; roleId2 = Global.GetManagerRoleId(roleId3, orgKind, _clientInfo); if (gRoleIds.Contains(roleId2)) { String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "InstanceManager", "UserManagerIsCircle"), roleId2); throw new FLException(2, message); } if (roleId2 == roleId3) { String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "InstanceManager", "UserManagerCanNotBeYouself"), roleId2); throw new FLException(2, message); } gRoleIds.Add(roleId2); } while (!(name == a.Name || (((FLApproveActivity)approveActivity).I == 0 && a.Name == approveActivity.Name + "-0"))); if (!bb) { continue; } _r = roleId3; if (approveRights.IndexOf(a) == approveRights.Count - 1 && currentFLActivity.Name == name) // add by andy { break; } SetUpperParallel(a); SetLocation(a); nextFLActivities.Add(a); b = true; approveActivity.Execute(); ((FLApproveActivity)approveActivity).I++; break; } } } if (!b) { approveActivity.Execute(); GetNextFLActivities(approveActivity, nextFLActivities); } #endregion } else if (currentFLActivity is IFLDetailsActivity && currentFLActivity.ExecutionStatus != FLActivityExecutionStatus.Executed) { #region IFLDetailsActivity detailsActivity = (IFLDetailsActivity)currentFLActivity; if (_hostDataSet == null) { _hostDataSet = HostTable.GetHostDataSet(this, _keyValues, _clientInfo); } currentFLActivity.ClearActivities(); FLActivity childActivity = null; if (!string.IsNullOrEmpty(detailsActivity.ExtApproveID)) { childActivity = new FLSequenceActivity(); DataRow hostRow = _hostDataSet.Tables[0].Rows[0]; string groupID = hostRow[detailsActivity.ExtGroupField].ToString(); object value = hostRow[detailsActivity.ExtValueField]; List<string> roles = Global.GetExtApproveRoles(detailsActivity.ExtApproveID, groupID, value, _clientInfo); for (int i = 0; i < roles.Count; i++) { FLStandActivity stand = new FLStandActivity(); stand.Name = detailsActivity.Name + "_" + i.ToString(); childActivity.AddFLActivity(stand); stand.Description = ((IFLDetailsActivity)detailsActivity).Description; stand.Enabled = ((IFLDetailsActivity)detailsActivity).Enabled; stand.ExpTime = ((IFLDetailsActivity)detailsActivity).ExpTime; stand.FLNavigatorMode = ((IFLDetailsActivity)detailsActivity).FLNavigatorMode; stand.FormName = ((IFLDetailsActivity)detailsActivity).FormName; stand.WebFormName = ((IFLDetailsActivity)detailsActivity).WebFormName; stand.NavigatorMode = ((IFLDetailsActivity)detailsActivity).NavigatorMode; stand.Parameters = ((IFLDetailsActivity)detailsActivity).Parameters; stand.SendToField = ((IFLDetailsActivity)detailsActivity).SendToField; stand.SendToKind = ((IFLDetailsActivity)detailsActivity).SendToKind; stand.SendToRole = ((IFLDetailsActivity)detailsActivity).SendToRole; stand.SendToUser = ((IFLDetailsActivity)detailsActivity).SendToUser; stand.TimeUnit = ((IFLDetailsActivity)detailsActivity).TimeUnit; stand.UrgentTime = ((IFLDetailsActivity)detailsActivity).UrgentTime; stand.SendEmail = ((IFLDetailsActivity)detailsActivity).SendEmail; stand.PlusApprove = ((IFLDetailsActivity)detailsActivity).PlusApprove; stand.PlusApproveReturn = ((IFLDetailsActivity)detailsActivity).PlusApproveReturn; stand.AllowSendBack = ((IFLDetailsActivity)detailsActivity).AllowSendBack; ((ISupportFLDetailsActivity)stand).SendToId2 = roles[i]; } if (childActivity.ChildFLActivities.Count > 0) //当有子activity时才加入 { ((FLActivity)detailsActivity).AddFLActivity(childActivity); } } else if (!string.IsNullOrEmpty(detailsActivity.SendToMasterField)) { #region DataRow hostRow = _hostDataSet.Tables[0].Rows[0]; string ids = string.Empty; if (hostRow.Table.Columns.Contains(detailsActivity.SendToMasterField)) { //String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "TableNotExistColumn"), _rootFLActivity.TableName, detailsActivity.SendToMasterField); //throw new FLException(2, message); object obj = hostRow[detailsActivity.SendToMasterField]; if (obj != null && obj != DBNull.Value && !string.IsNullOrEmpty(obj.ToString())) { //String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "SendToFieldValueIsNull"), _rootFLActivity.TableName, detailsActivity.SendToMasterField); //throw new FLException(2, message); ids = obj.ToString(); } } if (detailsActivity.ParallelMode == ParallelMode.And || detailsActivity.ParallelMode == ParallelMode.Or) { childActivity = new FLParallelActivity(); childActivity.Description = (detailsActivity.ParallelMode == ParallelMode.And && detailsActivity.ParallelRate > 0) ? string.Format("rate:{0}", detailsActivity.ParallelRate) : detailsActivity.ParallelMode.ToString(); childActivity.Name = detailsActivity.Name + "_p1"; } else { childActivity = new FLSequenceActivity(); childActivity.Name = detailsActivity.Name + "_se1"; } int i0 = 0; string[] sendToIds = ids.ToString().Split(",".ToCharArray()); foreach (string sendToId in sendToIds) { if (string.IsNullOrEmpty(sendToId)) { continue; } FLStandActivity stand = new FLStandActivity(); stand.Name = detailsActivity.Name + "_" + i0.ToString(); i0++; if (detailsActivity.ParallelMode == ParallelMode.And || detailsActivity.ParallelMode == ParallelMode.Or) { FLSequenceActivity sequenceActivity = new FLSequenceActivity(); sequenceActivity.Name = detailsActivity.Name + "_se" + i0.ToString(); sequenceActivity.AddFLActivity(stand); childActivity.AddFLActivity(sequenceActivity); } else { childActivity.AddFLActivity(stand); } stand.Description = ((IFLDetailsActivity)detailsActivity).Description; stand.Enabled = ((IFLDetailsActivity)detailsActivity).Enabled; stand.ExpTime = ((IFLDetailsActivity)detailsActivity).ExpTime; stand.FLNavigatorMode = ((IFLDetailsActivity)detailsActivity).FLNavigatorMode; stand.FormName = ((IFLDetailsActivity)detailsActivity).FormName; stand.WebFormName = ((IFLDetailsActivity)detailsActivity).WebFormName; stand.NavigatorMode = ((IFLDetailsActivity)detailsActivity).NavigatorMode; stand.Parameters = ((IFLDetailsActivity)detailsActivity).Parameters; stand.SendToField = ((IFLDetailsActivity)detailsActivity).SendToField; stand.SendToKind = ((IFLDetailsActivity)detailsActivity).SendToKind; stand.SendToRole = ((IFLDetailsActivity)detailsActivity).SendToRole; stand.SendToUser = ((IFLDetailsActivity)detailsActivity).SendToUser; stand.TimeUnit = ((IFLDetailsActivity)detailsActivity).TimeUnit; stand.UrgentTime = ((IFLDetailsActivity)detailsActivity).UrgentTime; stand.SendEmail = ((IFLDetailsActivity)detailsActivity).SendEmail; stand.PlusApprove = ((IFLDetailsActivity)detailsActivity).PlusApprove; stand.PlusApproveReturn = ((IFLDetailsActivity)detailsActivity).PlusApproveReturn; stand.AllowSendBack = ((IFLDetailsActivity)detailsActivity).AllowSendBack; // ((ISupportFLDetailsActivity)stand).SendToId2 = sendToId; if (((IFLDetailsActivity)detailsActivity).SendToKind == SendToKind.RefRole) { stand.SendToKind = SendToKind.Role; stand.SendToRole = sendToId; } else if (((IFLDetailsActivity)detailsActivity).SendToKind == SendToKind.RefUser) { stand.SendToKind = SendToKind.User; stand.SendToUser = sendToId; } } if (childActivity.ChildFLActivities.Count > 0) //当有子activity时才加入 { ((FLActivity)detailsActivity).AddFLActivity(childActivity); } #endregion } else { #region Activity temp = FLInstance.GetActivityByXoml(this.FLDefinitionFile, string.Empty); IFLRootActivity rootActivity = (IFLRootActivity)temp; DataSet detailsDataSet = HostTable.GetDetailsDataSet(this, _hostDataSet, rootActivity.Keys, detailsActivity.DetailsTableName, detailsActivity.RelationKeys, _clientInfo); string parallelField = detailsActivity.ParallelField; string sendToField = detailsActivity.SendToField; Dictionary<string, FLSequenceActivity> sequenceActivities = new Dictionary<string, FLSequenceActivity>(); // for y1,y2,y3 if (detailsDataSet != null && detailsDataSet.Tables.Count != 0 && detailsDataSet.Tables[0].Rows.Count != 0) { int i0 = 1; int i1 = 1; int i2 = 1; foreach (DataRow row in detailsDataSet.Tables[0].Rows) { FLStandActivity stand = new FLStandActivity(); //stand.Name = n.Name + "_s" + i0.ToString(); stand.Name = detailsActivity.Name + "_" + i0.ToString(); i0++; stand.Description = ((IFLDetailsActivity)detailsActivity).Description; stand.Enabled = ((IFLDetailsActivity)detailsActivity).Enabled; stand.ExpTime = ((IFLDetailsActivity)detailsActivity).ExpTime; stand.FLNavigatorMode = ((IFLDetailsActivity)detailsActivity).FLNavigatorMode; stand.FormName = ((IFLDetailsActivity)detailsActivity).FormName; stand.WebFormName = ((IFLDetailsActivity)detailsActivity).WebFormName; stand.NavigatorMode = ((IFLDetailsActivity)detailsActivity).NavigatorMode; stand.Parameters = ((IFLDetailsActivity)detailsActivity).Parameters; stand.SendToField = ((IFLDetailsActivity)detailsActivity).SendToField; stand.SendToKind = ((IFLDetailsActivity)detailsActivity).SendToKind; stand.SendToRole = ((IFLDetailsActivity)detailsActivity).SendToRole; stand.SendToUser = ((IFLDetailsActivity)detailsActivity).SendToUser; stand.TimeUnit = ((IFLDetailsActivity)detailsActivity).TimeUnit; stand.UrgentTime = ((IFLDetailsActivity)detailsActivity).UrgentTime; stand.SendEmail = ((IFLDetailsActivity)detailsActivity).SendEmail; stand.PlusApprove = ((IFLDetailsActivity)detailsActivity).PlusApprove; stand.PlusApproveReturn = ((IFLDetailsActivity)detailsActivity).PlusApproveReturn; stand.AllowSendBack = ((IFLDetailsActivity)detailsActivity).AllowSendBack; if (!string.IsNullOrEmpty(detailsActivity.FLNavigatorField)) { object flNavigatorMode = row[detailsActivity.FLNavigatorField]; if (flNavigatorMode != null) { if (string.Compare(flNavigatorMode.ToString(), "Continue", true) == 0) { stand.FLNavigatorMode = FLNavigatorMode.Continue; } } } object sendToId2 = row[sendToField]; if (sendToId2 == null || sendToId2 == DBNull.Value || sendToId2.ToString() == string.Empty) { continue; //String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "SendToFieldValueIsNull"), n.DetailsTableName); //throw new FLException(message); } //((ISupportFLDetailsActivity)stand).SendToId2 = sendToId2.ToString(); if (((IFLDetailsActivity)detailsActivity).SendToKind == SendToKind.RefRole) { stand.SendToKind = SendToKind.Role; stand.SendToRole = sendToId2.ToString(); } else if (((IFLDetailsActivity)detailsActivity).SendToKind == SendToKind.RefUser) { stand.SendToKind = SendToKind.User; stand.SendToUser = sendToId2.ToString(); } if (!string.IsNullOrEmpty(parallelField)) { object isParallel = row[parallelField]; if ((isParallel != null && isParallel != DBNull.Value) && (isParallel.ToString().Trim().ToLower() == "y" || isParallel.ToString().Trim().ToLower() == "and")) { if (childActivity == null) { childActivity = new FLParallelActivity(); childActivity.Description = detailsActivity.ParallelRate > 0 ? string.Format("rate:{0}", detailsActivity.ParallelRate) : "and"; childActivity.Name = detailsActivity.Name + "_p" + i2.ToString(); i2++; ((FLActivity)detailsActivity).AddFLActivity(childActivity); } FLSequenceActivity sequenceActivity = new FLSequenceActivity(); sequenceActivity.Name = detailsActivity.Name + "_se" + i1.ToString(); i1++; ((FLActivity)childActivity).AddFLActivity(sequenceActivity); ((FLActivity)sequenceActivity).AddFLActivity(stand); } else if ((isParallel != null && isParallel != DBNull.Value) && (isParallel.ToString().Trim().ToLower().StartsWith("y"))) { if (childActivity == null) { childActivity = new FLParallelActivity(); childActivity.Description = "and"; childActivity.Name = detailsActivity.Name + "_p" + i2.ToString(); i2++; ((FLActivity)detailsActivity).AddFLActivity(childActivity); } FLSequenceActivity sequenceActivity = null; if(sequenceActivities.ContainsKey(isParallel.ToString())) { sequenceActivity = sequenceActivities[isParallel.ToString()]; } if (sequenceActivity == null) { sequenceActivity = new FLSequenceActivity(); sequenceActivity.Name = detailsActivity.Name + "_se" + i1.ToString(); i1++; ((FLActivity)childActivity).AddFLActivity(sequenceActivity); sequenceActivities[isParallel.ToString()] = sequenceActivity; } sequenceActivity.AddFLActivity(stand); } //修改n值时会串签 //else if ((isParallel != null && isParallel != DBNull.Value) && // (isParallel.ToString().Trim().ToLower() == "n" || isParallel.ToString().Trim().ToLower() == "or")) //{ // if (childActivity == null) // { // childActivity = new FLParallelActivity(); // childActivity.Description = "Or"; // childActivity.Name = detailsActivity.Name + "_p" + i2.ToString(); // i2++; // ((FLActivity)detailsActivity).AddFLActivity(childActivity); // } // FLSequenceActivity sequenceActivity = new FLSequenceActivity(); // sequenceActivity.Name = detailsActivity.Name + "_se" + i1.ToString(); // i1++; // ((FLActivity)childActivity).AddFLActivity(sequenceActivity); // ((FLActivity)sequenceActivity).AddFLActivity(stand); //} else { childActivity = null; ((FLActivity)detailsActivity).AddFLActivity(stand); } } else { childActivity = null; ((FLActivity)detailsActivity).AddFLActivity(stand); } } } #endregion } XmlSerializer serializer = CreateXmlSerializer(typeof(FLDetailsActivity)); StringBuilder builder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(builder); serializer.Serialize(writer, detailsActivity); XmlDocument doc = new XmlDocument(); doc.LoadXml(builder.ToString()); XmlNode nodeDetails = doc.SelectSingleNode(string.Format("FLDetailsActivity[@Name='{0}']", detailsActivity.Name)); XmlNode nodeOldDetails = (XmlNode)_flDefinitionXmlNodes[detailsActivity.Name]; nodeOldDetails.InnerXml = nodeDetails.InnerXml; InitFLDefinitionXmlNodes(nodeOldDetails); _flDefinitionXmlString = nodeOldDetails.OwnerDocument.InnerXml; ((FLActivity)detailsActivity).Execute(); Hashtable childAll = ((FLActivity)detailsActivity).GetAllChildFLActivities(); foreach (string key in childAll.Keys) { _setUpperParallels.Remove(key); } foreach (string key in childAll.Keys) { _setLocations.Remove(key); } SetUpperParallel((FLActivity)detailsActivity); SetLocation((FLActivity)detailsActivity); if (((FLActivity)detailsActivity).ChildFLActivities.Count == 0) { GetNextFLActivities((FLActivity)detailsActivity, nextFLActivities); //当detailsActivity没有任何人需要签核时, 撤消detailsActivity状态,不然退回后再也无法进入detailsActivity ((FLActivity)detailsActivity).InitExecStatus(); } else { if (((FLActivity)detailsActivity).ChildFLActivities[0] is FLStandActivity) { SetUpperParallel(((FLActivity)detailsActivity).ChildFLActivities[0]); SetLocation(((FLActivity)detailsActivity).ChildFLActivities[0]); nextFLActivities.Add(((FLActivity)detailsActivity).ChildFLActivities[0]); } else { GetNextFLActivities(((FLActivity)detailsActivity).ChildFLActivities[0], nextFLActivities); } } #endregion } else if (currentFLActivity is IFLSubFlowActivity && currentFLActivity.ExecutionStatus != FLActivityExecutionStatus.Executed) { IFLSubFlowActivity subflow = currentFLActivity as IFLSubFlowActivity; ((FLActivity)subflow).ChildFLActivities.Clear(); string xomlName = subflow.XomlName; if (_hostDataSet == null) { _hostDataSet = HostTable.GetHostDataSet(this, _keyValues, _clientInfo); } DataRow hostRow = _hostDataSet.Tables[0].Rows[0]; if (!string.IsNullOrEmpty(subflow.XomlField) && hostRow.Table.Columns.Contains(subflow.XomlField)) { object obj = hostRow[subflow.XomlField]; if (obj != null && obj != DBNull.Value && !string.IsNullOrEmpty(obj.ToString())) { xomlName = obj.ToString(); } } if (!string.IsNullOrEmpty(xomlName)) { FLRootActivity subflowRoot = new FLRootActivity(); FileInfo fileInfo = new FileInfo(this.FLDefinitionFile); string file = fileInfo.Directory + @"\" + xomlName; if (!File.Exists(file)) { file = fileInfo.Directory + @"\SubFlows\" + xomlName; } Activity subflowDefniation = GetActivityByXoml(file, string.Empty); InitFLActivities(subflowRoot, subflowDefniation); for (int i = 0; i < subflowRoot.ChildFLActivities.Count; i++) { if (i == 0 && !subflow.IncludeFirstActivity) { continue; } FLActivity child = subflowRoot.ChildFLActivities[i]; //((FLActivity)subflowRoot).ChildFLActivities.Remove(child); if (this.RootFLActivity.GetFLActivityByName(child.Name) != null) { if (this.RootFLActivity.GetFLActivityByName(currentFLActivity.Name).GetFLActivityByName(child.Name) == null) { throw new FLException(string.Format("Activity:'{0}' exists in main flow and sub flow.", child.Name)); } } ((FLActivity)subflow).AddFLActivity(child); } } XmlSerializer serializer = CreateXmlSerializer(typeof(FLSubFlowActivity)); StringBuilder builder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(builder); serializer.Serialize(writer, subflow); XmlDocument doc = new XmlDocument(); doc.LoadXml(builder.ToString()); XmlNode nodeSubs = doc.SelectSingleNode(string.Format("FLSubFlowActivity[@Name='{0}']", subflow.Name)); XmlNode nodeOldSubs = (XmlNode)_flDefinitionXmlNodes[subflow.Name]; nodeOldSubs.InnerXml = nodeSubs.InnerXml; InitFLDefinitionXmlNodes(nodeOldSubs); _flDefinitionXmlString = nodeOldSubs.OwnerDocument.InnerXml; ((FLActivity)subflow).Execute(); Hashtable childAll = ((FLActivity)subflow).GetAllChildFLActivities(); foreach (string key in childAll.Keys) { _setUpperParallels.Remove(key); _setLocations.Remove(key); } SetUpperParallel((FLActivity)subflow); SetLocation((FLActivity)subflow); if (((FLActivity)subflow).ChildFLActivities.Count == 0) { GetNextFLActivities((FLActivity)subflow, nextFLActivities); //当subflow没有任何人需要签核时, 撤消subflow状态,不然退回后再也无法进入subflow ((FLActivity)subflow).InitExecStatus(); } else { if (((FLActivity)subflow).ChildFLActivities[0] is FLStandActivity) { SetUpperParallel(((FLActivity)subflow).ChildFLActivities[0]); SetLocation(((FLActivity)subflow).ChildFLActivities[0]); nextFLActivities.Add(((FLActivity)subflow).ChildFLActivities[0]); } else { GetNextFLActivities(((FLActivity)subflow).ChildFLActivities[0], nextFLActivities); } } } else { #region if ((currentFLActivity is IEventWaiting) || (currentFLActivity is IFLValidateActivity) || ((currentFLActivity is IControlFL) && (currentFLActivity.ExecutionStatus == FLActivityExecutionStatus.Executed))) { if (currentFLActivity is IFLParallelActivity && (string.IsNullOrEmpty(((IFLParallelActivity)currentFLActivity).Description) || string.IsNullOrEmpty(((IFLParallelActivity)currentFLActivity).Description.Trim()) || ((IFLParallelActivity)currentFLActivity).Description.ToLower() == "and")) { bool b = true; foreach (FLActivity a in currentFLActivity.ChildFLActivities) { if (!((IFLParallelActivity)currentFLActivity).ExecutedBranches.Exists( delegate(string s) { if (a.Name == s) return true; else return false; } )) { b = false; break; } } if (!b) { return; } } else if (currentFLActivity is IFLParallelActivity && (!string.IsNullOrEmpty(((IFLParallelActivity)currentFLActivity).Description) && !string.IsNullOrEmpty(((IFLParallelActivity)currentFLActivity).Description.Trim()) && ((IFLParallelActivity)currentFLActivity).Description.ToLower().Contains("rate"))) { decimal rate = 0; decimal x = currentFLActivity.ChildFLActivities.Count; if (x != 0) { decimal y = ((IFLParallelActivity)currentFLActivity).ExecutedBranches.Count; decimal j = y / x; string q = ((IFLParallelActivity)currentFLActivity).Description.Trim(); string[] qq = q.Split(":".ToCharArray()); string p = qq[1].Trim(); rate = decimal.Parse(p); rate = rate / 100; if (j < rate) { return; } } } activity = GetRealNextFLActivity(currentFLActivity); if (activity == null) { activity = GetRealParentFLActivity(currentFLActivity); if (activity == null || activity is IFLRootActivity) { _flflag = 'Z'; return; } FLActivity parentActivity = GetRealParentFLActivity(activity); if (parentActivity is IFLParallelActivity && ((string.IsNullOrEmpty(((IFLParallelActivity)parentActivity).Description) || string.IsNullOrEmpty(((IFLParallelActivity)parentActivity).Description.Trim()) || ((IFLParallelActivity)parentActivity).Description.Trim().ToLower() == "and") || (!string.IsNullOrEmpty(((IFLParallelActivity)parentActivity).Description) && !string.IsNullOrEmpty(((IFLParallelActivity)parentActivity).Description.Trim()) && ((IFLParallelActivity)parentActivity).Description.Trim().ToLower().Contains("rate")))) { if (!((IFLParallelActivity)parentActivity).ExecutedBranches.Exists( delegate(string s) { if (currentFLActivity.Name == s) return true; else return false; } )) { ((IFLParallelActivity)parentActivity).ExecutedBranches.Add(activity.Name); foreach (FLActivity a in parentActivity.ChildFLActivities) { FLDirection direction = ((IFLSequenceActivity)a).FLDirection; if (a.Name != activity.Name && direction != FLDirection.Waiting) { //if (direction != _flDirection) //{ // String message = string.Format(SysMsg.GetSystemMessage((SYS_LANGUAGE)(((object[])(_clientInfo[0]))[0]), "FLRuntime", "FLInstance", "DirectionError"), _flDirection.ToString(), a.Name, direction.ToString()); // throw new FLException(2, message); //} } } ((IFLSequenceActivity)activity).SetFLDirection(_flDirection); } } } if (activity is IEventWaiting && !(activity is IFLApproveActivity || activity is IFLApproveBranchActivity) && activity.Enabled) { SetUpperParallel(activity); SetLocation(activity); nextFLActivities.Add(activity); } else { GetNextFLActivities(activity, nextFLActivities); } } else { if (currentFLActivity is IControlFL && !(currentFLActivity is IFLRootActivity)) { currentFLActivity.Execute(); } FLActivity parentFLActivity = GetRealParentFLActivity(currentFLActivity); if (parentFLActivity != null && parentFLActivity is IFLIfElseActivity) { foreach (FLActivity flActivity in parentFLActivity.ChildFLActivities) { flActivity.Execute(); } } if (currentFLActivity is IFLIfElseActivity) { List<FLActivity> branchActivities = currentFLActivity.ChildFLActivities; List<FLActivity> runBranchActivities = new List<FLActivity>(); FLActivity elseBranchActivity = null; foreach (FLActivity branchActivity in branchActivities) { IFLIfElseBranchActivity a = (IFLIfElseBranchActivity)branchActivity; string condition = a.Condition; if (condition != string.Empty) { if (JudgeCondition(condition)) { runBranchActivities.Add(branchActivity); break; } } else { elseBranchActivity = branchActivity; } } foreach (FLActivity branchActivity in runBranchActivities) { GetNextFLActivities(branchActivity, nextFLActivities); } if (runBranchActivities.Count == 0) { GetNextFLActivities(elseBranchActivity, nextFLActivities); } } else if (currentFLActivity is IFLParallelActivity) { _isFirstInParallel = true; _tempParallel = currentFLActivity.Name; foreach (FLActivity a in currentFLActivity.ChildFLActivities) { _tempParallelBranch = a.Name; List<FLActivity> tempNextFLActivities = new List<FLActivity>(); ((IFLSequenceActivity)a).SetFLDirection(FLDirection.Waiting); GetNextFLActivities(a, tempNextFLActivities); int j = 0; foreach (FLActivity tempFLActivity in tempNextFLActivities) { if (tempFLActivity is IEventWaiting) { j++; } } if (j == 0) { ((IFLParallelActivity)currentFLActivity).ExecutedBranches.Add(a.Name); } nextFLActivities.AddRange(tempNextFLActivities); } _isFirstInParallel = false; _tempParallel = string.Empty; _tempParallelBranch = string.Empty; if (nextFLActivities.Count == 0) { GetNextFLActivities(currentFLActivity, nextFLActivities); } } else { List<FLActivity> activities = currentFLActivity.ChildFLActivities; if (activities.Count == 0) { activity = GetRealNextFLActivity(currentFLActivity); if (activity == null) { activity = GetRealParentFLActivity(currentFLActivity); if (activity == null || activity is IFLRootActivity) { _flflag = 'Z'; return; } } if (activity is IEventWaiting && !(activity is IFLApproveActivity || activity is IFLApproveBranchActivity) && activity.Enabled) { SetUpperParallel(activity); SetLocation(activity); nextFLActivities.Add(activity); } else { GetNextFLActivities(activity, nextFLActivities); } } else { activity = activities[0]; if (activity is IEventWaiting && !(activity is IFLApproveActivity || activity is IFLApproveBranchActivity) && activity.Enabled) { SetUpperParallel(activity); SetLocation(activity); nextFLActivities.Add(activity); } else { GetNextFLActivities(activity, nextFLActivities); } } } } #endregion } }