//通过后置活动查找 public List <CLink> FindByNextActives(Guid NextActives) { GetList(); List <CLink> lstRet = new List <CLink>(); foreach (CBaseObject obj in m_lstObj) { CLink Link = (CLink)obj; if (Link.NextActives == NextActives) { lstRet.Add(Link); } } return(lstRet); }
//启动工作流 public bool StartWorkflow(CWorkflow wf, out string sErr) { sErr = ""; CCompany Company = null; if (wf.B_Company_id == Guid.Empty) { Company = (CCompany)Ctx.CompanyMgr.FindTopCompany(); } else { Company = (CCompany)Ctx.CompanyMgr.Find(wf.B_Company_id); } CWorkflowDef WorkflowDef = (CWorkflowDef)Company.WorkflowDefMgr.Find(wf.WF_WorkflowDef_id); if (WorkflowDef == null) { sErr = "工作流定义不存在!"; return(false); } CActivesDef start = WorkflowDef.ActivesDefMgr.FindStart(); if (start == null) { sErr = "启动活动不存在!"; return(false); } List <CLink> lstLink = WorkflowDef.LinkMgr.FindByPreActives(start.Id); if (lstLink.Count == 0) { sErr = "启动活动没有连接!"; return(false); } //启动活动有且仅有一个连接 CLink Link = lstLink[0]; CActivesDef next = (CActivesDef)WorkflowDef.ActivesDefMgr.Find(Link.NextActives); if (next == null) { sErr = "启动活动没有连接!"; return(false); } //启动条件 if (!ValidateCond(WorkflowDef, wf, Link.Condiction, out sErr)) { return(false); } Update(wf); wf.State = enumApprovalState.Running; //实例化活动 CActives Actives = new CActives(); Actives.Ctx = Ctx; Actives.WF_Workflow_id = wf.Id; Actives.WF_ActivesDef_id = next.Id; Actives.Result = enumApprovalResult.Init; Actives.AType = next.AType; if (Actives.AType == "按用户") { Actives.B_User_id = next.B_User_id; } else { Actives.B_Role_id = next.B_Role_id; } wf.ActivesMgr.AddNew(Actives); //考虑发邮件等通知方式 //if (!Save(true)) //{ // sErr = "保存失败!"; // return false; //} return(true); }