采用全新的数据库架构

This commit is contained in:
yubaolee
2015-10-26 21:58:12 +08:00
parent 366d3a5351
commit 13d44f28b6
91 changed files with 21208 additions and 9430 deletions

View File

@@ -0,0 +1,27 @@
// ***********************************************************************
// Assembly : FairUtility
// Author : Yubao Li
// Created : 08-27-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 08-27-2015
// ***********************************************************************
// <copyright file="AutoMapperExt.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using AutoMapper;
namespace Infrastructure
{
public class AutoMapperExt
{
public static TResult ConvertTo<T, TResult>(T source)
{
var mapper = Mapper.CreateMap<T, TResult>();
return Mapper.Map<TResult>(source);
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
namespace Infrastructure
{
public class ControlHelper
{
/// <summary>
/// 根据集合得到下拉框
/// </summary>
/// <typeparam name="T">实体对象</typeparam>
/// <param name="rList">实体集合</param>
/// <param name="id">下拉框的id</param>
/// <param name="valFiled">值 字段名</param>
/// <param name="nameFiled">文本 字段名</param>
/// <param name="selected">需要选中的值</param>
/// <param name="css">样式名称</param>
/// <returns></returns>
public static string GetDropDownByList<T>(List<T> rList, string id, string valFiled, string nameFiled, string selected = "0", string css = "")
{
string str = " <select id='" + id + "' name='" + id + "' class='" + css + "'>";
foreach (var item in rList)
{
string value = item.GetType().GetProperty(valFiled).GetValue(item, null).ToString();
string text = item.GetType().GetProperty(nameFiled).GetValue(item, null).ToString();
str += "<option ";
if (value.Equals(selected)) str += " selected='selected' ";
str += " value='" + value + "'>" + text + "</option>";
}
if (rList.Count == 0) str += "<option value='没有数据'>没有数据</option>";
str += " </select>";
return str;
}
/// <summary>
/// 根据枚举得到下拉框
/// </summary>
/// <typeparam name="type">枚举对象</typeparam>
/// <param name="id">下拉框的id</param>
/// <param name="selected">需要选中的值</param>
/// <param name="css">样式名称</param>
/// <returns></returns>
public static string GetDropDownByEnum(Type type, string id, string selected = "", string css = "")
{
string str = " <select id='" + id + "' name='" + id + "' class='" + css + "'>";
str += "<option value=''>全部</option>";
foreach (int item in System.Enum.GetValues(type))
{
string value = item.ToString();
string text = System.Enum.GetName(type, item);
str += "<option ";
if (value.Equals(selected)) str += " selected='selected' ";
str += " value='" + value + "'>" + text + "</option>";
}
str += " </select>";
return str;
}
}
}

View File

@@ -0,0 +1,162 @@
// ***********************************************************************
// Assembly : FairUtility
// Author : Yubao Li
// Created : 08-18-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 08-18-2015
// ***********************************************************************
// <copyright file="DynamicLinq.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>动态linq</summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Infrastructure
{
public static class DynamicLinq
{
public static ParameterExpression CreateLambdaParam<T>(string name)
{
return Expression.Parameter(typeof(T), name);
}
/// <summary>
/// 创建linq表达示的body部分
/// </summary>
public static Expression GenerateBody<T>(this ParameterExpression param, Filter filterObj)
{
PropertyInfo property = typeof(T).GetProperty(filterObj.Key);
//组装左边
Expression left = Expression.Property(param, property);
//组装右边
Expression right = null;
if (property.PropertyType == typeof(int))
{
right = Expression.Constant(int.Parse(filterObj.Value));
}
else if (property.PropertyType == typeof(DateTime))
{
right = Expression.Constant(DateTime.Parse(filterObj.Value));
}
else if (property.PropertyType == typeof(string))
{
right = Expression.Constant((filterObj.Value));
}
else if (property.PropertyType == typeof(decimal))
{
right = Expression.Constant(decimal.Parse(filterObj.Value));
}
else if (property.PropertyType == typeof(Guid))
{
right = Expression.Constant(Guid.Parse(filterObj.Value));
}
else if (property.PropertyType == typeof(bool))
{
right = Expression.Constant(filterObj.Value.Equals("1"));
}
else
{
throw new Exception("暂不能解析该Key的类型");
}
//c.XXX=="XXX"
Expression filter = Expression.Equal(left, right);
switch (filterObj.Contrast)
{
case "<=":
filter = Expression.LessThanOrEqual(left, right);
break;
case "<":
filter = Expression.LessThan(left, right);
break;
case ">":
filter = Expression.GreaterThan(left, right);
break;
case ">=":
filter = Expression.GreaterThanOrEqual(left, right);
break;
case "like":
filter = Expression.Call(left, typeof(string).GetMethod("Contains", new Type[] { typeof(string) }),
Expression.Constant(filterObj.Value));
break;
}
return filter;
}
public static Expression<Func<T, bool>> GenerateTypeBody<T>(this ParameterExpression param, Filter filterObj)
{
return (Expression<Func<T, bool>>)(param.GenerateBody<T>(filterObj));
}
/// <summary>
/// 创建完整的lambda
/// </summary>
public static LambdaExpression GenerateLambda(this ParameterExpression param, Expression body)
{
//c=>c.XXX=="XXX"
return Expression.Lambda(body, param);
}
public static Expression<Func<T, bool>> GenerateTypeLambda<T>(this ParameterExpression param, Expression body)
{
return (Expression<Func<T, bool>>)(param.GenerateLambda(body));
}
public static Expression AndAlso(this Expression expression, Expression expressionRight)
{
return Expression.AndAlso(expression, expressionRight);
}
public static Expression Or(this Expression expression, Expression expressionRight)
{
return Expression.Or(expression, expressionRight);
}
public static Expression And(this Expression expression, Expression expressionRight)
{
return Expression.And(expression, expressionRight);
}
//系统已经有该函数的实现
//public static IQueryable<T> Where<T>(this IQueryable<T> query, Expression expression)
//{
// Expression expr = Expression.Call(typeof(Queryable), "Where", new[] { typeof(T) },
// Expression.Constant(query), expression);
// //生成动态查询
// IQueryable<T> result = query.Provider.CreateQuery<T>(expr);
// return result;
//}
public static IQueryable<T> GenerateFilter<T>(this IQueryable<T> query, string filterjson)
{
if (!string.IsNullOrEmpty(filterjson))
{
var filters = JsonHelper.Instance.Deserialize<IEnumerable<Filter>>(filterjson);
var param = CreateLambdaParam<T>("c");
Expression result = Expression.Constant(true);
foreach (var filter in filters)
{
result = result.AndAlso(param.GenerateBody<T>(filter));
}
query = query.Where(param.GenerateTypeLambda<T>(result));
}
return query;
}
}
}

File diff suppressed because it is too large Load Diff

9
Infrastructure/Filter.cs Normal file
View File

@@ -0,0 +1,9 @@
namespace Infrastructure
{
public class Filter
{
public string Key { get; set; }
public string Value { get; set; }
public string Contrast { get; set; }
}
}

View File

@@ -0,0 +1,111 @@
// ***********************************************************************
// Assembly : FairUtility
// Author : Yubao Li
// Created : 10-13-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 10-13-2015
// ***********************************************************************
// <copyright file="GenerateId.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>创建唯一ID</summary>
// ***********************************************************************
using System;
namespace Infrastructure
{
public class GenerateId
{
/// <summary>
/// 生成一个长整型可以转成19字节长的字符串
/// </summary>
/// <returns>System.Int64.</returns>
public static long GenerateLong()
{
byte[] buffer = Guid.NewGuid().ToByteArray();
return BitConverter.ToInt64(buffer, 0);
}
/// <summary>
/// 生成16个字节长度的数据与英文组合串
/// </summary>
public static string GenerateStr()
{
long i = 1;
foreach (byte b in Guid.NewGuid().ToByteArray())
{
i *= ((int)b + 1);
}
return string.Format("{0:x}", i - DateTime.Now.Ticks);
}
/// <summary>
/// 唯一订单号生成
/// </summary>
/// <returns></returns>
public static string GenerateOrderNumber()
{
string strDateTimeNumber = DateTime.Now.ToString("yyyyMMddHHmmssffff");
string strRandomResult = NextRandom(1000, 1).ToString("0000");
return strDateTimeNumber + strRandomResult;
}
/// <summary>
/// 参考msdn上的RNGCryptoServiceProvider例子
/// </summary>
/// <param name="numSeeds"></param>
/// <param name="length"></param>
/// <returns></returns>
private static int NextRandom(int numSeeds, int length)
{
// Create a byte array to hold the random value.
byte[] randomNumber = new byte[length];
// Create a new instance of the RNGCryptoServiceProvider.
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
// Fill the array with a random value.
rng.GetBytes(randomNumber);
// Convert the byte to an uint value to make the modulus operation easier.
uint randomResult = 0x0;
for (int i = 0; i < length; i++)
{
randomResult |= ((uint)randomNumber[i] << ((length - 1 - i) * 8));
}
return (int)(randomResult % numSeeds) + 1;
}
/// <summary>
/// 创建11位的英文与数字组合
/// </summary>
/// <returns>System.String.</returns>
public static string ShortStr()
{
return Convert(GenerateLong());
}
static string Seq = "s9LFkgy5RovixI1aOf8UhdY3r4DMplQZJXPqebE0WSjBn7wVzmN2Gc6THCAKut";
/// <summary>
/// 10进制转换为62进制
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
private static string Convert(long id)
{
if (id < 62)
{
return Seq[(int)id].ToString();
}
int y = (int)(id % 62);
long x = (long)(id / 62);
return Convert(x) + Seq[y];
}
}
}

View File

@@ -30,6 +30,16 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper">
<HintPath>..\packages\AutoMapper.4.1.0\lib\net45\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\packages\log4net.2.0.3\lib\net40-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
@@ -40,9 +50,22 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Helper\CookieHelper.cs" />
<Compile Include="Helper\SessionHelper.cs" />
<Compile Include="AutoMapperExt.cs" />
<Compile Include="ControlHelper.cs" />
<Compile Include="CookieHelper.cs" />
<Compile Include="DynamicLinq.cs" />
<Compile Include="DynamicQueryable.cs" />
<Compile Include="Filter.cs" />
<Compile Include="GenerateId.cs" />
<Compile Include="JsonConverter.cs" />
<Compile Include="JsonHelper.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="PredicateBuilder.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SessionHelper.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -0,0 +1,61 @@
// ***********************************************************************
// Assembly : Infrastructure
// Author : Yubao Li
// Created : 09-07-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 09-07-2015
// ***********************************************************************
// <copyright file="GuidConverter.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>解决JSON转换空GUID问题</summary>
// ***********************************************************************
using System;
using Newtonsoft.Json;
namespace Infrastructure
{
public class GuidConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType.IsAssignableFrom(typeof(Guid));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
Guid result = Guid.Empty;
if (reader.Value == null) return result;
Guid.TryParse(reader.Value.ToString(), out result);
return result;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
public class DecimalConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return objectType.IsAssignableFrom(typeof(decimal));
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
decimal result = 0;
if (reader.Value == null) return result;
decimal.TryParse(reader.Value.ToString(), out result);
return result;
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
serializer.Serialize(writer, value);
}
}
}

View File

@@ -0,0 +1,55 @@
// ***********************************************************************
// Assembly : FairUtility
// Author : Yubao Li
// Created : 08-12-2015
//
// Last Modified By : Yubao Li
// Last Modified On : 08-12-2015
// ***********************************************************************
// <copyright file="JsonHelper.cs" company="">
// Copyright (c) . All rights reserved.
// </copyright>
// <summary>json序列化帮助类</summary>
// ***********************************************************************
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Infrastructure
{
public class JsonHelper
{
private static JsonHelper _jsonHelper = new JsonHelper();
public static JsonHelper Instance { get { return _jsonHelper; } }
public string Serialize(object obj)
{
return JsonConvert.SerializeObject(obj, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });
}
public string SerializeByConverter(object obj, params JsonConverter[] converters)
{
return JsonConvert.SerializeObject(obj, converters);
}
public T Deserialize<T>(string input)
{
return JsonConvert.DeserializeObject<T>(input);
}
public T DeserializeByConverter<T>(string input,params JsonConverter[] converter)
{
return JsonConvert.DeserializeObject<T>(input, converter);
}
public T DeserializeBySetting<T>(string input, JsonSerializerSettings settings)
{
return JsonConvert.DeserializeObject<T>(input, settings);
}
private object NullToEmpty(object obj)
{
return null;
}
}
}

View File

@@ -0,0 +1,30 @@
using log4net;
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace Infrastructure
{
public class LogHelper
{
public static readonly ILog _log = LogManager.GetLogger("log4net");
public static void Log(string message)
{
_log.Info(message);
}
public static void Debug(string message)
{
_log.Debug(message);
}
public static void Fatal(string message)
{
_log.Fatal(message);
}
public static void Warn(string message)
{
_log.Warn(message);
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Infrastructure
{
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>() { return f => true; }
public static Expression<Func<T, bool>> False<T>() { return f => false; }
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.OrElse(expr1.Body, invokedExpr), expr1.Parameters);
}
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var invokedExpr = Expression.Invoke(expr2, expr1.Parameters.Cast<Expression>());
return Expression.Lambda<Func<T, bool>>
(Expression.AndAlso(expr1.Body, invokedExpr), expr1.Parameters);
}
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="4.1.0" targetFramework="net45" />
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>