利用c#制作简单的留言板
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
利用c#制作简单的留言板
留言板分三个模块:列出留言列表、显示详细内容、发表留言notepage.cs
namespace notpage
{
using System;
using System.Data.SQL ;
using System.Data ;
using System.Collections ;
///
/// Summary description for notepage.
///
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;
}
///
///
/// 取得留言的内容
///
///
///
public notepage GetTopic(int a_intID)
{
//
// TODO: Add Constructor Logic here
//
//读取数据库
myconn myConn = new myconn();
SQLCommand myCommand = new SQLCommand() ;
myCommand.ActiveConnection = myConn ;
mandText = "n_GetTopicInfo" ; //调用存储过程
mandType = 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;
}
///
///
/// 目的:将留言的内容入库
///
/// 利用构造函数来传递信息
///
///
///
public bool AddTopic(notepage n_Topic)
{
//
// TODO: Add Constructor Logic here
//
//读取数据库
myconn myConn = new myconn(); SQLCommand myCommand = new SQLCommand() ;