Keine Beschreibung

KnowledgeEdit.aspx.cs 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Text.RegularExpressions;
  8. using System.Text;
  9. using System.Data;
  10. public partial class Knowledge_KnowledgeEdit : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. if (!this.IsPostBack)
  15. {
  16. if (!string.IsNullOrEmpty(Request.QueryString["type"]))
  17. {
  18. if (Request.QueryString["type"].ToString() == "update")
  19. {
  20. if (!string.IsNullOrEmpty(Request.QueryString["id"]))
  21. {
  22. int sid = int.Parse(Request.QueryString["id"].ToString());
  23. Update(sid);
  24. }
  25. }
  26. else
  27. {
  28. if (!string.IsNullOrEmpty(Request.QueryString["typeid"]))
  29. {
  30. this.classid.Value = Request.QueryString["typeid"].Substring(1);
  31. this.txtFL.Text=changeClass(this.classid.Value);
  32. }
  33. }
  34. }
  35. }
  36. }
  37. public string changeClass(string classid)
  38. {
  39. string sql = "F_ID=" + classid;
  40. XYFDRQ.BLL.T_KnowledgeClass bll = new XYFDRQ.BLL.T_KnowledgeClass();
  41. DataTable table = bll.GetList(sql).Tables[0];
  42. if (table.Rows.Count > 0)
  43. {
  44. return table.Rows[0]["F_Name"].ToString();
  45. }
  46. else
  47. {
  48. return "";
  49. }
  50. }
  51. private XYFDRQ.Model.T_Knowledge SaveData()
  52. {
  53. XYFDRQ.Model.T_Knowledge model = new XYFDRQ.Model.T_Knowledge();
  54. XYFDRQ.BLL.T_Knowledge bll=new XYFDRQ.BLL.T_Knowledge ();
  55. if (!string.IsNullOrEmpty(Request.QueryString["type"]))
  56. {
  57. if (Request.QueryString["type"].ToString() == "update")
  58. {
  59. if (!string.IsNullOrEmpty(Request.QueryString["id"]))
  60. {
  61. model = bll.GetModel(int.Parse(Request.QueryString["id"].ToString()));
  62. }
  63. }
  64. }
  65. model.F_Title = txtTitle.Text;
  66. if (classid.Value != "")
  67. {
  68. model.F_Class = int.Parse(classid.Value);
  69. }
  70. model.F_Content = FCKeditor1.Value;
  71. if (!string.IsNullOrEmpty(Request.QueryString["type"]))
  72. {
  73. if (Request.QueryString["type"].ToString() == "new")
  74. {
  75. model.F_AddData = DateTime.Now;
  76. }
  77. }
  78. if (userid.Value != "")
  79. {
  80. model.F_UserId = int.Parse (userid.Value);
  81. }
  82. model.F_Digest = NoHTML(FCKeditor1.Value);
  83. return model;
  84. }
  85. private void Update(int sid)
  86. {
  87. XYFDRQ.Model.T_Knowledge model = new XYFDRQ.Model.T_Knowledge();
  88. XYFDRQ.BLL.T_Knowledge bll = new XYFDRQ.BLL.T_Knowledge();
  89. model = bll.GetModel(sid);
  90. txtTitle.Text = model.F_Title;
  91. if (model.F_Class.ToString() != "")
  92. {
  93. classid.Value = model.F_Class.ToString();
  94. txtFL.Text = changeClass(model.F_Class.ToString());
  95. }
  96. FCKeditor1.Value = model.F_Content;
  97. }
  98. public static string NoHTML(string Htmlstring) //替换HTML标记
  99. {
  100. //删除脚本
  101. Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
  102. //删除HTML
  103. Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
  104. Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
  105. Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
  106. Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
  107. Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
  108. Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
  109. Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
  110. Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
  111. Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
  112. Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
  113. Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
  114. Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
  115. Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
  116. Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
  117. Htmlstring = Regex.Replace(Htmlstring, @"<img[^>]*>;", "", RegexOptions.IgnoreCase);
  118. Htmlstring.Replace("<", "");
  119. Htmlstring.Replace(">", "");
  120. Htmlstring.Replace("\r\n", "");
  121. Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
  122. return Htmlstring;
  123. }
  124. protected void btnSave_Click(object sender, EventArgs e)
  125. {
  126. if (!string.IsNullOrEmpty(Request.QueryString["type"]))
  127. {
  128. XYFDRQ.BLL.T_Knowledge bll = new XYFDRQ.BLL.T_Knowledge();
  129. try
  130. {
  131. string type = Request.QueryString["type"].ToString();
  132. if (type == "new")
  133. {
  134. int i = bll.Add(SaveData());
  135. if (i > 0)
  136. {
  137. Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存成功', 220, 5);", true);
  138. }
  139. else
  140. {
  141. Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存失败', 220, 0);", true);
  142. }
  143. }
  144. else if (type == "update")
  145. {
  146. bool s = bll.Update(SaveData());
  147. if (s)
  148. {
  149. Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '修改成功', 220, 5);", true);
  150. }
  151. else
  152. {
  153. Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存失败', 220, 0);", true);
  154. }
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存失败', 220, 0);", true);
  160. }
  161. }
  162. }
  163. }