利用c#制作简单的留言板(1)[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 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"

本文关键:利用c#制作简单的留言板(1)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top