Exemple #1
0
        /// <summary>
        /// 检查操作者是否有权限执行该动作
        /// </summary>
        /// <param name="workflowName">工作流名称</param>
        /// <param name="dataid">业务表id</param>
        /// <param name="actionName">动作名称</param>
        /// <param name="operatorid">操作者ID</param>
        /// <returns></returns>
        public bool checkNodeAction(string workflowName, int dataid, string actionName, int operatorid)
        {
            workflowEx          workflowEx    = new workflowEx();
            workflow            wf            = workflowEx.getworkflow(workflowName);              //获取该工作流名称对应的工作流数据
            workflowinstancesEx wfinstancesEx = new workflowinstancesEx();
            workflowinstances   wfinstances   = wfinstancesEx.getworkflowinstances(wf.id, dataid); //获得工作流执行结果

            //状态跃迁时
            //判断操作者是否有权限
            if (wfinstances != null)
            {
                return(checkNodeAction(actionName, operatorid, wf, wfinstances));
            }
            else//新增动作只判断当前操作者是否有权限执行这个动作
            {
                workflownodeactionEx   wfnaEx = new workflownodeactionEx();
                workflownodeaction     wfna   = wfnaEx.getworkflownodeaction(wf.id, actionName);
                workflownodeoperatorEx wfnoEx = new workflownodeoperatorEx();
                workflownodeoperator   wfno   = wfnoEx.getworkflownodeoperator(wfna.id, operatorid);
                if (wfno == null)
                {
                    return(false);
                }
                return(true);
            }
        }
        /// <summary>
        /// 节点跃迁方法
        /// </summary>
        /// <param name="workflowName">工作流名称</param>
        /// <param name="dataid">业务数据主码</param>
        /// <param name="actionName">动作名称</param>
        /// <param name="operatorid">操作者ID</param>
        /// <param name="executer">执行者</param>
        /// <param name="remark">工作流执行备注</param>
        /// <param name="isRecordTrace">是否记录工作流操作日志(默认记录)</param>
        /// <returns>返回是否执行成功</returns>
        public bool trace(string workflowName, int dataid, string actionName, int operatorid, string executer, string remark, bool isRecordTrace = true)
        {
            workflowEx           workflowEx    = new workflowEx();
            workflow             wf            = workflowEx.getworkflow(workflowName);
            int                  instancesid   = 0;
            workflowinstancesEx  wfinstancesEx = new workflowinstancesEx();
            workflowinstances    wfinstances   = wfinstancesEx.getworkflowinstances(wf.id, dataid);
            workflownodeactionEx wfnaEx        = new workflownodeactionEx();
            workflownodeaction   wfna          = wfnaEx.getworkflownodeaction(wf.id, actionName);
            workflownodeEx       wfnEx         = new workflownodeEx();
            string               sql           = string.Empty;

            if (wfinstances != null)
            {
                int currentnodeid = wfna.nextnodeid;
                int?nodcodevalue  = 0;
                if (wfna.nodetype == 2)                                                      //会签节点跳跃
                {
                    List <workflownodeaction> wfnas = wfnaEx.getcountersignnodeaction(wfna); //会签动作集合
                    nodcodevalue = (wfinstances.nodcode | wfna.nodeactioncode) == wfna.nodeactioncode ? wfinstances.nodcode : (wfinstances.nodcode + wfna.nodeactioncode);
                    if (nodcodevalue != wfnas.Select(p => p.nodeactioncode).Sum())
                    {
                        currentnodeid = wfna.currentnodeid;
                    }
                }
                //更新Trace表节点信息
                sql = string.Format(@"update {0} 
                                       set currentnodeid={1},
                                                  nodcode={2}
                                                 where id={3}",
                                    wf.wfinstancestable, currentnodeid, nodcodevalue, wfinstances.id);
                instancesid = wfinstances.id;
                db.SqlQueryDynamic(sql);
                //更新业务表工作流字段值

                workflownode wfn    = wfnEx.getworkflownode(wfna.nextnodeid);
                string       sqlstr = string.Format("update {0} set {1}={2} where id={3}", wf.wfownertable, wf.wffieldname, wfn.wfnodememo);
                db.SqlQueryDynamic(sqlstr);
            }
            else
            {
                instancesid = insert(wf, instancesid, wfna, dataid);
                //更新业务表工作流字段值
                workflownode wfn    = wfnEx.getworkflownode(wfna.nextnodeid);
                string       sqlstr = string.Format("update {0} set {1}='{2}' where id={3}", wf.wfownertable, wf.wffieldname, wfn.wfnodememo, dataid);
                db.SqlQueryDynamic(sqlstr);
            }
            if (isRecordTrace)
            {
                workflowinstancetracingsEx wfinstancetringEx = new workflowinstancetracingsEx();
                wfinstancetringEx.insert(executer, instancesid, wfna);
            }

            return(true);
        }
        /// <summary>
        /// 添加工作流结果表数据
        /// </summary>
        /// <param name="wf"></param>
        /// <param name="instancesid"></param>
        /// <param name="wfna"></param>
        /// <param name="dataid"></param>
        /// <returns></returns>
        public int insert(workflow wf, int instancesid, workflownodeaction wfna, int dataid)
        {
            workflowinstancesEx wfinstancesEx = new workflowinstancesEx();
            workflowinstances   wfinstacnes   = new workflowinstances();

            wfinstacnes.ownertabledataid = dataid;
            wfinstacnes.nodcode          = wfna.nodeactioncode;
            wfinstacnes.wfid             = wf.id;
            wfinstacnes.currentnodeid    = wfna.nextnodeid;
            instancesid = wfinstancesEx.insert(wfinstacnes);
            return(instancesid);
        }