/// <summary> /// 删除新闻内容图片 /// </summary> /// <param name="id"></param> private void DELContentImages(Object id) { T_NewsEntity data = db.ExecuteObject <T_NewsEntity>("SELECT * FROM [t_news] WHERE id=" + id); if (File.Exists(Server.MapPath(data.Attac_Url))) { File.Delete(Server.MapPath(data.Attac_Url)); } if (File.Exists(Server.MapPath(data.Video_Url))) { File.Delete(Server.MapPath(data.Video_Url)); } if (File.Exists(Server.MapPath(data.Image_Url))) { File.Delete(Server.MapPath(data.Image_Url)); } HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(data.Content + data.Abstract); var nodes = xml.DocumentNode.CssSelect("img[src^='/']"); foreach (HtmlNode n in nodes) { String src = Server.MapPath(n.Attributes["src"].Value.Trim()); if (File.Exists(src)) { File.Delete(src); } } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (readaccess.SelectedIndex == -1) { readaccess.SelectedIndex = 0; } T_NewsEntity data = (T_NewsEntity)ViewState["data"]; data = this.GetFormValue <T_NewsEntity>(data); CmdType cmd = IsEdit ? CmdType.UPDATE : CmdType.INSERT; data.EditDate = DateTime.Now; if (!IsEdit) { data.PubDate = DateTime.Now; } T_AccessControlEntity acl = GetGroupAction(data.GroupId); if (acl.ActionType.HasFlag(ActionType.Create) || acl.ActionType.HasFlag(ActionType.Edit)) { #region 网络图片采集 HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(data.Content); var html = xml.DocumentNode; var nodes = html.CssSelect("img[src^='http:']"); foreach (HtmlNode n in nodes) { HtmlAttribute src = n.Attributes["src"]; src.Value = DownloadImage(src.Value); } data.Content = xml.DocumentNode.WriteTo(); content.Text = data.Content; #endregion if (db.ExecuteCommand <T_NewsEntity>(data, cmd)) { if (!IsEdit) { this.ClearFromValue(); } Alert(Label1, "保存成功!", "line1px_3"); } } }
/// <summary> /// 加载编辑数据 /// </summary> protected void LoadData() { String sql = String.Format("SELECT a.*,b.groupname FROM [T_News] as a LEFT JOIN [T_Group] as b ON a.groupid = b.ID WHERE a.ID={0}", EditID); T_NewsEntity data = db.ExecuteObject <T_NewsEntity>(sql); ViewState["data"] = data; this.SetFormValue(data); T_AccessControlEntity acl = Access.Find(a => { return(a.Node == data.GroupId); }); if (!Admin.IsSuper && !ActionTypeHelper.IsSetting(acl.ActionType)) { nominate.Enabled = hotspot.Enabled = focus.Enabled = stick.Enabled = status.Enabled = false; } }
/// <summary> /// 加载编辑数据 /// </summary> protected void LoadData() { String strSql = String.Format("SELECT a.*,b.groupname FROM [T_News] as a LEFT JOIN [T_Group] as b ON a.groupid = b.ID WHERE a.ID={0}", EditID); T_NewsEntity data = db.ExecuteObject <T_NewsEntity>(strSql); ViewState["data"] = data; this.SetFormValue(data); T_AccessControlEntity acl = GetGroupAction(data.GroupId); if (acl == null || !acl.ActionType.HasFlag(ActionType.Edit)) { form1.Visible = false; btnSave.Visible = false; } if (acl != null && !acl.ActionType.HasFlag(ActionType.Setting)) { isnominate.Enabled = ishotspot.Enabled = isslide.Enabled = isstick.Enabled = isenable.Enabled = isaudit.Enabled = iscomments.Enabled = readaccess.Enabled = false; } }