Пример #1
0
        /// <summary>
        /// nextPARALLEL: 并行节点的下一步扭转
        /// </summary>
        /// <param name="currID"></param>
        /// <param name="nextID"></param>
        /// <param name="jsonStr"></param>
        /// <param name="ext"></param>
        /// <returns></returns>
        private string nextPARALLEL(int currID, int nextID, string jsonStr, string ext = "")
        {
            string   _return = String.Empty;
            SqlTrans trans   = new SqlTrans(api);
            bool     _ifNext = false;

            try
            {
                string _pkv = "state=" + S_P_PASS, _ekv = MConvert.toUpdateSql(jsonStr);
                string _currUserId = MSession.get(MSession.getClientKey());
                if (!Native.isEmpty(_ekv))
                {
                    _pkv += "," + _ekv;
                }
                string _instanceID = trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "pid", Convert.ToInt16(currID)));
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "owner=REPLACE(owner, '" + _currUserId + ",', '')", Convert.ToInt32(_instanceID)));
                int    _ifSucc = trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, _pkv, "pid=" + currID + " and dbo.SYS_TRANS_CONFIRM_USERS(nodeName,'" + _currUserId + "')<>0"));
                string _count  = trans.execScalar("select count(*) from {0} where pid={1} and state=" + S_P_NORMAL + ";", R.Table.WF_INSTANCE, currID);
                if (_count == "0")
                {
                    _ifNext = true;
                }
                api.setDataType("json");
                _return = trans.execReader(MString.getSelectStr(R.Table.WF_INSTANCE, "*", Convert.ToInt16(currID)));
                api.setDataType("html");
                trans.commit();
            }
            catch (Exception e)
            {
                _return = Native.getErrorMsg(e.Message + "--WFInstance--nextPARALLEL");
                trans.rollback();
            }
            finally
            {
                trans.close();
            }
            if (_ifNext)
            {
                _return = nextNORMAL(currID, nextID, "", "");
            }
            return(_return);
        }
Пример #2
0
        /// <summary>
        /// nextPARALLEL: 并行节点的下一步扭转
        /// </summary>
        /// <param name="currID"></param>
        /// <param name="nextID"></param>
        /// <param name="jsonStr"></param>
        /// <param name="ext"></param>
        /// <returns></returns>
        public string denyPARALLEL(int currID, int nextID, string jsonStr, string ext = "")
        {
            string   _return = String.Empty;
            SqlTrans trans   = new SqlTrans(api);
            bool     _ifNext = false;

            try
            {
                string _pkv = "state=" + S_P_DENY, _ekv = MConvert.toUpdateSql(jsonStr);
                if (!Native.isEmpty(_ekv))
                {
                    _pkv += "," + _ekv;
                }
                int    _ifSucc = trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, _pkv, "pid=" + currID + " and nodeName='" + MSession.get(MSession.getClientKey()) + "'"));
                string _count  = trans.execScalar("select count(*) from {0} where pid={1} and state=" + S_P_NORMAL + ";", R.Table.WF_INSTANCE, currID);
                if (_count == "0")
                {
                    _ifNext = true;
                }
                api.setDataType("json");
                _return = trans.execReader(MString.getSelectStr(R.Table.WF_INSTANCE, "*", Convert.ToInt16(currID)));
                api.setDataType("html");
                trans.commit();
            }
            catch (Exception e)
            {
                _return = Native.getErrorMsg(e.Message + "--WFInstance--nextPARALLEL");
                trans.rollback();
            }
            finally
            {
                trans.close();
            }
            if (_ifNext)
            {
                _return = nextNORMAL(currID, nextID, "", "");
            }
            return(_return);
        }
