生活随笔
收集整理的這篇文章主要介紹了
弗尤博客(八)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
好幾天沒更新博客了,畢業設計進度慢下了,做了幾個網頁耽擱了。但是還是完成了評論的基本功能。
我的思路還是以前一樣通過datalist 來實現的,在顯示博文詳細頁面時,登錄情況下,用session來確保評論人,非登錄情況下,用label顯示需要登錄后才可評論,評論內容后臺調用datalist中的控件完成數據庫的添加弗尤博客(七) 評論數量是倒敘查看數據庫后取第一個,發評論時也是相同的,數目加一就好。
`using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Business;
using Entity;
public partial class UserBlogs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{if (!Page.IsPostBack){if (Session["uid"] == null){if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null){}if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null){Cind();}if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null){Aind();Eind();}}else{if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null){Bind();}if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null){Cind();}if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null){Aind();Dind();}}}
}public void Aind()//該篇博文
{BlogsBusiness blogs = new BlogsBusiness();BlogsEntity b = new BlogsEntity();DataTable dt = new DataTable();b.Bid =Convert.ToInt32(Request.QueryString["bid"]);dt = blogs.SelectUid(b);DataList1.DataSource = dt;DataList1.DataBind();CommentEntity c = new CommentEntity();CommentBusiness comment = new CommentBusiness();DataTable data = new DataTable();c.Bid= Convert.ToInt32(Request.QueryString["bid"]);data = comment.SelectComment(c);DataList3.DataSource = data; DataList3.DataBind();lbl.Text = "";
}
public void Bind()//我的博客
{BlogsBusiness blogs = new BlogsBusiness();BlogsEntity b = new BlogsEntity();DataTable dt = new DataTable();b.Uid = Session["uid"].ToString();dt = blogs.SelectBid(b);DataList2.DataSource = dt;DataList2.DataBind();
}
public void Cind()//他人的博客
{BlogsBusiness blogs = new BlogsBusiness();BlogsEntity b = new BlogsEntity();DataTable dt = new DataTable();b.Uid = Request.QueryString["uid"];dt = blogs.SelectBid(b);DataList2.DataSource = dt;DataList2.DataBind();
}
public void Dind()//評論
{UserBusiness user = new UserBusiness();UserEntity u = new UserEntity();DataTable d = new DataTable();u.Uid = Session["uid"].ToString();d = user.FindUserInfo(u);DataList4.DataSource = d;DataList4.DataBind();
}
public void Eind()//登錄后可評論
{lbl.Text = "登錄后可評論";
}protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
{if (e.CommandName == "blogs"){Response.Redirect("UserBlogs.aspx?bid=" + e.CommandArgument.ToString());}
}protected void Button1_Click(object sender, EventArgs e)
{//TextBox t = new TextBox();//t=(TextBox)DataList4.FindControl("TextBox4");//Label l = new Label();//l = (Label)DataList3.FindControl("Label7");DataListItem item = (DataListItem)((Button)sender).NamingContainer;TextBox txt = item.FindControl("TextBox4") as TextBox;CommentBusiness comment = new CommentBusiness();CommentEntity c = new CommentEntity();c.Bid = Convert.ToInt32(Request.QueryString["bid"]);DataTable dt = new DataTable();dt = comment.SelectCid(c);int cidnums=Convert.ToInt32(dt.Rows[0][0]);cidnums = cidnums + 1;CommentEntity ce = new CommentEntity();ce.Cid = cidnums;//ce.Comment = txt.ToString();ce.Comment = txt.Text.ToString();ce.Bid= Convert.ToInt32(Request.QueryString["bid"]);ce.Uid= Session["uid"].ToString();ce.Ctime= DateTime.Now;int res = 0;res = comment.InsertComment(ce);if (res > 0){//DataListItem items = (DataListItem)((Button)sender).NamingContainer;//Label lbl = items.FindControl("Label3") as Label;BlogsBusiness blogs = new BlogsBusiness();BlogsEntity b = new BlogsEntity();b.Comment = cidnums.ToString();b.Bid=Convert.ToInt32(Request.QueryString["bid"]);int r = 0;r = blogs.UpdateCommentNums(b);if (res > 0){Aind();Dind();Response.Write("<script>alert('評論成功')</script>");}}else{Response.Write("<script>alert('評論失敗')</script>");}}
}`
轉載于:https://www.cnblogs.com/frankybpx/p/10167729.html
總結
以上是生活随笔為你收集整理的弗尤博客(八)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。