[摘要]一段显示论坛贴子的程序 /////////////////////////////////////////////////////////////////////////////////// File name: showtopic.cs//// Description: ...
一段显示论坛贴子的程序 ///////////////////////////////////////////////////////////////////////////////
//
// File name: showtopic.cs
//
// Description: showtopic.aspx的后台代码
//
// date: 2000/11/01
//
// Programming: Bigeagle
//
// History: version 1.0
// start at 2000/11/01 11:00 finish at
//
////////////////////////////////////////////////////////////////////////////////
using BBS ; //my own namespace
using System;
using System.Data;
using System.Data.SQL;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing ;
using System.Web.Security ;
using System.Collections ;
using System.Text.RegularExpressions ;
public class ShowTopic : Page
{
public int ForumID ;
public int ID ;
public Label lblForumName ; //板块名称
public HyperLink linkMaster ; //斑竹连接
public Label lblTopicCounts ; //论坛贴子数
public HtmlImage imgNew1 ; //是否新贴子图片
public HtmlImage imgOICQ ; //oicq图片
public HyperLink linkForumName ; //板块名称
public HyperLink linkPrev ; //上一主题
public HyperLink linkPrev1 ; //上一主题
public HyperLink linkNext ; //下一主题
public HyperLink linkNext1 ; //下一主题
public Panel panReply ; //回复
//本贴
public HyperLink linkAuthor ; //作者
public Label lblTitle ; //主题
public Label lblPostTime ; //发表时间
public Label lblHits ; //本贴点击数
public HtmlGenericControl divSignature ; //用户签名
public HtmlGenericControl divContent ; //内容
public HtmlImage imgFace ; //表情图片
public void Page_Load(object sender , EventArgs e)
{
int m_intID = 0;
//取页面参数
try
{
m_intID = Request.QueryString["id"].ToInt32() ;
ID = m_intID ;
}
catch(Exception exp)
{
Response.Write("[ln48]:" + exp.ToString());
}
finally
{
Dictionary objUserList = (Dictionary)Application["User"] ; //用户列表
//取贴子
SQLConnection myConnection = new SQLConnection("server=server1;uid=sa;pwd=;database=BBS");
SQLCommand myCommand = new SQLCommand("up_GetTopics" , myConnection);
myCommand.ActiveConnection = myConnection ;
myCommand.CommandType = CommandType.StoredProcedure;
SQLParameter workParam = null;
//贴子id
workParam = myCommand.Parameters.Add(new SQLParameter("@a_intID", SQLDataType.Int, 4));
workParam.Direction = ParameterDirection.Input;
workParam.Value = m_intID ;
SQLDataReader myReader ;
try
{
myConnection.Open();
myCommand.Execute(out myReader);
//首先取出上一主题、下一主题的id号
if (myReader.Read())
{
linkPrev.NavigateUrl = (int)myReader["ProvID"]==0 ? "" : "showtopic.aspx?id=" + myReader["ProvID"].ToString() ;
linkPrev1.NavigateUrl = linkPrev.NavigateUrl ;
linkNext.NavigateUrl = (int)myReader["NextID"]==0 ? "" : "showtopic.aspx?id=" + myReader["NextID"].ToString() ;
linkNext1.NavigateUrl = linkNext.NavigateUrl ;
}
else
{
Response.Redirect("default.aspx") ;
}
//取出论坛信息
//if (myReader.NextResult() )
//{
//myReader.Read() ;
//显示板块信息
//Response.Write(myReader.FieldCount.ToString() );
//ShowForumInfo(5) ;
//}
//else
//{
//Response.Redirect("default.aspx") ;
//}
//显示本贴内容
if (myReader.NextResult() && myReader.Read())
{
ForumID = (int)myReader[2] ;
ShowForumInfo((int)myReader[2]) ;
//作者
linkAuthor.NavigateUrl = myReader[5].ToString() == "" ? ""
: "mailto:" + myReader[5].ToString() ;
linkAuthor.Text = myReader[4].ToString() ;
linkAuthor.ToolTip = objUserList.Contains(myReader[3].ToString())
? "当前在线,写信给他。" : "不在线,写信给他。" ;
//主题
lblTitle.Text = myReader[8].ToString() ;
//发表时间
lblPostTime.Text = myReader[10].ToString() ;
//本帖点击数
lblHits.Text = myReader[12].ToString() ;
//签名
divSignature.InnerHtml = myReader[13].ToString() ;
//内容
String strContent = myReader[9].ToString() ;
divContent.InnerHtml = ubb.UnEncode (strContent) ;
//表情图片
imgFace.Src = "images/icon" + myReader[11].ToString().Trim() + ".gif" ;
}
else
{
//Response.Redirect("default.aspx") ;
}
//显示回复
myReader.NextResult() ;
while (myReader.Read())
{
//缩进
for (int i = 0 ; i < myReader[1].ToString().ToInt32() ; i ++)
{
panReply.Controls.Add(new LiteralControl("<ul>")) ;
}
//显示表情图片
panReply.Controls.Add(new LiteralControl(
"<img src=images/icon" + myReader[11].ToString().Trim()
+ ".gif>")) ;
//显示id,点击数
panReply.Controls.Add(new LiteralControl("(id:"
+ myReader[0].ToString() + " 点击:"
+ myReader[12].ToString() + " )")) ;
//显示标题
String strTemp ;
if (myReader.GetInt32(0) == m_intID)
{
strTemp = "<font class=title><font color=red>"
+ myReader[8].ToString() + "</font></font>" ;
}
else
{
strTemp = "<a href=showtopic.aspx?id="
+ myReader[0].ToString() + ">"
+ "<font class=title><font color=green>"
+ myReader[8].ToString() + "</font></font></a>" ;
}
panReply.Controls.Add(new LiteralControl(strTemp)) ;
//字节数
panReply.Controls.Add(new LiteralControl("("
+ myReader[14].ToString() + "字节)")) ;
//缩进
for (int i = 0 ; i < myReader[1].ToString().ToInt32() ; i ++)
{
panReply.Controls.Add(new LiteralControl("</ul>")) ;
}
//panReply.Visible = false ;
}
}
catch(Exception exp)
{
Response.Write(exp.ToString()) ;
}
finally
{
//myReader.Close() ;
myConnection.Close();
//Response.Redirect("default.aspx") ;
}
}
}
//显示板块信息函数
private void ShowForumInfo(int a_intForumID)
{
SQLConnection myConnection = new SQLConnection("server=server1;uid=sa;pwd=;database=BBS");
SQLCommand myCommand = new SQLCommand("up_GetForum" , myConnection);
myCommand.ActiveConnection = myConnection ;
myCommand.CommandType = CommandType.StoredProcedure;
SQLParameter workParam = null;
//论坛id
workParam = myCommand.Parameters.Add(new SQLParameter("@a_ForumID", SQLDataType.Int, 4));
workParam.Direction = ParameterDirection.Input;
workParam.Value = a_intForumID ;
SQLDataReader myReader ;
try
{
myConnection.Open();
myCommand.Execute(out myReader);
myReader.Read() ;
//板块名称
lblForumName.Text = myReader["CategoryName"].ToString() ;
lblForumName.CssClass = "BigTitle" ;
lblForumName.ToolTip = myReader["Description"].ToString() ;
linkForumName.CssClass = "bigtitle" ;
linkForumName.Text = lblForumName.Text ;
linkForumName.ToolTip = myReader["Description"].ToString() ;
linkForumName.NavigateUrl = "forum.aspx?id=" + myReader["CategoryID"].ToString() ;
//oicq
if (myReader["OICQ"].ToString() != "")
{
imgOICQ.Src = "http://infocenter.tencent.com/" + myReader["OICQ"].ToString() + "/s/00/99" ;
imgOICQ.Alt = "OICQ:" + myReader["OICQ"].ToString() ;
//imgOICQ.Src = "images/off.gif" ;
}
else
{
imgOICQ.Src = "" ;
imgOICQ.Alt = "没留OICQ。" ;
}
//贴子数
lblTopicCounts.Text = myReader["NewTopicNumber"].ToString() ;
lblTopicCounts.ToolTip = "当前贴子数:" + lblTopicCounts.Text ;
//版主
linkMaster.Text = myReader["UserName"].ToString() ;
linkMaster.NavigateUrl = (myReader["Email"].ToString() == "" ? "" :
"MailTo:" + myReader["Email"].ToString()) ;
linkMaster.ToolTip = (myReader["Email"].ToString() == "" ? "版主没留Email。" :"写信给版主。") ;
}
catch(Exception exp)
{
Response.Write(exp.ToString()) ;
//Response.Redirect("error.asp") ;
}
finally
{
myConnection.Close();
//Response.Redirect("default.aspx") ;
}
}
//发新贴子
public void OnPost(object Source, ImageClickEventArgs e)
{
Page.Navigate("post.aspx?forumid=" + ForumID.ToString ()) ;
//Response.Write(e.ToString() ) ;
}
//回应
public void OnReply(object Source, ImageClickEventArgs e)
{
Page.Navigate("post.aspx?id=" + ID.ToString ()) ;
//Response.Write(e.ToString() ) ;
}
}
……