首页 > 代码库 > EasyFastCMS系列教学课程——1、三层框架的搭建
EasyFastCMS系列教学课程——1、三层框架的搭建
在本系列教程中,我们以一个大型CMS系统的完整开发流程为例,和大家一起探讨net开发的经验和教训。在本程序中,我们采用了流行的三层/N层框架+仓储模式的架构模式。项目分层示意图:
各层的主要用途:
- EasyFast.Web ——UI展示层,系统的操作界面。
- EasyFast.BLL ——业务逻辑层,用于处理程序中的业务逻辑。
- EasyFast.Model ——用于在各层之间传递数据。
- EasyFast.Utility ——公共类库
- EasyFast.Repository ——数据操作(数据仓储层)
- EasyFast.DBContext ——ORM工具层
基本框架代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; namespace EasyFast.Repository.Interface { public interface IRepository<T> where T : class { T GetById(int id); T Find(string where, string orderColumn, List<SqlParameter> parameters); int Add(T model); int Delete(int id); int Update(T model); int GetPageCount(string tableName, string where, List<SqlParameter> parameters); DataTable GetPageList(string tableName, string fieldNames, string where, string orderColumn, int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters); DataTable GetDataTable(string tableName, string fieldNames, string where, string orderColumn, List<SqlParameter> parameters); } }
——目录结构:EasyFast.Repository.Interface.IRepository
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using EasyFast.Repository.Interface; using System.Data; using System.Data.SqlClient; namespace EasyFast.Repository { public class Repository<T> : IRepository<T> where T : class { public T GetById(int id) { T model = default(T); return model; } public T Find(string where, string orderColumn, List<SqlParameter> parameters) { T model = default(T); return model; } public int Add(T model) { int _result = 0; return _result; } public int Delete(int id) { int _result = 0; return _result; } public int Update(T model) { int _result = 0; return _result; } public int GetPageCount(string tableName, string where, List<SqlParameter> parameters) { int _result = 0; return _result; } public DataTable GetPageList(string tableName, string fieldNames, string where, string orderColumn, int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters) { DataTable dt = new DataTable(); return dt; } public DataTable GetDataTable(string tableName, string fieldNames, string where, string orderColumn, List<SqlParameter> parameters) { DataTable dt = new DataTable(); return dt; } } }
——目录结构:EasyFast.Repository.Repository
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using EasyFast.Repository; using EasyFast.Repository.Interface; namespace EasyFast.BLL { public class BaseBLL<T> where T : class { IRepository<T> repository = new Repository<T>(); protected readonly Object lockHelper = new object (); #region 获取model public T GetById( int id) { return repository.GetById(id); } public T Find( string where ) { return repository.Find( where , "" , null ); } public T Find( string where , List<SqlParameter> parameters) { return repository.Find( where , "" , parameters); } public T Find( string where , string orderColumn, List<SqlParameter> parameters) { return repository.Find( where , orderColumn, parameters); } #endregion #region 新增一条记录 public int Add(T model) { return repository.Add(model); } #endregion #region 删除一条记录 public int Delete( int id) { return repository.Delete(id); } #endregion #region 更新一条记录 public int Update(T model) { return repository.Update(model); } #endregion #region 获取指定条件的记录集 public virtual DataTable GetDataTable( string tableName, string fieldNames, string where , string orderColumn, List<SqlParameter> parameters) { return repository.GetDataTable(tableName, fieldNames, where , orderColumn, parameters); } public virtual DataTable GetDataTable( string fieldNames, string where , string orderColumn, List<SqlParameter> parameters) { return repository.GetDataTable( "" , fieldNames, where , orderColumn, parameters); } public virtual DataTable GetDataTable( string fieldNames, string where , List<SqlParameter> parameters) { return repository.GetDataTable( "" , fieldNames, where , "" , parameters); } public virtual DataTable GetDataTable( string where , List<SqlParameter> parameters) { return repository.GetDataTable( "" , "*" , where , "" , parameters); } public virtual DataTable GetDataTable( string where ) { return repository.GetDataTable( "" , "*" , where , "" , null ); } public virtual DataTable GetDataTable() { return repository.GetDataTable( "" , "*" , "" , "" , null ); } #endregion #region 获取指定条件的记录数 public virtual int GetPageCount( string tableName, string where , List<SqlParameter> parameters) { return repository.GetPageCount(tableName, where , parameters); } public virtual int GetPageCount( string where , List<SqlParameter> parameters) { return repository.GetPageCount( "" , where , parameters); } public virtual int GetPageCount( string where ) { return repository.GetPageCount( "" , where , null ); } public virtual int GetPageCount() { return repository.GetPageCount( "" , "" , null ); } #endregion #region 分页获取指定条件的记录 public virtual DataTable GetPageList( string tableName, string fieldNames, string where , string orderColumn, int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters) { return repository.GetPageList(tableName, fieldNames, where , orderColumn, startRecordIndex, endRecordIndex, parameters); } public virtual DataTable GetPageList( string tableName, string fieldNames, string where , int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters) { return repository.GetPageList(tableName, fieldNames, where , "" , startRecordIndex, endRecordIndex, parameters); } public virtual DataTable GetPageList( string fieldNames, string where , int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters) { return repository.GetPageList( "" , fieldNames, where , "" , startRecordIndex, endRecordIndex, parameters); } public virtual DataTable GetPageList( string where , int startRecordIndex, int endRecordIndex, List<SqlParameter> parameters) { return repository.GetPageList( "" , "*" , where , "" , startRecordIndex, endRecordIndex, parameters); } public virtual DataTable GetPageList( string where , int startRecordIndex, int endRecordIndex) { return repository.GetPageList( "" , "*" , where , "" , startRecordIndex, endRecordIndex, null ); } public virtual DataTable GetPageList( int startRecordIndex, int endRecordIndex) { return repository.GetPageList( "" , "*" , "" , "" , startRecordIndex, endRecordIndex, null ); } #endregion } } |
——目录结构:EasyFast.BLL.BaseBLL
示例代码下载: EasyFastCMS-2014.05.28.zip
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。