直播中
public class notepage
{
//私有變量
private int n_intID ; //ID編號
private string n_strTitle ; //主題
private string n_strAuthor ; //留言人
private string n_strContent ; //留言內(nèi)容
private DateTime n_dateTime ; //留言時間</P><P>
//屬性
</P><P> public int ID
{
get
{
return n_intID ;
}
set
{
n_intID = value;
}
}</P><P> public string Title
{
get
{
return n_strTitle ;
}
set
{
n_strTitle = value;
}
}</P><P> 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;
}
}
//構造函數(shù)
public notepage()
{
//
// TODO: Add Constructor Logic here
//
this.n_intID = 0 ;
this.n_strTitle = "" ;
this.n_strAuthor = "" ;
this.n_strContent = "" ;
this.n_dateTime = System.DateTime.Now;
}</P><P> /// <summary>
///
/// 取得留言的內(nèi)容
///
/// </summary>
/// <param name="a_intID"> </param>
public notepage GetTopic(int a_intID)
{
//
// TODO: Add Constructor Logic here
//
</P><P>
//讀取數(shù)據(jù)庫
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicInfo" ; //調用存儲過程
myCommand.CommandType = CommandType.StoredProcedure ;
myCommand.Parameters.Add(new SQLParameter("@a_intTopicID" , SQLDataType.Int)) ;
myCommand.Parameters["@a_intTopicID"].Value = a_intID ;</P><P> notepage objNp = new notepage();
try
{
myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;
if (myReader.Read())
{
objNp.ID = (int)myReader["ID"] ;
objNp.Title = (string)myReader["Title"] ;
objNp.Author = (string)myReader["Author"] ;
objNp.Content = (string)myReader["Content"];
objNp.adddate = (DateTime)myReader["adddate"];
}
</P><P>
//清場
myReader.Close();
myConn.Close() ;</P><P> }
catch(Exception e)
{
throw(new Exception("取貼子失敗:" + e.ToString())) ;
}
return objNp;
}</P><P> /// <summary>
///
/// 目的:將留言的內(nèi)容入庫
///
/// 利用構造函數(shù)來傳遞信息
///
/// </summary>
/// <param name="n_Topic"> </param>
public bool AddTopic(notepage n_Topic)
{
//
// TODO: Add Constructor Logic here
//
//讀取數(shù)據(jù)庫
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_addTopic" ; //調用存儲過程
myCommand.CommandType = CommandType.StoredProcedure ;
myCommand.Parameters.Add(new SQLParameter("@a_strTitle" , SQLDataType.VarChar,100)) ;
myCommand.Parameters["@a_strTitle"].Value = n_Topic.Title ;</P><P> myCommand.Parameters.Add(new SQLParameter("@a_strAuthor" , SQLDataType.VarChar,50)) ;
myCommand.Parameters["@a_strAuthor"].Value = n_Topic.Author ;</P><P> myCommand.Parameters.Add(new SQLParameter("@a_strContent" , SQLDataType.VarChar,2000)) ;
myCommand.Parameters["@a_strContent"].Value = n_Topic.Content ;</P><P> try
{
myConn.Open() ;
myCommand.ExecuteNonQuery() ;
//清場
myConn.Close() ;</P><P> }
catch(Exception e)
{
throw(new Exception("取貼子失敗:" + e.ToString())) ;
}
return true;
</P><P> }</P><P>
/// <summary>
/// 取的貼子列表
/// </summary>
/// <remarks>
/// 返回一個Topic數(shù)組
/// </remarks>
public ArrayList GetTopicList()
{
//定義一個forum數(shù)組做為返回值
ArrayList arrForumList =new ArrayList() ;</P><P> //從數(shù)據(jù)庫中讀取留言列表
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicList" ; //調用存儲過程
myCommand.CommandType = CommandType.StoredProcedure ;</P><P> try
{
myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;</P><P> for (int i = 0 ; myReader.Read() ; i++)
{
notepage objItem = new notepage() ;
objItem.ID = myReader["ID"].ToString().ToInt32() ;
objItem.Title = myReader["Title"].ToString() ;
objItem.Author = myReader["Author"].ToString() ;
objItem.adddate = myReader["adddate"].ToString().ToDateTime();
objItem.Content = myReader["Content"].ToString();
arrForumList.Add(objItem) ;
}</P><P>
//清場
myReader.Close();
myConn.Close() ;</P><P> }
catch(SQLException e)
{
throw(new Exception("數(shù)據(jù)庫出錯:" + e.ToString())) ;
//return null ;
}</P><P> return arrForumList ;
}
}
}