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 ...
随机推荐
- awk 数据处理小技巧
进行数据分析或统计时,如果数据量较小,我们可以用awk快速处理,以下是一些小技巧 一.时间戳转换 日期转时间戳: date -d "20150315" "+%s&q ...
- Linux环境下搭建python+selenium+webdriver环境
1.下载并安装python,一般安装linux系统,自带有python,则python不用安装.要下载可以在官网上下载: 或者使用下面命令安装: sudo apt-get install python ...
- java访问共享文件夹
由于工作需要读取局域网中一台机器的共享目录中的文件,需要jcifs-1.1.11.jar的支持,使用SMB协议,以下是实现了远程读取文件的功能: package junit; import jcifs ...
- XP下安装IIS的图文教程(无光盘)
IIS5.1安装文件包下载地址:http://yunpan.cn/QzBZGugw84wEr 安装记录: 1. 将IIS5.1安装文件包解压 2. 开始-->控制面板-->添加/删除程序- ...
- apktool.bat
@echo off if "%PATH_BASE%" == "" set PATH_BASE=%PATH% set PATH=%CD%;%PATH_BASE%; ...
- ThreadLocal原理深入解析
目录 1. 从一次项目经历说起 2. ThreadLocal源码解析 2.1 set方法源码解析 2.2 get方法源码解析 2.3 ThreadLocal源码总结 3. ThreadLocalMap ...
- MySQL多表查询回顾
----------------------siwuxie095 MySQL 多表查询回顾 以客户和联系人为例(一对多) 1.内连接 /*内连接写法一*/ select * from t_custom ...
- CocoaPods私有库!!!!!!!!!!!(装逼特技)
1http://www.jianshu.com/p/4b63dfbd8be7 2 修改工程下的.podspec文件,如 注意1: 验证库是否正确: pod lib lint --verbose -- ...
- crontab学习笔记
一.crond与crontab简介 在Linux系统中,循环运行的例行性计划任务,是由 cron (crond) 这个系统服务来控制的,而crontab命令则被用来提交和管理用户的需要周期性执行的任务 ...
- tp5循环+判断