NFine——精选推荐
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
NFine
摘要: 前⾔我在博客园潜⽔两三年了,在这⾥看过很多⼤神的⽂章,也学到了很多东西。
可以说我是汲取着博客园的营养成长的。
想当年,我也是拿10个G的精神粮⾷从⼀个博客园⼤神那⾥换来⼀套开发框架,正式⾛上开发之路,到后来成为主⼒开发,再到项⽬经理再后来顺利拿下美⼯妹,也算是⾛上⼈⽣巅峰。
只索取,不分享就是⾃私posted @ 2016-08-22 16:19 NFine 阅读(53683) 评论(209) 编辑
前⾔
我在博客园潜⽔两三年了,在这⾥看过很多⼤神的⽂章,也学到了很多东西。
可以说我是汲取着博客园的营养成长的。
想当年,我也是拿10个G的精神粮⾷从⼀个博客园⼤神那⾥换来⼀套开发框架,正式⾛上开发之路,到后来成为主⼒开发,再到项⽬经理再后来顺利拿下美⼯妹,也算是⾛上⼈⽣巅峰。
只索取,不分享就是⾃私,⼤家都这么⾃私还怎么做技术交流,说到分享⾸先想到的就是我那120G的精神粮⾷,但是分享这个好像有点法律风险,所以我把这⼏年在.net开发⽣涯中积累的⼀套框架分享给⼤家。
早上发过⼀篇博客,⼀会⼉就让管理员拿掉了,这⾥我解释下完全没有⼴告推⼴的意思,我不会放置任何推⼴信息,没那个必要,房⼦、车⼦、妹⼦都有了,在⼀家还不错的单位上着班,不然也没这个闲⼼来做什么开源框架,⽬的是有,就是出来在新⼿⾯前装个逼。
这样吧⼤家下了代码去看,⾥⾯如果有⼀点点⼴告嫌疑作者我⼩JJ⾃动缩短⼀厘⽶。
废话少说,先来介绍下这个开发框架。
框架名称:NFine.Framwork,⽜逼框架,好框架
框架使⽤场景:OA、ERP、BPM、CRM、WMS、TMS、MIS等业务管理系统及后台系统
框架解决⽅案:
解决⽅案简介:
1、NFine.Code 底层核⼼类(开发时不涉及,可编绎成dll提供)。
2、NFine.Data 数据层(开发时不涉及,可编绎成dll提供)。
3、NFine.Application 应⽤(有点类似业务逻辑层)
4、NFine.Domain 领域层。
5、NFine.Mapping 数据库映射。
6、NFine.Repository 数据访问。
7、NFine.Web 前端视图及控制器。
框架主要运⽤技术:
1、前端技术
JS框架:jquery-2.1.1、Bootstrap.js、JQuery UI
CSS框架:Bootstrap v3.3.4(稳定是后台,UI⽅⾯根据需求⾃⼰升级改造吧)。
客户端验证:jQuery Validation Plugin 1.9.0。
在线编辑器:ckeditor、simditor
上传⽂件:Uploadify v3.2.1
动态页签:Jerichotab(⾃⼰改造)
数据表格:jqGrid、Bootstrap Talbe
对话框:layer-v2.3
下拉选择框:jQuery Select2
树结构控件:jQuery zTree、jQuery wdtree
页⾯布局:yout.js 1.4.4
图表插件:echarts、highcharts
⽇期控件: My97DatePicker
2、后端技术
核⼼框架: MVC5、WEB API
持久层框架:EntityFramework 6.0
定时计划任务:组件
安全⽀持:过滤器、Sql注⼊、请求伪造
服务端验证:实体模型验证、⾃⼰封装Validator
缓存框架:微软⾃带Cache、Redis
⽇志管理:Log4net、登录⽇志、操作⽇志
⼯具类:NPOI、Newtonsoft.Json、验证码、丰富公共类似
框架代码风格:
数据库、仓库代码
1using NFine.Code;
2using System;
3using System.Collections.Generic;
4using mon;
5using System.Linq;
6using System.Linq.Expressions;
7
8namespace NFine.Data
9 {
10///<summary>
11///仓储接⼝
12///</summary>
13///<typeparam name="TEntity">实体类型</typeparam>
14public interface IRepositoryBase<TEntity> where TEntity : class,new()
15 {
16int Insert(TEntity entity);
17int Insert(List<TEntity> entitys);
18int Update(TEntity entity);
19int Delete(TEntity entity);
20int Delete(Expression<Func<TEntity, bool>> predicate);
21 TEntity FindEntity(object keyValue);
22 TEntity FindEntity(Expression<Func<TEntity, bool>> predicate);
23 IQueryable<TEntity> IQueryable();
24 IQueryable<TEntity> IQueryable(Expression<Func<TEntity, bool>> predicate);
25 List<TEntity> FindList(string strSql);
26 List<TEntity> FindList(string strSql, DbParameter[] dbParameter);
27 List<TEntity> FindList(Pagination pagination);
28 List<TEntity> FindList(Expression<Func<TEntity, bool>> predicate, Pagination pagination);
29 }
30 }
using NFine.Code;
using System;
using System.Collections.Generic;
using mon;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text.RegularExpressions;
namespace NFine.Data
{
///<summary>
///仓储实现
///</summary>
///<typeparam name="TEntity"></typeparam>
public class RepositoryBase<TEntity> : IRepositoryBase<TEntity> where TEntity : class,new() {
public NFineDbContext dbcontext = new NFineDbContext();
public int Insert(TEntity entity)
{
dbcontext.Entry<TEntity>(entity).State = EntityState.Added;
return dbcontext.SaveChanges();
}
public int Insert(List<TEntity> entitys)
{
{
foreach (var entity in entitys)
{
dbcontext.Entry<TEntity>(entity).State = EntityState.Added;
}
return dbcontext.SaveChanges();
}
public int Update(TEntity entity)
{
dbcontext.Set<TEntity>().Attach(entity);
PropertyInfo[] props = entity.GetType().GetProperties();
foreach (PropertyInfo prop in props)
{
if (prop.GetValue(entity, null) != null)
{
if (prop.GetValue(entity, null).ToString() == " ")
dbcontext.Entry(entity).Property().CurrentValue = null;
dbcontext.Entry(entity).Property().IsModified = true;
}
}
return dbcontext.SaveChanges();
}
public int Delete(TEntity entity)
{
dbcontext.Set<TEntity>().Attach(entity);
dbcontext.Entry<TEntity>(entity).State = EntityState.Deleted;
return dbcontext.SaveChanges();
}
public int Delete(Expression<Func<TEntity, bool>> predicate)
{
var entitys = dbcontext.Set<TEntity>().Where(predicate).ToList();
entitys.ForEach(m => dbcontext.Entry<TEntity>(m).State = EntityState.Deleted);
return dbcontext.SaveChanges();
}
public TEntity FindEntity(object keyValue)
{
return dbcontext.Set<TEntity>().Find(keyValue);
}
public TEntity FindEntity(Expression<Func<TEntity, bool>> predicate)
{
return dbcontext.Set<TEntity>().FirstOrDefault(predicate);
}
public IQueryable<TEntity> IQueryable()
{
return dbcontext.Set<TEntity>();
}
public IQueryable<TEntity> IQueryable(Expression<Func<TEntity, bool>> predicate)
{
return dbcontext.Set<TEntity>().Where(predicate);
}
public List<TEntity> FindList(string strSql)
{
return dbcontext.Database.SqlQuery<TEntity>(strSql).ToList<TEntity>();
}
public List<TEntity> FindList(string strSql, DbParameter[] dbParameter)
{
return dbcontext.Database.SqlQuery<TEntity>(strSql, dbParameter).ToList<TEntity>();
}
public List<TEntity> FindList(Pagination pagination)
{
bool isAsc = pagination.sord.ToLower() == "asc" ? true : false;
string[] _order = pagination.sidx.Split(',');
MethodCallExpression resultExp = null;
var tempData = dbcontext.Set<TEntity>().AsQueryable();
foreach (string item in _order)
{
string _orderPart = item;
_orderPart = Regex.Replace(_orderPart, @"\s+", "");
string[] _orderArry = _orderPart.Split('');
string _orderField = _orderArry[0];
bool sort = isAsc;
if (_orderArry.Length == 2)
{
isAsc = _orderArry[1].ToUpper() == "ASC" ? true : false;
}
var parameter = Expression.Parameter(typeof(TEntity), "t");
var property = typeof(TEntity).GetProperty(_orderField);
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var orderByExp = mbda(propertyAccess, parameter);
resultExp = Expression.Call(typeof(Queryable), isAsc ? "OrderBy" : "OrderByDescending", new Type[] { typeof(TEntity), property.PropertyType }, tempData.Expression, Expression.Quote(orderByExp)); }
tempData = tempData.Provider.CreateQuery<TEntity>(resultExp);
pagination.records = tempData.Count();
tempData = tempData.Skip<TEntity>(pagination.rows * (pagination.page - 1)).Take<TEntity>(pagination.rows).AsQueryable();
return tempData.ToList();
}
public List<TEntity> FindList(Expression<Func<TEntity, bool>> predicate, Pagination pagination)
{
bool isAsc = pagination.sord.ToLower() == "asc" ? true : false;
string[] _order = pagination.sidx.Split(',');
MethodCallExpression resultExp = null;
var tempData = dbcontext.Set<TEntity>().Where(predicate);
foreach (string item in _order)
{
string _orderPart = item;
_orderPart = Regex.Replace(_orderPart, @"\s+", "");
string[] _orderArry = _orderPart.Split('');
string _orderField = _orderArry[0];
bool sort = isAsc;
if (_orderArry.Length == 2)
{
isAsc = _orderArry[1].ToUpper() == "ASC" ? true : false;
}
var parameter = Expression.Parameter(typeof(TEntity), "t");
var property = typeof(TEntity).GetProperty(_orderField);
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var orderByExp = mbda(propertyAccess, parameter);
resultExp = Expression.Call(typeof(Queryable), isAsc ? "OrderBy" : "OrderByDescending", new Type[] { typeof(TEntity), property.PropertyType }, tempData.Expression, Expression.Quote(orderByExp)); }
tempData = tempData.Provider.CreateQuery<TEntity>(resultExp);
pagination.records = tempData.Count();
tempData = tempData.Skip<TEntity>(pagination.rows * (pagination.page - 1)).Take<TEntity>(pagination.rows).AsQueryable();
return tempData.ToList();
}
}
}
⾃动映射对象实体
框架界⾯展⽰:
⽀持多⽪肤切换
下⼀篇给⼤家讲解下如何实现动态⽪肤切换总结:
1:本⽂并没有详细讲解实现机制。
2:本⽂并没有详细讲解开发⽅式。
但,⾄少你可以:看源码、看API 、看Demo ,还可以加⼊技术交流群进⾏交流分享。
但,⾄少你可以:看源码、看API、看Demo,还可以加⼊技术交流群进⾏交流分享。
当然,后续我会补充相关⽂章,更加细化和完善的机制及开发⽅式。
如果您⽀持开源精神,在精神层⾯可以点赞以⽰⿎励
另外补充:有Bug及漏洞,请私下提交。