提交rbac
提交设置右键错位的bug
This commit is contained in:
322
DH.RBAC/Utility/Extension/ExtMethods.cs
Normal file
322
DH.RBAC/Utility/Extension/ExtMethods.cs
Normal file
@ -0,0 +1,322 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DH.RBAC.Utility.Extension
|
||||
{
|
||||
public class ExtMethods
|
||||
{
|
||||
public static List<SqlFuncExternal> GetExpMethods
|
||||
{
|
||||
get
|
||||
{
|
||||
var expMethods = new List<SqlFuncExternal>();
|
||||
//abs
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Abs",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("ABS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("ABS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("abs({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("ABS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("ABS({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//sin
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Sin",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("SIN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("SIN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("sin({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("SIN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("SIN({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//cos
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Cos",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("COS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("COS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("cos({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("COS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("COS({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//asin
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Asin",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("ASIN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("ASIN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("asin({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("ASIN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("ASIN({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//acos
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Acos",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("ACOS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("ACOS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("acos({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("ACOS({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("ACOS({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//tan
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Tan",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("TAN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("TAN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("tan({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("TAN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("TAN({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//atan
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Atan",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("ATAN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("ATAN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("atan({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("ATAN({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("ATAN({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//atan2
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Atan2",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("ATAN2({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("ATAN({0}/{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("atan2({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("ATAN2({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("ATAN2({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//pow
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Pow",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("POW({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("POWER({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("power({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("POWER({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("POWER({0},{1})", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//sqrt
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Sqrt",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("SQRT({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("SQRT({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("sqrt({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("SQRT({0})", expInfo.Args[0].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("SQRT({0})", expInfo.Args[0].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//GetDistance
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "GetDistance",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("((6378.138 * 2 * ASIN(POW(SIN(({0} * PI() / 180 - {2} * PI() / 180) / 2), 2) + COS({0} * PI() / 180) * COS({2} * PI() / 180) * POW(SIN(({1} * PI() / 180 - {3} * PI() / 180) / 2), 2))) * 1000)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName, expInfo.Args[2].MemberName, expInfo.Args[3].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("((6378.138 * 2 * ASIN(POWER(SIN(({0} * PI() / 180 - {2} * PI() / 180) / 2), 2) + COS({0} * PI() / 180) * COS({2} * PI() / 180) * POWER(SIN(({1} * PI() / 180 - {3} * PI() / 180) / 2), 2))) * 1000)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName, expInfo.Args[2].MemberName, expInfo.Args[3].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("((6378.138 * 2 * ASIN(POWER(SIN(({0} * PI() / 180 - {2} * PI() / 180) / 2), 2) + COS({0} * PI() / 180) * COS({2} * PI() / 180) * POWER(SIN(({1} * PI() / 180 - {3} * PI() / 180) / 2), 2))) * 1000)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName, expInfo.Args[2].MemberName, expInfo.Args[3].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("((6378.138 * 2 * ASIN(POWER(SIN(({0} * PI() / 180 - {2} * PI() / 180) / 2), 2) + COS({0} * PI() / 180) * COS({2} * PI() / 180) * POWER(SIN(({1} * PI() / 180 - {3} * PI() / 180) / 2), 2))) * 1000)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName, expInfo.Args[2].MemberName, expInfo.Args[3].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("((6378.138 * 2 * ASIN(POWER(SIN(({0} * PI() / 180 - {2} * PI() / 180) / 2), 2) + COS({0} * PI() / 180) * COS({2} * PI() / 180) * POWER(SIN(({1} * PI() / 180 - {3} * PI() / 180) / 2), 2))) * 1000)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName, expInfo.Args[2].MemberName, expInfo.Args[3].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//Bd09ToGcj02Lat
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Bd09ToGcj02Lat",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("((SQRT( ({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * SIN(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS( ({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0))))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("((SQRT( ({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * SIN(ATAN(({1} - 0.006)/({0} - 0.0065)) - 0.000003 * COS( ({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0))))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("((SQRT( ({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * SIN(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS( ({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0))))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("((SQRT( ({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * SIN(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS( ({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0))))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("((SQRT( ({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * SIN(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS( ({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0))))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//Bd09ToGcj02Lon
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Bd09ToGcj02Lon",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("(SQRT(({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS(({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0)))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("(SQRT(({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN(({1} - 0.006)/({0} - 0.0065)) - 0.000003 * COS(({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0)))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("(SQRT(({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS(({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0)))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("(SQRT(({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS(({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0)))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("(SQRT(({0} - 0.0065) * ({0} - 0.0065) + ({1} - 0.006) * ({1} - 0.006)) - 0.00002 * SIN(({1} - 0.006) * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2(({1} - 0.006), ({0} - 0.0065)) - 0.000003 * COS(({0} - 0.0065) * (3.14159265358979324 * 3000.0 / 180.0)))", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//Gcj02ToBd09Lat
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Gcj02ToBd09Lat",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * SIN( ATAN2({1},{0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.006)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * SIN( ATAN({1}/{0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.006)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * SIN( ATAN2({1},{0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.006)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * SIN( ATAN2({1},{0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.006)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * SIN( ATAN2({1},{0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.006)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
//Gcj02ToBd09Lon
|
||||
expMethods.Add(new SqlFuncExternal()
|
||||
{
|
||||
UniqueMethodName = "Gcj02ToBd09Lon",
|
||||
MethodValue = (expInfo, dbType, expContext) =>
|
||||
{
|
||||
if (dbType == DbType.MySql)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2({1}, {0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.0065)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.SqlServer)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN({1}/{0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.0065)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.PostgreSQL)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2({1}, {0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.0065)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Oracle)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2({1}, {0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.0065)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else if (dbType == DbType.Sqlite)
|
||||
return string.Format("((SQRT({0} * {0} + {1} * {1}) - 0.00002 * SIN({1} * (3.14159265358979324 * 3000.0 / 180.0))) * COS(ATAN2({1}, {0}) - 0.000003 * COS({0} * (3.14159265358979324 * 3000.0 / 180.0)))+0.0065)", expInfo.Args[0].MemberName, expInfo.Args[1].MemberName);
|
||||
else
|
||||
throw new Exception("未实现");
|
||||
}
|
||||
});
|
||||
return expMethods;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
70
DH.RBAC/Utility/Extension/MyEnvironment.cs
Normal file
70
DH.RBAC/Utility/Extension/MyEnvironment.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.RBAC.Utility.Extension
|
||||
{
|
||||
public class MyEnvironment
|
||||
{
|
||||
private static string _currentPath;
|
||||
public static void Init(string currentPath)
|
||||
{
|
||||
_currentPath = currentPath;
|
||||
}
|
||||
|
||||
public static string WebRootPath(string path)
|
||||
{
|
||||
return RootPath("/wwwroot" + path);
|
||||
}
|
||||
|
||||
public static string RootPath(string path)
|
||||
{
|
||||
string basePath = "";
|
||||
#if NETFRAMEWORK
|
||||
basePath = AppDomain.CurrentDomain.BaseDirectory.Replace("/", "\\");
|
||||
if (!basePath.EndsWith("\\"))
|
||||
{
|
||||
basePath += "\\";
|
||||
}
|
||||
path = path.Replace("/", "\\");
|
||||
if (path.StartsWith("\\"))
|
||||
{
|
||||
path = path.Substring(1, path.Length - 1);
|
||||
}
|
||||
return basePath + path;
|
||||
#else
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
basePath = AppDomain.CurrentDomain.BaseDirectory.Replace("/", "\\");
|
||||
if (!basePath.EndsWith("\\"))
|
||||
{
|
||||
basePath += "\\";
|
||||
}
|
||||
path = path.Replace("/", "\\");
|
||||
if (path.StartsWith("\\"))
|
||||
{
|
||||
path = path.Substring(1, path.Length - 1);
|
||||
}
|
||||
return basePath + path;
|
||||
}
|
||||
else
|
||||
{
|
||||
basePath = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/");
|
||||
if (!basePath.EndsWith("/"))
|
||||
{
|
||||
basePath += "/";
|
||||
}
|
||||
path = path.Replace("\\", "/");
|
||||
if (path.StartsWith("/"))
|
||||
{
|
||||
path = path.Substring(1, path.Length - 1);
|
||||
}
|
||||
return basePath + path;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
108
DH.RBAC/Utility/Other/DESHelper.cs
Normal file
108
DH.RBAC/Utility/Other/DESHelper.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public static class DESHelper
|
||||
{
|
||||
#region DES加密解密
|
||||
|
||||
/// <summary>
|
||||
/// 默认密钥。
|
||||
/// </summary>
|
||||
private const string DESENCRYPT_KEY = "hsdjxlzf";
|
||||
|
||||
/// <summary>
|
||||
/// DES加密,使用自定义密钥。
|
||||
/// </summary>
|
||||
/// <param name="text">待加密的明文</param>
|
||||
/// <param name="key">8位字符的密钥字符串</param>
|
||||
/// <returns></returns>
|
||||
public static string DESEncrypt(this string text, string key)
|
||||
{
|
||||
if (key.Length != 8)
|
||||
{
|
||||
key = DESENCRYPT_KEY;
|
||||
}
|
||||
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
||||
byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(text);
|
||||
|
||||
byte[] a = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
MemoryStream ms = new MemoryStream();
|
||||
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
|
||||
|
||||
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
cs.FlushFinalBlock();
|
||||
|
||||
StringBuilder ret = new StringBuilder();
|
||||
foreach (byte b in ms.ToArray())
|
||||
{
|
||||
ret.AppendFormat("{0:X2}", b);//将第一个参数转换为十六进制数,长度为2,不足前面补0
|
||||
}
|
||||
return ret.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DES解密,使用自定义密钥。
|
||||
/// </summary>
|
||||
/// <param name="cyphertext">待解密的秘文</param>
|
||||
/// <param name="key">必须是8位字符的密钥字符串(不能有特殊字符)</param>
|
||||
/// <returns></returns>
|
||||
public static string DESDecrypt(this string cyphertext, string key)
|
||||
{
|
||||
if (key.Length != 8)
|
||||
{
|
||||
key = DESENCRYPT_KEY;
|
||||
}
|
||||
if (string.IsNullOrEmpty(cyphertext))
|
||||
return string.Empty;
|
||||
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
|
||||
|
||||
byte[] inputByteArray = new byte[cyphertext.Length / 2];
|
||||
for (int x = 0; x < cyphertext.Length / 2; x++)
|
||||
{
|
||||
int i = (Convert.ToInt32(cyphertext.Substring(x * 2, 2), 16));
|
||||
inputByteArray[x] = (byte)i;
|
||||
}
|
||||
|
||||
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
|
||||
MemoryStream ms = new MemoryStream();
|
||||
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
|
||||
cs.Write(inputByteArray, 0, inputByteArray.Length);
|
||||
cs.FlushFinalBlock();
|
||||
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
||||
return System.Text.Encoding.GetEncoding("UTF-8").GetString(ms.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DES加密,使用默认密钥。
|
||||
/// </summary>
|
||||
/// <param name="text">待加密的明文</param>
|
||||
/// <returns></returns>
|
||||
public static string DESEncrypt(this string text)
|
||||
{
|
||||
return DESEncrypt(text, DESENCRYPT_KEY);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DES解密,使用默认密钥。
|
||||
/// </summary>
|
||||
/// <param name="cyphertext">待解密的秘文</param>
|
||||
/// <returns></returns>
|
||||
public static string DESDecrypt(this string cyphertext)
|
||||
{
|
||||
return DESDecrypt(cyphertext, DESENCRYPT_KEY);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
40
DH.RBAC/Utility/Other/FormHelper.cs
Normal file
40
DH.RBAC/Utility/Other/FormHelper.cs
Normal file
@ -0,0 +1,40 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public class FormHelper
|
||||
{
|
||||
public static Form subForm;
|
||||
|
||||
/// <summary>
|
||||
/// 显示子Form
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
public static void ShowSubForm(Form form,UserControl userControl)
|
||||
{
|
||||
//关闭之前的
|
||||
try { if (subForm != null) subForm.Close(); } catch { }
|
||||
//打开现在的
|
||||
subForm = form;
|
||||
form.Show(userControl);
|
||||
|
||||
}
|
||||
|
||||
public static void ShowSubForm(Form form)
|
||||
{
|
||||
//关闭之前的
|
||||
try { if (subForm != null) subForm.Close(); } catch { }
|
||||
//打开现在的
|
||||
subForm = form;
|
||||
form.Show();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
131
DH.RBAC/Utility/Other/JsonHelper.cs
Normal file
131
DH.RBAC/Utility/Other/JsonHelper.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public static class JsonHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 对象序列化成JSON字符串。
|
||||
/// </summary>
|
||||
/// <param name="obj">序列化对象</param>
|
||||
/// <param name="ignoreProperties">设置需要忽略的属性</param>
|
||||
/// <returns></returns>
|
||||
public static string ToJson(this object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return string.Empty;
|
||||
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
|
||||
timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
|
||||
return JsonConvert.SerializeObject(obj, timeConverter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// JSON字符串序列化成对象。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">对象类型</typeparam>
|
||||
/// <param name="json">JSON字符串</param>
|
||||
/// <returns></returns>
|
||||
public static T ToObject<T>(this string json)
|
||||
{
|
||||
//var setting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
return json == null ? default(T) : JsonConvert.DeserializeObject<T>(json);//, setting);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// JSON字符串序列化成集合。
|
||||
/// </summary>
|
||||
/// <typeparam name="T">集合类型</typeparam>
|
||||
/// <param name="json">JSON字符串</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> ToList<T>(this string json)
|
||||
{
|
||||
//var setting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };
|
||||
return json == null ? null : JsonConvert.DeserializeObject<List<T>>(json);//, setting);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// JSON字符串序列化成DataTable。
|
||||
/// </summary>
|
||||
/// <param name="json">JSON字符串</param>
|
||||
/// <returns></returns>
|
||||
public static DataTable ToTable(this string json)
|
||||
{
|
||||
return json == null ? null : JsonConvert.DeserializeObject<DataTable>(json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将JSON字符串反序列化成对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseEntity"></param>
|
||||
/// <param name="strJson"></param>
|
||||
/// <returns></returns>
|
||||
public static T Json2Obj<T>(T baseEntity, string strJson)
|
||||
{
|
||||
return JsonConvert.DeserializeAnonymousType(strJson, baseEntity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将对象转换层JSON字符串
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static string Obj2Json<T>(T data)
|
||||
{
|
||||
return JsonConvert.SerializeObject(data);
|
||||
}
|
||||
|
||||
|
||||
public static List<T> JsonToList<T>(string strJson)
|
||||
{
|
||||
T[] list = JsonConvert.DeserializeObject<T[]>(strJson);
|
||||
return list.ToList();
|
||||
}
|
||||
|
||||
public static T Json2Obj<T>(string strJson)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(strJson);
|
||||
}
|
||||
|
||||
public static DataTable ToDataTable(this string json)
|
||||
{
|
||||
return json.ToTable();
|
||||
}
|
||||
|
||||
public static string FormatJson(this string json)
|
||||
{
|
||||
//格式化json字符串
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
TextReader tr = new StringReader(json);
|
||||
JsonTextReader jtr = new JsonTextReader(tr);
|
||||
object obj = serializer.Deserialize(jtr);
|
||||
if (obj != null)
|
||||
{
|
||||
StringWriter textWriter = new StringWriter();
|
||||
JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
|
||||
{
|
||||
Formatting = Formatting.Indented,
|
||||
Indentation = 4,
|
||||
IndentChar = ' '
|
||||
};
|
||||
serializer.Serialize(jsonWriter, obj);
|
||||
return textWriter.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return json;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
117
DH.RBAC/Utility/Other/MD5Helper.cs
Normal file
117
DH.RBAC/Utility/Other/MD5Helper.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public static class MD5Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串MD5加密。
|
||||
/// </summary>
|
||||
/// <param name="strOri">需要加密的字符串</param>
|
||||
/// <returns></returns>
|
||||
public static string md5(this string text)
|
||||
{
|
||||
return md5(text, Encoding.Default);
|
||||
}
|
||||
public static string MD5(this string text)
|
||||
{
|
||||
return MD5(text, Encoding.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// 字符串MD5加密。
|
||||
/// </summary>
|
||||
/// <param name="strOri">需要加密的字符串</param>
|
||||
/// <returns></returns>
|
||||
public static string md5(this string text, Encoding encoder)
|
||||
{
|
||||
// Create a new instance of the MD5CryptoServiceProvider object.
|
||||
System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create();
|
||||
// Convert the input string to a byte array and compute the hash.
|
||||
byte[] data = md5Hasher.ComputeHash(encoder.GetBytes(text));
|
||||
// Create a new Stringbuilder to collect the bytes
|
||||
// and create a string.
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
// Loop through each byte of the hashed data
|
||||
// and format each one as a hexadecimal string.
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
// Return the hexadecimal string.
|
||||
return sBuilder.ToString().ToLower();
|
||||
}
|
||||
public static string MD5(this string text, Encoding encoder)
|
||||
{
|
||||
return md5(text, encoder).ToUpper();
|
||||
}
|
||||
/// <summary>
|
||||
/// 文件流MD5加密。
|
||||
/// </summary>
|
||||
/// <param name="stream">需要加密的文件流</param>
|
||||
/// <returns></returns>
|
||||
public static string md5(this Stream stream)
|
||||
{
|
||||
MD5 md5serv = MD5CryptoServiceProvider.Create();
|
||||
byte[] buffer = md5serv.ComputeHash(stream);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte var in buffer)
|
||||
{
|
||||
sb.Append(var.ToString("x2"));
|
||||
}
|
||||
return sb.ToString().ToLower();
|
||||
}
|
||||
public static string MD5(this Stream stream)
|
||||
{
|
||||
return md5(stream).ToUpper();
|
||||
}
|
||||
|
||||
#region MD5加密
|
||||
/// <summary>
|
||||
/// 字符串MD5加密。
|
||||
/// </summary>
|
||||
/// <param name="strOri">需要加密的字符串</param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt(this string text)
|
||||
{
|
||||
// Create a new instance of the MD5CryptoServiceProvider object.
|
||||
System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create();
|
||||
// Convert the input string to a byte array and compute the hash.
|
||||
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(text));
|
||||
// Create a new Stringbuilder to collect the bytes
|
||||
// and create a string.
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
// Loop through each byte of the hashed data
|
||||
// and format each one as a hexadecimal string.
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
// Return the hexadecimal string.
|
||||
return sBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件流MD5加密。
|
||||
/// </summary>
|
||||
/// <param name="stream">需要加密的文件流</param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt(this Stream stream)
|
||||
{
|
||||
MD5 md5serv = MD5CryptoServiceProvider.Create();
|
||||
byte[] buffer = md5serv.ComputeHash(stream);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte var in buffer)
|
||||
{
|
||||
sb.Append(var.ToString("x2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
45
DH.RBAC/Utility/Other/PanelScrollHelper.cs
Normal file
45
DH.RBAC/Utility/Other/PanelScrollHelper.cs
Normal file
@ -0,0 +1,45 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public class PanelScrollHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化panel
|
||||
/// </summary>
|
||||
/// <param name="panel"></param>
|
||||
public static void InitializePanelScroll(Panel panel)
|
||||
{
|
||||
panel.Click += (obj, arg) => { panel.Select(); };
|
||||
InitializePanelScroll(panel, panel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归初始化panel的内部个容器和控件
|
||||
/// </summary>
|
||||
/// <param name="panel1"></param>
|
||||
/// <param name="panel2"></param>
|
||||
private static void InitializePanelScroll(Control container, Control panelRoot)
|
||||
{
|
||||
foreach (Control control in container.Controls)
|
||||
{
|
||||
if (control is Panel || control is GroupBox || control is SplitContainer || control is TabControl || control is UserControl)
|
||||
{
|
||||
control.Click += (obj, arg) => { panelRoot.Select(); };
|
||||
InitializePanelScroll(control, panelRoot);
|
||||
}
|
||||
else if (control is Label)
|
||||
{
|
||||
control.Click += (obj, arg) => { panelRoot.Select(); };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
113
DH.RBAC/Utility/Other/ScreenUtils.cs
Normal file
113
DH.RBAC/Utility/Other/ScreenUtils.cs
Normal file
@ -0,0 +1,113 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public class ScreenUtils
|
||||
{
|
||||
#region Dll引用
|
||||
[DllImport("User32.dll", EntryPoint = "GetDC")]
|
||||
private extern static IntPtr GetDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("User32.dll", EntryPoint = "ReleaseDC")]
|
||||
private extern static int ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
public static extern int GetSystemMetrics(int hWnd);
|
||||
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
private static extern IntPtr MonitorFromPoint([In] System.Drawing.Point pt, [In] uint dwFlags);
|
||||
|
||||
[DllImport("Shcore.dll")]
|
||||
private static extern IntPtr GetDpiForMonitor([In] IntPtr hmonitor, [In] DpiType dpiType, [Out] out uint dpiX, [Out] out uint dpiY);
|
||||
#endregion
|
||||
|
||||
const int DESKTOPVERTRES = 117;
|
||||
const int DESKTOPHORZRES = 118;
|
||||
|
||||
const int SM_CXSCREEN = 0;
|
||||
const int SM_CYSCREEN = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 获取DPI缩放比例
|
||||
/// </summary>
|
||||
/// <param name="dpiscalex"></param>
|
||||
/// <param name="dpiscaley"></param>
|
||||
public static void GetDPIScale(ref float dpiscalex, ref float dpiscaley)
|
||||
{
|
||||
int x = GetSystemMetrics(SM_CXSCREEN);
|
||||
int y = GetSystemMetrics(SM_CYSCREEN);
|
||||
IntPtr hdc = GetDC(IntPtr.Zero);
|
||||
int w = GetDeviceCaps(hdc, DESKTOPHORZRES);
|
||||
int h = GetDeviceCaps(hdc, DESKTOPVERTRES);
|
||||
ReleaseDC(IntPtr.Zero, hdc);
|
||||
dpiscalex = (float)w / x;
|
||||
dpiscaley = (float)h / y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取分辨率
|
||||
/// </summary>
|
||||
/// <param name="width">宽</param>
|
||||
/// <param name="height">高</param>
|
||||
private static void GetResolving(ref int width, ref int height)
|
||||
{
|
||||
IntPtr hdc = GetDC(IntPtr.Zero);
|
||||
width = GetDeviceCaps(hdc, DESKTOPHORZRES);
|
||||
height = GetDeviceCaps(hdc, DESKTOPVERTRES);
|
||||
ReleaseDC(IntPtr.Zero, hdc);
|
||||
}
|
||||
|
||||
public static int ScreenCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return Screen.AllScreens.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public static ScreenSize GetScreenSize(int index)
|
||||
{
|
||||
if (index > (ScreenCount - 1))
|
||||
throw new Exception("索引异常");
|
||||
Screen screen = Screen.AllScreens[index];
|
||||
uint width = 0;
|
||||
uint height = 0;
|
||||
GetDpi(screen, DpiType.Effective, out width, out height);
|
||||
double scale = width / 96.0;
|
||||
return new ScreenSize { Left = (int)(screen.Bounds.X / scale), Top = screen.Bounds.Y, Width = (int)(screen.Bounds.Width / scale), Height = (int)(screen.Bounds.Height / scale), Scale = scale };
|
||||
}
|
||||
|
||||
public static void GetDpi(Screen screen, DpiType dpiType, out uint dpiX, out uint dpiY)
|
||||
{
|
||||
var pnt = new System.Drawing.Point(screen.Bounds.Left + 800, screen.Bounds.Top + 600);
|
||||
var mon = MonitorFromPoint(pnt, 2);
|
||||
GetDpiForMonitor(mon, dpiType, out dpiX, out dpiY);
|
||||
}
|
||||
|
||||
}
|
||||
public enum DpiType
|
||||
{
|
||||
Effective = 0,
|
||||
Angular = 1,
|
||||
Raw = 2,
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class ScreenSize
|
||||
{
|
||||
public int Left { get; set; }
|
||||
public int Top { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public double Scale { get; set; }
|
||||
}
|
||||
}
|
||||
#endif
|
203
DH.RBAC/Utility/Other/SnowFlakeHelper.cs
Normal file
203
DH.RBAC/Utility/Other/SnowFlakeHelper.cs
Normal file
@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public class SnowFlakeHelper
|
||||
{
|
||||
|
||||
private static readonly object _obj = new object();
|
||||
private static SnowFlakeHelper Instance;
|
||||
private SnowFlakeHelper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取雪花帮助类对象
|
||||
/// </summary>
|
||||
/// <param name="datacenterId">数据中心ID</param>
|
||||
/// <param name="workerId">工作机器Id</param>
|
||||
/// <returns></returns>
|
||||
public static SnowFlakeHelper GetSnowInstance(long datacenterId = 1, long workerId = 1)
|
||||
{
|
||||
//双if 加锁
|
||||
if (Instance == null)
|
||||
{
|
||||
lock (_obj)
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = new SnowFlakeHelper(datacenterId, workerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Instance;
|
||||
}
|
||||
|
||||
// 开始时间截((new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc)-Jan1st1970).TotalMilliseconds)
|
||||
private const long twepoch = 1577836800000L;
|
||||
|
||||
// 机器id所占的位数
|
||||
private const int workerIdBits = 5;
|
||||
|
||||
// 数据标识id所占的位数
|
||||
private const int datacenterIdBits = 5;
|
||||
|
||||
// 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
|
||||
private const long maxWorkerId = -1L ^ (-1L << workerIdBits);
|
||||
|
||||
// 支持的最大数据标识id,结果是31
|
||||
private const long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
|
||||
|
||||
// 序列在id中占的位数
|
||||
private const int sequenceBits = 12;
|
||||
|
||||
// 数据标识id向左移17位(12+5)
|
||||
private const int datacenterIdShift = sequenceBits + workerIdBits;
|
||||
|
||||
// 机器ID向左移12位
|
||||
private const int workerIdShift = sequenceBits;
|
||||
|
||||
|
||||
// 时间截向左移22位(5+5+12)
|
||||
private const int timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
|
||||
|
||||
// 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095)
|
||||
private const long sequenceMask = -1L ^ (-1L << sequenceBits);
|
||||
|
||||
// 数据中心ID(0~31)
|
||||
public long datacenterId { get; private set; }
|
||||
|
||||
// 工作机器ID(0~31)
|
||||
public long workerId { get; private set; }
|
||||
|
||||
// 毫秒内序列(0~4095)
|
||||
public long sequence { get; private set; }
|
||||
|
||||
// 上次生成ID的时间截
|
||||
public long lastTimestamp { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 雪花ID
|
||||
/// </summary>
|
||||
/// <param name="datacenterId">数据中心ID</param>
|
||||
/// <param name="workerId">工作机器ID</param>
|
||||
private SnowFlakeHelper(long datacenterId, long workerId)
|
||||
{
|
||||
if (datacenterId > maxDatacenterId || datacenterId < 0)
|
||||
{
|
||||
throw new Exception(string.Format("datacenter Id can't be greater than {0} or less than 0", maxDatacenterId));
|
||||
}
|
||||
if (workerId > maxWorkerId || workerId < 0)
|
||||
{
|
||||
throw new Exception(string.Format("worker Id can't be greater than {0} or less than 0", maxWorkerId));
|
||||
}
|
||||
this.workerId = workerId;
|
||||
this.datacenterId = datacenterId;
|
||||
this.sequence = 0L;
|
||||
this.lastTimestamp = -1L;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获得下一个ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public long NextId()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
long timestamp = GetCurrentTimestamp();
|
||||
if (timestamp > lastTimestamp) //时间戳改变,毫秒内序列重置
|
||||
{
|
||||
sequence = 0L;
|
||||
}
|
||||
else if (timestamp == lastTimestamp) //如果是同一时间生成的,则进行毫秒内序列
|
||||
{
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
if (sequence == 0) //毫秒内序列溢出
|
||||
{
|
||||
timestamp = GetNextTimestamp(lastTimestamp); //阻塞到下一个毫秒,获得新的时间戳
|
||||
}
|
||||
}
|
||||
else //当前时间小于上一次ID生成的时间戳,证明系统时钟被回拨,此时需要做回拨处理
|
||||
{
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
if (sequence > 0)
|
||||
{
|
||||
timestamp = lastTimestamp; //停留在最后一次时间戳上,等待系统时间追上后即完全度过了时钟回拨问题。
|
||||
}
|
||||
else //毫秒内序列溢出
|
||||
{
|
||||
timestamp = lastTimestamp + 1; //直接进位到下一个毫秒
|
||||
}
|
||||
//throw new Exception(string.Format("Clock moved backwards. Refusing to generate id for {0} milliseconds", lastTimestamp - timestamp));
|
||||
}
|
||||
|
||||
lastTimestamp = timestamp; //上次生成ID的时间截
|
||||
|
||||
//移位并通过或运算拼到一起组成64位的ID
|
||||
var id = ((timestamp - twepoch) << timestampLeftShift)
|
||||
| (datacenterId << datacenterIdShift)
|
||||
| (workerId << workerIdShift)
|
||||
| sequence;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析雪花ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string AnalyzeId(long Id)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
var timestamp = (Id >> timestampLeftShift);
|
||||
var time = Jan1st1970.AddMilliseconds(timestamp + twepoch);
|
||||
sb.Append(time.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss:fff"));
|
||||
|
||||
var datacenterId = (Id ^ (timestamp << timestampLeftShift)) >> datacenterIdShift;
|
||||
sb.Append("_" + datacenterId);
|
||||
|
||||
var workerId = (Id ^ ((timestamp << timestampLeftShift) | (datacenterId << datacenterIdShift))) >> workerIdShift;
|
||||
sb.Append("_" + workerId);
|
||||
|
||||
var sequence = Id & sequenceMask;
|
||||
sb.Append("_" + sequence);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 阻塞到下一个毫秒,直到获得新的时间戳
|
||||
/// </summary>
|
||||
/// <param name="lastTimestamp">上次生成ID的时间截</param>
|
||||
/// <returns>当前时间戳</returns>
|
||||
private static long GetNextTimestamp(long lastTimestamp)
|
||||
{
|
||||
long timestamp = GetCurrentTimestamp();
|
||||
while (timestamp <= lastTimestamp)
|
||||
{
|
||||
timestamp = GetCurrentTimestamp();
|
||||
}
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前时间戳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static long GetCurrentTimestamp()
|
||||
{
|
||||
return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
|
||||
}
|
||||
|
||||
private static readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
}
|
||||
}
|
316
DH.RBAC/Utility/Other/StringHelper.cs
Normal file
316
DH.RBAC/Utility/Other/StringHelper.cs
Normal file
@ -0,0 +1,316 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串操作类
|
||||
/// </summary>
|
||||
public static class StringHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 把字符串按照分隔符转换成 List
|
||||
/// </summary>
|
||||
/// <param name="str">源字符串</param>
|
||||
/// <param name="speater">分隔符</param>
|
||||
/// <param name="toLower">是否转换为小写</param>
|
||||
/// <returns></returns>
|
||||
public static List<string> SplitToList(this string str, char speater = ',', bool toLower = false)
|
||||
{
|
||||
List<string> list = new List<string>();
|
||||
string[] ss = str.Split(speater);
|
||||
foreach (string s in ss)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(s) && s != speater.ToString())
|
||||
{
|
||||
string strVal = s;
|
||||
if (toLower)
|
||||
{
|
||||
strVal = s.ToLower();
|
||||
}
|
||||
list.Add(strVal);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把 List<string> 按照分隔符组装成 string
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="speater"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetStrArray(this List<string> list, string speater = ",")
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (i == list.Count - 1)
|
||||
{
|
||||
sb.Append(list[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(list[i]);
|
||||
sb.Append(speater);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除最后结尾的指定字符后的字符
|
||||
/// </summary>
|
||||
public static string DelLastChar(this string str, string strChar = ",")
|
||||
{
|
||||
return str.Substring(0, str.LastIndexOf(strChar));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 转全角的函数(SBC case)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public static string ToSBC(string input)
|
||||
{
|
||||
//半角转全角:
|
||||
char[] c = input.ToCharArray();
|
||||
for (int i = 0; i < c.Length; i++)
|
||||
{
|
||||
if (c[i] == 32)
|
||||
{
|
||||
c[i] = (char)12288;
|
||||
continue;
|
||||
}
|
||||
if (c[i] < 127)
|
||||
c[i] = (char)(c[i] + 65248);
|
||||
}
|
||||
return new string(c);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转半角的函数(SBC case)
|
||||
/// </summary>
|
||||
/// <param name="input">输入</param>
|
||||
/// <returns></returns>
|
||||
public static string ToDBC(string input)
|
||||
{
|
||||
char[] c = input.ToCharArray();
|
||||
for (int i = 0; i < c.Length; i++)
|
||||
{
|
||||
if (c[i] == 12288)
|
||||
{
|
||||
c[i] = (char)32;
|
||||
continue;
|
||||
}
|
||||
if (c[i] > 65280 && c[i] < 65375)
|
||||
c[i] = (char)(c[i] - 65248);
|
||||
}
|
||||
return new string(c);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取正确的Id,如果不是正整数,返回0
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns>返回正确的整数ID,失败返回0</returns>
|
||||
public static int ToInt32(this string value)
|
||||
{
|
||||
if (IsNumberId(value))
|
||||
return int.Parse(value);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查一个字符串是否是纯数字构成的,一般用于查询字符串参数的有效性验证。(0除外)
|
||||
/// </summary>
|
||||
/// <param name="_value">需验证的字符串。。</param>
|
||||
/// <returns>是否合法的bool值。</returns>
|
||||
public static bool IsNumberId(string _value)
|
||||
{
|
||||
return QuickValidate("^[1-9]*[0-9]*$", _value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 快速验证一个字符串是否符合指定的正则表达式。
|
||||
/// </summary>
|
||||
/// <param name="_express">正则表达式的内容。</param>
|
||||
/// <param name="_value">需验证的字符串。</param>
|
||||
/// <returns>是否合法的bool值。</returns>
|
||||
public static bool QuickValidate(string _express, string _value)
|
||||
{
|
||||
if (_value == null) return false;
|
||||
Regex myRegex = new Regex(_express);
|
||||
if (_value.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return myRegex.IsMatch(_value);
|
||||
}
|
||||
/// <summary>
|
||||
/// 得到字符串长度,一个汉字长度为2
|
||||
/// </summary>
|
||||
/// <param name="inputString">参数字符串</param>
|
||||
/// <returns></returns>
|
||||
public static int StrLength(this string inputString)
|
||||
{
|
||||
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
|
||||
int tempLen = 0;
|
||||
byte[] s = ascii.GetBytes(inputString);
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
if ((int)s[i] == 63)
|
||||
tempLen += 2;
|
||||
else
|
||||
tempLen += 1;
|
||||
}
|
||||
return tempLen;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 截取指定长度字符串
|
||||
/// </summary>
|
||||
/// <param name="inputString">要处理的字符串</param>
|
||||
/// <param name="len">指定长度</param>
|
||||
/// <returns>返回处理后的字符串</returns>
|
||||
public static string splitString(this string inputString, int len)
|
||||
{
|
||||
bool isShowFix = false;
|
||||
if (len % 2 == 1)
|
||||
{
|
||||
isShowFix = true;
|
||||
len--;
|
||||
}
|
||||
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
|
||||
int tempLen = 0;
|
||||
string tempString = "";
|
||||
byte[] s = ascii.GetBytes(inputString);
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
if ((int)s[i] == 63)
|
||||
tempLen += 2;
|
||||
else
|
||||
tempLen += 1;
|
||||
|
||||
try
|
||||
{
|
||||
tempString += inputString.Substring(i, 1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (tempLen > len)
|
||||
break;
|
||||
}
|
||||
|
||||
byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString);
|
||||
if (isShowFix && mybyte.Length > len)
|
||||
tempString += "…";
|
||||
return tempString;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// HTML转行成TEXT
|
||||
/// </summary>
|
||||
/// <param name="strHtml"></param>
|
||||
/// <returns></returns>
|
||||
public static string HtmlToTxt(this string strHtml)
|
||||
{
|
||||
string[] aryReg ={
|
||||
@"<script[^>]*?>.*?</script>",
|
||||
@"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",
|
||||
@"([\r\n])[\s]+",
|
||||
@"&(quot|#34);",
|
||||
@"&(amp|#38);",
|
||||
@"&(lt|#60);",
|
||||
@"&(gt|#62);",
|
||||
@"&(nbsp|#160);",
|
||||
@"&(iexcl|#161);",
|
||||
@"&(cent|#162);",
|
||||
@"&(pound|#163);",
|
||||
@"&(copy|#169);",
|
||||
@"&#(\d+);",
|
||||
@"-->",
|
||||
@"<!--.*\n"
|
||||
};
|
||||
|
||||
string newReg = aryReg[0];
|
||||
string strOutput = strHtml;
|
||||
for (int i = 0; i < aryReg.Length; i++)
|
||||
{
|
||||
Regex regex = new Regex(aryReg[i], RegexOptions.IgnoreCase);
|
||||
strOutput = regex.Replace(strOutput, string.Empty);
|
||||
}
|
||||
|
||||
strOutput.Replace("<", "");
|
||||
strOutput.Replace(">", "");
|
||||
strOutput.Replace("\r\n", "");
|
||||
|
||||
|
||||
return strOutput;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 判断对象是否为空,为空返回true
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要验证的对象的类型</typeparam>
|
||||
/// <param name="data">要验证的对象</param>
|
||||
public static bool IsNullOrEmpty(this object data)
|
||||
{
|
||||
//如果为null
|
||||
if (data == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (string.IsNullOrEmpty(data.ToString().Trim()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断对象是否为空,为空返回true
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要验证的对象的类型</typeparam>
|
||||
/// <param name="data">要验证的对象</param>
|
||||
public static bool IsNullOrEmpty<T>(this List<T> collection)
|
||||
{
|
||||
if (collection == null)
|
||||
return true;
|
||||
if (collection.Count() == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(this DataSet ds)
|
||||
{
|
||||
if (ds == null)
|
||||
return true;
|
||||
if (ds.Tables.Count == 0)
|
||||
return true;
|
||||
return ds.Tables[0].IsNullOrEmpty();
|
||||
}
|
||||
|
||||
public static bool IsNullOrEmpty(this DataTable dt)
|
||||
{
|
||||
if (dt == null)
|
||||
return true;
|
||||
if (dt.Rows.Count == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
55
DH.RBAC/Utility/Other/TreeSelect.cs
Normal file
55
DH.RBAC/Utility/Other/TreeSelect.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
/// <summary>
|
||||
/// Select2树形下拉列表模型。
|
||||
/// </summary>
|
||||
public class TreeSelect
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string text { get; set; }
|
||||
public string parentId { get; set; }
|
||||
public object data { get; set; }
|
||||
}
|
||||
|
||||
public static class TreeSelectHelper
|
||||
{
|
||||
public static string ToTreeSelectJson(this List<TreeSelect> data)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("[");
|
||||
sb.Append(ToTreeSelectJson(data, "0", ""));
|
||||
sb.Append("]");
|
||||
return sb.ToString();
|
||||
}
|
||||
private static string ToTreeSelectJson(List<TreeSelect> data, string parentId, string blank)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
var childList = data.FindAll(t => t.parentId == parentId);
|
||||
|
||||
var tabline = "";
|
||||
if (parentId != "0")
|
||||
{
|
||||
tabline = " ";
|
||||
}
|
||||
if (childList.Count > 0)
|
||||
{
|
||||
tabline = tabline + blank;
|
||||
}
|
||||
foreach (TreeSelect entity in childList)
|
||||
{
|
||||
entity.text = tabline + entity.text;
|
||||
string strJson = JsonConvert.SerializeObject(entity);
|
||||
sb.Append(strJson);
|
||||
sb.Append(ToTreeSelectJson(data, entity.id, tabline));
|
||||
}
|
||||
return sb.ToString().Replace("}{", "},{");
|
||||
}
|
||||
}
|
||||
}
|
277
DH.RBAC/Utility/Other/UIUtils.cs
Normal file
277
DH.RBAC/Utility/Other/UIUtils.cs
Normal file
@ -0,0 +1,277 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using Sunny.UI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// UI控件多线程赋值专用
|
||||
/// </summary>
|
||||
public static class UIUtils
|
||||
{
|
||||
public delegate void InvokeBackColorDelegate(Control control, Color color);
|
||||
public delegate void InvokeTextDelegate(Control control, string text);
|
||||
public delegate void InvokeVisibleDelegate(Control control, bool enable);
|
||||
public delegate void InvokeDataDelegate(Control control, DataTable dt);
|
||||
public delegate void InvokeLineDelegate(Control control, string[] line);
|
||||
public delegate void InvokeAppendLineDelegate(Control control, string line);
|
||||
public delegate void InvokeAppendLineMaxDelegate(Control control, string line);
|
||||
public delegate void InvokeTabIndex(UITabControl control, int index);
|
||||
public delegate void InvokMESStateDelegate(UILight light, UILightState state);
|
||||
public delegate void InvokeProgressDelegate(UIProcessBar control, int value);
|
||||
public static void InvokeProgressValue(this UIProcessBar control, int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeProgressDelegate(InvokeProgressValue), new object[] { control, value });
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Value = value;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
public static void InvokMESState(this UILight light, UILightState state)
|
||||
{
|
||||
if (light.InvokeRequired)
|
||||
{
|
||||
light.BeginInvoke(new InvokMESStateDelegate(InvokMESState), new object[] { light, state });
|
||||
}
|
||||
else
|
||||
{
|
||||
light.State = state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void InvokeBackColor(this Control control, Color color)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeBackColorDelegate(InvokeBackColor), new object[] { control, color });
|
||||
}
|
||||
else
|
||||
{
|
||||
control.BackColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
public static void InvokeVisible(this Control control, bool enable)
|
||||
{
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeVisibleDelegate(InvokeVisible), new object[] { control, enable });
|
||||
}
|
||||
else
|
||||
{
|
||||
control.Visible = enable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void InvokeText(this Control control, string text)
|
||||
{
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeTextDelegate(InvokeText), new object[] { control, text });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (control is UITextBox)
|
||||
{
|
||||
((UITextBox)control).Text = text;
|
||||
}
|
||||
else if (control is TextBox)
|
||||
{
|
||||
((TextBox)control).Text = text;
|
||||
}
|
||||
else if (control is UILabel)
|
||||
{
|
||||
((UILabel)control).Text = text;
|
||||
}
|
||||
else if (control is Label)
|
||||
{
|
||||
((Label)control).Text = text;
|
||||
}
|
||||
else if (control is UIButton)
|
||||
{
|
||||
((UIButton)control).Text = text;
|
||||
}
|
||||
else if (control is Button)
|
||||
{
|
||||
((Button)control).Text = text;
|
||||
}
|
||||
else if (control is UIGroupBox)
|
||||
{
|
||||
((UIGroupBox)control).Text = text;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void InvokeData(this Control control, DataTable dt)
|
||||
{
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeDataDelegate(InvokeData), new object[] { control, dt });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (control is UIDataGridView)
|
||||
{
|
||||
UIDataGridView dgv = ((UIDataGridView)control);
|
||||
dgv.DataSource = dt;
|
||||
dgv.ClearSelection();
|
||||
dgv.Refresh();
|
||||
}
|
||||
else if (control is DataGridView)
|
||||
{
|
||||
DataGridView dgv = ((DataGridView)control);
|
||||
dgv.DataSource = dt;
|
||||
dgv.ClearSelection();
|
||||
dgv.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void InvokeLine(this Control control, string[] line)
|
||||
{
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeLineDelegate(InvokeLine), new object[] { control, line });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (control is UITextBox)
|
||||
{
|
||||
UITextBox tb = ((UITextBox)control);
|
||||
tb.Lines = line;
|
||||
}
|
||||
else if (control is TextBox)
|
||||
{
|
||||
TextBox tb = ((TextBox)control);
|
||||
tb.Lines = line;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void InvokeLine(this Control control, List<string> line)
|
||||
{
|
||||
InvokeLine(control, line.ToArray());
|
||||
}
|
||||
|
||||
public static void InvokeAppendLine(this Control control, string value)
|
||||
{
|
||||
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeAppendLineDelegate(InvokeAppendLine), new object[] { control, value });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (control is UITextBox)
|
||||
{
|
||||
UITextBox component = (UITextBox)control;
|
||||
List<string> lines = component.Lines.ToList();
|
||||
lines.Add(value);
|
||||
component.Lines = lines.ToArray();
|
||||
component.Focus();//获取焦点
|
||||
component.Select(component.TextLength, 0);//光标定位到文本最后
|
||||
component.ScrollToCaret();//滚动到光标处
|
||||
}
|
||||
else if (control is TextBox)
|
||||
{
|
||||
TextBox component = (TextBox)control;
|
||||
List<string> lines = component.Lines.ToList();
|
||||
lines.Add(value);
|
||||
component.Lines = lines.ToArray();
|
||||
component.Focus();//获取焦点
|
||||
component.Select(component.TextLength, 0);//光标定位到文本最后
|
||||
component.ScrollToCaret();//滚动到光标处
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void InvokeAppendLine(this Control control, string value, int maxLineNum)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeAppendLineMaxDelegate(InvokeAppendLine), new object[] { control, value, maxLineNum });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (control is UITextBox)
|
||||
{
|
||||
UITextBox component = (UITextBox)control;
|
||||
List<string> lines = component.Lines.ToList();
|
||||
lines.Add(value);
|
||||
if (lines.Count > maxLineNum)
|
||||
{
|
||||
int cha = lines.Count - maxLineNum;
|
||||
//lines.Reverse();
|
||||
//差多少,删多少
|
||||
for (int i = 0; i < cha; i++)
|
||||
{
|
||||
lines.RemoveAt(0);
|
||||
}
|
||||
//lines.Reverse();
|
||||
}
|
||||
component.Lines = lines.ToArray();
|
||||
component.Focus();//获取焦点
|
||||
component.Select(component.TextLength, 0);//光标定位到文本最后
|
||||
component.ScrollToCaret();//滚动到光标处
|
||||
}
|
||||
else if (control is TextBox)
|
||||
{
|
||||
TextBox component = (TextBox)control;
|
||||
List<string> lines = component.Lines.ToList();
|
||||
lines.Add(value);
|
||||
if (lines.Count > maxLineNum)
|
||||
{
|
||||
int cha = lines.Count - maxLineNum;
|
||||
//lines.Reverse();
|
||||
//差多少,删多少
|
||||
for (int i = 0; i < cha; i++)
|
||||
{
|
||||
lines.RemoveAt(0);
|
||||
}
|
||||
//lines.Reverse();
|
||||
}
|
||||
component.Lines = lines.ToArray();
|
||||
component.Focus();//获取焦点
|
||||
component.Select(component.TextLength, 0);//光标定位到文本最后
|
||||
component.ScrollToCaret();//滚动到光标处
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void InvokeIndex(this UITabControl control, int index)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(new InvokeTabIndex(InvokeIndex), new object[] { control, index });
|
||||
}
|
||||
else
|
||||
{
|
||||
control.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
52
DH.RBAC/Utility/Other/UUID.cs
Normal file
52
DH.RBAC/Utility/Other/UUID.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
public class UUID
|
||||
{
|
||||
public static long SnowId
|
||||
{
|
||||
get
|
||||
{
|
||||
return SnowFlakeHelper.GetSnowInstance().NextId();
|
||||
}
|
||||
}
|
||||
|
||||
public static string StrSnowId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToString(SnowId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static string NewTimeUUID
|
||||
{
|
||||
get
|
||||
{
|
||||
return DateTime.Today.ToString("yyyyMMdd") + Guid.NewGuid().ToString().Replace("-", "").ToUpper().Substring(0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
public static string NewTimeUUID2
|
||||
{
|
||||
get
|
||||
{
|
||||
return DateTime.Today.ToString("yyyyMMdd") + Guid.NewGuid().ToString().Replace("-", "").ToUpper();
|
||||
}
|
||||
}
|
||||
|
||||
public static string NewUUID
|
||||
{
|
||||
get
|
||||
{
|
||||
return Guid.NewGuid().ToString().Replace("-", "").ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
34
DH.RBAC/Utility/Other/ZTreeNode.cs
Normal file
34
DH.RBAC/Utility/Other/ZTreeNode.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace DH.RBAC.Utility.Other
|
||||
{
|
||||
/// <summary>
|
||||
/// zTree单层节点数据模型。
|
||||
/// </summary>
|
||||
public class ZTreeNode
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点ID。
|
||||
/// </summary>
|
||||
public string id { get; set; }
|
||||
/// <summary>
|
||||
/// 父节点ID。
|
||||
/// </summary>
|
||||
public string pId { get; set; }
|
||||
/// <summary>
|
||||
/// 节点名称。
|
||||
/// </summary>
|
||||
public string name { get; set; }
|
||||
/// <summary>
|
||||
/// 是否展开。
|
||||
/// </summary>
|
||||
public bool open { get; set; }
|
||||
/// <summary>
|
||||
/// 是否选中。
|
||||
/// </summary>
|
||||
public bool @checked { get; set; }
|
||||
}
|
||||
}
|
114
DH.RBAC/Utility/PopupTool/GripBounds.cs
Normal file
114
DH.RBAC/Utility/PopupTool/GripBounds.cs
Normal file
@ -0,0 +1,114 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
internal struct GripBounds
|
||||
{
|
||||
public GripBounds(Rectangle clientRectangle)
|
||||
{
|
||||
this.clientRectangle = clientRectangle;
|
||||
}
|
||||
public Rectangle ClientRectangle
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.clientRectangle;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle Bottom
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Y = result.Bottom - 6 + 1;
|
||||
result.Height = 6;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle BottomRight
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Y = result.Bottom - 12 + 1;
|
||||
result.Height = 12;
|
||||
result.X = result.Width - 12 + 1;
|
||||
result.Width = 12;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle Top
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Height = 6;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle TopRight
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Height = 12;
|
||||
result.X = result.Width - 12 + 1;
|
||||
result.Width = 12;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle Left
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Width = 6;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle BottomLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Width = 12;
|
||||
result.Y = result.Height - 12 + 1;
|
||||
result.Height = 12;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle Right
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.X = result.Right - 6 + 1;
|
||||
result.Width = 6;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public Rectangle TopLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
Rectangle result = this.ClientRectangle;
|
||||
result.Width = 12;
|
||||
result.Height = 12;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private const int GripSize = 6;
|
||||
|
||||
private const int CornerGripSize = 12;
|
||||
|
||||
private Rectangle clientRectangle;
|
||||
}
|
||||
#endif
|
524
DH.RBAC/Utility/PopupTool/Popup.cs
Normal file
524
DH.RBAC/Utility/PopupTool/Popup.cs
Normal file
@ -0,0 +1,524 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Permissions;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
|
||||
namespace PopupTool
|
||||
{
|
||||
[ToolboxItem(false)]
|
||||
public class Popup : ToolStripDropDown
|
||||
{
|
||||
public Control Content
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.content;
|
||||
}
|
||||
}
|
||||
|
||||
public bool UseFadeEffect
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.fade;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (this.fade != value)
|
||||
{
|
||||
this.fade = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool FocusOnOpen
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.focusOnOpen;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.focusOnOpen = value;
|
||||
}
|
||||
}
|
||||
public bool AcceptAlt
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.acceptAlt;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.acceptAlt = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Resizable
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.resizable && this._resizable;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.resizable = value;
|
||||
}
|
||||
}
|
||||
|
||||
public new Size MinimumSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.minSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.minSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
public new Size MaximumSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.maxSize;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.maxSize = value;
|
||||
}
|
||||
}
|
||||
public bool IsOpen
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._isOpen;
|
||||
}
|
||||
}
|
||||
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
get
|
||||
{
|
||||
CreateParams createParams = base.CreateParams;
|
||||
createParams.ExStyle |= 134217728;
|
||||
return createParams;
|
||||
}
|
||||
}
|
||||
|
||||
public Popup(Control content)
|
||||
{
|
||||
EventHandler handler = null;
|
||||
EventHandler handler2 = null;
|
||||
PaintEventHandler handler3 = null;
|
||||
this.focusOnOpen = true;
|
||||
this.acceptAlt = true;
|
||||
if (ReferenceEquals(content, null))
|
||||
{
|
||||
throw new ArgumentNullException("content");
|
||||
}
|
||||
this.content = content;
|
||||
this.fade = SystemInformation.IsMenuAnimationEnabled && SystemInformation.IsMenuFadeEnabled;
|
||||
this._resizable = true;
|
||||
this.AutoSize = false;
|
||||
this.DoubleBuffered = true;
|
||||
base.ResizeRedraw = true;
|
||||
this.host = new ToolStripControlHost(content);
|
||||
Padding padding1 = this.host.Margin = Padding.Empty;
|
||||
Padding padding2 = this.host.Padding = padding1;
|
||||
base.Padding = base.Margin = padding2;
|
||||
this.MinimumSize = content.MinimumSize;
|
||||
content.MinimumSize = content.Size;
|
||||
this.MaximumSize = content.MaximumSize;
|
||||
content.MaximumSize = content.Size;
|
||||
base.Size = content.Size;
|
||||
content.Location = Point.Empty;
|
||||
this.Items.Add(this.host);
|
||||
if (handler == null)
|
||||
{
|
||||
handler = delegate (object sender, EventArgs e) {
|
||||
content = null;
|
||||
this.Dispose(true);
|
||||
};
|
||||
}
|
||||
content.Disposed += handler;
|
||||
if (handler2 == null)
|
||||
{
|
||||
handler2 = (sender, e) => this.UpdateRegion();
|
||||
}
|
||||
content.RegionChanged += handler2;
|
||||
if (handler3 == null)
|
||||
{
|
||||
handler3 = (sender, e) => this.PaintSizeGrip(e);
|
||||
}
|
||||
content.Paint += handler3;
|
||||
this.UpdateRegion();
|
||||
}
|
||||
|
||||
protected override bool ProcessDialogKey(Keys keyData)
|
||||
{
|
||||
if (this.acceptAlt && (keyData & Keys.Alt) == Keys.Alt)
|
||||
{
|
||||
if ((keyData & Keys.F4) != Keys.F4)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
base.Close();
|
||||
}
|
||||
return base.ProcessDialogKey(keyData);
|
||||
}
|
||||
|
||||
protected void UpdateRegion()
|
||||
{
|
||||
if (base.Region != null)
|
||||
{
|
||||
base.Region.Dispose();
|
||||
base.Region = null;
|
||||
}
|
||||
if (this.content.Region != null)
|
||||
{
|
||||
base.Region = this.content.Region.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
public void Show(Control control)
|
||||
{
|
||||
this.Show(control, control.ClientRectangle);
|
||||
}
|
||||
|
||||
public void Show(Control control, bool center)
|
||||
{
|
||||
this.Show(control, control.ClientRectangle, center);
|
||||
}
|
||||
|
||||
public void Show(Control control, Rectangle area)
|
||||
{
|
||||
this.Show(control, area, false);
|
||||
}
|
||||
|
||||
public void Show(Control control, Rectangle area, bool center)
|
||||
{
|
||||
if (control == null)
|
||||
{
|
||||
throw new ArgumentNullException("control");
|
||||
}
|
||||
this.SetOwnerItem(control);
|
||||
this.resizableTop = (this.resizableLeft = false);
|
||||
Point point = control.PointToScreen(new Point(area.Left, area.Top + area.Height));
|
||||
Rectangle workingArea = Screen.FromControl(control).WorkingArea;
|
||||
if (center)
|
||||
{
|
||||
if (point.X + (area.Width + base.Size.Width) / 2 > workingArea.Right)
|
||||
{
|
||||
this.resizableLeft = true;
|
||||
point.X = workingArea.Right - base.Size.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.resizableLeft = true;
|
||||
point.X -= (base.Size.Width - area.Width) / 2;
|
||||
}
|
||||
}
|
||||
else if (point.X + base.Size.Width > workingArea.Left + workingArea.Width)
|
||||
{
|
||||
this.resizableLeft = true;
|
||||
point.X = workingArea.Left + workingArea.Width - base.Size.Width;
|
||||
}
|
||||
if (point.Y + base.Size.Height > workingArea.Top + workingArea.Height)
|
||||
{
|
||||
this.resizableTop = true;
|
||||
point.Y -= base.Size.Height + area.Height;
|
||||
}
|
||||
point = control.PointToClient(point);
|
||||
base.Show(control, point, ToolStripDropDownDirection.BelowRight);
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool visible)
|
||||
{
|
||||
double opacity = base.Opacity;
|
||||
if (visible && this.fade && this.focusOnOpen)
|
||||
{
|
||||
base.Opacity = 0.0;
|
||||
}
|
||||
base.SetVisibleCore(visible);
|
||||
if (visible && this.fade && this.focusOnOpen)
|
||||
{
|
||||
for (int i = 1; i <= 5; i++)
|
||||
{
|
||||
if (i > 1)
|
||||
{
|
||||
Thread.Sleep(20);
|
||||
}
|
||||
base.Opacity = opacity * (double)i / 5.0;
|
||||
}
|
||||
base.Opacity = opacity;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetOwnerItem(Control control)
|
||||
{
|
||||
if (control != null)
|
||||
{
|
||||
if (control is Popup)
|
||||
{
|
||||
Popup popup = control as Popup;
|
||||
this.ownerPopup = popup;
|
||||
this.ownerPopup.childPopup = this;
|
||||
base.OwnerItem = popup.Items[0];
|
||||
}
|
||||
else if (control.Parent != null)
|
||||
{
|
||||
this.SetOwnerItem(control.Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnSizeChanged(EventArgs e)
|
||||
{
|
||||
this.content.MinimumSize = base.Size;
|
||||
this.content.MaximumSize = base.Size;
|
||||
this.content.Size = base.Size;
|
||||
this.content.Location = Point.Empty;
|
||||
base.OnSizeChanged(e);
|
||||
}
|
||||
|
||||
protected override void OnOpening(CancelEventArgs e)
|
||||
{
|
||||
if (this.content.IsDisposed || this.content.Disposing)
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.UpdateRegion();
|
||||
base.OnOpening(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnOpened(EventArgs e)
|
||||
{
|
||||
if (this.ownerPopup != null)
|
||||
{
|
||||
this.ownerPopup._resizable = false;
|
||||
}
|
||||
if (this.focusOnOpen)
|
||||
{
|
||||
this.content.Focus();
|
||||
}
|
||||
this._isOpen = true;
|
||||
base.OnOpened(e);
|
||||
}
|
||||
|
||||
protected override void OnClosed(ToolStripDropDownClosedEventArgs e)
|
||||
{
|
||||
if (this.ownerPopup != null)
|
||||
{
|
||||
this.ownerPopup._resizable = true;
|
||||
}
|
||||
this._isOpen = false;
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
protected override void WndProc(ref Message m)
|
||||
{
|
||||
if (!this.InternalProcessResizing(ref m, false))
|
||||
{
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
public bool ProcessResizing(ref Message m)
|
||||
{
|
||||
return this.InternalProcessResizing(ref m, true);
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
private bool InternalProcessResizing(ref Message m, bool contentControl)
|
||||
{
|
||||
if (m.Msg == 134 && m.WParam != IntPtr.Zero && this.childPopup != null && this.childPopup.Visible)
|
||||
{
|
||||
this.childPopup.Hide();
|
||||
}
|
||||
bool result;
|
||||
if (!this.Resizable)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else if (m.Msg == 132)
|
||||
{
|
||||
result = this.OnNcHitTest(ref m, contentControl);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (m.Msg == 36 && this.OnGetMinMaxInfo(ref m));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
|
||||
private bool OnGetMinMaxInfo(ref Message m)
|
||||
{
|
||||
UnsafeMethods.MINMAXINFO minmaxinfo = (UnsafeMethods.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(UnsafeMethods.MINMAXINFO));
|
||||
minmaxinfo.maxTrackSize = this.MaximumSize;
|
||||
minmaxinfo.minTrackSize = this.MinimumSize;
|
||||
Marshal.StructureToPtr(minmaxinfo, m.LParam, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OnNcHitTest(ref Message m, bool contentControl)
|
||||
{
|
||||
int x = UnsafeMethods.LOWORD(m.LParam);
|
||||
int y = UnsafeMethods.HIWORD(m.LParam);
|
||||
Point pt = base.PointToClient(new Point(x, y));
|
||||
GripBounds gripBounds = new GripBounds(contentControl ? this.content.ClientRectangle : base.ClientRectangle);
|
||||
IntPtr intPtr = new IntPtr(-1);
|
||||
if (this.resizableTop)
|
||||
{
|
||||
if (this.resizableLeft && gripBounds.TopLeft.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)13));
|
||||
return true;
|
||||
}
|
||||
if (!this.resizableLeft && gripBounds.TopRight.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)14));
|
||||
return true;
|
||||
}
|
||||
if (gripBounds.Top.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)12));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.resizableLeft && gripBounds.BottomLeft.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)16));
|
||||
return true;
|
||||
}
|
||||
if (!this.resizableLeft && gripBounds.BottomRight.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)17));
|
||||
return true;
|
||||
}
|
||||
if (gripBounds.Bottom.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)15));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
bool result;
|
||||
if (this.resizableLeft && gripBounds.Left.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)10));
|
||||
result = true;
|
||||
}
|
||||
else if (!this.resizableLeft && gripBounds.Right.Contains(pt))
|
||||
{
|
||||
m.Result = (contentControl ? intPtr : ((IntPtr)11));
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void PaintSizeGrip(PaintEventArgs e)
|
||||
{
|
||||
if (e != null && e.Graphics != null && this.resizable)
|
||||
{
|
||||
Size clientSize = this.content.ClientSize;
|
||||
using (Bitmap bitmap = new Bitmap(16, 16))
|
||||
{
|
||||
using (Graphics graphics = Graphics.FromImage(bitmap))
|
||||
{
|
||||
if (Application.RenderWithVisualStyles)
|
||||
{
|
||||
if (this.sizeGripRenderer == null)
|
||||
{
|
||||
this.sizeGripRenderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal);
|
||||
}
|
||||
this.sizeGripRenderer.DrawBackground(graphics, new Rectangle(0, 0, 16, 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
ControlPaint.DrawSizeGrip(graphics, this.content.BackColor, 0, 0, 16, 16);
|
||||
}
|
||||
}
|
||||
GraphicsState gstate = e.Graphics.Save();
|
||||
e.Graphics.ResetTransform();
|
||||
if (this.resizableTop)
|
||||
{
|
||||
if (this.resizableLeft)
|
||||
{
|
||||
e.Graphics.RotateTransform(180f);
|
||||
e.Graphics.TranslateTransform((float)(-(float)clientSize.Width), (float)(-(float)clientSize.Height));
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Graphics.ScaleTransform(1f, -1f);
|
||||
e.Graphics.TranslateTransform(0f, (float)(-(float)clientSize.Height));
|
||||
}
|
||||
}
|
||||
else if (this.resizableLeft)
|
||||
{
|
||||
e.Graphics.ScaleTransform(-1f, 1f);
|
||||
e.Graphics.TranslateTransform((float)(-(float)clientSize.Width), 0f);
|
||||
}
|
||||
e.Graphics.DrawImage(bitmap, clientSize.Width - 16, clientSize.Height - 16 + 1, 16, 16);
|
||||
e.Graphics.Restore(gstate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const int frames = 5;
|
||||
|
||||
private const int totalduration = 100;
|
||||
|
||||
private const int frameduration = 20;
|
||||
|
||||
private Control content;
|
||||
|
||||
private bool fade;
|
||||
|
||||
private bool focusOnOpen = true;
|
||||
|
||||
private bool acceptAlt = true;
|
||||
|
||||
private Popup ownerPopup;
|
||||
|
||||
private Popup childPopup;
|
||||
|
||||
private bool _resizable;
|
||||
|
||||
private bool resizable;
|
||||
|
||||
private ToolStripControlHost host;
|
||||
|
||||
private Size minSize;
|
||||
|
||||
private Size maxSize;
|
||||
|
||||
private bool _isOpen;
|
||||
|
||||
private bool resizableTop;
|
||||
|
||||
private bool resizableLeft;
|
||||
|
||||
private VisualStyleRenderer sizeGripRenderer;
|
||||
}
|
||||
}
|
||||
#endif
|
180
DH.RBAC/Utility/PopupTool/UnsafeMethods.cs
Normal file
180
DH.RBAC/Utility/PopupTool/UnsafeMethods.cs
Normal file
@ -0,0 +1,180 @@
|
||||
#if NETFRAMEWORK || WINDOWS
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal class UnsafeMethods
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hDC);
|
||||
|
||||
[DllImport("user32")]
|
||||
public static extern bool TrackMouseEvent(ref UnsafeMethods.TRACKMOUSEEVENT lpEventTrack);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
internal static int HIWORD(int n)
|
||||
{
|
||||
return n >> 16 & 65535;
|
||||
}
|
||||
|
||||
internal static int HIWORD(IntPtr n)
|
||||
{
|
||||
return UnsafeMethods.HIWORD((int)((long)n));
|
||||
}
|
||||
|
||||
internal static int LOWORD(int n)
|
||||
{
|
||||
return n & 65535;
|
||||
}
|
||||
|
||||
internal static int LOWORD(IntPtr n)
|
||||
{
|
||||
return UnsafeMethods.LOWORD((int)((long)n));
|
||||
}
|
||||
|
||||
public const int WM_LBUTTONDOWN = 513;
|
||||
|
||||
public const int WM_RBUTTONDOWN = 516;
|
||||
|
||||
public const int WM_MBUTTONDOWN = 519;
|
||||
|
||||
public const int WM_NCLBUTTONDOWN = 161;
|
||||
|
||||
public const int WM_NCRBUTTONDOWN = 164;
|
||||
|
||||
public const int WM_NCMBUTTONDOWN = 167;
|
||||
|
||||
public const int WM_NCCALCSIZE = 131;
|
||||
|
||||
public const int WM_NCHITTEST = 132;
|
||||
|
||||
public const int WM_NCPAINT = 133;
|
||||
|
||||
public const int WM_NCACTIVATE = 134;
|
||||
|
||||
public const int WM_MOUSELEAVE = 675;
|
||||
|
||||
public const int WS_EX_NOACTIVATE = 134217728;
|
||||
|
||||
public const int HTTRANSPARENT = -1;
|
||||
|
||||
public const int HTLEFT = 10;
|
||||
|
||||
public const int HTRIGHT = 11;
|
||||
|
||||
public const int HTTOP = 12;
|
||||
|
||||
public const int HTTOPLEFT = 13;
|
||||
|
||||
public const int HTTOPRIGHT = 14;
|
||||
|
||||
public const int HTBOTTOM = 15;
|
||||
|
||||
public const int HTBOTTOMLEFT = 16;
|
||||
|
||||
public const int HTBOTTOMRIGHT = 17;
|
||||
|
||||
public const int WM_USER = 1024;
|
||||
|
||||
public const int WM_REFLECT = 8192;
|
||||
|
||||
public const int WM_COMMAND = 273;
|
||||
|
||||
public const int CBN_DROPDOWN = 7;
|
||||
|
||||
public const int WM_GETMINMAXINFO = 36;
|
||||
|
||||
public static readonly IntPtr TRUE = new IntPtr(1);
|
||||
|
||||
public static readonly IntPtr FALSE = new IntPtr(0);
|
||||
|
||||
public enum TrackerEventFlags : uint
|
||||
{
|
||||
TME_HOVER = 1U,
|
||||
TME_LEAVE,
|
||||
TME_QUERY = 1073741824U,
|
||||
TME_CANCEL = 2147483648U
|
||||
}
|
||||
internal struct TRACKMOUSEEVENT
|
||||
{
|
||||
public uint cbSize;
|
||||
|
||||
public uint dwFlags;
|
||||
|
||||
public IntPtr hwndTrack;
|
||||
|
||||
public uint dwHoverTime;
|
||||
}
|
||||
|
||||
internal struct MINMAXINFO
|
||||
{
|
||||
public Point reserved;
|
||||
|
||||
public Size maxSize;
|
||||
|
||||
public Point maxPosition;
|
||||
|
||||
public Size minTrackSize;
|
||||
|
||||
public Size maxTrackSize;
|
||||
}
|
||||
|
||||
internal struct RECT
|
||||
{
|
||||
public RECT(int left, int top, int right, int bottom)
|
||||
{
|
||||
this.left = left;
|
||||
this.top = top;
|
||||
this.right = right;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public Rectangle Rect
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle(this.left, this.top, this.right - this.left, this.bottom - this.top);
|
||||
}
|
||||
}
|
||||
|
||||
public static UnsafeMethods.RECT FromXYWH(int x, int y, int width, int height)
|
||||
{
|
||||
return new UnsafeMethods.RECT(x, y, x + width, y + height);
|
||||
}
|
||||
|
||||
public static UnsafeMethods.RECT FromRectangle(Rectangle rect)
|
||||
{
|
||||
return new UnsafeMethods.RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);
|
||||
}
|
||||
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
}
|
||||
|
||||
internal struct WINDOWPOS
|
||||
{
|
||||
internal IntPtr hwnd;
|
||||
internal IntPtr hWndInsertAfter;
|
||||
internal int x;
|
||||
internal int y;
|
||||
internal int cx;
|
||||
internal int cy;
|
||||
internal uint flags;
|
||||
}
|
||||
|
||||
public struct NCCALCSIZE_PARAMS
|
||||
{
|
||||
public UnsafeMethods.RECT rectProposed;
|
||||
public UnsafeMethods.RECT rectBeforeMove;
|
||||
public UnsafeMethods.RECT rectClientBeforeMove;
|
||||
public UnsafeMethods.WINDOWPOS lpPos;
|
||||
}
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user