一段顯示論壇貼子的程序
發(fā)表時(shí)間:2024-01-21 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]一段顯示論壇貼子的程序 /////////////////////////////////////////////////////////////////////////////////// File name: showtopic.cs//// Description: ...
一段顯示論壇貼子的程序 ///////////////////////////////////////////////////////////////////////////////
//
// File name: showtopic.cs
//
// Description: showtopic.aspx的后臺(tái)代碼
//
// 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 ; //論壇貼子數(shù)
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 ; //回復(fù)
//本貼
public HyperLink linkAuthor ; //作者
public Label lblTitle ; //主題
public Label lblPostTime ; //發(fā)表時(shí)間
public Label lblHits ; //本貼點(diǎn)擊數(shù)
public HtmlGenericControl divSignature ; //用戶簽名
public HtmlGenericControl divContent ; //內(nèi)容
public HtmlImage imgFace ; //表情圖片
public void Page_Load(object sender , EventArgs e)
{
int m_intID = 0;
//取頁(yè)面參數(shù)
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號(hào)
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") ;
//}
//顯示本貼內(nèi)容
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())
? "當(dāng)前在線,寫(xiě)信給他。" : "不在線,寫(xiě)信給他。" ;
//主題
lblTitle.Text = myReader[8].ToString() ;
//發(fā)表時(shí)間
lblPostTime.Text = myReader[10].ToString() ;
//本帖點(diǎn)擊數(shù)
lblHits.Text = myReader[12].ToString() ;
//簽名
divSignature.InnerHtml = myReader[13].ToString() ;
//內(nèi)容
String strContent = myReader[9].ToString() ;
divContent.InnerHtml = ubb.UnEncode (strContent) ;
//表情圖片
imgFace.Src = "images/icon" + myReader[11].ToString().Trim() + ".gif" ;
}
else
{
//Response.Redirect("default.aspx") ;
}
//顯示回復(fù)
myReader.NextResult() ;
while (myReader.Read())
{
//縮進(jìn)
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,點(diǎn)擊數(shù)
panReply.Controls.Add(new LiteralControl("(id:"
+ myReader[0].ToString() + " 點(diǎn)擊:"
+ myReader[12].ToString() + " )")) ;
//顯示標(biāo)題
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)) ;
//字節(jié)數(shù)
panReply.Controls.Add(new LiteralControl("("
+ myReader[14].ToString() + "字節(jié))")) ;
//縮進(jìn)
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") ;
}
}
}
//顯示板塊信息函數(shù)
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 = "沒(méi)留OICQ。" ;
}
//貼子數(shù)
lblTopicCounts.Text = myReader["NewTopicNumber"].ToString() ;
lblTopicCounts.ToolTip = "當(dāng)前貼子數(shù):" + lblTopicCounts.Text ;
//版主
linkMaster.Text = myReader["UserName"].ToString() ;
linkMaster.NavigateUrl = (myReader["Email"].ToString() == "" ? "" :
"MailTo:" + myReader["Email"].ToString()) ;
linkMaster.ToolTip = (myReader["Email"].ToString() == "" ? "版主沒(méi)留Email。" :"寫(xiě)信給版主。") ;
}
catch(Exception exp)
{
Response.Write(exp.ToString()) ;
//Response.Redirect("error.asp") ;
}
finally
{
myConnection.Close();
//Response.Redirect("default.aspx") ;
}
}
//發(fā)新貼子
public void OnPost(object Source, ImageClickEventArgs e)
{
Page.Navigate("post.aspx?forumid=" + ForumID.ToString ()) ;
//Response.Write(e.ToString() ) ;
}
//回應(yīng)
public void OnReply(object Source, ImageClickEventArgs e)
{
Page.Navigate("post.aspx?id=" + ID.ToString ()) ;
//Response.Write(e.ToString() ) ;
}
}