Пример #3
0
        /// <summary>
        /// nextNORMAL: 正常节点的下一步扭转
        /// </summary>
        /// <param name="currID">当前节点</param>
        /// <param name="nextID">下个节点</param>
        /// <param name="jsonStr">提交的json字符串</param>
        /// <param name="ext">扩展信息</param>
        /// <returns></returns>
        private string nextNORMAL(int currID, int nextID, string jsonStr, string ext = "")
        {
            string   _return = String.Empty, _nextOwners = String.Empty;
            SqlTrans trans = new SqlTrans(api);

            string[] _onEndResult = new string[] {};
            int      _newNextID = 0;
            Json     _cNode = null, _nNode = null, _parentNode = null;

            try
            {
                _cNode      = trans.execJson("select pid, definedNodeID, owner, cPerson from {0} where id={1};", R.Table.WF_INSTANCE, currID);
                _nNode      = trans.execJson("select * from {0} where id={1};", R.Table.WF_DEFINITION, nextID);
                _parentNode = trans.execJson("select * from {0} where id={1};", R.Table.WF_INSTANCE, _cNode.getValue("pid"));
                switch (_nNode.getInt("logicState"))
                {
                case 0:
                    _nextOwners = trans.getAllUsers(_nNode.getValue("users"), _nNode.getValue("roles"));
                    break;

                case 1:
                case 2:
                    //_nextOwners = trans.getAllUsers(MConvert.removeKey(ref jsonStr, "users"), MConvert.removeKey(ref jsonStr, "roles"));
                    _nextOwners = getParallerUsers(trans, MConvert.removeKey(ref jsonStr, "users"), MConvert.removeKey(ref jsonStr, "roles"), _nNode.getInt("logicState"), _parentNode);
                    break;

                case 3:
                    _nextOwners = "," + trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "cPerson", "id=" + _cNode.getValue("pid"))) + ",";
                    break;

                case 4:
                    _nextOwners = _cNode.getValue("owner");
                    break;

                case 5:
                    _nextOwners = getAllStepUsers(trans, _cNode.getInt("pid"));
                    break;

                case 6:
                    _nextOwners = "," + trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "cPerson", "id=" + _cNode.getInt("pid"))) + ",";
                    break;

                case 7:
                    _nextOwners = trans.getDeptOwners(trans.execScalar(MString.getSelectStr(R.Table.WF_INSTANCE, "cPerson", "id=" + _cNode.getInt("pid"))));
                    break;

                case 10:      //自动节点
                    string[] _nextids = trans.execScalar(MString.getSelectStr(R.Table.WF_DEFINITION, "next", nextID)).Split(',');
                    if (_nextids.Length == 3 && !Native.isEmpty(_nextids[1]))
                    {
                        _newNextID = Convert.ToInt16(_nextids[1]);
                    }
                    else
                    {
                        trans.commit();
                        trans.close();
                        return(Native.getErrorMsg("自动进行扭转到下个节点时, 当前节点的next不唯一或为空, 请先确认!"));
                    }
                    break;
                }
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, MConvert.toUpdateSql(jsonStr), currID));
                string _nk    = "oid,definedNodeID,nodeName,next,pre,ext,type,state,users,roles,owner";
                string _nv    = _nNode.getValue("oid") + "," + _nNode.getValue("id") + ",'" + _nNode.getValue("nodeName") + "','" + _nNode.getValue("next") + "'," + currID + ",'" + ext + "'," + _nNode.getValue("type") + ",1,'" + _nNode.getValue("users") + "','" + _nNode.getValue("roles") + "','" + _nextOwners + "'";
                string _newID = trans.addTreeNode(R.Table.WF_INSTANCE, _cNode.getInt("pid"), _nk, _nv);
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "state=0, next='" + _newID + "'", currID));
                switch (_nNode.getInt("type"))
                {
                case T_PARALLEL:
                    string _nOwners = getParallerUsers(trans, _nNode.getValue("users"), _nNode.getValue("roles"), _nNode.getInt("logicState"), _parentNode);
                    if (_nOwners.Length > 2 && _nNode.getInt("logicState") != 1 && _nNode.getInt("logicState") != 2)
                    {
                        _nextOwners = _nOwners;
                    }
                    trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "owner=dbo.SYS_TRANS_RIGHTS_USERS('" + _nextOwners + "')", Convert.ToInt16(_newID)));
                    string[] _users = _nextOwners.Split(',');
                    for (int _u = 0, _uLen = _users.Length; _u < _uLen; _u++)
                    {
                        string _uid = _users[_u];
                        if (!Native.isEmpty(_uid))
                        {
                            trans.addTreeNode(R.Table.WF_INSTANCE, Convert.ToInt16(_newID), "state,nodeName,owner,users", S_P_NORMAL + ",'" + _uid + "','," + _uid + ",','," + _uid + ",'");
                        }
                    }
                    trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "users='" + _nextOwners + "'", Convert.ToInt16(_newID)));
                    break;

                case T_SUB_PROCESS:
                    string[] subIds = _nNode.getValue("subProcessIdxIds").Split(',');
                    for (int _u = 0, _uLen = subIds.Length; _u < _uLen; _u++)
                    {
                        string _sid = subIds[_u];
                        if (!Native.isEmpty(_sid))
                        {
                            addSubProcess(trans, Convert.ToInt16(_newID), Convert.ToInt16(_sid));
                        }
                    }
                    break;

                case T_END:
                    int _pid = _cNode.getInt("pid");
                    trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "state=" + S_ENDED, _pid));
                    _onEndResult = onProcessEnd(trans, _pid);
                    break;
                }
                trans.execNonQuery(MString.getUpdateStr(R.Table.WF_INSTANCE, "owner=dbo.SYS_TRANS_RIGHTS_USERS('" + _nextOwners + "')", _cNode.getInt("pid")));
                api.setDataType("json");
                _return = trans.execReader(MString.getSelectStr(R.Table.WF_INSTANCE, "*, dbo.SYS_TRANS_USERS(users) as t_users", Convert.ToInt16(_newID)));
                api.setDataType("html");
                trans.commit();
            }
            catch (Exception e)
            {
                _return = Native.getErrorMsg(e.Message + "--WFInstance--nextNORMAL");
                trans.rollback();
            }
            finally
            {
                trans.close();
            }
            if (_cNode != null && _nNode != null)
            {
                WFRuler.runNext(_cNode.getInt("definedNodeID"), _nNode.getInt("id"), _cNode.getValue("owner"), _nextOwners);
            }
            if (_newNextID != 0)
            {
                return(next(nextID, _newNextID, jsonStr, "节点[" + nextID + "]---->[" + _newNextID + "]自动扭转"));
            }
            if (_onEndResult.Length > 0)
            {
                return(nextNORMAL(Convert.ToInt16(_onEndResult[0]), Convert.ToInt16(_onEndResult[1]), "子流程结束时主动触发主流程向下扭转", ""));
            }
            return(_return);
        }