留言板分三個模塊
notepage
namespace notpage
{
using System;
using System
using System
using System
////////////////////////////////////////////////////////////////////
//
// 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
//
this
this
this
this
this
}
/// <summary>
///
/// 取得留言的內容
///
/// </summary>
/// <param name=
public notepage GetTopic(int a_intID)
{
//
// TODO: Add Constructor Logic here
//
//讀取數據庫
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand
myCommand
myCommand
myCommand
myCommand
notepage objNp = new notepage();
try
{
myConn
SQLDataReader myReader ;
myCommand
if (myReader
{
objNp
objNp
objNp
objNp
objNp
}
//清場
myReader
myConn
}
catch(Exception e)
{
throw(new Exception(
}
return objNp;
}
/// <summary>
///
/// 目的
///
/// 利用構造函數來傳遞信息
///
/// </summary>
/// <param name=
public bool AddTopic(notepage n_Topic)
{
//
// TODO: Add Constructor Logic here
//
//讀取數據庫
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand
myCommand
myCommand
myCommand
myCommand
myCommand
myCommand
myCommand
myCommand
try
{
myConn
myCommand
//清場
myConn
}
catch(Exception e)
{
throw(new Exception(
}
return true;
}
/// <summary>
/// 取的貼子列表
/// </summary>
/// <remarks>
/// 返回一個Topic數組
/// </remarks>
public ArrayList GetTopicList()
{
//定義一個forum數組做為返回值
ArrayList arrForumList =new ArrayList() ;
//從數據庫中讀取留言列表
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand
myCommand
myCommand
try
{
myConn
SQLDataReader myReader ;
myCommand
for (int i =
{
notepage objItem = new notepage() ;
objItem
objItem
objItem
objItem
objItem
arrForumList
}
//清場
myReader
myConn
}
catch(SQLException e)
{
throw(new Exception(
//return null ;
}
return arrForumList ;
}
}
}
myconn
namespace notpage
{
using System;
using System
/// Summary description for myconn
/// </summary>
public class myconn:System
{
private void InitializeComponent ()
{
}
public myconn()
{
//
// TODO: Add Constructor Logic here
//
this
this
this
this
}
}
}
添加留言addTopic
<%@ Page language=
<html><head>
<meta content=
<meta content=C# name=CODE_LANGUAGE></head>
<body>
<form method=post runat=
<table cellSpacing=
<tr>
<td>留言主題
<td><asp:textbox id=txtTitle runat=
<tr>
<td>姓名
<td><asp:textbox id=txtAuthor runat=
<tr>
<td>留言內容</TD>
<td><asp:textbox id=txtContent runat=
id=btnSubmit runat=
text=
</body></html></P><P>對應的cs
namespace notpage
{
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
/// Summary description for AddTopic
/// </summary>
public class AddTopic : System
{
protected System
protected System
protected System
protected System
public AddTopic()
{
Page
}</P><P> protected void Page_Load(object sender
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}</P><P> protected void Page_Init(object sender
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
InitializeComponent();
}</P><P> /// <summary>
/// Required method for Designer support
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
btnSubmit
this
}
public void OnSubmit(Object sender
{
if (Page
{
//數據入庫
try
{
notepage objNp = new notepage();
objNp
objNp
objNp
objNp
notepage objNp
if(objNp
{
Response
}
}
catch(Exception exp)
{
#if DEBUG
Response
return ;
#endif//DEBUG
}
}
}</P><P> }
}
顯示列表list
<%@ Page language=
<html><head>
<meta name=
<meta name=
<body>
<form method=
<TABLE WIDTH=
<TR>
<TD>主題</TD>
<TD>留言人</TD>
<TD>留言時間</TD>
</TR>
<asp:label id=
</TABLE></P><P> </body></html>
namespace notpage
{
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
/// <summary>
/// Summary description for list
/// </summary>
public class list : System
{
protected System
public list()
{
Page
}</P><P> protected void Page_Load(object sender
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}</P><P> protected void Page_Init(object sender
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
InitializeComponent();
Init_tdtitle();
</P><P> }
</P><P> /// <summary>
/// Required method for Designer support
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
this
}
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 = np
for ( int i =
{
notepage objTopic = (notepage)arrTopic[i] ;
string str =
str = str +
str = str +
n_tdtitle
}
}
catch(Exception e)
{
throw(new Exception(
}</P><P> }
}
}
查看留言內容showtopic
<%@ Page language=
<html><head>
<meta content=
<meta content=C# name=CODE_LANGUAGE></head>
<body>
<form method=post runat=
<p align=center><font color=red><b>察看留言</b></font></p><br>
<p align=left><font color=blue>留言主題
<br>留言時間
<asp:label
id=n_tdAuthor runat=
runat=
</body></html>
對應的cs
namespace notpage
{
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
/// Summary description for showTopic
/// </summary>
public class showTopic : System
{
protected System
protected System
protected System
protected System
protected System
protected System
public showTopic()
{
Page
}</P><P> protected void Page_Load(object sender
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}</P><P> protected void Page_Init(object sender
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer
//
int int_ID;
int_ID = Request
notepage np = new notepage();
notepage objNp = np
n_tdtitle
n_tdContent
n_tdAuthor
n_tdAdddate
InitializeComponent();
}</P><P> /// <summary>
/// Required method for Designer support
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
this
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/12898.html