网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.如何开发基于ASP的FLASH MX在线图.
.数字和字母组合并生成图片的验证.
.用XML+FSO+JS实现服务器端文件的.
.利用ASP存取各种常用类型数据库(.
.在ASP中使用Oracle数据库.
.ASP程序界面的多语言支持.
.用Asp隐藏文件路径实现防盗链.
.使用InstallShield制作ASP安装程.
.股票报价的WebService之三.
.asp生日自动提醒小程式.
.在Web界面下如何生成像资源管理器.
.如何用ASP编写网站统计系统(四).
.XMLHTTP+Javascript+Asp写得聊天.
.ASP程序中输出Excel文件实例一则.
.基于WEB系统的多语言支持--ASP国.
.关于页面局部刷新例程.
.利用XSL和ASP在线编辑XML文档.
.制作我们自己的Ebay(拍卖系统)(7).
.金额大小写转换的asp完全无错版本.
.用EasyMailObject组件处理Exchan.

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

发表日期:2000-12-4


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='images/closed.gif' alt='没有新回复。'>" ;
                    }
                  else if((int)myReader["TotalChilds"] < 5)
                    {
                      strInnerHtml = "<img src='images/closedb.gif' alt='有新回复,不过不多。'>";
                    }
                  else if((int)myReader["TotalChilds"] >= 10)
                    {
                      strInnerHtml = "<img src='images/hotclosedb.gif' alt='太火了。'>";
                    }                    
                  else if((int)myReader["TotalChilds"] >= 5)
                    {
                      strInnerHtml = "<img src='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 ;
     
   }  
}   

上一篇:用多种方法制作WEB页面的计数器 人气:10330
下一篇:asp+的论坛列表程序---页面部分 人气:10249
浏览全部的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