Example #1
0
 //²éÕÒδÉóÅú»î¶¯
 public CActives FindNotApproval()
 {
     GetList();
     foreach (CBaseObject obj in m_lstObj)
     {
         CActives Actives = (CActives)obj;
         if (Actives.Result == enumApprovalResult.Init)
         {
             return(Actives);
         }
     }
     return(null);
 }
Example #2
0
        //启动工作流
        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);
        }
Example #3
0
        //审批活动
        public bool Approval(CWorkflow wf, CActives Actives, 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);
            }
            if (Company == null)
            {
                sErr = "单位不存在!";
                return(false);
            }
            CWorkflowDef WorkflowDef = (CWorkflowDef)Company.WorkflowDefMgr.Find(wf.WF_WorkflowDef_id);

            if (WorkflowDef == null)
            {
                sErr = "工作流定义不存在!";
                return(false);
            }
            List <CLink> lstLink = WorkflowDef.LinkMgr.FindByPreActives(Actives.WF_ActivesDef_id);

            if (lstLink.Count == 0)
            {
                sErr = "活动没有连接!";
                return(false);
            }
            //找出符合条件的连接,并获取下一个活动
            CActivesDef next = null;

            foreach (CLink link in lstLink)
            {
                if (Actives.Result == link.Result)
                {
                    //检验条件表达式
                    if (!ValidateCond(WorkflowDef, wf, link.Condiction, out sErr))
                    {
                        if (sErr != "")
                        {
                            return(false);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    next = (CActivesDef)WorkflowDef.ActivesDefMgr.Find(link.NextActives);
                    break;
                }
            }
            if (next == null)
            {
                sErr = "活动没有连接!";
                return(false);
            }


            Update(wf);
            wf.ActivesMgr.Update(Actives);
            //如果是结束活动,则结束工作流
            if (next.WType == ActivesType.Success)
            {
                wf.State = enumApprovalState.Accept;
            }
            else if (next.WType == ActivesType.Failure)
            {
                wf.State = enumApprovalState.Reject;
            }
            else
            {
                //实例化下一个活动
                CActives nextActives = new CActives();
                nextActives.Ctx              = Ctx;
                nextActives.WF_Workflow_id   = wf.Id;
                nextActives.WF_ActivesDef_id = next.Id;
                nextActives.Result           = enumApprovalResult.Init;
                nextActives.AType            = next.AType;
                if (nextActives.AType == "按用户")
                {
                    nextActives.B_User_id = next.B_User_id;
                }
                else
                {
                    nextActives.B_Role_id = next.B_Role_id;
                }
                wf.ActivesMgr.AddNew(nextActives);
                //考虑发邮件等通知方式
            }

            if (!Save(true))
            {
                sErr = "保存失败!";
                return(false);
            }

            return(true);
        }