国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

利用c#制作簡單的留言板(1)

2019-11-18 19:17:59
字體:
來源:轉載
供稿:網友

選擇自 masterall 的 Blog

留言板分三個模塊:列出留言列表、顯示詳細內容、發表留言
notepage.cs
namespace notpage
{
using System;
using System.Data.SQL ;
using System.Data ;
using System.Collections ;

 

/// <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.n_intID = 0 ;
this.n_strTitle = "" ;
this.n_strAuthor = "" ;
this.n_strContent = "" ;
this.n_dateTime = System.DateTime.Now;

}

/// <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() ;
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 ;

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"];
}

 

//清場
myReader.Close();
myConn.Close() ;

}
catch(Exception e)
{
throw(new Exception("取貼子失敗:" + e.ToString())) ;
}
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() ;
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 ;

myCommand.Parameters.Add(new SQLParameter("@a_strAuthor" , SQLDataType.VarChar,50)) ;
myCommand.Parameters["@a_strAuthor"].Value = n_Topic.Author ;

myCommand.Parameters.Add(new SQLParameter("@a_strContent" , SQLDataType.VarChar,2000)) ;
myCommand.Parameters["@a_strContent"].Value = n_Topic.Content ;

try
{

myConn.Open() ;
myCommand.ExecuteNonQuery() ;

//清場

myConn.Close() ;

}
catch(Exception e)
{
throw(new Exception("取貼子失敗:" + e.ToString())) ;
}
return true;

 

}


/// <summary>
/// 取的貼子列表
/// </summary>
/// <remarks>
/// 返回一個Topic數組
/// </remarks>
public ArrayList GetTopicList()
{
//定義一個forum數組做為返回值
ArrayList arrForumList =new ArrayList() ;

//從數據庫中讀取留言列表
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
myCommand.CommandText = "n_GetTopicList" ; //調用存儲過程
myCommand.CommandType = CommandType.StoredProcedure ;

try
{
myConn.Open() ;
SQLDataReader myReader ;
myCommand.Execute(out myReader) ;

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) ;
}


//清場
myReader.Close();
myConn.Close() ;

}
catch(SQLException e)
{
throw(new Exception("數據庫出錯:" + e.ToString())) ;
//return null ;
}

return arrForumList ;
}

}
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 连平县| 巴彦县| 普陀区| 双桥区| 望奎县| 治县。| 海伦市| 垫江县| 西城区| 措勤县| 沐川县| 阜阳市| 盱眙县| 广饶县| 商河县| 望谟县| 双流县| 兰西县| 灵武市| 阿克| 莱芜市| 巴马| 兴文县| 平湖市| 海晏县| 长丰县| 区。| 莱州市| 云安县| 江门市| 双桥区| 台北县| 苗栗市| 曲沃县| 龙泉市| 曲沃县| 周宁县| 杭锦后旗| 报价| 招远市| 邵武市|