RoadFlow2.1 临时演示

Publish.ashx.cs 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.IO;
  6. using System.Web.SessionState;
  7. namespace WebForm.Platform.WorkFlowFormDesigner
  8. {
  9. /// <summary>
  10. /// Publish 的摘要说明
  11. /// </summary>
  12. public class Publish : IHttpHandler,IRequiresSessionState
  13. {
  14. public void ProcessRequest(HttpContext context)
  15. {
  16. context.Response.ContentType = "text/plain";
  17. string html = context.Request["html"];
  18. string name = context.Request["name"];
  19. string att = context.Request["att"];
  20. string id = context.Request["id"];
  21. Guid gid;
  22. if (!id.IsGuid(out gid) || name.IsNullOrEmpty() || att.IsNullOrEmpty() || html.IsNullOrEmpty())
  23. {
  24. context.Response.Write("参数错误!");
  25. return;
  26. }
  27. RoadFlow.Platform.WorkFlowForm WFF = new RoadFlow.Platform.WorkFlowForm();
  28. RoadFlow.Data.Model.WorkFlowForm wff = WFF.Get(gid);
  29. if (wff == null)
  30. {
  31. context.Response.Write("未找到表单!");
  32. return;
  33. }
  34. string fileName = id + ".aspx";
  35. System.Text.StringBuilder serverScript = new System.Text.StringBuilder("<%@ Page Language=\"C#\"%>\r\n<%\r\n");
  36. var attrJSON = LitJson.JsonMapper.ToObject(att);
  37. serverScript.Append("\tstring FlowID = Request.QueryString[\"flowid\"];\r\n");
  38. serverScript.Append("\tstring StepID = Request.QueryString[\"stepid\"];\r\n");
  39. serverScript.Append("\tstring GroupID = Request.QueryString[\"groupid\"];\r\n");
  40. serverScript.Append("\tstring TaskID = Request.QueryString[\"taskid\"];\r\n");
  41. serverScript.Append("\tstring InstanceID = Request.QueryString[\"instanceid\"];\r\n");
  42. serverScript.Append("\tstring DisplayModel = Request.QueryString[\"display\"] ?? \"0\";\r\n");
  43. serverScript.AppendFormat("\tstring DBConnID = \"{0}\";\r\n", attrJSON["dbconn"].ToString());
  44. serverScript.AppendFormat("\tstring DBTable = \"{0}\";\r\n", attrJSON["dbtable"].ToString());
  45. serverScript.AppendFormat("\tstring DBTablePK = \"{0}\";\r\n", attrJSON["dbtablepk"].ToString());
  46. serverScript.AppendFormat("\tstring DBTableTitle = \"{0}\";\r\n", attrJSON["dbtabletitle"].ToString());
  47. serverScript.Append("if(InstanceID.IsNullOrEmpty()){InstanceID = Request.QueryString[\"instanceid1\"];}");
  48. serverScript.Append("\tRoadFlow.Platform.Dictionary BDictionary = new RoadFlow.Platform.Dictionary();\r\n");
  49. serverScript.Append("\tRoadFlow.Platform.WorkFlow BWorkFlow = new RoadFlow.Platform.WorkFlow();\r\n");
  50. serverScript.Append("\tRoadFlow.Platform.WorkFlowTask BWorkFlowTask = new RoadFlow.Platform.WorkFlowTask();\r\n");
  51. serverScript.Append("\tstring fieldStatus = BWorkFlow.GetFieldStatus(FlowID, StepID);\r\n");
  52. serverScript.Append("\tLitJson.JsonData initData = BWorkFlow.GetFormData(DBConnID, DBTable, DBTablePK, InstanceID, fieldStatus);\r\n");
  53. serverScript.Append("\tstring TaskTitle = BWorkFlow.GetFromFieldData(initData, DBTable, DBTableTitle);\r\n");
  54. serverScript.Append("%>\r\n");
  55. serverScript.Append("<link href=\"Scripts/Forms/flowform.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n");
  56. serverScript.Append("<script src=\"Scripts/Forms/common.js\" type=\"text/javascript\" ></script>\r\n");
  57. if (attrJSON.ContainsKey("hasEditor") && "1" == attrJSON["hasEditor"].ToString())
  58. {
  59. serverScript.Append("<script src=\"../../Scripts/Ueditor/ueditor.config.js\" type=\"text/javascript\" ></script>\r\n");
  60. serverScript.Append("<script src=\"../../Scripts/Ueditor/ueditor.all.min.js\" type=\"text/javascript\" ></script>\r\n");
  61. serverScript.Append("<script src=\"../../Scripts/Ueditor/lang/zh-cn/zh-cn.js\" type=\"text/javascript\" ></script>\r\n");
  62. serverScript.Append("<input type=\"hidden\" id=\"Form_HasUEditor\" name=\"Form_HasUEditor\" value=\"1\" />\r\n");
  63. }
  64. string validatePropType = attrJSON.ContainsKey("validatealerttype") ? attrJSON["validatealerttype"].ToString() : "2";
  65. serverScript.Append("<input type=\"hidden\" id=\"Form_ValidateAlertType\" name=\"Form_ValidateAlertType\" value=\"" + validatePropType + "\" />\r\n");
  66. if (attrJSON.ContainsKey("autotitle") && attrJSON["autotitle"].ToString().ToLower() == "true")
  67. {
  68. serverScript.AppendFormat("<input type=\"hidden\" id=\"{0}\" name=\"{0}\" value=\"{1}\" />\r\n",
  69. string.Concat(attrJSON["dbtable"].ToString(), ".", attrJSON["dbtabletitle"].ToString()),
  70. "<%=TaskTitle.IsNullOrEmpty() ? BWorkFlow.GetAutoTaskTitle(FlowID, StepID, Request.QueryString[\"groupid\"]) : TaskTitle %>"
  71. );
  72. }
  73. serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_TitleField\" name=\"Form_TitleField\" value=\"{0}\" />\r\n", string.Concat(attrJSON["dbtable"].ToString(), ".", attrJSON["dbtabletitle"].ToString()));
  74. //serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_Name\" name=\"Form_Name\" value=\"{0}\" />\r\n", attrJSON["name"].ToString());
  75. serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_DBConnID\" name=\"Form_DBConnID\" value=\"{0}\" />\r\n", attrJSON["dbconn"].ToString());
  76. serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_DBTable\" name=\"Form_DBTable\" value=\"{0}\" />\r\n", attrJSON["dbtable"].ToString());
  77. serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_DBTablePk\" name=\"Form_DBTablePk\" value=\"{0}\" />\r\n", attrJSON["dbtablepk"].ToString());
  78. serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_DBTableTitle\" name=\"Form_DBTableTitle\" value=\"{0}\" />\r\n", attrJSON["dbtabletitle"].ToString());
  79. serverScript.AppendFormat("<input type=\"hidden\" id=\"Form_AutoSaveData\" name=\"Form_AutoSaveData\" value=\"{0}\" />\r\n", "1");
  80. serverScript.Append("<script type=\"text/javascript\">\r\n");
  81. serverScript.Append("\tvar initData = <%=BWorkFlow.GetFormDataJsonString(initData)%>;\r\n");
  82. serverScript.Append("\tvar fieldStatus = \"1\"==\"<%=Request.QueryString[\"isreadonly\"]%>\"? {} : <%=fieldStatus%>;\r\n");
  83. serverScript.Append("\tvar displayModel = '<%=DisplayModel%>';\r\n");
  84. serverScript.Append("\t$(window).load(function (){\r\n");
  85. serverScript.AppendFormat("\t\tformrun.initData(initData, \"{0}\", fieldStatus, displayModel);\r\n", attrJSON["dbtable"].ToString());
  86. serverScript.Append("\t});\r\n");
  87. serverScript.Append("</script>\r\n");
  88. string file = context.Server.MapPath("Forms/" + fileName);
  89. System.IO.Stream stream = System.IO.File.Open(file, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
  90. stream.SetLength(0);
  91. StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8);
  92. sw.Write(serverScript.ToString());
  93. sw.Write(context.Server.HtmlDecode(html));
  94. sw.Close();
  95. stream.Close();
  96. string attr = wff.Attribute;
  97. string appType = LitJson.JsonMapper.ToObject(attr)["apptype"].ToString();
  98. RoadFlow.Platform.AppLibrary App = new RoadFlow.Platform.AppLibrary();
  99. var app = App.GetByCode(id);
  100. bool isAdd = false;
  101. if (app == null)
  102. {
  103. app = new RoadFlow.Data.Model.AppLibrary();
  104. app.ID = Guid.NewGuid();
  105. app.Code = id;
  106. isAdd = true;
  107. }
  108. app.Address = "/Platform/WorkFlowFormDesigner/Forms/" + fileName;
  109. app.Note = "流程表单";
  110. app.OpenMode = 0;
  111. app.Params = "";
  112. app.Title = name.Trim();
  113. app.Type = appType.IsGuid() ? appType.ToGuid() : new RoadFlow.Platform.Dictionary().GetIDByCode("FormTypes");
  114. if (isAdd)
  115. {
  116. App.Add(app);
  117. }
  118. else
  119. {
  120. App.Update(app);
  121. }
  122. RoadFlow.Platform.Log.Add("发布了流程表单", app.Serialize() + "内容:" + html, RoadFlow.Platform.Log.Types.流程相关);
  123. wff.Status = 1;
  124. WFF.Update(wff);
  125. context.Response.Write("发布成功!");
  126. }
  127. public bool IsReusable
  128. {
  129. get
  130. {
  131. return false;
  132. }
  133. }
  134. }
  135. }