protected void butPublish_Click(object sender, EventArgs e) { if (UserInfo()) { GetArticleInfo(); // 获取输入信息 userName = HttpUtility.UrlDecode(Request.Cookies["USERINFO"]["NAME"]); User user = UserHelper.GetUserInfoByUserName(userName); // 获取用户信息 Article articleInfo = new Article(); articleInfo.User_id = user.userID; articleInfo.Title = article_title; articleInfo.Content = article_content; articleInfo.Type = article_type; articleInfo.Tag = article_tag; articleInfo.Pub_time = DateUtils.GetNowTime(); articleInfo.Juri = "待审核"; // 默认'待审核'->'已审核' articleInfo.State = "可评论"; switch (butPublish.Text) { case "发表": if (ArticleHelper.InsertNewArticle(articleInfo)) // 判断发表结果 { // 获取刚保存的文章的相关信息 Article article = ArticleHelper.GetTheNewArticleByUserId(articleInfo.User_id); if (article != null) { // 创建新的文章其他信息表,并保存 ArticleInfo articleIn = new ArticleInfo(); articleIn.Comment_time = DateUtils.GetNowTime(); ArticleInfoHelper.InsertArticleInfoByarticleId(article.ID, articleIn); } // 用户发表文章数 +1 UserArticleInfoHelper.SetNumByUserId(articleInfo.User_id, 1); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + butPublish.Text + "成功!')" + ";window.location.href='MyPost.aspx?type=3'", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + butPublish.Text + "成功!')", true); } break; case "保存": if (ArticleHelper.UpdateArticle(articleInfo, user.userID, int.Parse(articleId))) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + butPublish.Text + "成功!')" + ";window.location.href='MyPost.aspx?type=3'", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + butPublish.Text + "成功!')", true); } break; } } }
protected void Bnt_Comm_Click(object sender, EventArgs e) { string floor = FloorList.SelectedValue; // 被评论楼层 string Comm_Content = content.Text.ToString().Replace("'", "‘"); // 评论内容 int ArticleID = int.Parse(articleId); // 文章id string Comm_time = DateUtils.GetNowTime(); // 系统时间 int BUserId = int.Parse(userID); // 被评论者id if (Comm_Content.Length < 15) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('评论内容长度至少15字!')", true); } else { User user = IsLogin(); if (user != null) { int UserId = user.userID; // 评论者id Comment comment = new Comment(); comment.ArticleID = ArticleID; comment.Comm_Content = Comm_Content; comment.Comm_Time = Comm_time; comment.Comm_userID = UserId; UserMessage msg = new UserMessage(); msg.ArticleID = ArticleID; msg.Comm_Content = Comm_Content; msg.Comm_Time = Comm_time; msg.Comm_UserID = UserId; msg.UserID = BUserId; msg.State = "未读"; msg.bComm_Content = Article_Title; if (MsgAndCommHelper.CommitComment(comment, msg)) // 将评论信息保存数据库 { UserArticleInfoHelper.SetNumByUserId(BUserId, 4); // 被评论用户被评论数 +1 UserArticleInfoHelper.SetNumByUserId(UserId, 3); // 评论用户的评论数 +1 Response.Redirect("ShowArticle.aspx?ArticleId=" + ArticleID); //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('发表成功!')", true); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('发表失败!')", true); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('请先登录!')", true); } } }
protected void Repeater_Post_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Look") // 查看 { //int ArticleId = int.Parse(e.CommandArgument.ToString()); Response.Redirect("ShowArticle.aspx?ArticleId=" + e.CommandArgument); } else if (e.CommandName == "Edit") // 编辑 { Response.Redirect("MyEditor.aspx?ArticleId=" + e.CommandArgument); } else if (e.CommandName == "State") // 分类 { string articleId = e.CommandArgument.ToString(); DBHelper mdb = new DBHelper(); mdb.Connect(); // 更新评论权限 bool result = ArticleData.UpdateArticleStateByArticleId(int.Parse(articleId), mdb.GetConn); mdb.Disconnect(); if (result) { Response.Redirect("MyPost.aspx?type=3"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改失败!')", true); } } else if (e.CommandName == "Delete") // 删除 { string articleId = e.CommandArgument.ToString(); DBHelper mdb = new DBHelper(); mdb.Connect(); // 更新评论权限 bool result = ArticleData.DeleteArticleByArticleId(int.Parse(articleId), mdb.GetConn); mdb.Disconnect(); if (result) { User user = GetUserInfo(); // 用户删除文章数 +1 UserArticleInfoHelper.SetNumByUserId(user.userID, 2); Response.Redirect("MyPost.aspx?type=3"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除失败!')", true); } } }