<%@ 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 string startoperator=null; private string flowId=""; public void ProcessRequest (HttpContext context) { this.context = context; sb = new StringBuilder(); this.dataManager = new DataManager(); userId = "400955"; //context.Session["userid"].ToString(); flowId = context.Request.QueryString["fid"].ToString(); string recordId = context.Request.QueryString["rid"].ToString(); string nodeId = context.Request.QueryString["nid"]==null?"":context.Request.QueryString["nid"].ToString(); if (!DataManager.IsNumber(flowId) || !DataManager.IsNumber(recordId)) context.Response.End(); LoginManager lm = new LoginManager(context); lm.Login(userId); DataTable dt; 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; sb.Append("{\"err\":false,\"nodeId\":" + nodeId + ",\"nodeDesc\":\""+flow.GetNodeProperty(nodeId, "JDMC")+"\",\"checkResult\":[{}"); string nodeList = GetNextNodes(flow.GetNodeProperty(nodeId, "XJJD"), recordId,1); sb.Append("],\"childNode\":\""+nodeList+"\"}"); context.Response.Write(sb.ToString()); } public string GetNextNodes(string nodeList, string recordId,int parentLevel) { int level = parentLevel + 1; string list = ""; getNextNodesCount++; if (getNextNodesCount > 100) { return list; } string s; string[] a = nodeList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string[] a2; string jdlb; for (int i = 0; i < a.Length;i++ ) { jdlb = flow.GetNodeProperty(a[i], "JDLB"); if (jdlb == "3") { //鉴别节点 sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + a[i] + "\",\"nodeDesc\":\"" + flow.GetNodeProperty(a[i], "JDMC") + "\",\"condition\":\"鉴别节点\",\"result\":null,\"err\":false}"); //s = GetNextNodes(GetNodeProperty(a[i], "XJJD"), recordId); s = GetDecisionNodeNext(a[i], recordId,level); s=GetNextNodes(s, recordId,level); if(s!="") list += "," + s; }else if (jdlb == "4") { sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + a[i] + "\",\"nodeDesc\":\"" + flow.GetNodeProperty(a[i], "JDMC") + "\",\"condition\":\"判断节点\",\"result\":null,\"err\":false}"); s = GetNextNodes(flow.GetNodeProperty(a[i], "XJJD"), recordId,level); //s = GetNextNodes(s, recordId); if (s != "") { list += "," + s; } } else { 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+1); } } if (list != "") list = list.Substring(1); return list; } public string GetDecisionNodeNext(string nodeId,string recordId,int parentLevel) { int level = parentLevel + 1; bool isElse = (StringHelper.GetParamValue(flow.GetNodeProperty(nodeId, "param"), "else") == "1"); string s=""; string sql=""; 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; for (int i = 0; i < c; i++) { sql = dt.Rows[i][0].ToString(); nid = dt.Rows[i][1].ToString(); if (sql == "") { s = "," + nid; sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\""+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(nid, "JDMC")+"\",\"condition\":\"default\",\"result\":true,\"err\":false}"); } else { b = ValidateCondition(recordId, sql); if (b) { s += "," + dt.Rows[i][1].ToString(); sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\""+flow.GetNodeProperty(nid, "JDMC")+"\",\"condition\":\""+sql+"\",\"result\":true,\"err\":false}"); } else { sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + nid + "\",\"nodeDesc\":\""+flow.GetNodeProperty(nid, "JDMC")+"\",\"condition\":\""+sql+"\",\"result\":false,\"err\":false}"); } if (isElse && b) { break; } } } if (s != "") s = s.Substring(1); else s = defaultnode; } catch (Exception e) { //throw new Exception("节点ID" + nodeId + "鉴别条件错误!"); sb.Append(",{\"level\":"+level+",\"nodeId\":\"" + nodeId + "\",\"nodeDesc\":\""+flow.GetNodeProperty(nodeId, "JDMC")+"\",\"condition\":\""+sql+"\",\"result\":false,\"err\":true}"); } return s; } 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) { string u = ""; string s; DataTable dt = null; string sql="1=1"; string gltj,gllx; string userInfo = StringHelper.GetParamValue(flow.GetNodeProperty(nodeId, "PARAM"), "UserInfo"); int i,c; 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(); } s = gltj.Replace("\r"," "); s = s.Replace("\n"," "); sb.Append(",{\"level\":"+level+",\"nodeId\":\"\",\"nodeDesc\":\"发送:"+u+"\",\"condition\":\"过滤:["+gllx+"]"+s+"\",\"result\":"+(u==""?"false":"true")+",\"err\":false}"); } catch (Exception e) { //throw new Exception("获取人员列表错误!(过滤类型:"+gllx +" 过滤条件:"+ gltj+")"); s = gltj.Replace("\r"," "); s = s.Replace("\n"," "); sb.Append(",{\"level\":"+level+",\"nodeId\":\""+ nodeId+"\",\"nodeDesc\":\"错误\",\"condition\":\"过滤:["+gllx+"]"+s+"\",\"result\":false,\"err\":true}"); } } } 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; } } }