/// <summary> /// 删除文章。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void LinkButtonDelete_Click(object sender, CommandEventArgs e) { int articleId; if(int.TryParse(e.CommandName, out articleId) == false) { MessageBox("错误提示", "文章编号必须为整数"); return; } // 添加操作日志 DataManager.LogManager logManager = new DataManager.LogManager(); int iExecuteNonQuery = 0; Wis.Website.DataManager.ArticleManager articleManager = new Wis.Website.DataManager.ArticleManager(); Wis.Website.DataManager.Article article = articleManager.GetArticle(articleId); #warning 删除与该文章相关的图片、视频、软件 // 重新生成静态页面和关联页面 DataManager.ReleaseManager releaseManager = new DataManager.ReleaseManager(); switch (article.Category.ArticleType) { case 1://ArticleType.Normal: iExecuteNonQuery = articleManager.Remove(article.ArticleGuid); logManager.AddNew(Guid.NewGuid(), Guid.Empty, "删除新闻", article.ArticleGuid, article.Title, System.DateTime.Now); releaseManager.ReleasingRemovedArticle(article); break; case 2://ArticleType.Photo: ArticlePhotoManager articlePhotoManager = new ArticlePhotoManager(); ArticlePhoto articlePhoto = articlePhotoManager.GetArticlePhoto(article.ArticleGuid); iExecuteNonQuery = articleManager.Remove(articlePhoto.ArticleGuid); logManager.AddNew(Guid.NewGuid(), Guid.Empty, "删除新闻", articlePhoto.ArticleGuid, articlePhoto.Title, System.DateTime.Now); releaseManager.ReleasingRemovedPhotoArticle(articlePhoto); break; case 3://ArticleType.Video: VideoArticleManager videoArticleManager = new VideoArticleManager(); VideoArticle videoArticle = videoArticleManager.GetVideoArticle(article.ArticleGuid); iExecuteNonQuery = articleManager.Remove(videoArticle.Article.ArticleGuid); logManager.AddNew(Guid.NewGuid(), Guid.Empty, "删除新闻", videoArticle.Article.ArticleGuid, videoArticle.Article.Title, System.DateTime.Now); releaseManager.ReleasingRemovedVideoArticle(videoArticle); break; //case ArticleType.Soft: // releaseManager.ReleasingRemovedSoftArticle(article); // break; //case ArticleType.Link: // releaseManager.ReleasingRemovedLinkArticle(article); // break; } if (iExecuteNonQuery > 0) { Warning.InnerHtml = "删除成功!"; } else { Warning.InnerHtml = "删除失败!"; } // 重新绑定新闻列表 BindRepeater(); }
public void ProcessRequest(HttpContext context) { // 1 验证验证码 if (context.Session[CommentVerifyHttpHandler.ConstCommentVerify] == null) { return; } string commentVerify1 = context.Session[CommentVerifyHttpHandler.ConstCommentVerify].ToString(); string commentVerify2 = context.Request[CommentVerifyHttpHandler.ConstCommentVerify]; if (string.IsNullOrEmpty(commentVerify1) || string.IsNullOrEmpty(commentVerify2)) { return; } if (commentVerify1.ToUpper() != commentVerify2.ToUpper()) { return; } // 验证评论数据,两者不能同时为空 string title = RequestManager.Request("Title"); string contentHtml = RequestManager.Request("ContentHtml"); if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(contentHtml)) { return; } // 评论标题和内过滤Html脚本 // TODO:过滤内嵌Script脚本、样式 title = Regex.Replace(title, "<[^>]*>", ""); contentHtml = Regex.Replace(contentHtml, "<[^>]*>", ""); // 2 验证评论数据 // 获取文章的编号 if (context.Request.UrlReferrer == null) { return; } string rawUrl = context.Request.UrlReferrer.AbsoluteUri; int charIndex = rawUrl.LastIndexOf('/'); if (charIndex == -1) { return; } // http://localhost:3419/Web/2/2-13/38.htm rawUrl = rawUrl.Substring(charIndex + 1); // 38.htm charIndex = rawUrl.IndexOf('.'); if (charIndex == -1) { return; } string requestArticleId = rawUrl.Substring(0, charIndex); // RequestManager.Request("ArticleId"); // 文章编号是否为数字 int articleId; if (int.TryParse(requestArticleId, out articleId) == false) { // 提示失败 return; } // 文章是否存在 ArticleManager articleManager = new ArticleManager(); Article article = articleManager.GetArticle(articleId); if (string.IsNullOrEmpty(article.Title)) { // 提示失败 return; } // 构造评论实体类 Comment comment = new Comment(); // 获得实体类 // TODO:如果前台支持用户注册和登录,获取用户的昵称(唯一不重复) comment.Commentator = string.Empty; comment.CommentGuid = Guid.NewGuid(); //comment.CommentId comment.ContentHtml = contentHtml; comment.DateCreated = DateTime.Now; comment.IPAddress = RequestManager.GetClientIP(); comment.Original = string.Empty; comment.SubmissionGuid = article.ArticleGuid; comment.Title = title; CommentManager commentManager = new CommentManager(); commentManager.AddNew(comment); // TODO:事务处理 // 更新Article的评论数 articleManager.UpdateArticleComments(article.ArticleGuid); // 清空评论验证码 context.Session[CommentVerifyHttpHandler.ConstCommentVerify] = null; // 输出评论数 //context.Response.Write((articlePhoto.Comments + 1).ToString()); // 重新生成 Article ReleaseManager releaseManager = new ReleaseManager(); switch (article.Category.ArticleType) { case 1://ArticleType.Normal: releaseManager.ReleasingArticleItem(article); break; case 2://ArticleType.Photo: ArticlePhotoManager articlePhotoManager = new ArticlePhotoManager(); ArticlePhoto articlePhoto = articlePhotoManager.GetArticlePhoto(article.ArticleGuid); releaseManager.ReleasingPhotoArticleItem(articlePhoto); break; case 3://ArticleType.Video: VideoArticleManager videoArticleManager = new VideoArticleManager(); VideoArticle videoArticle = videoArticleManager.GetVideoArticle(article.ArticleGuid); releaseManager.ReleasingVideoArticleItem(videoArticle); break; //case ArticleType.Soft: // releaseManager.ReleasingSoftArticleItem(article); // break; //case ArticleType.Link: // releaseManager.ReleasingLinkArticleItem(article); // break; } }
/// <summary> /// 发布文章。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void LinkButtonRelease_Click(object sender, CommandEventArgs e) { int articleId; if (int.TryParse(e.CommandName, out articleId) == false) { MessageBox("错误提示", "文章编号必须为整数"); return; } Wis.Website.DataManager.ArticleManager articleManager = new Wis.Website.DataManager.ArticleManager(); Wis.Website.DataManager.Article article = articleManager.GetArticle(articleId); // 重新生成静态页面和关联页面 DataManager.ReleaseManager releaseManager = new DataManager.ReleaseManager(); switch (article.Category.ArticleType) { case 1://ArticleType.Normal: releaseManager.ReleasingArticle(article); break; case 2://ArticleType.Photo: ArticlePhotoManager articlePhotoManager = new ArticlePhotoManager(); ArticlePhoto articlePhoto = articlePhotoManager.GetArticlePhoto(article.ArticleGuid); releaseManager.ReleasingPhotoArticle(articlePhoto); break; case 3://ArticleType.Video: VideoArticleManager videoArticleManager = new VideoArticleManager(); VideoArticle videoArticle = videoArticleManager.GetVideoArticle(article.ArticleGuid); releaseManager.ReleasingVideoArticle(videoArticle); break; //case ArticleType.Soft: // releaseManager.ReleasingRemovedSoftArticle(article); // break; //case ArticleType.Link: // releaseManager.ReleasingRemovedLinkArticle(article); // break; } MessageBox("操作提示", "发布成功!"); //MessageBox("操作提示", "发布失败!"); // 添加操作日志 DataManager.LogManager logManager = new DataManager.LogManager(); logManager.AddNew(Guid.NewGuid(), Guid.Empty, "发布新闻", article.ArticleGuid, article.Title, System.DateTime.Now); }