初始化
This commit is contained in:
35
Face.Services/App.config
Normal file
35
Face.Services/App.config
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</configSections>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||
<parameters>
|
||||
<parameter value="mssqllocaldb" />
|
||||
</parameters>
|
||||
</defaultConnectionFactory>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
|
||||
</entityFramework>
|
||||
<system.data>
|
||||
<DbProviderFactories>
|
||||
<remove invariant="MySql.Data.MySqlClient" />
|
||||
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
|
||||
</DbProviderFactories>
|
||||
</system.data>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" /></startup></configuration>
|
||||
271
Face.Services/Cache/BaseCacheHelp.cs
Normal file
271
Face.Services/Cache/BaseCacheHelp.cs
Normal file
@@ -0,0 +1,271 @@
|
||||
using Face.Services.Enums;
|
||||
using Face.Services.Extensions;
|
||||
using Face.Services.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Cache
|
||||
{
|
||||
public class BaseCacheHelp : BaseCacheHelpRedis
|
||||
{
|
||||
}
|
||||
|
||||
#region 缓存管理-MVC
|
||||
/// <summary>
|
||||
/// 缓存管理-MVC内核
|
||||
/// </summary>
|
||||
public abstract class BaseCacheHelpMVC
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取设置-string
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="setAcrion">委托方法</param>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="cacheTimeType">超时设置</param>
|
||||
/// <param name="cacheTime">超时设置</param>
|
||||
/// <returns>返回泛型实例</returns>
|
||||
public static T GetCache<T>(string key, Func<T> setAcrion, CacheTimeType? cacheTimeType = null, int? cacheTime = null)
|
||||
{
|
||||
if (CacheExtensions.CheckCache(key))
|
||||
{
|
||||
return CacheExtensions.GetCache<T>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
T model = setAcrion();
|
||||
if (model != null)
|
||||
{
|
||||
if (cacheTimeType != null && cacheTime != null)
|
||||
{
|
||||
CacheExtensions.SetCache(key, model, (CacheTimeType)cacheTimeType, (int)cacheTime);
|
||||
}
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置参数 string
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="setAcrion">委托方法</param>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="cacheTimeType">超时设置</param>
|
||||
/// <param name="cacheTime">超时设置</param>
|
||||
public static void SetCache<T>(string key, Func<T> setAcrion, CacheTimeType? cacheTimeType = null, int? cacheTime = null)
|
||||
{
|
||||
T model = setAcrion();
|
||||
if (model != null)
|
||||
{
|
||||
if (cacheTimeType != null && cacheTime != null)
|
||||
{
|
||||
CacheExtensions.SetCache(key, model, (CacheTimeType)cacheTimeType, (int)cacheTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 string 失败返回 null
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <returns>返回泛型实例</returns>
|
||||
public static T GetVaue<T>(string key)
|
||||
{
|
||||
if (CacheExtensions.CheckCache(key))
|
||||
{
|
||||
return CacheExtensions.GetCache<T>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除缓存
|
||||
/// </summary>
|
||||
/// <param name="key">缓存key</param>
|
||||
public static void ClearCache(string key)
|
||||
{
|
||||
if (CacheExtensions.CheckCache(key))
|
||||
{
|
||||
CacheExtensions.ClearCache(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 缓存管理
|
||||
/// <summary>
|
||||
/// 设置缓存
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetCacheHelp<T>(string key, Func<T> action)
|
||||
{
|
||||
if (CacheExtensions.CheckCache(key))
|
||||
{
|
||||
return CacheExtensions.GetCache<T>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
var model = action();
|
||||
CacheExtensions.SetCache(key, model);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 缓存管理-Redis 基于Redis-string
|
||||
/// <summary>
|
||||
/// 缓存管理-Redis内核 基于Redis-string
|
||||
/// </summary>
|
||||
public abstract class BaseCacheHelpRedis
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取设置-string
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="setAcrion">委托方法</param>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="expiry">超时设置</param>
|
||||
/// <returns>返回泛型实例</returns>
|
||||
public static T GetCache<T>(string key, Func<T> setAcrion, TimeSpan? expiry = default(TimeSpan?))
|
||||
{
|
||||
if (RedisHelper.CheckKey(key))
|
||||
{
|
||||
return RedisHelper.StringGet<T>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
T model = setAcrion();
|
||||
if (model != null)
|
||||
{
|
||||
RedisHelper.StringSet(key, model, expiry);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置参数 string
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="setAcrion">委托方法</param>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="expiry">超时设置</param>
|
||||
public static void SetCache<T>(string key, Func<T> setAcrion, TimeSpan? expiry = default(TimeSpan?))
|
||||
{
|
||||
T model = setAcrion();
|
||||
if (model != null)
|
||||
{
|
||||
RedisHelper.StringSet(key, model, expiry);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 string 失败返回 null
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <returns>返回泛型实例</returns>
|
||||
public static T GetVaue<T>(string key)
|
||||
{
|
||||
if (RedisHelper.CheckKey(key))
|
||||
{
|
||||
return RedisHelper.StringGet<T>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除缓存
|
||||
/// </summary>
|
||||
/// <param name="key">缓存key</param>
|
||||
public static void ClearCache(string key)
|
||||
{
|
||||
if (RedisHelper.CheckKey(key))
|
||||
{
|
||||
RedisHelper.RemoveKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取哈希缓存,没有则添加
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="sid">键</param>
|
||||
/// <param name="setAcrion">委托方法</param>
|
||||
/// <returns></returns>
|
||||
public static T GetHashCache<T>(string key, string sid, Func<T> setAcrion)
|
||||
{
|
||||
if (RedisHelper.HashExists(key, sid))
|
||||
{
|
||||
return RedisHelper.HashGet<T>(key, sid);
|
||||
}
|
||||
else
|
||||
{
|
||||
T model = setAcrion();
|
||||
if (model != null)
|
||||
{
|
||||
RedisHelper.HashSet(key, sid, model);
|
||||
}
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入哈希缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="sid">键</param>
|
||||
/// <param name="model">实体</param>
|
||||
public static void SetHashCache<T>(string key, string sid, T model)
|
||||
{
|
||||
RedisHelper.HashSet(key, sid, model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入哈希缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <param name="dic">字典</param>
|
||||
public static void SetHashCache<T>(string key, Dictionary<string, T> dic)
|
||||
{
|
||||
RedisHelper.HashSet(key, dic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取哈希缓存字典
|
||||
/// </summary>
|
||||
/// <typeparam name="T">泛型</typeparam>
|
||||
/// <param name="key">缓存key</param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, T> GetHashAllCache<T>(string key)
|
||||
{
|
||||
return RedisHelper.HashGetAll<T>(key);
|
||||
}
|
||||
|
||||
public static bool CheckKey(string key)
|
||||
{
|
||||
return RedisHelper.CheckKey(key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
320
Face.Services/Cache/CacheHelp.cs
Normal file
320
Face.Services/Cache/CacheHelp.cs
Normal file
@@ -0,0 +1,320 @@
|
||||
using Face.Domain.Entities;
|
||||
using Face.Services.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Face.Domain.ViewModels;
|
||||
using Newtonsoft.Json;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Face.Services.Manager;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Face.Services.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存
|
||||
/// </summary>
|
||||
public static class CacheHelp
|
||||
{
|
||||
|
||||
|
||||
|
||||
private static readonly string FaceListKsy = "sysFaceList";//人脸机列表
|
||||
private static readonly string HotelListKsy = "sysHotelslList";//酒店列表
|
||||
private static readonly string RoomCustomerKsy = "sysRoomCustomerList";//入住客人信息列表
|
||||
private static readonly string RoomCheckKey = "sysRoomCheckKeyList";//开放入住信息
|
||||
private static readonly string HotelGroupKey = "sysHotelGroupList";
|
||||
private static readonly string sysUserOperationKey = "UserOperation_";//用户当前选择库
|
||||
private static readonly string RoomGroupKey = "sysRoomGroupList";
|
||||
private static readonly string testinfo = "systest";
|
||||
|
||||
#region Hash缓存前缀
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取写入酒店列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<Hotels> GetHotelslist()
|
||||
{
|
||||
return BaseCacheHelp.GetCache(HotelListKsy, () =>
|
||||
{
|
||||
var list = new List<Hotels>();
|
||||
|
||||
list = SqlSugarBase.authoriydb.Queryable<Hotels>().ToList();
|
||||
|
||||
return list;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除酒店缓存
|
||||
/// </summary>
|
||||
public static void ClearHotelList()
|
||||
{
|
||||
|
||||
BaseCacheHelp.ClearCache(HotelListKsy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户当前选择库
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="dbID"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetUserOperation(string userName, int dbID = 0)
|
||||
{
|
||||
if (dbID == 0)
|
||||
{
|
||||
return BaseCacheHelp.GetCache(sysUserOperationKey + userName, () =>
|
||||
{
|
||||
return dbID;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseCacheHelp.SetCache(sysUserOperationKey + userName, () =>
|
||||
{
|
||||
return dbID;
|
||||
});
|
||||
return dbID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取写入人脸机列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<DeviceManage> GetFaceList()
|
||||
{
|
||||
|
||||
return BaseCacheHelp.GetCache(FaceListKsy, () =>
|
||||
{
|
||||
var list = new List<DeviceManage>();
|
||||
using (SqlSugarClient db = SqlSugarBase.GesmartDb())
|
||||
{
|
||||
list = db.Queryable<DeviceManage>().ToList();
|
||||
}
|
||||
return list;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取总数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int Geiface(string name,int i)
|
||||
{
|
||||
|
||||
return BaseCacheHelp.GetCache(name, () =>
|
||||
{
|
||||
return i;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除人脸机缓存
|
||||
/// </summary>
|
||||
public static void ClearFaceList()
|
||||
{
|
||||
BaseCacheHelp.ClearCache(FaceListKsy);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除入住客人信息
|
||||
/// </summary>
|
||||
public static void ClearRoomCustomer()
|
||||
{
|
||||
BaseCacheHelp.ClearCache(RoomCustomerKsy);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取开房入住信息列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<Hosts> GetRoomCheck()
|
||||
{
|
||||
return BaseCacheHelp.GetCache(RoomCheckKey, () =>
|
||||
{
|
||||
var list = new List<Hosts>();
|
||||
|
||||
list =SqlSugarBase.authoriydb.Queryable<Hosts>().ToList();
|
||||
|
||||
return list;
|
||||
});
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除开房入住信息
|
||||
/// </summary>
|
||||
public static void ClearRoomCheck()
|
||||
{
|
||||
BaseCacheHelp.ClearCache(RoomCheckKey);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取酒店项目信息列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<HotelGroups> GetHotelGroup()
|
||||
{
|
||||
return BaseCacheHelp.GetCache(HotelGroupKey, () =>
|
||||
{
|
||||
var list = new List<HotelGroups>();
|
||||
|
||||
list = SqlSugarBase.authoriydb.Queryable<HotelGroups>().ToList();
|
||||
|
||||
return list;
|
||||
});
|
||||
}
|
||||
//从数据库查询
|
||||
public static List<HotelGroups> GetHotelGroup2()
|
||||
{
|
||||
var list = new List<HotelGroups>();
|
||||
|
||||
list = SqlSugarBase.authoriydb.Queryable<HotelGroups>().ToList();
|
||||
|
||||
return list;
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除酒店项目信息
|
||||
/// </summary>
|
||||
public static void ClearHotelGroup()
|
||||
{
|
||||
BaseCacheHelp.ClearCache(HotelGroupKey);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取房间号信息列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<Hosts> GetRoomGroup()
|
||||
{
|
||||
return BaseCacheHelp.GetCache(RoomGroupKey, () =>
|
||||
{
|
||||
var list = new List<Hosts>();
|
||||
|
||||
list = SqlSugarBase.authoriydb.Queryable<Hosts>().ToList();
|
||||
|
||||
return list;
|
||||
});
|
||||
}
|
||||
public static List<Interfacefield> GetInInfoList()
|
||||
{
|
||||
var res =BaseCacheHelp.GetCache(testinfo, () =>
|
||||
{
|
||||
return new List<Interfacefield>();
|
||||
});
|
||||
//foreach (var info in res)
|
||||
//{
|
||||
// //已经过期的
|
||||
// if( DateTime.Now - info.CheckTime.AddHours(1) > TimeSpan.FromSeconds(0))
|
||||
// {
|
||||
// OutClass oc = new OutClass
|
||||
// {
|
||||
// HotelCode = info.HotelCode,
|
||||
// roomid = info.roomid,
|
||||
// checkOutTime = DateTime.Now
|
||||
|
||||
// };
|
||||
// outinfo(oc);
|
||||
// continue;
|
||||
// }
|
||||
// //未过期的
|
||||
// var time = info.CheckTime.AddMinutes(5) - DateTime.Now;
|
||||
// Task.Factory.StartNew(async () => {
|
||||
// await Task.Delay(time);
|
||||
// OutClass oc = new OutClass
|
||||
// {
|
||||
// HotelCode = info.HotelCode,
|
||||
// roomid = info.roomid,
|
||||
// checkOutTime = DateTime.Now
|
||||
|
||||
// };
|
||||
// outinfo(oc);
|
||||
// });
|
||||
//}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void SetInInfoList(Interfacefield info)
|
||||
{
|
||||
|
||||
var time = info.CheckTime.AddMinutes(3) - DateTime.Now ;
|
||||
Task.Factory.StartNew( ()=> {
|
||||
Task.Delay(time).Wait();
|
||||
OutClass oc = new OutClass
|
||||
{
|
||||
HotelCode = info.HotelCode,
|
||||
roomid = info.roomid,
|
||||
checkOutTime = DateTime.Now
|
||||
|
||||
};
|
||||
outinfo(oc);
|
||||
});
|
||||
BaseCacheHelp.SetCache(testinfo,new Func<List<Interfacefield>>(() =>
|
||||
{
|
||||
var data = GetInInfoList();
|
||||
data.Add(info);
|
||||
data = data.Where(x => DateTime.Now - x.CheckTime <= TimeSpan.FromHours(3)).ToList();
|
||||
return data;
|
||||
}));
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除房间信息
|
||||
/// </summary>
|
||||
public static void ClearRoomGroup()
|
||||
{
|
||||
BaseCacheHelp.ClearCache(RoomGroupKey);
|
||||
}
|
||||
|
||||
public static bool outinfo(OutClass po)//退房测试
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = "http://face.blv-oa.com/Interface/CheckOut";
|
||||
//InterfaceController li = new InterfaceController();
|
||||
//li.CheckOut("abc", JsonConvert.SerializeObject(
|
||||
// po
|
||||
// ));
|
||||
string postData = $"key=abc&data={JsonConvert.SerializeObject(po)}";
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
request.Method = "Post";
|
||||
request.ContentType = "application/x-www-form-urlencoded";
|
||||
StreamWriter sw = new StreamWriter(request.GetRequestStream());
|
||||
sw.Write(postData);
|
||||
sw.Flush();
|
||||
|
||||
WebResponse response = request.GetResponse();
|
||||
Stream s = response.GetResponseStream();
|
||||
StreamReader sr = new StreamReader(s, Encoding.GetEncoding("UTF-8"));
|
||||
string Show = sr.ReadToEnd();
|
||||
ReturnResult info = JsonConvert.DeserializeObject<ReturnResult>(Show);//josn转换实体类
|
||||
sw.Dispose();
|
||||
sw.Close();
|
||||
sr.Dispose();
|
||||
sr.Close();
|
||||
s.Dispose();
|
||||
s.Close();
|
||||
return info.Status == 200;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
public class OutClass
|
||||
{
|
||||
public string HotelCode { get; set; }
|
||||
public string roomid { get; set; }
|
||||
|
||||
public DateTime checkOutTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
76
Face.Services/DBUtility/CommandInfo.cs
Normal file
76
Face.Services/DBUtility/CommandInfo.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.DBUtility
|
||||
{
|
||||
public enum EffentNextType
|
||||
{
|
||||
/// <summary>
|
||||
/// 对其他语句无任何影响
|
||||
/// </summary>
|
||||
None,
|
||||
/// <summary>
|
||||
/// 当前语句必须为"select count(1) from .."格式,如果存在则继续执行,不存在回滚事务
|
||||
/// </summary>
|
||||
WhenHaveContine,
|
||||
/// <summary>
|
||||
/// 当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
|
||||
/// </summary>
|
||||
WhenNoHaveContine,
|
||||
/// <summary>
|
||||
/// 当前语句影响到的行数必须大于0,否则回滚事务
|
||||
/// </summary>
|
||||
ExcuteEffectRows,
|
||||
/// <summary>
|
||||
/// 引发事件-当前语句必须为"select count(1) from .."格式,如果不存在则继续执行,存在回滚事务
|
||||
/// </summary>
|
||||
SolicitationEvent
|
||||
}
|
||||
public class CommandInfo
|
||||
{
|
||||
public object ShareObject = null;
|
||||
public object OriginalData = null;
|
||||
event EventHandler _solicitationEvent;
|
||||
public event EventHandler SolicitationEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_solicitationEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_solicitationEvent -= value;
|
||||
}
|
||||
}
|
||||
public void OnSolicitationEvent()
|
||||
{
|
||||
if (_solicitationEvent != null)
|
||||
{
|
||||
_solicitationEvent(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
public string CommandText;
|
||||
public System.Data.Common.DbParameter[] Parameters;
|
||||
public EffentNextType EffentNextType = EffentNextType.None;
|
||||
public CommandInfo()
|
||||
{
|
||||
|
||||
}
|
||||
public CommandInfo(string sqlText, SqlParameter[] para)
|
||||
{
|
||||
this.CommandText = sqlText;
|
||||
this.Parameters = para;
|
||||
}
|
||||
public CommandInfo(string sqlText, SqlParameter[] para, EffentNextType type)
|
||||
{
|
||||
this.CommandText = sqlText;
|
||||
this.Parameters = para;
|
||||
this.EffentNextType = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
357
Face.Services/DBUtility/Common/DALHelper.cs
Normal file
357
Face.Services/DBUtility/Common/DALHelper.cs
Normal file
@@ -0,0 +1,357 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.DBUtility.Common
|
||||
{
|
||||
public class DALHelper<TEntity> where TEntity : class, new()
|
||||
{
|
||||
private string databasetablename; //数据库表名前缀
|
||||
|
||||
//private DbConfigsInfo confInfi;
|
||||
|
||||
public DALHelper()
|
||||
{
|
||||
databasetablename = "TBL_UTS_Manage";
|
||||
}
|
||||
public DALHelper(string _databaseprefix)
|
||||
{
|
||||
databasetablename = _databaseprefix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在该记录
|
||||
/// </summary>
|
||||
public bool Exists(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select count(1) from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
return DbHelperMySQL.Exists(strSql.ToString(), parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到最大ID
|
||||
/// </summary>
|
||||
public int GetMaxId(TEntity entity, string strField)
|
||||
{
|
||||
return DbHelperMySQL.GetMaxID(strField, databasetablename);
|
||||
}
|
||||
|
||||
//public bool Add(TEntity entity)
|
||||
//{
|
||||
// StringBuilder strSql = new StringBuilder();
|
||||
// strSql.Append("insert into " + databasetablename + "(");
|
||||
|
||||
// PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
// List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
// foreach (PropertyInfo pi in propertys)
|
||||
// {
|
||||
// if (!pi.CanWrite) continue;
|
||||
// strSql.Append(pi.Name + ",");
|
||||
// strSql.Append(" values (");
|
||||
// }
|
||||
// strSql.Append(" ) values (");
|
||||
// foreach (PropertyInfo pi in propertys)
|
||||
// {
|
||||
// if (!pi.CanWrite) continue;
|
||||
// strSql.Append(pi.Name + "@,");
|
||||
// parameters.Add(new SqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
// }
|
||||
// strSql.Append(");select @@IDENTITY");
|
||||
// int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
// if (rows > 0)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// 修改一个实体数据
|
||||
///// </summary>
|
||||
///// <param name="entity"></param>
|
||||
///// <param name="strField"></param>
|
||||
///// <param name="keyValue"></param>
|
||||
///// <returns></returns>
|
||||
//public bool Update(TEntity entity, string strField, object keyValue)
|
||||
//{
|
||||
// StringBuilder strSql = new StringBuilder();
|
||||
// strSql.Append("update " + databasetablename + " set ");
|
||||
|
||||
// PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
// List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
// foreach (PropertyInfo pi in propertys)
|
||||
// {
|
||||
// if (!pi.CanWrite) continue;
|
||||
// strSql.Append(pi.Name + "=@" + pi.Name + ",");
|
||||
// parameters.Add(new SqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
// }
|
||||
// strSql.Append(" where " + strField + "=@strValue");
|
||||
// parameters.Add(new MySqlParameter("@strValue", keyValue));
|
||||
// int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
// if (rows > 0)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一列数据
|
||||
/// </summary>
|
||||
public int UpdateField(TEntity entity, string strField, object strValue, string strWhere)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename);
|
||||
strSql.Append(" set " + strField + "=@strValue");
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
SqlParameter[] parameters = {
|
||||
new SqlParameter("@strValue",strValue)
|
||||
};
|
||||
|
||||
return DbHelperMySQL.ExecuteSql(strSql.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条数据
|
||||
/// </summary>
|
||||
public bool Delete(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("delete from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询语句,返回MySqlDataReader ( 注意:调用该方法后,一定要对MySqlDataReader进行Close )
|
||||
/// </summary>
|
||||
/// <param name="strSQL">查询语句</param>
|
||||
/// <returns>MySqlDataReader</returns>
|
||||
//public static void ExecuteReader(string strSQL, Action<MySqlDataReader> func)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
// {
|
||||
// using (MySqlCommand cmd = new MySqlCommand(strSQL, connection))
|
||||
// {
|
||||
// connection.Open();
|
||||
|
||||
// using (MySqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
|
||||
// {
|
||||
// func(myReader);
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// catch (MySqlException e)
|
||||
// {
|
||||
// throw e;
|
||||
// }
|
||||
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity GetModel(TEntity entity, string strField, string keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
strSql.Append(" LIMIT 0,1;");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModel(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<TEntity> GetList(string strWhere = null)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
//strSql.Append(" LIMIT 0,1;");
|
||||
TEntity entity = new TEntity();
|
||||
DataSet ds = DbHelperMySQL.Query(strSql.ToString());
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModels(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity DataRowToModel(TEntity model, DataTable dt)
|
||||
{
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dt.Rows[0][pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> DataRowToModels(TEntity model, DataTable dt)
|
||||
{
|
||||
List<TEntity> ts = new List<TEntity>();// 定义集合
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dr[pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ts.Add(t);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
1208
Face.Services/DBUtility/Common/DbHelperMySQL.cs
Normal file
1208
Face.Services/DBUtility/Common/DbHelperMySQL.cs
Normal file
File diff suppressed because it is too large
Load Diff
356
Face.Services/DBUtility/Common/MysqlHelpers.cs
Normal file
356
Face.Services/DBUtility/Common/MysqlHelpers.cs
Normal file
@@ -0,0 +1,356 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.DBUtility.Common
|
||||
{
|
||||
public class MysqlHelpers
|
||||
{
|
||||
|
||||
public static readonly string connectionString = "Server=blv-cloud-db.mysql.rds.aliyuncs.com;Database=face;Uid=blv_rcu;Pwd=fnadiaJDIJ7546;charset=utf8;port=3307;";
|
||||
|
||||
public MysqlHelpers() { }
|
||||
#region ExecuteNonQuery
|
||||
//执行SQL语句,返回影响的记录数
|
||||
/// <summary>
|
||||
/// 执行SQL语句,返回影响的记录数
|
||||
/// </summary>
|
||||
/// <param name="SQLString">SQL语句</param>
|
||||
/// <returns>影响的记录数</returns>
|
||||
public static int ExecuteNonQuery(string SQLString)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
int rows = cmd.ExecuteNonQuery();
|
||||
return rows;
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException e)
|
||||
{
|
||||
connection.Close();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行SQL语句,返回影响的记录数
|
||||
/// </summary>
|
||||
/// <param name="SQLString">SQL语句</param>
|
||||
/// <returns>影响的记录数</returns>
|
||||
public static int ExecuteNonQuery(string SQLString, params MySqlParameter[] cmdParms)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
|
||||
int rows = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
return rows;
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//执行多条SQL语句,实现数据库事务。
|
||||
/// <summary>
|
||||
/// 执行多条SQL语句,实现数据库事务。
|
||||
/// </summary>
|
||||
/// <param name="SQLStringList">多条SQL语句</param>
|
||||
public static bool ExecuteNoQueryTran(List<String> SQLStringList)
|
||||
{
|
||||
using (MySqlConnection conn = new MySqlConnection(connectionString))
|
||||
{
|
||||
conn.Open();
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
MySqlTransaction tx = conn.BeginTransaction();
|
||||
cmd.Transaction = tx;
|
||||
try
|
||||
{
|
||||
for (int n = 0; n < SQLStringList.Count; n++)
|
||||
{
|
||||
string strsql = SQLStringList[n];
|
||||
if (strsql.Trim().Length > 1)
|
||||
{
|
||||
cmd.CommandText = strsql;
|
||||
PrepareCommand(cmd, conn, tx, strsql, null);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
cmd.ExecuteNonQuery();
|
||||
tx.Commit();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
tx.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region ExecuteScalar
|
||||
/// <summary>
|
||||
/// 执行一条计算查询结果语句,返回查询结果(object)。
|
||||
/// </summary>
|
||||
/// <param name="SQLString">计算查询结果语句</param>
|
||||
/// <returns>查询结果(object)</returns>
|
||||
public static object ExecuteScalar(string SQLString)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
|
||||
{
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
object obj = cmd.ExecuteScalar();
|
||||
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException e)
|
||||
{
|
||||
connection.Close();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行一条计算查询结果语句,返回查询结果(object)。
|
||||
/// </summary>
|
||||
/// <param name="SQLString">计算查询结果语句</param>
|
||||
/// <returns>查询结果(object)</returns>
|
||||
public static object ExecuteScalar(string SQLString, params MySqlParameter[] cmdParms)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
|
||||
object obj = cmd.ExecuteScalar();
|
||||
cmd.Parameters.Clear();
|
||||
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region ExecuteReader
|
||||
/// <summary>
|
||||
/// 执行查询语句,返回MySqlDataReader ( 注意:调用该方法后,一定要对MySqlDataReader进行Close )
|
||||
/// </summary>
|
||||
/// <param name="strSQL">查询语句</param>
|
||||
/// <returns>MySqlDataReader</returns>
|
||||
public static MySqlDataReader ExecuteReader(string strSQL)
|
||||
{
|
||||
MySqlConnection connection = new MySqlConnection(connectionString);
|
||||
MySqlCommand cmd = new MySqlCommand(strSQL, connection);
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
MySqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
|
||||
return myReader;
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行查询语句,返回MySqlDataReader ( 注意:调用该方法后,一定要对MySqlDataReader进行Close )
|
||||
/// </summary>
|
||||
/// <param name="strSQL">查询语句</param>
|
||||
/// <returns>MySqlDataReader</returns>
|
||||
public static MySqlDataReader ExecuteReader(string SQLString, params MySqlParameter[] cmdParms)
|
||||
{
|
||||
MySqlConnection connection = new MySqlConnection(connectionString);
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
try
|
||||
{
|
||||
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
|
||||
MySqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
|
||||
cmd.Parameters.Clear();
|
||||
return myReader;
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
// finally
|
||||
// {
|
||||
// cmd.Dispose();
|
||||
// connection.Close();
|
||||
// }
|
||||
}
|
||||
#endregion
|
||||
#region ExecuteDataTable
|
||||
/// <summary>
|
||||
/// 执行查询语句,返回DataTable
|
||||
/// </summary>
|
||||
/// <param name="SQLString">查询语句</param>
|
||||
/// <returns>DataTable</returns>
|
||||
public static DataTable ExecuteDataTable(string SQLString)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
MySqlDataAdapter command = new MySqlDataAdapter(SQLString, connection);
|
||||
command.Fill(ds, "ds");
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
return ds.Tables[0];
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行查询语句,返回DataSet
|
||||
/// </summary>
|
||||
/// <param name="SQLString">查询语句</param>
|
||||
/// <returns>DataTable</returns>
|
||||
public static DataTable ExecuteDataTable(string SQLString, params MySqlParameter[] cmdParms)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
MySqlCommand cmd = new MySqlCommand();
|
||||
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
|
||||
using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
da.Fill(ds, "ds");
|
||||
cmd.Parameters.Clear();
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
return ds.Tables[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取起始页码和结束页码
|
||||
public static DataTable ExecuteDataTable(string cmdText, int startResord, int maxRecord)
|
||||
{
|
||||
using (MySqlConnection connection = new MySqlConnection(connectionString))
|
||||
{
|
||||
DataSet ds = new DataSet();
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
MySqlDataAdapter command = new MySqlDataAdapter(cmdText, connection);
|
||||
command.Fill(ds, startResord, maxRecord, "ds");
|
||||
}
|
||||
catch (MySql.Data.MySqlClient.MySqlException ex)
|
||||
{
|
||||
throw new Exception(ex.Message);
|
||||
}
|
||||
return ds.Tables[0];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 获取分页数据 在不用存储过程情况下
|
||||
/// </summary>
|
||||
/// <param name="recordCount">总记录条数</param>
|
||||
/// <param name="selectList">选择的列逗号隔开,支持top num</param>
|
||||
/// <param name="tableName">表名字</param>
|
||||
/// <param name="whereStr">条件字符 必须前加 and</param>
|
||||
/// <param name="orderExpression">排序 例如 ID</param>
|
||||
/// <param name="pageIdex">当前索引页</param>
|
||||
/// <param name="pageSize">每页记录数</param>
|
||||
/// <returns></returns>
|
||||
public static DataTable getPager(out int recordCount, string selectList, string tableName, string whereStr, string orderExpression, int pageIdex, int pageSize)
|
||||
{
|
||||
int rows = 0;
|
||||
DataTable dt = new DataTable();
|
||||
MatchCollection matchs = Regex.Matches(selectList, @"top\s+\d{1,}", RegexOptions.IgnoreCase);//含有top
|
||||
string sqlStr = sqlStr = string.Format("select {0} from {1} where 1=1 {2}", selectList, tableName, whereStr);
|
||||
if (!string.IsNullOrEmpty(orderExpression)) { sqlStr += string.Format(" Order by {0}", orderExpression); }
|
||||
if (matchs.Count > 0) //含有top的时候
|
||||
{
|
||||
DataTable dtTemp = ExecuteDataTable(sqlStr);
|
||||
rows = dtTemp.Rows.Count;
|
||||
}
|
||||
else //不含有top的时候
|
||||
{
|
||||
string sqlCount = string.Format("select count(*) from {0} where 1=1 {1} ", tableName, whereStr);
|
||||
//获取行数
|
||||
object obj = ExecuteScalar(sqlCount);
|
||||
if (obj != null)
|
||||
{
|
||||
rows = Convert.ToInt32(obj);
|
||||
}
|
||||
}
|
||||
dt = ExecuteDataTable(sqlStr, (pageIdex - 1) * pageSize, pageSize);
|
||||
recordCount = rows;
|
||||
return dt;
|
||||
}
|
||||
#region 创建command
|
||||
private static void PrepareCommand(MySqlCommand cmd, MySqlConnection conn, MySqlTransaction trans, string cmdText, MySqlParameter[] cmdParms)
|
||||
{
|
||||
if (conn.State != ConnectionState.Open)
|
||||
conn.Open();
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = cmdText;
|
||||
if (trans != null)
|
||||
cmd.Transaction = trans;
|
||||
cmd.CommandType = CommandType.Text;//cmdType;
|
||||
if (cmdParms != null)
|
||||
{
|
||||
foreach (MySqlParameter parameter in cmdParms)
|
||||
{
|
||||
if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
|
||||
(parameter.Value == null))
|
||||
{
|
||||
parameter.Value = DBNull.Value;
|
||||
}
|
||||
cmd.Parameters.Add(parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
4234
Face.Services/DBUtility/Common/SqlHelper.cs
Normal file
4234
Face.Services/DBUtility/Common/SqlHelper.cs
Normal file
File diff suppressed because it is too large
Load Diff
654
Face.Services/DBUtility/Common/SqlOperationsData.cs
Normal file
654
Face.Services/DBUtility/Common/SqlOperationsData.cs
Normal file
@@ -0,0 +1,654 @@
|
||||
using Face.Domain.Application;
|
||||
using Face.Domain.Entities;
|
||||
using Face.Services.Cache;
|
||||
using Face.Services.Enums;
|
||||
using Face.Services.Manager;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebSocketToolsConsole;
|
||||
|
||||
namespace Face.Services.DBUtility.Common
|
||||
{
|
||||
public static class SqlOperationsData
|
||||
{
|
||||
static SqlDependency dependency;
|
||||
|
||||
/// <summary>
|
||||
/// 更新人脸机状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static DataSet facestate()
|
||||
{
|
||||
string sql = "select Facestate,snnumber from DeviceManage";
|
||||
SqlDataAdapter sqldata = new SqlDataAdapter(sql, MysqlHelpers.connectionString);
|
||||
DataSet data = new DataSet();
|
||||
sqldata.Fill(data);
|
||||
return data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 数据库更新发生变化
|
||||
/// </summary>
|
||||
public static void Monitor()
|
||||
{
|
||||
//Start和Stop方法
|
||||
SqlDependency.Start(MysqlHelpers.connectionString);
|
||||
Update(MysqlHelpers.connectionString);
|
||||
}
|
||||
private static void Update(string conn)
|
||||
{
|
||||
using (
|
||||
SqlConnection connection =
|
||||
new SqlConnection(conn))
|
||||
{
|
||||
//此处 要注意 不能使用* 表名要加[dbo] 否则会出现一直调用执行 OnChange
|
||||
string sql = "select Status from [dbo].[DeviceManage]";
|
||||
|
||||
using (SqlCommand command = new SqlCommand(sql, connection))
|
||||
{
|
||||
connection.Open();
|
||||
command.CommandType = CommandType.Text;
|
||||
dependency = new SqlDependency(command);
|
||||
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
|
||||
//必须要执行一下command
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
//update insert delete都会进入
|
||||
private static void dependency_OnChange(object sender, SqlNotificationEventArgs e)
|
||||
{
|
||||
CacheHelp.ClearFaceList();
|
||||
//using (var db=new )
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加顾客信息
|
||||
/// </summary>
|
||||
public static int addClient(Lodger ci)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("select LodgerId from Lodger where IDNumber='" + ci.IDNumber + "'");
|
||||
object id = MysqlHelpers.ExecuteScalar(sql);
|
||||
if (id != null && Convert.ToInt64(id) > 0)
|
||||
{
|
||||
sql = string.Format("update Lodger set phonenumber='{0}' where LodgerId='{1}'", ci.phonenumber, id);
|
||||
int ss = MysqlHelpers.ExecuteNonQuery(sql);
|
||||
return ss;
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = "insert into Lodger(LodgerNmae, IDNumber, Sex, CheckInDate, Sourcedian,phonenumber,remark)VALUES(@LodgerNmae,@IDNumber,@Sex,@CheckInDate,@Sourcedian,@phonenumber,@remark)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[7] {
|
||||
new MySqlParameter("@LodgerNmae",ci.LodgerNmae),
|
||||
new MySqlParameter("@IDNumber", ci.IDNumber),
|
||||
new MySqlParameter("@Sex",ci.Sex),
|
||||
new MySqlParameter("@CheckInDate",DateTime.Now),
|
||||
new MySqlParameter("@Sourcedian",ci.Sourcedian),
|
||||
new MySqlParameter("@remark", ci.remark),
|
||||
new MySqlParameter("@phonenumber", ci.phonenumber)};
|
||||
return MysqlHelpers.ExecuteNonQuery(sql, sqlParams);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加入住信息
|
||||
/// </summary>
|
||||
public static int addcheckininfo(CheckInInfo co)
|
||||
{
|
||||
string sql = "insert into CheckInInfo(Name, IdNumber, CreationTime, InfoSource, HotelCode, Roomid,CheckTime,checkOutTime,picture,identitys)VALUES(@Name,@IdNumber,@CreationTime,@InfoSource,@HotelCode,@Roomid,@CheckTime,@checkOutTime,@picture,@identitys)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[10] {
|
||||
new MySqlParameter("@Name",co.Name),
|
||||
new MySqlParameter("@IdNumber", co.IdNumber),
|
||||
new MySqlParameter("@CreationTime",co.CreationTime),
|
||||
new MySqlParameter("@InfoSource",co.InfoSource),
|
||||
new MySqlParameter("@HotelCode",co.HotelCode),
|
||||
new MySqlParameter("@Roomid", co.Roomid),
|
||||
new MySqlParameter("@CheckTime", co.CheckTime),
|
||||
new MySqlParameter("@checkOutTime", co.checkOutTime),
|
||||
new MySqlParameter("@picture", co.picture),
|
||||
new MySqlParameter("@identitys", co.identitys) };
|
||||
return MysqlHelpers.ExecuteNonQuery(sql,sqlParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接口,查看是否有此人脸机
|
||||
/// </summary>
|
||||
/// <param name="hotelname"></param>
|
||||
/// <param name="roomname"></param>
|
||||
/// <returns></returns>
|
||||
public static string selectFace(string hotelname, string roomname)
|
||||
{
|
||||
string consequence = "";
|
||||
try
|
||||
{
|
||||
string sql = "select SerialNo from DeviceManage where HotelCode='" + hotelname + "' and RoomId='" + roomname + "'";
|
||||
object id = MysqlHelpers.ExecuteScalar(sql);
|
||||
if (id != null)
|
||||
{
|
||||
consequence = id.ToString();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
return consequence;
|
||||
}
|
||||
/// <summary>
|
||||
/// 为房间绑定人脸机
|
||||
/// </summary>
|
||||
public static int reviseRommFace(string hotel, int romm, string faceNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("UPDATE DeviceManage SET HotelCode='{0}',RoomId='{1}',bindingStatus=1,bindingDate=CURRENT_DATE() where SerialNo='{2}' ", hotel, romm, faceNo);
|
||||
return MysqlHelpers.ExecuteNonQuery(sql);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为酒店绑定人脸机
|
||||
/// </summary>
|
||||
/// <param name="hotel"></param>
|
||||
/// <param name="romm"></param>
|
||||
/// <param name="faceNo"></param>
|
||||
/// <returns></returns>
|
||||
public static int reviseHotelFace(string hotel, string faceNo)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("UPDATE DeviceManage SET HotelCode='{0}',bindingStatus=1,bindingDate=CURRENT_DATE() where SerialNo='{1}' ", hotel, faceNo);
|
||||
return MysqlHelpers.ExecuteNonQuery(sql);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 记录绑定/解绑操作
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int bindingState(FaceBinding fb)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = "insert into FaceBinding(SerialNo, Operator, OperatorType, bindingDate, HotelCode,RoomId)VALUES(@SerialNo,@Operator,@OperatorType,@bindingDate,@HotelCode,@RoomId)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[6] {
|
||||
new MySqlParameter("@SerialNo", fb.SerialNo),
|
||||
new MySqlParameter("@Operator",fb.Operator),
|
||||
new MySqlParameter("@OperatorType",fb.OperatorType),
|
||||
new MySqlParameter("@bindingDate",fb.bindingDate),
|
||||
new MySqlParameter("@HotelCode", fb.HotelCode),
|
||||
new MySqlParameter("@RoomId", fb.RoomId)};
|
||||
return MysqlHelpers.ExecuteNonQuery(sql,sqlParams);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="accountentity"></param>
|
||||
//public static Accountentity LoginAccount(string uid)
|
||||
//{
|
||||
// List<Accountentity> listay = new List<Accountentity>();
|
||||
// string sql = "select * from AuthorityDB.dbo.UserInfo where Uid='" + uid + "'";
|
||||
// SqlDataReader dr = DbHelperMySQL.ExecuteReader(sql);
|
||||
// Accountentity ay = new Accountentity();
|
||||
// while (dr.Read())
|
||||
// {
|
||||
// ay.Uid = dr["Uid"].ToString();
|
||||
// ay.CreateTime = dr["CreateTime"].ToDateTime();
|
||||
// }
|
||||
// return ay;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 查询酒店权限
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public static List<string> permission(string name)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
string sql = "select distinct HotelId from AuthorityDB.dbo.UserAuthoes where UserId in(select Id from AuthorityDB.dbo.UserInfo where Uid='" + name + "')";
|
||||
DbHelperMySQL.ExecuteReader(sql, dr => {
|
||||
while (dr.Read())
|
||||
{
|
||||
list.Add(dr["HotelId"].ToString());
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
/// <summary>
|
||||
/// 登录验证
|
||||
/// </summary>
|
||||
/// <param name="accountentity"></param>
|
||||
//public static Accountentity LoginAccount(string uid, string pwd)
|
||||
//{
|
||||
// List<Accountentity> listay = new List<Accountentity>();
|
||||
// string sql = "select * from AuthorityDB.dbo.UserInfo where Uid='" + uid + "'and Pwd='" + pwd + "'";
|
||||
// SqlDataReader dr = DbHelperMySQL.ExecuteReader(sql);
|
||||
// Accountentity ay = new Accountentity();
|
||||
// while (dr.Read())
|
||||
// {
|
||||
// ay.Uid = dr["Uid"].ToString();
|
||||
// ay.CreateTime = dr["CreateTime"].ToDateTime();
|
||||
// }
|
||||
// return ay;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 解绑房间
|
||||
/// </summary>
|
||||
public static int unbundleoperateRoom(string sn)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = "UPDATE DeviceManage SET RoomId=null,bindingStatus=0 WHERE SerialNo='" + sn + "'";
|
||||
return MysqlHelpers.ExecuteNonQuery(sql);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解绑酒店
|
||||
/// </summary>
|
||||
public static int unbundleoperatehotel(string sn)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = "UPDATE DeviceManage SET RoomId=null,bindingStatus=0,HotelCode=null WHERE SerialNo='" + sn + "'";
|
||||
return MysqlHelpers.ExecuteNonQuery(sql);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
///// <summary>
|
||||
///// 通过酒店id查询房间列表
|
||||
///// </summary>
|
||||
//public static Hosts Roominfo(string hotelname)
|
||||
//{
|
||||
// string sql = "select * from Hosts where HotelID=" + hotelname + "";
|
||||
// SqlDataReader dr = DbHelperMySQL.ExecuteReader(sql);
|
||||
// Hosts ay = new Hosts();
|
||||
// while (dr.Read())
|
||||
// {
|
||||
// ay.HotelID = int.Parse(dr["HotelID"].ToString());
|
||||
// ay.RoomNumber = dr["RoomNumber"].ToString();
|
||||
// ay.Status = int.Parse(dr["Status"].ToString());
|
||||
// }
|
||||
// return ay;
|
||||
//}
|
||||
/// <summary>
|
||||
/// 添加入住信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int additionCheck(CheckInInfo cf)
|
||||
{
|
||||
try
|
||||
{
|
||||
string date = cf.CreationTime.Value.ToString("yyyy-MM-dd");
|
||||
string sql = string.Format("select * from CheckInInfo where HotelCode=" + cf.HotelCode + " and IdNumber='" + cf.IdNumber + "'and Roomid="+cf.Roomid+"");
|
||||
object id = MysqlHelpers.ExecuteScalar(sql);
|
||||
if (id != null && Convert.ToInt64(id) > 0)
|
||||
{
|
||||
string dateout = cf.checkOutTime.Value.ToString("yyyy-MM-dd");
|
||||
sql = string.Format("UPDATE CheckInInfo SET HotelCode = '{0}', RoomId = '{1}',checkOutTime='{2}',picture='{3}' where id={4}", cf.HotelCode, cf.Roomid,dateout,cf.picture, id);
|
||||
return MysqlHelpers.ExecuteNonQuery(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
string sql2 = "insert into CheckInInfo (Name,CreationTime,IdNumber,InfoSource,HotelCode,Roomid,CheckTime,checkOutTime,picture) values(@Name,@CreationTime,@IdNumber,@InfoSource,@HotelCode,@Roomid,@CheckTime,@checkOutTime,@picture)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[9] {
|
||||
new MySqlParameter("@Name",cf.Name),
|
||||
new MySqlParameter("@CreationTime",cf.CreationTime),
|
||||
new MySqlParameter("@IdNumber",cf.IdNumber),
|
||||
new MySqlParameter("@InfoSource",cf.InfoSource),
|
||||
new MySqlParameter("@HotelCode",cf.HotelCode),
|
||||
new MySqlParameter("@Roomid",cf.Roomid),
|
||||
new MySqlParameter("@CheckTime",cf.CheckTime),
|
||||
new MySqlParameter("@checkOutTime",cf.checkOutTime.Value.ToString("yyyy/MM/dd")),
|
||||
new MySqlParameter("@picture",cf.picture) };
|
||||
return MysqlHelpers.ExecuteNonQuery(sql2, sqlParams);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 绑定/解绑操作记录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int bindingoperation(FaceBinding fb)
|
||||
{
|
||||
string sql = "insert into FaceBinding (SerialNo,Operator,OperatorType,bindingDate,HotelCode,RoomId) values(@SerialNo,@Operator,@OperatorType,@bindingDate,@HotelCode,@RoomId)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[6] {
|
||||
new MySqlParameter("@SerialNo",fb.SerialNo),
|
||||
new MySqlParameter("@Operator",fb.Operator),
|
||||
new MySqlParameter("@OperatorType",fb.OperatorType),
|
||||
new MySqlParameter("@bindingDate",fb.bindingDate),
|
||||
new MySqlParameter("@HotelCode",fb.HotelCode),
|
||||
new MySqlParameter("@RoomId",fb.RoomId) };
|
||||
return MysqlHelpers.ExecuteNonQuery(sql, sqlParams);
|
||||
}
|
||||
/// <summary>
|
||||
///// 获取人脸机地理位置
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
public static List<string> facelocation()
|
||||
{
|
||||
string sql = "SELECT faceAddress from DeviceManage WHERE HotelCode='' GROUP BY faceAddress ";
|
||||
List<string> location = new List<string>();
|
||||
|
||||
DbHelperMySQL.ExecuteReader(sql, dr => {
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
location.Add(dr["faceAddress"].ToString());
|
||||
}
|
||||
});
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存pms数据
|
||||
/// </summary>
|
||||
public static int preserve(string info, string hotelid, string room,string facesn,int issueresult,int pmstype)
|
||||
{
|
||||
string sql = "insert into pmsInterface values(CURRENT_DATE(),@pmsContent,@hotelid,@room,@faceSN,@issueresult,@pmstype)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[6] {
|
||||
new MySqlParameter("@pmsContent",info),
|
||||
new MySqlParameter("@hotelid",hotelid),
|
||||
new MySqlParameter("@room",room),
|
||||
new MySqlParameter("@faceSN",facesn),
|
||||
new MySqlParameter("@issueresult",issueresult),
|
||||
new MySqlParameter("@pmstype",pmstype)};
|
||||
return MysqlHelpers.ExecuteNonQuery(sql, sqlParams);
|
||||
}
|
||||
/// <summary>
|
||||
/// 操作日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int writeLog(ULog ul)
|
||||
{
|
||||
string sql = "insert into ulog values(@Uname,@Creationtime,@type,@faceSN,@hotelCode,@roomid)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[6] {
|
||||
new MySqlParameter("@Uname",ul.Uname),
|
||||
new MySqlParameter("@Creationtime",DateTime.Now),
|
||||
new MySqlParameter("@type",ul.operatetype),
|
||||
new MySqlParameter("@faceSN",ul.faceSN),
|
||||
new MySqlParameter("@hotelCode",ul.hotelcode),
|
||||
new MySqlParameter("@roomid",ul.roomid)};
|
||||
return MysqlHelpers.ExecuteNonQuery(sql, sqlParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日常日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int writeDailyLog(Dailyoperation dp)
|
||||
{
|
||||
string sql = "insert into Dailyoperation values(@Uname,CURRENT_DATE(),@type,@operatedata,@hotelCode)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[4] {
|
||||
new MySqlParameter("@Uname",dp.Uname),
|
||||
new MySqlParameter("@type",dp.operatetype),
|
||||
new MySqlParameter("@operatedata",dp.operatedata),
|
||||
new MySqlParameter("@hotelCode",dp.hotelCode)};
|
||||
return MysqlHelpers.ExecuteNonQuery(sql, sqlParams);
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据酒店code获取酒店id
|
||||
/// </summary>
|
||||
/// <param name="hotelid"></param>
|
||||
/// <returns></returns>
|
||||
public static string geihotelid(string hotelid)
|
||||
{
|
||||
string sql = string.Format("select Id from [AuthorityDB].[dbo].Hotels where Code={0}", hotelid);
|
||||
object roomid = MysqlHelpers.ExecuteScalar(sql);
|
||||
if (roomid == null)
|
||||
{
|
||||
roomid = "";
|
||||
}
|
||||
return roomid.ToString();
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据房间号获取房间id
|
||||
/// </summary>
|
||||
/// <param name="hotelid"></param>
|
||||
/// <param name="roomname"></param>
|
||||
/// <returns></returns>
|
||||
public static string geiroomid(string hotelid, string roomname)
|
||||
{
|
||||
string sql = string.Format("select Id ,RoomStatusID,HotelID,[RoomNumber],[Status] = convert(int,[Status]),[Desc] =[remark],[CreateTime]=[registerdate] from BLW.CRICS.[dbo].tb_Hosts where HotelID={0} and RoomNumber='{1}'", hotelid, roomname);
|
||||
object roomid = MysqlHelpers.ExecuteScalar(sql);
|
||||
if (roomid == null)
|
||||
{
|
||||
roomid = "";
|
||||
}
|
||||
return roomid.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 通过酒店id和房间id获取入住人的信息
|
||||
/// </summary>
|
||||
public static List<string> getCheck(string code,string room)
|
||||
{
|
||||
List<string> idnumber = new List<string>();
|
||||
string sql = string.Format("select IdNumber from CheckInInfo where checkOutTime = '2000-01-01' and HotelCode={0} and Roomid={1}", code,room);
|
||||
DbHelperMySQL.ExecuteReader(sql,dr=> {
|
||||
|
||||
while (dr.Read())
|
||||
{
|
||||
idnumber.Add(dr["IdNumber"].ToString());
|
||||
}
|
||||
});
|
||||
|
||||
return idnumber;
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加退房时间
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="hotel"></param>
|
||||
/// <param name="room"></param>
|
||||
/// <returns></returns>
|
||||
public static int reviseDate(string date,string hotel,string room)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("UPDATE CheckInInfo SET checkOutTime ='{0}' WHERE HotelCode={1} and Roomid={2} and checkOutTime='2000-01-01'", date, hotel, room);
|
||||
int sd= MysqlHelpers.ExecuteNonQuery(sql);
|
||||
return sd;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 冻结测试人员
|
||||
/// </summary>
|
||||
/// <param name="tiaojian"></param>
|
||||
/// <returns></returns>
|
||||
public static int amendtestUser(string tiaojian)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("UPDATE TestUser SET state =0 WHERE id={0}",tiaojian);
|
||||
int sd = MysqlHelpers.ExecuteNonQuery(sql);
|
||||
return sd;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 解冻测试人员
|
||||
/// </summary>
|
||||
/// <param name="tiaojian"></param>
|
||||
/// <returns></returns>
|
||||
public static int amendtestUser1(string tiaojian)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("UPDATE TestUser SET state =1 WHERE id={0}", tiaojian);
|
||||
int sd = MysqlHelpers.ExecuteNonQuery(sql);
|
||||
return sd;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 人脸机维修状态
|
||||
/// </summary>
|
||||
public static int maintainStaet(transferFace tf)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("select id from transferFace where faceSN='"+tf.faceSN+"'");
|
||||
object id = MysqlHelpers.ExecuteScalar(sql);
|
||||
if (id != null && Convert.ToInt64(id) > 0)
|
||||
{
|
||||
sql = string.Format("UPDATE transferFace SET infoid = '{0}', faultState = '{1}',creationTime='{2}' where faceSN={3}", tf.infoid, tf.faultState, tf.creationTime, id);
|
||||
return MysqlHelpers.ExecuteNonQuery(sql);
|
||||
}
|
||||
else
|
||||
{
|
||||
string sql2 = "insert into transferFace (faceSN,infoid,faultState,creationTime) values(@faceSN,@infoid,@faultState,@creationTime)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[4] {
|
||||
new MySqlParameter("@faceSN",tf.faceSN),
|
||||
new MySqlParameter("@infoid",tf.infoid),
|
||||
new MySqlParameter("@faultState",tf.faultState),
|
||||
new MySqlParameter("@creationTime",tf.creationTime) };
|
||||
return MysqlHelpers.ExecuteNonQuery(sql2, sqlParams);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加pms日志
|
||||
/// </summary>
|
||||
/// <param name="log"></param>
|
||||
/// <returns></returns>
|
||||
public static int revise(pmsLog log)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql2 = "insert into pmsLog (pmsid,step,app,Creationtime,message,Data) values(@pmsid,@step,@app,@Creationtime,@message,@Data)";
|
||||
MySqlParameter[] sqlParams = new MySqlParameter[6] {
|
||||
new MySqlParameter("@pmsid",log.pmsid),
|
||||
new MySqlParameter("@step",log.step),
|
||||
new MySqlParameter("@app",log.app),
|
||||
new MySqlParameter("@Creationtime",log.Creationtime),
|
||||
new MySqlParameter("@message",log.message),
|
||||
new MySqlParameter("@Data",log.Data) };
|
||||
return MysqlHelpers.ExecuteNonQuery(sql2, sqlParams);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加pms酒店房间信息
|
||||
/// </summary>
|
||||
/// <param name="pms"></param>
|
||||
/// <returns></returns>
|
||||
public static int revisepms(pmsInterface pms)
|
||||
{
|
||||
try
|
||||
{
|
||||
string sql = string.Format("UPDATE pmsInterface SET faceSN ='{0}',hotelid={1},room={2},messageid='{3}' WHERE pmsId={4}",pms.faceSN,pms.hotelid,pms.room,pms.messageid,pms.pmsId);
|
||||
int sd = MysqlHelpers.ExecuteNonQuery(sql);
|
||||
return sd;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return 0;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
///// <summary>
|
||||
///// 获取所有的房间
|
||||
///// </summary>
|
||||
//public static List<TBL_ROOM_BASIC_INFO> Roomdata()
|
||||
//{
|
||||
// List<TBL_ROOM_BASIC_INFO> Room = new List<TBL_ROOM_BASIC_INFO>();
|
||||
|
||||
// string sql = "select * from tbl_room_basic_info";
|
||||
// MySqlDataReader dr = MysqlHelper.ExecuteReader(sql);
|
||||
// while (dr.Read())
|
||||
// {
|
||||
// TBL_ROOM_BASIC_INFO log = new TBL_ROOM_BASIC_INFO();
|
||||
// log.ROOM_NUMBER = dr["ROOM_NUMBER"].ToString();
|
||||
// log.RoomStatusID = int.Parse(dr["RoomStatusID"].ToString());
|
||||
// log.HOTEL_OLD_ID = int.Parse(dr["HOTEL_OLD_ID"].ToString());
|
||||
// log.ROOM_OLD_ID = int.Parse(dr["ROOM_OLD_ID"].ToString());
|
||||
// Room.Add(log);
|
||||
// }
|
||||
// return Room;
|
||||
//}
|
||||
}
|
||||
}
|
||||
478
Face.Services/DBUtility/Custom/DALHelperCustom.cs
Normal file
478
Face.Services/DBUtility/Custom/DALHelperCustom.cs
Normal file
@@ -0,0 +1,478 @@
|
||||
using Face.Domain.Entities;
|
||||
using Fasce.Services.DBUtility.Custom;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebSocketToolsConsole;
|
||||
|
||||
namespace Face.Services.DBUtility.Custom
|
||||
{
|
||||
public class DALHelperCustom<TEntity> where TEntity : class, new()
|
||||
{
|
||||
private string databasetablename; //数据库表名前缀
|
||||
|
||||
//private DbConfigsInfo confInfi;
|
||||
|
||||
public DALHelperCustom()
|
||||
{
|
||||
databasetablename = "TBL_UTS_Manage";
|
||||
}
|
||||
public DALHelperCustom(string _databaseprefix)
|
||||
{
|
||||
databasetablename = _databaseprefix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否存在该记录
|
||||
/// </summary>
|
||||
public bool Exists(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select count(1) from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
MySqlParameter[] parameters = {
|
||||
new MySqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
return DbHelperMySqlCustom.Exists(strSql.ToString(), parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到最大ID
|
||||
/// </summary>
|
||||
public int GetMaxId(TEntity entity, string strField)
|
||||
{
|
||||
return DbHelperMySqlCustom.GetMaxID(strField, databasetablename);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一条数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public bool Add(TEntity entity)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("insert into " + databasetablename + "(");
|
||||
|
||||
PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
|
||||
List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + ",");
|
||||
}
|
||||
strSql.Remove(strSql.Length - 1, 1);//移除最后一个逗号
|
||||
strSql.Append(" ) values (");
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append("@" + pi.Name + ",");
|
||||
parameters.Add(new SqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
}
|
||||
strSql.Remove(strSql.Length - 1, 1);//移除最后一个逗号
|
||||
strSql.Append(");select @@IDENTITY");
|
||||
int rows = DbHelperMySqlCustom.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一个实体数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="strField"></param>
|
||||
/// <param name="keyValue"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename + " set ");
|
||||
PropertyInfo[] propertys = entity.GetType().GetProperties();// 获得此模型的公共属性
|
||||
List<SqlParameter> parameters = new List<SqlParameter>();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
|
||||
if (!pi.CanWrite) continue;
|
||||
strSql.Append(pi.Name + "=@" + pi.Name + ",");
|
||||
parameters.Add(new SqlParameter("@" + pi.Name, pi.GetValue(entity)));
|
||||
}
|
||||
strSql.Remove(strSql.Length - 1, 1);//移除最后一个逗号
|
||||
strSql.Append(" where " + strField + "=@strValue");
|
||||
strSql.Replace("Operatorid=@Operatorid,", "");
|
||||
System.Type keyType = keyValue.GetType();
|
||||
switch (keyType.Name)
|
||||
{
|
||||
case "Int32":
|
||||
SqlParameter strValue = new SqlParameter("@strValue", SqlDbType.Int)
|
||||
{
|
||||
Value = keyValue
|
||||
};
|
||||
parameters.Add(strValue);
|
||||
break;
|
||||
default:
|
||||
parameters.Add(new SqlParameter("@strValue", keyValue));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
int rows = DbHelperMySqlCustom.ExecuteSql(strSql.ToString(), parameters.ToArray());
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改一列数据
|
||||
/// </summary>
|
||||
public int UpdateField(TEntity entity, string strField, object strValue, string strWhere)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("update " + databasetablename);
|
||||
strSql.Append(" set " + strField + "=@strValue");
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
SqlParameter[] parameters = {
|
||||
new SqlParameter("@strValue",strValue)
|
||||
};
|
||||
return DbHelperMySqlCustom.ExecuteSql(strSql.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除一条数据
|
||||
/// </summary>
|
||||
public bool Delete(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("delete from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
SqlParameter[] parameters = {
|
||||
new SqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
int rows = DbHelperMySqlCustom.ExecuteSql(strSql.ToString(), parameters);
|
||||
if (rows > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="uid"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity GetModel(TEntity entity, string strField, object keyValue)
|
||||
{
|
||||
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
strSql.Append(" where " + strField + "=@keyValue ");
|
||||
strSql.Append(" LIMIT 0,1;");
|
||||
SqlParameter[] parameters = {
|
||||
new SqlParameter("@keyValue",keyValue)
|
||||
};
|
||||
|
||||
DataSet ds = DbHelperMySqlCustom.Query(strSql.ToString(), parameters);
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModel(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到数据列表
|
||||
/// </summary>
|
||||
/// <param name="strWhere"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> GetList(string strWhere = null)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select * from " + databasetablename);
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
//strSql.Append(" LIMIT 0,1;");
|
||||
strSql.Append(";");
|
||||
TEntity entity = new TEntity();
|
||||
DataSet ds = DbHelperMySqlCustom.Query(strSql.ToString());
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModels(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重载,得到数据列表
|
||||
/// </summary>
|
||||
/// <param name="columnName"></param>
|
||||
/// <param name="strWhere"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> GetList(string columnName, string strWhere)
|
||||
{
|
||||
StringBuilder strSql = new StringBuilder();
|
||||
strSql.Append("select " + columnName + " from " + databasetablename);
|
||||
if (!string.IsNullOrEmpty(strWhere))
|
||||
{
|
||||
strSql.Append(" where " + strWhere);
|
||||
}
|
||||
//strSql.Append(" LIMIT 0,1;");
|
||||
strSql.Append(";");
|
||||
TEntity entity = new TEntity();
|
||||
DataSet ds = DbHelperMySqlCustom.Query(strSql.ToString());
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModels(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<pmsLog> StoredprocedureList(List<int> ints)
|
||||
{
|
||||
return DbHelperMySqlCustom.Storedprocedure(ints);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到数据列表
|
||||
/// </summary>
|
||||
/// <param name="strSql"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> SqlQueryGetList(string strSql)
|
||||
{
|
||||
//StringBuilder strSql = new StringBuilder();
|
||||
//strSql.Append("select " + columnName + " from " + databasetablename);
|
||||
//if (!string.IsNullOrEmpty(strWhere))
|
||||
//{
|
||||
// strSql.Append(" where " + strWhere);
|
||||
//}
|
||||
//strSql.Append(" LIMIT 0,1;");
|
||||
//strSql.Append(";");
|
||||
TEntity entity = new TEntity();
|
||||
DataSet ds = DbHelperMySqlCustom.Query(strSql);
|
||||
if (ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
return DataRowToModels(entity, ds.Tables[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public TEntity DataRowToModel(TEntity model, DataTable dt)
|
||||
{
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dt.Rows[0][pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> DataRowToModels(TEntity model, DataTable dt)
|
||||
{
|
||||
List<TEntity> ts = new List<TEntity>();// 定义集合
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dr[pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
if (value.ToString().Trim().Length <= 0)
|
||||
{
|
||||
value = "0";
|
||||
}
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
bool fatr=false;
|
||||
if (value.ToString()== "1")
|
||||
{
|
||||
fatr = true;
|
||||
}
|
||||
pi.SetValue(t, fatr, null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ts.Add(t);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataTable转换得到一个对象实体集合
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public List<TEntity> DataRowToModels(DataTable dt)
|
||||
{
|
||||
List<TEntity> ts = new List<TEntity>();// 定义集合
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
TEntity t = new TEntity();
|
||||
PropertyInfo[] propertys = t.GetType().GetProperties();// 获得此模型的公共属性
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
if (dt.Columns.Contains(pi.Name))
|
||||
{
|
||||
if (!pi.CanWrite) continue;
|
||||
var value = dr[pi.Name];
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
switch (pi.PropertyType.FullName)
|
||||
{
|
||||
case "System.Decimal":
|
||||
pi.SetValue(t, decimal.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.String":
|
||||
pi.SetValue(t, value.ToString(), null);
|
||||
break;
|
||||
case "System.Single":
|
||||
pi.SetValue(t, float.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Double":
|
||||
pi.SetValue(t, double.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Int32":
|
||||
pi.SetValue(t, int.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.DateTime":
|
||||
pi.SetValue(t, DateTime.Parse(value.ToString()), null);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
pi.SetValue(t, bool.Parse(value.ToString()), null);
|
||||
break;
|
||||
default:
|
||||
pi.SetValue(t, value, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ts.Add(t);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1294
Face.Services/DBUtility/Custom/DbHelperMySqlCustom.cs
Normal file
1294
Face.Services/DBUtility/Custom/DbHelperMySqlCustom.cs
Normal file
File diff suppressed because it is too large
Load Diff
26
Face.Services/Enums/Accountentity.cs
Normal file
26
Face.Services/Enums/Accountentity.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
public class Accountentity
|
||||
{
|
||||
public string Uid { get; set; }
|
||||
|
||||
public string Pwd { get; set; }
|
||||
public string HeadImg { get; set; }
|
||||
|
||||
public string Sex { get; set; }
|
||||
public int Age { get; set; }
|
||||
|
||||
public int IsValid { get; set; }
|
||||
|
||||
public string Desc { get; set; }
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
public string CreatedBy { get; set; }
|
||||
}
|
||||
}
|
||||
31
Face.Services/Enums/CacheTimeType.cs
Normal file
31
Face.Services/Enums/CacheTimeType.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存的时间类别
|
||||
/// </summary>
|
||||
public enum CacheTimeType
|
||||
{
|
||||
/// <summary>
|
||||
/// 按照分钟模式
|
||||
/// </summary>
|
||||
ByMinutes,
|
||||
/// <summary>
|
||||
/// 按照小时模式
|
||||
/// </summary>
|
||||
ByHours,
|
||||
/// <summary>
|
||||
/// 按照天模式
|
||||
/// </summary>
|
||||
ByDays,
|
||||
/// <summary>
|
||||
/// 按照年模式
|
||||
/// </summary>
|
||||
ByYears
|
||||
}
|
||||
}
|
||||
30
Face.Services/Enums/LoginInfoType.cs
Normal file
30
Face.Services/Enums/LoginInfoType.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
public enum LoginInfoType
|
||||
{
|
||||
/*
|
||||
* 添加账户类型的时候,枚举值为2的倍数
|
||||
*
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// 管理人员
|
||||
/// </summary>
|
||||
[Description("管理人员")]
|
||||
Manager = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 用户
|
||||
/// </summary>
|
||||
[Description("用户")]
|
||||
User = 4,
|
||||
|
||||
}
|
||||
}
|
||||
34
Face.Services/Enums/OperationLevel.cs
Normal file
34
Face.Services/Enums/OperationLevel.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作权限级别
|
||||
/// </summary>
|
||||
public enum OperationLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// 只读
|
||||
/// </summary>
|
||||
[Description("只读")]
|
||||
ReadOnly = 10,
|
||||
|
||||
/// <summary>
|
||||
/// 读写
|
||||
/// </summary>
|
||||
[Description("读写")]
|
||||
ReadWrite = 20,
|
||||
|
||||
/// <summary>
|
||||
/// 完整
|
||||
/// </summary>
|
||||
[Description("完整")]
|
||||
Full = 30,
|
||||
|
||||
}
|
||||
}
|
||||
62
Face.Services/Enums/OrderStatus.cs
Normal file
62
Face.Services/Enums/OrderStatus.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
public enum OrderStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 已下单待转内部单
|
||||
/// </summary>
|
||||
[Description("已下单待转M/O")]
|
||||
PlaceOrder = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 已转M/O待制条码
|
||||
/// </summary>
|
||||
[Description("已转M/O待制条码")]
|
||||
MOrder = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 已制SN待制计划
|
||||
/// </summary>
|
||||
[Description("已制SN待制计划")]
|
||||
SnRules = 3,
|
||||
|
||||
/// <summary>
|
||||
/// 已制计划待生产
|
||||
/// </summary>
|
||||
[Description("已制计划待生产")]
|
||||
ProductionPlan = 4,
|
||||
|
||||
/// <summary>
|
||||
/// 生产中
|
||||
/// </summary>
|
||||
[Description("生产中")]
|
||||
InProduction = 5,
|
||||
|
||||
/// <summary>
|
||||
/// 完成生产
|
||||
/// </summary>
|
||||
[Description("完成生产")]
|
||||
CompleteProduction = 6,
|
||||
|
||||
/// <summary>
|
||||
/// 已完成
|
||||
/// </summary>
|
||||
[Description("已完成")]
|
||||
Completed = 7,
|
||||
|
||||
/// <summary>
|
||||
/// 取消
|
||||
/// </summary>
|
||||
[Description("取消")]
|
||||
Cancel = -1,
|
||||
|
||||
/// <summary>
|
||||
/// 暂停中
|
||||
/// </summary>
|
||||
[Description("暂停中")]
|
||||
Suspend = -2,
|
||||
|
||||
}
|
||||
}
|
||||
47
Face.Services/Enums/ShortStringVersion.cs
Normal file
47
Face.Services/Enums/ShortStringVersion.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// 短字符串版本
|
||||
/// </summary>
|
||||
public enum ShortStringVersion
|
||||
{
|
||||
/// <summary>
|
||||
/// 版本1
|
||||
/// </summary>
|
||||
[MaxLength(6)]
|
||||
[Description("版本1")]
|
||||
Version_1 = 5,
|
||||
/// <summary>
|
||||
/// 版本2
|
||||
/// </summary>
|
||||
[MaxLength(8)]
|
||||
[Description("版本2")]
|
||||
Version_2 = 4,
|
||||
/// <summary>
|
||||
/// 版本3
|
||||
/// </summary>
|
||||
[Description("版本3")]
|
||||
[MaxLength(10)]
|
||||
Version_3 = 3,
|
||||
/// <summary>
|
||||
/// 版本4
|
||||
/// </summary>
|
||||
[MaxLength(15)]
|
||||
[Description("版本4")]
|
||||
Version_4 = 2,
|
||||
/// <summary>
|
||||
/// 版本5
|
||||
/// </summary>
|
||||
[Description("版本5")]
|
||||
[MaxLength(30)]
|
||||
Version_5 = 1
|
||||
}
|
||||
}
|
||||
39
Face.Services/Enums/StationType.cs
Normal file
39
Face.Services/Enums/StationType.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Enums
|
||||
{
|
||||
public enum StationType
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 测试
|
||||
/// </summary>
|
||||
[Description("Test")]
|
||||
Test = 100,
|
||||
|
||||
/// <summary>
|
||||
/// 测试2
|
||||
/// </summary>
|
||||
[Description("Test2")]
|
||||
Test2 = 120,
|
||||
|
||||
/// <summary>
|
||||
/// 组装
|
||||
/// </summary>
|
||||
[Description("Assem")]
|
||||
Assem = 200,
|
||||
|
||||
/// <summary>
|
||||
/// 质量保证
|
||||
/// </summary>
|
||||
[Description("QA")]
|
||||
QA = 300,
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
149
Face.Services/Extensions/CacheExtensions.cs
Normal file
149
Face.Services/Extensions/CacheExtensions.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using Face.Services.Enums;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Face.Services.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存扩展
|
||||
/// </summary>
|
||||
public static class CacheExtensions
|
||||
{
|
||||
public static MvcHtmlString Cache(this HtmlHelper htmlHelper, string cacheName, Func<object> func, CacheTimeType cacheTimeType, int cacheTime)
|
||||
{
|
||||
if (!CacheExtensions.CheckCache(cacheName))
|
||||
{
|
||||
CacheExtensions.SetCache(cacheName, func().ToString(), cacheTimeType, cacheTime);
|
||||
}
|
||||
return MvcHtmlString.Create(CacheExtensions.GetCache<string>(cacheName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查缓存名是否存在,如果存在则返回True
|
||||
/// </summary>
|
||||
/// <param name="cacheName">缓存的枚举类</param>
|
||||
public static bool CheckCache(string cacheName)
|
||||
{
|
||||
return HttpRuntime.Cache[cacheName.ToString()] != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存,未做校验,每次取缓存的时候需要判断缓存是否存在
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="cacheName"></param>
|
||||
/// <param name="varName"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetCache<T>(string cacheName)
|
||||
{
|
||||
return (T)((object)HttpRuntime.Cache[cacheName]);
|
||||
}
|
||||
|
||||
public static T GetCacheWithSet<T>(string cacheName, Func<T> valueFunc, CacheTimeType cacheTimeType, int times)
|
||||
{
|
||||
if (!CacheExtensions.CheckCache(cacheName))
|
||||
{
|
||||
CacheExtensions.SetCache(cacheName, valueFunc(), cacheTimeType, times);
|
||||
}
|
||||
return CacheExtensions.GetCache<T>(cacheName);
|
||||
}
|
||||
|
||||
public static T GetCacheWithSet<T>(string cacheName, Func<T> valueFunc)
|
||||
{
|
||||
if (!CacheExtensions.CheckCache(cacheName))
|
||||
{
|
||||
CacheExtensions.SetCache(cacheName, valueFunc());
|
||||
}
|
||||
return CacheExtensions.GetCache<T>(cacheName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存集合,未做校验,每次取缓存的时候需要判断缓存是否存在
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="cacheName"></param>
|
||||
/// <param name="varName"></param>
|
||||
/// <returns></returns>
|
||||
public static List<T> GetCacheList<T>(string cacheName)
|
||||
{
|
||||
return (List<T>)HttpRuntime.Cache[cacheName];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置缓存
|
||||
/// </summary>
|
||||
/// <param name="cacheName"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cacheTimeType"></param>
|
||||
/// <param name="cacheTime"></param>
|
||||
public static void SetCache(string cacheName, object value, CacheTimeType cacheTimeType, int cacheTime)
|
||||
{
|
||||
switch (cacheTimeType)
|
||||
{
|
||||
case CacheTimeType.ByMinutes:
|
||||
HttpRuntime.Cache.Insert(cacheName, value, null, DateTime.Now.AddMinutes((double)cacheTime), TimeSpan.Zero);
|
||||
return;
|
||||
case CacheTimeType.ByHours:
|
||||
HttpRuntime.Cache.Insert(cacheName, value, null, DateTime.Now.AddHours((double)cacheTime), TimeSpan.Zero);
|
||||
return;
|
||||
case CacheTimeType.ByDays:
|
||||
HttpRuntime.Cache.Insert(cacheName, value, null, DateTime.Now.AddDays((double)cacheTime), TimeSpan.Zero);
|
||||
return;
|
||||
case CacheTimeType.ByYears:
|
||||
HttpRuntime.Cache.Insert(cacheName, value, null, DateTime.Now.AddYears(cacheTime), TimeSpan.Zero);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetCache(string cacheName, object value)
|
||||
{
|
||||
HttpRuntime.Cache.Insert(cacheName, value);
|
||||
}
|
||||
|
||||
public static List<string> GetAllCache()
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
IDictionaryEnumerator enumerator = HttpRuntime.Cache.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
list.Add(enumerator.Key.ToString());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除指定缓存
|
||||
/// </summary>
|
||||
/// <param name="cacheName"></param>
|
||||
public static void ClearCache(string cacheName)
|
||||
{
|
||||
if (CacheExtensions.CheckCache(cacheName))
|
||||
{
|
||||
HttpRuntime.Cache.Remove(cacheName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置缓存
|
||||
/// </summary>
|
||||
/// <param name="cacheName"></param>
|
||||
/// <param name="value"></param>
|
||||
public static void RestCache(string cacheName, object value)
|
||||
{
|
||||
if (CacheExtensions.CheckCache(cacheName))
|
||||
{
|
||||
HttpRuntime.Cache[cacheName] = value;
|
||||
return;
|
||||
}
|
||||
CacheExtensions.SetCache(cacheName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
82
Face.Services/Extensions/CookieExtensions.cs
Normal file
82
Face.Services/Extensions/CookieExtensions.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Face.Services.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// cookie扩展
|
||||
/// </summary>
|
||||
public static class CookieExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 写cookie值
|
||||
/// </summary>
|
||||
/// <param name="strName">名称</param>
|
||||
/// <param name="strValue">值</param>
|
||||
public static void WriteCookie(string strName, string strValue)
|
||||
{
|
||||
HttpCookie httpCookie = HttpContext.Current.Request.Cookies[strName];
|
||||
if (httpCookie == null)
|
||||
{
|
||||
httpCookie = new HttpCookie(strName);
|
||||
}
|
||||
httpCookie.Value = strValue;
|
||||
HttpContext.Current.Response.AppendCookie(httpCookie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写cookie值
|
||||
/// </summary>
|
||||
/// <param name="strName">名称</param>
|
||||
/// <param name="strValue">值</param>
|
||||
/// <param name="strValue">过期时间(分钟)</param>
|
||||
public static void WriteCookie(string strName, string strValue, int expires)
|
||||
{
|
||||
HttpCookie httpCookie = HttpContext.Current.Request.Cookies[strName];
|
||||
if (httpCookie == null)
|
||||
{
|
||||
httpCookie = new HttpCookie(strName);
|
||||
}
|
||||
httpCookie.Value = strValue;
|
||||
httpCookie.Expires = DateTime.Now.AddMinutes((double)expires);
|
||||
HttpContext.Current.Response.AppendCookie(httpCookie);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读cookie值
|
||||
/// </summary>
|
||||
/// <param name="strName">名称</param>
|
||||
/// <returns>cookie值</returns>
|
||||
public static string GetCookie(string strName)
|
||||
{
|
||||
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
|
||||
{
|
||||
return HttpContext.Current.Request.Cookies[strName].Value.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查Cookie,如果存在则为true
|
||||
/// </summary>
|
||||
/// <param name="strName"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CheckCookie(string strName)
|
||||
{
|
||||
return HttpContext.Current.Request.Cookies[strName] != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除Cookie
|
||||
/// </summary>
|
||||
/// <param name="strName"></param>
|
||||
public static void RemoveCookie(string strName)
|
||||
{
|
||||
HttpContext.Current.Request.Cookies.Remove(strName);
|
||||
}
|
||||
}
|
||||
}
|
||||
59
Face.Services/Extensions/CustomException.cs
Normal file
59
Face.Services/Extensions/CustomException.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 异常扩展
|
||||
/// </summary>
|
||||
public class CustomException : ApplicationException
|
||||
{
|
||||
//记录异常的类型
|
||||
private CustomExceptionType exceptionType;
|
||||
|
||||
public CustomException(CustomExceptionType type) : base()
|
||||
{
|
||||
this.exceptionType = type;
|
||||
}
|
||||
|
||||
public CustomException(CustomExceptionType type, string message) : base(message)
|
||||
{
|
||||
this.exceptionType = type;
|
||||
}
|
||||
|
||||
public CustomException(string message) : base(message)
|
||||
{
|
||||
this.exceptionType = CustomExceptionType.InputValidation;
|
||||
}
|
||||
|
||||
//序列化
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
}
|
||||
|
||||
//重写message方法,以让它显示相应异常提示信息
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
//根据异常类型从message.xml中读取相应异常提示信息
|
||||
return base.Message;
|
||||
//return string.Format(XmlMessageManager.GetXmlMessage((int)exceptionType), base.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum CustomExceptionType
|
||||
{
|
||||
InputValidation = 1,
|
||||
hint = 2,
|
||||
Warning = 3,
|
||||
Unknown = 8
|
||||
}
|
||||
}
|
||||
130
Face.Services/Extensions/EnumerableExtensions.cs
Normal file
130
Face.Services/Extensions/EnumerableExtensions.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 枚举扩展
|
||||
/// </summary>
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 对枚举器的每个元素执行指定的操作
|
||||
/// </summary>
|
||||
/// <typeparam name="T">枚举器类型参数</typeparam>
|
||||
/// <param name="source">枚举器</param>
|
||||
/// <param name="action">要对枚举器的每个元素执行的委托</param>
|
||||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
if (source.IsNullOrEmpty<T>() || action == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (T obj in source)
|
||||
{
|
||||
action(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指示指定的枚举器是null还是没有任何元素
|
||||
/// </summary>
|
||||
/// <typeparam name="T">枚举器类型参数</typeparam>
|
||||
/// <param name="source">要测试的枚举器</param>
|
||||
/// <returns>true:枚举器是null或者没有任何元素 false:枚举器不为null并且包含至少一个元素</returns>
|
||||
public static bool IsNullOrEmpty<T>(this IEnumerable<T> source)
|
||||
{
|
||||
return source == null || !source.Any<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到枚举中文备注
|
||||
/// </summary>
|
||||
/// <param name="enumValue"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetEnumDesc(this System.Enum enumValue)
|
||||
{
|
||||
string value = enumValue.ToString();
|
||||
System.Reflection.FieldInfo field = enumValue.GetType().GetField(value);
|
||||
object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false); //获取描述属性
|
||||
if (objs.Length == 0) //当描述属性没有时,直接返回名称
|
||||
return value;
|
||||
DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
|
||||
return descriptionAttribute.Description;
|
||||
}
|
||||
|
||||
public static string GetEnumDesc(this Type enumType, object val)
|
||||
{
|
||||
string enumvalue = Enum.GetName(enumType, val);
|
||||
if (string.IsNullOrEmpty(enumvalue))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
FieldInfo finfo = enumType.GetField(enumvalue);
|
||||
object[] enumAttr = finfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
if (enumAttr.Length > 0)
|
||||
{
|
||||
DescriptionAttribute desc = (DescriptionAttribute)enumAttr[0];
|
||||
if (desc != null)
|
||||
{
|
||||
return desc.Description;
|
||||
}
|
||||
}
|
||||
return enumvalue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有的枚举描述和值
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static List<EnumDto> GetEnumListItem(this Type type)
|
||||
{
|
||||
|
||||
List<EnumDto> list = new List<EnumDto>();
|
||||
|
||||
// 循环枚举获取所有的Fields
|
||||
foreach (var field in type.GetFields())
|
||||
{
|
||||
// 如果是枚举类型
|
||||
if (field.FieldType.IsEnum)
|
||||
{
|
||||
object tmp = field.GetValue(null);
|
||||
Enum enumValue = (Enum)tmp;
|
||||
int intValue = Convert.ToInt32(enumValue);
|
||||
string showName = enumValue.GetEnumDesc(); // 获取描述和排序
|
||||
list.Add(new EnumDto { Value = intValue, Description= showName });
|
||||
}
|
||||
}
|
||||
//返回
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
public class EnumDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 枚举code
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public int Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
469
Face.Services/Extensions/LinqExtensions.cs
Normal file
469
Face.Services/Extensions/LinqExtensions.cs
Normal file
@@ -0,0 +1,469 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.Linq
|
||||
{
|
||||
public static class LinqExtensions
|
||||
{
|
||||
/// <summary>通过页面控件动态构建查询</summary>
|
||||
public static IQueryable<TSource> WhereDynamic<TSource>(this IQueryable<TSource> source,
|
||||
NameValueCollection nameValues) where TSource : class
|
||||
{
|
||||
if (nameValues.Count > 0)
|
||||
{
|
||||
//构建 c=>Body中的c
|
||||
ParameterExpression param = Expression.Parameter(typeof(TSource), "c");
|
||||
//构建c=>Body中的Body
|
||||
var body = GetExpressoinBody(param, nameValues);
|
||||
if (body != null)
|
||||
{
|
||||
//将二者拼为c=>Body
|
||||
var expression = Expression.Lambda<Func<TSource, bool>>(body, param);
|
||||
//传到Where中当做参数,类型为Expression<Func<T,bool>>
|
||||
return source.Where(expression);
|
||||
}
|
||||
}
|
||||
return source;
|
||||
}
|
||||
/// <summary>构建body</summary>
|
||||
private static Expression GetExpressoinBody(ParameterExpression param, NameValueCollection nameValues)
|
||||
{
|
||||
var list = new List<Expression>();
|
||||
if (nameValues.Count > 0)
|
||||
{
|
||||
var plist = param.Type.GetRuntimeProperties().ToDictionary(z => z.Name);//可以加缓存改善性能
|
||||
foreach (var item in nameValues.AllKeys)
|
||||
if (item.EndsWith(">") || item.EndsWith(">="))//可能大小查询
|
||||
{
|
||||
bool isEqual = item.EndsWith(">=");
|
||||
string key = isEqual ? item.TrimEnd('=').TrimEnd('>') : item.TrimEnd('>');
|
||||
if (!plist.ContainsKey(key) || nameValues[item].Length <= 0) continue;
|
||||
var rType = plist[key].GetMethod.ReturnType;
|
||||
if (rType == typeof(string)) continue;
|
||||
var e1 = Expression.Property(param, key);
|
||||
object dValue;
|
||||
if (TryParser(nameValues[item], rType, out dValue))
|
||||
//list.Add(Expression.GreaterThan(e1, Expression.Constant(dValue, rType)));
|
||||
list.Add(AddGreaterGreaterThan(e1, Expression.Constant(dValue, rType), isEqual));
|
||||
else if (plist[key].GetMethod.ReturnType.GenericTypeArguments.Count() > 0 && TryParser(nameValues[item], plist[key].GetMethod.ReturnType.GenericTypeArguments[0], out dValue))
|
||||
//list.Add(Expression.GreaterThan(e1, Expression.Constant(dValue, rType)));
|
||||
list.Add(AddGreaterGreaterThan(e1, Expression.Constant(dValue, rType), isEqual));
|
||||
else if (rType == typeof(DateTime?))
|
||||
{
|
||||
DateTime enddate = nameValues[item].ToDateTime().GetValueOrDefault();
|
||||
//list.Add(Expression.GreaterThan(e1, Expression.Constant(enddate, typeof(DateTime?))));
|
||||
list.Add(AddGreaterGreaterThan(e1, Expression.Constant(enddate, typeof(DateTime?)), isEqual));
|
||||
}
|
||||
}
|
||||
else if (item.EndsWith("<") || item.EndsWith("<="))//可能大小查询
|
||||
{
|
||||
bool isEqual = item.EndsWith("<=");
|
||||
string key = isEqual ? item.TrimEnd('=').TrimEnd('<') : item.TrimEnd('<');
|
||||
if (!plist.ContainsKey(key) || nameValues[item].Length <= 0) continue;
|
||||
var rType = plist[key].GetMethod.ReturnType;
|
||||
if (rType == typeof(string)) continue;
|
||||
var e1 = Expression.Property(param, key);
|
||||
object dValue;
|
||||
if (TryParser(nameValues[item], rType, out dValue))
|
||||
{
|
||||
if (rType == typeof(DateTime)) dValue = ((DateTime)dValue).AddDays(1);
|
||||
//list.Add(Expression.LessThan(e1, Expression.Constant(dValue, rType)));
|
||||
list.Add(AddGreaterLessThan(e1, Expression.Constant(dValue, rType), isEqual));
|
||||
}
|
||||
else if (plist[key].GetMethod.ReturnType.GenericTypeArguments.Count() > 0 && TryParser(nameValues[item], plist[key].GetMethod.ReturnType.GenericTypeArguments[0], out dValue))
|
||||
{
|
||||
if (plist[key].GetMethod.ReturnType.GenericTypeArguments[0] == typeof(DateTime)) dValue = ((DateTime)dValue).AddDays(1);
|
||||
//list.Add(Expression.LessThan(e1, Expression.Constant(dValue, rType)));
|
||||
list.Add(AddGreaterLessThan(e1, Expression.Constant(dValue, rType), isEqual));
|
||||
}
|
||||
else if (rType == typeof(DateTime?))
|
||||
{
|
||||
DateTime enddate = nameValues[item].ToDateTime().GetValueOrDefault().AddDays(1);
|
||||
//list.Add(Expression.LessThan(e1, Expression.Constant(enddate, typeof(DateTime?))));
|
||||
list.Add(AddGreaterLessThan(e1, Expression.Constant(enddate, typeof(DateTime?)), isEqual));
|
||||
}
|
||||
}
|
||||
else if (plist.ContainsKey(item) && nameValues[item].Length > 0)
|
||||
{
|
||||
var e1 = Expression.Property(param, item);
|
||||
var rType = plist[item].GetMethod.ReturnType;
|
||||
if (rType == typeof(string))//可能是like查询
|
||||
{
|
||||
var value = nameValues[item].Trim('%');
|
||||
var e2 = Expression.Constant(value, rType);
|
||||
if (nameValues[item].StartsWith("%") && nameValues[item].EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "Contains", null, new Expression[] { e2 }));
|
||||
else if (nameValues[item].StartsWith("%"))
|
||||
list.Add(Expression.Call(e1, "EndsWith", null, new Expression[] { e2 }));
|
||||
else if (nameValues[item].EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "StartsWith", null, new Expression[] { e2 }));
|
||||
else
|
||||
list.Add(Expression.Equal(e1, e2));
|
||||
}
|
||||
|
||||
else if (nameValues[item].IndexOf(",") > 0)//可能是in查询
|
||||
{
|
||||
if (rType == typeof(short))
|
||||
{
|
||||
var searchList = TryParser<short>(nameValues[item]);
|
||||
if (searchList.Any())
|
||||
list.Add(Expression.Call(Expression.Constant(searchList, rType), "Contains", null, new Expression[] { e1 }));
|
||||
}
|
||||
else if (rType == typeof(int))
|
||||
{
|
||||
var searchList = TryParser<int>(nameValues[item]);
|
||||
if (searchList.Any())
|
||||
list.Add(Expression.Call(Expression.Constant(searchList, rType), "Contains", null, new Expression[] { e1 }));
|
||||
}
|
||||
else if (rType == typeof(long))
|
||||
{
|
||||
var searchList = TryParser<long>(nameValues[item]);
|
||||
if (searchList.Any())
|
||||
list.Add(Expression.Call(Expression.Constant(searchList, rType), "Contains", null, new Expression[] { e1 }));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
object dValue;
|
||||
if (TryParser(nameValues[item], rType, out dValue))
|
||||
list.Add(Expression.Equal(e1, Expression.Constant(dValue, rType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return list.Count > 0 ? list.Aggregate(Expression.AndAlso) : null;
|
||||
}
|
||||
|
||||
private static List<T> TryParser<T>(string value)
|
||||
{
|
||||
string[] searchArray = value.Split(',');
|
||||
List<T> dList = new List<T>();
|
||||
foreach (var l in searchArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
T dValue = (T)Convert.ChangeType(l, typeof(T));
|
||||
dList.Add(dValue);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
return dList;
|
||||
}
|
||||
|
||||
private static bool TryParser(string value, Type outType, out object dValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
dValue = Convert.ChangeType(value, outType);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
dValue = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//大于
|
||||
private static Expression AddGreaterGreaterThan(Expression exleft, Expression exright, bool Equal)
|
||||
{
|
||||
if (Equal)
|
||||
{
|
||||
return Expression.GreaterThanOrEqual(exleft, exright);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Expression.GreaterThan(exleft, exright);
|
||||
}
|
||||
}
|
||||
//大于
|
||||
private static Expression AddGreaterLessThan(Expression exleft, Expression exright, bool Equal)
|
||||
{
|
||||
if (Equal)
|
||||
{
|
||||
return Expression.LessThanOrEqual(exleft, exright);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Expression.LessThan(exleft, exright);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从 System.Collections.Generic.IQueryable`1 创建一个 System.Collections.Generic.List`1。并在集合末尾添加一个默认值为空的TSource实例
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">要从其创建 System.Collections.Generic.List`1 的 System.Collections.Generic.IEnumerable`1。</param>
|
||||
/// <returns>一个包含输入序列中元素的 System.Collections.Generic.List`1。</returns>
|
||||
public static List<TSource> ToListAndAddEmpty<TSource>(this IQueryable<TSource> source) where TSource : class
|
||||
{
|
||||
List<TSource> list = source.ToList();
|
||||
TSource addmodel = Activator.CreateInstance<TSource>();
|
||||
list.Add(addmodel);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从 System.Collections.Generic.IEnumerable`1 创建一个 System.Collections.Generic.List`1。并在集合末尾添加一个默认值为空的TSource实例
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">要从其创建 System.Collections.Generic.List`1 的 System.Collections.Generic.IEnumerable`1。</param>
|
||||
/// <returns>一个包含输入序列中元素的 System.Collections.Generic.List`1。</returns>
|
||||
public static List<TSource> ToListAndAddEmpty<TSource>(this IEnumerable<TSource> source) where TSource : class
|
||||
{
|
||||
List<TSource> list = source.ToList();
|
||||
TSource addmodel = Activator.CreateInstance<TSource>();
|
||||
list.Add(addmodel);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态模糊查询
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">一个要模糊查找的值序列。</param>
|
||||
/// <typeparam name="TKey">由 keySelector 表示的函数返回的键类型。</typeparam>
|
||||
/// <param name="keyword">查询关键字(动态模糊在首或尾部添加%)</param>
|
||||
/// <param name="keyfiled">查询字段</param>
|
||||
/// <param name="keySelector">查询字段Lamvda表达式(支持多表导航查询)</param>
|
||||
/// <returns>一个 System.Linq.IOrderedQueryable`1,根据键对其元素模糊查找。</returns>
|
||||
public static IQueryable<TSource> LikeQueryable<TSource, TKey>(this IQueryable<TSource> source, string keyword, params Expression<Func<TSource, TKey>>[] keySelector)
|
||||
{
|
||||
try
|
||||
{
|
||||
var paramT = Expression.Parameter(typeof(TSource), "c");//c=>
|
||||
Expression body = null;
|
||||
var list = new List<Expression>();
|
||||
foreach (var item in keySelector)
|
||||
{
|
||||
string[] paramKs = item.Body.ToString().Split('.');
|
||||
var e1 = Expression.Property(paramT, paramKs[1]);//c.user
|
||||
for (int i = 2; i < paramKs.Count(); i++)
|
||||
{
|
||||
e1 = Expression.Property(e1, paramKs[i]);//c.user.ID
|
||||
}
|
||||
if (e1.Type == typeof(string))
|
||||
{
|
||||
var value = keyword.Trim('%');
|
||||
var e2 = Expression.Constant(value, typeof(string));
|
||||
if (keyword.StartsWith("%") && keyword.EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "Contains", null, new Expression[] { e2 }));
|
||||
else if (keyword.StartsWith("%"))
|
||||
list.Add(Expression.Call(e1, "EndsWith", null, new Expression[] { e2 }));
|
||||
else if (keyword.EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "StartsWith", null, new Expression[] { e2 }));
|
||||
else
|
||||
list.Add(Expression.Equal(e1, e2));
|
||||
}
|
||||
}
|
||||
body = list.Count > 0 ? list.Aggregate(Expression.OrElse) : null;
|
||||
//构建c=>Body中的Body
|
||||
if (body != null)
|
||||
{
|
||||
//将二者拼为c=>Body
|
||||
var expression = Expression.Lambda<Func<TSource, bool>>(body, paramT);
|
||||
//传到Where中当做参数,类型为Expression<Func<T,bool>>
|
||||
source = source.Where(expression);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态模糊查询
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">一个要模糊查找的值序列。</param>
|
||||
/// <param name="keyword">查询关键字(动态模糊在首或尾部添加%)</param>
|
||||
/// <param name="keyfiled">查询字段</param>
|
||||
/// <param name="keySelector">查询字段Lamvda表达式(支持多表导航查询)</param>
|
||||
/// <returns>一个 System.Linq.IOrderedQueryable`1,根据键对其元素模糊查找。</returns>
|
||||
public static IQueryable<TSource> LikeQueryable<TSource>(this IQueryable<TSource> source, string keyword, params string[] keyfiled)
|
||||
{
|
||||
try
|
||||
{
|
||||
var paramT = Expression.Parameter(typeof(TSource), "c");//c=>
|
||||
Expression body = null;
|
||||
var list = new List<Expression>();
|
||||
foreach (var item in keyfiled)
|
||||
{
|
||||
string[] paramKs = item.Split('.');
|
||||
var e1 = Expression.Property(paramT, paramKs[0]);//c.user
|
||||
for (int i = 1; i < paramKs.Count(); i++)
|
||||
{
|
||||
e1 = Expression.Property(e1, paramKs[i]);//c.user.ID
|
||||
}
|
||||
if (e1.Type == typeof(string))
|
||||
{
|
||||
var value = keyword.Trim('%');
|
||||
var e2 = Expression.Constant(value, typeof(string));
|
||||
if (keyword.StartsWith("%") && keyword.EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "Contains", null, new Expression[] { e2 }));
|
||||
else if (keyword.StartsWith("%"))
|
||||
list.Add(Expression.Call(e1, "EndsWith", null, new Expression[] { e2 }));
|
||||
else if (keyword.EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "StartsWith", null, new Expression[] { e2 }));
|
||||
else
|
||||
list.Add(Expression.Equal(e1, e2));
|
||||
}
|
||||
}
|
||||
body = list.Count > 0 ? list.Aggregate(Expression.OrElse) : null;
|
||||
//构建c=>Body中的Body
|
||||
if (body != null)
|
||||
{
|
||||
//将二者拼为c=>Body
|
||||
var expression = Expression.Lambda<Func<TSource, bool>>(body, paramT);
|
||||
//传到Where中当做参数,类型为Expression<Func<T,bool>>
|
||||
source = source.Where(expression);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 外键表动态模糊查询
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">一个要模糊查找的值序列。</param>
|
||||
/// <typeparam name="TKey">由 keySelector 表示的函数返回的键类型。</typeparam>
|
||||
/// <param name="keyword">查询关键字(动态模糊在首或尾部添加%)</param>
|
||||
/// <param name="keyfiledn">查询字段</param>
|
||||
/// <param name="keySelector">查询字段Lamvda表达式(支持多表导航查询)</param>
|
||||
/// <returns>一个 System.Linq.IOrderedQueryable`1,根据键对其元素模糊查找。</returns>
|
||||
public static IQueryable<TSource> LikeQueryable<TSource, TKey>(this IQueryable<TSource> source, string keyword, string keyfiled, params Expression<Func<TSource, TKey>>[] keySelector)
|
||||
{
|
||||
try
|
||||
{
|
||||
var paramT = Expression.Parameter(typeof(TSource), "c");//c=>
|
||||
Expression body = null;
|
||||
var list = new List<Expression>();
|
||||
foreach (var item in keySelector)
|
||||
{
|
||||
string[] paramKs = item.Body.ToString().Split('.');
|
||||
var e1 = Expression.Property(paramT, paramKs[1]);//c.user
|
||||
for (int i = 2; i < paramKs.Count(); i++)
|
||||
{
|
||||
e1 = Expression.Property(e1, paramKs[i]);//c.user.ID
|
||||
}
|
||||
e1 = Expression.Property(e1, keyfiled);//c.user.ID
|
||||
if (e1.Type == typeof(string))
|
||||
{
|
||||
var value = keyword.Trim('%');
|
||||
var e2 = Expression.Constant(value, typeof(string));
|
||||
if (keyword.StartsWith("%") && keyword.EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "Contains", null, new Expression[] { e2 }));
|
||||
else if (keyword.StartsWith("%"))
|
||||
list.Add(Expression.Call(e1, "EndsWith", null, new Expression[] { e2 }));
|
||||
else if (keyword.EndsWith("%"))
|
||||
list.Add(Expression.Call(e1, "StartsWith", null, new Expression[] { e2 }));
|
||||
else
|
||||
list.Add(Expression.Equal(e1, e2));
|
||||
}
|
||||
}
|
||||
body = list.Count > 0 ? list.Aggregate(Expression.OrElse) : null;
|
||||
//构建c=>Body中的Body
|
||||
if (body != null)
|
||||
{
|
||||
//将二者拼为c=>Body
|
||||
var expression = Expression.Lambda<Func<TSource, bool>>(body, paramT);
|
||||
//传到Where中当做参数,类型为Expression<Func<T,bool>>
|
||||
source = source.Where(expression);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态排序
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">一个要排序查找的值序列。</param>
|
||||
/// <param name="keyfiled">排序字段</param>
|
||||
/// <param name="type">排序类型0不排序,1升序,2降序</param>
|
||||
/// <returns>一个 System.Linq.IOrderedQueryable`1,根据键对其元素模糊查找。</returns>
|
||||
public static IQueryable<TSource> OrderByQueryable<TSource>(this IQueryable<TSource> source, string keyfiled, int type)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (type == 0) return source;//不排序
|
||||
var paramT = Expression.Parameter(typeof(TSource), "c");//c=>
|
||||
string[] paramKs = keyfiled.Split('.');
|
||||
var e1 = Expression.Property(paramT, paramKs[0]);//c.user
|
||||
for (int i = 1; i < paramKs.Count(); i++)
|
||||
{
|
||||
e1 = Expression.Property(e1, paramKs[i]);//c.user.ID
|
||||
}
|
||||
|
||||
dynamic expression = Expression.Lambda(e1, paramT);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 1:
|
||||
source = Queryable.OrderBy(source, expression);
|
||||
break;
|
||||
case 2:
|
||||
source = Queryable.OrderByDescending(source, expression);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态排序
|
||||
/// </summary>
|
||||
/// <typeparam name="TSource">source 中的元素的类型。</typeparam>
|
||||
/// <param name="source">一个要排序查找的值序列。</param>
|
||||
/// <param name="keyfiled">排序字段</param>
|
||||
/// <param name="type">排序类型0不排序,1升序,2降序</param>
|
||||
/// <returns>一个 System.Linq.IOrderedQueryable`1,根据键对其元素模糊查找。</returns>
|
||||
public static IEnumerable<TSource> OrderByQueryable<TSource>(this IEnumerable<TSource> source, string keyfiled, int type)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (type == 0) return source;//不排序
|
||||
var paramT = Expression.Parameter(typeof(TSource), "c");//c=>
|
||||
string[] paramKs = keyfiled.Split('.');
|
||||
var e1 = Expression.Property(paramT, paramKs[0]);//c.user
|
||||
for (int i = 1; i < paramKs.Count(); i++)
|
||||
{
|
||||
e1 = Expression.Property(e1, paramKs[i]);//c.user.ID
|
||||
}
|
||||
|
||||
dynamic expression = Expression.Lambda(e1, paramT);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 1:
|
||||
source = Queryable.OrderBy(source.AsQueryable(), expression);
|
||||
break;
|
||||
case 2:
|
||||
source = Queryable.OrderByDescending(source.AsQueryable(), expression);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
Face.Services/Extensions/ModelExtensions.cs
Normal file
66
Face.Services/Extensions/ModelExtensions.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 对象扩展
|
||||
/// </summary>
|
||||
public static class ModelExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建一个新的类型的对象,并将现有对象的属性值赋给新对象相同名称的属性
|
||||
/// </summary>
|
||||
/// <typeparam name="T">新对象的类型</typeparam>
|
||||
/// <param name="source">现有对象</param>
|
||||
/// <returns>新的对象</returns>
|
||||
public static T ToModel<T>(this object source) where T : new()
|
||||
{
|
||||
if (source == null)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
return Activator.CreateInstance<T>().UpdateFrom(source, new string[0]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将源对象的属性值赋给目标对象相同名称的属性
|
||||
/// </summary>
|
||||
/// <typeparam name="T">目标类型</typeparam>
|
||||
/// <param name="target">目标对象</param>
|
||||
/// <param name="source">源对象</param>
|
||||
/// <param name="copyPropertyName">需要复制的属性名,为空时表示复制全部</param>
|
||||
/// <returns>目标类型</returns>
|
||||
public static T UpdateFrom<T>(this T target, object source, params string[] copyPropertyName)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
if (source == null)
|
||||
{
|
||||
return target;
|
||||
}
|
||||
Type typeFromHandle = typeof(T);
|
||||
foreach (PropertyInfo obj in source.GetType().GetProperties())
|
||||
{
|
||||
//PropertyDescriptor propertyDescriptor = (PropertyDescriptor)obj;
|
||||
if (copyPropertyName == null || copyPropertyName.Length == 0 || copyPropertyName.Contains(obj.Name))
|
||||
{
|
||||
PropertyInfo property = typeFromHandle.GetProperty(obj.Name, BindingFlags.Instance | BindingFlags.Public);
|
||||
if (property != null && property.CanWrite)
|
||||
{
|
||||
property.SetValue(target, obj.GetValue(source, null), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
132
Face.Services/Extensions/SafeInputExtensions.cs
Normal file
132
Face.Services/Extensions/SafeInputExtensions.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串转换扩展
|
||||
/// </summary>
|
||||
public static class SafeInputExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 将字符串转换成Int类型,如果出错则返回0
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static short ToShort(this object str)
|
||||
{
|
||||
short result = 0;
|
||||
if (str != null)
|
||||
{
|
||||
short.TryParse(str.ToString(), out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换成Int类型,如果出错则返回0
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(this object str)
|
||||
{
|
||||
int result = 0;
|
||||
if (str != null)
|
||||
{
|
||||
int.TryParse(str.ToString(), out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换成decimal类型,如果出错则返回0
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static double ToDouble(this object str)
|
||||
{
|
||||
double result = 0.0;
|
||||
if (str != null)
|
||||
{
|
||||
double.TryParse(str.ToString(), out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static decimal ToDecimal(this object str)
|
||||
{
|
||||
decimal result = 0m;
|
||||
if (str != null)
|
||||
{
|
||||
decimal.TryParse(str.ToString(), out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string ToNone(this object str, string extStr)
|
||||
{
|
||||
if (str != null && !string.IsNullOrEmpty(str.ToString()))
|
||||
{
|
||||
return str + " " + extStr;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换成真假
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ToBool(this object str)
|
||||
{
|
||||
return str != null && str.ToString().Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换成GUID,出错则为Guid.NewGuid()
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static Guid ToGuid(this object str)
|
||||
{
|
||||
Guid result = Guid.NewGuid();
|
||||
if (str != null)
|
||||
{
|
||||
Guid.TryParse(str.ToString(), out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static DateTime ToDateTime(this object str)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
if (str != null)
|
||||
{
|
||||
DateTime.TryParse(str.ToString(), out now);
|
||||
}
|
||||
return now;
|
||||
}
|
||||
|
||||
public static string ToDateTimeRandom()
|
||||
{
|
||||
return DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(9999).ToString();
|
||||
}
|
||||
|
||||
public static string ToDateString()
|
||||
{
|
||||
return DateTime.Now.ToString("yyyyMMdd");
|
||||
}
|
||||
|
||||
public static string ToBr(this string str)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
return str.Replace("\r\n", "<br>");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
402
Face.Services/Extensions/StringExtensions.cs
Normal file
402
Face.Services/Extensions/StringExtensions.cs
Normal file
@@ -0,0 +1,402 @@
|
||||
using Face.Services.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串扩展函数工具类
|
||||
/// </summary>
|
||||
public static class StringExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 将\r\n替换成BR
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToSafeBR(this string str)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(str))
|
||||
{
|
||||
return str.Replace("\r\n", "<br>").Replace("\r", "<br>").Replace("\n", "<br>");
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到父部门的ID
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDepartmentFatherID(this string str)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(str) && str.Length > 2)
|
||||
{
|
||||
str = str.Substring(0, str.Length - 3);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 截取字符串,超过部分用...代替
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="len"></param>
|
||||
/// <returns></returns>
|
||||
public static string Substr(this string source, int len)
|
||||
{
|
||||
return source.Substr(len, "...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 截取字符串,超过部分用自定义代替
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="len"></param>
|
||||
/// <param name="att"></param>
|
||||
/// <returns></returns>
|
||||
public static string Substr(this string source, int len, string att)
|
||||
{
|
||||
if (string.IsNullOrEmpty(source))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
att = (att ?? string.Empty);
|
||||
Regex regex = new Regex("[\\u4e00-\\u9fa5]");
|
||||
Regex regex2 = new Regex("^[A-Za-z0-9]+$");
|
||||
if (regex.IsMatch(source))
|
||||
{
|
||||
if (source.Length <= len)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
return source.Substring(0, len) + att;
|
||||
}
|
||||
else if (regex2.IsMatch(source))
|
||||
{
|
||||
if (source.Length <= len * 2)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
return source.Substring(0, len * 2) + att;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (source.Length <= len)
|
||||
{
|
||||
return source;
|
||||
}
|
||||
return source.Substring(0, len) + att;
|
||||
}
|
||||
}
|
||||
|
||||
public static string InputStr(this string source)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(source))
|
||||
{
|
||||
Regex regex = new Regex("[\\u4e00-\\u9fa5]");
|
||||
Regex regex2 = new Regex("^[A-Za-z0-9]+$");
|
||||
if (regex.IsMatch(source))
|
||||
{
|
||||
if (source.Length < 3)
|
||||
{
|
||||
return string.Format("{0}**", source[0]);
|
||||
}
|
||||
if (source.Length == 3)
|
||||
{
|
||||
return string.Format("{0}*{1}", source[0], source[source.Length - 1]);
|
||||
}
|
||||
if (source.Length > 3)
|
||||
{
|
||||
return string.Format("{0}**{1}", source[0], source[source.Length - 1]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!regex2.IsMatch(source))
|
||||
{
|
||||
return string.Format("{0}**", source.Substring(0, 2));
|
||||
}
|
||||
if (source.Length < 6)
|
||||
{
|
||||
return string.Format("{0}**", source.Substring(0, 2));
|
||||
}
|
||||
return string.Format("{0}****{1}", source.Substring(0, 2), source.Substring(source.Length - 3, 2));
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除掉所有的Html代码
|
||||
/// </summary>
|
||||
/// <param name="strHtml"></param>
|
||||
/// <returns></returns>
|
||||
public static string RemoveHtml(this string strHtml)
|
||||
{
|
||||
Regex regex = new Regex("<.+?>", RegexOptions.IgnoreCase);
|
||||
strHtml = regex.Replace(strHtml, "");
|
||||
strHtml = strHtml.Replace(" ", "");
|
||||
return strHtml;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成0-9随机数
|
||||
/// </summary>
|
||||
/// <param name="VcodeNum">生成长度</param>
|
||||
/// <returns></returns>
|
||||
public static string RndNum(int VcodeNum)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder(VcodeNum);
|
||||
Random random = new Random();
|
||||
for (int i = 1; i < VcodeNum + 1; i++)
|
||||
{
|
||||
int num = random.Next(9);
|
||||
stringBuilder.AppendFormat("{0}", num);
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回星号的加密
|
||||
/// </summary>
|
||||
/// <param name="items"></param>
|
||||
/// <param name="mask"></param>
|
||||
/// <returns></returns>
|
||||
public static string MaskStar(Dictionary<string, string> items, bool mask)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (mask)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> keyValuePair in items)
|
||||
{
|
||||
stringBuilder.Append(string.Concat(new string[]
|
||||
{
|
||||
"$('#",
|
||||
keyValuePair.Key,
|
||||
"').attr('name', '",
|
||||
keyValuePair.Key,
|
||||
"mask');"
|
||||
}));
|
||||
}
|
||||
stringBuilder.Append("$('.maskstar').attr('disabled', true);");
|
||||
stringBuilder.Append("$('.maskstar').val('***');");
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (KeyValuePair<string, string> keyValuePair2 in items)
|
||||
{
|
||||
stringBuilder.Append(string.Concat(new string[]
|
||||
{
|
||||
"$('#",
|
||||
keyValuePair2.Key,
|
||||
"').attr('name', '",
|
||||
keyValuePair2.Key,
|
||||
"');"
|
||||
}));
|
||||
stringBuilder.Append(string.Concat(new string[]
|
||||
{
|
||||
"$('#",
|
||||
keyValuePair2.Key,
|
||||
"').val('",
|
||||
keyValuePair2.Value,
|
||||
"');"
|
||||
}));
|
||||
}
|
||||
stringBuilder.Append("$('.maskstar').attr('disabled', false);");
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 给自动填充使用
|
||||
/// </summary>
|
||||
/// <param name="str1"></param>
|
||||
/// <param name="str2"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToAutoComplate(this string str1, string str2)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(str1) && !string.IsNullOrEmpty(str2))
|
||||
{
|
||||
return str1 + "," + str2;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回红色字体
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToRedColor(this int value)
|
||||
{
|
||||
if (value != 0)
|
||||
{
|
||||
return "<font color='red'>" + value.ToString() + "</font>";
|
||||
}
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回安全的字符串类型如果为NULL则返回空
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToSafeString(this object value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将中文转换成Unicode编码,主要用在URL传递中文
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string GB2Unicode(this string str)
|
||||
{
|
||||
string text = "";
|
||||
Encoding encoding = Encoding.GetEncoding("GB2312");
|
||||
Encoding unicode = Encoding.Unicode;
|
||||
byte[] bytes = encoding.GetBytes(str);
|
||||
for (int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
string str2 = "%" + bytes[i].ToString("x");
|
||||
text += str2;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换成为大写的MD5
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToMD5(this string str)
|
||||
{
|
||||
MD5CryptoServiceProvider md5CryptoServiceProvider = new MD5CryptoServiceProvider();
|
||||
byte[] array = md5CryptoServiceProvider.ComputeHash(Encoding.Default.GetBytes(str));
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (byte b in array)
|
||||
{
|
||||
stringBuilder.Append(b.ToString("x2"));
|
||||
}
|
||||
return stringBuilder.ToString().ToUpper();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字节码长度转可读字符串 00000000 bytes 0.0GB
|
||||
/// </summary>
|
||||
/// <param name="KSize"></param>
|
||||
/// <returns></returns>
|
||||
public static string ByteSizeToString(this long KSize)
|
||||
{
|
||||
if (KSize > 0L)
|
||||
{
|
||||
string[] array = new string[]
|
||||
{
|
||||
"B",
|
||||
"KB",
|
||||
"MB",
|
||||
"GB",
|
||||
"TB"
|
||||
};
|
||||
double num = 0.0;
|
||||
int num2 = array.Length - 1;
|
||||
while (num2 >= 0 && (num = Math.Round((double)KSize / Math.Pow(1024.0, (double)num2), 2)) < 1.0)
|
||||
{
|
||||
num2--;
|
||||
}
|
||||
return string.Format("{0}{1}", num, array[num2]);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将图片的字节码数组转成 base64 字符串
|
||||
/// </summary>
|
||||
/// <param name="img"></param>
|
||||
/// <param name="format"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetImgBase64String(this byte[] img, ImageFormat format)
|
||||
{
|
||||
return string.Format("data:image/{0};base64,{1}", format.ToString(), Convert.ToBase64String(img));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将字符串转换成为大写的MD5
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
private static string GetMD5Code(this string str)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
using (MD5CryptoServiceProvider md5CryptoServiceProvider = new MD5CryptoServiceProvider())
|
||||
{
|
||||
byte[] array = md5CryptoServiceProvider.ComputeHash(Encoding.Default.GetBytes(str));
|
||||
foreach (byte b in array)
|
||||
{
|
||||
stringBuilder.Append(b.ToString("x2"));
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转码成短字符串
|
||||
/// </summary>
|
||||
/// <param name="str">源字符串</param>
|
||||
/// <param name="version">制码版本</param>
|
||||
/// <returns>短码数组</returns>
|
||||
public static string[] EncodeShortString(this string str, ShortStringVersion version)
|
||||
{
|
||||
string text = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
int length = text.Length;
|
||||
string md5Code = str.GetMD5Code();
|
||||
string[] array = new string[4];
|
||||
FieldInfo field = typeof(ShortStringVersion).GetField(version.ToString());
|
||||
MaxLengthAttribute maxLengthAttribute = ((MaxLengthAttribute[])field.GetCustomAttributes(typeof(MaxLengthAttribute), false))[0];
|
||||
int num = 0;
|
||||
while (num < 4 && text.Length > 0)
|
||||
{
|
||||
int i = 1073741823 & Convert.ToInt32("0x" + md5Code.Substring(num * 8, 8), 16);
|
||||
string text2 = string.Empty;
|
||||
int index = 61 & i;
|
||||
while (i > 0)
|
||||
{
|
||||
text2 += text[index];
|
||||
i >>= (int)version;
|
||||
index = (61 & i);
|
||||
}
|
||||
while (text2.Length < maxLengthAttribute.Length)
|
||||
{
|
||||
text2 += text[num];
|
||||
}
|
||||
array[num] = text2;
|
||||
num++;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转码成短字符串
|
||||
/// </summary>
|
||||
/// <param name="str">源字符串</param>
|
||||
/// <returns>短码数组</returns>
|
||||
public static string[] EncodeShortString(this string str)
|
||||
{
|
||||
return str.EncodeShortString(ShortStringVersion.Version_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Face.Services/Extensions/TimeExtensions.cs
Normal file
29
Face.Services/Extensions/TimeExtensions.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System
|
||||
{
|
||||
public static class TimeExtensions
|
||||
{
|
||||
public static DateTime? ToDateTime(this string timeStamp)
|
||||
{
|
||||
long ticks = 0L;
|
||||
if (long.TryParse(timeStamp, out ticks))
|
||||
{
|
||||
DateTime dateTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||||
TimeSpan value = new TimeSpan(ticks);
|
||||
return new DateTime?(dateTime.Add(value));
|
||||
}
|
||||
DateTime now = DateTime.Now;
|
||||
if (DateTime.TryParse(timeStamp, out now))
|
||||
{
|
||||
return new DateTime?(now);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
173
Face.Services/Face.Services.csproj
Normal file
173
Face.Services/Face.Services.csproj
Normal file
@@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{56438F1C-BA3A-4272-964E-C6739AE0B4EC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Face.Services</RootNamespace>
|
||||
<AssemblyName>Face.Services</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.6.9.12\lib\net45\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data.Entity.EF6, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.Entity.6.9.12\lib\net45\MySql.Data.Entity.EF6.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SqlSugar, Version=5.0.8.7, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SqlSugar.5.0.8.7\lib\SqlSugar.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\StackExchange.Redis.1.2.6\lib\net46\StackExchange.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Text.Encodings.Web, Version=4.0.3.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.4.5.1\lib\netstandard2.0\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.4\lib\net45\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.4\lib\net45\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="TencentCloudCommon, Version=3.0.902.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\TencentCloudSDK.Common.3.0.902\lib\net45\TencentCloudCommon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="TencentCloudSms, Version=3.0.902.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\TencentCloudSDK.Sms.3.0.902\lib\net45\TencentCloudSms.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Cache\BaseCacheHelp.cs" />
|
||||
<Compile Include="Cache\CacheHelp.cs" />
|
||||
<Compile Include="DBUtility\CommandInfo.cs" />
|
||||
<Compile Include="DBUtility\Common\DALHelper.cs" />
|
||||
<Compile Include="DBUtility\Common\DbHelperMySQL.cs" />
|
||||
<Compile Include="DBUtility\Common\MysqlHelpers.cs" />
|
||||
<Compile Include="DBUtility\Common\SqlHelper.cs" />
|
||||
<Compile Include="DBUtility\Common\SqlOperationsData.cs" />
|
||||
<Compile Include="DBUtility\Custom\DALHelperCustom.cs" />
|
||||
<Compile Include="DBUtility\Custom\DbHelperMySqlCustom.cs" />
|
||||
<Compile Include="Enums\Accountentity.cs" />
|
||||
<Compile Include="Enums\CacheTimeType.cs" />
|
||||
<Compile Include="Enums\LoginInfoType.cs" />
|
||||
<Compile Include="Enums\OperationLevel.cs" />
|
||||
<Compile Include="Enums\OrderStatus.cs" />
|
||||
<Compile Include="Enums\ShortStringVersion.cs" />
|
||||
<Compile Include="Enums\StationType.cs" />
|
||||
<Compile Include="Extensions\CacheExtensions.cs" />
|
||||
<Compile Include="Extensions\CookieExtensions.cs" />
|
||||
<Compile Include="Extensions\CustomException.cs" />
|
||||
<Compile Include="Extensions\EnumerableExtensions.cs" />
|
||||
<Compile Include="Extensions\LinqExtensions.cs" />
|
||||
<Compile Include="Extensions\ModelExtensions.cs" />
|
||||
<Compile Include="Extensions\SafeInputExtensions.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Extensions\TimeExtensions.cs" />
|
||||
<Compile Include="Manager\Logs.cs" />
|
||||
<Compile Include="Manager\OperatorOperate.cs" />
|
||||
<Compile Include="Manager\Users.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tool\DateTimeDiff.cs" />
|
||||
<Compile Include="Tool\ModelHelper.cs" />
|
||||
<Compile Include="Tool\System\ComputerHelp.cs" />
|
||||
<Compile Include="Tool\System\ConfigHelper.cs" />
|
||||
<Compile Include="Tool\System\EnumHelper.cs" />
|
||||
<Compile Include="Tool\System\IPHelper.cs" />
|
||||
<Compile Include="Tool\RedisHelper.cs" />
|
||||
<Compile Include="Tool\System\StringHelp.cs" />
|
||||
<Compile Include="UDP\DevManageHelp.cs" />
|
||||
<Compile Include="UDP\UDPHelp.cs" />
|
||||
<Compile Include="UserLoginHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Face.Domain.ViewModels\Face.Domain.ViewModels.csproj">
|
||||
<Project>{be790400-c1ee-4d97-b3f1-604f6831e5e7}</Project>
|
||||
<Name>Face.Domain.ViewModels</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Face.Domain\Face.Domain.csproj">
|
||||
<Project>{709aa98f-388f-44dd-b64b-ad44e695c34c}</Project>
|
||||
<Name>Face.Domain</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Face.Log4Net\Face.Log4Net.csproj">
|
||||
<Project>{5500f9dd-89d9-40f3-b62f-90c6b633d55a}</Project>
|
||||
<Name>Face.Log4Net</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
10
Face.Services/Face.Services.csproj.vspscc
Normal file
10
Face.Services/Face.Services.csproj.vspscc
Normal file
@@ -0,0 +1,10 @@
|
||||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{56438F1C-BA3A-4272-964E-C6739AE0B4EC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Face.Services</RootNamespace>
|
||||
<AssemblyName>Face.Services</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.6.9.12\lib\net45\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data.Entity.EF6, Version=6.9.12.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MySql.Data.Entity.6.9.12\lib\net45\MySql.Data.Entity.EF6.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\StackExchange.Redis.1.2.6\lib\net46\StackExchange.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Mvc">
|
||||
<HintPath>..\..\..\AUTS-DATA\packages\Microsoft.AspNet.Mvc.5.2.4\lib\net45\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Cache\BaseCacheHelp.cs" />
|
||||
<Compile Include="Cache\CacheHelp.cs" />
|
||||
<Compile Include="DBUtility\CommandInfo.cs" />
|
||||
<Compile Include="DBUtility\Common\DALHelper.cs" />
|
||||
<Compile Include="DBUtility\Common\DbHelperMySQL.cs" />
|
||||
<Compile Include="DBUtility\Common\SqlHelper.cs" />
|
||||
<Compile Include="DBUtility\Common\SqlOperationsData.cs" />
|
||||
<Compile Include="DBUtility\Custom\DALHelperCustom.cs" />
|
||||
<Compile Include="DBUtility\Custom\DbHelperMySqlCustom.cs" />
|
||||
<Compile Include="Enums\Accountentity.cs" />
|
||||
<Compile Include="Enums\CacheTimeType.cs" />
|
||||
<Compile Include="Enums\LoginInfoType.cs" />
|
||||
<Compile Include="Enums\OperationLevel.cs" />
|
||||
<Compile Include="Enums\OrderStatus.cs" />
|
||||
<Compile Include="Enums\ShortStringVersion.cs" />
|
||||
<Compile Include="Enums\StationType.cs" />
|
||||
<Compile Include="Extensions\CacheExtensions.cs" />
|
||||
<Compile Include="Extensions\CookieExtensions.cs" />
|
||||
<Compile Include="Extensions\CustomException.cs" />
|
||||
<Compile Include="Extensions\EnumerableExtensions.cs" />
|
||||
<Compile Include="Extensions\LinqExtensions.cs" />
|
||||
<Compile Include="Extensions\ModelExtensions.cs" />
|
||||
<Compile Include="Extensions\SafeInputExtensions.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Extensions\TimeExtensions.cs" />
|
||||
<Compile Include="Manager\Logs.cs" />
|
||||
<Compile Include="Manager\OperatorOperate.cs" />
|
||||
<Compile Include="Manager\Users.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Tool\DateTimeDiff.cs" />
|
||||
<Compile Include="Tool\ModelHelper.cs" />
|
||||
<Compile Include="Tool\System\ComputerHelp.cs" />
|
||||
<Compile Include="Tool\System\ConfigHelper.cs" />
|
||||
<Compile Include="Tool\System\EnumHelper.cs" />
|
||||
<Compile Include="Tool\System\IPHelper.cs" />
|
||||
<Compile Include="Tool\RedisHelper.cs" />
|
||||
<Compile Include="Tool\System\StringHelp.cs" />
|
||||
<Compile Include="UDP\DevManageHelp.cs" />
|
||||
<Compile Include="UDP\UDPHelp.cs" />
|
||||
<Compile Include="UserLoginHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Face.Domain.ViewModels\Face.Domain.ViewModels.csproj">
|
||||
<Project>{be790400-c1ee-4d97-b3f1-604f6831e5e7}</Project>
|
||||
<Name>Face.Domain.ViewModels</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Face.Domain\Face.Domain.csproj">
|
||||
<Project>{709aa98f-388f-44dd-b64b-ad44e695c34c}</Project>
|
||||
<Name>Face.Domain</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Face.Log4Net\Face.Log4Net.csproj">
|
||||
<Project>{5500f9dd-89d9-40f3-b62f-90c6b633d55a}</Project>
|
||||
<Name>Face.Log4Net</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
347
Face.Services/Manager/Logs.cs
Normal file
347
Face.Services/Manager/Logs.cs
Normal file
@@ -0,0 +1,347 @@
|
||||
using Face.Services.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace Face.Services.Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志类
|
||||
/// </summary>
|
||||
public partial class Logs
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 锁1 路径/App_Data/Log/
|
||||
/// </summary>
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 锁2 路径/App_Data/TimingPlan/
|
||||
/// </summary>
|
||||
private static readonly object _lock1 = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 锁3 路径/App_Data/UDPlog/
|
||||
/// </summary>
|
||||
private static readonly object _lockUdp = new object();
|
||||
|
||||
public static void WriteErrorLog(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = "类型:错误代码\r\n";
|
||||
content += "时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "来源:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "内容:" + ex.Message + "\r\n";
|
||||
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
|
||||
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志\r\n";
|
||||
content += "时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errtxt = "";
|
||||
string exname = ex.GetType().ToString();
|
||||
if (exname == "System.Data.Entity.Validation.DbEntityValidationException")
|
||||
{
|
||||
foreach (var item in ((DbEntityValidationException)ex).EntityValidationErrors)
|
||||
{
|
||||
foreach (var err in item.ValidationErrors)
|
||||
{
|
||||
errtxt += "EntityValidationErrors >>>>>> “" + err.PropertyName + "”字段" + err.ErrorMessage + "\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自页面:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n" + errtxt;
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
//if (BaseConfigs.GetLogInDB == 1)
|
||||
//{
|
||||
//TSysLog log = new TSysLog();
|
||||
//log.Content = content;
|
||||
//log.Type = "系统日志";
|
||||
//log.CreateTime = DateTime.Now;
|
||||
//DataAccess.CreateSysLog().Add(log);
|
||||
//}
|
||||
//if (BaseConfigs.GetLogInFile == 1)
|
||||
//{
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
//}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void WriteTimingPlanLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/TimingPlan/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorTimingPlanLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自作业线程:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n";
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/TimingPlan/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exl)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
LogHelp.WriteExceptionLog(exl);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteTimingUDPLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/UDPLog/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lockUdp)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorTimingUDPLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自作业线程:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n";
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/UDPLog/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
lock (_lockUdp)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exl)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
LogHelp.WriteExceptionLog(exl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LogHelp
|
||||
{
|
||||
/// <summary>
|
||||
/// 写入日志
|
||||
/// </summary>
|
||||
/// <param name="ex">异常对象</param>
|
||||
/// <param name="operationer">操作人</param>
|
||||
/// <param name="actionName">功能站点名称</param>
|
||||
public static void WriteExceptionLog(Exception ex, string operationer = "")
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
Log4Net.ExceptionLogHelper.Log(new Face.Log4Net.ExceptionLogMessage() { exception = ex, Header = "", Url = "线程", Operationer = "线程", IP = "" });
|
||||
}
|
||||
else
|
||||
{
|
||||
Log4Net.ExceptionLogHelper.Log(new Face.Log4Net.ExceptionLogMessage() { exception = ex, Header = HttpContext.Current.Request.Headers.ToString(), Url = HttpContext.Current.Request.Url.ToString(), Operationer = operationer, IP = IPHelper.GetIP() });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入日志
|
||||
/// </summary>
|
||||
/// <param name="ex">异常对象</param>
|
||||
/// <param name="operationer">操作人</param>
|
||||
/// <param name="actionName">功能站点名称</param>
|
||||
public static void WriteExceptionLogAddTxt(Exception ex, string operationer = "", string txt = "")
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
Log4Net.ExceptionLogHelper.Log(new Face.Log4Net.ExceptionLogMessage() { exception = ex, Header = "", Url = "线程", Operationer = "线程", IP = "" + txt });
|
||||
}
|
||||
else
|
||||
{
|
||||
Log4Net.ExceptionLogHelper.Log(new Face.Log4Net.ExceptionLogMessage() { exception = ex, Header = HttpContext.Current.Request.Headers.ToString(), Url = HttpContext.Current.Request.Url.ToString(), Operationer = operationer, IP = IPHelper.GetIP() });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
41
Face.Services/Manager/OperatorOperate.cs
Normal file
41
Face.Services/Manager/OperatorOperate.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Face.Domain.Entities;
|
||||
using Face.Domain.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Manager
|
||||
{
|
||||
public class OperatorOperate
|
||||
{
|
||||
|
||||
//public static ReturnResult<object> OperatorOperates(string Opname, List<UserInfo> opList)
|
||||
//{
|
||||
// ReturnResult<object> result = new ReturnResult<object>();
|
||||
// try
|
||||
// {
|
||||
// var project = opList.SingleOrDefault(x => x.Uid == Opname);
|
||||
// if (project == null)
|
||||
// {
|
||||
// result.Message = "无效";
|
||||
// return result;
|
||||
// }
|
||||
// var OpModel = new UserInfo()
|
||||
// {
|
||||
// //Operatorid = project.Id,
|
||||
// //name = project.Uid,
|
||||
|
||||
// };
|
||||
|
||||
// }
|
||||
// catch (System.Exception)
|
||||
// {
|
||||
|
||||
// throw;
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
}
|
||||
14
Face.Services/Manager/Users.cs
Normal file
14
Face.Services/Manager/Users.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace Face.Services.Manager
|
||||
{
|
||||
class Users
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
36
Face.Services/Properties/AssemblyInfo.cs
Normal file
36
Face.Services/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("Face.Services")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Face.Services")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("56438f1c-ba3a-4272-964e-c6739ae0b4ec")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
306
Face.Services/Tool/DateTimeDiff.cs
Normal file
306
Face.Services/Tool/DateTimeDiff.cs
Normal file
@@ -0,0 +1,306 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Tool
|
||||
{
|
||||
public class DateTimeDiff
|
||||
{
|
||||
public DateTimeDiff()
|
||||
{
|
||||
//
|
||||
// TODO: 在此处添加构造函数逻辑
|
||||
//
|
||||
}
|
||||
/// <summary>
|
||||
/// 把秒转换成分钟
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static int SecondToMinute(int Second)
|
||||
{
|
||||
decimal mm = (decimal)((decimal)Second / (decimal)60);
|
||||
return Convert.ToInt32(Math.Ceiling(mm));
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算两个时间的时间间隔
|
||||
/// </summary>
|
||||
/// <param name="DateTimeOld">较早的日期和时间</param>
|
||||
/// <param name="DateTimeNew">较后的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static string DateDiff(DateTime DateTimeOld, DateTime DateTimeNew)
|
||||
{
|
||||
string dateDiff = "";
|
||||
TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTimeNew.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
int day = ts.Days;
|
||||
int hou = ts.Hours;
|
||||
int minu = ts.Minutes;
|
||||
int sec = ts.Seconds;
|
||||
if (day > 0)
|
||||
{
|
||||
if (day > 30)
|
||||
{
|
||||
if (day > 364)
|
||||
{
|
||||
dateDiff += day / 365 + "年";
|
||||
}
|
||||
else
|
||||
{
|
||||
dateDiff += day / 30 + "个月";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dateDiff += day.ToString() + "天";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hou > 0)
|
||||
{
|
||||
dateDiff += hou.ToString() + "小时";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (minu > 0)
|
||||
{
|
||||
dateDiff += minu.ToString() + "分钟";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sec > 0)
|
||||
{
|
||||
dateDiff += sec.ToString() + "秒";
|
||||
}
|
||||
else
|
||||
{
|
||||
dateDiff += "0秒";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (DateTimeNew.CompareTo(DateTimeOld) > 0)
|
||||
{
|
||||
dateDiff += "前";
|
||||
}
|
||||
else
|
||||
{
|
||||
dateDiff += "后";
|
||||
}
|
||||
return dateDiff;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回两个日期之间的时间间隔(y:年份间隔、M:月份间隔、d:天数间隔、h:小时间隔、m:分钟间隔、s:秒钟间隔、ms:微秒间隔)
|
||||
/// </summary>
|
||||
/// <param name="Date1">开始日期</param>
|
||||
/// <param name="Date2">结束日期</param>
|
||||
/// <param name="Interval">间隔标志</param>
|
||||
/// <returns>返回间隔标志指定的时间间隔</returns>
|
||||
public static int DateDiff(System.DateTime Date1, System.DateTime Date2, string Interval)
|
||||
{
|
||||
double dblYearLen = 365;//年的长度,365天
|
||||
double dblMonthLen = (365 / 12);//每个月平均的天数
|
||||
System.TimeSpan objT;
|
||||
objT = Date2.Subtract(Date1);
|
||||
switch (Interval)
|
||||
{
|
||||
case "y"://返回日期的年份间隔
|
||||
return System.Convert.ToInt32(objT.Days / dblYearLen);
|
||||
case "M"://返回日期的月份间隔
|
||||
return System.Convert.ToInt32(objT.Days / dblMonthLen);
|
||||
case "d"://返回日期的天数间隔
|
||||
return objT.Days;
|
||||
case "h"://返回日期的小时间隔
|
||||
return objT.Hours;
|
||||
case "m"://返回日期的分钟间隔
|
||||
return objT.Minutes;
|
||||
case "s"://返回日期的秒钟间隔
|
||||
return objT.Seconds;
|
||||
case "ms"://返回时间的微秒间隔
|
||||
return objT.Milliseconds;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///判断是否于1分钟之前
|
||||
/// </summary>
|
||||
/// <param name="DateTimeOld">较早的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static bool DateDiff_minu(DateTime DateTimeOld)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
int minu = ts.Minutes;
|
||||
if (minu > 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///判断是否于m分钟之前
|
||||
/// </summary>
|
||||
/// <param name="DateTimeOld">较早的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static bool DateDiff_minu(DateTime DateTimeOld, int m)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
int minu = ts.Minutes;
|
||||
if (minu > m)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static bool DateDiff_1minu(DateTime DateTimeOld)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
int minu = ts.Seconds;
|
||||
if (minu > 10)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 与当前时间比较,重载时间比较函数,只有一个参数
|
||||
/// </summary>
|
||||
/// <param name="DateTimeOld">较早的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static string DateDiff(DateTime DateTimeOld)
|
||||
{
|
||||
return DateDiff(DateTimeOld, DateTime.Now);
|
||||
}
|
||||
/// <summary>
|
||||
/// 日期比较,返回精确的几分几秒
|
||||
/// </summary>
|
||||
/// <param name="DateTime1">较早的日期和时间</param>
|
||||
/// <param name="DateTime2">较迟的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static string DateDiff_full(DateTime DateTime1, DateTime DateTime2)
|
||||
{
|
||||
string dateDiff = null;
|
||||
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "时" + ts.Minutes.ToString() + "分" + ts.Seconds.ToString() + "秒";
|
||||
return dateDiff;
|
||||
}
|
||||
/// <summary>
|
||||
/// 时间比较,返回精确的几秒
|
||||
/// </summary>
|
||||
/// <param name="DateTime1">较早的日期和时间</param>
|
||||
/// <param name="DateTime2">较迟的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static int DateDiff_Sec(DateTime DateTime1, DateTime DateTime2)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
int dateDiff = ts.Days * 86400 + ts.Hours * 3600 + ts.Minutes * 60 + ts.Seconds;
|
||||
return dateDiff;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 日期比较
|
||||
/// </summary>
|
||||
/// <param name="today">当前日期</param>
|
||||
/// <param name="writeDate">输入日期</param>
|
||||
/// <param name="n">比较天数</param>
|
||||
/// <returns>大于天数返回true,小于返回false</returns>
|
||||
public static bool CompareDate(string today, string writeDate, int n)
|
||||
{
|
||||
DateTime Today = Convert.ToDateTime(today);
|
||||
DateTime WriteDate = Convert.ToDateTime(writeDate);
|
||||
WriteDate = WriteDate.AddDays(n);
|
||||
if (Today >= WriteDate)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string FormatProgress(DateTime StartTime, DateTime EndTime)
|
||||
{
|
||||
|
||||
|
||||
if (DateTime.Now > DateTime.Parse(EndTime.ToShortDateString() + " 23:59:59"))
|
||||
return "活动结束";
|
||||
else if (DateTime.Now < DateTime.Parse(StartTime.ToShortDateString() + " 0:0:0"))
|
||||
return "即将开始";
|
||||
else
|
||||
{
|
||||
int totalDay = DateTimeDiff.DateDiff(StartTime, EndTime, "d");
|
||||
int inDay = DateTimeDiff.DateDiff(StartTime, DateTime.Now, "d");
|
||||
if ((float)inDay / (float)totalDay < 0.2f)
|
||||
return "刚刚开始";
|
||||
else if ((float)inDay / (float)totalDay >= 0.2f && (float)inDay / (float)totalDay < 0.4)
|
||||
return "正在进行";
|
||||
else if ((float)inDay / (float)totalDay >= 0.4 && (float)inDay / (float)totalDay < 0.6)
|
||||
return "活动过半";
|
||||
else if ((float)inDay / (float)totalDay > 0.6 && (float)inDay / (float)totalDay <= 0.8)
|
||||
return "进入尾声";
|
||||
else
|
||||
return "即将结束";
|
||||
}
|
||||
}
|
||||
|
||||
// 时间戳转为C#格式时间
|
||||
public static DateTime StampToDateTime(string timeStamp)
|
||||
{
|
||||
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||||
long lTime = long.Parse(timeStamp + "0000000");
|
||||
TimeSpan toNow = new TimeSpan(lTime);
|
||||
|
||||
return dateTimeStart.Add(toNow);
|
||||
}
|
||||
|
||||
// DateTime时间格式转换为Unix时间戳格式
|
||||
public static double DateTimeToStamp(System.DateTime time)
|
||||
{
|
||||
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
|
||||
return (time - startTime).TotalMilliseconds;
|
||||
}
|
||||
/// <summary>
|
||||
///判断是否于多少分钟之前
|
||||
/// </summary>
|
||||
/// <param name="DateTimeOld">较早的日期和时间</param>
|
||||
/// <returns></returns>
|
||||
public static bool allDateDiff_minu(DateTime DateTimeOld, int m)
|
||||
{
|
||||
TimeSpan ts1 = new TimeSpan(DateTimeOld.Ticks);
|
||||
TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
|
||||
TimeSpan ts = ts1.Subtract(ts2).Duration();
|
||||
int minu = ts.Minutes;
|
||||
if (minu > m)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
53
Face.Services/Tool/ModelHelper.cs
Normal file
53
Face.Services/Tool/ModelHelper.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// 实体帮助
|
||||
/// </summary>
|
||||
public static class ModelHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取实体属性名
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetModelPropertyName<T>() where T : class, new()
|
||||
{
|
||||
string nameStr = "";
|
||||
|
||||
foreach (PropertyInfo pi in (new T()).GetType().GetProperties())
|
||||
{
|
||||
//获得属性的名字,后面就可以根据名字判断来进行些自己想要的操作
|
||||
var name = pi.Name;
|
||||
//var value = pi.GetValue(list, null);//用pi.GetValue获得值
|
||||
//var type = value?.GetType() ?? typeof(object);//获得属性的类型
|
||||
|
||||
nameStr += "`" + name + "`,";
|
||||
}
|
||||
return nameStr.Substring(0, nameStr.Length - 1);//nameStr; 去除最后一个逗号
|
||||
}
|
||||
|
||||
public static List<Dictionary<string, object>> TableToRow(DataTable tbl)
|
||||
{
|
||||
List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
|
||||
foreach (DataRow Row in tbl.Rows)//循环行
|
||||
{
|
||||
Dictionary<string, object> row = new Dictionary<string, object>();
|
||||
for (int i = 0; i < Row.ItemArray.Length; i++)
|
||||
{
|
||||
row.Add(tbl.Columns[i].ColumnName, Row[i].ToString());
|
||||
}
|
||||
rows.Add(row);
|
||||
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
1125
Face.Services/Tool/RedisHelper.cs
Normal file
1125
Face.Services/Tool/RedisHelper.cs
Normal file
File diff suppressed because it is too large
Load Diff
17
Face.Services/Tool/System/ComputerHelp.cs
Normal file
17
Face.Services/Tool/System/ComputerHelp.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Tool
|
||||
{
|
||||
public class ComputerHelp
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
162
Face.Services/Tool/System/ConfigHelper.cs
Normal file
162
Face.Services/Tool/System/ConfigHelper.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using Face.Services.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Configuration;
|
||||
|
||||
namespace Face.Services.Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// web.config操作类
|
||||
/// Copyright (C) Maticsoft
|
||||
/// </summary>
|
||||
public sealed class ConfigHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 得到AppSettings中的配置字符串信息
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetConfigString(string key)
|
||||
{
|
||||
string CacheKey = "AppSettings-" + key;
|
||||
object objModel = CacheExtensions.GetCache<object>(CacheKey);
|
||||
if (objModel == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
objModel = ConfigurationManager.AppSettings[key];
|
||||
if (objModel != null)
|
||||
{
|
||||
CacheExtensions.SetCache(CacheKey, objModel, Enums.CacheTimeType.ByHours, 3);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return objModel.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得到AppSettings中的配置Bool信息
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static bool GetConfigBool(string key)
|
||||
{
|
||||
bool result = false;
|
||||
string cfgVal = GetConfigString(key);
|
||||
if (null != cfgVal && string.Empty != cfgVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = bool.Parse(cfgVal);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// Ignore format exceptions.
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 得到AppSettings中的配置Decimal信息
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static decimal GetConfigDecimal(string key)
|
||||
{
|
||||
decimal result = 0;
|
||||
string cfgVal = GetConfigString(key);
|
||||
if (null != cfgVal && string.Empty != cfgVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = decimal.Parse(cfgVal);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// Ignore format exceptions.
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 得到AppSettings中的配置int信息
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetConfigInt(string key)
|
||||
{
|
||||
int result = 0;
|
||||
string cfgVal = GetConfigString(key);
|
||||
if (null != cfgVal && string.Empty != cfgVal)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = int.Parse(cfgVal);
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
// Ignore format exceptions.
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改AppSettings中的配置信息
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static void UpdatetConfig(string key, string value)
|
||||
{
|
||||
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
|
||||
AppSettingsSection objAppSettings = (AppSettingsSection)objConfig.GetSection("appSettings");
|
||||
if (objAppSettings != null)
|
||||
{
|
||||
objAppSettings.Settings[key].Value = value;
|
||||
objConfig.Save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载配置文件 app升级配置文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<String, String> loadCfg()
|
||||
{
|
||||
string cfgPath = Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ApplicationBase)
|
||||
+ Path.DirectorySeparatorChar + "appset" + Path.DirectorySeparatorChar + "appconfig.properties";
|
||||
Dictionary<String, String> cfg = new Dictionary<string, string>();
|
||||
using (StreamReader sr = new StreamReader(cfgPath))
|
||||
{
|
||||
while (sr.Peek() >= 0)
|
||||
{
|
||||
string line = sr.ReadLine();
|
||||
if (line.StartsWith("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int startInd = line.IndexOf("=");
|
||||
string key = line.Substring(0, startInd);
|
||||
string val = line.Substring(startInd + 1, line.Length - (startInd + 1));
|
||||
if (!cfg.ContainsKey(key) && !string.IsNullOrEmpty(val))
|
||||
{
|
||||
cfg.Add(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Face.Services/Tool/System/EnumHelper.cs
Normal file
43
Face.Services/Tool/System/EnumHelper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Face.Services.Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// 枚举帮助类
|
||||
/// </summary>
|
||||
public static class EnumHelper
|
||||
{
|
||||
|
||||
///// <summary>
|
||||
///// 获取枚举的Short类型
|
||||
///// </summary>
|
||||
///// <param name="value"></param>
|
||||
///// <returns></returns>
|
||||
//public static short GetShortValue(Enum value)
|
||||
//{
|
||||
// return short.Parse(((int)Enum.Parse(value.GetType(), value.ToString())).ToString());
|
||||
//}
|
||||
|
||||
///// <summary>
|
||||
///// 得到枚举中文备注
|
||||
///// </summary>
|
||||
///// <param name="enumValue"></param>
|
||||
///// <returns></returns>
|
||||
//public static string GetEnumDesc(Enum enumValue)
|
||||
//{
|
||||
// string value = enumValue.ToString();
|
||||
// FieldInfo field = enumValue.GetType().GetField(value);
|
||||
// object[] objs = field.GetCustomAttributes(typeof(DescriptionAttribute), false); //获取描述属性
|
||||
// if (objs.Length == 0) //当描述属性没有时,直接返回名称
|
||||
// return value;
|
||||
// DescriptionAttribute descriptionAttribute = (DescriptionAttribute)objs[0];
|
||||
// return descriptionAttribute.Description;
|
||||
//}
|
||||
}
|
||||
}
|
||||
94
Face.Services/Tool/System/IPHelper.cs
Normal file
94
Face.Services/Tool/System/IPHelper.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Face.Services.Tool
|
||||
{
|
||||
public class IPHelper
|
||||
{
|
||||
public static string GetIP()
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
throw new Exception("HttpContext.Current为null");
|
||||
}
|
||||
|
||||
string ip = string.Empty;
|
||||
if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_VIA"]))
|
||||
ip = Convert.ToString(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
ip = Convert.ToString(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
|
||||
if (IPAddress.TryParse(ip, out var ips))
|
||||
{
|
||||
byte[] ipBytes = ips.GetAddressBytes();
|
||||
if (ipBytes[0] == 10) return ip;
|
||||
if (ipBytes[0] == 172 && ipBytes[1] >= 16 && ipBytes[1] <= 31) return ip;
|
||||
if (ipBytes[0] == 192 && ipBytes[1] == 168) return ip;
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/// <summary>获取客户端的IP,可以取到代理后的IP
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetClientIp()
|
||||
{
|
||||
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
//可能有代理
|
||||
if (result.IndexOf(".", StringComparison.Ordinal) == -1)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
if (result.IndexOf(",", StringComparison.Ordinal) != -1)
|
||||
{
|
||||
//有“,”,估计多个代理。取第一个不是内网的IP。
|
||||
result = result.Replace(" ", "").Replace("'", "");
|
||||
string[] temparyip = result.Split(",;".ToCharArray());
|
||||
foreach (string t in temparyip)
|
||||
{
|
||||
if (IsIpAddress(t)
|
||||
&& t.Substring(0, 3) != "10."
|
||||
&& t.Substring(0, 7) != "192.168"
|
||||
&& t.Substring(0, 7) != "172.16.")
|
||||
{
|
||||
return t; //找到不是内网的地址
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (IsIpAddress(result)) //代理即是IP格式
|
||||
return result;
|
||||
else
|
||||
result = null; //代理中的内容 非IP,取IP
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(result))
|
||||
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
|
||||
if (string.IsNullOrEmpty(result))
|
||||
result = HttpContext.Current.Request.UserHostAddress;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>判断是否是IP地址格式 0.0.0.0
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="str">待判断的IP地址</param>
|
||||
/// <returns>true or false</returns>
|
||||
public static bool IsIpAddress(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str) || str.Length < 7 || str.Length > 15) return false;
|
||||
|
||||
const string regformat = @"^d{1,3}[.]d{1,3}[.]d{1,3}[.]d{1,3}$";
|
||||
|
||||
Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
|
||||
return regex.IsMatch(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
1194
Face.Services/Tool/System/StringHelp.cs
Normal file
1194
Face.Services/Tool/System/StringHelp.cs
Normal file
File diff suppressed because it is too large
Load Diff
15
Face.Services/UDP/DevManageHelp.cs
Normal file
15
Face.Services/UDP/DevManageHelp.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Face.Domain.Entities;
|
||||
using Face.Services.Cache;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Face.Services
|
||||
{
|
||||
public partial class DevManageHelp
|
||||
{
|
||||
public static void UdpDevServiceHandle(int sID)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
296
Face.Services/UDP/UDPHelp.cs
Normal file
296
Face.Services/UDP/UDPHelp.cs
Normal file
@@ -0,0 +1,296 @@
|
||||
using Face.Services;
|
||||
using Face.Services.Manager;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace FaceMachines.Services
|
||||
{
|
||||
public partial class UDPHelp
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 用于UDP发送的网络服务类Socket
|
||||
/// </summary>
|
||||
static Socket socketRecv = null;
|
||||
|
||||
/// <summary>
|
||||
/// 本机IP端口信息
|
||||
/// </summary>
|
||||
static IPEndPoint localIpep = null;
|
||||
|
||||
/// <summary>
|
||||
/// 开关:在监听UDP报文阶段为true,否则为false
|
||||
/// </summary>
|
||||
static bool IsUdpcRecvStart = false;
|
||||
|
||||
/// <summary>
|
||||
/// 线程:不断监听UDP报文
|
||||
/// </summary>
|
||||
static Thread thrRecv;
|
||||
|
||||
/// <summary>
|
||||
/// 开启监听
|
||||
/// </summary>
|
||||
public static void StartReceive()
|
||||
{
|
||||
//if (!IsUdpcRecvStart) // 未监听的情况,开始监听
|
||||
//{
|
||||
//localIpep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7254); // 本机IP和监听端口号
|
||||
localIpep = new IPEndPoint(IPAddress.Any, 5920); // 本机IP和监听端口号
|
||||
|
||||
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
|
||||
//IPEndPoint[] ipEndPoints = ipProperties.GetActiveUdpListeners();
|
||||
var portCount = ipProperties.GetActiveUdpListeners().Where(x => x.Port == 5920).Count();
|
||||
|
||||
if (portCount == 0)
|
||||
{
|
||||
socketRecv = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
socketRecv.Bind(localIpep);
|
||||
|
||||
thrRecv = new Thread(new ThreadStart(ReceiveMessage)); //开辟一个新线程
|
||||
|
||||
if (thrRecv.ThreadState != ThreadState.Running)
|
||||
{
|
||||
thrRecv.Start();
|
||||
IsUdpcRecvStart = true;
|
||||
Logs.WriteTimingUDPLog("UDP监听器已成功启动,IP:" + localIpep);
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭监听
|
||||
/// </summary>
|
||||
public static void StopReceive()
|
||||
{
|
||||
if (IsUdpcRecvStart)
|
||||
{
|
||||
thrRecv.Abort(); // 必须先关闭这个线程,否则会异常
|
||||
//udpcRecv.Close();
|
||||
socketRecv.Close();
|
||||
IsUdpcRecvStart = false;
|
||||
Logs.WriteTimingUDPLog("UDP监听器已成功关闭");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接收数据
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
private static void ReceiveMessage()
|
||||
{
|
||||
while (IsUdpcRecvStart)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 接收
|
||||
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
|
||||
EndPoint Remote = (EndPoint)sender;
|
||||
byte[] data = new byte[256];
|
||||
int len = socketRecv.ReceiveFrom(data, ref Remote);
|
||||
|
||||
string result = BitConverter.ToString(data, 0, len);
|
||||
|
||||
UdpMsgHandle(data, len, Remote);
|
||||
|
||||
Logs.WriteTimingUDPLog("UDP接收数据:{来源IP:" + Remote + " ,数据包:" + result + " }");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteErrorTimingUDPLog("UDP接收错误:", ex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送信息
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
private static void SendMessage(object obj)
|
||||
{
|
||||
try
|
||||
{
|
||||
string message = (string)obj;
|
||||
byte[] sendbytes = Encoding.Unicode.GetBytes(message);
|
||||
IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8819); // 发送到的IP地址和端口号
|
||||
socketRecv.SendTo(sendbytes, sendbytes.Length, SocketFlags.None, remoteIpep);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteErrorTimingUDPLog("UDP发送", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理UDP信息
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="len"></param>
|
||||
/// <param name="Remote"></param>
|
||||
public static void UdpMsgHandle(byte[] data, int len, EndPoint Remote)
|
||||
{
|
||||
var keyNum = Convert.ToInt32(data[2]);//数据包长度
|
||||
|
||||
var checkValue = data[3];//校验位
|
||||
Array.Clear(data, 3, 1);//data 从起始位置4, 删除1个位置
|
||||
var packetSum = AddMsgByte(data);//数据包累加
|
||||
var checkSum = (byte)((255 - packetSum) & 0xFF);
|
||||
|
||||
if ((len - keyNum) == 5 && checkSum == checkValue)
|
||||
{
|
||||
var sID = BitConverter.ToInt32(data, 5);
|
||||
DevManageHelp.UdpDevServiceHandle(sID);
|
||||
|
||||
IPEndPoint endpoint = Remote as IPEndPoint;
|
||||
|
||||
var ipByte = endpoint.Address.GetAddressBytes();
|
||||
|
||||
var retMsg = new byte[256];
|
||||
Buffer.BlockCopy(data, 0, retMsg, 0, 3);
|
||||
retMsg[4] = Convert.ToByte(data[4] + 0xA0);
|
||||
|
||||
Buffer.BlockCopy(ipByte, 0, retMsg, 5, ipByte.Length);
|
||||
|
||||
var num = AddMsgByte(retMsg);
|
||||
retMsg[3] = (byte)((255 - num) & 0xFF);
|
||||
socketRecv.SendTo(retMsg, len, SocketFlags.None, Remote);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 累加十六进制数据
|
||||
/// </summary>
|
||||
/// <param name="retMsg"></param>
|
||||
/// <returns></returns>
|
||||
public static int AddMsgByte(byte[] retMsg)
|
||||
{
|
||||
//var len = retMsg.Length;
|
||||
var num = 0;
|
||||
for (var i = 0; i < retMsg.Length; i++)
|
||||
{
|
||||
num += retMsg[i];
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public partial class UDPHelp_New
|
||||
{
|
||||
/// <summary>
|
||||
/// 累加十六进制数据
|
||||
/// </summary>
|
||||
/// <param name="retMsg"></param>
|
||||
/// <returns></returns>
|
||||
public static int AddMsgByte(byte[] retMsg)
|
||||
{
|
||||
//var len = retMsg.Length;
|
||||
var num = 0;
|
||||
for (var i = 0; i < retMsg.Length; i++)
|
||||
{
|
||||
num += retMsg[i];
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
public static void CreatSocket()
|
||||
{
|
||||
try
|
||||
{
|
||||
int port = 5930;
|
||||
string host = "127.0.0.1";
|
||||
|
||||
/**/
|
||||
///创建终结点(EndPoint)
|
||||
IPAddress ip = IPAddress.Parse(host); //把ip地址字符串转换为IPAddress类型的实例
|
||||
IPEndPoint ipe = new IPEndPoint(ip, port); //用指定的端口和ip初始化IPEndPoint类的新实例
|
||||
|
||||
/**/
|
||||
///创建终结点(EndPoint)
|
||||
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
|
||||
foreach (IPAddress address in Dns.GetHostEntry(host).AddressList)
|
||||
{
|
||||
if (address.AddressFamily.ToString() == "InterNetwork")
|
||||
{
|
||||
IPAddress hostIP = address;
|
||||
IPEndPoint ipe2 = new IPEndPoint(address, 5930);
|
||||
socket.Bind(ipe2); //绑定EndPoint对像
|
||||
//socket.Listen(0); //开始监听
|
||||
|
||||
//接受到client连接,为此连接建立新的socket,并接受信息
|
||||
while (true) //定义循环,以便可以简历N次连接
|
||||
{
|
||||
Socket temp = socket.Accept(); //为新建连接创建新的socket
|
||||
|
||||
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
|
||||
EndPoint Remote = (EndPoint)sender;
|
||||
|
||||
byte[] recvBytes = new byte[256];
|
||||
int bytes = temp.ReceiveFrom(recvBytes, ref Remote); //从客户端接受信息
|
||||
|
||||
var sID = BitConverter.ToInt32(recvBytes, 5);
|
||||
DevManageHelp.UdpDevServiceHandle(sID);
|
||||
|
||||
string recvStr = BitConverter.ToString(recvBytes, 0, bytes);
|
||||
|
||||
var retMsg = UdpMsgHandle_New(recvBytes, bytes, Remote);
|
||||
temp.Send(retMsg, bytes, 0);//返回信息给客户端
|
||||
|
||||
if (temp != null)
|
||||
temp.Close();
|
||||
|
||||
Logs.WriteTimingUDPLog("UDP接收-IP:" + Remote + ",数据包:" + recvStr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteErrorTimingUDPLog("UDP监听器开启错误:", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] UdpMsgHandle_New(byte[] data, int len, EndPoint Remote)
|
||||
{
|
||||
var retMsg = new byte[256];
|
||||
var keyNum = Convert.ToInt32(data[2]);
|
||||
if ((len - keyNum) == 5)
|
||||
{
|
||||
IPEndPoint endpoint = Remote as IPEndPoint;
|
||||
//IPAddress ip = endpoint.Address;
|
||||
|
||||
var ipByte = endpoint.Address.GetAddressBytes();
|
||||
//var ipByte = new byte[] { 183, 12, 223, 210 };
|
||||
|
||||
retMsg[0] = data[0];
|
||||
retMsg[1] = data[1];
|
||||
retMsg[2] = data[2];
|
||||
retMsg[4] = Convert.ToByte(data[4].ToInt() + 160);
|
||||
|
||||
retMsg[5] = ipByte[0];
|
||||
retMsg[6] = ipByte[1];
|
||||
retMsg[7] = ipByte[2];
|
||||
retMsg[8] = ipByte[3];
|
||||
|
||||
var num = AddMsgByte(retMsg);
|
||||
retMsg[3] = (byte)((255 - num) & 0xFF);
|
||||
}
|
||||
return retMsg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
146
Face.Services/UserLoginHelper.cs
Normal file
146
Face.Services/UserLoginHelper.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using Face.Domain.Entities;
|
||||
using Face.Services.DBUtility.Common;
|
||||
using Face.Services.Enums;
|
||||
using Face.Services.Extensions;
|
||||
using Face.Services.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
|
||||
namespace Face.Services
|
||||
{
|
||||
public static class UserLoginHelper
|
||||
{
|
||||
//登录缓存键前缀
|
||||
/// <summary>
|
||||
/// 登录缓存键前缀
|
||||
/// </summary>
|
||||
//static string CacheUserName { get { return typeof(TBL_UTS_Manage_UserList).Name + "_"; } }
|
||||
static string CookieName_User = (ConfigHelper.GetConfigString("DBName") + "_User").ToMD5();
|
||||
static string CookieName_Token = (ConfigHelper.GetConfigString("DBName") + "_Token").ToMD5();
|
||||
|
||||
//public static Accountentity GetUserLoginBy(string keyword)
|
||||
//{
|
||||
|
||||
// //string pwd = password.ToMD5().ToMD5();
|
||||
// using (var db = new FaceEntitiesShow())
|
||||
// {
|
||||
// //var account = db.TBL_UTS_Manage_UserList.SingleOrDefault(a => (a.UserName == keyword.Trim()) && a.Password == password);
|
||||
// //var account = db.Operator.SingleOrDefault(a=>(a.name==keyword.Trim())&&a.pwd==pwd);
|
||||
|
||||
// var account = SqlOperationsData.LoginAccount(keyword);
|
||||
// if (account != null)
|
||||
// {
|
||||
// HttpContext.Current.ViewData[CookieName_User] = account;
|
||||
// CookieExtensions.WriteCookie(CookieName_User, keyword, 60);
|
||||
// return account;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
|
||||
|
||||
//获取当前会员登录对象
|
||||
/// <summary>
|
||||
/// 获取当前会员登录对象
|
||||
/// <para>当没登陆或者登录信息不符时,这里返回 null </para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
//public static Accountentity CurrentUser()
|
||||
//{
|
||||
// //校验用户是否已经登录
|
||||
// var user = HttpContext.Current.ViewData[CookieName_User] as Accountentity;
|
||||
// if (user != null) return user;
|
||||
// else
|
||||
// {
|
||||
// if (HttpContext.Current.Request.Cookies[CookieName_User] != null && HttpContext.Current.Request.Cookies[CookieName_Token] != null)
|
||||
// {
|
||||
// string keyword = HttpContext.Current.Request.Cookies[CookieName_User].Value;
|
||||
// string token = HttpContext.Current.Request.Cookies[CookieName_Token].Value;
|
||||
// string pwd = token.Substring(32);
|
||||
// var db = new FaceEntitiesShow();
|
||||
// var account = SqlOperationsData.LoginAccount(keyword.Trim(), pwd);
|
||||
// if (account != null)
|
||||
// {
|
||||
// return account;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
|
||||
//登出
|
||||
/// <summary>
|
||||
/// 登出
|
||||
/// </summary>
|
||||
//public static void UserLogout()
|
||||
//{
|
||||
// if (CheckUserLogin())
|
||||
// {
|
||||
// //获取会员ID
|
||||
// var id = HttpContext.Current.User.Identity.Name;
|
||||
// FormsAuthentication.SignOut();
|
||||
// RemoveUser(id);
|
||||
// }
|
||||
//}
|
||||
|
||||
////移除指定会员ID的登录缓存
|
||||
///// <summary>
|
||||
///// 移除指定会员ID的登录缓存
|
||||
///// </summary>
|
||||
///// <param name="ID"></param>
|
||||
//public static void RemoveUser(string ID)
|
||||
//{
|
||||
// //MvcCore.Extensions.CacheExtensions.ClearCache(cacheUserName + ID);
|
||||
|
||||
// HttpContext.Current.ViewData.Clear();
|
||||
// HttpCookie hc1 = HttpContext.Current.Request.Cookies[CookieName_User];
|
||||
// hc1.Expires = DateTime.Now.AddDays(-1);
|
||||
// HttpContext.Current.Response.Cookies.Add(hc1);
|
||||
|
||||
// HttpCookie hc2 = HttpContext.Current.Request.Cookies[CookieName_Token];
|
||||
// hc2.Expires = DateTime.Now.AddDays(-1);
|
||||
// HttpContext.Current.Response.Cookies.Add(hc2);
|
||||
//}
|
||||
|
||||
//判断当前访问是否有会员登录
|
||||
/// <summary>
|
||||
/// 判断当前访问是否有会员登录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool CheckUserLogin()
|
||||
{
|
||||
|
||||
if (HttpContext.Current.Request.Cookies[CookieName_User] != null && HttpContext.Current.Request.Cookies[CookieName_Token] != null)
|
||||
{
|
||||
string keyword = HttpContext.Current.Request.Cookies[CookieName_User].Value;
|
||||
string token = HttpContext.Current.Request.Cookies[CookieName_Token].Value;
|
||||
string pwd = token.Substring(32);
|
||||
var account = SqlSugarBase.authoriydb.Queryable<UserInfo>().Single(a => a.Uid == keyword.Trim() && a.Pwd == pwd);
|
||||
if (account != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
////当前在线会员数量
|
||||
///// <summary>
|
||||
///// 当前在线会员数量
|
||||
///// </summary>
|
||||
//public static int UserCount
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return CacheExtensions.GetAllCache().Where(s => s.StartsWith(CacheUserName)).Count();
|
||||
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
17
Face.Services/packages.config
Normal file
17
Face.Services/packages.config
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />
|
||||
<package id="log4net" version="2.0.8" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net47" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.4" targetFramework="net47" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="3.2.4" targetFramework="net47" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net47" />
|
||||
<package id="MySql.Data" version="6.9.12" targetFramework="net461" />
|
||||
<package id="MySql.Data.Entity" version="6.9.12" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="13.0.2" targetFramework="net47" />
|
||||
<package id="SqlSugar" version="5.0.8.7" targetFramework="net461" />
|
||||
<package id="StackExchange.Redis" version="1.2.6" targetFramework="net461" />
|
||||
<package id="System.Text.Encodings.Web" version="4.5.1" targetFramework="net47" />
|
||||
<package id="TencentCloudSDK.Common" version="3.0.902" targetFramework="net47" />
|
||||
<package id="TencentCloudSDK.Sms" version="3.0.902" targetFramework="net47" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user