%@ WebHandler Language="C#" Class="EditData3" %>
using System;
using eMIS;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web.SessionState;
public class EditData3 : IHttpHandler, IRequiresSessionState
{
private HttpContext context = null;
public void ProcessRequest(HttpContext context)
{
if (context.Session["userid"] == null)
{
LoginManager lm = new LoginManager(context);
//lm.Login("40001");
if (!lm.VerifyIdentity())
{
context.Response.Write("会话丢失,请重新登陆!");
context.Response.End();
}
}
this.context = context;
string wwwroot = context.Request.ApplicationPath;
if (wwwroot == "/") wwwroot = "";
StringBuilder finalresult = new StringBuilder();
//string themePath = wwwroot + "/Themes/" + context.Session["Theme"].ToString();
string menuId = context.Request["proid"].ToString();
string recordId = context.Request["varSign"] == null ? "" : context.Request["varSign"].ToString();
string recordId2 = (context.Request["mrid"] == null ? "" : context.Request["mrid"].ToString());
string buttonId = context.Request["buttonId"] == null ? "4" : context.Request["buttonId"].ToString();
//打开模板
string s = context.Server.MapPath("EditData3.htm");
System.IO.StreamReader sr = new System.IO.StreamReader(s, Encoding.GetEncoding("utf-8"));
string tempstr = sr.ReadToEnd();
sr.Close();
//bool isIP = (context.Session["ismobile"].ToString() == "1");
int i;
//string userId = context.Session["userid"].ToString();
string userCnName = context.Session["usercnname"].ToString();
string rndstr = DateTime.Now.ToString();
DataManager dm = new DataManager();
InstanceManager inst = new InstanceManager(context, dm, menuId);
inst.IsMobileDevice = true;
inst.PrimaryKeyValue = recordId;
inst.Ver = "201706";
inst.ControlTemplates=GetTemplateList(tempstr);
bool multiRowEdit = false;
if (recordId2 != "")
{
multiRowEdit = true;
}
ProgramManager program = inst.Program;
string programId = program.ID;
string[] a;
string flowId = "";
string nodeId = "";
DataTable dt = dm.ExecuteTable("select LCID,JDID from COM_XTCDB where ID=?",menuId);
nodeId = dt.Rows[0][1].ToString();
flowId =dt.Rows[0][0].ToString();
DataManager dataManager = new DataManager();
FlowManager flow = new FlowManager(flowId, dataManager);
string htjd = "";
if (nodeId != "")
{
htjd = flow.GetNodeProperty(nodeId, "HTJD");
}
string customUi = (multiRowEdit ? "" : program.Properties["DZBJYM"].ToString());
string bt = program.Properties["bt"].ToString();
//替换 ${CLIENT}
StringBuilder client = new StringBuilder();
inst.OutClientHeadHtml(client, customUi, userCnName);
inst.OutHiddenControlsHtml(client);
//var menucfg = { "menucfg": [{ "func": "DeleteData()", "desc": "删除" }, { "func": "EditSend()", "desc": "发送" }, { "func": "EditReturn()", "desc": "回退" }] };
client.Append("");
tempstr = tempstr.Replace("{{CLIENT}}",client.ToString());
tempstr = tempstr.Replace("{{MENUID}}",menuId);
/*********如果存在子表
finalresult.Append("" + bt + "");
* */
//int l = program.Subprograms.Rows.Count;
//int index = 2;
//for (i = 0; i < l; i++)
//{
// DataRow row = program.Subprograms.Rows[i];
// string xml = row["xml"].ToString();
// if (StringHelper.GetXmlValue(row["xml"].ToString(), "同页编辑") != "0")
// {
// finalresult.Append("
" + row["glms"].ToString()+ "");
// index++;
// }
//}
//if (inst.CustomListTemplatePath() == "")
//替换模板
StringBuilder sb = new StringBuilder();
try
{
AppendCustomPageHtml(inst, tempstr, sb);
}
catch (Exception exc)
{
context.Response.Write(exc.Message+exc.StackTrace);
context.Response.End();
}
finalresult.Append(sb);
context.Response.Write(finalresult.ToString());
}
/*
*/
public void AppendCustomPageHtml(InstanceManager inst,string tempstr,StringBuilder sb)
{
bool b = false;
string groupList;
int currIdx=0;
TagContent tc;
int i;
string groups= ",";
string s;
//获取全部的组名
for (i = 0; i < inst.EditControls.Count;i++)
{
s = ""; //inst.EditControls[i].GroupName;
if (s!="" && !groups.Contains("," + s + ","))
{
groups += s + ",";
}
}
if (groups == ",")
groups = "";
string[] a;
for(i=0;i<5;i++)
{
tc = GetTagContent(tempstr, "t-group",currIdx);
//获取当前组的组名过滤
groupList = GetProperty(tempstr, "group-list",currIdx);
if (groupList == "")
groupList = groups;
if (tc.BeginIndex == -1)
{
//输出剩余html
sb.Append(tempstr.Substring(currIdx));
break;
}
//输出前次位置到当前组标记前的html
sb.Append(tempstr.Substring(currIdx, tc.BeginIndex));
a = groupList.Split(',');
foreach (string group in a)
{
AppendGroupHtml(inst.EditControls, tc.Content, group, sb);
}
currIdx = tc.EndIndex;
}
}
//处理一个分组里的控件模板,组模板的循环在上层
public void AppendGroupHtml(IList elements, string groupTempStr,string groupName, StringBuilder sb)
{
int idx=0;
//获取当前分组里的所有控件模板
List elementTemplateList = GetElementTemplateList(groupTempStr);
foreach (ElementTemplate elementTemplate in elementTemplateList)
{
//输出到字符串
sb.Append(groupTempStr.Substring(idx, elementTemplate.Tag.BeginIndex-idx));
AppendElementsHtml(elements, elementTemplate, groupName,sb);
idx = elementTemplate.Tag.EndIndex;
}
//输出到字符串
sb.Append(groupTempStr.Substring(idx));
}
//获取分组内的控件模板数量
public List GetElementTemplateList(string groupTempStr)
{
List elementTemplateList = new List();
int idx=0;
TagContent tc;
ElementTemplate et;
string[] a;
for (int i = 1; i < 10; i++)
{
tc = GetTagContent(groupTempStr,"t-element",idx);
if (tc.BeginIndex == -1)
break;
et = new ElementTemplate();
et.Tag = tc;
a = GetProperty(groupTempStr, "desc-length-range", idx).Split(',');
et.ComboboxMaxCount = int.Parse(GetProperty(groupTempStr, "combobox-max-count", idx));
et.DescLengthRange[0] = int.Parse(a[0]);
et.DescLengthRange[1] = int.Parse(a[1]);
elementTemplateList.Add(et);
idx = tc.EndIndex;
}
return elementTemplateList;
}
private Dictionary GetTemplateList(string tempStr)
{
/*
*/
Dictionary templateList = new Dictionary();
int idx=0;
TagContent tc;
string templateId;
for (int i = 1; i < 10; i++)
{
tc = GetTagContent(tempStr,"template",idx);
if (tc.BeginIndex == -1)
break;
templateId = GetProperty(tempStr, "id", idx);
templateList.Add(templateId,tc.Content);
idx = tc.EndIndex;
}
return templateList;
}
public void AppendElementsHtml(IList elements, ElementTemplate elementTemplate, string groupName,StringBuilder sb)
{
ControlManager cm = null;
int count = elements.Count;
string desc;
string temp;
string controlType;
for (int i = 0; i < count; i++)
{
temp = elementTemplate.Tag.Content;
cm = elements[i];
desc = cm.ControlDescription;
if ((!cm.IsHidden) && (groupName=="" || groupName!="cm.GroupName") && desc.Length>=elementTemplate.DescLengthRange[0] && desc.Length<=elementTemplate.DescLengthRange[1])
{
controlType = cm.ControlType;
if (!cm.AllowNull)
desc += " *";
temp = temp.Replace("{{DESC}}", desc);
if (controlType == "36" && cm.Items.Count>elementTemplate.ComboboxMaxCount)
{
cm.ControlType = "2";
}
temp = temp.Replace("{{ELEMENT}}", cm.GetHtml());
sb.Append(temp);
}
}
}
public string GetProperty(string str,string name,int beginIndex)
{
int i = str.IndexOf(name+"=",beginIndex);
string pro = "";
if (i != -1)
{
i = i + name.Length + 2;
pro = str.Substring(i, str.IndexOf("\"",i) - i);
}
return pro;
}
public TagContent GetTagContent(string text,string tag,int startIndex)
{
TagContent tc = new TagContent();
string beginstr = "<" + tag + "";
string endstr = "" + tag + "";
tc.BeginIndex = text.IndexOf(beginstr, startIndex);
if (tc.BeginIndex != -1)
{
tc.BeginIndex = text.IndexOf(">", tc.BeginIndex) + 1;
tc.EndIndex = text.IndexOf(endstr, tc.BeginIndex);
if (tc.EndIndex != -1)
{
//tc.EndIndex = text.IndexOf(">",tc.EndIndex);
tc.Content = text.Substring(tc.BeginIndex, tc.EndIndex - tc.BeginIndex);
}
}
return tc;
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class TagContent
{
public int BeginIndex=-1;
public int EndIndex = -1;
public string Content = null;
}
public class ElementTemplate
{
public int ComboboxMaxCount = 4;
public string WhiteList = "";
public string BlackList = "";
public int[] DescLengthRange = new int[2]{ 0,999 };
public TagContent Tag = null;
}