Skip to content

Commit

Permalink
387:MDataTable ToJson 对于null的数据,默认输出 xx:null 值(2016-10-09)
Browse files Browse the repository at this point in the history
388:Oracle(DBTool.GetTables) 增加对视图的过滤(2016-10-10)
389:JsonHelper 修正实体嵌套的问题、同时增加对数组的支持(2016-10-14)
  • Loading branch information
cyq1162 committed Oct 14, 2016
1 parent 4c3e037 commit 072c96b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 22 deletions.
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-09)")]
[assembly: AssemblyCompany("秋式软件 (2016-10-14)")]
[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.6.3")]
[assembly: AssemblyFileVersion("5.6.6.3")]
[assembly: AssemblyVersion("5.6.6.4")]
[assembly: AssemblyFileVersion("5.6.6.4")]
2 changes: 1 addition & 1 deletion SQL/TableSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ internal static string GetMSSQLTables(bool for2000)
}
internal static string GetOracleTables()
{
return "select TABLE_NAME AS TableName,COMMENTS AS Description from user_tab_comments";
return "select TABLE_NAME AS TableName,COMMENTS AS Description from user_tab_comments where TABLE_TYPE='TABLE'";
}
internal static string GetMySqlTables(string dbName)
{
Expand Down
4 changes: 2 additions & 2 deletions Table/MDataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,12 @@ public string ToJson()
/// <param name="addSchema">首行输出表架构信息,反接收时可还原架构(默认false)</param>
public string ToJson(bool addHead, bool addSchema)
{
return ToJson(addHead, addSchema, RowOp.IgnoreNull);
return ToJson(addHead, addSchema, RowOp.None);
}
/// <param name="isConvertNameToLower">是否将名称转为小写</param>
public string ToJson(bool addHead, bool addSchema, bool isConvertNameToLower)
{
return ToJson(addHead, addSchema, RowOp.IgnoreNull, isConvertNameToLower);
return ToJson(addHead, addSchema, RowOp.None, isConvertNameToLower);
}
/// <param name="rowOp">过滤选项</param>
public string ToJson(bool addHead, bool addSchema, RowOp rowOp)
Expand Down
1 change: 1 addition & 0 deletions Table/MDataTableFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public static MDataTable Select(MDataTable table, int pageIndex, int pageSize, o
List<MDataRow> findRows = FindAll(table, whereObj);
if (findRows != null)
{
sTable.RecordsAffected = findRows.Count;//设置记录总数
FilterPager(findRows, pageIndex, pageSize);//进行分页筛选,再克隆最后的数据。

for (int i = 0; i < findRows.Count; i++)
Expand Down
62 changes: 47 additions & 15 deletions Tool/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum EscapeOp
/// </summary>
public partial class JsonHelper
{

#region 实例属性

public JsonHelper()
Expand Down Expand Up @@ -151,7 +151,7 @@ public void AddBr()
jsonItems.Add(brFlag);
rowCount++;
}
string footText = string.Empty;
StringBuilder footText = new StringBuilder();
/// <summary>
/// 添加底部数据(只有AddHead为true情况才能添加数据)
/// </summary>
Expand All @@ -166,7 +166,7 @@ public void AddFoot(string name, string value, bool noQuotes)
{
if (_AddHead)
{
footText += "," + Format(name, value, noQuotes);
footText.Append("," + Format(name, value, noQuotes));
}
}

Expand Down Expand Up @@ -269,7 +269,14 @@ public override string ToString()
{
sb.Append("[");
}
sb.Append("{");
char left = '{', right = '}';
if (!jsonItems[0].Contains(":") && !jsonItems[rowCount - 1].Contains(":"))
{
//说明为数组
left = '[';
right = ']';
}
sb.Append(left);
int index = 0;
foreach (string val in jsonItems)
{
Expand All @@ -284,10 +291,10 @@ public override string ToString()
{
sb.Remove(sb.Length - 1, 1);//性能优化(内部时,必须多了一个“,”号)。
//sb = sb.Replace(",", "", sb.Length - 1, 1);
sb.Append("},");
sb.Append(right + ",");
if (index < jsonItems.Count)
{
sb.Append("{");
sb.Append(left);
}
}
}
Expand All @@ -304,7 +311,7 @@ public override string ToString()
}
if (_AddHead)
{
sb.Append(footText + "}");
sb.Append(footText.ToString() + "}");
}
string json = sb.ToString();
if ((Escape == EscapeOp.Default && System.Web.HttpContext.Current != null) || Escape == EscapeOp.Yes) // Web应用
Expand Down Expand Up @@ -588,14 +595,8 @@ public void Fill(MDataRow row)
}
else
{
if (!t.FullName.StartsWith("System."))//普通对象。
{
MDataRow oRow = new MDataRow(TableSchema.GetColumns(t));
oRow.LoadFrom(cell.Value);
value = oRow.ToJson(_RowOp, IsConvertNameToLower);
noQuot = true;
}
else if (cell.Value is IEnumerable)

if (cell.Value is IEnumerable)
{
int len = StaticTool.GetArgumentLength(ref t);
if (len == 1)
Expand All @@ -610,6 +611,21 @@ public void Fill(MDataRow row)
noQuot = true;
}
}
else
{
if (t.FullName == "System.Object")
{
t = cell.Value.GetType();
}
if (!t.FullName.StartsWith("System."))//普通对象。
{
MDataRow oRow = new MDataRow(TableSchema.GetColumns(t));
oRow.LoadFrom(cell.Value);
value = oRow.ToJson(_RowOp, IsConvertNameToLower);
noQuot = true;
}
}

}

}
Expand Down Expand Up @@ -692,6 +708,22 @@ public void Fill(object obj)
MDataTable dt = o as DataTable;
Fill(dt);
}
else if (o is String || o is DateTime || o is Enum || o is Guid)
{
string str = o.ToString();
if ((str[0] == '{' || str[0] == '[') && JsonSplit.IsJson(str))
{
Fill(MDataRow.CreateFrom(o));
}
else
{
jsonItems.Add("\"" + str + "\"");
}
}
else if (o is ValueType)
{
jsonItems.Add(o.ToString());
}
else
{
Fill(MDataRow.CreateFrom(o));
Expand Down
5 changes: 4 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -599,4 +599,7 @@
383��XHtmlBase ������Xml�ļ��أ�2016-10-08)
384��SqlValue �����������ƣ�GUID��ISNULL����������2016-10-08)
385��MDataTable ����Select����Ϊ<=�������ж����⣨2016-10-08)
386��AutoCache��JsonHelper����Escape���ԡ�MDataTable����ToJson���أ�������\n��ת���滻��2016-10-09)
386��AutoCache��JsonHelper����Escape���ԡ�MDataTable����ToJson���أ�������\n��ת���滻��2016-10-09)
387��MDataTable ToJson ����null�����ݣ�Ĭ����� xx:null ֵ��2016-10-09)
388��Oracle(DBTool.GetTables) ���Ӷ���ͼ�Ĺ��ˣ�2016-10-10)
389��JsonHelper ����ʵ��Ƕ�׵����⡢ͬʱ���Ӷ������֧�֣�2016-10-14)

0 comments on commit 072c96b

Please sign in to comment.