留言板分三个模块列出留言列表显示详细内容发表留言
notepagecs
namespace notpage
{
using System;
using SystemDataSQL ;
using SystemData ;
using SystemCollections ;
////////////////////////////////////////////////////////////////////
//
// Class Name : 留言板
//
// Description: 构造一个留言板对象
//
// date: //
//
// 作者 天啦
/// ////////////////////////////////////////////////////////////////
/// <summary>
/// Summary description for notepage
/// </summary>
public class notepage
{
//私有变量
private int n_intID ; //ID编号
private string n_strTitle ; //主题
private string n_strAuthor ; //留言人
private string n_strContent ; //留言内容
private DateTime n_dateTime ; //留言时间
//属性
public int ID
{
get
{
return n_intID ;
}
set
{
n_intID = value;
}
}
public string Title
{
get
{
return n_strTitle ;
}
set
{
n_strTitle = value;
}
}
public string Author
{
get
{
return n_strAuthor ;
}
set
{
n_strAuthor = value ;
}
}
public string Content
{
get
{
return n_strContent ;
}
set
{
n_strContent = value ;
}
}
public DateTime adddate
{
get
{
return n_dateTime;
}
set
{
n_dateTime = value;
}
}
//构造函数
public notepage()
{
//
// TODO: Add Constructor Logic here
//
thisn_intID = ;
thisn_strTitle = ;
thisn_strAuthor = ;
thisn_strContent = ;
thisn_dateTime = SystemDateTimeNow;
}
/// <summary>
///
/// 取得留言的内容
///
/// </summary>
/// <param name=a_intID> </param>
public notepage GetTopic(int a_intID)
{
//
// TODO: Add Constructor Logic here
//
//读取数据库
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommandActiveConnection = myConn ;
myCommandCommandText = n_GetTopicInfo ; //调用存储过程
myCommandCommandType = CommandTypeStoredProcedure ;
myCommandParametersAdd(new SQLParameter(@a_intTopicID SQLDataTypeInt)) ;
myCommandParameters[@a_intTopicID]Value = a_intID ;
notepage objNp = new notepage();
try
{
myConnOpen() ;
SQLDataReader myReader ;
myCommandExecute(out myReader) ;
if (myReaderRead())
{
objNpID = (int)myReader[ID] ;
objNpTitle = (string)myReader[Title] ;
objNpAuthor = (string)myReader[Author] ;
objNpContent = (string)myReader[Content];
objNpadddate = (DateTime)myReader[adddate];
}
//清场
myReaderClose();
myConnClose() ;
}
catch(Exception e)
{
throw(new Exception(取贴子失败: + eToString())) ;
}
return objNp;
}
/// <summary>
///
/// 目的将留言的内容入库
///
/// 利用构造函数来传递信息
///
/// </summary>
/// <param name=n_Topic> </param>
public bool AddTopic(notepage n_Topic)
{
//
// TODO: Add Constructor Logic here
//
//读取数据库
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommandActiveConnection = myConn ;
myCommandCommandText = n_addTopic ; //调用存储过程
myCommandCommandType = CommandTypeStoredProcedure ;
myCommandParametersAdd(new SQLParameter(@a_strTitle SQLDataTypeVarChar)) ;
myCommandParameters[@a_strTitle]Value = n_TopicTitle ;
myCommandParametersAdd(new SQLParameter(@a_strAuthor SQLDataTypeVarChar)) ;
myCommandParameters[@a_strAuthor]Value = n_TopicAuthor ;
myCommandParametersAdd(new SQLParameter(@a_strContent SQLDataTypeVarChar)) ;
myCommandParameters[@a_strContent]Value = n_TopicContent ;
try
{
myConnOpen() ;
myCommandExecuteNonQuery() ;
//清场
myConnClose() ;
}
catch(Exception e)
{
throw(new Exception(取贴子失败: + eToString())) ;
}
return true;
}
/// <summary>
/// 取的贴子列表
/// </summary>
/// <remarks>
/// 返回一个Topic数组
/// </remarks>
public ArrayList GetTopicList()
{
//定义一个forum数组做为返回值
ArrayList arrForumList =new ArrayList() ;
//从数据库中读取留言列表
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommandActiveConnection = myConn ;
myCommandCommandText = n_GetTopicList ; //调用存储过程
myCommandCommandType = CommandTypeStoredProcedure ;
try
{
myConnOpen() ;
SQLDataReader myReader ;
myCommandExecute(out myReader) ;
for (int i = ; myReaderRead() ; i++)
{
notepage objItem = new notepage() ;
objItemID = myReader[ID]ToString()ToInt() ;
objItemTitle = myReader[Title]ToString() ;
objItemAuthor = myReader[Author]ToString() ;
objItemadddate = myReader[adddate]ToString()ToDateTime();
objItemContent = myReader[Content]ToString();
arrForumListAdd(objItem) ;
}
//清场
myReaderClose();
myConnClose() ;
}
catch(SQLException e)
{
throw(new Exception(数据库出错: + eToString())) ;
//return null ;
}
return arrForumList ;
}
}
}
myconncs
namespace notpage
{
using System;
using SystemDataSQL ;</P><P> /// <summary>
/// Summary description for myconn
/// </summary>
public class myconn:SystemDataSQLSQLConnection
{
private void InitializeComponent ()
{
}
public myconn()
{
//
// TODO: Add Constructor Logic here
//
thisDatabase = back ;
thisDataSource = LUOCHANG ;
thisUserID = sa ;
thisPassword = ;
}
}
}
添加留言addTopicaspx
<%@ Page language=c# Codebehind=AddTopiccs AutoEventWireup=false Inherits=notpageAddTopic %>
<html><head>
<meta content=Microsoft Visual Studio name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE></head>
<body>
<form method=post runat=server>
<table cellSpacing= cellPadding= width=% border=>
<tr>
<td>留言主题</TD>
<td><asp:textbox id=txtTitle runat=server maxlength= columns=></asp:textbox></TD></TR>
<tr>
<td>姓名</TD>
<td><asp:textbox id=txtAuthor runat=server maxlength= columns=></asp:textbox></TD></TR>
<tr>
<td>留言内容</TD>
<td><asp:textbox id=txtContent runat=server maxlength= columns= rows= TextMode=MultiLine></asp:textbox><asp:button
id=btnSubmit runat=Server
text=确认></asp:button></TD></TR></TABLE></FORM>
</body></html></P><P>对应的cs
namespace notpage
{
using System;
using SystemCollections;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemWeb;
using SystemWebSessionState;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIHtmlControls;</P><P> /// <summary>
/// Summary description for AddTopic
/// </summary>
public class AddTopic : SystemWebUIPage
{
protected SystemWebUIWebControlsTextBox txtContent;
protected SystemWebUIWebControlsTextBox txtAuthor;
protected SystemWebUIWebControlsTextBox txtTitle;
protected SystemWebUIWebControlsButton btnSubmit;
public AddTopic()
{
PageInit += new SystemEventHandler(Page_Init);
}</P><P> protected void Page_Load(object sender EventArgs e)
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}</P><P> protected void Page_Init(object sender EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
InitializeComponent();
}</P><P> /// <summary>
/// Required method for Designer support do not modify
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
btnSubmitClick += new SystemEventHandler (thisOnSubmit);
thisLoad += new SystemEventHandler (thisPage_Load);
}
public void OnSubmit(Object sender EventArgs e)
{
if (PageIsValid)
{
//数据入库
try
{
notepage objNp = new notepage();
objNpTitle = txtTitleText;
objNpAuthor = txtAuthorText;
objNpContent = txtContentText;
objNpadddate = SystemDateTimeNow;
notepage objNp = new notepage();
if(objNpAddTopic(objNp))
{
ResponseWrite (<p align=center class=cn>成功留言点击<a href = listaspx>此处</a>查看留言列表!</p>) ;
}
}
catch(Exception exp)
{
#if DEBUG
ResponseWrite (出现异常 + expMessage) ;
return ;
#endif//DEBUG
}
}
}</P><P> }
}
显示列表listaspx
<%@ Page language=c# Codebehind=listcs AutoEventWireup=false Inherits=notpagelist %>
<html><head>
<meta name=GENERATOR Content=Microsoft Visual Studio >
<meta name=CODE_LANGUAGE Content=C#></head>
<body>
<form method=post runat=server></P><P> </form><a href = addTopicaspx>发表留言</a><br>
<TABLE WIDTH=% HEIGHT= BORDER= CELLSPACING= CELLPADDING= id=liuyan>
<TR>
<TD>主题</TD>
<TD>留言人</TD>
<TD>留言时间</TD>
</TR>
<asp:label id=n_tdtitle runat=Server></asp:label>
</TABLE></P><P> </body></html>
namespace notpage
{
using System;
using SystemCollections;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemWeb;
using SystemWebSessionState;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIHtmlControls;</P><P> </P><P>
/// <summary>
/// Summary description for list
/// </summary>
public class list : SystemWebUIPage
{
protected SystemWebUIWebControlsLabel n_tdtitle;
public list()
{
PageInit += new SystemEventHandler(Page_Init);
}</P><P> protected void Page_Load(object sender EventArgs e)
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}</P><P> protected void Page_Init(object sender EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
InitializeComponent();
Init_tdtitle();
</P><P> }
</P><P> /// <summary>
/// Required method for Designer support do not modify
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
thisLoad += new SystemEventHandler (thisPage_Load);
}
protected void Init_tdtitle()
{
InitializeComponent();
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
try
{
notepage np = new notepage();</P><P> ArrayList arrTopic = npGetTopicList();
for ( int i = ; i < arrTopicCount ; i ++)
{
notepage objTopic = (notepage)arrTopic[i] ;
string str =<tr><td><a href = showTopicaspx?id=+objTopicIDToString()+> + objTopicTitleToString() + </a></td>;
str = str +<td> + objTopicAuthorToString()+</td>;
str = str +<td> + objTopicadddateToString()+</td></tr>;
n_tdtitleText = str + n_tdtitleText;
}
}
catch(Exception e)
{
throw(new Exception(取得贴子列表出错 + eToString())) ;
}</P><P> }
}
}
查看留言内容showtopicaspx
<%@ Page language=c# Codebehind=showTopiccs AutoEventWireup=false Inherits=notpageshowTopic %>
<html><head>
<meta content=Microsoft Visual Studio name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE></head>
<body>
<form method=post runat=server>
<p align=center><font color=red><b>察看留言</b></font></p><br>
<p align=left><font color=blue>留言主题<asp:label id=n_tdtitle runat=Server forecolor=Black></asp:label>
<br>留言时间<asp:label id=n_tdAdddate runat=Server forecolor=Black></asp:label><br></font><font color=blue>留言人
<asp:label
id=n_tdAuthor runat=server forecolor=Black></asp:label><br>留言内容<asp:label id=n_tdContent
runat=Server forecolor=Black></asp:label> </font></p></form>
</body></html>
对应的cs
namespace notpage
{
using System;
using SystemCollections;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemWeb;
using SystemWebSessionState;
using SystemWebUI;
using SystemWebUIWebControls;
using SystemWebUIHtmlControls;</P><P> /// <summary>
/// Summary description for showTopic
/// </summary>
public class showTopic : SystemWebUIPage
{
protected SystemWebUIWebControlsLabel n_tdAuthor;
protected SystemWebUIWebControlsLabel td;
protected SystemWebUIWebControlsLabel n_tdContent;
protected SystemWebUIWebControlsLabel n_tdAdddate;
protected SystemWebUIWebControlsLabel n_tdtitle;
protected SystemWebUIWebControlsLabel n_ttitle;
public showTopic()
{
PageInit += new SystemEventHandler(Page_Init);
}</P><P> protected void Page_Load(object sender EventArgs e)
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}</P><P> protected void Page_Init(object sender EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
int int_ID;
int_ID = RequestQueryString[ID]ToInt();
notepage np = new notepage();
notepage objNp = npGetTopic(int_ID);
n_tdtitleText = objNpTitleToString();
n_tdContentText = objNpContentToString();
n_tdAuthorText = objNpAuthorToString();
n_tdAdddateText = objNpadddateToString();
InitializeComponent();
}</P><P> /// <summary>
/// Required method for Designer support do not modify
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
thisLoad += new SystemEventHandler (thisPage_Load);
}
}
}