| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Text.RegularExpressions;
- using System.Text;
- using System.Data;
- public partial class Knowledge_KnowledgeEdit : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.IsPostBack)
- {
- if (!string.IsNullOrEmpty(Request.QueryString["type"]))
- {
- if (Request.QueryString["type"].ToString() == "update")
- {
- if (!string.IsNullOrEmpty(Request.QueryString["id"]))
- {
- int sid = int.Parse(Request.QueryString["id"].ToString());
- Update(sid);
- }
- }
- else
- {
- if (!string.IsNullOrEmpty(Request.QueryString["typeid"]))
- {
- this.classid.Value = Request.QueryString["typeid"].Substring(1);
- this.txtFL.Text=changeClass(this.classid.Value);
- }
- }
- }
- }
- }
- public string changeClass(string classid)
- {
- string sql = "F_ID=" + classid;
- XYFDRQ.BLL.T_KnowledgeClass bll = new XYFDRQ.BLL.T_KnowledgeClass();
- DataTable table = bll.GetList(sql).Tables[0];
- if (table.Rows.Count > 0)
- {
- return table.Rows[0]["F_Name"].ToString();
- }
- else
- {
- return "";
- }
- }
- private XYFDRQ.Model.T_Knowledge SaveData()
- {
- XYFDRQ.Model.T_Knowledge model = new XYFDRQ.Model.T_Knowledge();
- XYFDRQ.BLL.T_Knowledge bll=new XYFDRQ.BLL.T_Knowledge ();
- if (!string.IsNullOrEmpty(Request.QueryString["type"]))
- {
- if (Request.QueryString["type"].ToString() == "update")
- {
- if (!string.IsNullOrEmpty(Request.QueryString["id"]))
- {
- model = bll.GetModel(int.Parse(Request.QueryString["id"].ToString()));
- }
- }
- }
- model.F_Title = txtTitle.Text;
- if (classid.Value != "")
- {
- model.F_Class = int.Parse(classid.Value);
- }
- model.F_Content = FCKeditor1.Value;
- if (!string.IsNullOrEmpty(Request.QueryString["type"]))
- {
- if (Request.QueryString["type"].ToString() == "new")
- {
- model.F_AddData = DateTime.Now;
- }
- }
- if (userid.Value != "")
- {
- model.F_UserId = int.Parse (userid.Value);
- }
- model.F_Digest = NoHTML(FCKeditor1.Value);
- return model;
-
- }
- private void Update(int sid)
- {
- XYFDRQ.Model.T_Knowledge model = new XYFDRQ.Model.T_Knowledge();
- XYFDRQ.BLL.T_Knowledge bll = new XYFDRQ.BLL.T_Knowledge();
- model = bll.GetModel(sid);
- txtTitle.Text = model.F_Title;
- if (model.F_Class.ToString() != "")
- {
- classid.Value = model.F_Class.ToString();
- txtFL.Text = changeClass(model.F_Class.ToString());
- }
-
- FCKeditor1.Value = model.F_Content;
-
- }
- public static string NoHTML(string Htmlstring) //替换HTML标记
- {
- //删除脚本
- Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
- //删除HTML
- Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"<img[^>]*>;", "", RegexOptions.IgnoreCase);
- Htmlstring.Replace("<", "");
- Htmlstring.Replace(">", "");
- Htmlstring.Replace("\r\n", "");
- Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
- return Htmlstring;
- }
- protected void btnSave_Click(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(Request.QueryString["type"]))
- {
- XYFDRQ.BLL.T_Knowledge bll = new XYFDRQ.BLL.T_Knowledge();
- try
- {
- string type = Request.QueryString["type"].ToString();
- if (type == "new")
- {
-
- int i = bll.Add(SaveData());
- if (i > 0)
- {
- Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存成功', 220, 5);", true);
- }
- else
- {
- Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存失败', 220, 0);", true);
- }
- }
- else if (type == "update")
- {
- bool s = bll.Update(SaveData());
- if (s)
- {
- Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '修改成功', 220, 5);", true);
- }
- else
- {
- Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存失败', 220, 0);", true);
- }
- }
- }
- catch (Exception ex)
- {
- Page.ClientScript.RegisterStartupScript(GetType(), "confirm", "OpenMessage('framemessage', '提示', '保存失败', 220, 0);", true);
- }
- }
- }
- }
|