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 ...
随机推荐
- 【Django】uWSGI和Gunicorn【转】
因为nginx等优秀的开源项目,有不少本来不是做服务器的同学也可以写很多服务器端的程序了.但是在聊天中会发现,大家虽然写了不少代码,但是对wsgi是什么,gunicorn是什么,反向代理又是什么并不了 ...
- eureka快速剔除失效服务
eureka服务端配置 #eureka server刷新readCacheMap的时间,注意,client读取的是readCacheMap,这个时间决定了多久会把readWriteCacheMap的缓 ...
- 3DMAX导出FBX的烘焙动画选项
勾选了 [烘焙动画]选项时,表示由骨骼动画塌陷为逐帧动画,这样的结果就是:导出的动画确保是正确的,但体积增大,这是骨骼动画与逐帧去画的区别所在. 如果不勾选此选项,则导出的是骨骼动画,可能出现一些问题 ...
- Java并发编程之——Amino框架
Amino框架是一个采用无锁方式实现并行计算的框架,可惜的是,网上关于Amino框架的介绍甚少.根据所掌握的资料,稍微总结一下: 1. 锁机制到无锁机制 锁机制可以确保程序和数据的线程安全,但是锁是一 ...
- python时间戳、日期、时间转换
1.str转时间戳 # 字符类型的时间 tss1 = '2013-10-10 23:40:00' # 转为时间数组 timeArray = time.strptime(tss1, "%Y-% ...
- canvas的性能优化
canvas玩多了后,就会自动的要开始考虑性能问题了.怎么优化canvas的动画呢? [使用缓存] 使用缓存也就是用离屏canvas进行预渲染了,原理很简单,就是先绘制到一个离屏canvas中,然后再 ...
- 深入探究jvm之GC的算法及种类
一.GC基本概念 GC(Garbage Collection)垃圾收集,1960年最早在List中使用.在Java中GC回收的对象是堆空间和永久区,可以有效避免程序员人为造成内存泄漏问题.将堆空间和永 ...
- 如何查看Mysql服务器上的版本
select version(); 1,mysql 的守护进程是mysqld [root@localhost ~]# service mysqld start 启动 MySQL: [确定] 你可以看看 ...
- emulator: Trying to vcpu execute at eip:6d4053
- cdoj32-树上战争(Battle on the tree) 【记忆化搜索】
http://acm.uestc.edu.cn/#/problem/show/32 树上战争(Battle on the tree) Time Limit: 12000/4000MS (Java/Ot ...