1. 程式人生 > >弗尤部落格(五)

弗尤部落格(五)

這一篇中,我實現了,登入和遊客環境下,在首頁中單擊博文標題跳轉到該篇博文,點選博文作者跳轉到該作者部落格首頁,在我的部落格中點選博文標題跳轉到該篇博文。

這些跳轉都是在同一個頁面中實現的,我用母版頁放個人部落格的導航和公告。web頁面放datalist實現博文的,由於不會後臺呼叫datalist中的控制元件,更改不了textbox的大小,我把資料庫更改了,資料庫中有個單獨存放博文摘要的,準備以後實現下自動選取摘要,所以我用了2個datalist來顯示全博文,和詳細博文,寫到這我有個想法,把它換成兩張表是不是可以更好的實現。

  1 //MyBlogs.master
  2
using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Web; 6 using System.Web.UI; 7 using System.Web.UI.WebControls; 8 using System.Data; 9 using Business; 10 using Entity; 11 public partial class MyBlogs : System.Web.UI.MasterPage 12 { 13
protected void Page_Load(object sender, EventArgs e) 14 { 15 if (Session["uid"] == null) 16 { 17 18 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 19 { 20 21 }
22 if(Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 23 { 24 Cind(); 25 } 26 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 27 { 28 Aind(); 29 } 30 } 31 else 32 { 33 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 34 { 35 Bind(); 36 } 37 if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 38 { 39 Cind(); 40 } 41 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 42 { 43 Aind(); 44 } 45 46 } 47 } 48 public void Bind()//我的部落格 49 { 50 UserBusiness uname = new UserBusiness(); 51 UserEntity user = new UserEntity(); 52 user.Uid = Session["uid"].ToString(); 53 DataTable dt = new DataTable(); 54 dt = uname.FindUserInfo(user); 55 DataList1.DataSource = dt; 56 DataList1.DataBind(); 57 DataList2.DataSource = dt; 58 DataList2.DataBind(); 59 } 60 public void Aind()//該篇博文 61 { 62 BlogsBusiness blogs = new BlogsBusiness(); 63 BlogsEntity b = new BlogsEntity(); 64 DataTable dt = new DataTable(); 65 b.Bid=Convert.ToInt32( Request.QueryString["bid"]); 66 dt = blogs.SelectUid(b); 67 DataList1.DataSource = dt; 68 DataList1.DataBind(); 69 DataList2.DataSource = dt; 70 DataList2.DataBind(); 71 72 } 73 public void Cind() 74 { 75 UserBusiness uname = new UserBusiness(); 76 UserEntity user = new UserEntity(); 77 user.Uid = Request.QueryString["uid"]; 78 DataTable dt = new DataTable(); 79 dt = uname.FindUserInfo(user); 80 DataList1.DataSource = dt; 81 DataList1.DataBind(); 82 DataList2.DataSource = dt; 83 DataList2.DataBind(); 84 } 85 86 protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e) 87 { 88 if (e.CommandName == "user") 89 { 90 Response.Redirect("UserBlogs.aspx?uid=" + e.CommandArgument.ToString()); 91 } 92 if (e.CommandName == "NewBlogs") 93 { 94 Response.Redirect("NewBlogs.aspx?uid=" + e.CommandArgument.ToString()); 95 } 96 if (e.CommandName == "Manage") 97 { 98 Response.Redirect("Manage.aspx?uid=" + e.CommandArgument.ToString()); 99 } 100 } 101 } 102 //UserBlogs.aspx 103 using System; 104 using System.Collections.Generic; 105 using System.Linq; 106 using System.Web; 107 using System.Web.UI; 108 using System.Web.UI.WebControls; 109 using System.Data; 110 using Business; 111 using Entity; 112 public partial class UserBlogs : System.Web.UI.Page 113 { 114 protected void Page_Load(object sender, EventArgs e) 115 { 116 if (Session["uid"] == null) 117 { 118 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 119 { 120 121 } 122 if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 123 { 124 Cind(); 125 } 126 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 127 { 128 Aind(); 129 } 130 } 131 else 132 { 133 134 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] == null) 135 { 136 Bind(); 137 } 138 if (Request.QueryString["uid"] != null && Request.QueryString["bid"] == null) 139 { 140 Cind(); 141 } 142 if (Request.QueryString["uid"] == null && Request.QueryString["bid"] != null) 143 { 144 Aind(); 145 } 146 } 147 } 148 149 public void Aind()//該篇博文 150 { 151 BlogsBusiness blogs = new BlogsBusiness(); 152 BlogsEntity b = new BlogsEntity(); 153 DataTable dt = new DataTable(); 154 b.Bid =Convert.ToInt32(Request.QueryString["bid"]); 155 dt = blogs.SelectUid(b); 156 DataList1.DataSource = dt; 157 DataList1.DataBind(); 158 } 159 public void Bind()//我的部落格 160 { 161 BlogsBusiness blogs = new BlogsBusiness(); 162 BlogsEntity b = new BlogsEntity(); 163 DataTable dt = new DataTable(); 164 b.Uid = Session["uid"].ToString(); 165 dt = blogs.SelectBid(b); 166 DataList2.DataSource = dt; 167 DataList2.DataBind(); 168 } 169 public void Cind()//他人的部落格 170 { 171 BlogsBusiness blogs = new BlogsBusiness(); 172 BlogsEntity b = new BlogsEntity(); 173 DataTable dt = new DataTable(); 174 b.Uid = Request.QueryString["uid"]; 175 dt = blogs.SelectBid(b); 176 DataList2.DataSource = dt; 177 DataList2.DataBind(); 178 } 179 180 181 182 183 184 protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e) 185 { 186 if (e.CommandName == "blogs") 187 { 188 Response.Redirect("UserBlogs.aspx?bid=" + e.CommandArgument.ToString()); 189 } 190 } 191 }
View Code

我通過3條if判斷登入下和非登入下的情況的。

後面還用之前的方法跳轉到釋出和管理頁面,但是這個在後臺程式碼中要判斷是否登入,沒有登入的話需要登入。