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);
}
}
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 = ;
return _result;
}
public int Delete(int id)
{
int _result = ;
return _result;
}
public int Update(T model)
{
int _result = ;
return _result;
} public int GetPageCount(string tableName, string where, List<SqlParameter> parameters)
{
int _result = ;
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;
}
}
}
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
}
}
示例代码下载: EasyFastCMS-2014.05.28.zip
EasyFastCMS系列教学课程——1、三层框架的搭建的更多相关文章
- EasyFastCMS系列教学课程——2、底层代码 ModelHelper与SQLHelper简介
从本节课开始,我们开始逐步正式进入实际的编码过程中.本节课的核心内容为SQLHeelper和ModelHelper两个核心类库的介绍. SQLHelper这个类相信大家都很熟悉了,他是微软petsho ...
- .Net Core2.2 + EF Core + DI,三层框架项目搭建教程
笔记: 近两年.Net Core发展的很快,目前最新版为3.0预览版,之前在网上买了一本1.1版书籍都还没来得及看呢,估计现在拿出来看也毫无意义了.已多年.net工作经验,看书不如直接实际上手来得快, ...
- 系列免费课程汇总(Java、单体应用、微服务、物联网、SaaS)
概述 2020年春节尽在眼前,又忙碌了一年的你一定有很多收获:是升职加薪,还是收获爱情?是买房置业,还是新添人口? 我在2019年的最大收获是:我的第二枚千金诞生,使我顺利加入富豪行列! 新年伊始我们 ...
- 微软云平台windows azure入门系列八课程
微软云平台windows azure入门系列八课程: Windows Azure入门教学系列 (一): 创建第一个WebRole程序与部署 Windows Azure入门教学系列 (二): 创建第一个 ...
- 【.NET特供-第三季】ASP.NET MVC系列:MVC与三层图形对照
近期在开发小组在研究:BS项目中是利用'MVC框架'还是继续沿用'三层'的问题. 由于曾经的.NET项目大多数都是利用三层开发的,所以大多数人都可以对三层进行熟练地运用.而项目的開始我们也曾听说过MV ...
- [No000019A]【波浪理论精典教学课程】
波浪理论的产生和发展 拉尔夫·纳尔逊·艾略特(Ralph Nelson Elliott ),是波浪理论的创始人.1871年7月28日出生在美国密苏里州堪萨斯市的玛丽斯维利镇Marysville ...
- RobotFrameWork系列免费课程-开课了~
1. 背景介绍 有一段时间没有发表过文章了,一方面除了自己确实变得懒惰外,另一方面也确实有其它事情,无法抽出闲余时间来坚持写下去. 之前在博客园中,发表了关于<公开课一:Robot FrameW ...
- Java多线程系列--“JUC锁”01之 框架
本章,我们介绍锁的架构:后面的章节将会对它们逐个进行分析介绍.目录如下:01. Java多线程系列--“JUC锁”01之 框架02. Java多线程系列--“JUC锁”02之 互斥锁Reentrant ...
- 学习笔记_Java_day12_设计模式MVC(13).JavaWeb的三层框架(14)
MVC 1. 什么是MVC MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Contr ...
随机推荐
- UGUI BUG
UNITY UGUI问题:父类使用 GroupLayout,子类使用contentsize filter时,会出现运行时布局重叠,但隐藏后再显示就会好了.
- Eclipse将控制台输出信息保存为文件
当你在Eclipse中 running/debugging一个应用程序的时候,有关该应用程序的运行调试信息及日志信息都会输出到控制台(console )显示,但是Eclipse只会显示最后一部分的日志 ...
- linux服务器中Apache隐藏index.php失败
可以通过URL重写隐藏应用的入口文件index.php,下面是相关服务器的配置参考: [Apache] httpd.conf配置文件中加载了mod_rewrite.so模块 AllowOverride ...
- php使用curl 实现GET和POST请求(抓取网页,上传文件),支持跨项目和跨服务器
一:curl 函数和参数详解 函数库:1:curl_init 初始化一个curl会话2:curl_close 关闭一个curl会话3:curl_setopt 为一个curl设置会话参数4:curl_e ...
- 825. Friends Of Appropriate Ages有效的好友请求的数量
[抄题]: Some people will make friend requests. The list of their ages is given and ages[i] is the age ...
- js失去焦点触发
onblur="displayRest($(this))"
- Photo2
Story: 驯鹿:“其实我只是想要一个肩膀而已.” 小男孩:“当你需要我的时候,我会在你身边.” Profession: 页面的主色调是淡黄色,这种柔和的色调表达出了柔和的气氛,整个画面颜色的运用都 ...
- 如何写摘要(abstract)
- 利用crosstool-ng自动化编译交叉编译环境(转)
原文地址:http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/ A ...
- mongodb 更新操作
db.aaaa.update({},{$push:{money:{$each:[8,9,10],$slice:-4}}}) db.aaaa.update({},{$addToSet:{money:{$ ...