/// <summary> /// addInstance: 新建在该流程索引下的实例 /// </summary> /// <returns></returns> public string addInstance(string alias, string url, string owners, bool ifReturnCurrID, string note) { SqlTrans trans = new SqlTrans(api); string _return = String.Empty; try { Json json = trans.execJson("select id,oid,nodeName,type,next,users,roles,logicState from {0} where oid={1} and type=10;", R.Table.WF_DEFINITION, indexID); if (json == null) { _return = Native.getErrorMsg("在索引ID为{0}中未找到开始节点, 请核实!", indexID); } else { if (owners.Length < 2) { owners = trans.getAllUsers(json.getValue("users"), json.getValue("roles")); } switch (json.getInt("logicState")) { case 6: owners = "," + MSession.get(MSession.getClientKey()) + ","; break; case 7: owners = trans.getDeptOwners(MSession.get(MSession.getClientKey())); break; } string _k = "oid,nodeName,owner,url"; string _v = json.getValue("oid") + ",'" + alias + "','" + owners + "','" + url + "'"; _return = trans.execScalar(MString.getInsertStr(R.Table.WF_INSTANCE, _k, _v, true)); int _rootID = Convert.ToInt16(_return); string _kt = "oid,definedNodeID,nodeName,next,pre,state,type,owner,note"; string _vt = json.getValue("oid") + "," + json.getValue("id") + ",'" + json.getValue("nodeName") + "','" + json.getValue("next") + "',0,1,10,'" + owners + "','" + note + "'"; string _CURRID = trans.addTreeNode(R.Table.WF_INSTANCE, _rootID, _kt, _vt); if (ifReturnCurrID) { _return += "@" + _CURRID; } trans.commit(); } } catch (Exception ex) { _return = Native.getErrorMsg(ex.Message + "--addInstance"); trans.rollback(); } finally { trans.close(); } return(_return); }
/// <summary> /// getInsertStr: 得到sql insert字符串 /// </summary> /// <param name="_table">表名</param> /// <param name="_key">字段列表, 字段之间通过逗号分隔开</param> /// <param name="_val">值列表, 每个字段值之间通过逗号分隔开</param> /// <returns>返回sql insert语句</returns> public static string getInsertStr(string _table, string _key, string _val) { string _cPerson = MSession.get(MSession.getClientKey()); if (Native.isNullEmpty(_cPerson)) { _cPerson = "0"; } string _sql = "insert into {0} ({1},cPerson) values ({2}," + _cPerson + ");", _return = format(_sql, _table, _key, _val); //logger.log(_return).logToNet("Insert", _table, _return); return(_return); }
/// <summary> /// getUpdateStr: 得到update字符串 /// </summary> /// <param name="_table">表名</param> /// <param name="_update">更新字符串</param> /// <param name="_condition">更行条件</param> /// <returns>update字符串</returns> public static string getUpdateStr(string _table, string _update, string _condition) { string _mPerson = MSession.get(MSession.getClientKey()); if (Native.isNullEmpty(_mPerson)) { _mPerson = "0"; } string _sql = "update {0} set mPerson=" + _mPerson + ", mTime=getdate(),{1} where {2};", _return = format(_sql, _table, _update, _condition); //logger.log(_return).logToNet("Update", _table, _return); return(_return); }
/// <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); }
/// <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); }
/// <summary> /// getSelectStr: 得到有权限的查询字符串 /// </summary> /// <param name="_table">表名</param> /// <param name="_key">字段列表, 字段之间通过逗号分隔开</param> /// <param name="_condition">查询条件/param> /// <param name="_orderColumn">排序字段名</param> /// <param name="_order">排序方式</param> /// <returns>查询字符串</returns> public static string getManagerRightsSelectStr(string _table, string _key, string _condition, string _orderColumn, string _order) { string _sql = "select {0} from {1} as self where (ifRights=0 or (ifRights=1 and dbo.SYS_TRANS_RIGHTS('" + MSession.get(MSession.getClientKey()) + "', users,roles,cPerson)<>0)) and delFlag<>1 and {2}"; if (!Native.isEmpty(_orderColumn) && !Native.isEmpty(_order) && _key.ToLower().IndexOf("count(") == -1) { _sql += " order by {3} {4}"; } _sql += ';'; return(format(_sql, _key, _table, _condition, _orderColumn, _order)); }