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); } } }
protected void Button1_Click(object sender, EventArgs e) { string newuser = newUser.Text.Trim(); string newpsw = newPsw.Text.Trim(); string newrpsw = newRpsw.Text.Trim(); string newtel = newTel.Text.Trim(); // 检测用户名是否有效 System.Text.RegularExpressions.Regex regex_name = new System.Text.RegularExpressions.Regex("[A-Za-z0-9\u4e00-\u9fa5]+"); System.Text.RegularExpressions.Regex regex_psw = new System.Text.RegularExpressions.Regex("[A-Za-z0-9]+"); System.Text.RegularExpressions.Regex regex_tel = new System.Text.RegularExpressions.Regex("0?(13|14|15|18)[0-9]{9}"); registerMsg.Text = ""; if (regex_name.IsMatch(newuser)) { if (newpsw.Equals(newrpsw)) { if (regex_psw.IsMatch(newpsw)) { if (regex_tel.IsMatch(newtel)) { // 注册成功 // 保存用户信息,并对密码进行加密 if (UserHelper.Register(newuser, MD5Encryption.EnCondingMD5(newpsw), newtel)) { UserArticleInfo articleInfo = new UserArticleInfo(); User user = UserHelper.GetUserInfoByUserName(newuser); // 获取新用户信息,以便获取用户ID UserArticleInfoHelper.InsertNewArticleInfo(user.userID, articleInfo); // 新建用户发文概况信息 Page.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('注册成功!前往登录...');window.location.href='Login.aspx'", true); } else { registerMsg.Text = "用户名已存在!"; } } else { registerMsg.Text = "请输入正确手机号!"; } } else { registerMsg.Text = "无效密码!(大小写母、数字)"; } } else { registerMsg.Text = "输入两次密码不一样!"; } } else { registerMsg.Text = "无效用户名!(中文、大小写母、数字、'-'或'_')"; } }