<%@ WebHandler Language="C#" Class="CustomPageDisplay" %> using System; using System.Collections.Generic; using System.Web; using System.Data; using System.IO; using eMIS.Data; using System.Data.Common; using System.Web.SessionState; using eMIS; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; public class CustomPageDisplay : IHttpHandler, IRequiresSessionState { private string wwwroot; private string recordId; private int recordCount; private int recordPosition; private string menuId; private string templateId; private string displayToolbar; private bool isTab=false; private string tabName; private string userId; private HttpContext context; private string rnd = DateTime.Now.Ticks.ToString(); public void ProcessRequest (HttpContext context) { bool tools = true; this.context = context; if (context.Session["userid"] == null) { LoginManager lm = new LoginManager(context); if (!lm.VerifyIdentity()) { //context.Response.Write("会话丢失,请重新登陆!"); //context.Response.End(); //token=B06D9D344A389DC782B5E1A7F01E4583D777EF54A56607984193D6E447202410 if (context.Request.QueryString["token"] != null) { string[] a = DataManager.Decrypt( context.Request.QueryString["token"].ToString()).Split(','); lm.Login(a[0]); tools = false; } else { context.Response.Write("会话丢失,请重新登陆!"); context.Response.End(); } } } userId = context.Session["userid"].ToString(); bool b = false; wwwroot = context.Request.ApplicationPath; string url = ""; if (wwwroot == "/") wwwroot = ""; StringBuilder sb = new StringBuilder(); DataManager dm = new DataManager(); menuId = context.Request.QueryString["proid"].ToString(); recordId = context.Request.QueryString["recid"].ToString(); displayToolbar = (context.Request.QueryString["toolbar"] == null ? "" : context.Request.QueryString["toolbar"].ToString()); string flowId = (context.Request.QueryString["lcid"] == null ? "" : context.Request.QueryString["lcid"].ToString()); if (flowId != "") { FlowManager flow = new FlowManager(flowId, dm); string objectId = flow.BusinessObjectID; BusinessObjectManager bom = new BusinessObjectManager(dm, objectId); menuId = bom.MenuID; } string f = (context.Request.QueryString["f"]==null?"":context.Request.QueryString["f"].ToString()); InstanceManager inst = new InstanceManager(context,dm,menuId); if (recordId == "" && context.Request.QueryString["position"] != null) { recordPosition= int.Parse(context.Request.QueryString["position"].ToString()); inst.RecordPosition = recordPosition; recordId = inst.PrimaryKeyValue; } else { inst.PrimaryKeyValue = recordId; recordPosition = 1;// inst.RecordPosition; } //context.Response.Write(inst.PrimaryKeyValue); // context.Response.End(); recordCount = 1;// inst.RecordCount; templateId = inst.Program.Properties["DZBJYM"].ToString(); tabName = inst.Program.EditPageTabName; isTab = ( tabName!= ""); if (inst.EditDataRow == null) { context.Response.Write("记录已删除!"); context.Response.End(); } inst.Tag.BusinessDataRow = inst.EditDataRow; if (templateId != "") { string r0=""; if (templateId == "1") { r0 = context.Server.MapPath(wwwroot + "/App_Web/Programs/"+inst.ProgramID+"/template.htm"); } else { DbDataReader reader = inst.SystemDbOperator.ExecuteReader("Select MBLJ,LX,MBMS From COM_ZDYMBB where ID=" + templateId); string r1 = ""; if (reader.Read()) { r1 = reader[1].ToString(); r0 = reader[0].ToString(); } reader.Close(); if (r1 == "程序") { context.Response.Redirect(wwwroot + r0 + (r0.IndexOf("?") == -1 ? "?" : "&") + "id=" + recordId + "&pid=" + menuId + "&recordcount=" + recordCount.ToString() + "&position=" + recordPosition + "&r=" + DateTime.Now.Ticks.ToString()); } r0 = context.Server.MapPath(wwwroot + "/App_Web/Template/" + r0); } sb.Append(""); sb.Append(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); if(displayToolbar!="0" && tools) WriteToolBar(sb); WriteCustomPage(context,sb,inst, r0); //if (isTab) //{ // sb.Append("
"); // subprogs3div(sb, inst); //} sb.Append(""); context.Response.Write(sb.ToString()); } else { int controlCount = inst.EditControls.Count; ControlManager cm = null; JObject json = JsonConvert.DeserializeObject("{" + inst.Program.Properties["json"].ToString() + "}"); JObject uicfg = (JObject)json["display"]; bool flowlog = false; if (uicfg != null) { if (uicfg["flowlog"] != null) { flowlog = uicfg["flowlog"].ToString()=="1"; } } int total_cols = 2; bool ui_border = true; bool ui_columns = false; bool ui_subtab = true; JObject editcfg = (JObject)json["edit"]; string desc_width = "120px"; if (editcfg != null) { if (editcfg["columns"] != null) { total_cols = int.Parse(editcfg["columns"].ToString()); ui_columns = true; } if (editcfg["border"] != null) { //ui_border = editcfg["border"].ToString() == "1"; } if (editcfg["subtab"] != null) { ui_subtab = editcfg["subtab"].ToString() == "1"; } } sb.Append(""); sb.Append(""); sb.Append("" + inst.Program.Properties["bt"].ToString()+ ""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); if (displayToolbar != "0") WriteToolBar(sb); sb.Append("
"); sb.Append("
"); int control_cols = 1; int control_rows = 1; int cur_col_idx = 0; int cur_cols=1, cur_rows; string default_size_c; string default_size_r; int ii, iii=-1; int item_width = 100 / total_cols; int colnum = 0, colspan; string w; sb.Append("
"+inst.Program.Properties["bt"].ToString()+"
"); sb.Append(""); for (int i = 0; i < controlCount; i++) { cm = inst.EditControls[i]; cm.PageType = 3; if (!cm.IsHidden) { default_size_c = (cm.ControlType == "4"||cm.ControlType == "42"||cm.ControlType == "140" ? "2" : "1"); default_size_r= (cm.ControlType == "4"||cm.ControlType == "42" ? "3" : "1"); cur_cols = int.Parse(GetStyle(cm.ControlStyle, "colspan", default_size_c)); cur_rows = int.Parse(GetStyle(cm.ControlStyle, "rowspan", default_size_r)); cur_col_idx += cur_cols; if (colnum==0) sb.Append(""); colnum += cur_cols; sb.Append(""); if (colnum >= total_cols) { sb.Append(""); colnum = 0; } } } //context.Response.Write(cur_col_idx); //context.Response.End(); cur_cols = (cur_col_idx % total_cols); //context.Response.Write(cur_cols); //context.Response.End(); if (cur_cols != 0) { cur_cols = total_cols - cur_cols; sb.Append(""); sb.Append(""); } sb.Append("
"); sb.Append(cm.ControlDescription); w = (Convert.ToDouble(cur_cols) / Convert.ToDouble(total_cols) * 100).ToString("0"); colspan = cur_cols * 2 - 1; sb.Append(""); cm.GetDisplayHtml(sb); sb.Append("
"); sb.Append(""); sb.Append("
"); sb.Append("
"); //if (isIP) //oPage.WriteSubprogramsRO("全部"); //else //inst.AppendSubprogramsHtml(sb, "all"); subprogs2(context,sb, inst, "all"); sb.Append("
"); if (flowlog || menuId == "652824400") { sb.Append("
流程日志
"); inst.WriteFlowLogs(sb, "", "1"); sb.Append("
"); } sb.Append(""); context.Response.Write(sb.ToString()); } if (url != "") context.Response.Redirect(url); } private string GetStyle(string style, string name,string def) { string r=def; int i = style.IndexOf(name); if (i == -1) return r; style += ";"; i = style.IndexOf(":", i); int j = style.IndexOf(";",i); r = style.Substring(i+1, j - i-1); return r; } private string getfilename(string url) { int i = url.LastIndexOf("/"); return url.Substring(i+1); } private string GetWidth(string style) { string s = style.ToLower() + ";"; int i = s.IndexOf("width:"); if (i == -1) return ""; s = s.Substring(i, s.IndexOf(";", i) - i+1); return s; } private string GetTextAlign(string style) { string s = style.ToLower() + ";"; int i = s.IndexOf("text-align:"); if (i == -1) return ""; s = s.Substring(i, s.IndexOf(";", i) - i + 1); return s; } private void WriteToolBar(StringBuilder sb) { sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.Append("
"); sb.Append("
"); sb.Append(""); if (false && recordPosition != 1) { sb.Append(""); sb.Append(""); } if (false && recordCount != recordPosition) { sb.Append(""); sb.Append(""); } sb.Append(""); // sb.Append(""); // sb.Append(""); sb.Append(""); sb.Append(""); // sb.Append(""); // sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append("
"); sb.Append("
上一条
|"); sb.Append("
下一条
|"); sb.Append("
打印
|"); // sb.Append("
预览
|"); sb.Append("
刷新
|"); // sb.Append("
另存
|"); sb.Append("
导出PDF
|"); sb.Append("
关闭
  
"); } private void WriteCustomPage(HttpContext context,StringBuilder sb,InstanceManager instance,string templatePath) { StreamReader sr = new StreamReader(templatePath, Encoding.GetEncoding("utf-8")); string line; int beginPosition; int endPosition; int findPoistion; DataTable elements = instance.Program.EditElements; ControlManager control = null; string ms, str,fff; string[] a; int i; bool b = false; bool b2 = false; string s; while (!sr.EndOfStream) { line = sr.ReadLine(); line = line.Replace("<", "<"); line = line.Replace(">", ">"); findPoistion = 0; while (true) { beginPosition = line.IndexOf("<#"); if (beginPosition == -1) { sb.Append(line.Substring(0)); break; } sb.Append(line.Substring(0,beginPosition)); endPosition = line.IndexOf("#>"); ms = line.Substring(beginPosition+2, endPosition - beginPosition - 2); line = line.Substring(endPosition+2); if (instance.EditControlDescriptionIndex.ContainsKey(ms)) { control = instance.EditControls[instance.EditControlDescriptionIndex[ms]]; control.Display = true; control.GetDisplayHtml(sb); } else { ms = ms.ToUpper(); if (ms.IndexOf("IF") != -1) ms = StringHelper.GetRightString(ms); str = ""; if (ms.IndexOf("GLCX3") != -1) { b = true; //subprogs3(StringHelper.GetRightString(ms)); } else if (ms.IndexOf("TABGLCX") != -1) { //subprogs2(sb, instance, StringHelper.GetRightString(ms)); //b2 = true; } else if (ms.IndexOf("GLCX") != -1) { subprogs2(context,sb, instance, StringHelper.GetRightString(ms)); b2 = true; } else if (ms.IndexOf("FLOWLOGS") != -1) { instance.WriteFlowLogs(sb,StringHelper.GetRightString(ms),"1"); } else if(ms.IndexOf("FLOW") != -1) { sb.Append(instance.GetFlowLog(StringHelper.GetRightString(ms))); } } findPoistion = endPosition + 2; } } sr.Close(); if (b) instance.Context.Response.Write(""); if (b2) instance.Context.Response.Write(""); } private void subprogs3tab(StringBuilder sb, InstanceManager instance) { DataRow row = null; string subprogid, xml, iframesrc, s, s2; int l = instance.Program.Subprograms.Rows.Count; sb.Append(""); if (isTab) sb.Append(""); int i; for (i = 0; i < l; i++) { row = instance.Program.Subprograms.Rows[i]; sb.Append(""); } sb.Append("
" + instance.Program.EditPageTabName + "" + row["glms"].ToString() + "
"); } private void subprogs3div(HttpContext context,StringBuilder sb, InstanceManager instance,InstanceManager parentInst) { DataRow row = null; string subprogid, xml, iframesrc,s,s2; int l = instance.Program.Subprograms.Rows.Count; for (int i = 0; i < l; i++) { row = instance.Program.Subprograms.Rows[i]; if (tabName.IndexOf(row["glms"].ToString()) != -1) { subprogid = row["glcxid"].ToString(); xml = row["xml"].ToString(); if (subprogid == "") { iframesrc = row["glcxmc"].ToString(); iframesrc = instance.Tag.ReplaceExpression(iframesrc, "colval"); sb.Append(""); } else { s = StringHelper.GetXmlValue(xml, "外键") + "='" + instance.EditDataRow[StringHelper.GetXmlValue(xml, "主键")].ToString() + "'"; s2 = row["gltj"].ToString(); s2 = parentInst.Tag.ReplaceExpression(s2, "COLVAL"); s2 = getJSTJ(instance.SystemDataManager,s2,subprogid,userId); if (s2 != "") s += " and (" + s2 + ")"; sb.Append("
"); if (StringHelper.GetXmlValue(xml, "同页编辑") == "1") getSubList2(context,sb, instance, subprogid, s); else getSubList1(sb, instance, subprogid, s); sb.Append("
"); } } } } private string getJSTJ(DataManager dm, string cond, string glcxid,string userid) { string s = cond; string s2; DataTable tj = dm.ExecuteTable("select TJ from COM_XTCDB_JSTJ a,COM_YHGWDZB b,COM_XTCDB c where a.caidan_id=c.id and c.cxid="+glcxid+" and a.gangwei_id=b.gangwei_id and b.renyuan_id=" + userid + " order by a.cx"); if (tj.Rows.Count != 0) { s2 = tj.Rows[0][0].ToString(); if(s2!="") s += (s == "" ? "" : " and ") + "("+s2+")"; } return s; } private void subprogs2(HttpContext context,StringBuilder sb,InstanceManager instance,string idx) { int l; int i; DataRow row =null; string s; string s2; string subprogid; string iframesrc; string c; string xml; if(int.TryParse(idx,out l)) { row = instance.Program.Subprograms.Rows[l-1]; xml = row["xml"].ToString(); c = row["gltj"].ToString(); c = instance.Tag.ReplaceExpression(c, "COLVAL"); c = getJSTJ(instance.SystemDataManager,c,row["glcxid"].ToString(),userId); s = StringHelper.GetXmlValue(xml, "外键"); if (s == "") s = "<#primarykey#>"; if (c == "") c = s + "='" + instance.EditDataRow[StringHelper.GetXmlValue(xml, "主键")].ToString() + "'"; else c += " and " + s + "='" + instance.EditDataRow[StringHelper.GetXmlValue(xml, "主键")].ToString() + "'"; s = StringHelper.GetXmlValue(xml, "同页编辑"); if(s=="1") getSubList2(context,sb, instance, row["glcxid"].ToString(), c); else if(s=="4") getSubList4(sb, instance, row["glcxid"].ToString(), c); else getSubList1(sb, instance, row["glcxid"].ToString(), c); } else { l = instance.Program.Subprograms.Rows.Count; if(l==0) return ; //sb.Append("
"); for(i=0;i