/// <summary> /// 申请工作 /// </summary> private void Apply(Result Arguments) { Guid itemId = Guid.Parse(Arguments.Attributes["itemId"].ToString()); Guid userId = RbacPrincipal.CurrentUser.UserId; string Pbo_Type = Arguments.Attributes["Pbo_Type"].ToString(); string memo = Arguments.Attributes["Memo"].ToString(); Result = new Result(true); var rout = RF.Concrete <IWFRoutRepository>().GetRoutName(WFRoutType.维修审批流程.ToString()); WFItem item = new WFItem(); item.ID = Guid.NewGuid(); item.ApplyUserID = userId; item.Pbo_ID = itemId; item.Pbo_Type = Convert.ToInt32(Pbo_Type); item.Pbo_Adderss = "EDMSRepairsBill"; item.Name = rout.Name + "(" + DateTime.Now.Minute + ")"; item.Rout_ID = rout.ID; RF.Concrete <IWFItemRepository>().Create(item); //查找所选流程的第一个步骤 var actor = RF.Concrete <IWFActorRepository>().GetByRoutId(rout.ID)[0]; //插入任务列表taskList RF.Concrete <IWFTaskListRepository>().Create(new WFTaskList { Actor_ID = actor.ID, Item_ID = item.ID, State = 0, Version = 1, }); //插入任务历史记录 RF.Concrete <IWFTaskHistoryRepository>().Create(new WFTaskHistory { Item_ID = itemId, Actor_ID = actor.ID, OperateUserID = userId, IsExamine = false, Memo = memo, }); RF.Concrete <IWFTaskHistoryRepository>().Context.Commit(); Result.DataObject = item; }
/// <summary> /// 申请工作 /// </summary> private void Apply(Result Arguments) { var identity = LEnvironment.Principal as LCLIdentity; //if (identity == null) { return; } Guid itemId = Guid.Parse(Arguments.Attributes["itemId"].ToString()); Guid userId = Guid.Empty; Result = new Result(true); var rout = RF.Concrete <IWFRoutRepository>().GetRoutName(WFRoutType.维修审批流程.ToString()); WFItem item = new WFItem(); item.ApplyUserID = userId; item.Pbo_ID = itemId; item.Pbo_Adderss = "EDMSRepairsBill"; item.Name = rout.Name + "(" + DateTime.Now.Minute + ")"; item.Rout_ID = rout.ID; RF.Concrete <IWFItemRepository>().Create(item); //查找所选流程的第一个步骤 var actor = RF.Concrete <IWFActorRepository>().GetByRoutId(rout.ID)[0]; //插入任务列表taskList RF.Concrete <IWFTaskListRepository>().Create(new WFTaskList { Actor_ID = actor.ID, Item_ID = item.ID, State = 0, Version = 1, }); //插入任务历史记录 RF.Concrete <IWFTaskHistoryRepository>().Create(new WFTaskHistory { Item_ID = itemId, Actor_ID = actor.ID, OperateUserID = userId, IsExamine = false, Memo = "申请", }); RF.Concrete <IWFTaskHistoryRepository>().Context.Commit(); Result.DataObject = item; }
/// <summary> /// Retrieves all the workflow data associated with this item. /// </summary> /// <param name="className"></param> /// <param name="itemId"></param> public void LoadWorkflow(string className, int itemId) { //Get the workflow object by class name if (Workflow.LoadByObjectName(className)) { //Load the WFItem using the itemId, this is the not the same as the primary key for the WFItem. WFItem.LoadByItemId(Workflow.ID, itemId); //Get all owner groups for this workflow WFOwnerGroups.Load(Workflow.ID); //Get the owners for this item WFOwners.Load(WFItem.ID); //Add any owner groups that aren't in the list foreach (ENTWFOwnerGroupEO wfOwnerGroup in WFOwnerGroups) { ENTWFItemOwnerEO wfItemOwner = WFOwners.SingleOrDefault(o => o.ENTWFOwnerGroupId == wfOwnerGroup.ID); if (wfItemOwner == null) { //Add this with a blank user WFOwners.Add(new ENTWFItemOwnerEO { ENTWFItemId = itemId, ENTWFOwnerGroupId = wfOwnerGroup.ID }); } } //Get all the state histories WFStateHistory.Load(WFItem.ID); //Load the transitions based on the current state. WFTransitions.Load(WFItem.CurrentWFStateId); //Load the current state. _currentState = new ENTWFStateEO(); _currentState.Load(WFItem.CurrentWFStateId); } else { throw new Exception("Workflow not set correctly. Please associate this item with a workflow."); } }
/// <summary> /// 申请工作 /// </summary> private void Apply(Result Arguments) { var identity = LEnvironment.Principal as LCLIdentity; //if (identity == null) { return; } Guid itemId = Guid.Parse(Arguments.Attributes["itemId"].ToString()); Guid userId = Guid.Empty; Result = new Result(true); var rout = RF.Concrete<IWFRoutRepository>().GetRoutName(WFRoutType.维修审批流程.ToString()); WFItem item = new WFItem(); item.ApplyUserID = userId; item.Pbo_ID = itemId; item.Pbo_Adderss = "EDMSRepairsBill"; item.Name = rout.Name + "(" + DateTime.Now.Minute + ")"; item.Rout_ID = rout.ID; RF.Concrete<IWFItemRepository>().Create(item); //查找所选流程的第一个步骤 var actor = RF.Concrete<IWFActorRepository>().GetByRoutId(rout.ID)[0]; //插入任务列表taskList RF.Concrete<IWFTaskListRepository>().Create(new WFTaskList { Actor_ID = actor.ID, Item_ID = item.ID, State = 0, Version = 1, }); //插入任务历史记录 RF.Concrete<IWFTaskHistoryRepository>().Create(new WFTaskHistory { Item_ID = itemId, Actor_ID = actor.ID, OperateUserID = userId, IsExamine = false, Memo = "申请", }); RF.Concrete<IWFTaskHistoryRepository>().Context.Commit(); Result.DataObject = item; }
public bool SaveWorkflow(HRPaidTimeOffDataContext db, ref ENTValidationErrors validationErrors, ENTBaseEO item, int userAccountId) { WFItem.ItemId = item.ID; ValidateWorkflow(db, ref validationErrors, item); if (validationErrors.Count == 0) { //Set the ID for all the child owner objects foreach (ENTWFItemOwnerEO entWFItemOwner in WFOwners) { entWFItemOwner.ENTWFItemId = item.ID; } foreach (ENTWFItemStateHistoryEO entWFItemStateHistory in WFStateHistory) { entWFItemStateHistory.ENTWFItemId = item.ID; } if (WFItem.Save(db, ref validationErrors, userAccountId)) { foreach (ENTWFItemOwnerEO wfItemOwner in WFOwners) { wfItemOwner.ENTWFItemId = WFItem.ID; if (wfItemOwner.Save(db, ref validationErrors, userAccountId) == false) { return(false); } } foreach (ENTWFItemStateHistoryEO wfItemStateHistory in WFStateHistory) { if (wfItemStateHistory.IsNewRecord()) { //A state history is only added if an item changes state or a different person becomes the owner. //Send notification if user became owner, Chapter 8. //Check if the new owner is registered to recieve a notification when they become the owner of an item. ENTNotificationEO myNotification = new ENTNotificationEO(); if (myNotification.Load(db, ENTNotificationEO.NotificationType.IBecameOwnerOfIssue, wfItemStateHistory.ENTUserAccountId)) { //Get the new owner's email address ENTUserAccountEO newOwner = new ENTUserAccountEO(); newOwner.Load(db, wfItemStateHistory.ENTUserAccountId); ENTEmailEO email = new ENTEmailEO { FromEmailAddress = myNotification.FromEmailAddress, Subject = ReplaceTokens(myNotification.Subject, item), Body = ReplaceTokens(myNotification.Body, item), EmailStatusFlag = ENTEmailEO.EmailStatusFlagEnum.NotSent, ToEmailAddress = newOwner.Email }; email.Save(db, ref validationErrors, userAccountId); } } wfItemStateHistory.ENTWFItemId = WFItem.ID; if (wfItemStateHistory.Save(db, ref validationErrors, userAccountId) == false) { return(false); } } //Call any methods the transition requires if (ENTWFTransitionId != 0) { ENTWFTransitionEO entWFTransition = WFTransitions.Get(ENTWFTransitionId); if (entWFTransition.PostTransitionMethodName != null) { //Create an instance of the object Type objectType = Type.GetType(Workflow.ENTWorkflowObjectName); //object listObject = Activator.CreateInstance(objectType); //Call the method to load the object objectType.InvokeMember(entWFTransition.PostTransitionMethodName, BindingFlags.InvokeMethod, null, item, new object[] { db }); } //Send notifications if user requests to be notified when their issue changes state, Chapter 8. ENTNotificationEO issueChangedStateNotification = new ENTNotificationEO(); if (issueChangedStateNotification.Load(db, ENTNotificationEO.NotificationType.MyRequestChangedState, WFItem.SubmitterENTUserAccountId)) { //Get the submitters email address. ENTUserAccountEO submitter = new ENTUserAccountEO(); submitter.Load(db, WFItem.SubmitterENTUserAccountId); ENTEmailEO email = new ENTEmailEO { FromEmailAddress = issueChangedStateNotification.FromEmailAddress, Subject = ReplaceTokens(issueChangedStateNotification.Subject, item), Body = ReplaceTokens(issueChangedStateNotification.Body, item), EmailStatusFlag = ENTEmailEO.EmailStatusFlagEnum.NotSent, ToEmailAddress = submitter.Email }; email.Save(db, ref validationErrors, userAccountId); } //Check if anyone registered for this notification for the current state. ENTNotificationENTUserAccountEOList goesToStateNotification = new ENTNotificationENTUserAccountEOList(); goesToStateNotification.Load(db, WFItem.CurrentWFStateId, ENTNotificationEO.NotificationType.IssueIOwnedGoesToState); if (goesToStateNotification.Count > 0) { //Get the notification details to send the email. ENTNotificationEO notification = new ENTNotificationEO(); notification.Load(db, (int)ENTNotificationEO.NotificationType.IssueIOwnedGoesToState); //Send notifications if user requests to be notified if they owned an issue an it reaches a specific state. foreach (ENTWFItemOwnerEO owner in WFOwners) { ENTNotificationENTUserAccountEO notifyForState = goesToStateNotification.GetByENTUserAccountId((int)owner.ENTUserAccountId); if (notifyForState != null) { //Get the owner's email address. ENTUserAccountEO ownerUserAccount = new ENTUserAccountEO(); ownerUserAccount.Load(db, (int)owner.ENTUserAccountId); ENTEmailEO email = new ENTEmailEO { FromEmailAddress = notification.FromEmailAddress, Subject = ReplaceTokens(notification.Subject, item), Body = ReplaceTokens(notification.Body, item), EmailStatusFlag = ENTEmailEO.EmailStatusFlagEnum.NotSent, ToEmailAddress = ownerUserAccount.Email }; email.Save(db, ref validationErrors, userAccountId); } } } } return(true); } else { //Failed item save. return(false); } } else { //Failed Validation return(false); } }