Skip to content

Commit

Permalink
403:JsonHelper的GetJosnValue(json写错顺理)变更名称为GetValue(2016-10-21)
Browse files Browse the repository at this point in the history
404:NoSqlAction 文本数据库加强删除最后一条数据时的并发处理问题(2016-10-23)
405:DBTool.GetColumns修正对于没有where的group by语句拿表结构的问题(2016-10-24)
406:AppConfig增加SetConn方法(同时增加链接缓存)(2016-10-24)
407:SqlCreateForPager 处理分页的order by aa,bb 没带asc的问题(2016-10-25)
  • Loading branch information
cyq1162 committed Oct 25, 2016
1 parent 68062e2 commit df8655c
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 113 deletions.
236 changes: 133 additions & 103 deletions Action/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@ namespace CYQ.Data
public static partial class AppConfig
{
#region 基方法
private static MDictionary<string, string> configs = new MDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static MDictionary<string, string> appConfigs = new MDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static MDictionary<string, string> connConfigs = new MDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// 设置Web.config或App.config的值。
/// </summary>
public static void SetApp(string key, string value)
{
try
{
if (configs.ContainsKey(key))
if (appConfigs.ContainsKey(key))
{
configs[key] = value;
appConfigs[key] = value;
}
else
{
configs.Add(key, value);
appConfigs.Add(key, value);
}
}
catch (Exception err)
Expand All @@ -46,17 +47,17 @@ public static string GetApp(string key)
/// </summary>
public static string GetApp(string key, string defaultValue)
{
if (configs.ContainsKey(key))
if (appConfigs.ContainsKey(key))
{
return configs[key];
return appConfigs[key];
}
else
{
string value = ConfigurationManager.AppSettings[key];
value = string.IsNullOrEmpty(value) ? defaultValue : value;
try
{
configs.Add(key, value);
appConfigs.Add(key, value);
}
catch
{
Expand All @@ -82,50 +83,160 @@ public static int GetAppInt(string key, int defaultValue)
/// <summary>
/// 获取Web.config或App.config的connectionStrings节点的值。
/// </summary>
public static string GetConn(string key, out string providerName)
public static string GetConn(string name, out string providerName)
{
providerName = string.Empty;
if (string.IsNullOrEmpty(key))
if (string.IsNullOrEmpty(name))
{
key = "Conn";
name = "Conn";
}
if (key.Trim().Contains(" "))
if (name.Trim().Contains(" "))
{
return key;
return name;
}
ConnectionStringSettings conn = ConfigurationManager.ConnectionStrings[key];
if (connConfigs.ContainsKey(name))
{
return connConfigs[name];
}
ConnectionStringSettings conn = ConfigurationManager.ConnectionStrings[name];
if (conn != null)
{
providerName = conn.ProviderName;
if (key == conn.ConnectionString)//避免误写自己造成死循环。
if (name == conn.ConnectionString)//避免误写自己造成死循环。
{
return name;
}
name = conn.ConnectionString;
if (!string.IsNullOrEmpty(name) && name.Length < 32 && name.Split(' ').Length == 1)
{
return key;
return GetConn(name);
}
key = conn.ConnectionString;
if (!string.IsNullOrEmpty(key) && key.Length < 32 && key.Split(' ').Length == 1)
if (!connConfigs.ContainsKey(name) && string.IsNullOrEmpty(providerName)) // 如果有providerName,则不存档
{
return GetConn(key);
connConfigs.Add(name, conn.ConnectionString);
}
return conn.ConnectionString;
}
if (key.Length > 32 && key.Split('=').Length > 3 && key.Contains(";")) //链接字符串很长,没空格的情况
if (name.Length > 32 && name.Split('=').Length > 3 && name.Contains(";")) //链接字符串很长,没空格的情况
{
return key;
return name;
}
return "";
}

/// <summary>
/// 获取Web.config或App.config的connectionStrings节点的值。
/// </summary>
public static string GetConn(string key)
public static string GetConn(string name)
{
string p;
return GetConn(key, out p);
return GetConn(name, out p);
}
/// <summary>
/// 添加自定义链接(内存有效,并未写入config文件)
/// </summary>
/// <param name="name">名称</param>
/// <param name="connectionString">链接字符串</param>
public static void SetConn(string name, string connectionString)
{
if (!connConfigs.ContainsKey(name))
{
connConfigs.Add(name, connectionString);
}
else
{
connConfigs[name] = connectionString;
}
}

#endregion


/// <summary>
/// 是否使用表字段枚举转Int方式(默认为false)。
/// 设置为true时,可以加快一点性能,但生成的表字段枚举必须和数据库一致。
/// </summary>
public static bool IsEnumToInt
{
get
{
bool _IsEnumToInt;
bool.TryParse(GetApp("IsEnumToInt", "false"), out _IsEnumToInt);
return _IsEnumToInt;
}
set
{
SetApp("IsEnumToInt", value.ToString());
}
}

/// <summary>
/// Aop 插件配置项 示例配置:[ 完整类名,程序集(dll)名称]&lt;add key="Aop" value="Web.Aop.AopAction,Aop"/>
/// </summary>
public static string Aop
{
get
{
return GetApp("Aop");
}
set
{
SetApp("Aop", value);
}
}
/// <summary>
/// Tool.ThreadBreak 使用时,外置的文件配置相对路径(默认在环境变量Temp对应文件中)
/// </summary>
public static string ThreadBreakPath
{
get
{
return GetApp("ThreadBreakPath", Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.User));
}
set
{
SetApp("ThreadBreakPath", value);
}
}

/// <summary>
/// 生成的实体类的后缀。
/// </summary>
public static string EntitySuffix
{
get
{
return GetApp("EntitySuffix", "Bean");
}
set
{
SetApp("EntitySuffix", value);
}
}
/// <summary>
/// 获取当前Dll的版本号
/// </summary>
public static string Version
{
get
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
/// <summary>
/// 框架的运行路径(Bin目录)
/// </summary>
public static string RunPath
{
get
{
return AppConst.RunFolderPath;
}
}
}

public static partial class AppConfig
{
#region Xml相关配置
/// <summary>
/// XHtml 相关的配置
Expand Down Expand Up @@ -868,86 +979,5 @@ public static bool OpenDebugInfo
}
#endregion

/// <summary>
/// 是否使用表字段枚举转Int方式(默认为false)。
/// 设置为true时,可以加快一点性能,但生成的表字段枚举必须和数据库一致。
/// </summary>
public static bool IsEnumToInt
{
get
{
bool _IsEnumToInt;
bool.TryParse(GetApp("IsEnumToInt", "false"), out _IsEnumToInt);
return _IsEnumToInt;
}
set
{
SetApp("IsEnumToInt", value.ToString());
}
}

/// <summary>
/// Aop 插件配置项 示例配置:[ 完整类名,程序集(dll)名称]&lt;add key="Aop" value="Web.Aop.AopAction,Aop"/>
/// </summary>
public static string Aop
{
get
{
return GetApp("Aop");
}
set
{
SetApp("Aop", value);
}
}
/// <summary>
/// Tool.ThreadBreak 使用时,外置的文件配置相对路径(默认在环境变量Temp对应文件中)
/// </summary>
public static string ThreadBreakPath
{
get
{
return GetApp("ThreadBreakPath", Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.User));
}
set
{
SetApp("ThreadBreakPath", value);
}
}

/// <summary>
/// 生成的实体类的后缀。
/// </summary>
public static string EntitySuffix
{
get
{
return GetApp("EntitySuffix", "Bean");
}
set
{
SetApp("EntitySuffix", value);
}
}
/// <summary>
/// 获取当前Dll的版本号
/// </summary>
public static string Version
{
get
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
/// <summary>
/// 框架的运行路径(Bin目录)
/// </summary>
public static string RunPath
{
get
{
return AppConst.RunFolderPath;
}
}
}
}
2 changes: 1 addition & 1 deletion Action/MAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ internal void SetIdentityInsertOff()
_AllowInsertID = false;
}
/// <summary>
/// 当DeleteField被设置后(删除转更新操作),如果仍想删除操作(可将些属性置为true
/// 当DeleteField被设置后(删除转更新操作),如果仍想删除操作(可将此属性置为true
/// </summary>
internal bool IsIgnoreDeleteField = false;
#endregion
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyDescription("论坛:http://www.cyqdata.com/cyqdata")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("秋式软件 (2016-10-20)")]
[assembly: AssemblyCompany("秋式软件 (2016-10-25)")]
[assembly: AssemblyProduct("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyCopyright("版权所有 (C) 秋式软件 2010-2020")]
[assembly: AssemblyTrademark("CYQ.Data")]
Expand All @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.7.2")]
[assembly: AssemblyFileVersion("5.6.7.2")]
[assembly: AssemblyVersion("5.6.7.3")]
[assembly: AssemblyFileVersion("5.6.7.3")]
5 changes: 5 additions & 0 deletions SQL/SqlCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ internal static string AddOrderBy(string where, string primaryKey)
{
where += " order by " + primaryKey + " asc";
}
else if (where.IndexOf(" asc", StringComparison.OrdinalIgnoreCase) == -1 && where.IndexOf(" desc", StringComparison.OrdinalIgnoreCase) == -1)
{
//有order by 但没 asc
where += " asc";
}
return where;
}
internal static string GetWhere(DalType dalType, params MDataCell[] cells)
Expand Down
11 changes: 10 additions & 1 deletion SQL/SqlFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,16 @@ internal static string BuildSqlWithWhereOneEqualsTow(string tableName)
return Regex.Replace(sql, key, " where 1=2 and ", RegexOptions.IgnoreCase);
}
}

