-
您的位置:首页 → 网页设计 → ASP实例 → asp+的论坛列表程序---代码部分
asp+的论坛列表程序---代码部分
时间:2004/11/7 2:52:00来源:本站整理作者:蓝点我要评论(0)
-
asp+的论坛列表程序---代码部分
--------------------------------------------------------------------------------
【bigeagle】 于 2000-11-13 15:38:57 加贴在 Joy ASP ↑:
///////////////////////////////////////////////////////////////////////////////
//
// File name: forum.cs
//
// Description: forum.aspx的后台代码
//
// date: 2000/10/13
//
// Programming: Bigeagle
//
// History: version 1.0
// start at 2000/10/13 16:45 finish
//
////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections ;
using System.Data;
using System.Data.SQL;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing ;
public class Forum : Page
{
//public Image imgIfNew ;
public Label lblForumName ;
public HyperLink linkMaster ;
public Label lblForumName1 ;
public ImageButton btnPostNew ;
public ImageButton btnPostNew1 ;
public Label lblTopicCounts ;
public Label lblTopicCounts1 ;
public Label lblPerPage ;
public Label lblPosition ;
public HtmlImage imgOICQ ;
public HyperLink linkFirstPage ;
public HyperLink linkPrevPage ;
public HyperLink linkNextPage ;
public HyperLink linkLastPage ;
public HyperLink linkFirstPage1 ;
public HyperLink linkPrevPage1 ;
public HyperLink linkNextPage1 ;
public HyperLink linkLastPage1 ;
public DropDownList selChangeForum ; //转换版面下拉框
public Table tblTopic ;
public void Page_Load(Object sender , EventArgs e)
{
Int32 intForumID = new Int32();
Int32 intPageNo = new Int32() ;
int intPageSize = 20 ;
int intPageCount = 0 ;
int intTopicCounts = 0 ;
//--edit by bigeagle 2000/10/25------------------
// if (Session["LoginID"] == null )
// {
// Response.Redirect("login.aspx") ;
// }
//-----------------------------------------------
//接收论坛ID
try
{
intForumID = Request.QueryString["ID"].ToInt32() ;
}
catch(Exception exp)
{
Response.Write(exp.ToString()) ;
}
GetForumInfo(intForumID) ;
//接收页号
try
{
intPageNo = Request.QueryString["PageNo"].ToInt32() ;
}
catch(Exception exp)
{
intPageNo = 1 ;
}
//规范页号,页数
intTopicCounts = lblTopicCounts1.Text.ToInt32() ;
if (intTopicCounts <= intPageSize)
{
intPageCount = 1 ;
}
else if (intTopicCounts / intPageSize == 0)
{
intPageCount = intTopicCounts / intPageSize ;
}
else
{
intPageCount = (int)(intTopicCounts / intPageSize) + 1 ;
}
if (intPageNo < 1)
{
intPageNo = 1 ;
}
else if (intPageNo > intPageCount)
{
intPageNo = intPageCount ;
}
//初始化页面显示
lblTopicCounts.Text = intTopicCounts.ToString() ;
lblTopicCounts.ForeColor = Color.Green ;
lblPerPage.Text = intPageSize.ToString() ;
lblPerPage.ForeColor = Color.Green ;
lblPosition.Text = intPageNo.ToString() + "/" + intPageCount.ToString() ;
lblPosition.ForeColor = Color.Green ;
//更新导航栏
//首页
if (intPageNo != 1)
{
linkFirstPage.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString() ;
linkFirstPage.ToolTip = "回到首页" ;
linkFirstPage1.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString() ;
linkFirstPage1.ToolTip = "回到首页" ;
}
else
{
linkFirstPage.ToolTip = "你现在就在首页。" ;
linkFirstPage1.ToolTip = "你现在就在首页。" ;
}
//前页
if (intPageNo > 1 )
{
linkPrevPage.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString()
+ "&PageNo=" + (intPageNo - 1).ToString() ;
linkPrevPage.ToolTip = "回到上一页。" ;
linkPrevPage1.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString()
+ "&PageNo=" + (intPageNo - 1).ToString() ;
linkPrevPage1.ToolTip = "回到上一页。" ;
}
else
{
linkPrevPage.ToolTip = "你现在就位于第一页,你还想上哪儿?" ;
linkPrevPage1.ToolTip = "你现在就位于第一页,你还想上哪儿?" ;
}
//后页
if (intPageNo < intPageCount )
{
linkNextPage.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString()
+ "&PageNo=" + (intPageNo + 1).ToString() ;
linkNextPage.ToolTip = "到下一页。" ;
linkNextPage1.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString()
+ "&PageNo=" + (intPageNo + 1).ToString() ;
linkNextPage1.ToolTip = "到下一页。" ;
}
else
{
linkNextPage.ToolTip = "你现在就位于最后一页,你还想上哪
儿?" ;
linkNextPage1.ToolTip = "你现在就位于最后一页,你还想上哪
儿?" ;
}
//末页
if (intPageNo != intPageCount)
{
linkLastPage.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString()
+ "&PageNo=" + intPageCount.ToString() ;
linkLastPage.ToolTip = "到最后一页。" ;
linkLastPage1.NavigateUrl = "forum.aspx?" + "ID=" + intForumID.ToString()
+ "&PageNo=" + intPageCount.ToString() ;
linkLastPage1.ToolTip = "到最后一页。" ;
}
else
{
linkLastPage.ToolTip = "你现在就位于最后一页。" ;
linkLastPage1.ToolTip = "你现在就位于最后一页。" ;
}
//贴子列表
ShowTopicList(intForumID , 0 , intPageNo , intPageSize) ;
//显示转换版面下拉列表
ShowChangeForum(intForumID) ;
}
private void ShowTopicList(int a_intForumID , int a_intDays , int a_intPageNo , int a_intPageSize)
{
//读出纪录
SQLConnection myConnection = new SQLConnection("server=server1;uid=sa;pwd=;database=BBS");
SQLCommand myCommand = new SQLCommand("up_TopicsList" , 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 ;
//限定天数
workParam = myCommand.Parameters.Add(new SQLParameter("@a_intDays", SQLDataType.Int, 4));
workParam.Direction = ParameterDirection.Input;
workParam.Value = a_intDays ;
//页号
workParam = myCommand.Parameters.Add(new SQLParameter("@a_intPageNo", SQLDataType.Int, 4));
workParam.Direction = ParameterDirection.Input;
workParam.Value = a_intPageNo ;
//每页显示数
workParam = myCommand.Parameters.Add(new SQLParameter("@a_intPageSize", SQLDataType.Int, 4));
workParam.Direction = ParameterDirection.Input;
workParam.Value = a_intPageSize ;
SQLDataReader myReader ;
try
{
myConnection.Open();
myCommand.Execute(out myReader);
//Response.Write(myReader.HasValue.ToString());
//取纪录
if (lblTopicCounts.Text.ToInt32() == 0) //如果没有发言
{
TableRow tr = new TableRow() ;
tr.BackColor = Color.White ;
TableCell td = new TableCell() ;
td.ColumnSpan = 6 ;
td.VerticalAlign = VerticalAlign.Middle ;
td.HorizontalAlign = HorizontalAlign.Center ;
td.Height =200 ;
td.Controls.Add(new LiteralControl("目前尚未有人发言!")) ;
tr.Cells.Add(td) ;
tblTopic.Rows.Add(tr) ;
}
else //否则,显示贴字列表
{
while (myReader.Read())
{
String strInnerHtml = "";
TableRow tr = new TableRow() ;
tr.BackColor = Color.White ;
//贴子状态图片
TableCell tdStatus = new TableCell() ;
if ((int)myReader["TotalChilds"] == 0)
{
strInnerHtml = "" ;
}
else if((int)myReader["TotalChilds"] < 5)
{
strInnerHtml = "";
}
else if((int)myReader["TotalChilds"] >= 10)
{
strInnerHtml = "";
}
else if((int)myReader["TotalChilds"] >= 5)
{
strInnerHtml = "";
}
tdStatus.Controls.Add(new LiteralControl(strInnerHtml)) ;
tr.Cells.Add(tdStatus) ;
//表情图片
TableCell tdFace = new TableCell() ;
strInnerHtml = "" ;
//Response.Write(strInnerHtml) ;
tdFace.Controls.Add(new LiteralControl(strInnerHtml)) ;
tr.Cells.Add(tdFace) ;
//主题
TableCell tdTitle = new TableCell() ;
strInnerHtml = ""
+ myReader["Title"].ToString() + "";
tdTitle.Controls.Add(new LiteralControl(strInnerHtml)) ;
tr.Cells.Add(tdTitle) ;
//作者
TableCell tdAuthor = new TableCell() ;
strInnerHtml = myReader["UserName"].ToString() ;
tdAuthor.Controls.Add(new LiteralControl(strInnerHtml)) ;
tr.Cells.Add(tdAuthor) ;
//回复数
TableCell tdReply = new TableCell() ;
strInnerHtml = myReader["TotalChilds"].ToString() ;
tdReply.Controls.Add(new LiteralControl(strInnerHtml)) ;
tr.Cells.Add(tdReply) ;
//最后回复时间
TableCell tdReplyTime = new TableCell() ;
strInnerHtml = myReader["LastReplyTime"].ToString() ;
tdReplyTime.Controls.Add(new LiteralControl(strInnerHtml)) ;
tr.Cells.Add(tdReplyTime) ;
tblTopic.Rows.Add(tr) ;
}
}
}
catch(Exception exp)
{
Response.Write(exp.ToString() ) ;
//Response.Redirect("error.asp") ;
}
finally
{
myConnection.Close();
//Response.Redirect("default.aspx") ;
}
}
private void GetForumInfo(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() ;
lblForumName1.Text = lblForumName.Text ;
lblForumName1.CssClass = "Title" ;
lblForumName1.ToolTip = myReader["Description"].ToString() ;
//贴子数
lblTopicCounts1.Text = myReader["NewTopicNumber"].ToString() ;
lblTopicCounts1.ToolTip = "当前贴子数:" + lblTopicCounts1.Text ;
//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。" ;
}
//版主
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") ;
}
}
//显示转换版面下拉列表
private void ShowChangeForum(int a_intForumID)
{
selChangeForum.Width = 200 ;
}
}
相关阅读
Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么
-
热门文章
没有查询到任何记录。
最新文章
迅雷新手完全入门手册
asp下面javascript上传图片限制格式大小方法告诉大家网页弹出窗口应用总结ASP常见错误类型大全asp常见错误分析和解决办法
人气排行
总是弹出visual studio 实时调试器 三种解决SQLSERVER存储过程及调用详解Asp获取真实IP地址ASP中连接Mssql的几种方法一个简单好用的UBB编辑器(含代码)如何用Split将字符串转换为数组并获取数组下ASP防止表单重复提交的办法告诉你免费的简单聊天室源代码
查看所有0条评论>>