第3.2节 用户管理首页userindex http://www.paper51.com 图3·3 用户管理首页图 paper51.com 用户管理首页为用户提供了各个管理功能的链接,如添加日志、管理日志、管理专题、个人信息修改、评论管理等,如图3.3所示。 内容来自论文无忧网 www.paper51.com 在HTML语言中A href="userlogmanage.aspx"target="_blank"提供了在新窗口中打开userlogmanage.aspx的链接,添加日志链接到的页面是useraddlog.aspx,分类管理链接到的页面是userclass.aspx,修改用户资料链接到的页面是userinfomodify.aspx。 http://www.paper51.com
第3.3节 发表日志user_addlog.aspx paper51.com (1) 动态加载系统分类、用户分类、表情 内容来自www.paper51.com 系统分类信息在表category中,加载的时候把所有的系统分类id和对应的类名作为一个list的项加入到控件中,用户分类在表userclass中,需要通过userid来筛选该分类是否当前登录用户的分类。 paper51.com 具体实现如下所示: 内容来自论文无忧网 www.paper51.com IfNot IsPostBack Then 内容来自论文无忧网 www.paper51.com Fori = 1 To 8 内容来自www.paper51.com Dim srcstr As String http://www.paper51.com srcstr = "myimage\emot\face" + i.ToString + ".gif"//添加表情 copyright paper51.com Dim a As New System.Web.UI.WebControls.ListItem paper51.com a.Value = srcstr 内容来自论文无忧网 www.paper51.com a.Text = "<img src='" + srcstr + "'>" paper51.com imagelist.Items.Add(a) paper51.com Next copyright paper51.com mycon.Open() 内容来自论文无忧网 www.paper51.com mycmd.CommandText = "select * from category" http://www.paper51.com
dr = mycmd.ExecuteReader 内容来自论文无忧网 www.paper51.com Whiledr.Read paper51.com Dim a As New Web.UI.WebControls.ListItem http://www.paper51.com
Dim a As New Web.UI.WebControls.ListItem paper51.com a.Value = dr.GetValue(2) 内容来自www.paper51.com a.Text = dr.GetValue(0) 内容来自www.paper51.com category.Items.Add(a) 内容来自www.paper51.com End While 内容来自www.paper51.com dr.Close()[17] 内容来自www.paper51.com mycmd.Connection = mycon 内容来自www.paper51.com mycmd.CommandText = "select * from userclass where user_id ='" & Session("username") & "'" http://www.paper51.com dr = mycmd.ExecuteReader paper51.com
userclass.Items.Clear() copyright paper51.com
While dr.Read copyright paper51.com Dim a As New Web.UI.WebControls.ListItem http://www.paper51.com
a.Value = dr.GetValue(3) paper51.com a.Text = dr.GetValue(0) copyright paper51.com
userclass.Items.Add(a) 内容来自www.paper51.com End While copyright paper51.com mycon.Close() copyright paper51.com dr.Close() copyright paper51.com EndIf http://www.paper51.com
(2) 发表日志: 内容来自www.paper51.com 发表日志主要是在log基本表中添加一条日志记录,包括日志ID,标题,内容,发表人ID,所属系统分类ID,所属用户分类ID,发表时间,表情,是否隐藏,是否需要密码。 paper51.com 日志的ID需要遍历log基本表的日志ID,把最大的ID号加1,做为新日志的ID,而不是只统计当前的日志总数,因为日志可能被删掉。发表日志的时候需要判断标题、内容、系统分类是否为空,若为空则给出提示,不为空则对基本表进行插入操作,插入前需要将标题、内容、表情进行特殊字符的变换。具体实现代码如下: copyright paper51.com If(Session("username") = "") Then 内容来自www.paper51.com Page.Response.Redirect("index.aspx") paper51.com
EndIf paper51.com If logtitle.Text ="" Then '日志标题 paper51.com Response.Write("<script language=vbscript>alert""日志标题不能为空""</script>") 内容来自论文无忧网 www.paper51.com ElseIf body.Text = "" Then '日志内容 内容来自论文无忧网 www.paper51.com Response.Write("<script language=vbscript>alert""日志内容不能为空""</script>") 内容来自www.paper51.com ElseIf category.SelectedItem.Text = "请选择分类"Then '日志内容 内容来自论文无忧网 www.paper51.com Response.Write("<script language=vbscript>alert""请选择系统分类""</script>") copyright paper51.com Else http://www.paper51.com
mycmd.Connection = mycon http://www.paper51.com mycmd.CommandText = "select log_id from log" 内容来自论文无忧网 www.paper51.com Dim log_num As Integer copyright paper51.com
log_num = 1 copyright paper51.com dr = mycmd.ExecuteReader http://www.paper51.com While dr.Read 内容来自www.paper51.com If (dr.GetValue(0) > log_num) Then http://www.paper51.com
log_num = dr.GetValue(0) copyright paper51.com End If http://www.paper51.com End While copyright paper51.com
log_num =log_num + 1 内容来自www.paper51.com dr.Close() http://www.paper51.com Dim display_num As Integer copyright paper51.com
Dim subjectstr As String = logtitle.Text http://www.paper51.com Dim contentstr As String = body.Text 内容来自www.paper51.com
Dim imagesrc As String = imagelist.SelectedValue 内容来自论文无忧网 www.paper51.com //特殊字符转换 内容来自www.paper51.com imagesrc = imagesrc.Replace("&", "&") http://www.paper51.com …… http://www.paper51.com
contentstr = contentstr.Replace(">", ">") 内容来自www.paper51.com contentstr = contentstr.Replace(Chr(32), " ") 内容来自论文无忧网 www.paper51.com category_id = CInt(category.SelectedItem.Value) paper51.com
If(userclass.SelectedIndex = -1) Then copyright paper51.com class_id = 0 paper51.com Else 内容来自www.paper51.com
class_id = CInt(userclass.SelectedItem.Value) 内容来自论文无忧网 www.paper51.com End If 内容来自www.paper51.com sql = "insert into log values(" & log_num &",'" & subjectstr & "','" & contentstr &"','" & Now & "','" &Session("username") & "'," & category_id &"," & class_id & ",'" & ispassword.Text &"',0,'" & hide.SelectedItem.Text & "','" &imagesrc & "')" paper51.com mycmd.CommandText = sql http://www.paper51.com mycmd.ExecuteNonQuery() 内容来自www.paper51.com
mycmd.CommandText= "update category set log_num=log_num+1 where category_id=" &category_id copyright paper51.com mycmd.ExecuteNonQuery() http://www.paper51.com If (class_id <> 0) Then paper51.com mycmd.CommandText = "updateuserclass setlog_num=log_num+1 whereclass_id=" & class_id copyright paper51.com mycmd.ExecuteNonQuery() copyright paper51.com End If http://www.paper51.com mycon.Close() 内容来自www.paper51.com
Response.Write("<script language=vbscript>alert""发表日志成功""</script>") 内容来自论文无忧网 www.paper51.com
Page.Response.Redirect("viewblog.aspx?username=" &Session("username")) copyright paper51.com EndIf 内容来自论文无忧网 www.paper51.com
内容来自www.paper51.com 图3·4 发表日志页面 内容来自论文无忧网 www.paper51.com
|