//检测是否有group by
keys = new string[] { " group by", "\ngroup by" };
foreach (string key in keys)
{
if (sql.IndexOf(key, StringComparison.OrdinalIgnoreCase) > -1)
{
string newKey = key.Replace("group", "where 1=2 group");
return Regex.Replace(sql, key, newKey, RegexOptions.IgnoreCase);
}
}
return sql + " where 1=2";
}
return string.Format("select * from {0} where 1=2", tableName);
Expand Down
5 changes: 2 additions & 3 deletions Table/MDataTableBatchAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ internal bool LoadDataInsert(DalType dalType, bool keepID)
_dalHelper.Dispose();
_dalHelper = null;
}
//IOHelper.Delete(path);//删除文件。
IOHelper.Delete(path);//删除文件。
}
return false;
}
Expand All @@ -643,7 +643,7 @@ private static string CreateCTL(string sql, string path)
}
private static string MDataTableToFile(MDataTable dt, bool keepID, DalType dalType)
{
string path = Path.GetTempPath() + dt.TableName + ".csv";//不能用.txt(会产生默认编码,影响第一行数据(空表时自增的ID被置为初始1)
string path = Path.GetTempPath() + dt.TableName + ".csv";
using (StreamWriter sw = new StreamWriter(path, false, new UTF8Encoding(false)))
{
MCellStruct ms;
Expand Down Expand Up @@ -678,7 +678,6 @@ private static string MDataTableToFile(MDataTable dt, bool keepID, DalType dalTy
{
value = v.ToString();
}

}
else
{
Expand Down
Loading

0 comments on commit df8655c

Please sign in to comment.