<%@ WebHandler Language="C#" Class="GetBDZInfro" Debug="true" %> using System; using System.Web; using System.Text; using System.Data; using System.Data.Common; using System.Collections.Generic; using eMIS; public class GetBDZInfro : IHttpHandler,System.Web.SessionState.IRequiresSessionState { private int getNextNodesCount = 0; private FlowManager flow = null; private HttpContext context = null; private string userId = null; private string[] recordIdList = null; string nodes = null; string users = null; string remark = null; string sms = null; private DataManager dataManager=null; private string param = null; private string superman = null; private string action = null; private string ck = null; private string currNodeId = null; private InstanceManager inst = null; private string wwwroot=null; private bool isSQLServer; private string skipNodes = ""; private StringBuilder sb = null; private StringBuilder line = null; private string startoperator=null; private string flowId=""; private int seqid=0; public void ProcessRequest (HttpContext context) { this.context = context; sb = new StringBuilder(); line = new StringBuilder(); this.dataManager = new DataManager(); DataTable dt; flowId = context.Request.QueryString["fid"]==null?"":context.Request.QueryString["fid"].ToString(); string recordId = context.Request.QueryString["rid"].ToString(); if (flowId == "") { dt = this.dataManager.ExecuteTable("select LCID from XT_LCSL where JLID=?",recordId); if (dt.Rows.Count != 0) { flowId = dt.Rows[0][0].ToString(); } else { context.Response.Write("未发现流程实例!"); context.Response.End(); } } string nodeId = context.Request.QueryString["nid"]==null?"":context.Request.QueryString["nid"].ToString(); if (!DataManager.IsNumber(flowId) || !DataManager.IsNumber(recordId)) context.Response.End(); if (context.Session["userid"] == null) { userId = "400955"; //context.Session["userid"].ToString(); LoginManager lm = new LoginManager(context); lm.Login(userId,true); } if (nodeId == "") { dt = dataManager.ExecuteTable("select top 1 JDID from COM_LCJDB where LCID=? and (SJJD is null or SJJD='') and XJJD is not null order by JDID", flowId); nodeId = dt.Rows[0][0].ToString(); } dt = dataManager.ExecuteTable("select ID from COM_XTCDB where LCID=? and JDID=?", flowId,nodeId); if (dt.Rows.Count == 0) { context.Response.Write("{\"err\":true}"); context.Response.End(); } string menuId = dt.Rows[0][0].ToString(); inst = new InstanceManager(context, dataManager, menuId); flow = new FlowManager(inst); flow.MenuID = menuId; flow.Init(recordId); getNextNodesCount = 0; int idx = GetID(); line.Append("[{\"desc\":\""+StringHelper.ConvertToJson( flow.GetNodeProperty(nodeId, "JDMC")) + "[" + nodeId + "]\",\"parent\":0,\"id\":"+nodeId+",\"idx\":0}"); sb.Append("{\"err\":false,\"nodeId\":" + nodeId + ",\"nodeDesc\":\""+StringHelper.ConvertToJson( flow.GetNodeProperty(nodeId, "JDMC"))+"\",\"checkResult\":[{}"); GetNextNodes(flow.GetNodeProperty(nodeId, "XJJD"), recordId,1,nodeId,0); line.Append("]"); sb.Append("],\"childNodes\":"+line.ToString()+"}"); context.Response.Write(sb.ToString()); } private int GetID() { return seqid++; } public string GetNextNodes(string nodeList, string recordId,int parentLevel,string parentNodeId,int pidx) { int level = parentLevel + 1; string list = ""; getNextNodesCount++; if (getNextNodesCount > 200) { return list; } string s; string[] a = nodeList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] a2; string jdlb; int idx; for (int i = 0; i < a.Length;i++ ) { jdlb = flow.GetNodeProperty(a[i], "JDLB"); if (jdlb == "3") { idx = GetID(); //鉴别节点 sb.Append(",{\"idx\":"+idx.ToString()+",\"pidx\":"+pidx.ToString()+",\"level\":"+level+",\"nodeId\":\"" + a[i] + "\",\"nodeDesc\":\"" + StringHelper.ConvertToJson( flow.GetNodeProperty(a[i], "JDMC")) + "\",\"condition\":\"鉴别节点\",\"result\":null,\"err\":false}"); //s = GetNextNodes(GetNodeProperty(a[i], "XJJD"), recordId); s = GetDecisionNodeNext(a[i], recordId,level,parentNodeId,idx); if(s!="") list += "," + s; }else if (jdlb == "4") { idx = GetID(); sb.Append(",{\"idx\":"+idx.ToString()+",\"pidx\":"+pidx.ToString()+",\"level\":"+level+",\"nodeId\":\"" + a[i] + "\",\"nodeDesc\":\"" + StringHelper.ConvertToJson(flow.GetNodeProperty(a[i], "JDMC")) + "\",\"condition\":\"判断节点\",\"result\":null,\"err\":false}"); s = GetNextNodes(flow.GetNodeProperty(a[i], "XJJD"), recordId,level,parentNodeId,idx); //s = GetNextNodes(s, recordId); if (s != "") { list += "," + s; } } else { line.Append(",{\"desc\":\""+flow.GetNodeProperty(a[i], "JDMC") + "[" + a[i] + "]\",\"parent\":"+parentNodeId+",\"id\":"+a[i]+"}"); list += "," + a[i]; //sb.Append(",{\"level\":"+level+",\"nodeId\":\""+ a[i]+"\",\"nodeDesc\":\""+flow.GetNodeProperty(a[i], "JDMC")+"\",\"condition\":\"普通节点\",\"result\":null,\"err\":false}"); GetNodeUsers("发送", recordId, flowId, a[i],level,pidx); GetNextNodes(flow.GetNodeProperty(a[i], "XJJD"), recordId, level,a[i],pidx); } } if (list != "") list = list.Substring(1); return list; } public string GetDecisionNodeNext(string nodeId,string recordId,int parentLevel,string parentNodeId,int pidx) { int level = parentLevel + 1; bool isElse = (StringHelper.GetParamValue(flow.GetNodeProperty(nodeId, "param"), "else") == "1"); string s=""; string sql=""; string sql2 = ""; int idx; try { DataTable dt = dataManager.DmExecuteTable("select FZTJ,XJJDID from COM_LCFZTJB where LCID=" + flow.FlowID + " and JDID=" + nodeId + " order by xh"); int c = dt.Rows.Count; bool b; string defaultnode = ""; string nid; bool result=false; for (int i = 0; i < c; i++) { sql = dt.Rows[i][0].ToString(); sql2 = getJson(sql); nid = dt.Rows[i][1].ToString(); idx = GetID(); if (sql == "") { s = "," + nid; sb.Append(",{\"idx\":" + idx.ToString() + ",\"pidx\":" + pidx.ToString() + ",\"level\":" + level + ",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\"分支节点(" + StringHelper.ConvertToJson((i+1)+" / "+c) + "):" + flow.GetNodeProperty(nid, "JDMC") + "\",\"condition\":\"\",\"result\":true,\"err\":false}"); break; } else if (sql.ToLower()=="default") { //defaultnode = nid; //sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\""+flow.GetNodeProperty(nodeId, "JDMC")+"["+nodeId+"]分支节点("+(i+1)+"/"+c+"):"+flow.GetNodeProperty(nid, "JDMC")+"\",\"condition\":\"default\",\"result\":true,\"err\":false}"); //GetNextNodes(nid, recordId,level,parentNodeId); } else { b = ValidateCondition(recordId, sql); if (b) { result = true; s += "," + dt.Rows[i][1].ToString(); sb.Append(",{\"idx\":" + idx.ToString() + ",\"pidx\":" + pidx.ToString() + ",\"level\":" + level + ",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\"分支节点(" + StringHelper.ConvertToJson((i + 1) + " / " + c) + "):" + flow.GetNodeProperty(nid, "JDMC") + "\",\"condition\":\"条件: " +StringHelper.ConvertToJson( sql2) + "\",\"result\":true,\"err\":false}"); GetNextNodes(dt.Rows[i][1].ToString(), recordId,level,parentNodeId,idx); } else { sb.Append(",{\"idx\":" + idx.ToString() + ",\"pidx\":" + pidx.ToString() + ",\"level\":" + level + ",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\"分支节点(" + StringHelper.ConvertToJson((i + 1) + " / " + c) + "):" + flow.GetNodeProperty(nid, "JDMC") + "\",\"condition\":\"条件: " + StringHelper.ConvertToJson(sql2) + "\",\"result\":false,\"err\":false}"); } if (isElse && b) { break; } } } for (int i = 0; i < c; i++) { sql = dt.Rows[i][0].ToString(); nid = dt.Rows[i][1].ToString(); if (sql.ToLower() == "default") { idx = GetID(); defaultnode = nid; if (!result) { sb.Append(",{\"idx\":" + idx.ToString() + ",\"pidx\":" + pidx.ToString() + ",\"level\":" + level + ",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\"分支节点((" + StringHelper.ConvertToJson((i + 1) + " / " + c) + ")):" + flow.GetNodeProperty(nid, "JDMC") + "\",\"condition\":\"default\",\"result\":true,\"err\":false}"); GetNextNodes(nid, recordId, level, parentNodeId,idx); } else { sb.Append(",{\"idx\":" + idx.ToString() + ",\"pidx\":" + pidx.ToString() + ",\"level\":" + level + ",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\"" + StringHelper.ConvertToJson( flow.GetNodeProperty(nodeId, "JDMC")) + "[" + nodeId + "]分支节点(" + StringHelper.ConvertToJson((i + 1) + " / " + c) + "):" + StringHelper.ConvertToJson( flow.GetNodeProperty(nid, "JDMC")) + "\",\"condition\":\"default\",\"result\":false,\"err\":false}"); } } } if (s != "") s = s.Substring(1); else s = defaultnode; } catch (Exception e) { //throw new Exception("节点ID" + nodeId + "鉴别条件错误!"); idx = GetID(); sb.Append(",{\"idx\":"+idx.ToString()+",\"pidx\":"+pidx.ToString()+",\"level\":"+level+",\"nodeId\":\"" + nodeId + "\",\"nodeDesc\":\""+StringHelper.ConvertToJson( flow.GetNodeProperty(nodeId, "JDMC"))+"\",\"condition\":\""+ StringHelper.ConvertToJson( sql2)+"\",\"result\":false,\"err\":true}"); } return s; } public string getJson(string s) { string r = s.Replace("\r", " "); r = r.Replace("\n", " "); r = r.Replace("<","<"); r = r.Replace(">",">"); r = r.Replace("\"","""); return r; } public bool ValidateCondition(string recordId, string sqlWhere) { bool b = false; if (sqlWhere == "") { b = true; sqlWhere = "1=1"; } else { sqlWhere = inst.Tag.ReplaceExpression(sqlWhere,""); } if(!b) { string sql = "Select count(*) From " + inst.Program.EditTableName + " Where " + inst.Program.PrimaryKey + "='" + recordId + "' and (" + sqlWhere + ")"; if (inst.BusinessDataManager.DmExecuteTable(sql).Rows[0][0].ToString() != "0") { b = true; } } return b; } public void GetNodeUsers(string sendType, string recordId, string flowId, string nodeId,int level,int pidx) { string u = ""; string s,s2; DataTable dt = null; string sql="1=1"; string gltj,gllx; string userInfo = StringHelper.GetParamValue(flow.GetNodeProperty(nodeId, "PARAM"), "UserInfo"); int i,c,idx; DataRow reader = null; if (sendType == "退回" && flow.GetNodeProperty(nodeId, "JDLB") == "2") { dt = dataManager.DmExecuteTable("select b.id,b.xingming ,b.gw from xt_lcsl_hq a,com_yhb b where a.nt=3 and a.ryid=b.id and a.jlid=" + recordId + " and a.jd1=" + nodeId + " and zt=1"); Item item = null; c = dt.Rows.Count; for (i = 0; i < c;i++ ) { reader = dt.Rows[i]; item = new Item(); item.Value = reader[0].ToString(); if (userInfo == "1") item.Text = reader[1].ToString() + "(" + reader[2].ToString() + ")"; else item.Text = reader[1].ToString(); u+=(u==""?"":"、")+reader[1].ToString(); } } else { gltj = flow.GetNodeProperty(nodeId, "GLTJ"); gllx = flow.GetNodeProperty(nodeId, "GLLX"); switch(gllx) { case "单位名称": //""; gltj = " and u.id in (select zztable1.renyuan_id from " + inst.Program.EditTableName + " businesstable,com_yhb_zz zztable1,com_ybh_zz zztable2 where businesstable." + inst.Program.PrimaryKey + "='" + recordId + "' and zztable1.keshi_id=zztable2.keshi_id and zztable2.keshi_mc=businesstable." + gltj + ")"; break; case "单位ID": gltj = " and u.id in (select zztable1.renyuan_id from " + inst.Program.EditTableName + " businesstable,com_yhb_zz zztable1 where businesstable." + inst.Program.PrimaryKey + "='" + recordId + "' and zztable1.keshi_id=businesstable." + gltj + ")"; break; case "人员姓名": gltj = " and u.id in (select zztable1.id from " + inst.Program.EditTableName + " businesstable,com_yhb zztable1 where businesstable." + inst.Program.PrimaryKey + "='" + recordId + "' and zztable1.xingming=businesstable." + gltj + ")"; break; case "人员ID": gltj = " and u.id in (select zztable1.id from " + inst.Program.EditTableName + " businesstable,com_yhb zztable1 where businesstable." + inst.Program.PrimaryKey + "='" + recordId + "' and zztable1.id=businesstable." + gltj + ")"; break; case "自定义": if (gltj != "") { gltj = " and u.id in (" + gltj.Replace("$userid", STARTOPERATOR(recordId)) + ")"; gltj = gltj.Replace("$recordid", recordId); } break; case "本人": if (gltj != "") gltj = " and u.id in (" + gltj.Replace("$userid", STARTOPERATOR(recordId)) + ")"; break; default: if (gltj != "") { gltj = "select a.renyuan_id from com_yhb_zz a ,com_yhb_zz b where a.keshi_id =b.keshi_id and b.renyuan_id=" + STARTOPERATOR(recordId) + " and b.zzdm='" + gltj + "'"; gltj = " and u.id in (" + gltj + ")"; } break; } try { sql = "select distinct u.id,u.xingming,u.gw from com_yhb u ,COM_YHGWDZB r,com_lc_jdyhb f where f.gwid=r.gangwei_id and f.lcid=" + flowId + " and f.jdid=" + nodeId + " and f.lx=0 and u.id=r.renyuan_id " + gltj + " order by u.xingming"; dt = dataManager.DmExecuteTable(sql); Item item = null; c = dt.Rows.Count; for (i = 0; i < c; i++) { reader = dt.Rows[i]; item = new Item(); item.Value = reader[0].ToString(); if (userInfo == "1") { sql = reader[2].ToString(); item.Text = reader[1].ToString() + (sql == "" ? "" : "(" + sql + ")"); } else { item.Text = reader[1].ToString(); } u+=(u==""?"":"、")+reader[1].ToString(); } if (u.Length > 40) u = u.Substring(40) + "..."; s = getJson(gltj); if (u == "") s2 = "true"; else s2 = "false"; if (flow.GetNodeProperty(nodeId, "XJJD") == "") s2 = "false"; idx = GetID(); sb.Append(",{\"idx\":"+idx.ToString()+",\"pidx\":"+pidx.ToString()+",\"level\":"+level+",\"nodeId\":\""+nodeId+"\",\"nodeDesc\":\""+StringHelper.ConvertToJson( flow.GetNodeProperty(nodeId, "JDMC"))+"["+nodeId+"]待办接收人:"+u+"\",\"condition\":\"过滤:["+gllx+"]"+s+"\",\"result\":"+(u==""?"false":"true")+",\"err\":"+s2+",\"users\":\""+u+"\",\"nodeType\":\"user\"}"); } catch (Exception e) { //throw new Exception("获取人员列表错误!(过滤类型:"+gllx +" 过滤条件:"+ gltj+")"); s = getJson(gltj); idx = GetID(); sb.Append(",{\"idx\":"+idx.ToString()+",\"pidx\":"+pidx.ToString()+",\"level\":"+level+",\"nodeId\":\""+ nodeId+"\",\"nodeDesc\":\"错误\",\"condition\":\"过滤:["+gllx+"]"+s+"\",\"result\":false,\"err\":true,\"nodeType\":\"user\"}"); } } } public string STARTOPERATOR(string recordId) { if (startoperator == null) { string sql = "select STARTOPERATOR from XT_LCSL where JLID=" + recordId; DataTable xt_lcsl = dataManager.ExecuteTable(sql); startoperator = xt_lcsl.Rows[0][0].ToString(); } return startoperator; } public bool IsReusable { get { return false; } } }