; // …..
dt.Columns["Id"].AutoIncrement = true;
dt.Columns["Id"].AutoIncrementSeed = 0;
dt.Columns["Id"].AutoIncrementStep = -1;
dt.PrimaryKey = new DataColumn {dt.Columns["Id"]};
this.Tables.Add(dt);
}
AddedNewRow属性返回一个新增进数据表的、空的DataRow,用于给逻辑层填充。FillDataFormDataBase()的两个重载调用数据访问层的相应方法来填充一个新的CMessageData对象并返回。UpdateToDatabase用于讲自身的数据更改更新回数据库。
public DataRow AddedNewRow()…
public static CMessageData FillDataFromDatabase(Int32 startRecord, Int32 maxRecord)…
public static CMessageData FillDataFromDatabase(Int32 id)…
public void UpdateToDatabase()…
二、数据访问层(CDataAccess类)
负责连接数据库,进行SIUD(Select,Insert,Update,Delete)操作。数据连接信息放在AppParameters.xml文件中。
FillMessageData()的两个重载创建新的CMessageData对象,填充数据,然后返回:
public static CMessageData FillMessageData(Int32 startRecord, Int32 maxRecord)
public static CMessageData FillMessageData(Int32 id)
UpdateMessageData()把参数中的CMessageData对象所作出的更改更新回数据库:
public static Int32 UpdateMessageData(CMessageData messageData) {
OleDbConnection conn = new OleDbConnection(CAppParameters.OleDbConnectionString);
OleDbCommand cmdSelect = new OleDbCommand("Select username,last_reply_time,guest_name,guest_email,guest_website_name,guest_website_url,guest_oicq,guest_ip,guest_post_time,guest_text,reply_data From t_gbook_postinfo", conn);
OleDbCommand cmdInsert = new OleDbCommand();
cmdInsert.Connection = conn;
cmdInsert.CommandText = "Insert Into t_gbook_postinfo (last_reply_time,guest_name,guest_email,guest_website_name,guest_website_url,guest_oicq,guest_ip,guest_post_time,guest_text,reply_data) Values (@last_reply_time,@guest_name,@guest_email,@guest_website_name,@guest_website_url,@guest_oicq,@guest_ip,@guest_post_time,@guest_text,@reply_data)";
cmdInsert.Parameters.Add("@last_reply_time", OleDbType.DBDate, 0, "last_reply_time");