WEB开发网
开发学院WEB开发ASP asp+的论坛列表程序---代码部分 阅读

asp+的论坛列表程序---代码部分

 2000-12-04 10:54:49 来源:WEB开发网   
核心提示:asp+的论坛列表程序---代码部分【bigeagle】 于 2000-11-13 15:38:57 加贴在 Joy ASP ↑:/// File name: forum.cs Description: forum.aspx的后台代码 date:2000/10/13 PRogramming: Bigeagle Hist
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 = "<img src='http://www.cncms.com/images/closed.gif' alt='没有新回复。'>" ;
          }
         else if((int)myReader["TotalChilds"] < 5)
          {
           strInnerHtml = "<img src='http://www.cncms.com/images/closedb.gif' alt='有新回复,不过不多。'>";
          }
         else if((int)myReader["TotalChilds"] >= 10)
          {
           strInnerHtml = "<img src='http://www.cncms.com/images/hotclosedb.gif' alt='太火了。'>";
          }          
         else if((int)myReader["TotalChilds"] >= 5)
          {
           strInnerHtml = "<img src='http://www.cncms.com/images/hotclosed.gif' alt='回复不少。'>";
          }
         tdStatus.Controls.Add(new LiteralControl(strInnerHtml)) ;
         tr.Cells.Add(tdStatus) ;
         
         //表情图片
         TableCell tdFace = new TableCell() ;
         strInnerHtml = "<img src='images/icon"+myReader["FaceID"].ToString() +".gif'>" ;
         //Response.Write(strInnerHtml) ;
         tdFace.Controls.Add(new LiteralControl(strInnerHtml)) ;
         tr.Cells.Add(tdFace) ;
         
         //主题
         TableCell tdTitle = new TableCell() ;
         strInnerHtml = "<a href='ShowTopic.aspx?id=" + myReader["ID"].ToString() + "'>"
                + myReader["Title"].ToString() + "</a>";
         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 ;
   
  } 
}  

Tags:asp 论坛 列表

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接