ASP.NET三层架构详解 如何实现三层架构(2)

using System; using System.Data; using System.Data.SqlClient; using Model; using IDAL; namespace SQLServerDAL { /// <summary> /// Content 的摘要说明。 /// </summary> public class Content:IContent { private const string PARM_ID = "@ID"; private const string SQL_SELECT_CONTENT = "Select ID, Title, Content, AddDate, CategoryID From newsContent Where ID = @ID"; public ContentInfo GetContentInfo(int id) { //创意文章内容类 ContentInfo ci = null; //创建一个参数 SqlParameter parm = new SqlParameter(PARM_ID, SqlDbType.BigInt, 8); //赋上ID值 parm.Value = id; using(SqlDataReader sdr = SqlHelper.ExecuteReader(SqlHelper.CONN_STR, CommandType.Text, SQL_SELECT_CONTENT, parm)) { if(sdr.Read()) { ci = new ContentInfo(sdr.GetInt32(0),sdr.GetString(1), sdr.GetString(2), sdr.GetDateTime(3), sdr.GetInt32(4), sdr.GetInt32(5), sdr.GetString(6)); } } return ci; } } }

3、Model项目

(1)contentInfo.cs

using System; namespace Model { /// <summary> /// Class1 的摘要说明。 /// </summary> public class ContentInfo { private int _ID; private string _Content; private string _Title; private string _From; private DateTime _AddDate; private int _clsID; private int _tmpID; /// <summary> /// 文章内容构造函数 /// </summary> /// <param>文章流水号ID</param> /// <param>文章内容</param> /// <param>文章标题</param> /// <param>文章来源</param> /// <param>文章的分类属性ID</param> /// <param>文章的模板属性ID</param> public ContentInfo(int id,string title,string content,string from,DateTime addDate,int clsid,int tmpid ) { this._ID = id; this._Content = content; this._Title = title; this._From = from; this._AddDate = addDate; this._clsID = clsid; this._tmpID = tmpid; } //属性 public int ID { get { return _ID; } } public string Content { get { return _Content; } } public string Title { get { return _Title; } } public string From { get { return _From; } } public DateTime AddDate { get { return _AddDate; } } public int ClsID { get { return _clsID; } } public int TmpID { get { return _tmpID; } } } }

4、IDAL项目

(1)Icontent.cs

using System; using Model; namespace IDAL { /// <summary> /// 文章内容操作接口 /// </summary> public interface IContent { /// <summary> /// 取得文章的内容。 /// </summary> /// <param>文章的ID</param> /// <returns></returns> ContentInfo GetContentInfo(int id); } }

5、DALFactory项目

(1)Content.cs

using System; using System.Reflection; using System.Configuration; using IDAL; namespace DALFactory { /// <summary> /// 工产模式实现文章接口。 /// </summary> public class Content { public static IDAL.IContent Create() { // 这里可以查看 DAL 接口类。 string path = System.Configuration.ConfigurationSettings.AppSettings["WebDAL"].ToString(); string className = path+".Content"; // 用配置文件指定的类组合 return (IDAL.IContent)Assembly.Load(path).CreateInstance(className); } } }

6、BLL项目

(1)Content.cs

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwwww.html